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 1017 by alloc, Mon Mar 23 23:29:19 2015 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 277 | Line 280 | void DD_Patch_ShowNames()
280   }
281  
282  
283 <
283 > void DD_Patch_CharacterAwareness()
284 > {
285 >        const unsigned char patch[] =
286 >        {
287 >                0x52,                           //  0: push   edx
288 >                0xBA, 0xA0, 0x16, 0x00, 0x00,   //  1: mov    edx,0x16a0
289 >                0x89, 0xF8,                     //  6: mov    eax,edi
290 >                0xF7, 0xE2,                     //  8: mul    edx
291 >                0x89, 0xC2,                     //  a: mov    edx,eax
292 >                0xE8, 0x00, 0x00, 0x00, 0x00,   //  c: call   ONrGameState_LivingCharacterList_Get (-> OniExe + 0x000fca90)
293 >                0x8B, 0x00,                     // 11: mov    eax,[eax]
294 >                0x01, 0xD0,                     // 13: add    eax,edx
295 >                0x89, 0xC6,                     // 15: mov    esi,eax
296 >                0x5A,                           // 17: pop    edx
297 >                0x8B, 0x46, 0x04,               // 18: (ORIG) mov        eax, dword [ds:esi+0x4]
298 >                0xF6, 0xC4, 0x80                // 1b: (ORIG) test       ah, 0x80
299 >        };
300 >        void* newCode = DDrPatch_ExecutableASM((char*)(OniExe + 0x0009A609), (char*)(OniExe + 0x0009A60F), patch, sizeof(patch));
301 >        if ((int)newCode > 0) {
302 >                DDrPatch_MakeCall((char*)(newCode+0xC), (char*)(OniExe + 0x000FCA90));
303 >                DDrPatch_NOOP((char*)(OniExe + 0x0009A60E), 1);
304 >        }
305 > }
306  
307  
308  
# Line 291 | Line 316 | bool DD_Patch_Init()
316          // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the
317          // Windows key but has the possible side effect of allowing the screensaver
318          // to enable itself in-game.
319 <        if (DDrConfig_GetOptOfType("patches.alttab", C_BOOL)->value.intBoolVal)
319 >        if (DDrConfig_GetOptOfType("windows.alttab", C_BOOL)->value.intBoolVal)
320          {
321                  // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start
322                  DDrPatch_Byte((char*)UUrPlatform_Initialize, 0xC3);
# Line 299 | Line 324 | bool DD_Patch_Init()
324          }
325          
326          // Textures using ARGB8888 can be used
327 <        if (DDrConfig_GetOptOfType("patches.argb8888", C_BOOL)->value.intBoolVal)
327 >        if (DDrConfig_GetOptOfType("modding.argb8888", C_BOOL)->value.intBoolVal)
328          {
329                  // Update conversion lookups in IMgConvertPixelType_List
330                  DDrPatch_Byte((char*)(OniExe + 0x00135af0), 0x07);
# Line 310 | Line 335 | bool DD_Patch_Init()
335          // instead of DirectDraw; patch ONiRunGame to use the same method to play
336          // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
337          // latter has problems on WINE).
338 <        if (DDrConfig_GetOptOfType("patches.binkplay", C_BOOL)->value.intBoolVal)
338 >        if (DDrConfig_GetOptOfType("graphics.binkplay", C_BOOL)->value.intBoolVal)
339          {
340                  // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
341                  DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
# Line 318 | Line 343 | bool DD_Patch_Init()
343                  DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
344          }
345  
346 <        if (DDrConfig_GetOptOfType("patches.d_regen", C_BOOL)->value.intBoolVal)
346 >        if (DDrConfig_GetOptOfType("modding.d_regen", C_BOOL)->value.intBoolVal)
347                  DD_Patch_Regeneration();
348  
349 +        if (DDrConfig_GetOptOfType("gameplay.characterawareness", C_BOOL)->value.intBoolVal)
350 +                DD_Patch_CharacterAwareness();
351 +
352          // Cheats always enabled
353 <        if (DDrConfig_GetOptOfType("patches.cheatsenabled", C_BOOL)->value.intBoolVal)
353 >        if (DDrConfig_GetOptOfType("gameplay.cheatsenabled", C_BOOL)->value.intBoolVal)
354          {
355                  DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
356          }
357  
358          // Use Daodan's own cheattable
359 <        if (DDrConfig_GetOptOfType("patches.cheattable", C_BOOL)->value.intBoolVal)
359 >        if (DDrConfig_GetOptOfType("gameplay.cheattable", C_BOOL)->value.intBoolVal)
360          {
361                  // In ONrGameState_HandleCheats: Replace pointers to orig cheattable
362                  DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name);
# Line 346 | Line 374 | bool DD_Patch_Init()
374  
375                  // At end of ONrUnlockLevel to init values on level loading
376                  DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
377 +                
378 +                if (DDrConfig_GetOptOfType("gameplay.bindablecheats", C_BOOL)->value.intBoolVal)
379 +                {
380 +                        InitBindableCheats();
381 +                }
382          }
383          
384 <        if (DDrConfig_GetOptOfType("patches.chinese", C_BOOL)->value.intBoolVal)
384 >        if (DDrConfig_GetOptOfType("language.chinese", C_BOOL)->value.intBoolVal)
385                  DD_Patch_Chinese();
386  
387          // Limit cursor to Oni's window
388 <        if (DDrConfig_GetOptOfType("patches.clipcursor", C_BOOL)->value.intBoolVal)
388 >        if (DDrConfig_GetOptOfType("windows.clipcursor", C_BOOL)->value.intBoolVal)
389          {
390                  // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
391                  DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
# Line 365 | Line 398 | bool DD_Patch_Init()
398          }
399  
400          // Disables weapon cooldown exploit
401 <        if (DDrConfig_GetOptOfType("patches.cooldowntimer", C_BOOL)->value.intBoolVal)
401 >        if (DDrConfig_GetOptOfType("gameplay.cooldowntimer", C_BOOL)->value.intBoolVal)
402          {
403                  // In WPrRelease: NoOp 4 MOVs
404                  DDrPatch_NOOP((char*)(OniExe + 0x0011a825), 22);
405          }
406  
407          // Daodan device mode enumeration function
408 <        if (DDrConfig_GetOptOfType("patches.daodandisplayenum", C_BOOL)->value.intBoolVal)
408 >        if (DDrConfig_GetOptOfType("graphics.displayenum", C_BOOL)->value.intBoolVal)
409          {
410                  DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
411          }
412          
413          // Forced DirectInput (for Windows NT)
414 <        if (DDrConfig_GetOptOfType("patches.directinput", C_BOOL)->value.intBoolVal)
414 >        if (DDrConfig_GetOptOfType("windows.directinput", C_BOOL)->value.intBoolVal)
415          {
416                  // LIrPlatform_Initialize: replace conditional jump by unconditional
417                  DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb);
418          }
419  
420          // Disable Oni's command line parser so it doesn't interfere with ours
421 <        if (DDrConfig_GetOptOfType("patches.disablecmdline", C_BOOL)->value.intBoolVal)
421 >        if (DDrConfig_GetOptOfType("windows.disablecmdline", C_BOOL)->value.intBoolVal)
422          {
423                  // Replace start of OniParseCommandLine with XOR eax,eax; RET
424                  DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033);
# Line 394 | Line 427 | bool DD_Patch_Init()
427          }
428  
429          // Font texture cache doubled
430 <        if (DDrConfig_GetOptOfType("patches.fonttexturecache", C_BOOL)->value.intBoolVal)
430 >        if (DDrConfig_GetOptOfType("language.fonttexturecache", C_BOOL)->value.intBoolVal)
431          {
432                  // Double two values in TMrGame_Initialize
433                  DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20);
# Line 402 | Line 435 | bool DD_Patch_Init()
435          }
436  
437          // Allow HD screens on resolutions < 1024*768
438 <        if (DDrConfig_GetOptOfType("patches.hdscreens_lowres", C_BOOL)->value.intBoolVal)
438 >        if (DDrConfig_GetOptOfType("modding.hdscreens_lowres", C_BOOL)->value.intBoolVal)
439          {
440                  DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap);
441          }
442  
443          // Allow for console to show on higher resolutions
444 <        if (DDrConfig_GetOptOfType("patches.highres_console", C_BOOL)->value.intBoolVal)
444 >        if (DDrConfig_GetOptOfType("devmode.highres_console", C_BOOL)->value.intBoolVal)
445          {
446                  Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize);
447          }
448          
449 +        // Allow custom actions to be bound through Daodan
450 +        if (DDrConfig_GetOptOfType("gameplay.customactions", C_BOOL)->value.intBoolVal)
451 +        {
452 +                Input_PatchCode ();
453 +        }
454 +        
455          // Hackish fix for Konoko not kicking guns
456          // Don't use this, it breaks stairs.
457 <        if (DDrConfig_GetOptOfType("patches.kickguns", C_BOOL)->value.intBoolVal)
457 >        if (DDrConfig_GetOptOfType("gameplay.kickguns", C_BOOL)->value.intBoolVal)
458          {
459                  // In ONrCharacter_EnablePhysics: Load different values to same addresses as before
460                  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 462 | bool DD_Patch_Init()
462          }
463          
464          // Disable loading the vtuneapi.dll
465 <        if (DDrConfig_GetOptOfType("patches.killvtune", C_BOOL)->value.intBoolVal)
465 >        if (DDrConfig_GetOptOfType("windows.killvtune", C_BOOL)->value.intBoolVal)
466          {
467                  // Instantly return from UUrLoadVtuneAPI
468                  DDrPatch_Byte((char*)(OniExe + 0x00026340), 0xC3);
469          }
470  
471          // Now supports textures up to 512x512
472 <        if (DDrConfig_GetOptOfType("patches.largetextures", C_BOOL)->value.intBoolVal)
472 >        if (DDrConfig_GetOptOfType("modding.largetextures", C_BOOL)->value.intBoolVal)
473          {
474                  DDrPatch_Byte((char*)(OniExe + 0x00005251), 0x10);
475          }
476          
477          // Non-"_Final" levels are now valid
478 <        if (DDrConfig_GetOptOfType("patches.levelplugins", C_BOOL)->value.intBoolVal)
478 >        if (DDrConfig_GetOptOfType("modding.levelplugins", C_BOOL)->value.intBoolVal)
479          {
480                  // Patch in TMrUtility_LevelInfo_Get:
481                  DDrPatch_Byte((char*)(OniExe + 0x000206a8), 0x01);
482          }
483  
484          // Weapon on ground shown with name and magazine contents
485 <        if (DDrConfig_GetOptOfType("patches.newweap", C_BOOL)->value.intBoolVal)
485 >        if (DDrConfig_GetOptOfType("graphics.newweap", C_BOOL)->value.intBoolVal)
486          {
487                  //Makes it always say "Received weapon_name."
488                  //Needs check for loc_4DFC66
# Line 463 | Line 502 | bool DD_Patch_Init()
502          }
503  
504          // Disable Multi-byte character awareness patch (multiple language support)
505 <        if (DDrConfig_GetOptOfType("patches.nomultibyte", C_BOOL)->value.intBoolVal)
505 >        if (DDrConfig_GetOptOfType("language.nomultibyte", C_BOOL)->value.intBoolVal)
506          {
507                  // TSiContext_DrawLine: Replace conditional jumps by unconditional ones
508                  DDrPatch_Byte  ((char*)(OniExe + 0x0002d8f8), 0xeb);
# Line 488 | Line 527 | bool DD_Patch_Init()
527          }
528  
529          // Fix options not visible in main menu when a game was started
530 <        if (DDrConfig_GetOptOfType("patches.optionsvisible", C_BOOL)->value.intBoolVal)
530 >        if (DDrConfig_GetOptOfType("graphics.optionsvisible", C_BOOL)->value.intBoolVal)
531          {
532                  // replace WMrWindow_SetVisible calls
533                  DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
# Line 496 | Line 535 | bool DD_Patch_Init()
535          }
536  
537          // Pathfinding grid cache size x8
538 <        if (DDrConfig_GetOptOfType("patches.pathfinding", C_BOOL)->value.intBoolVal)
538 >        if (DDrConfig_GetOptOfType("gameplay.pathfinding", C_BOOL)->value.intBoolVal)
539          {
540                  // Replaces conditional jump (je) with unconditional jump
541                  const unsigned char pathfinding[2] = {0x90 , 0xE9 };
# Line 508 | Line 547 | bool DD_Patch_Init()
547          }
548  
549          // Projectile awareness fixed
550 <        if (DDrConfig_GetOptOfType("patches.projaware", C_BOOL)->value.intBoolVal)
550 >        if (DDrConfig_GetOptOfType("gameplay.projaware", C_BOOL)->value.intBoolVal)
551          {
552                  DDrPatch_Byte  ((char*)(OniExe + 0x0009c07c), 0x6c);
553                  DDrPatch_Byte  ((char*)(OniExe + 0x0009c080), 0x70);
# Line 517 | Line 556 | bool DD_Patch_Init()
556          }
557  
558          // Safe startup message printer
559 <        if (DDrConfig_GetOptOfType("patches.safeprintf", C_BOOL)->value.intBoolVal)
559 >        if (DDrConfig_GetOptOfType("windows.safeprintf", C_BOOL)->value.intBoolVal)
560          {
561                  DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
562          }
563  
564          // Show all (also enemies') lasersights
565 <        if (DDrConfig_GetOptOfType("patches.showalllasersights", C_BOOL)->value.intBoolVal)
565 >        if (DDrConfig_GetOptOfType("graphics.showalllasersights", C_BOOL)->value.intBoolVal)
566          {
567                  DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 );
568          }
569  
570          // Allow bsl-var show_triggervolumes or ctrl+shift+x (devmode) to work
571 <        if (DDrConfig_GetOptOfType("patches.showtriggervolumes", C_BOOL)->value.intBoolVal)
571 >        if (DDrConfig_GetOptOfType("devmode.showtriggervolumes", C_BOOL)->value.intBoolVal)
572          {
573                  Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register);
574                  Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput);
575          }
576          
577          // Experiment with allowing enemies to be thrown over railings
578 <        if (DDrConfig_GetOptOfType("patches.throwtest", C_BOOL)->value.intBoolVal)
578 >        if (DDrConfig_GetOptOfType("gameplay.throwtest", C_BOOL)->value.intBoolVal)
579          {
580                  DDrPatch_NOOP((char*)(OniExe + 0x000dc190), 10);
581          }
582  
583          // DaodanGL with windowed mode support
584 <        if (DDrConfig_GetOptOfType("patches.usedaodangl", C_BOOL)->value.intBoolVal)
584 >        if (DDrConfig_GetOptOfType("graphics.daodangl", C_BOOL)->value.intBoolVal)
585          {
586                  // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
587                  DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
# 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)