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 994 by alloc, Mon Apr 7 10:33:27 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 <        ConfigOption_t* co = DDrConfig_GetOptOfType("options.usedaodanbsl", C_BOOL);
88 <        if (co->value.intBoolVal)
88 >        if (DDrConfig_GetOptOfType("modding.daodanbsl", C_BOOL)->value.intBoolVal)
89                  SLrDaodan_Initialize();
90   }
91  
# Line 132 | 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 192 | Line 194 | void ONICALL DD_ONrGameState_HandleUtili
194   }
195  
196  
197 < int DD_Patch_DebugNameTextureInit(short width, short height, int type, int allocated, int flags, char* name, void** output)
197 > // Enables d_regen script command. Instead of one global flag to only regenerate player each char has a flag to enable local regeneration
198 > void DD_Patch_Regeneration()
199   {
200 <        //flags = (1 << 10);
198 <        type = 1;
199 <        //DDrPatch_Byte( 0x005EB83C + 3, 0xff );
200 <        DDrPatch_Int32((int*)(OniExe + 0x001EB83C), 0xFF000000 );
201 <        return M3rTextureMap_New(width, height, type, allocated, flags, name, output);
202 < }
203 <
204 < short DD_Patch_DebugNameShadeHack( Character* Char )
205 < {
206 <        return TSrContext_SetShade(*(void**)(OniExe + 0x001EB844), ONrCharacter_GetHealthShade( Char->Health, Char->MaxHealth ));
207 <        //return TSrContext_SetShade(*(void**)0x005EB844, 0xFFFFFFFF);
208 < }
209 <
210 <
211 < // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the
212 < // Windows key but has the possible side effect of allowing the screensaver
213 < // to enable itself in-game.
214 < void DD_Patch_AltTab()
215 < {
216 <        // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start
217 <        DDrPatch_Byte  ((char*)UUrPlatform_Initialize, 0xC3);
218 <        DDrPatch_Byte  ((char*)UUrPlatform_Terminate, 0xC3);
219 < }
220 <
221 < // Textures using ARGB8888 can be used
222 < void DD_Patch_ARGB8888()
223 < {
224 <        DDrPatch_Byte  ((char*)(OniExe + 0x00135af0), 0x07);
225 <        DDrPatch_Byte  ((char*)(OniExe + 0x00135af4), 0x0B);
226 < }
227 <
228 < // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting
229 < // instead of DirectDraw; patch ONiRunGame to use the same method to play
230 < // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
231 < // latter has problems on WINE).
232 < void DD_Patch_BinkPlay()
233 < {
234 <        // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
235 <        DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
236 <        // call ONrMovie_Play_Hardware -> call ONrMovie_Play
237 <        DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
238 < }
239 <
240 < // Enables d_regen (unfinished) and prevents fly-in portraits from being
241 < // stretched when playing in widescreen resolutions.
242 < void DD_Patch_BSL()
243 < {
244 <        //Calculating the value of the needed offset is much more reliable when the compiler does it for you.
245 <
246 <        //TODO: fix moonshadow.
200 >        // In: WPrInventory_Update
201          Character * Chr = 0;
202          int NoPath = (int)&(Chr[0].RegenHax) & 0x000000FF;
203          const unsigned char regen_patch[] =
204          {0x90, 0x90, 0x90, 0x90, 0x90,                          // mov    al, _WPgRegenerationCheat     -> NOOP
205 <        0x90, 0x90,                                                                     // test   al, al                                        -> NOOP
206 <        0x90, 0x90,                                                                     // jz     short loc_51BB98                      -> NOOP
205 >        0x90, 0x90,                                             // test   al, al                        -> NOOP
206 >        0x90, 0x90,                                             // jz     short loc_51BB98                      -> NOOP
207          0x8B, 0x86, (char)NoPath, 0x01, 0x00, 0x00, // mov     eax, [esi+Character.field_1E8]
208 <                                                                                                //      -> mov     eax, [esi+Character.RegenHax]
209 <        0x85, 0xC0,                                                                     // test eax, eax
210 <        0x74, 0x21                                                                      // jnz 0x21 -> jz 0x21
211 <        };      
208 >                                                        //      -> mov     eax, [esi+Character.RegenHax]
209 >        0x85, 0xC0,                                             // test eax, eax
210 >        0x74, 0x21                                              // jnz 0x21 -> jz 0x21
211 >        };
212          DDrPatch_Const((char*)(OniExe + 0x0011BB64), regen_patch);
259
260        // Patches for existing BSL functions
261        SLrDaodan_Patch();
262 }
263
264 // Adds new cheat codes if cheattable is also enabled
265 void DD_Patch_Cheater()
266 {
267        DDrPatch_MakeCall((void*)(OniExe + 0x000f618f), (void*)DDrCheater);
268        DDrPatch_Int16((short*)(OniExe + 0x000deb45), 0x5590);
269 #if 1
270        DDrPatch_MakeCall((void*)(OniExe + 0x000deb47), (void*)FallingFrames);
271 #endif
272        DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad);
273 }
274
275 // Cheats always enabled
276 void DD_Patch_CheatsEnabled()
277 {
278        DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
213   }
214  
281 // Use Daodan's own cheattable
282 void DD_Patch_CheatTable()
283 {
284        DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name);
285        DDrPatch_Int32 ((int*)(OniExe + 0x000f617a), (int)&DDr_CheatTable[0].message_on);
286 }
215  
216   // Load chinese font DLL if available
217   void DD_Patch_Chinese()
# Line 311 | Line 239 | void DD_Patch_Chinese()
239          }
240   }
241  
314 // Limit cursor to Oni's window
315 void DD_Patch_ClipCursor()
316 {
317        // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
318        DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
319
320        // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
321        DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
322        
323        // LIrTermiante: replace LIrPlatform_Terminate call with our hook.
324        DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
325 }
326
327 // Disables weapon cooldown exploit
328 void DD_Patch_CooldownTimer()
329 {
330        const unsigned char cooldown_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
331        DDrPatch_Const ((char*)(OniExe + 0x0011a825), cooldown_patch);
332 }
333
334 // Daodan device mode enumeration function
335 void DD_Patch_DaodanDisplayEnum()
336 {
337        DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
338 }
339
340 // Adds new BSL functions
341 void DD_Patch_DaodanInit()
342 {
343        DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init);
344 }
345
346 // Forced DirectInput (for Windows NT)
347 void DD_Patch_DirectInput()
348 {
349        DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb);
350 }
351
352 // Disable Oni's command line parser so it doesn't interfere with ours
353 void DD_Patch_DisableCmdLine()
354 {
355        // Replace start of OniParseCommandLine with XOR ax,ax; RET
356 //      DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0xc3c03366);
357        // Replace start of OniParseCommandLine with XOR eax,eax; RET
358        DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033);
359 }
360
361 // Font texture cache doubled
362 void DD_Patch_FontTextureCache()
363 {
364        DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20);
365        DDrPatch_Byte((char*)(OniExe + 0x00020f4a), 0x40);
366 }
367
368 // Disable Oni's internal CLrGetCommandLine function (to eventually replace it with our own)
369 void DD_Patch_GetCmdLine()
370 {
371        DDrPatch_NOOP  ((char*)(OniExe + 0x000d3280), 51);
372 }
373
374 // Allow HD screens with resolution < 1024*768
375 void DD_Patch_HDScreens_LowRes()
376 {
377        DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap);
378 }
379
380 void DD_Patch_HighresConsole() {
381        Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize);
382 }
383
384 // Hackish fix for Konoko not kicking guns
385 // Don't use this, it breaks stairs.
386 void DD_Patch_KickGuns()
387 {
388        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 };
389        DDrPatch_Const ((char*)(OniExe + 0x000dc420), kickgun_patch);
390 }
391
392 // Disable loading the vtuneapi.dll
393 void DD_Patch_KillVTune()
394 {
395        DDrPatch_Byte  ((char*)(OniExe + 0x00026340), 0xC3);
396 }
397
398 // Now supports textures up to 512x512
399 void DD_Patch_LargeTextures()
400 {
401        DDrPatch_Byte  ((char*)(OniExe + 0x00005251), 0x10);
402 }
403
404 // Non-"_Final" levels are now valid
405 void DD_Patch_LevelPlugins()
406 {
407        DDrPatch_Byte  ((char*)(OniExe + 0x000206a8), 0x01);
408 }
409
410 // Weapon on ground shown with name and magazine contents
411 void DD_Patch_NewWeap()
412 {
413        //Makes it always say "Received weapon_name."
414        //Needs check for loc_4DFC66
415        //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2);
416
417        //Adds Weapon name and ammo meter to pickup autoprompt
418        DDrPatch_NOOP((char*)(OniExe + 0x000FAC73), 9);
419        DDrPatch_NOOP((char*)(OniExe + 0x000FAC80), 5);
420        DDrPatch_MakeCall((void*)(OniExe + 0xFAC85), (void*)DDrWeapon2Message);
421        
422        //Moves location of colors
423        //DDrPatch_Int32((int*)(OniExe + 0x0002E3D5), (int)&DDrDSayColors );
424        //DDrPatch_Int32((int*)(OniExe + 0x0002E3DA), (int)&DDrDSayColors );
425 }
426
427 // Disable Multi-byte character awareness patch (multiple language support)
428 void DD_Patch_NoMultiByte()
429 {
430        DDrPatch_Byte  ((char*)(OniExe + 0x0002d8f8), 0xeb);
431        DDrPatch_Byte  ((char*)(OniExe + 0x0002d9ad), 0xeb);
432        DDrPatch_Byte  ((char*)(OniExe + 0x0002dbe2), 0xeb);
433        DDrPatch_Byte  ((char*)(OniExe + 0x0002dec3), 0xeb);
434        DDrPatch_Byte  ((char*)(OniExe + 0x0002e2ab), 0xeb);
435        DDrPatch_Byte  ((char*)(OniExe + 0x0002e2c4), 0xeb);
436        DDrPatch_Byte  ((char*)(OniExe + 0x0002e379), 0xeb);
437        DDrPatch_Byte  ((char*)(OniExe + 0x0002e48c), 0xeb);
438        DDrPatch_Byte  ((char*)(OniExe + 0x0002e4d0), 0xeb);
439        DDrPatch_Byte  ((char*)(OniExe + 0x0002e4f4), 0xeb);
440        DDrPatch_Byte  ((char*)(OniExe + 0x0002e646), 0xeb);
441        DDrPatch_Byte  ((char*)(OniExe + 0x0002e695), 0xeb);
442        DDrPatch_Byte  ((char*)(OniExe + 0x0002e944), 0xeb);
443        DDrPatch_Byte  ((char*)(OniExe + 0x0002e95d), 0xeb);
444        DDrPatch_Byte  ((char*)(OniExe + 0x0002e98e), 0xeb);
445        DDrPatch_Byte  ((char*)(OniExe + 0x0002e9dc), 0xeb);
446 }
447
448 // Fix options not visible in main menu when a game was started
449 void DD_Patch_OptionsVisible()
450 {
451        DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
452        DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton);
453 }
454
455 // Unlocks particle action disabling/enabling bits for all events. (Will be
456 // controlled by a command line switch when I figure out how to do that without
457 // Win32 hacks.)
458 void DD_Patch_ParticleDisableBit()
459 {
460        DDrPatch_Int16 ((short*)(OniExe + 0x001b184), 0x9090);
461 }
462
463 // Pathfinding grid cache size x8
464 void DD_Patch_PathFinding()
465 {
466        const unsigned char pathfinding[2] = {0x90 , 0xE9 };
467        DDrPatch_Byte  ((char*)(OniExe + 0x0010b03b), 0x20);
468        DDrPatch_Byte  ((char*)(OniExe + 0x0010b04c), 0x20);
469
470        //other stuff
471        DDrPatch_Const((char*)(OniExe + 0x00040789), pathfinding);
472 }
473
474 // Projectile awareness fixed
475 void DD_Patch_ProjAware()
476 {
477        DDrPatch_Byte  ((char*)(OniExe + 0x0009c07c), 0x6c);
478        DDrPatch_Byte  ((char*)(OniExe + 0x0009c080), 0x70);
479        DDrPatch_Byte  ((char*)(OniExe + 0x0009c084), 0x74);
480        DDrPatch_Byte  ((char*)(OniExe + 0x0009c110), 0x6c);
481 }
482
483 // Safe startup message printer
484 void DD_Patch_SafePrintf()
485 {
486        DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
487 }
488
489 // Show all (also enemies') lasersights
490 void DD_Patch_ShowAllLasersights()
491 {
492        DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 );
493 }
494
495 void DD_Patch_ShowTriggerVolumes()
496 {
497        Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register);
498        Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput);
499 }
500
501 // Experiment with allowing enemies to be thrown over railings
502 void DD_Patch_Throwtest()
503 {
504        const unsigned char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
505        DDrPatch_Const((char*)(OniExe + 0x000dc190), throwtest_patch);
506 }
507
508 // DaodanGL with windowed mode support
509 void DD_Patch_UseDaodanGL()
510 {
511        // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
512        DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
513        DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect);
514
515        // UUrWindow_GetSize: GetWindowRect -> GetClientRect.
516        DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
517        DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
242  
519        // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates.
520        DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6);
521        DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos);
243  
244 <        // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates.
524 <        DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6);
525 <        DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos);
526 <
527 <        // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
528 <        DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6);
529 <        DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos);
530 <
531 <        // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
532 <        DDrPatch_NOOP((char*) OniExe + 0x00003349, 6);
533 <        DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos);
534 <
535 <        // Replace ONrPlatformInitialize.
536 <        DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize);
537 <
538 <        // Replace gl_platform_initialize.
539 <        DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize);
540 <
541 <        // Replace gl_platform_dispose.
542 <        DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose);
543 < }
544 <
545 < // Performance patch
546 < void DD_Patch_UseGetTickCount()
547 < {
548 <        DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High);
549 <        DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency);
550 <        DDrPatch_MakeJump((void*)UUrMachineTime_Sixtieths, (void*)DDrMachineTime_Sixtieths);
551 < }
552 <
553 < // Adds working function for existing BSL command wp_fadetime, sets fade time to 4800
554 < void DD_Patch_WpFadetime()
555 < {
556 <        // Makes wp_fadetime actually have a function
557 <        const unsigned char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
558 <        DDrPatch_Const ((char*)(OniExe + 0x0011a889), fadetime_patch);
559 <        DDrPatch_Byte  ((char*)(OniExe + 0x0011a560), 0x31);
560 <        
561 <        // Sets the fadetime to 4800 by default
562 <        DDrPatch_Int16 ((short*)(OniExe + 0x0011ab0e), 0x12c0);
563 < }
564 <
565 < // Disable gamma slider in options in windowed mode
566 < void DD_Patch_GammaSlider()
244 > int DD_Patch_DebugNameTextureInit(short width, short height, int type, int allocated, int flags, char* name, void** output)
245   {
246 <        DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
246 >        //flags = (1 << 10);
247 >        type = 1;
248 >        //DDrPatch_Byte( 0x005EB83C + 3, 0xff );
249 >        DDrPatch_Int32((int*)(OniExe + 0x001EB83C), 0xFF000000 );
250 >        return M3rTextureMap_New(width, height, type, allocated, flags, name, output);
251   }
252  
253 < // Fix the warning print method
572 < void DD_Patch_PrintWarning()
253 > short DD_Patch_DebugNameShadeHack( Character* Char )
254   {
255 <        DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
255 >        return TSrContext_SetShade(*(void**)(OniExe + 0x001EB844), ONrCharacter_GetHealthShade( Char->Health, Char->MaxHealth ));
256   }
257  
258   //Fix crappy ai2_shownames
# Line 598 | Line 279 | void DD_Patch_ShowNames()
279   */
280   }
281  
601 /*
602 void DD_Patch_ShowTriggerVolumes()
603 {
604        DDrPatch_Int32((int*)(OniExe + 0x000cc9bb+4), (uint32_t)DD_OBJiTriggerVolume_Draw);
605 }
282  
283 < void DD_Patch_ShowFlags()
283 > void DD_Patch_CharacterAwareness()
284   {
285 <        DDrPatch_Int32((int*)(OniExe + 0x000c4ed4+4), (uint32_t)DD_OBJiFlag_Draw);
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 < */
306 >
307 >
308 >
309 >
310 >
311  
312   bool DD_Patch_Init()
313   {
314          STARTUPMESSAGE("Patching engine", 0);
315          
316 <        if (DDrConfig_GetOptOfType("patches.alttab", C_BOOL)->value.intBoolVal)
317 <                DD_Patch_AltTab();
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("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);
323 >                DDrPatch_Byte((char*)UUrPlatform_Terminate, 0xC3);
324 >        }
325          
326 <        if (DDrConfig_GetOptOfType("patches.argb8888", C_BOOL)->value.intBoolVal)
327 <                DD_Patch_ARGB8888();
326 >        // Textures using ARGB8888 can be used
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);
331 >                DDrPatch_Byte((char*)(OniExe + 0x00135af4), 0x0B);
332 >        }
333  
334 <        if (DDrConfig_GetOptOfType("patches.binkplay", C_BOOL)->value.intBoolVal)
335 <                DD_Patch_BinkPlay();
334 >        // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting
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("graphics.binkplay", C_BOOL)->value.intBoolVal)
339 >        {
340 >                // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
341 >                DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
342 >                // call ONrMovie_Play_Hardware -> call ONrMovie_Play
343 >                DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
344 >        }
345  
346 <        if (DDrConfig_GetOptOfType("patches.bsl", C_BOOL)->value.intBoolVal)
347 <                DD_Patch_BSL();
346 >        if (DDrConfig_GetOptOfType("modding.d_regen", C_BOOL)->value.intBoolVal)
347 >                DD_Patch_Regeneration();
348  
349 <        if (DDrConfig_GetOptOfType("patches.cheater", C_BOOL)->value.intBoolVal)
350 <                DD_Patch_Cheater();
349 >        if (DDrConfig_GetOptOfType("gameplay.characterawareness", C_BOOL)->value.intBoolVal)
350 >                DD_Patch_CharacterAwareness();
351  
352 <        if (DDrConfig_GetOptOfType("patches.cheatsenabled", C_BOOL)->value.intBoolVal)
353 <                DD_Patch_CheatsEnabled();
352 >        // Cheats always enabled
353 >        if (DDrConfig_GetOptOfType("gameplay.cheatsenabled", C_BOOL)->value.intBoolVal)
354 >        {
355 >                DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
356 >        }
357  
358 <        if (DDrConfig_GetOptOfType("patches.cheattable", C_BOOL)->value.intBoolVal)
359 <                DD_Patch_CheatTable();
358 >        // Use Daodan's own cheattable
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);
363 >                DDrPatch_Int32 ((int*)(OniExe + 0x000f617a), (int)&DDr_CheatTable[0].message_on);
364 >
365 >                // ONrGameState_HandleCheats: Replace call to ONrCheater
366 >                DDrPatch_MakeCall((void*)(OniExe + 0x000f618f), (void*)DDrCheater);
367 >
368 >                // In: ONrGameState_DoCharacterFrame
369 >                //  -> NOP; PUSH ebp; CALL FallingFrames
370 >                // Replace fall height frame counter (actually in-air frame counter) increase by a
371 >                //  conditional one (only counted when inc_fallingframes)
372 >                DDrPatch_Int16((short*)(OniExe + 0x000deb45), 0x5590);
373 >                DDrPatch_MakeCall((void*)(OniExe + 0x000deb47), (void*)FallingFrames);
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 <        if (DDrConfig_GetOptOfType("patches.clipcursor", C_BOOL)->value.intBoolVal)
388 <                DD_Patch_ClipCursor();
389 <
390 <        if (DDrConfig_GetOptOfType("patches.cooldowntimer", C_BOOL)->value.intBoolVal)
391 <                DD_Patch_CooldownTimer();
387 >        // Limit cursor to Oni's window
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);
392  
393 <        if (DDrConfig_GetOptOfType("patches.daodandisplayenum", C_BOOL)->value.intBoolVal)
394 <                DD_Patch_DaodanDisplayEnum();
393 >                // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
394 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
395          
396 <        if (DDrConfig_GetOptOfType("patches.directinput", C_BOOL)->value.intBoolVal)
397 <                DD_Patch_DirectInput();
396 >                // LIrTerminate: replace LIrPlatform_Terminate call with our hook.
397 >                DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
398 >        }
399  
400 <        if (DDrConfig_GetOptOfType("patches.disablecmdline", C_BOOL)->value.intBoolVal)
401 <                DD_Patch_DisableCmdLine();
400 >        // Disables weapon cooldown exploit
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("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("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 <        if (DDrConfig_GetOptOfType("patches.fonttexturecache", C_BOOL)->value.intBoolVal)
421 <                DD_Patch_FontTextureCache();
420 >        // Disable Oni's command line parser so it doesn't interfere with ours
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);
425 >                // NoOp first 51 byte in ONiMain, including tests and conditional exec of CLrGetCommandLine
426 >                DDrPatch_NOOP((char*)(OniExe + 0x000d3280), 51);
427 >        }
428  
429 <        if (DDrConfig_GetOptOfType("patches.getcmdline", C_BOOL)->value.intBoolVal)
430 <                DD_Patch_GetCmdLine();
429 >        // Font texture cache doubled
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);
434 >                DDrPatch_Byte((char*)(OniExe + 0x00020f4a), 0x40);
435 >        }
436  
437 <        if (DDrConfig_GetOptOfType("patches.hdscreens_lowres", C_BOOL)->value.intBoolVal)
438 <                DD_Patch_HDScreens_LowRes();
437 >        // Allow HD screens on resolutions < 1024*768
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 <        if (DDrConfig_GetOptOfType("patches.highres_console", C_BOOL)->value.intBoolVal)
444 <                DD_Patch_HighresConsole();
443 >        // Allow for console to show on higher resolutions
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 <        if (DDrConfig_GetOptOfType("patches.kickguns", C_BOOL)->value.intBoolVal)
450 <                DD_Patch_KickGuns();
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 <        //if (patch_killvtune)
456 <        //      DD_Patch_KillVTune();
455 >        // Hackish fix for Konoko not kicking guns
456 >        // Don't use this, it breaks stairs.
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 };
461 >                DDrPatch_Const ((char*)(OniExe + 0x000dc420), kickgun_patch);
462 >        }
463 >        
464 >        // Disable loading the vtuneapi.dll
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 <        if (DDrConfig_GetOptOfType("patches.largetextures", C_BOOL)->value.intBoolVal)
472 <                DD_Patch_LargeTextures();
471 >        // Now supports textures up to 512x512
472 >        if (DDrConfig_GetOptOfType("modding.largetextures", C_BOOL)->value.intBoolVal)
473 >        {
474 >                DDrPatch_Byte((char*)(OniExe + 0x00005251), 0x10);
475 >        }
476          
477 <        if (DDrConfig_GetOptOfType("patches.levelplugins", C_BOOL)->value.intBoolVal)
478 <                DD_Patch_LevelPlugins();
477 >        // Non-"_Final" levels are now valid
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 <        if (DDrConfig_GetOptOfType("patches.newweap", C_BOOL)->value.intBoolVal)
485 <                DD_Patch_NewWeap();
484 >        // Weapon on ground shown with name and magazine contents
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
489 >                //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2);
490 >
491 >                //Adds Weapon name and ammo meter to pickup autoprompt (patches to ONrGameState_ProcessHeartbeat)
492 >                // Do not call WPrHasAmmo and ignore conditional jump:
493 >                DDrPatch_NOOP((char*)(OniExe + 0x000FAC73), 9);
494 >                // Do not load ecx with some magic value?
495 >                DDrPatch_NOOP((char*)(OniExe + 0x000FAC80), 5);
496 >                // Replace call to ONiGameState_FindAutoPromptMessage
497 >                DDrPatch_MakeCall((void*)(OniExe + 0xFAC85), (void*)DDrWeapon2Message);
498 >        
499 >                //Moves location of colors
500 >                //DDrPatch_Int32((int*)(OniExe + 0x0002E3D5), (int)&DDrDSayColors );
501 >                //DDrPatch_Int32((int*)(OniExe + 0x0002E3DA), (int)&DDrDSayColors );
502 >        }
503  
504 <        if (DDrConfig_GetOptOfType("patches.nomultibyte", C_BOOL)->value.intBoolVal)
505 <                DD_Patch_NoMultiByte();
504 >        // Disable Multi-byte character awareness patch (multiple language support)
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);
509 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002d9ad), 0xeb);
510 >                // TSiContext_DrawTextLine: same
511 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002dbe2), 0xeb);
512 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002dec3), 0xeb);
513 >                // TSrContext_FormatString: same
514 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e2ab), 0xeb);
515 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e2c4), 0xeb);
516 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e379), 0xeb);
517 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e48c), 0xeb);
518 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e4d0), 0xeb);
519 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e4f4), 0xeb);
520 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e646), 0xeb);
521 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e695), 0xeb);
522 >                // TSrContext_GetStringRect: same
523 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e944), 0xeb);
524 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e95d), 0xeb);
525 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e98e), 0xeb);
526 >                DDrPatch_Byte  ((char*)(OniExe + 0x0002e9dc), 0xeb);
527 >        }
528  
529 <        if (DDrConfig_GetOptOfType("patches.optionsvisible", C_BOOL)->value.intBoolVal)
530 <                DD_Patch_OptionsVisible();
529 >        // Fix options not visible in main menu when a game was started
530 >        if (DDrConfig_GetOptOfType("graphics.optionsvisible", C_BOOL)->value.intBoolVal)
531 >        {
532 >                // replace WMrWindow_SetVisible calls
533 >                DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton);
534 >                DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton);
535 >        }
536  
537 <        if (DDrConfig_GetOptOfType("patches.particledisablebit", C_BOOL)->value.intBoolVal)
538 <                DD_Patch_ParticleDisableBit();
539 <        
540 <        if (DDrConfig_GetOptOfType("patches.pathfinding", C_BOOL)->value.intBoolVal)
541 <                DD_Patch_PathFinding();
537 >        // Pathfinding grid cache size x8
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 };
542 >                DDrPatch_Byte  ((char*)(OniExe + 0x0010b03b), 0x20);
543 >                DDrPatch_Byte  ((char*)(OniExe + 0x0010b04c), 0x20);
544  
545 <        if (DDrConfig_GetOptOfType("patches.projaware", C_BOOL)->value.intBoolVal)
546 <                DD_Patch_ProjAware();
545 >                //other stuff
546 >                DDrPatch_Const((char*)(OniExe + 0x00040789), pathfinding);
547 >        }
548  
549 <        if (DDrConfig_GetOptOfType("patches.safeprintf", C_BOOL)->value.intBoolVal)
550 <                DD_Patch_SafePrintf();
549 >        // Projectile awareness fixed
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);
554 >                DDrPatch_Byte  ((char*)(OniExe + 0x0009c084), 0x74);
555 >                DDrPatch_Byte  ((char*)(OniExe + 0x0009c110), 0x6c);
556 >        }
557  
558 <        if (DDrConfig_GetOptOfType("patches.showalllasersights", C_BOOL)->value.intBoolVal)
559 <                DD_Patch_ShowAllLasersights();
558 >        // Safe startup message printer
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("graphics.showalllasersights", C_BOOL)->value.intBoolVal)
566 >        {
567 >                DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 );
568 >        }
569  
570 <        if (DDrConfig_GetOptOfType("patches.showtriggervolumes", C_BOOL)->value.intBoolVal)
571 <                DD_Patch_ShowTriggerVolumes();
570 >        // Allow bsl-var show_triggervolumes or ctrl+shift+x (devmode) to work
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 <        if (DDrConfig_GetOptOfType("patches.throwtest", C_BOOL)->value.intBoolVal)
578 <                DD_Patch_Throwtest();
577 >        // Experiment with allowing enemies to be thrown over railings
578 >        if (DDrConfig_GetOptOfType("gameplay.throwtest", C_BOOL)->value.intBoolVal)
579 >        {
580 >                DDrPatch_NOOP((char*)(OniExe + 0x000dc190), 10);
581 >        }
582  
583 <        if (DDrConfig_GetOptOfType("patches.usedaodangl", C_BOOL)->value.intBoolVal)
584 <                DD_Patch_UseDaodanGL();
583 >        // DaodanGL with windowed mode support
584 >        if (DDrConfig_GetOptOfType("graphics.daodangl", C_BOOL)->value.intBoolVal)
585 >        {
586 >                // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
587 >                DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
588 >                DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect);
589 >
590 >                // UUrWindow_GetSize: GetWindowRect -> GetClientRect.
591 >                DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
592 >                DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
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);
597 >
598 >                // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates.
599 >                DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6);
600 >                DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos);
601 >
602 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
603 >                DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6);
604 >                DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos);
605 >
606 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
607 >                DDrPatch_NOOP((char*) OniExe + 0x00003349, 6);
608 >                DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos);
609  
610 <        if (DDrConfig_GetOptOfType("patches.usegettickcount", C_BOOL)->value.intBoolVal)
611 <                DD_Patch_UseGetTickCount();
612 <        
613 <        if (DDrConfig_GetOptOfType("patches.wpfadetime", C_BOOL)->value.intBoolVal)
614 <                DD_Patch_WpFadetime();
610 >                // Replace ONrPlatformInitialize.
611 >                DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize);
612 >
613 >                // Replace gl_platform_initialize.
614 >                DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize);
615  
616 +                // Replace gl_platform_dispose.
617 +                DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose);
618 +        }
619 +
620 +        // Performance patch
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);
625 +                DDrPatch_MakeJump((void*)UUrMachineTime_Sixtieths, (void*)DDrMachineTime_Sixtieths);
626 +        }
627 +
628 +        // Fix displaying the talking portraits in widescreen modes
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("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:
639 +                // orig: MOV [esi+0x46], 0x12c0 ; POP ebx ; POP esi ; ADD esp, 0x14 ; RET
640 +                // new:  MOV bx, [0x627dc4] ; MOV [esi+0x46], bx ; POP ebx ; POP esi ; ADD esp, 0x14 ; RET
641 +                const unsigned char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 };
642 +                DDrPatch_Const ((char*)(OniExe + 0x0011a889), fadetime_patch);
643 +                // Fixes jump because of new length of code in patch
644 +                DDrPatch_Byte  ((char*)(OniExe + 0x0011a560), 0x31);
645 +        
646 +                // Sets the fadetime to 4800 by default (in WPrInitialize)
647 +                DDrPatch_Int16 ((short*)(OniExe + 0x0011ab0e), 4800);
648 +        }
649  
650 <        DD_Patch_DaodanInit();
650 >        // Adds new BSL functions
651 >        // Replaces an early unused call (OBJrLevel_Unload_Unknown_2) in ONiMain
652 >        DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init);
653          
654 <        DD_Patch_GammaSlider();
654 >        // Disable gamma slider in options in windowed mode
655 >        // In ONiOGU_Options_Callback: Replace WMrSlider_SetRange
656 >        DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
657  
658 <        DD_Patch_PrintWarning();
658 >        // Fix the warning print method
659 >        // Replace UUrError_Report_Internal
660 >        DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
661  
662          DD_Patch_ShowNames();
663  

Diff Legend

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