--- Daodan/src/Daodan.c 2013/03/08 00:31:30 694 +++ Daodan/src/Daodan.c 2013/03/19 15:00:23 705 @@ -9,7 +9,6 @@ #include "Daodan_Persistence.h" #include "Daodan_BSL.h" #include "Daodan_Console.h" -#include "Daodan_WindowHack.h" #include "Oni.h" @@ -41,12 +40,13 @@ 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; @@ -54,13 +54,21 @@ 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 WINAPI); -bool patch_chinese = false; +typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId); +bool patch_chinese = true; - -void ONICALL DDrShowResumeButton(int window, int visibility) +// 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); @@ -69,7 +77,7 @@ void ONICALL DDrShowResumeButton(int win /* Options always visible patch */ -void ONICALL DDrShowOptionsButton(int window, int visibility) +void ONICALL DDrShowOptionsButton(WMtWindow* window, int visibility) { WMrWindow_SetVisible(window, 1); } @@ -254,10 +262,12 @@ bool DDrPatch_Init() if(patch_chinese) { - DDrStartupMessage("Loading chinese DLL"); - HMODULE dll = LoadLibrary("xfhsm_oni.dll"); - DWORD err = GetLastError(); - DDrStartupMessage(" - Module loading returned error %i", err); + HMODULE dll; + DWORD err; + + DDrStartupMessage("Loading chinese DLL"); + dll = LoadLibrary("xfhsm_oni.dll"); + err = GetLastError(); if( dll ) { void* proc = GetProcAddress( dll, "InstallHook" ); @@ -265,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); } } @@ -311,6 +325,23 @@ bool DDrPatch_Init() 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; } @@ -359,6 +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, "gamma")) + opt_gamma = !_stricmp(inifile_cleanstr(value), "true"); else DDrStartupMessage("unrecognised option \"%s\"", name); break; @@ -409,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")) @@ -421,6 +454,8 @@ bool DDrIniCallback(char* section, bool 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; @@ -665,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) @@ -679,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); @@ -713,7 +783,7 @@ void __cdecl DDrMain(int argc, char* arg DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning); - ONiMain(argc, argv); + ONiMain(argc, argv); } /* void DDrWrongExe()