--- Daodan/src/Patches/Patches.c 2014/04/07 10:33:27 994 +++ Daodan/src/Patches/Patches.c 2014/04/09 00:10:18 995 @@ -84,8 +84,7 @@ void ONICALL DDrShowOptionsButton(void* void ONICALL DDrGame_Init() { - ConfigOption_t* co = DDrConfig_GetOptOfType("options.usedaodanbsl", C_BOOL); - if (co->value.intBoolVal) + if (DDrConfig_GetOptOfType("patches.usedaodanbsl", C_BOOL)->value.intBoolVal) SLrDaodan_Initialize(); } @@ -192,98 +191,24 @@ void ONICALL DD_ONrGameState_HandleUtili } -int DD_Patch_DebugNameTextureInit(short width, short height, int type, int allocated, int flags, char* name, void** output) -{ - //flags = (1 << 10); - type = 1; - //DDrPatch_Byte( 0x005EB83C + 3, 0xff ); - DDrPatch_Int32((int*)(OniExe + 0x001EB83C), 0xFF000000 ); - return M3rTextureMap_New(width, height, type, allocated, flags, name, output); -} - -short DD_Patch_DebugNameShadeHack( Character* Char ) -{ - return TSrContext_SetShade(*(void**)(OniExe + 0x001EB844), ONrCharacter_GetHealthShade( Char->Health, Char->MaxHealth )); - //return TSrContext_SetShade(*(void**)0x005EB844, 0xFFFFFFFF); -} - - -// Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the -// Windows key but has the possible side effect of allowing the screensaver -// to enable itself in-game. -void DD_Patch_AltTab() +// Enables d_regen script command. Instead of one global flag to only regenerate player each char has a flag to enable local regeneration +void DD_Patch_Regeneration() { - // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start - DDrPatch_Byte ((char*)UUrPlatform_Initialize, 0xC3); - DDrPatch_Byte ((char*)UUrPlatform_Terminate, 0xC3); -} - -// Textures using ARGB8888 can be used -void DD_Patch_ARGB8888() -{ - DDrPatch_Byte ((char*)(OniExe + 0x00135af0), 0x07); - DDrPatch_Byte ((char*)(OniExe + 0x00135af4), 0x0B); -} - -// Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting -// instead of DirectDraw; patch ONiRunGame to use the same method to play -// outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the -// latter has problems on WINE). -void DD_Patch_BinkPlay() -{ - // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION. - DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02); - // call ONrMovie_Play_Hardware -> call ONrMovie_Play - DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play); -} - -// Enables d_regen (unfinished) and prevents fly-in portraits from being -// stretched when playing in widescreen resolutions. -void DD_Patch_BSL() -{ - //Calculating the value of the needed offset is much more reliable when the compiler does it for you. - - //TODO: fix moonshadow. + // In: WPrInventory_Update Character * Chr = 0; int NoPath = (int)&(Chr[0].RegenHax) & 0x000000FF; const unsigned char regen_patch[] = {0x90, 0x90, 0x90, 0x90, 0x90, // mov al, _WPgRegenerationCheat -> NOOP - 0x90, 0x90, // test al, al -> NOOP - 0x90, 0x90, // jz short loc_51BB98 -> NOOP + 0x90, 0x90, // test al, al -> NOOP + 0x90, 0x90, // jz short loc_51BB98 -> NOOP 0x8B, 0x86, (char)NoPath, 0x01, 0x00, 0x00, // mov eax, [esi+Character.field_1E8] - // -> mov eax, [esi+Character.RegenHax] - 0x85, 0xC0, // test eax, eax - 0x74, 0x21 // jnz 0x21 -> jz 0x21 - }; + // -> mov eax, [esi+Character.RegenHax] + 0x85, 0xC0, // test eax, eax + 0x74, 0x21 // jnz 0x21 -> jz 0x21 + }; DDrPatch_Const((char*)(OniExe + 0x0011BB64), regen_patch); - - // Patches for existing BSL functions - SLrDaodan_Patch(); } -// Adds new cheat codes if cheattable is also enabled -void DD_Patch_Cheater() -{ - DDrPatch_MakeCall((void*)(OniExe + 0x000f618f), (void*)DDrCheater); - DDrPatch_Int16((short*)(OniExe + 0x000deb45), 0x5590); -#if 1 - DDrPatch_MakeCall((void*)(OniExe + 0x000deb47), (void*)FallingFrames); -#endif - DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad); -} - -// Cheats always enabled -void DD_Patch_CheatsEnabled() -{ - DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame); -} - -// Use Daodan's own cheattable -void DD_Patch_CheatTable() -{ - DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name); - DDrPatch_Int32 ((int*)(OniExe + 0x000f617a), (int)&DDr_CheatTable[0].message_on); -} // Load chinese font DLL if available void DD_Patch_Chinese() @@ -311,267 +236,20 @@ void DD_Patch_Chinese() } } -// Limit cursor to Oni's window -void DD_Patch_ClipCursor() -{ - // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook. - DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set); - - // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook. - DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set); - - // LIrTermiante: replace LIrPlatform_Terminate call with our hook. - DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate); -} - -// Disables weapon cooldown exploit -void DD_Patch_CooldownTimer() -{ - 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 }; - DDrPatch_Const ((char*)(OniExe + 0x0011a825), cooldown_patch); -} - -// Daodan device mode enumeration function -void DD_Patch_DaodanDisplayEnum() -{ - DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes); -} - -// Adds new BSL functions -void DD_Patch_DaodanInit() -{ - DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init); -} - -// Forced DirectInput (for Windows NT) -void DD_Patch_DirectInput() -{ - DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb); -} - -// Disable Oni's command line parser so it doesn't interfere with ours -void DD_Patch_DisableCmdLine() -{ - // Replace start of OniParseCommandLine with XOR ax,ax; RET -// DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0xc3c03366); - // Replace start of OniParseCommandLine with XOR eax,eax; RET - DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033); -} - -// Font texture cache doubled -void DD_Patch_FontTextureCache() -{ - DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20); - DDrPatch_Byte((char*)(OniExe + 0x00020f4a), 0x40); -} - -// Disable Oni's internal CLrGetCommandLine function (to eventually replace it with our own) -void DD_Patch_GetCmdLine() -{ - DDrPatch_NOOP ((char*)(OniExe + 0x000d3280), 51); -} - -// Allow HD screens with resolution < 1024*768 -void DD_Patch_HDScreens_LowRes() -{ - DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap); -} - -void DD_Patch_HighresConsole() { - Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize); -} - -// Hackish fix for Konoko not kicking guns -// Don't use this, it breaks stairs. -void DD_Patch_KickGuns() -{ - 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 }; - DDrPatch_Const ((char*)(OniExe + 0x000dc420), kickgun_patch); -} - -// Disable loading the vtuneapi.dll -void DD_Patch_KillVTune() -{ - DDrPatch_Byte ((char*)(OniExe + 0x00026340), 0xC3); -} - -// Now supports textures up to 512x512 -void DD_Patch_LargeTextures() -{ - DDrPatch_Byte ((char*)(OniExe + 0x00005251), 0x10); -} - -// Non-"_Final" levels are now valid -void DD_Patch_LevelPlugins() -{ - DDrPatch_Byte ((char*)(OniExe + 0x000206a8), 0x01); -} - -// Weapon on ground shown with name and magazine contents -void DD_Patch_NewWeap() -{ - //Makes it always say "Received weapon_name." - //Needs check for loc_4DFC66 - //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2); - - //Adds Weapon name and ammo meter to pickup autoprompt - DDrPatch_NOOP((char*)(OniExe + 0x000FAC73), 9); - DDrPatch_NOOP((char*)(OniExe + 0x000FAC80), 5); - DDrPatch_MakeCall((void*)(OniExe + 0xFAC85), (void*)DDrWeapon2Message); - - //Moves location of colors - //DDrPatch_Int32((int*)(OniExe + 0x0002E3D5), (int)&DDrDSayColors ); - //DDrPatch_Int32((int*)(OniExe + 0x0002E3DA), (int)&DDrDSayColors ); -} - -// Disable Multi-byte character awareness patch (multiple language support) -void DD_Patch_NoMultiByte() -{ - DDrPatch_Byte ((char*)(OniExe + 0x0002d8f8), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002d9ad), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002dbe2), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002dec3), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e2ab), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e2c4), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e379), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e48c), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e4d0), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e4f4), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e646), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e695), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e944), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e95d), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e98e), 0xeb); - DDrPatch_Byte ((char*)(OniExe + 0x0002e9dc), 0xeb); -} - -// Fix options not visible in main menu when a game was started -void DD_Patch_OptionsVisible() -{ - DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton); - DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton); -} - -// Unlocks particle action disabling/enabling bits for all events. (Will be -// controlled by a command line switch when I figure out how to do that without -// Win32 hacks.) -void DD_Patch_ParticleDisableBit() -{ - DDrPatch_Int16 ((short*)(OniExe + 0x001b184), 0x9090); -} - -// Pathfinding grid cache size x8 -void DD_Patch_PathFinding() -{ - const unsigned char pathfinding[2] = {0x90 , 0xE9 }; - DDrPatch_Byte ((char*)(OniExe + 0x0010b03b), 0x20); - DDrPatch_Byte ((char*)(OniExe + 0x0010b04c), 0x20); - - //other stuff - DDrPatch_Const((char*)(OniExe + 0x00040789), pathfinding); -} - -// Projectile awareness fixed -void DD_Patch_ProjAware() -{ - DDrPatch_Byte ((char*)(OniExe + 0x0009c07c), 0x6c); - DDrPatch_Byte ((char*)(OniExe + 0x0009c080), 0x70); - DDrPatch_Byte ((char*)(OniExe + 0x0009c084), 0x74); - DDrPatch_Byte ((char*)(OniExe + 0x0009c110), 0x6c); -} - -// Safe startup message printer -void DD_Patch_SafePrintf() -{ - DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage); -} - -// Show all (also enemies') lasersights -void DD_Patch_ShowAllLasersights() -{ - DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 ); -} - -void DD_Patch_ShowTriggerVolumes() -{ - Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register); - Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput); -} - -// Experiment with allowing enemies to be thrown over railings -void DD_Patch_Throwtest() -{ - const unsigned char throwtest_patch[] = { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }; - DDrPatch_Const((char*)(OniExe + 0x000dc190), throwtest_patch); -} - -// DaodanGL with windowed mode support -void DD_Patch_UseDaodanGL() -{ - // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect. - DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6); - DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect); - - // UUrWindow_GetSize: GetWindowRect -> GetClientRect. - DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6); - DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect); - // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates. - DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6); - DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos); - // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates. - DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6); - DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos); - - // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates. - DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6); - DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos); - - // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates. - DDrPatch_NOOP((char*) OniExe + 0x00003349, 6); - DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos); - - // Replace ONrPlatformInitialize. - DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize); - - // Replace gl_platform_initialize. - DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize); - - // Replace gl_platform_dispose. - DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose); -} - -// Performance patch -void DD_Patch_UseGetTickCount() -{ - DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High); - DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency); - DDrPatch_MakeJump((void*)UUrMachineTime_Sixtieths, (void*)DDrMachineTime_Sixtieths); -} - -// Adds working function for existing BSL command wp_fadetime, sets fade time to 4800 -void DD_Patch_WpFadetime() -{ - // Makes wp_fadetime actually have a function - const unsigned char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 }; - DDrPatch_Const ((char*)(OniExe + 0x0011a889), fadetime_patch); - DDrPatch_Byte ((char*)(OniExe + 0x0011a560), 0x31); - - // Sets the fadetime to 4800 by default - DDrPatch_Int16 ((short*)(OniExe + 0x0011ab0e), 0x12c0); -} - -// Disable gamma slider in options in windowed mode -void DD_Patch_GammaSlider() +int DD_Patch_DebugNameTextureInit(short width, short height, int type, int allocated, int flags, char* name, void** output) { - DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange); + //flags = (1 << 10); + type = 1; + //DDrPatch_Byte( 0x005EB83C + 3, 0xff ); + DDrPatch_Int32((int*)(OniExe + 0x001EB83C), 0xFF000000 ); + return M3rTextureMap_New(width, height, type, allocated, flags, name, output); } -// Fix the warning print method -void DD_Patch_PrintWarning() +short DD_Patch_DebugNameShadeHack( Character* Char ) { - DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning); + return TSrContext_SetShade(*(void**)(OniExe + 0x001EB844), ONrCharacter_GetHealthShade( Char->Health, Char->MaxHealth )); } //Fix crappy ai2_shownames @@ -598,130 +276,349 @@ void DD_Patch_ShowNames() */ } -/* -void DD_Patch_ShowTriggerVolumes() -{ - DDrPatch_Int32((int*)(OniExe + 0x000cc9bb+4), (uint32_t)DD_OBJiTriggerVolume_Draw); -} -void DD_Patch_ShowFlags() -{ - DDrPatch_Int32((int*)(OniExe + 0x000c4ed4+4), (uint32_t)DD_OBJiFlag_Draw); -} -*/ + + + + + + bool DD_Patch_Init() { STARTUPMESSAGE("Patching engine", 0); + // Disable UUrPlatform_Initalize/Terminate, this enables the Alt-Tab and the + // Windows key but has the possible side effect of allowing the screensaver + // to enable itself in-game. if (DDrConfig_GetOptOfType("patches.alttab", C_BOOL)->value.intBoolVal) - DD_Patch_AltTab(); + { + // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start + DDrPatch_Byte((char*)UUrPlatform_Initialize, 0xC3); + DDrPatch_Byte((char*)UUrPlatform_Terminate, 0xC3); + } + // Textures using ARGB8888 can be used if (DDrConfig_GetOptOfType("patches.argb8888", C_BOOL)->value.intBoolVal) - DD_Patch_ARGB8888(); + { + // Update conversion lookups in IMgConvertPixelType_List + DDrPatch_Byte((char*)(OniExe + 0x00135af0), 0x07); + DDrPatch_Byte((char*)(OniExe + 0x00135af4), 0x0B); + } + // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting + // instead of DirectDraw; patch ONiRunGame to use the same method to play + // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the + // latter has problems on WINE). if (DDrConfig_GetOptOfType("patches.binkplay", C_BOOL)->value.intBoolVal) - DD_Patch_BinkPlay(); - - if (DDrConfig_GetOptOfType("patches.bsl", C_BOOL)->value.intBoolVal) - DD_Patch_BSL(); + { + // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION. + DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02); + // call ONrMovie_Play_Hardware -> call ONrMovie_Play + DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play); + } - if (DDrConfig_GetOptOfType("patches.cheater", C_BOOL)->value.intBoolVal) - DD_Patch_Cheater(); + if (DDrConfig_GetOptOfType("patches.d_regen", C_BOOL)->value.intBoolVal) + DD_Patch_Regeneration(); + // Cheats always enabled if (DDrConfig_GetOptOfType("patches.cheatsenabled", C_BOOL)->value.intBoolVal) - DD_Patch_CheatsEnabled(); + { + DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame); + } + // Use Daodan's own cheattable if (DDrConfig_GetOptOfType("patches.cheattable", C_BOOL)->value.intBoolVal) - DD_Patch_CheatTable(); + { + // In ONrGameState_HandleCheats: Replace pointers to orig cheattable + DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name); + DDrPatch_Int32 ((int*)(OniExe + 0x000f617a), (int)&DDr_CheatTable[0].message_on); + + // ONrGameState_HandleCheats: Replace call to ONrCheater + DDrPatch_MakeCall((void*)(OniExe + 0x000f618f), (void*)DDrCheater); + + // In: ONrGameState_DoCharacterFrame + // -> NOP; PUSH ebp; CALL FallingFrames + // Replace fall height frame counter (actually in-air frame counter) increase by a + // conditional one (only counted when inc_fallingframes) + DDrPatch_Int16((short*)(OniExe + 0x000deb45), 0x5590); + DDrPatch_MakeCall((void*)(OniExe + 0x000deb47), (void*)FallingFrames); + + // At end of ONrUnlockLevel to init values on level loading + DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad); + } if (DDrConfig_GetOptOfType("patches.chinese", C_BOOL)->value.intBoolVal) DD_Patch_Chinese(); + // Limit cursor to Oni's window if (DDrConfig_GetOptOfType("patches.clipcursor", C_BOOL)->value.intBoolVal) - DD_Patch_ClipCursor(); + { + // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook. + DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set); + // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook. + DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set); + + // LIrTerminate: replace LIrPlatform_Terminate call with our hook. + DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate); + } + + // Disables weapon cooldown exploit if (DDrConfig_GetOptOfType("patches.cooldowntimer", C_BOOL)->value.intBoolVal) - DD_Patch_CooldownTimer(); + { + // In WPrRelease: NoOp 4 MOVs + DDrPatch_NOOP((char*)(OniExe + 0x0011a825), 22); + } + // Daodan device mode enumeration function if (DDrConfig_GetOptOfType("patches.daodandisplayenum", C_BOOL)->value.intBoolVal) - DD_Patch_DaodanDisplayEnum(); + { + DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes); + } + // Forced DirectInput (for Windows NT) if (DDrConfig_GetOptOfType("patches.directinput", C_BOOL)->value.intBoolVal) - DD_Patch_DirectInput(); + { + // LIrPlatform_Initialize: replace conditional jump by unconditional + DDrPatch_Byte((char*)(OniExe + 0x00002e6d), 0xeb); + } + // Disable Oni's command line parser so it doesn't interfere with ours if (DDrConfig_GetOptOfType("patches.disablecmdline", C_BOOL)->value.intBoolVal) - DD_Patch_DisableCmdLine(); + { + // Replace start of OniParseCommandLine with XOR eax,eax; RET + DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033); + // NoOp first 51 byte in ONiMain, including tests and conditional exec of CLrGetCommandLine + DDrPatch_NOOP((char*)(OniExe + 0x000d3280), 51); + } + // Font texture cache doubled if (DDrConfig_GetOptOfType("patches.fonttexturecache", C_BOOL)->value.intBoolVal) - DD_Patch_FontTextureCache(); - - if (DDrConfig_GetOptOfType("patches.getcmdline", C_BOOL)->value.intBoolVal) - DD_Patch_GetCmdLine(); + { + // Double two values in TMrGame_Initialize + DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20); + DDrPatch_Byte((char*)(OniExe + 0x00020f4a), 0x40); + } + // Allow HD screens on resolutions < 1024*768 if (DDrConfig_GetOptOfType("patches.hdscreens_lowres", C_BOOL)->value.intBoolVal) - DD_Patch_HDScreens_LowRes(); + { + DDrPatch_MakeJump((void*)M3rDraw_BigBitmap, (void*)DD_M3rDraw_BigBitmap); + } + // Allow for console to show on higher resolutions if (DDrConfig_GetOptOfType("patches.highres_console", C_BOOL)->value.intBoolVal) - DD_Patch_HighresConsole(); + { + Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize); + } + // Hackish fix for Konoko not kicking guns + // Don't use this, it breaks stairs. if (DDrConfig_GetOptOfType("patches.kickguns", C_BOOL)->value.intBoolVal) - DD_Patch_KickGuns(); + { + // In ONrCharacter_EnablePhysics: Load different values to same addresses as before + 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 }; + DDrPatch_Const ((char*)(OniExe + 0x000dc420), kickgun_patch); + } - //if (patch_killvtune) - // DD_Patch_KillVTune(); + // Disable loading the vtuneapi.dll + if (DDrConfig_GetOptOfType("patches.killvtune", C_BOOL)->value.intBoolVal) + { + // Instantly return from UUrLoadVtuneAPI + DDrPatch_Byte((char*)(OniExe + 0x00026340), 0xC3); + } + // Now supports textures up to 512x512 if (DDrConfig_GetOptOfType("patches.largetextures", C_BOOL)->value.intBoolVal) - DD_Patch_LargeTextures(); + { + DDrPatch_Byte((char*)(OniExe + 0x00005251), 0x10); + } + // Non-"_Final" levels are now valid if (DDrConfig_GetOptOfType("patches.levelplugins", C_BOOL)->value.intBoolVal) - DD_Patch_LevelPlugins(); + { + // Patch in TMrUtility_LevelInfo_Get: + DDrPatch_Byte((char*)(OniExe + 0x000206a8), 0x01); + } + // Weapon on ground shown with name and magazine contents if (DDrConfig_GetOptOfType("patches.newweap", C_BOOL)->value.intBoolVal) - DD_Patch_NewWeap(); + { + //Makes it always say "Received weapon_name." + //Needs check for loc_4DFC66 + //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2); + + //Adds Weapon name and ammo meter to pickup autoprompt (patches to ONrGameState_ProcessHeartbeat) + // Do not call WPrHasAmmo and ignore conditional jump: + DDrPatch_NOOP((char*)(OniExe + 0x000FAC73), 9); + // Do not load ecx with some magic value? + DDrPatch_NOOP((char*)(OniExe + 0x000FAC80), 5); + // Replace call to ONiGameState_FindAutoPromptMessage + DDrPatch_MakeCall((void*)(OniExe + 0xFAC85), (void*)DDrWeapon2Message); + + //Moves location of colors + //DDrPatch_Int32((int*)(OniExe + 0x0002E3D5), (int)&DDrDSayColors ); + //DDrPatch_Int32((int*)(OniExe + 0x0002E3DA), (int)&DDrDSayColors ); + } + // Disable Multi-byte character awareness patch (multiple language support) if (DDrConfig_GetOptOfType("patches.nomultibyte", C_BOOL)->value.intBoolVal) - DD_Patch_NoMultiByte(); + { + // TSiContext_DrawLine: Replace conditional jumps by unconditional ones + DDrPatch_Byte ((char*)(OniExe + 0x0002d8f8), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002d9ad), 0xeb); + // TSiContext_DrawTextLine: same + DDrPatch_Byte ((char*)(OniExe + 0x0002dbe2), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002dec3), 0xeb); + // TSrContext_FormatString: same + DDrPatch_Byte ((char*)(OniExe + 0x0002e2ab), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e2c4), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e379), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e48c), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e4d0), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e4f4), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e646), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e695), 0xeb); + // TSrContext_GetStringRect: same + DDrPatch_Byte ((char*)(OniExe + 0x0002e944), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e95d), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e98e), 0xeb); + DDrPatch_Byte ((char*)(OniExe + 0x0002e9dc), 0xeb); + } + // Fix options not visible in main menu when a game was started if (DDrConfig_GetOptOfType("patches.optionsvisible", C_BOOL)->value.intBoolVal) - DD_Patch_OptionsVisible(); + { + // replace WMrWindow_SetVisible calls + DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton); + DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton); + } - if (DDrConfig_GetOptOfType("patches.particledisablebit", C_BOOL)->value.intBoolVal) - DD_Patch_ParticleDisableBit(); - + // Pathfinding grid cache size x8 if (DDrConfig_GetOptOfType("patches.pathfinding", C_BOOL)->value.intBoolVal) - DD_Patch_PathFinding(); + { + // Replaces conditional jump (je) with unconditional jump + const unsigned char pathfinding[2] = {0x90 , 0xE9 }; + DDrPatch_Byte ((char*)(OniExe + 0x0010b03b), 0x20); + DDrPatch_Byte ((char*)(OniExe + 0x0010b04c), 0x20); + + //other stuff + DDrPatch_Const((char*)(OniExe + 0x00040789), pathfinding); + } + // Projectile awareness fixed if (DDrConfig_GetOptOfType("patches.projaware", C_BOOL)->value.intBoolVal) - DD_Patch_ProjAware(); + { + DDrPatch_Byte ((char*)(OniExe + 0x0009c07c), 0x6c); + DDrPatch_Byte ((char*)(OniExe + 0x0009c080), 0x70); + DDrPatch_Byte ((char*)(OniExe + 0x0009c084), 0x74); + DDrPatch_Byte ((char*)(OniExe + 0x0009c110), 0x6c); + } + // Safe startup message printer if (DDrConfig_GetOptOfType("patches.safeprintf", C_BOOL)->value.intBoolVal) - DD_Patch_SafePrintf(); + { + DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage); + } + // Show all (also enemies') lasersights if (DDrConfig_GetOptOfType("patches.showalllasersights", C_BOOL)->value.intBoolVal) - DD_Patch_ShowAllLasersights(); + { + DDrPatch_NOOP((char*)(OniExe + 0x000E1957), 6 ); + } + // Allow bsl-var show_triggervolumes or ctrl+shift+x (devmode) to work if (DDrConfig_GetOptOfType("patches.showtriggervolumes", C_BOOL)->value.intBoolVal) - DD_Patch_ShowTriggerVolumes(); + { + Oni_ONrMechanics_Register = DDrPatch_MakeDetour((void*)ONrMechanics_Register, (void*)DD_ONrMechanics_Register); + Oni_ONrGameState_HandleUtilityInput = DDrPatch_MakeDetour((void*)ONrGameState_HandleUtilityInput, (void*)DD_ONrGameState_HandleUtilityInput); + } + // Experiment with allowing enemies to be thrown over railings if (DDrConfig_GetOptOfType("patches.throwtest", C_BOOL)->value.intBoolVal) - DD_Patch_Throwtest(); + { + DDrPatch_NOOP((char*)(OniExe + 0x000dc190), 10); + } + // DaodanGL with windowed mode support if (DDrConfig_GetOptOfType("patches.usedaodangl", C_BOOL)->value.intBoolVal) - DD_Patch_UseDaodanGL(); + { + // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect. + DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6); + DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect); + + // UUrWindow_GetSize: GetWindowRect -> GetClientRect. + DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6); + DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect); + + // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates. + DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6); + DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos); + + // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates. + DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6); + DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos); + + // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates. + DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6); + DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos); + + // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates. + DDrPatch_NOOP((char*) OniExe + 0x00003349, 6); + DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos); + + // Replace ONrPlatformInitialize. + DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize); + + // Replace gl_platform_initialize. + DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize); + // Replace gl_platform_dispose. + DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose); + } + + // Performance patch if (DDrConfig_GetOptOfType("patches.usegettickcount", C_BOOL)->value.intBoolVal) - DD_Patch_UseGetTickCount(); + { + DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High); + DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency); + DDrPatch_MakeJump((void*)UUrMachineTime_Sixtieths, (void*)DDrMachineTime_Sixtieths); + } + + // Fix displaying the talking portraits in widescreen modes + if (DDrConfig_GetOptOfType("patches.widescreenportraits", C_BOOL)->value.intBoolVal) + { + SLrDaodan_Patch(); + } + // Adds working function for existing BSL command wp_fadetime, sets fade time to 4800 if (DDrConfig_GetOptOfType("patches.wpfadetime", C_BOOL)->value.intBoolVal) - DD_Patch_WpFadetime(); - + { + // Makes wp_fadetime actually have a function (changes within WPrRelease) + // Patches end of function to instead of use a constant value for fadetime (12c0 = 4800) actually use value of wp_fadetime: + // orig: MOV [esi+0x46], 0x12c0 ; POP ebx ; POP esi ; ADD esp, 0x14 ; RET + // new: MOV bx, [0x627dc4] ; MOV [esi+0x46], bx ; POP ebx ; POP esi ; ADD esp, 0x14 ; RET + const unsigned char fadetime_patch[] = { 0x66, 0x8B, 0x1D, 0xC4, 0x7D, 0x62, 0x00, 0x66, 0x89, 0x5E, 0x46, 0x5B, 0x5E, 0x83, 0xC4, 0x14, 0xC3 }; + DDrPatch_Const ((char*)(OniExe + 0x0011a889), fadetime_patch); + // Fixes jump because of new length of code in patch + DDrPatch_Byte ((char*)(OniExe + 0x0011a560), 0x31); + + // Sets the fadetime to 4800 by default (in WPrInitialize) + DDrPatch_Int16 ((short*)(OniExe + 0x0011ab0e), 4800); + } - DD_Patch_DaodanInit(); + // Adds new BSL functions + // Replaces an early unused call (OBJrLevel_Unload_Unknown_2) in ONiMain + DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init); - DD_Patch_GammaSlider(); + // Disable gamma slider in options in windowed mode + // In ONiOGU_Options_Callback: Replace WMrSlider_SetRange + DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange); - DD_Patch_PrintWarning(); + // Fix the warning print method + // Replace UUrError_Report_Internal + DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning); DD_Patch_ShowNames();