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

Comparing Daodan/src/Patches/Patches.c (file contents):
Revision 995 by alloc, Wed Apr 9 00:10:18 2014 UTC vs.
Revision 1163 by rossy, Sun Oct 24 02:50:48 2021 UTC

# Line 5 | Line 5
5   #include "Cheater.h"
6   #include "../Daodan_Config.h"
7   #include "GL.h"
8 + #include "Input.h"
9   #include "../Daodan_Patch.h"
10   #include "Utility.h"
11   #include "Win32.h"
# Line 17 | Line 18 | typedef int (__cdecl *CHINESEPROC)(DWORD
18   // slider in windowed mode.
19   static void ONICALL DD_ONiOGU_GammaSlider_SetRange(void* window, int min_value, int max_value)
20   {
21 <        ConfigOption_t* co = DDrConfig_GetOptOfType("options.gamma", C_BOOL);
21 >        ConfigOption_t* co = DDrConfig_GetOptOfType("graphics.gamma", C_BOOL);
22          WMrWindow_SetEnabled(window, M3gResolutionSwitch && co->value.intBoolVal);
23          WMrSlider_SetRange(window, min_value, max_value);
24   }
# Line 84 | Line 85 | void ONICALL DDrShowOptionsButton(void*
85  
86   void ONICALL DDrGame_Init()
87   {
88 <        if (DDrConfig_GetOptOfType("patches.usedaodanbsl", C_BOOL)->value.intBoolVal)
88 >        if (DDrConfig_GetOptOfType("modding.daodanbsl", C_BOOL)->value.intBoolVal)
89                  SLrDaodan_Initialize();
90   }
91  
# Line 131 | Line 132 | int16_t ONICALL DD_COrTextArea_Resize(vo
132          return Oni_COrTextArea_Resize(inTextArea, inBounds, inNumTextEntries);
133   }
134  
135 +
136 +
137   #define IMcShade_Red (0xFFFF0000)
138   #define IMcShade_Green (0xFF00FF00)
139   #define IMcShade_Blue (0xFF0000FF)
# Line 180 | Line 183 | int16_t ONICALL DD_ONrMechanics_Register
183          return Oni_ONrMechanics_Register(inObjectType, inObjectTypeIndex, inGroupName, inSizeInMemory, inObjectMethods, inFlags, inMechanicsMethods);
184   }
185  
183 _ONrGameState_HandleUtilityInput Oni_ONrGameState_HandleUtilityInput = (_ONrGameState_HandleUtilityInput)0;
184 void ONICALL DD_ONrGameState_HandleUtilityInput(const void* inInput)
185 {
186        Oni_ONrGameState_HandleUtilityInput(inInput);
187        
188        if (ONrDebugKey_WentDown(7)) {
189                OBJgTriggerVolume_Visible = !OBJgTriggerVolume_Visible;
190        }
191 }
192
193
186   // Enables d_regen script command. Instead of one global flag to only regenerate player each char has a flag to enable local regeneration
187   void DD_Patch_Regeneration()
188   {
# Line 277 | Line 269 | void DD_Patch_ShowNames()
269   }
270  
271  
272 <
272 > void DD_Patch_CharacterAwareness()
273 > {
274 >        const unsigned char patch[] =
275 >        {
276 >                0x52,                           //  0: push   edx
277 >                0xBA, 0xA0, 0x16, 0x00, 0x00,   //  1: mov    edx,0x16a0
278 >                0x89, 0xF8,                     //  6: mov    eax,edi
279 >                0xF7, 0xE2,                     //  8: mul    edx
280 >                0x89, 0xC2,                     //  a: mov    edx,eax
281 >                0xE8, 0x00, 0x00, 0x00, 0x00,   //  c: call   ONrGameState_LivingCharacterList_Get (-> OniExe + 0x000fca90)
282 >                0x8B, 0x00,                     // 11: mov    eax,[eax]
283 >                0x01, 0xD0,                     // 13: add    eax,edx
284 >                0x89, 0xC6,                     // 15: mov    esi,eax
285 >                0x5A,                           // 17: pop    edx
286 >                0x8B, 0x46, 0x04,               // 18: (ORIG) mov        eax, dword [ds:esi+0x4]
287 >                0xF6, 0xC4, 0x80                // 1b: (ORIG) test       ah, 0x80
288 >        };
289 >        void* newCode = DDrPatch_ExecutableASM((char*)(OniExe + 0x0009A609), (char*)(OniExe + 0x0009A60F), patch, sizeof(patch));
290 >        if ((int)newCode > 0) {
291 >                DDrPatch_MakeCall((char*)(newCode+0xC), (char*)(OniExe + 0x000FCA90));
292 >                DDrPatch_NOOP((char*)(OniExe + 0x0009A60E), 1);
293 >        }
294 > }
295  
296  
297  
# Line 291 | Line 305 | bool DD_Patch_Init()
305          // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the
306          // Windows key but has the possible side effect of allowing the screensaver
307          // to enable itself in-game.
308 <        if (DDrConfig_GetOptOfType("patches.alttab", C_BOOL)->value.intBoolVal)
308 >        if (DDrConfig_GetOptOfType("windows.alttab", C_BOOL)->value.intBoolVal)
309          {
310                  // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start
311                  DDrPatch_Byte((char*)UUrPlatform_Initialize, 0xC3);
# Line 299 | Line 313 | bool DD_Patch_Init()
313          }
314          
315          // Textures using ARGB8888 can be used
316 <        if (DDrConfig_GetOptOfType("patches.argb8888", C_BOOL)->value.intBoolVal)
316 >        if (DDrConfig_GetOptOfType("modding.argb8888", C_BOOL)->value.intBoolVal)
317          {
318                  // Update conversion lookups in IMgConvertPixelType_List
319                  DDrPatch_Byte((char*)(OniExe + 0x00135af0), 0x07);
# Line 310 | Line 324 | bool DD_Patch_Init()
324          // instead of DirectDraw; patch ONiRunGame to use the same method to play
325          // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
326          // latter has problems on WINE).
327 <        if (DDrConfig_GetOptOfType("patches.binkplay", C_BOOL)->value.intBoolVal)
327 >        if (DDrConfig_GetOptOfType("graphics.binkplay", C_BOOL)->value.intBoolVal)
328          {
329                  // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
330                  DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
# Line 318 | Line 332 | bool DD_Patch_Init()
332                  DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
333          }
334  
335 <        if (DDrConfig_GetOptOfType("patches.d_regen", C_BOOL)->value.intBoolVal)
335 >        if (DDrConfig_GetOptOfType("modding.d_regen", C_BOOL)->value.intBoolVal)
336                  DD_Patch_Regeneration();
337  
338 +        if (DDrConfig_GetOptOfType("gameplay.characterawareness", C_BOOL)->value.intBoolVal)
339 +                DD_Patch_CharacterAwareness();
340 +
341          // Cheats always enabled
342 <        if (DDrConfig_GetOptOfType("patches.cheatsenabled", C_BOOL)->value.intBoolVal)
342 >        if (DDrConfig_GetOptOfType("gameplay.cheatsenabled", C_BOOL)->value.intBoolVal)
343          {
344                  DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
345          }
346  
347          // Use Daodan's own cheattable
348 <        if (DDrConfig_GetOptOfType("patches.cheattable", C_BOOL)->value.intBoolVal)
348 >        if (DDrConfig_GetOptOfType("gameplay.cheattable", C_BOOL)->value.intBoolVal)
349          {
350                  // In ONrGameState_HandleCheats: Replace pointers to orig cheattable
351                  DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name);
# Line 346 | Line 363 | bool DD_Patch_Init()
363  
364                  // At end of ONrUnlockLevel to init values on level loading
365                  DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
366 +                
367 +                if (DDrConfig_GetOptOfType("gameplay.bindablecheats", C_BOOL)->value.intBoolVal)
368 +                {
369 +                        InitBindableCheats();
370 +                }
371          }
372          
373 <        if (DDrConfig_GetOptOfType("patches.chinese", C_BOOL)->value.intBoolVal)
373 >        if (DDrConfig_GetOptOfType("language.chinese", C_BOOL)->value.intBoolVal)
374                  DD_Patch_Chinese();
375  
354        // Limit cursor to Oni's window
355        if (DDrConfig_GetOptOfType("patches.clipcursor", C_BOOL)->value.intBoolVal)
356        {
357                // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
358                DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
359
360                // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
361                DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
362        
363                // LIrTerminate: replace LIrPlatform_Terminate call with our hook.
364                DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
365        }
366
376          // Disables weapon cooldown exploit
377 <        if (DDrConfig_GetOptOfType("patches.cooldowntimer", C_BOOL)->value.intBoolVal)
377 >        if (DDrConfig_GetOptOfType("gameplay.cooldowntimer", C_BOOL)->value.intBoolVal)
378          {
379                  // In WPrRelease: NoOp 4 MOVs
380                  DDrPatch_NOOP((char*)(OniExe + 0x0011a825), 22);
381          }
382  
383          // Daodan device mode enumeration function
384 <        if (DDrConfig_GetOptOfType("patches.daodandisplayenum", C_BOOL)->value.intBoolVal)
384 >        if (DDrConfig_GetOptOfType("graphics.displayenum", C_BOOL)->value.intBoolVal)
385          {
386                  DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
387          }
388 <        
389 <        // Forced DirectInput (for Windows NT)
381 <        if (DDrConfig_GetOptOfType("patches.directinput", C_BOOL)->value.intBoolVal)
388 >
389 >        if (DDrConfig_GetOptOfType("windows.daodaninput", C_BOOL)->value.intBoolVal)
390          {
391 <                // LIrPlatform_Initialize: replace conditional jump by unconditional
392 <                DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb);
391 >                DDrInput_PatchDaodanInput();
392 >        }
393 >        else
394 >        {
395 >                // The following patches aren't compatible with, or are superseded by
396 >                // Daodan input
397 >
398 >                // Limit cursor to Oni's window
399 >                if (DDrConfig_GetOptOfType("windows.clipcursor", C_BOOL)->value.intBoolVal)
400 >                {
401 >                        // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
402 >                        DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
403 >
404 >                        // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
405 >                        DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
406 >
407 >                        // LIrTerminate: replace LIrPlatform_Terminate call with our hook.
408 >                        DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
409 >                }
410 >
411 >                // Forced DirectInput (for Windows NT)
412 >                if (DDrConfig_GetOptOfType("windows.directinput", C_BOOL)->value.intBoolVal)
413 >                {
414 >                        // LIrPlatform_Initialize: replace conditional jump by unconditional
415 >                        DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb);
416 >                }
417          }
418  
419          // Disable Oni's command line parser so it doesn't interfere with ours
420 <        if (DDrConfig_GetOptOfType("patches.disablecmdline", C_BOOL)->value.intBoolVal)
420 >        if (DDrConfig_GetOptOfType("windows.disablecmdline", C_BOOL)->value.intBoolVal)
421          {
422                  // Replace start of OniParseCommandLine with XOR eax,eax; RET
423                  DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033);
# Line 394 | Line 426 | bool DD_Patch_Init()
426          }
427  
428          // Font texture cache doubled
429 <        if (DDrConfig_GetOptOfType("patches.fonttexturecache", C_BOOL)->value.intBoolVal)
429 >        if (DDrConfig_GetOptOfType("language.fonttexturecache", C_BOOL)->value.intBoolVal)
430          {
431                  // Double two values in TMrGame_Initialize
432                  DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20);
# Line 402 | Line 434 | bool DD_Patch_Init()
434          }
435  
436          // Allow HD screens on resolutions < 1024*768
437 <        if (DDrConfig_GetOptOfType("patches.hdscreens_lowres", C_BOOL)->value.intBoolVal)
437 >        if (DDrConfig_GetOptOfType("modding.hdscreens_lowres", C_BOOL)->value.intBoolVal)
438          {
439                  DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap);
440          }
441  
442          // Allow for console to show on higher resolutions
443 <        if (DDrConfig_GetOptOfType("patches.highres_console", C_BOOL)->value.intBoolVal)
443 >        if (DDrConfig_GetOptOfType("devmode.highres_console", C_BOOL)->value.intBoolVal)
444          {
445                  Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize);
446          }
447          
448 +        // Allow custom actions to be bound through Daodan
449 +        if (DDrConfig_GetOptOfType("gameplay.customactions", C_BOOL)->value.intBoolVal)
450 +                DDrInput_PatchCustomActions();
451 +
452          // Hackish fix for Konoko not kicking guns
453          // Don't use this, it breaks stairs.
454 <        if (DDrConfig_GetOptOfType("patches.kickguns", C_BOOL)->value.intBoolVal)
454 >        if (DDrConfig_GetOptOfType("gameplay.kickguns", C_BOOL)->value.intBoolVal)
455          {
456                  // In ONrCharacter_EnablePhysics: Load different values to same addresses as before
457                  const unsigned char kickgun_patch[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0xC7, 0x05, 0x1C, 0xC9, 0x5E, 0x00, 0x70, 0xB8, 0x43, 0x00, 0xC7, 0x05, 0x20, 0xC9, 0x5E, 0x00, 0x20, 0xBE, 0x43 };
# Line 423 | Line 459 | bool DD_Patch_Init()
459          }
460          
461          // Disable loading the vtuneapi.dll
462 <        if (DDrConfig_GetOptOfType("patches.killvtune", C_BOOL)->value.intBoolVal)
462 >        if (DDrConfig_GetOptOfType("windows.killvtune", C_BOOL)->value.intBoolVal)
463          {
464                  // Instantly return from UUrLoadVtuneAPI
465                  DDrPatch_Byte((char*)(OniExe + 0x00026340), 0xC3);
466          }
467  
468          // Now supports textures up to 512x512
469 <        if (DDrConfig_GetOptOfType("patches.largetextures", C_BOOL)->value.intBoolVal)
469 >        if (DDrConfig_GetOptOfType("modding.largetextures", C_BOOL)->value.intBoolVal)
470          {
471                  DDrPatch_Byte((char*)(OniExe + 0x00005251), 0x10);
472          }
473          
474          // Non-"_Final" levels are now valid
475 <        if (DDrConfig_GetOptOfType("patches.levelplugins", C_BOOL)->value.intBoolVal)
475 >        if (DDrConfig_GetOptOfType("modding.levelplugins", C_BOOL)->value.intBoolVal)
476          {
477                  // Patch in TMrUtility_LevelInfo_Get:
478                  DDrPatch_Byte((char*)(OniExe + 0x000206a8), 0x01);
479          }
480  
481          // Weapon on ground shown with name and magazine contents
482 <        if (DDrConfig_GetOptOfType("patches.newweap", C_BOOL)->value.intBoolVal)
482 >        if (DDrConfig_GetOptOfType("graphics.newweap", C_BOOL)->value.intBoolVal)
483          {
484                  //Makes it always say "Received weapon_name."
485                  //Needs check for loc_4DFC66
# Line 463 | Line 499 | bool DD_Patch_Init()
499          }
500  
501          // Disable Multi-byte character awareness patch (multiple language support)
502 <        if (DDrConfig_GetOptOfType("patches.nomultibyte", C_BOOL)->value.intBoolVal)
502 >        if (DDrConfig_GetOptOfType("language.nomultibyte", C_BOOL)->value.intBoolVal)
503          {
504                  // TSiContext_DrawLine: Replace conditional jumps by unconditional ones
505                  DDrPatch_Byte  ((char*)(OniExe + 0x0002d8f8), 0xeb);
# Line 488 | Line 524 | bool DD_Patch_Init()
524          }
525  
526          // Fix options not visible in main menu when a game was started
527 <        if (DDrConfig_GetOptOfType("patches.optionsvisible", C_BOOL)->value.intBoolVal)
527 >        if (DDrConfig_GetOptOfType("graphics.optionsvisible", C_BOOL)->value.intBoolVal)
528          {
529                  // replace WMrWindow_SetVisible calls
530                  DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
# Line 496 | Line 532 | bool DD_Patch_Init()
532          }
533  
534          // Pathfinding grid cache size x8
535 <        if (DDrConfig_GetOptOfType("patches.pathfinding", C_BOOL)->value.intBoolVal)
535 >        if (DDrConfig_GetOptOfType("gameplay.pathfinding", C_BOOL)->value.intBoolVal)
536          {
537                  // Replaces conditional jump (je) with unconditional jump
538                  const unsigned char pathfinding[2] = {0x90 , 0xE9 };
# Line 508 | Line 544 | bool DD_Patch_Init()
544          }
545  
546          // Projectile awareness fixed
547 <        if (DDrConfig_GetOptOfType("patches.projaware", C_BOOL)->value.intBoolVal)
547 >        if (DDrConfig_GetOptOfType("gameplay.projaware", C_BOOL)->value.intBoolVal)
548          {
549                  DDrPatch_Byte  ((char*)(OniExe + 0x0009c07c), 0x6c);
550                  DDrPatch_Byte  ((char*)(OniExe + 0x0009c080), 0x70);
# Line 517 | Line 553 | bool DD_Patch_Init()
553          }
554  
555          // Safe startup message printer
556 <        if (DDrConfig_GetOptOfType("patches.safeprintf", C_BOOL)->value.intBoolVal)
556 >        if (DDrConfig_GetOptOfType("windows.safeprintf", C_BOOL)->value.intBoolVal)
557          {
558                  DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
559          }
560  
561          // Show all (also enemies') lasersights
562 <        if (DDrConfig_GetOptOfType("patches.showalllasersights", C_BOOL)->value.intBoolVal)
562 >        if (DDrConfig_GetOptOfType("graphics.showalllasersights", C_BOOL)->value.intBoolVal)
563          {
564                  DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 );
565          }
566  
567          // Allow bsl-var show_triggervolumes or ctrl+shift+x (devmode) to work
568 <        if (DDrConfig_GetOptOfType("patches.showtriggervolumes", C_BOOL)->value.intBoolVal)
568 >        if (DDrConfig_GetOptOfType("devmode.showtriggervolumes", C_BOOL)->value.intBoolVal)
569          {
570 +                DDrInput_PatchUtilityInput();
571                  Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register);
535                Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput);
572          }
573 <        
573 >
574          // Experiment with allowing enemies to be thrown over railings
575 <        if (DDrConfig_GetOptOfType("patches.throwtest", C_BOOL)->value.intBoolVal)
575 >        if (DDrConfig_GetOptOfType("gameplay.throwtest", C_BOOL)->value.intBoolVal)
576          {
577                  DDrPatch_NOOP((char*)(OniExe + 0x000dc190), 10);
578          }
579  
580          // DaodanGL with windowed mode support
581 <        if (DDrConfig_GetOptOfType("patches.usedaodangl", C_BOOL)->value.intBoolVal)
581 >        if (DDrConfig_GetOptOfType("graphics.daodangl", C_BOOL)->value.intBoolVal)
582          {
583                  // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
584                  DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
# Line 552 | Line 588 | bool DD_Patch_Init()
588                  DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
589                  DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
590  
591 +                // Note: Daodan input makes the following GetCursorPos and SetCursorPos
592 +                // patches unnecessary
593 +
594                  // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates.
595                  DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6);
596                  DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos);
# Line 579 | Line 618 | bool DD_Patch_Init()
618          }
619  
620          // Performance patch
621 <        if (DDrConfig_GetOptOfType("patches.usegettickcount", C_BOOL)->value.intBoolVal)
621 >        if (DDrConfig_GetOptOfType("windows.usegettickcount", C_BOOL)->value.intBoolVal)
622          {
623                  DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High);
624                  DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency);
# Line 587 | Line 626 | bool DD_Patch_Init()
626          }
627  
628          // Fix displaying the talking portraits in widescreen modes
629 <        if (DDrConfig_GetOptOfType("patches.widescreenportraits", C_BOOL)->value.intBoolVal)
629 >        if (DDrConfig_GetOptOfType("graphics.widescreenportraits", C_BOOL)->value.intBoolVal)
630          {
631                  SLrDaodan_Patch();
632          }
633          
634          // Adds working function for existing BSL command wp_fadetime, sets fade time to 4800
635 <        if (DDrConfig_GetOptOfType("patches.wpfadetime", C_BOOL)->value.intBoolVal)
635 >        if (DDrConfig_GetOptOfType("gameplay.wpfadetime", C_BOOL)->value.intBoolVal)
636          {
637                  // Makes wp_fadetime actually have a function (changes within WPrRelease)
638                  // Patches end of function to instead of use a constant value for fadetime (12c0 = 4800) actually use value of wp_fadetime:

Diff Legend

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