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 837 by alloc, Mon Apr 29 15:26:54 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");
89 >        DDrStartupMessage("Daodan: Patching engine");
90          
91          // Font texture cache doubled
92          if (patch_fonttexturecache)
# 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");
240 <                if( dll )
265 >                if (GetFileAttributes("xfhsm_oni.dll") != INVALID_FILE_ATTRIBUTES)
266                  {
267 <                        void* proc = GetProcAddress( dll, "InstallHook" );
268 <                        if(proc)
267 >                        HMODULE dll;
268 >                        DWORD err;
269 >
270 >                        DDrStartupMessage("Daodan: Loading chinese DLL");
271 >                        dll = LoadLibrary("xfhsm_oni.dll");
272 >                        err = GetLastError();
273 >                        if( dll )
274                          {
275 <                                ((CHINESEPROC)proc)(GetCurrentThreadId());
275 >                                void* proc = GetProcAddress( dll, "InstallHook" );
276 >                                if(proc)
277 >                                {
278 >                                        ((CHINESEPROC)proc)(GetCurrentThreadId());
279 >                                }
280 >                        } else {
281 >                                char msg[100];
282 >                                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL);
283 >                                DDrStartupMessage("Daodan: Loading DLL failed with error %i: %s", err, msg);
284                          }
285                  }
286          }
# Line 281 | Line 319 | bool DDrPatch_Init()
319  
320   //FLATLINE?     DDrPatch_MakeCall((void*)(OniExe + 0x000C26CB), FLrHook_DoorOpen);
321   //FLATLINE?     DDrPatch_MakeCall((void*)(OniExe + 0x000EE3CF), FLrHook_ConsoleActivate);
322 +
323 +
324 +        // Fix options not visible in main menu when a game was started
325 +        if(patch_optionsvisible)
326 +        {
327 +                DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
328 +                DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton);
329 +        }
330 +
331 +        // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting
332 +        // instead of DirectDraw; patch ONiRunGame to use the same method to play
333 +        // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
334 +        // latter has problems on WINE).
335 +        if (patch_binkplay)
336 +        {
337 +                // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
338 +                DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
339 +                // call ONrMovie_Play_Hardware -> call ONrMovie_Play
340 +                DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
341 +        }
342 +
343 +        // Patch a gamma slider in Options dialog (unconditionally).
344 +        // ONiOGU_Options_InitDialog: replace WMrSlider_SetRange(gammaSliderWindow, ...)
345 +        // call with our hook function.
346 +        DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
347 +
348          return true;
349   }
350  
351 +
352   enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section;
353  
354   bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
# Line 301 | Line 366 | bool DDrIniCallback(char* section, bool
366                  else
367                  {
368                          ini_section = s_unknown;
369 <                        DDrStartupMessage("unrecognised section \"%s\"", section);
369 >                        DDrStartupMessage("Daodan: Unrecognised ini section \"%s\"", section);
370                  }
371          }
372          
# Line 312 | Line 377 | bool DDrIniCallback(char* section, bool
377                                  opt_usedaodanbsl = !_stricmp(inifile_cleanstr(value), "true");
378                          else if (!_stricmp(name, "border"))
379                                  opt_border = !_stricmp(inifile_cleanstr(value), "true");
315                        else if (!_stricmp(name, "shadow"))
316                                opt_shadow = !_stricmp(inifile_cleanstr(value), "true");
380                          else if (!_stricmp(name, "topmost"))
381                                  opt_topmost = !_stricmp(inifile_cleanstr(value), "true");
382                          else if (!_stricmp(name, "multibyte"))
# Line 330 | Line 393 | bool DDrIniCallback(char* section, bool
393                                  opt_sound = !_stricmp(inifile_cleanstr(value), "true");
394                          else if (!_stricmp(name, "switch"))
395                                  M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true");
396 <                        //else if (!_stricmp(name, "devmode"))
397 <                                //turn_dev_mode_on = !_stricmp(inifile_cleanstr(value), "true");
396 >                        else if (!_stricmp(name, "gamma"))
397 >                                opt_gamma = !_stricmp(inifile_cleanstr(value), "true");
398                          else
399 <                                DDrStartupMessage("unrecognised option \"%s\"", name);
399 >                                DDrStartupMessage("Daodan: Unrecognised ini option \"%s\"", name);
400                          break;
401                  case s_patch:
402                          if (!_stricmp(name, "fonttexturecache"))
# Line 382 | Line 445 | bool DDrIniCallback(char* section, bool
445                                  patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true");
446                          else if (!_stricmp(name, "usedaodangl"))
447                                  patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true");
448 <                        else if (!_stricmp(name, "windowhack"))
449 <                                patch_windowhack = !_stricmp(inifile_cleanstr(value), "true");
448 >                        else if (!_stricmp(name, "clipcursor"))
449 >                                patch_clipcursor = !_stricmp(inifile_cleanstr(value), "true");
450                          else if (!_stricmp(name, "daodaninit"))
451                                  patch_daodaninit = !_stricmp(inifile_cleanstr(value), "true");
452                          else if (!_stricmp(name, "bsl"))
# Line 392 | Line 455 | bool DDrIniCallback(char* section, bool
455                                  patch_cheater = !_stricmp(inifile_cleanstr(value), "true");
456                          else if (!_stricmp(name, "newweap"))
457                                  patch_newweapon = !_stricmp(inifile_cleanstr(value), "true");
458 +                        else if (!_stricmp(name, "optionsvisible"))
459 +                                patch_optionsvisible = !_stricmp(inifile_cleanstr(value), "true");
460 +                        else if (!_stricmp(name, "binkplay"))
461 +                                patch_binkplay = !_stricmp(inifile_cleanstr(value), "true");
462                          else
463 <                                DDrStartupMessage("unrecognised patch \"%s\"", name);
463 >                                DDrStartupMessage("Daodan: Unrecognised ini patch \"%s\"", name);
464                          break;
465                  case s_language:
466                          if (!_stricmp(name, "chinese"))
# Line 503 | Line 570 | bool DDrIniCallback(char* section, bool
570                          else if (!_stricmp(name, "carousel_off"))
571                                  DDr_CheatTable[21].message_off = _strdup(value);
572                          else
573 <                                DDrStartupMessage("unrecognised language item \"%s\"", name);
573 >                                DDrStartupMessage("Daodan: Unrecognised ini language item \"%s\"", name);
574                          break;
575                  case s_bsl:
576                  default:
# Line 519 | Line 586 | void DDrConfig()
586          if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
587          {
588                  FILE* fp;
589 <                DDrStartupMessage("daodan.ini doesn't exist, creating");
589 >                DDrStartupMessage("Daodan: daodan.ini doesn't exist, creating");
590                  fp = fopen("daodan.ini", "w");
591                  if (fp)
592                  {
# Line 528 | Line 595 | void DDrConfig()
595                  }
596          }
597          
598 <        DDrStartupMessage("parsing daodan.ini...");
598 >        DDrStartupMessage("Daodan: Parsing daodan.ini...");
599          if (!inifile_read("daodan.ini", DDrIniCallback))
600 <                DDrStartupMessage("error reading daodan.ini, check your syntax!");
601 <        DDrStartupMessage("finished parsing");
600 >                DDrStartupMessage("Daodan: Error reading daodan.ini, check your syntax!");
601 >        DDrStartupMessage("Daodan: Finished parsing");
602   }
603  
604   void ONICALL DDrGame_Init()
605   {
606          if (opt_usedaodanbsl)
607 <                SLrDaodan_Initalize();
607 >                SLrDaodan_Initialize();
608   }
609  
610   void DDrException() {
# Line 586 | Line 653 | void __cdecl DDrMain(int argc, char* arg
653          char* option;
654          bool falseoption;
655  
656 <        DDrStartupMessage("daodan attached!");
656 >        DDrStartupMessage("Daodan: Daodan attached!");
657          
658 +        // Tell Oni to not load non levelX_final-files by default:
659          opt_ignore_private_data = false;
660 +
661 +        // Enable sound by default:
662          opt_sound = true;
663          
664          DDrConfig();
665 <        DDrStartupMessage("parsing command line...");
665 >        DDrStartupMessage("Daodan: Parsing command line...");
666          for (i = 1; i < argc; i ++)
667          {
668                  if (argv[i][0] == '-')
# Line 620 | Line 690 | void __cdecl DDrMain(int argc, char* arg
690                  }
691                  else
692                  {
693 <                        DDrStartupMessage("parse error \"%s\"", argv[i]);
693 >                        DDrStartupMessage("Daodan: Parse error \"%s\"", argv[i]);
694                          break;
695                  }
696          }
697 <        DDrStartupMessage("finished parsing");
697 >        DDrStartupMessage("Daodan: Finished parsing");
698          DDrPatch_Init();
699          
700          // Safe startup message printer
# Line 633 | Line 703 | void __cdecl DDrMain(int argc, char* arg
703          
704          // Daodan device mode enumeration function
705          if (patch_daodandisplayenum)
706 <                DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)daodan_enumerate_valid_display_modes);
706 >                DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
707          
708          // Performance patch
709          if (patch_usegettickcount)
# Line 647 | Line 717 | void __cdecl DDrMain(int argc, char* arg
717          if (patch_cheatsenabled)
718                  DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
719  
720 <        // Windowed mode
720 >        // DaodanGL with windowed mode support.
721          if (patch_usedaodangl)
722          {
723 <                DDrPatch_NOOP((char*)(OniExe + 0x000032B7), 6);
724 <                DDrPatch_MakeCall((void*)(OniExe + 0x000032B7), (void*)LIiP_SetCursorPosHook);
725 <        
726 <                DDrPatch_NOOP((char*)(OniExe + 0x00003349), 6);
727 <                DDrPatch_MakeCall((void*)(OniExe + 0x00003349), (void*)LIiP_SetCursorPosHook);
728 <                DDrPatch_MakeJump((void*)ONrPlatform_Initialize, (void*)DDrPlatform_Initialize);
729 <                DDrPatch_MakeJump((void*)gl_platform_initialize, (void*)daodangl_platform_initialize);
730 <        }
731 <        // Hacked windowed mode (for when daodangl isn't working properly)
732 <        else if (patch_windowhack)
733 <                DDrWindowHack_Install();
723 >                // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
724 >                DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
725 >                DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect);
726 >
727 >                // UUrWindow_GetSize: GetWindowRect -> GetClientRect.
728 >                DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
729 >                DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
730 >
731 >                // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates.
732 >                DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6);
733 >                DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos);
734 >
735 >                // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates.
736 >                DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6);
737 >                DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos);
738 >
739 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
740 >                DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6);
741 >                DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos);
742 >
743 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
744 >                DDrPatch_NOOP((char*) OniExe + 0x00003349, 6);
745 >                DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos);
746 >
747 >                // Replace ONrPlatformInitialize.
748 >                DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize);
749 >
750 >                // Replace gl_platform_initialize.
751 >                DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize);
752 >
753 >                // Replace gl_platform_dispose.
754 >                DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose);
755 >        }
756 >
757 >        if (patch_clipcursor)
758 >        {
759 >                // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
760 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
761 >
762 >                // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
763 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
764 >                
765 >                // LIrTermiante: replace LIrPlatform_Terminate call with our hook.
766 >                DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
767 >        }
768 >
769          
770          if (patch_daodaninit)
771                  DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init);
# Line 679 | Line 784 | void __cdecl DDrMain(int argc, char* arg
784                  DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
785          }
786  
682        //DDrPatch_MakeJump((void*)(OniExe + 0x000378c0, (void*)DDrException);
787          DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
684        //init_daodan_gl();
788          
789 <        ONiMain(argc, argv);
789 >        ONiMain(argc, argv);
790   }
791   /*
792   void DDrWrongExe()

Diff Legend

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