ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/Daodan.c
(Generate patch)

Comparing Daodan/src/Daodan.c (file contents):
Revision 694 by alloc, Fri Mar 8 00:31:30 2013 UTC vs.
Revision 705 by alloc, Tue Mar 19 15:00:23 2013 UTC

# Line 9 | Line 9
9   #include "Daodan_Persistence.h"
10   #include "Daodan_BSL.h"
11   #include "Daodan_Console.h"
12 #include "Daodan_WindowHack.h"
12  
13   #include "Oni.h"
14  
# Line 41 | Line 40 | bool patch_getcmdline = true;
40   bool patch_disablecmdline = true;
41   bool patch_optionsvisible = true;
42  
43 + bool patch_binkplay = true;
44   bool patch_safeprintf = true;
45   bool patch_daodandisplayenum = true;
46   bool patch_usegettickcount = true;
47   bool patch_cheatsenabled = true;
48 < bool patch_usedaodangl = false;
49 < bool patch_windowhack = true;
48 > bool patch_usedaodangl = true;
49 > bool patch_clipcursor = true;
50   bool patch_daodaninit = true;
51   bool patch_bsl = true;
52   bool patch_cheater = true;
# Line 54 | Line 54 | bool patch_newweapon = true;
54   bool opt_usedaodanbsl = true;
55   bool opt_border = true;
56   bool opt_topmost = false;
57 + bool opt_gamma = true;
58  
59 < typedef int (__cdecl *CHINESEPROC)(DWORD WINAPI);
60 < bool patch_chinese = false;
59 > typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId);
60 > bool patch_chinese = true;
61  
62  
63 <
64 < void ONICALL DDrShowResumeButton(int window, int visibility)
63 > // Hooked WMrSlider_SetRange() in ONiOGU_Options_InitDialog. Disables a gamma
64 > // slider in windowed mode.
65 > static void ONICALL DD_ONiOGU_GammaSlider_SetRange(WMtWindow* window, int min_value, int max_value)
66 > {
67 >        WMrWindow_SetEnabled(window, M3gResolutionSwitch && opt_gamma);
68 >        WMrSlider_SetRange(window, min_value, max_value);
69 > }
70 >
71 > void ONICALL DDrShowResumeButton(WMtWindow* window, int visibility)
72   {
73          if (visibility)
74                  WMrWindow_SetLocation(window, 150, 350);
# Line 69 | Line 77 | void ONICALL DDrShowResumeButton(int win
77  
78  
79   /* Options always visible patch */
80 < void ONICALL DDrShowOptionsButton(int window, int visibility)
80 > void ONICALL DDrShowOptionsButton(WMtWindow* window, int visibility)
81   {
82          WMrWindow_SetVisible(window, 1);
83   }
# Line 254 | Line 262 | bool DDrPatch_Init()
262          
263          if(patch_chinese)
264          {
265 <                DDrStartupMessage("Loading chinese DLL");
266 <                HMODULE dll = LoadLibrary("xfhsm_oni.dll");
267 <                DWORD err = GetLastError();
268 <                DDrStartupMessage(" - Module loading returned error %i", err);
265 >                HMODULE dll;
266 >                DWORD err;
267 >
268 >                DDrStartupMessage("Loading chinese DLL");
269 >                dll = LoadLibrary("xfhsm_oni.dll");
270 >                err = GetLastError();
271                  if( dll )
272                  {
273                          void* proc = GetProcAddress( dll, "InstallHook" );
# Line 265 | Line 275 | bool DDrPatch_Init()
275                          {
276                                  ((CHINESEPROC)proc)(GetCurrentThreadId());
277                          }
278 +                } else {
279 +                        char msg[100];
280 +                        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL);
281 +                        DDrStartupMessage(" - Module loading failed with error %i: %s", err, msg);
282                  }
283          }
284  
# Line 311 | Line 325 | bool DDrPatch_Init()
325                  DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton);
326          }
327  
328 +        // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting
329 +        // instead of DirectDraw; patch ONiRunGame to use the same method to play
330 +        // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
331 +        // latter has problems on WINE).
332 +        if (patch_binkplay)
333 +        {
334 +                // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
335 +                DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
336 +                // call ONrMovie_Play_Hardware -> call ONrMovie_Play
337 +                DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
338 +        }
339 +
340 +        // Patch a gamma slider in Options dialog (unconditionally).
341 +        // ONiOGU_Options_InitDialog: replace WMrSlider_SetRange(gammaSliderWindow, ...)
342 +        // call with our hook function.
343 +        DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
344 +
345          return true;
346   }
347  
# Line 359 | Line 390 | bool DDrIniCallback(char* section, bool
390                                  opt_sound = !_stricmp(inifile_cleanstr(value), "true");
391                          else if (!_stricmp(name, "switch"))
392                                  M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true");
393 +                        else if (!_stricmp(name, "gamma"))
394 +                                opt_gamma = !_stricmp(inifile_cleanstr(value), "true");
395                          else
396                                  DDrStartupMessage("unrecognised option \"%s\"", name);
397                          break;
# Line 409 | Line 442 | bool DDrIniCallback(char* section, bool
442                                  patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true");
443                          else if (!_stricmp(name, "usedaodangl"))
444                                  patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true");
445 <                        else if (!_stricmp(name, "windowhack"))
446 <                                patch_windowhack = !_stricmp(inifile_cleanstr(value), "true");
445 >                        else if (!_stricmp(name, "clipcursor"))
446 >                                patch_clipcursor = !_stricmp(inifile_cleanstr(value), "true");
447                          else if (!_stricmp(name, "daodaninit"))
448                                  patch_daodaninit = !_stricmp(inifile_cleanstr(value), "true");
449                          else if (!_stricmp(name, "bsl"))
# Line 421 | Line 454 | bool DDrIniCallback(char* section, bool
454                                  patch_newweapon = !_stricmp(inifile_cleanstr(value), "true");
455                          else if (!_stricmp(name, "optionsvisible"))
456                                  patch_optionsvisible = !_stricmp(inifile_cleanstr(value), "true");
457 +                        else if (!_stricmp(name, "binkplay"))
458 +                                patch_binkplay = !_stricmp(inifile_cleanstr(value), "true");
459                          else
460                                  DDrStartupMessage("unrecognised patch \"%s\"", name);
461                          break;
# Line 665 | Line 700 | void __cdecl DDrMain(int argc, char* arg
700          
701          // Daodan device mode enumeration function
702          if (patch_daodandisplayenum)
703 <                DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)daodan_enumerate_valid_display_modes);
703 >                DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
704          
705          // Performance patch
706          if (patch_usegettickcount)
# Line 679 | Line 714 | void __cdecl DDrMain(int argc, char* arg
714          if (patch_cheatsenabled)
715                  DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
716  
717 <        // Windowed mode
717 >        // DaodanGL with windowed mode support.
718          if (patch_usedaodangl)
719          {
720 <                DDrPatch_NOOP((char*)(OniExe + 0x000032B7), 6);
721 <                DDrPatch_MakeCall((void*)(OniExe + 0x000032B7), (void*)LIiP_SetCursorPosHook);
722 <        
723 <                DDrPatch_NOOP((char*)(OniExe + 0x00003349), 6);
724 <                DDrPatch_MakeCall((void*)(OniExe + 0x00003349), (void*)LIiP_SetCursorPosHook);
725 <                DDrPatch_MakeJump((void*)ONrPlatform_Initialize, (void*)DDrPlatform_Initialize);
726 <                DDrPatch_MakeJump((void*)gl_platform_initialize, (void*)daodangl_platform_initialize);
727 <        }
728 <        // Hacked windowed mode (for when daodangl isn't working properly)
729 <        else if (patch_windowhack)
730 <                DDrWindowHack_Install();
720 >                // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
721 >                DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
722 >                DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect);
723 >
724 >                // UUrWindow_GetSize: GetWindowRect -> GetClientRect.
725 >                DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
726 >                DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
727 >
728 >                // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates.
729 >                DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6);
730 >                DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos);
731 >
732 >                // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates.
733 >                DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6);
734 >                DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos);
735 >
736 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
737 >                DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6);
738 >                DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos);
739 >
740 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
741 >                DDrPatch_NOOP((char*) OniExe + 0x00003349, 6);
742 >                DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos);
743 >
744 >                // Replace ONrPlatformInitialize.
745 >                DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize);
746 >
747 >                // Replace gl_platform_initialize.
748 >                DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize);
749 >
750 >                // Replace gl_platform_dispose.
751 >                DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose);
752 >        }
753 >
754 >        if (patch_clipcursor)
755 >        {
756 >                // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
757 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
758 >
759 >                // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
760 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
761 >                
762 >                // LIrTermiante: replace LIrPlatform_Terminate call with our hook.
763 >                DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
764 >        }
765 >
766          
767          if (patch_daodaninit)
768                  DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init);
# Line 713 | Line 783 | void __cdecl DDrMain(int argc, char* arg
783  
784          DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
785          
786 <        ONiMain(argc, argv);
786 >        ONiMain(argc, argv);
787   }
788   /*
789   void DDrWrongExe()

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)