--- Daodan/src/Daodan.c 2013/03/07 22:38:21 693 +++ Daodan/src/Daodan.c 2013/04/29 15:26:54 837 @@ -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); } @@ -78,7 +86,7 @@ void ONICALL DDrShowOptionsButton(int wi bool DDrPatch_Init() { - DDrStartupMessage("patching engine"); + DDrStartupMessage("Daodan: Patching engine"); // Font texture cache doubled if (patch_fonttexturecache) @@ -207,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); @@ -254,13 +262,25 @@ bool DDrPatch_Init() if(patch_chinese) { - HMODULE dll = LoadLibrary("xfhsm_oni.dll"); - if( dll ) + if (GetFileAttributes("xfhsm_oni.dll") != INVALID_FILE_ATTRIBUTES) { - void* proc = GetProcAddress( dll, "InstallHook" ); - if(proc) + HMODULE dll; + DWORD err; + + DDrStartupMessage("Daodan: Loading chinese DLL"); + dll = LoadLibrary("xfhsm_oni.dll"); + err = GetLastError(); + if( dll ) { - ((CHINESEPROC)proc)(GetCurrentThreadId()); + void* proc = GetProcAddress( dll, "InstallHook" ); + if(proc) + { + ((CHINESEPROC)proc)(GetCurrentThreadId()); + } + } else { + char msg[100]; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL); + DDrStartupMessage("Daodan: Loading DLL failed with error %i: %s", err, msg); } } } @@ -308,6 +328,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; } @@ -329,7 +366,7 @@ bool DDrIniCallback(char* section, bool else { ini_section = s_unknown; - DDrStartupMessage("unrecognised section \"%s\"", section); + DDrStartupMessage("Daodan: Unrecognised ini section \"%s\"", section); } } @@ -356,8 +393,10 @@ 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); + DDrStartupMessage("Daodan: Unrecognised ini option \"%s\"", name); break; case s_patch: if (!_stricmp(name, "fonttexturecache")) @@ -406,8 +445,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")) @@ -418,8 +457,10 @@ 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); + DDrStartupMessage("Daodan: Unrecognised ini patch \"%s\"", name); break; case s_language: if (!_stricmp(name, "chinese")) @@ -529,7 +570,7 @@ bool DDrIniCallback(char* section, bool else if (!_stricmp(name, "carousel_off")) DDr_CheatTable[21].message_off = _strdup(value); else - DDrStartupMessage("unrecognised language item \"%s\"", name); + DDrStartupMessage("Daodan: Unrecognised ini language item \"%s\"", name); break; case s_bsl: default: @@ -545,7 +586,7 @@ void DDrConfig() if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES) { FILE* fp; - DDrStartupMessage("daodan.ini doesn't exist, creating"); + DDrStartupMessage("Daodan: daodan.ini doesn't exist, creating"); fp = fopen("daodan.ini", "w"); if (fp) { @@ -554,16 +595,16 @@ void DDrConfig() } } - DDrStartupMessage("parsing daodan.ini..."); + DDrStartupMessage("Daodan: Parsing daodan.ini..."); if (!inifile_read("daodan.ini", DDrIniCallback)) - DDrStartupMessage("error reading daodan.ini, check your syntax!"); - DDrStartupMessage("finished parsing"); + DDrStartupMessage("Daodan: Error reading daodan.ini, check your syntax!"); + DDrStartupMessage("Daodan: Finished parsing"); } void ONICALL DDrGame_Init() { if (opt_usedaodanbsl) - SLrDaodan_Initalize(); + SLrDaodan_Initialize(); } void DDrException() { @@ -612,7 +653,7 @@ void __cdecl DDrMain(int argc, char* arg char* option; bool falseoption; - DDrStartupMessage("daodan attached!"); + DDrStartupMessage("Daodan: Daodan attached!"); // Tell Oni to not load non levelX_final-files by default: opt_ignore_private_data = false; @@ -621,7 +662,7 @@ void __cdecl DDrMain(int argc, char* arg opt_sound = true; DDrConfig(); - DDrStartupMessage("parsing command line..."); + DDrStartupMessage("Daodan: Parsing command line..."); for (i = 1; i < argc; i ++) { if (argv[i][0] == '-') @@ -649,11 +690,11 @@ void __cdecl DDrMain(int argc, char* arg } else { - DDrStartupMessage("parse error \"%s\"", argv[i]); + DDrStartupMessage("Daodan: Parse error \"%s\"", argv[i]); break; } } - DDrStartupMessage("finished parsing"); + DDrStartupMessage("Daodan: Finished parsing"); DDrPatch_Init(); // Safe startup message printer @@ -662,7 +703,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) @@ -676,20 +717,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); @@ -710,7 +786,7 @@ void __cdecl DDrMain(int argc, char* arg DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning); - ONiMain(argc, argv); + ONiMain(argc, argv); } /* void DDrWrongExe()