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
This commit is contained in:
Sku-111 2023-11-04 22:35:37 +01:00
parent 6c73790cff
commit 7db48e99cf
14 changed files with 109 additions and 9 deletions

View File

@ -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();

34
hook_lib/debug_output.cpp Normal file
View File

@ -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<void>(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);
}

5
hook_lib/debug_output.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
inline bool gameInitialized = false;
void debug_output_init(const char* output_file);

View File

@ -31,3 +31,7 @@ dvar_t* Dvar_FindVarByName_Detour(const char* dvarName)
return ret;
}
bool CheatsEnabled()
{
return sv_cheats->current.enabled;
}

View File

@ -11,3 +11,5 @@ dvar_t* Dvar_RegisterString_Detour(const char* dvarName, const char* value, unsi
inline utils::hook::detour dvar_findvarbyname;
dvar_t* Dvar_FindVarByName_Detour(const char* dvarName);
bool CheatsEnabled();

View File

@ -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<uintptr_t(*)(const char*)>(0x1413E63A0_g);
dvar_t* Dvar_FindVarByName(const char* dvarName) {
auto func = reinterpret_cast<dvar_t*(*)(const char*)>(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;

View File

@ -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);

View File

@ -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
}

View File

@ -165,6 +165,7 @@
<ClCompile Include="common\utils\string.cpp" />
<ClCompile Include="common\utils\thread.cpp" />
<ClCompile Include="ddl.cpp" />
<ClCompile Include="debug_output.cpp" />
<ClCompile Include="devgui.cpp" />
<ClCompile Include="dvar.cpp" />
<ClCompile Include="fastfile.cpp" />
@ -209,6 +210,7 @@
<ClInclude Include="common\utils\string.hpp" />
<ClInclude Include="common\utils\thread.hpp" />
<ClInclude Include="ddl.h" />
<ClInclude Include="debug_output.h" />
<ClInclude Include="devgui.h" />
<ClInclude Include="dvar.h" />
<ClInclude Include="fastfile.h" />

View File

@ -139,6 +139,9 @@
<ClCompile Include="party.cpp">
<Filter>hook_lib\game</Filter>
</ClCompile>
<ClCompile Include="debug_output.cpp">
<Filter>hook_lib\game</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="common\utils\binary_resource.hpp">
@ -276,5 +279,8 @@
<ClInclude Include="party.h">
<Filter>hook_lib\game</Filter>
</ClInclude>
<ClInclude Include="debug_output.h">
<Filter>hook_lib\game</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -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<void>();
}

View File

@ -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<byte>(0x141101946_g, 0xEB);
// remove FF Header version check
// utils::hook::set<byte>(0x1411A776B_g, 0xEB);
}

View File

@ -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<void(*)(int)>(0x1417E5CD0_g);
auto Con_DrawConsole = reinterpret_cast<void(*)(int)>(0x1415AE0B0_g);
gameInitialized = true;
Con_DrawConsole(0);
DevGui_Draw(0);

View File

@ -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"];