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 1008 by alloc, Mon Aug 25 23:21:09 2014 UTC

# Line 17 | Line 17 | typedef int (__cdecl *CHINESEPROC)(DWORD
17   // slider in windowed mode.
18   static void ONICALL DD_ONiOGU_GammaSlider_SetRange(void* window, int min_value, int max_value)
19   {
20 <        ConfigOption_t* co = DDrConfig_GetOptOfType("options.gamma", C_BOOL);
20 >        ConfigOption_t* co = DDrConfig_GetOptOfType("graphics.gamma", C_BOOL);
21          WMrWindow_SetEnabled(window, M3gResolutionSwitch && co->value.intBoolVal);
22          WMrSlider_SetRange(window, min_value, max_value);
23   }
# Line 84 | Line 84 | void ONICALL DDrShowOptionsButton(void*
84  
85   void ONICALL DDrGame_Init()
86   {
87 <        if (DDrConfig_GetOptOfType("patches.usedaodanbsl", C_BOOL)->value.intBoolVal)
87 >        if (DDrConfig_GetOptOfType("modding.daodanbsl", C_BOOL)->value.intBoolVal)
88                  SLrDaodan_Initialize();
89   }
90  
# Line 277 | Line 277 | void DD_Patch_ShowNames()
277   }
278  
279  
280 <
280 > void DD_Patch_CharacterAwareness()
281 > {
282 >        const unsigned char patch[] =
283 >        {
284 >                0x52,                           //  0: push   edx
285 >                0xBA, 0xA0, 0x16, 0x00, 0x00,   //  1: mov    edx,0x16a0
286 >                0x89, 0xF8,                     //  6: mov    eax,edi
287 >                0xF7, 0xE2,                     //  8: mul    edx
288 >                0x89, 0xC2,                     //  a: mov    edx,eax
289 >                0xE8, 0x00, 0x00, 0x00, 0x00,   //  c: call   ONrGameState_LivingCharacterList_Get (-> OniExe + 0x000fca90)
290 >                0x8B, 0x00,                     // 11: mov    eax,[eax]
291 >                0x01, 0xD0,                     // 13: add    eax,edx
292 >                0x89, 0xC6,                     // 15: mov    esi,eax
293 >                0x5A,                           // 17: pop    edx
294 >                0x8B, 0x46, 0x04,               // 18: (ORIG) mov        eax, dword [ds:esi+0x4]
295 >                0xF6, 0xC4, 0x80                // 1b: (ORIG) test       ah, 0x80
296 >        };
297 >        void* newCode = DDrPatch_ExecutableASM((char*)(OniExe + 0x0009A609), (char*)(OniExe + 0x0009A60F), patch, sizeof(patch));
298 >        if ((int)newCode > 0) {
299 >                DDrPatch_MakeCall((char*)(newCode+0xC), (char*)(OniExe + 0x000FCA90));
300 >                DDrPatch_NOOP((char*)(OniExe + 0x0009A60E), 1);
301 >        }
302 > }
303  
304  
305  
# Line 291 | Line 313 | bool DD_Patch_Init()
313          // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the
314          // Windows key but has the possible side effect of allowing the screensaver
315          // to enable itself in-game.
316 <        if (DDrConfig_GetOptOfType("patches.alttab", C_BOOL)->value.intBoolVal)
316 >        if (DDrConfig_GetOptOfType("windows.alttab", C_BOOL)->value.intBoolVal)
317          {
318                  // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start
319                  DDrPatch_Byte((char*)UUrPlatform_Initialize, 0xC3);
# Line 299 | Line 321 | bool DD_Patch_Init()
321          }
322          
323          // Textures using ARGB8888 can be used
324 <        if (DDrConfig_GetOptOfType("patches.argb8888", C_BOOL)->value.intBoolVal)
324 >        if (DDrConfig_GetOptOfType("modding.argb8888", C_BOOL)->value.intBoolVal)
325          {
326                  // Update conversion lookups in IMgConvertPixelType_List
327                  DDrPatch_Byte((char*)(OniExe + 0x00135af0), 0x07);
# Line 310 | Line 332 | bool DD_Patch_Init()
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 (DDrConfig_GetOptOfType("patches.binkplay", C_BOOL)->value.intBoolVal)
335 >        if (DDrConfig_GetOptOfType("graphics.binkplay", C_BOOL)->value.intBoolVal)
336          {
337                  // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
338                  DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
# Line 318 | Line 340 | bool DD_Patch_Init()
340                  DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
341          }
342  
343 <        if (DDrConfig_GetOptOfType("patches.d_regen", C_BOOL)->value.intBoolVal)
343 >        if (DDrConfig_GetOptOfType("modding.d_regen", C_BOOL)->value.intBoolVal)
344                  DD_Patch_Regeneration();
345  
346 +        if (DDrConfig_GetOptOfType("gameplay.characterawareness", C_BOOL)->value.intBoolVal)
347 +                DD_Patch_CharacterAwareness();
348 +
349          // Cheats always enabled
350 <        if (DDrConfig_GetOptOfType("patches.cheatsenabled", C_BOOL)->value.intBoolVal)
350 >        if (DDrConfig_GetOptOfType("gameplay.cheatsenabled", C_BOOL)->value.intBoolVal)
351          {
352                  DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
353          }
354  
355          // Use Daodan's own cheattable
356 <        if (DDrConfig_GetOptOfType("patches.cheattable", C_BOOL)->value.intBoolVal)
356 >        if (DDrConfig_GetOptOfType("gameplay.cheattable", C_BOOL)->value.intBoolVal)
357          {
358                  // In ONrGameState_HandleCheats: Replace pointers to orig cheattable
359                  DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name);
# Line 348 | Line 373 | bool DD_Patch_Init()
373                  DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
374          }
375          
376 <        if (DDrConfig_GetOptOfType("patches.chinese", C_BOOL)->value.intBoolVal)
376 >        if (DDrConfig_GetOptOfType("language.chinese", C_BOOL)->value.intBoolVal)
377                  DD_Patch_Chinese();
378  
379          // Limit cursor to Oni's window
380 <        if (DDrConfig_GetOptOfType("patches.clipcursor", C_BOOL)->value.intBoolVal)
380 >        if (DDrConfig_GetOptOfType("windows.clipcursor", C_BOOL)->value.intBoolVal)
381          {
382                  // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
383                  DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
# Line 365 | Line 390 | bool DD_Patch_Init()
390          }
391  
392          // Disables weapon cooldown exploit
393 <        if (DDrConfig_GetOptOfType("patches.cooldowntimer", C_BOOL)->value.intBoolVal)
393 >        if (DDrConfig_GetOptOfType("gameplay.cooldowntimer", C_BOOL)->value.intBoolVal)
394          {
395                  // In WPrRelease: NoOp 4 MOVs
396                  DDrPatch_NOOP((char*)(OniExe + 0x0011a825), 22);
397          }
398  
399          // Daodan device mode enumeration function
400 <        if (DDrConfig_GetOptOfType("patches.daodandisplayenum", C_BOOL)->value.intBoolVal)
400 >        if (DDrConfig_GetOptOfType("graphics.displayenum", C_BOOL)->value.intBoolVal)
401          {
402                  DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
403          }
404          
405          // Forced DirectInput (for Windows NT)
406 <        if (DDrConfig_GetOptOfType("patches.directinput", C_BOOL)->value.intBoolVal)
406 >        if (DDrConfig_GetOptOfType("windows.directinput", C_BOOL)->value.intBoolVal)
407          {
408                  // LIrPlatform_Initialize: replace conditional jump by unconditional
409                  DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb);
410          }
411  
412          // Disable Oni's command line parser so it doesn't interfere with ours
413 <        if (DDrConfig_GetOptOfType("patches.disablecmdline", C_BOOL)->value.intBoolVal)
413 >        if (DDrConfig_GetOptOfType("windows.disablecmdline", C_BOOL)->value.intBoolVal)
414          {
415                  // Replace start of OniParseCommandLine with XOR eax,eax; RET
416                  DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033);
# Line 394 | Line 419 | bool DD_Patch_Init()
419          }
420  
421          // Font texture cache doubled
422 <        if (DDrConfig_GetOptOfType("patches.fonttexturecache", C_BOOL)->value.intBoolVal)
422 >        if (DDrConfig_GetOptOfType("language.fonttexturecache", C_BOOL)->value.intBoolVal)
423          {
424                  // Double two values in TMrGame_Initialize
425                  DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20);
# Line 402 | Line 427 | bool DD_Patch_Init()
427          }
428  
429          // Allow HD screens on resolutions < 1024*768
430 <        if (DDrConfig_GetOptOfType("patches.hdscreens_lowres", C_BOOL)->value.intBoolVal)
430 >        if (DDrConfig_GetOptOfType("modding.hdscreens_lowres", C_BOOL)->value.intBoolVal)
431          {
432                  DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap);
433          }
434  
435          // Allow for console to show on higher resolutions
436 <        if (DDrConfig_GetOptOfType("patches.highres_console", C_BOOL)->value.intBoolVal)
436 >        if (DDrConfig_GetOptOfType("devmode.highres_console", C_BOOL)->value.intBoolVal)
437          {
438                  Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize);
439          }
440          
441          // Hackish fix for Konoko not kicking guns
442          // Don't use this, it breaks stairs.
443 <        if (DDrConfig_GetOptOfType("patches.kickguns", C_BOOL)->value.intBoolVal)
443 >        if (DDrConfig_GetOptOfType("gameplay.kickguns", C_BOOL)->value.intBoolVal)
444          {
445                  // In ONrCharacter_EnablePhysics: Load different values to same addresses as before
446                  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 448 | bool DD_Patch_Init()
448          }
449          
450          // Disable loading the vtuneapi.dll
451 <        if (DDrConfig_GetOptOfType("patches.killvtune", C_BOOL)->value.intBoolVal)
451 >        if (DDrConfig_GetOptOfType("windows.killvtune", C_BOOL)->value.intBoolVal)
452          {
453                  // Instantly return from UUrLoadVtuneAPI
454                  DDrPatch_Byte((char*)(OniExe + 0x00026340), 0xC3);
455          }
456  
457          // Now supports textures up to 512x512
458 <        if (DDrConfig_GetOptOfType("patches.largetextures", C_BOOL)->value.intBoolVal)
458 >        if (DDrConfig_GetOptOfType("modding.largetextures", C_BOOL)->value.intBoolVal)
459          {
460                  DDrPatch_Byte((char*)(OniExe + 0x00005251), 0x10);
461          }
462          
463          // Non-"_Final" levels are now valid
464 <        if (DDrConfig_GetOptOfType("patches.levelplugins", C_BOOL)->value.intBoolVal)
464 >        if (DDrConfig_GetOptOfType("modding.levelplugins", C_BOOL)->value.intBoolVal)
465          {
466                  // Patch in TMrUtility_LevelInfo_Get:
467                  DDrPatch_Byte((char*)(OniExe + 0x000206a8), 0x01);
468          }
469  
470          // Weapon on ground shown with name and magazine contents
471 <        if (DDrConfig_GetOptOfType("patches.newweap", C_BOOL)->value.intBoolVal)
471 >        if (DDrConfig_GetOptOfType("graphics.newweap", C_BOOL)->value.intBoolVal)
472          {
473                  //Makes it always say "Received weapon_name."
474                  //Needs check for loc_4DFC66
# Line 463 | Line 488 | bool DD_Patch_Init()
488          }
489  
490          // Disable Multi-byte character awareness patch (multiple language support)
491 <        if (DDrConfig_GetOptOfType("patches.nomultibyte", C_BOOL)->value.intBoolVal)
491 >        if (DDrConfig_GetOptOfType("language.nomultibyte", C_BOOL)->value.intBoolVal)
492          {
493                  // TSiContext_DrawLine: Replace conditional jumps by unconditional ones
494                  DDrPatch_Byte  ((char*)(OniExe + 0x0002d8f8), 0xeb);
# Line 488 | Line 513 | bool DD_Patch_Init()
513          }
514  
515          // Fix options not visible in main menu when a game was started
516 <        if (DDrConfig_GetOptOfType("patches.optionsvisible", C_BOOL)->value.intBoolVal)
516 >        if (DDrConfig_GetOptOfType("graphics.optionsvisible", C_BOOL)->value.intBoolVal)
517          {
518                  // replace WMrWindow_SetVisible calls
519                  DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
# Line 496 | Line 521 | bool DD_Patch_Init()
521          }
522  
523          // Pathfinding grid cache size x8
524 <        if (DDrConfig_GetOptOfType("patches.pathfinding", C_BOOL)->value.intBoolVal)
524 >        if (DDrConfig_GetOptOfType("gameplay.pathfinding", C_BOOL)->value.intBoolVal)
525          {
526                  // Replaces conditional jump (je) with unconditional jump
527                  const unsigned char pathfinding[2] = {0x90 , 0xE9 };
# Line 508 | Line 533 | bool DD_Patch_Init()
533          }
534  
535          // Projectile awareness fixed
536 <        if (DDrConfig_GetOptOfType("patches.projaware", C_BOOL)->value.intBoolVal)
536 >        if (DDrConfig_GetOptOfType("gameplay.projaware", C_BOOL)->value.intBoolVal)
537          {
538                  DDrPatch_Byte  ((char*)(OniExe + 0x0009c07c), 0x6c);
539                  DDrPatch_Byte  ((char*)(OniExe + 0x0009c080), 0x70);
# Line 517 | Line 542 | bool DD_Patch_Init()
542          }
543  
544          // Safe startup message printer
545 <        if (DDrConfig_GetOptOfType("patches.safeprintf", C_BOOL)->value.intBoolVal)
545 >        if (DDrConfig_GetOptOfType("windows.safeprintf", C_BOOL)->value.intBoolVal)
546          {
547                  DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
548          }
549  
550          // Show all (also enemies') lasersights
551 <        if (DDrConfig_GetOptOfType("patches.showalllasersights", C_BOOL)->value.intBoolVal)
551 >        if (DDrConfig_GetOptOfType("graphics.showalllasersights", C_BOOL)->value.intBoolVal)
552          {
553                  DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 );
554          }
555  
556          // Allow bsl-var show_triggervolumes or ctrl+shift+x (devmode) to work
557 <        if (DDrConfig_GetOptOfType("patches.showtriggervolumes", C_BOOL)->value.intBoolVal)
557 >        if (DDrConfig_GetOptOfType("devmode.showtriggervolumes", C_BOOL)->value.intBoolVal)
558          {
559                  Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register);
560                  Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput);
561          }
562          
563          // Experiment with allowing enemies to be thrown over railings
564 <        if (DDrConfig_GetOptOfType("patches.throwtest", C_BOOL)->value.intBoolVal)
564 >        if (DDrConfig_GetOptOfType("gameplay.throwtest", C_BOOL)->value.intBoolVal)
565          {
566                  DDrPatch_NOOP((char*)(OniExe + 0x000dc190), 10);
567          }
568  
569          // DaodanGL with windowed mode support
570 <        if (DDrConfig_GetOptOfType("patches.usedaodangl", C_BOOL)->value.intBoolVal)
570 >        if (DDrConfig_GetOptOfType("graphics.daodangl", C_BOOL)->value.intBoolVal)
571          {
572                  // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
573                  DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
# Line 579 | Line 604 | bool DD_Patch_Init()
604          }
605  
606          // Performance patch
607 <        if (DDrConfig_GetOptOfType("patches.usegettickcount", C_BOOL)->value.intBoolVal)
607 >        if (DDrConfig_GetOptOfType("windows.usegettickcount", C_BOOL)->value.intBoolVal)
608          {
609                  DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High);
610                  DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency);
# Line 587 | Line 612 | bool DD_Patch_Init()
612          }
613  
614          // Fix displaying the talking portraits in widescreen modes
615 <        if (DDrConfig_GetOptOfType("patches.widescreenportraits", C_BOOL)->value.intBoolVal)
615 >        if (DDrConfig_GetOptOfType("graphics.widescreenportraits", C_BOOL)->value.intBoolVal)
616          {
617                  SLrDaodan_Patch();
618          }
619          
620          // Adds working function for existing BSL command wp_fadetime, sets fade time to 4800
621 <        if (DDrConfig_GetOptOfType("patches.wpfadetime", C_BOOL)->value.intBoolVal)
621 >        if (DDrConfig_GetOptOfType("gameplay.wpfadetime", C_BOOL)->value.intBoolVal)
622          {
623                  // Makes wp_fadetime actually have a function (changes within WPrRelease)
624                  // 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)