--- Daodan/src/Patches/Patches.c 2014/04/09 00:10:18 995 +++ Daodan/src/Patches/Patches.c 2015/03/23 23:29:19 1017 @@ -5,6 +5,7 @@ #include "Cheater.h" #include "../Daodan_Config.h" #include "GL.h" +#include "Input.h" #include "../Daodan_Patch.h" #include "Utility.h" #include "Win32.h" @@ -17,7 +18,7 @@ typedef int (__cdecl *CHINESEPROC)(DWORD // slider in windowed mode. static void ONICALL DD_ONiOGU_GammaSlider_SetRange(void* window, int min_value, int max_value) { - ConfigOption_t* co = DDrConfig_GetOptOfType("options.gamma", C_BOOL); + ConfigOption_t* co = DDrConfig_GetOptOfType("graphics.gamma", C_BOOL); WMrWindow_SetEnabled(window, M3gResolutionSwitch && co->value.intBoolVal); WMrSlider_SetRange(window, min_value, max_value); } @@ -84,7 +85,7 @@ void ONICALL DDrShowOptionsButton(void* void ONICALL DDrGame_Init() { - if (DDrConfig_GetOptOfType("patches.usedaodanbsl", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("modding.daodanbsl", C_BOOL)->value.intBoolVal) SLrDaodan_Initialize(); } @@ -131,6 +132,8 @@ int16_t ONICALL DD_COrTextArea_Resize(vo return Oni_COrTextArea_Resize(inTextArea, inBounds, inNumTextEntries); } + + #define IMcShade_Red (0xFFFF0000) #define IMcShade_Green (0xFF00FF00) #define IMcShade_Blue (0xFF0000FF) @@ -277,7 +280,29 @@ void DD_Patch_ShowNames() } - +void DD_Patch_CharacterAwareness() +{ + const unsigned char patch[] = + { + 0x52, // 0: push edx + 0xBA, 0xA0, 0x16, 0x00, 0x00, // 1: mov edx,0x16a0 + 0x89, 0xF8, // 6: mov eax,edi + 0xF7, 0xE2, // 8: mul edx + 0x89, 0xC2, // a: mov edx,eax + 0xE8, 0x00, 0x00, 0x00, 0x00, // c: call ONrGameState_LivingCharacterList_Get (-> OniExe + 0x000fca90) + 0x8B, 0x00, // 11: mov eax,[eax] + 0x01, 0xD0, // 13: add eax,edx + 0x89, 0xC6, // 15: mov esi,eax + 0x5A, // 17: pop edx + 0x8B, 0x46, 0x04, // 18: (ORIG) mov eax, dword [ds:esi+0x4] + 0xF6, 0xC4, 0x80 // 1b: (ORIG) test ah, 0x80 + }; + void* newCode = DDrPatch_ExecutableASM((char*)(OniExe + 0x0009A609), (char*)(OniExe + 0x0009A60F), patch, sizeof(patch)); + if ((int)newCode > 0) { + DDrPatch_MakeCall((char*)(newCode+0xC), (char*)(OniExe + 0x000FCA90)); + DDrPatch_NOOP((char*)(OniExe + 0x0009A60E), 1); + } +} @@ -291,7 +316,7 @@ bool DD_Patch_Init() // 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) + if (DDrConfig_GetOptOfType("windows.alttab", C_BOOL)->value.intBoolVal) { // 0xC3 = ret, so makes those functions just have a "ret" instruction at their start DDrPatch_Byte((char*)UUrPlatform_Initialize, 0xC3); @@ -299,7 +324,7 @@ bool DD_Patch_Init() } // Textures using ARGB8888 can be used - if (DDrConfig_GetOptOfType("patches.argb8888", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("modding.argb8888", C_BOOL)->value.intBoolVal) { // Update conversion lookups in IMgConvertPixelType_List DDrPatch_Byte((char*)(OniExe + 0x00135af0), 0x07); @@ -310,7 +335,7 @@ bool DD_Patch_Init() // 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) + if (DDrConfig_GetOptOfType("graphics.binkplay", C_BOOL)->value.intBoolVal) { // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION. DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02); @@ -318,17 +343,20 @@ bool DD_Patch_Init() DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play); } - if (DDrConfig_GetOptOfType("patches.d_regen", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("modding.d_regen", C_BOOL)->value.intBoolVal) DD_Patch_Regeneration(); + if (DDrConfig_GetOptOfType("gameplay.characterawareness", C_BOOL)->value.intBoolVal) + DD_Patch_CharacterAwareness(); + // Cheats always enabled - if (DDrConfig_GetOptOfType("patches.cheatsenabled", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("gameplay.cheatsenabled", C_BOOL)->value.intBoolVal) { DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame); } // Use Daodan's own cheattable - if (DDrConfig_GetOptOfType("patches.cheattable", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("gameplay.cheattable", C_BOOL)->value.intBoolVal) { // In ONrGameState_HandleCheats: Replace pointers to orig cheattable DDrPatch_Int32 ((int*)(OniExe + 0x000f616b), (int)&DDr_CheatTable[0].name); @@ -346,13 +374,18 @@ bool DD_Patch_Init() // At end of ONrUnlockLevel to init values on level loading DDrPatch_MakeJump((void*)(OniExe + 0x0010f021), (void*)DDrCheater_LevelLoad); + + if (DDrConfig_GetOptOfType("gameplay.bindablecheats", C_BOOL)->value.intBoolVal) + { + InitBindableCheats(); + } } - if (DDrConfig_GetOptOfType("patches.chinese", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("language.chinese", C_BOOL)->value.intBoolVal) DD_Patch_Chinese(); // Limit cursor to Oni's window - if (DDrConfig_GetOptOfType("patches.clipcursor", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("windows.clipcursor", C_BOOL)->value.intBoolVal) { // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook. DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set); @@ -365,27 +398,27 @@ bool DD_Patch_Init() } // Disables weapon cooldown exploit - if (DDrConfig_GetOptOfType("patches.cooldowntimer", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("gameplay.cooldowntimer", C_BOOL)->value.intBoolVal) { // 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) + if (DDrConfig_GetOptOfType("graphics.displayenum", C_BOOL)->value.intBoolVal) { 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) + if (DDrConfig_GetOptOfType("windows.directinput", C_BOOL)->value.intBoolVal) { // 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) + if (DDrConfig_GetOptOfType("windows.disablecmdline", C_BOOL)->value.intBoolVal) { // Replace start of OniParseCommandLine with XOR eax,eax; RET DDrPatch_Int32 ((int*)(OniExe + 0x000d3570), 0x00c3c033); @@ -394,7 +427,7 @@ bool DD_Patch_Init() } // Font texture cache doubled - if (DDrConfig_GetOptOfType("patches.fonttexturecache", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("language.fonttexturecache", C_BOOL)->value.intBoolVal) { // Double two values in TMrGame_Initialize DDrPatch_Byte((char*)(OniExe + 0x00020ea7), 0x20); @@ -402,20 +435,26 @@ bool DD_Patch_Init() } // Allow HD screens on resolutions < 1024*768 - if (DDrConfig_GetOptOfType("patches.hdscreens_lowres", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("modding.hdscreens_lowres", C_BOOL)->value.intBoolVal) { 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) + if (DDrConfig_GetOptOfType("devmode.highres_console", C_BOOL)->value.intBoolVal) { Oni_COrTextArea_Resize = DDrPatch_MakeDetour((void*)COrTextArea_Resize, (void*)DD_COrTextArea_Resize); } + // Allow custom actions to be bound through Daodan + if (DDrConfig_GetOptOfType("gameplay.customactions", C_BOOL)->value.intBoolVal) + { + Input_PatchCode (); + } + // Hackish fix for Konoko not kicking guns // Don't use this, it breaks stairs. - if (DDrConfig_GetOptOfType("patches.kickguns", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("gameplay.kickguns", C_BOOL)->value.intBoolVal) { // 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 }; @@ -423,27 +462,27 @@ bool DD_Patch_Init() } // Disable loading the vtuneapi.dll - if (DDrConfig_GetOptOfType("patches.killvtune", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("windows.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) + if (DDrConfig_GetOptOfType("modding.largetextures", C_BOOL)->value.intBoolVal) { DDrPatch_Byte((char*)(OniExe + 0x00005251), 0x10); } // Non-"_Final" levels are now valid - if (DDrConfig_GetOptOfType("patches.levelplugins", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("modding.levelplugins", C_BOOL)->value.intBoolVal) { // 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) + if (DDrConfig_GetOptOfType("graphics.newweap", C_BOOL)->value.intBoolVal) { //Makes it always say "Received weapon_name." //Needs check for loc_4DFC66 @@ -463,7 +502,7 @@ bool DD_Patch_Init() } // Disable Multi-byte character awareness patch (multiple language support) - if (DDrConfig_GetOptOfType("patches.nomultibyte", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("language.nomultibyte", C_BOOL)->value.intBoolVal) { // TSiContext_DrawLine: Replace conditional jumps by unconditional ones DDrPatch_Byte ((char*)(OniExe + 0x0002d8f8), 0xeb); @@ -488,7 +527,7 @@ bool DD_Patch_Init() } // Fix options not visible in main menu when a game was started - if (DDrConfig_GetOptOfType("patches.optionsvisible", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("graphics.optionsvisible", C_BOOL)->value.intBoolVal) { // replace WMrWindow_SetVisible calls DDrPatch_MakeCall((void*)(OniExe + 0x000d2d2d), DDrShowOptionsButton); @@ -496,7 +535,7 @@ bool DD_Patch_Init() } // Pathfinding grid cache size x8 - if (DDrConfig_GetOptOfType("patches.pathfinding", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("gameplay.pathfinding", C_BOOL)->value.intBoolVal) { // Replaces conditional jump (je) with unconditional jump const unsigned char pathfinding[2] = {0x90 , 0xE9 }; @@ -508,7 +547,7 @@ bool DD_Patch_Init() } // Projectile awareness fixed - if (DDrConfig_GetOptOfType("patches.projaware", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("gameplay.projaware", C_BOOL)->value.intBoolVal) { DDrPatch_Byte ((char*)(OniExe + 0x0009c07c), 0x6c); DDrPatch_Byte ((char*)(OniExe + 0x0009c080), 0x70); @@ -517,32 +556,32 @@ bool DD_Patch_Init() } // Safe startup message printer - if (DDrConfig_GetOptOfType("patches.safeprintf", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("windows.safeprintf", C_BOOL)->value.intBoolVal) { DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage); } // Show all (also enemies') lasersights - if (DDrConfig_GetOptOfType("patches.showalllasersights", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("graphics.showalllasersights", C_BOOL)->value.intBoolVal) { 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) + if (DDrConfig_GetOptOfType("devmode.showtriggervolumes", C_BOOL)->value.intBoolVal) { 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) + if (DDrConfig_GetOptOfType("gameplay.throwtest", C_BOOL)->value.intBoolVal) { DDrPatch_NOOP((char*)(OniExe + 0x000dc190), 10); } // DaodanGL with windowed mode support - if (DDrConfig_GetOptOfType("patches.usedaodangl", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("graphics.daodangl", C_BOOL)->value.intBoolVal) { // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect. DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6); @@ -579,7 +618,7 @@ bool DD_Patch_Init() } // Performance patch - if (DDrConfig_GetOptOfType("patches.usegettickcount", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("windows.usegettickcount", C_BOOL)->value.intBoolVal) { DDrPatch_MakeJump((void*)UUrMachineTime_High, (void*)DDrMachineTime_High); DDrPatch_MakeJump((void*)UUrMachineTime_High_Frequency, (void*)DDrMachineTime_High_Frequency); @@ -587,13 +626,13 @@ bool DD_Patch_Init() } // Fix displaying the talking portraits in widescreen modes - if (DDrConfig_GetOptOfType("patches.widescreenportraits", C_BOOL)->value.intBoolVal) + if (DDrConfig_GetOptOfType("graphics.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) + if (DDrConfig_GetOptOfType("gameplay.wpfadetime", C_BOOL)->value.intBoolVal) { // 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: