From 7db48e99cffaaa8119a89f11e6f1497760f1292f Mon Sep 17 00:00:00 2001 From: Sku-111 Date: Sat, 4 Nov 2023 22:35:37 +0100 Subject: [PATCH] added debug_output, update for weapefs, enabled jump_height dvar update for custom weapondef loading/dumping by jydenx added debug_output with print_debug dvar by staturnz enabled functionality for jump_height dvar --- hook_lib/Main.cpp | 3 ++- hook_lib/debug_output.cpp | 34 ++++++++++++++++++++++++++++ hook_lib/debug_output.h | 5 +++++ hook_lib/dvar.cpp | 4 ++++ hook_lib/dvar.h | 4 +++- hook_lib/functions.cpp | 5 +++-- hook_lib/functions.hpp | 3 ++- hook_lib/gamemode.cpp | 4 ++-- hook_lib/hook_lib.vcxproj | 2 ++ hook_lib/hook_lib.vcxproj.filters | 6 +++++ hook_lib/lui_cod.cpp | 2 ++ hook_lib/patch.cpp | 6 +++++ hook_lib/screen.cpp | 3 +++ hook_lib/weapons.cpp | 37 +++++++++++++++++++++++++++++-- 14 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 hook_lib/debug_output.cpp create mode 100644 hook_lib/debug_output.h diff --git a/hook_lib/Main.cpp b/hook_lib/Main.cpp index 91b4c5d..0842f22 100644 --- a/hook_lib/Main.cpp +++ b/hook_lib/Main.cpp @@ -1,5 +1,6 @@ #include "Main.hpp" #include "game_inc.h" +#include "debug_output.h" #include "addr_utils.hpp" @@ -54,7 +55,7 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD Reason, LPVOID lpVoid) printf("Base Address: %p\n", 0_b); - addCustomDvars(); + debug_output_init(nullptr); addCustomCmds(); patchGame(); diff --git a/hook_lib/debug_output.cpp b/hook_lib/debug_output.cpp new file mode 100644 index 0000000..30304b7 --- /dev/null +++ b/hook_lib/debug_output.cpp @@ -0,0 +1,34 @@ +#include "debug_output.h" +#include "Main.hpp" +#include "game_inc.h" +#include "addr_utils.hpp" + +FILE* debug_file; + +void debug_output(const char* buf) +{ + if (gameInitialized == true) + { + if (Dvar_GetBoolSafe("print_debug")) + { + printf(buf); + if (debug_file != NULL) + { + fprintf(debug_file, buf); + } + } + } +} + +utils::hook::detour com_printmessageinternal; +void Com_PrintMessageInternal_Detour(int channel, const char* text, int param_3) +{ + debug_output(text); + com_printmessageinternal.stub(channel, text, param_3); +} + +void debug_output_init(const char* output_file) { + if (output_file != NULL) debug_file = fopen(output_file, "w+"); + + com_printmessageinternal.create(0x1412B0660_g, Com_PrintMessageInternal_Detour); +} \ No newline at end of file diff --git a/hook_lib/debug_output.h b/hook_lib/debug_output.h new file mode 100644 index 0000000..17b77b6 --- /dev/null +++ b/hook_lib/debug_output.h @@ -0,0 +1,5 @@ +#pragma once + +inline bool gameInitialized = false; + +void debug_output_init(const char* output_file); \ No newline at end of file diff --git a/hook_lib/dvar.cpp b/hook_lib/dvar.cpp index 3702ca0..d7d3bf9 100644 --- a/hook_lib/dvar.cpp +++ b/hook_lib/dvar.cpp @@ -31,3 +31,7 @@ dvar_t* Dvar_FindVarByName_Detour(const char* dvarName) return ret; } +bool CheatsEnabled() +{ + return sv_cheats->current.enabled; +} \ No newline at end of file diff --git a/hook_lib/dvar.h b/hook_lib/dvar.h index d326a6a..c6c5b69 100644 --- a/hook_lib/dvar.h +++ b/hook_lib/dvar.h @@ -10,4 +10,6 @@ inline utils::hook::detour dvar_registerstring; dvar_t* Dvar_RegisterString_Detour(const char* dvarName, const char* value, unsigned int flags, const char* description); inline utils::hook::detour dvar_findvarbyname; -dvar_t* Dvar_FindVarByName_Detour(const char* dvarName); \ No newline at end of file +dvar_t* Dvar_FindVarByName_Detour(const char* dvarName); + +bool CheatsEnabled(); \ No newline at end of file diff --git a/hook_lib/functions.cpp b/hook_lib/functions.cpp index 21689ef..28ef946 100644 --- a/hook_lib/functions.cpp +++ b/hook_lib/functions.cpp @@ -144,8 +144,8 @@ unsigned __int64 I_atoui64(const char* str) { return func(str); } -uintptr_t Dvar_FindVarByName(const char* dvarName) { - auto func = reinterpret_cast(0x1413E63A0_g); +dvar_t* Dvar_FindVarByName(const char* dvarName) { + auto func = reinterpret_cast(0x1413E63A0_g); return func(dvarName); } @@ -520,6 +520,7 @@ dvar_t* sv_cheats; dvar_t* spawn_br_gas; dvar_t* show_watermark; dvar_t* player_sustainammo; +dvar_t* print_debug; cmd_function_s set_byte_f_VAR; cmd_function_s set_short_f_VAR; diff --git a/hook_lib/functions.hpp b/hook_lib/functions.hpp index 9a096af..9fe12c5 100644 --- a/hook_lib/functions.hpp +++ b/hook_lib/functions.hpp @@ -108,6 +108,7 @@ extern dvar_t* sv_cheats; extern dvar_t* spawn_br_gas; extern dvar_t* show_watermark; extern dvar_t* player_sustainammo; +extern dvar_t* print_debug; extern cmd_function_s set_byte_f_VAR; extern cmd_function_s set_short_f_VAR; @@ -164,7 +165,7 @@ unsigned __int64 Sys_Microseconds(); int I_irand(int min, int max); unsigned __int64 I_atoui64_hex(const char* str); unsigned __int64 I_atoui64(const char* str); -uintptr_t Dvar_FindVarByName(const char* dvarName); +dvar_t* Dvar_FindVarByName(const char* dvarName); void CL_DrawText(const uintptr_t scrPlace, const char* text, int maxChars, uintptr_t font, float x, float y, int horzAlign, int vertAlign, float xScale, float yScale, const float* color, int style); dvar_t* Dvar_RegisterString(const char* dvarName, const char* value, unsigned int flags, const char* description); diff --git a/hook_lib/gamemode.cpp b/hook_lib/gamemode.cpp index ced4e87..f0bf5bb 100644 --- a/hook_lib/gamemode.cpp +++ b/hook_lib/gamemode.cpp @@ -7,8 +7,8 @@ bool Com_GameMode_SupportsFeature_Detour(unsigned int featureID) if (com_timescale == nullptr && featureID == 70) { - com_timescale = (dvar_t*)Dvar_FindVarByName("LNOTRKNRPS"); - timescale = (dvar_t*)Dvar_FindVarByName("MSNTNLNQNM"); + com_timescale = Dvar_FindVarByName("LNOTRKNRPS"); + timescale = Dvar_FindVarByName("MSNTNLNQNM"); // fixes slowmotion final killcam, but not in an ideal way } diff --git a/hook_lib/hook_lib.vcxproj b/hook_lib/hook_lib.vcxproj index a67e5d8..0f7fc88 100644 --- a/hook_lib/hook_lib.vcxproj +++ b/hook_lib/hook_lib.vcxproj @@ -165,6 +165,7 @@ + @@ -209,6 +210,7 @@ + diff --git a/hook_lib/hook_lib.vcxproj.filters b/hook_lib/hook_lib.vcxproj.filters index 8db2e37..99614d2 100644 --- a/hook_lib/hook_lib.vcxproj.filters +++ b/hook_lib/hook_lib.vcxproj.filters @@ -139,6 +139,9 @@ hook_lib\game + + hook_lib\game + @@ -276,5 +279,8 @@ hook_lib\game + + hook_lib\game + \ No newline at end of file diff --git a/hook_lib/lui_cod.cpp b/hook_lib/lui_cod.cpp index 040ca52..50074c0 100644 --- a/hook_lib/lui_cod.cpp +++ b/hook_lib/lui_cod.cpp @@ -11,6 +11,8 @@ void LUI_CoD_RegisterDvars_Detour() player_sustainammo = Dvar_RegisterBool("player_sustainAmmo", false, 0, "Firing weapon will not decrease clip ammo."); + print_debug = Dvar_RegisterBool("print_debug", false, 0, "Print debug output to the external console"); + lui_cod_registerdvars.stub(); } diff --git a/hook_lib/patch.cpp b/hook_lib/patch.cpp index 33d0cc6..b227920 100644 --- a/hook_lib/patch.cpp +++ b/hook_lib/patch.cpp @@ -153,6 +153,9 @@ void hooks() utils::hook::jump(0x141609140_g, ProfanityFilter_IsBadWord_Detour); + // replacing Com_GameMode_GetActiveGameMode call with CheatsEnabled for jump_height dvar + utils::hook::call(0x14110195A_g, CheatsEnabled); + // remove FF Header version check // db_checkxfileversion.create(0x1411A7840_g, DB_CheckXFileVersion_Detour); } @@ -197,6 +200,9 @@ void patchGame() utils::hook::nop(0x141665289_g, 5); utils::hook::nop(0x14166567D_g, 5); + // enable functionality for jump_height dvar + utils::hook::set(0x141101946_g, 0xEB); + // remove FF Header version check // utils::hook::set(0x1411A776B_g, 0xEB); } \ No newline at end of file diff --git a/hook_lib/screen.cpp b/hook_lib/screen.cpp index 1ac26d2..1fe3bb4 100644 --- a/hook_lib/screen.cpp +++ b/hook_lib/screen.cpp @@ -1,5 +1,6 @@ #include "addr_utils.hpp" #include "screen.h" +#include "debug_output.h" void CG_DrawWaterMark() { @@ -12,6 +13,8 @@ void CL_ScreenMP_DrawOverlay_Detour() auto DevGui_Draw = reinterpret_cast(0x1417E5CD0_g); auto Con_DrawConsole = reinterpret_cast(0x1415AE0B0_g); + gameInitialized = true; + Con_DrawConsole(0); DevGui_Draw(0); diff --git a/hook_lib/weapons.cpp b/hook_lib/weapons.cpp index 7e635e0..8b7af01 100644 --- a/hook_lib/weapons.cpp +++ b/hook_lib/weapons.cpp @@ -37,7 +37,24 @@ void Dump_WeaponDef() { WeaponCompleteDef* weap = bg_weaponCompleteDefs[i]; if (!weap) continue; if (strstr(weap->szInternalName, "iw8") && !strstr(weap->szInternalName, "watch") && !strstr(weap->szInternalName, "execution") && !strstr(weap->szInternalName, "plyr")) { + // WeaponCompleteDef weaponDefJson[weap->szInternalName]["vfxImpactType"] = weap->vfxImpactType; + weaponDefJson[weap->szInternalName]["iClipSize"] = weap->iClipSize; + weaponDefJson[weap->szInternalName]["penetrateMultiplier"] = weap->penetrateMultiplier; + + // ZoomSettings + weaponDefJson[weap->szInternalName]["zoomSetting"]["weapon"]["adsZoomFov"] = weap->zoomSettings.weapon.adsZoomFov; + + // WeaponDamageInfo + for (int i = 0; i < 3; ++i) { + weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["minDamage"] = weap->weapDef->damageInfo.damageData[i].minDamage; + weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["mid1Damage"] = weap->weapDef->damageInfo.damageData[i].mid1Damage; + weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["mid2Damage"] = weap->weapDef->damageInfo.damageData[i].mid2Damage; + weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["mid3Damage"] = weap->weapDef->damageInfo.damageData[i].mid3Damage; + weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["damage"] = weap->weapDef->damageInfo.damageData[i].damage; + } + + // WeaponDef weaponDefJson[weap->szInternalName]["ladderWeapon"] = weap->weapDef->ladderWeapon; weaponDefJson[weap->szInternalName]["canHoldBreath"] = weap->weapDef->canHoldBreath; weaponDefJson[weap->szInternalName]["iFireTime"] = weap->weapDef->iFireTime; @@ -55,8 +72,6 @@ void Dump_WeaponDef() { else { Com_SetErrorMessage("[DLL ERROR] Must be in-game to dump WeaponDef."); } - - } void Load_WeaponDef() { @@ -73,7 +88,25 @@ void Load_WeaponDef() { WeaponCompleteDef* weap = bg_weaponCompleteDefs[i]; if (!weap) continue; if (weaponDefJson.contains(weap->szInternalName)) { + // WeaponCompleteDef weap->vfxImpactType = weaponDefJson[weap->szInternalName]["vfxImpactType"]; + weap->iClipSize = weaponDefJson[weap->szInternalName]["iClipSize"]; + weap->penetrateMultiplier = weaponDefJson[weap->szInternalName]["penetrateMultiplier"]; + + // ZoomSettings + weap->zoomSettings.weapon.adsZoomFov = weaponDefJson[weap->szInternalName]["zoomSetting"]["weapon"]["adsZoomFov"]; + + // WeaponDef + + // WeaponDamageInfo + for (int i = 0; i < 3; ++i) { + weap->weapDef->damageInfo.damageData[i].minDamage = weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["minDamage"]; + weap->weapDef->damageInfo.damageData[i].mid1Damage = weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["mid1Damage"]; + weap->weapDef->damageInfo.damageData[i].mid2Damage = weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["mid2Damage"]; + weap->weapDef->damageInfo.damageData[i].mid3Damage = weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["mid3Damage"]; + weap->weapDef->damageInfo.damageData[i].damage = weaponDefJson[weap->szInternalName]["damageInfo"]["damageData"][i]["damage"]; + } + weap->weapDef->ladderWeapon = weaponDefJson[weap->szInternalName]["ladderWeapon"]; weap->weapDef->canHoldBreath = weaponDefJson[weap->szInternalName]["canHoldBreath"]; weap->weapDef->iFireTime = weaponDefJson[weap->szInternalName]["iFireTime"];