--- Daodan/src/Daodan.c 2013/03/06 18:33:15 690 +++ Daodan/src/Daodan.c 2013/03/24 14:41:49 739 @@ -1,3 +1,4 @@ +#include #include #include "Daodan.h" @@ -8,17 +9,13 @@ #include "Daodan_Persistence.h" #include "Daodan_BSL.h" #include "Daodan_Console.h" -#include "Daodan_WindowHack.h" #include "Oni.h" -#include "Oni_Persistence.h" -#include "BFW_Utility.h" +#include "Oni_GL.h" +#include "Daodan_GL.h" -#include "oni_gl.h" -#include "daodan_gl.h" - -#include "inifile.h" +#include "Inifile_Reader.h" HMODULE DDrDLLModule; HMODULE DDrONiModule; @@ -41,13 +38,15 @@ bool patch_argb8888 = true; bool patch_killvtune = true; bool patch_getcmdline = true; bool patch_disablecmdline = true; +bool patch_optionsvisible = true; +bool patch_binkplay = true; bool patch_safeprintf = true; bool patch_daodandisplayenum = true; bool patch_usegettickcount = true; bool patch_cheatsenabled = true; -bool patch_usedaodangl = false; -bool patch_windowhack = true; +bool patch_usedaodangl = true; +bool patch_clipcursor = true; bool patch_daodaninit = true; bool patch_bsl = true; bool patch_cheater = true; @@ -55,9 +54,36 @@ bool patch_newweapon = true; bool opt_usedaodanbsl = true; bool opt_border = true; bool opt_topmost = false; +bool opt_gamma = true; + +typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId); +bool patch_chinese = true; + + +// Hooked WMrSlider_SetRange() in ONiOGU_Options_InitDialog. Disables a gamma +// slider in windowed mode. +static void ONICALL DD_ONiOGU_GammaSlider_SetRange(WMtWindow* window, int min_value, int max_value) +{ + WMrWindow_SetEnabled(window, M3gResolutionSwitch && opt_gamma); + WMrSlider_SetRange(window, min_value, max_value); +} + +void ONICALL DDrShowResumeButton(WMtWindow* window, int visibility) +{ + if (visibility) + WMrWindow_SetLocation(window, 150, 350); + WMrWindow_SetVisible(window, visibility); +} + + +/* Options always visible patch */ +void ONICALL DDrShowOptionsButton(WMtWindow* window, int visibility) +{ + WMrWindow_SetVisible(window, 1); +} + + -typedef int (__cdecl *CHINESEPROC)(DWORD WINAPI); -bool patch_chinese = false; bool DDrPatch_Init() { DDrStartupMessage("patching engine"); @@ -189,7 +215,7 @@ bool DDrPatch_Init() //Test newweap patch if (patch_newweapon) { - //Makes it always say "Recieved weapon_name." + //Makes it always say "Received weapon_name." //Needs check for loc_4DFC66 //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2); @@ -236,7 +262,12 @@ bool DDrPatch_Init() if(patch_chinese) { - HMODULE dll = LoadLibrary("xfhsm_oni.dll"); + HMODULE dll; + DWORD err; + + DDrStartupMessage("Loading chinese DLL"); + dll = LoadLibrary("xfhsm_oni.dll"); + err = GetLastError(); if( dll ) { void* proc = GetProcAddress( dll, "InstallHook" ); @@ -244,6 +275,10 @@ bool DDrPatch_Init() { ((CHINESEPROC)proc)(GetCurrentThreadId()); } + } else { + char msg[100]; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL); + DDrStartupMessage(" - Module loading failed with error %i: %s", err, msg); } } @@ -281,9 +316,36 @@ bool DDrPatch_Init() //FLATLINE? DDrPatch_MakeCall((void*)(OniExe + 0x000C26CB), FLrHook_DoorOpen); //FLATLINE? DDrPatch_MakeCall((void*)(OniExe + 0x000EE3CF), FLrHook_ConsoleActivate); + + + // Fix options not visible in main menu when a game was started + if(patch_optionsvisible) + { + DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton); + DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton); + } + + // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting + // instead of DirectDraw; patch ONiRunGame to use the same method to play + // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the + // latter has problems on WINE). + if (patch_binkplay) + { + // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION. + DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02); + // call ONrMovie_Play_Hardware -> call ONrMovie_Play + DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play); + } + + // Patch a gamma slider in Options dialog (unconditionally). + // ONiOGU_Options_InitDialog: replace WMrSlider_SetRange(gammaSliderWindow, ...) + // call with our hook function. + DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange); + return true; } + enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section; bool DDrIniCallback(char* section, bool newsection, char* name, char* value) @@ -328,8 +390,8 @@ bool DDrIniCallback(char* section, bool opt_sound = !_stricmp(inifile_cleanstr(value), "true"); else if (!_stricmp(name, "switch")) M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true"); - //else if (!_stricmp(name, "devmode")) - //turn_dev_mode_on = !_stricmp(inifile_cleanstr(value), "true"); + else if (!_stricmp(name, "gamma")) + opt_gamma = !_stricmp(inifile_cleanstr(value), "true"); else DDrStartupMessage("unrecognised option \"%s\"", name); break; @@ -380,8 +442,8 @@ bool DDrIniCallback(char* section, bool patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true"); else if (!_stricmp(name, "usedaodangl")) patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true"); - else if (!_stricmp(name, "windowhack")) - patch_windowhack = !_stricmp(inifile_cleanstr(value), "true"); + else if (!_stricmp(name, "clipcursor")) + patch_clipcursor = !_stricmp(inifile_cleanstr(value), "true"); else if (!_stricmp(name, "daodaninit")) patch_daodaninit = !_stricmp(inifile_cleanstr(value), "true"); else if (!_stricmp(name, "bsl")) @@ -390,6 +452,10 @@ bool DDrIniCallback(char* section, bool patch_cheater = !_stricmp(inifile_cleanstr(value), "true"); else if (!_stricmp(name, "newweap")) patch_newweapon = !_stricmp(inifile_cleanstr(value), "true"); + else if (!_stricmp(name, "optionsvisible")) + patch_optionsvisible = !_stricmp(inifile_cleanstr(value), "true"); + else if (!_stricmp(name, "binkplay")) + patch_binkplay = !_stricmp(inifile_cleanstr(value), "true"); else DDrStartupMessage("unrecognised patch \"%s\"", name); break; @@ -535,7 +601,7 @@ void DDrConfig() void ONICALL DDrGame_Init() { if (opt_usedaodanbsl) - SLrDaodan_Initalize(); + SLrDaodan_Initialize(); } void DDrException() { @@ -634,7 +700,7 @@ void __cdecl DDrMain(int argc, char* arg // Daodan device mode enumeration function if (patch_daodandisplayenum) - DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)daodan_enumerate_valid_display_modes); + DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes); // Performance patch if (patch_usegettickcount) @@ -648,20 +714,55 @@ void __cdecl DDrMain(int argc, char* arg if (patch_cheatsenabled) DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame); - // Windowed mode + // DaodanGL with windowed mode support. if (patch_usedaodangl) { - DDrPatch_NOOP((char*)(OniExe + 0x000032B7), 6); - DDrPatch_MakeCall((void*)(OniExe + 0x000032B7), (void*)LIiP_SetCursorPosHook); - - DDrPatch_NOOP((char*)(OniExe + 0x00003349), 6); - DDrPatch_MakeCall((void*)(OniExe + 0x00003349), (void*)LIiP_SetCursorPosHook); - DDrPatch_MakeJump((void*)ONrPlatform_Initialize, (void*)DDrPlatform_Initialize); - DDrPatch_MakeJump((void*)gl_platform_initialize, (void*)daodangl_platform_initialize); - } - // Hacked windowed mode (for when daodangl isn't working properly) - else if (patch_windowhack) - DDrWindowHack_Install(); + // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect. + DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6); + DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect); + + // UUrWindow_GetSize: GetWindowRect -> GetClientRect. + DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6); + DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect); + + // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates. + DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6); + DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos); + + // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates. + DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6); + DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos); + + // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates. + DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6); + DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos); + + // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates. + DDrPatch_NOOP((char*) OniExe + 0x00003349, 6); + DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos); + + // Replace ONrPlatformInitialize. + DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize); + + // Replace gl_platform_initialize. + DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize); + + // Replace gl_platform_dispose. + DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose); + } + + if (patch_clipcursor) + { + // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook. + DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set); + + // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook. + DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set); + + // LIrTermiante: replace LIrPlatform_Terminate call with our hook. + DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate); + } + if (patch_daodaninit) DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init); @@ -680,11 +781,9 @@ void __cdecl DDrMain(int argc, char* arg DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad); } - //DDrPatch_MakeJump((void*)(OniExe + 0x000378c0, (void*)DDrException); DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning); - //init_daodan_gl(); - ONiMain(argc, argv); + ONiMain(argc, argv); } /* void DDrWrongExe()