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 689 by alloc, Mon Mar 4 15:52:19 2013 UTC vs.
Revision 739 by iritscen, Sun Mar 24 14:41:49 2013 UTC

# Line 1 | Line 1
1 + #include <windows.h>
2   #include <string.h>
3  
4   #include "Daodan.h"
# Line 8 | Line 9
9   #include "Daodan_Persistence.h"
10   #include "Daodan_BSL.h"
11   #include "Daodan_Console.h"
11 #include "Daodan_WindowHack.h"
12  
13   #include "Oni.h"
14 #include "Oni_Persistence.h"
14  
15 < #include "BFW_Utility.h"
15 > #include "Oni_GL.h"
16 > #include "Daodan_GL.h"
17  
18 < #include "oni_gl.h"
19 < #include "daodan_gl.h"
20 <
21 < #include "inifile.h"
18 > #include "Inifile_Reader.h"
19  
20   HMODULE DDrDLLModule;
21   HMODULE DDrONiModule;
# Line 41 | Line 38 | bool patch_argb8888 = true;
38   bool patch_killvtune = true;
39   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;
53   bool patch_newweapon = true;
54   bool opt_usedaodanbsl = true;
55   bool opt_border = true;
57 bool opt_shadow = false;
56   bool opt_topmost = false;
57 + bool opt_gamma = true;
58 +
59 + typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId);
60 + bool patch_chinese = true;
61 +
62 +
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);
75 +        WMrWindow_SetVisible(window, visibility);
76 + }
77 +
78 +
79 + /* Options always visible patch */
80 + void ONICALL DDrShowOptionsButton(WMtWindow* window, int visibility)
81 + {
82 +        WMrWindow_SetVisible(window, 1);
83 + }
84 +
85 +
86  
60 typedef int (__cdecl *CHINESEPROC)(DWORD WINAPI);
61 bool patch_chinese = false;
87   bool DDrPatch_Init()
88   {
89          DDrStartupMessage("patching engine");
# Line 143 | Line 168 | bool DDrPatch_Init()
168          // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the Windows key but has the possible side effect of allowing the screensaver to enable itself in-game.
169          if (patch_alttab)
170          {
171 +                // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start
172                  DDrPatch_Byte  ((char*)UUrPlatform_Initialize, 0xC3);
173                  DDrPatch_Byte  ((char*)UUrPlatform_Terminate, 0xC3);
174          }
# Line 189 | Line 215 | bool DDrPatch_Init()
215          //Test newweap patch
216          if (patch_newweapon) {
217                  
218 <                //Makes it always say "Recieved weapon_name."
218 >                //Makes it always say "Received weapon_name."
219                  //Needs check for loc_4DFC66
220                  //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2);
221  
# Line 236 | Line 262 | bool DDrPatch_Init()
262          
263          if(patch_chinese)
264          {
265 <                HMODULE dll = LoadLibrary("xfhsm_oni.dll");
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 244 | 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 281 | Line 316 | bool DDrPatch_Init()
316  
317   //FLATLINE?     DDrPatch_MakeCall((void*)(OniExe + 0x000C26CB), FLrHook_DoorOpen);
318   //FLATLINE?     DDrPatch_MakeCall((void*)(OniExe + 0x000EE3CF), FLrHook_ConsoleActivate);
319 +
320 +
321 +        // Fix options not visible in main menu when a game was started
322 +        if(patch_optionsvisible)
323 +        {
324 +                DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
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  
348 +
349   enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section;
350  
351   bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
# Line 312 | Line 374 | bool DDrIniCallback(char* section, bool
374                                  opt_usedaodanbsl = !_stricmp(inifile_cleanstr(value), "true");
375                          else if (!_stricmp(name, "border"))
376                                  opt_border = !_stricmp(inifile_cleanstr(value), "true");
315                        else if (!_stricmp(name, "shadow"))
316                                opt_shadow = !_stricmp(inifile_cleanstr(value), "true");
377                          else if (!_stricmp(name, "topmost"))
378                                  opt_topmost = !_stricmp(inifile_cleanstr(value), "true");
379                          else if (!_stricmp(name, "multibyte"))
# Line 330 | 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, "devmode"))
394 <                                //turn_dev_mode_on = !_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 382 | 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 392 | Line 452 | bool DDrIniCallback(char* section, bool
452                                  patch_cheater = !_stricmp(inifile_cleanstr(value), "true");
453                          else if (!_stricmp(name, "newweap"))
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 537 | Line 601 | void DDrConfig()
601   void ONICALL DDrGame_Init()
602   {
603          if (opt_usedaodanbsl)
604 <                SLrDaodan_Initalize();
604 >                SLrDaodan_Initialize();
605   }
606  
607   void DDrException() {
# Line 588 | Line 652 | void __cdecl DDrMain(int argc, char* arg
652  
653          DDrStartupMessage("daodan attached!");
654          
655 +        // Tell Oni to not load non levelX_final-files by default:
656          opt_ignore_private_data = false;
657 +
658 +        // Enable sound by default:
659          opt_sound = true;
660          
661          DDrConfig();
# Line 633 | 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 647 | 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 679 | Line 781 | void __cdecl DDrMain(int argc, char* arg
781                  DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
782          }
783  
682        //DDrPatch_MakeJump((void*)(OniExe + 0x000378c0, (void*)DDrException);
784          DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
684        //init_daodan_gl();
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)