From d00aaa933d9504e3f3de8be42cc8accdca4282af Mon Sep 17 00:00:00 2001 From: Marvin D <41352111+IcePixelx@users.noreply.github.com> Date: Thu, 10 Nov 2022 00:53:12 +0100 Subject: [PATCH] CRenderView init, GetWorldMatrixForView() * Fixed .gitignore for root /game/ * Fixed bug in WalkVTable where it would offset self. * General clean up: VAR -> CON, CON -> VAR --- .gitignore | 2 +- r5dev/core/init.cpp | 2 +- r5dev/game/client/view.h | 34 ----------- .../game/client/{view.cpp => viewrender.cpp} | 7 ++- r5dev/game/client/viewrender.h | 61 +++++++++++++++++++ r5dev/game/shared/ai_utility_shared.cpp | 2 +- r5dev/public/utility/memaddr.h | 4 +- r5dev/tier1/IConVar.h | 4 +- r5dev/tier1/cmd.h | 6 +- r5dev/vproj/gamesdk.vcxproj | 4 +- r5dev/vproj/gamesdk.vcxproj.filters | 4 +- r5dev/vstdlib/callback.cpp | 2 +- 12 files changed, 82 insertions(+), 50 deletions(-) delete mode 100644 r5dev/game/client/view.h rename r5dev/game/client/{view.cpp => viewrender.cpp} (70%) create mode 100644 r5dev/game/client/viewrender.h diff --git a/.gitignore b/.gitignore index 654b1332..3ec781bb 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,7 @@ bld/ [Ll]ib/ [Ll]og/ [Ll]ogs/ -[Gg]ame/ +/[Gg]ame/ # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 941b607a..b55f3ebc 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -107,7 +107,7 @@ #include "game/server/gameinterface.h" #endif // !CLIENT_DLL #ifndef DEDICATED -#include "game/client/view.h" +#include "game/client/viewrender.h" #endif // !DEDICATED #include "public/edict.h" #ifndef DEDICATED diff --git a/r5dev/game/client/view.h b/r5dev/game/client/view.h deleted file mode 100644 index 17d1b98b..00000000 --- a/r5dev/game/client/view.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CL_VIEW_H -#define CL_VIEW_H - -const Vector3D& MainViewOrigin(); -const QAngle& MainViewAngles(); - -inline Vector3D* g_vecRenderOrigin = nullptr; -inline QAngle* g_vecRenderAngles = nullptr; - -/////////////////////////////////////////////////////////////////////////////// -class V_View : public IDetour -{ - virtual void GetAdr(void) const - { - spdlog::debug("| VAR: g_vecRenderOrigin : {:#18x} |\n", reinterpret_cast(g_vecRenderOrigin)); - spdlog::debug("| VAR: g_vecRenderAngles : {:#18x} |\n", reinterpret_cast(g_vecRenderAngles)); - spdlog::debug("+----------------------------------------------------------------+\n"); - } - virtual void GetFun(void) const { } - virtual void GetVar(void) const - { - CMemory base = g_GameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x30\xF3\x0F\x10\x05\x00\x00\x00\x00\x00\x8B\x00"), "xxxx?xxxxxxxxx?????x?"); - - g_vecRenderOrigin = base.Offset(0x00).FindPatternSelf("F3 0F 10 05").ResolveRelativeAddressSelf(0x4, 0x8).RCast(); - g_vecRenderAngles = base.Offset(0x30).FindPatternSelf("F3 0F 10 0D").ResolveRelativeAddressSelf(0x4, 0x8).RCast(); - } - virtual void GetCon(void) const { } - virtual void Attach(void) const { } - virtual void Detach(void) const { } -}; -/////////////////////////////////////////////////////////////////////////////// - -REGISTER(V_View); -#endif // CL_VIEW_H \ No newline at end of file diff --git a/r5dev/game/client/view.cpp b/r5dev/game/client/viewrender.cpp similarity index 70% rename from r5dev/game/client/view.cpp rename to r5dev/game/client/viewrender.cpp index cb1da367..b09d43d4 100644 --- a/r5dev/game/client/view.cpp +++ b/r5dev/game/client/viewrender.cpp @@ -6,7 +6,12 @@ #include "core/stdafx.h" #include "mathlib/vector.h" -#include "game/client/view.h" +#include "game/client/viewrender.h" + +VMatrix* CViewRender::GetWorldMatrixForView(int8_t slot) +{ + return CViewRender_GetWorldMatrixForView(this, slot); +} const Vector3D& MainViewOrigin() { diff --git a/r5dev/game/client/viewrender.h b/r5dev/game/client/viewrender.h new file mode 100644 index 00000000..b827b510 --- /dev/null +++ b/r5dev/game/client/viewrender.h @@ -0,0 +1,61 @@ +#pragma once + +//------------------------------------------------------------------------------------- +// Forward declarations +//------------------------------------------------------------------------------------- +class VMatrix; + +class CViewRender +{ +public: + VMatrix* GetWorldMatrixForView(int8_t slot); +}; + +/////////////////////////////////////////////////////////////////////////////// +const Vector3D& MainViewOrigin(); +const QAngle& MainViewAngles(); + +inline CMemory p_CViewRender_GetWorldMatrixForView; +inline auto CViewRender_GetWorldMatrixForView = p_CViewRender_GetWorldMatrixForView.RCast(); + +inline Vector3D* g_vecRenderOrigin = nullptr; +inline QAngle* g_vecRenderAngles = nullptr; + +inline CViewRender* g_pViewRender = nullptr; +inline CMemory g_pViewRender_VFTable; + +/////////////////////////////////////////////////////////////////////////////// +class V_ViewRender : public IDetour +{ + virtual void GetAdr(void) const + { + spdlog::debug("| FUN: CViewRender::GetWorldMatrixForView : {:#18x} |\n", p_CViewRender_GetWorldMatrixForView.GetPtr()); + spdlog::debug("| VAR: g_vecRenderOrigin : {:#18x} |\n", reinterpret_cast(g_vecRenderOrigin)); + spdlog::debug("| VAR: g_vecRenderAngles : {:#18x} |\n", reinterpret_cast(g_vecRenderAngles)); + spdlog::debug("| VAR: g_pViewRender : {:#18x} |\n", reinterpret_cast(g_pViewRender)); + spdlog::debug("| CON: CViewRender (VFTable) : {:#18x} |\n", g_pViewRender_VFTable.GetPtr()); + spdlog::debug("+----------------------------------------------------------------+\n"); + } + virtual void GetFun(void) const + { + g_pViewRender_VFTable = g_GameDll.GetVirtualMethodTable(".?AVCViewRender@@"); + + p_CViewRender_GetWorldMatrixForView = g_pViewRender_VFTable.WalkVTable(16).Deref(); // 16th vfunc. + CViewRender_GetWorldMatrixForView = p_CViewRender_GetWorldMatrixForView.RCast(); + } + virtual void GetVar(void) const + { + CMemory base = g_GameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x30\xF3\x0F\x10\x05\x00\x00\x00\x00\x00\x8B\x00"), "xxxx?xxxxxxxxx?????x?"); + + g_vecRenderOrigin = base.Offset(0x00).FindPatternSelf("F3 0F 10 05").ResolveRelativeAddressSelf(0x4, 0x8).RCast(); + g_vecRenderAngles = base.Offset(0x30).FindPatternSelf("F3 0F 10 0D").ResolveRelativeAddressSelf(0x4, 0x8).RCast(); + + g_pViewRender = g_GameDll.FindPatternSIMD(reinterpret_cast("\x48\x8D\x05\x00\x00\x00\x00\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x8B\xC4"), "xxx????xxxxxxxxxxxxxx").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); /*48 8D 05 ?? ?? ?? ?? C3 CC CC CC CC CC CC CC CC CC CC 48 8B C4*/ + } + virtual void GetCon(void) const { } + virtual void Attach(void) const { } + virtual void Detach(void) const { } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(V_ViewRender); \ No newline at end of file diff --git a/r5dev/game/shared/ai_utility_shared.cpp b/r5dev/game/shared/ai_utility_shared.cpp index 5682269d..838646c2 100644 --- a/r5dev/game/shared/ai_utility_shared.cpp +++ b/r5dev/game/shared/ai_utility_shared.cpp @@ -16,7 +16,7 @@ #include "game/server/ai_utility.h" #include "game/server/ai_networkmanager.h" #include "game/server/ai_network.h" -#include "game/client/view.h" +#include "game/client/viewrender.h" #include "thirdparty/recast/detour/include/detourcommon.h" #include "thirdparty/recast/detour/include/detournavmesh.h" diff --git a/r5dev/public/utility/memaddr.h b/r5dev/public/utility/memaddr.h index fd010eef..035fd21a 100644 --- a/r5dev/public/utility/memaddr.h +++ b/r5dev/public/utility/memaddr.h @@ -105,8 +105,8 @@ public: inline CMemory WalkVTable(ptrdiff_t vfuncIndex) { - ptr += (8 * vfuncIndex); - return CMemory(this); + uintptr_t reference = ptr + (8 * vfuncIndex); + return CMemory(reference); } inline CMemory WalkVTableSelf(ptrdiff_t vfuncIndex) diff --git a/r5dev/tier1/IConVar.h b/r5dev/tier1/IConVar.h index 17bd4603..e9002f6c 100644 --- a/r5dev/tier1/IConVar.h +++ b/r5dev/tier1/IConVar.h @@ -122,8 +122,8 @@ class VConVar : public IDetour spdlog::debug("| FUN: ConVar::IsFlagSet : {:#18x} |\n", p_ConVar_IsFlagSet.GetPtr()); spdlog::debug("| FUN: ConVar::Register : {:#18x} |\n", p_ConVar_Register.GetPtr()); spdlog::debug("| FUN: ConVar_PrintDescription : {:#18x} |\n", p_ConVar_PrintDescription.GetPtr()); - spdlog::debug("| VAR: g_pConVarVFTable : {:#18x} |\n", g_pConVarVFTable.GetPtr()); - spdlog::debug("| VAR: g_pIConVarVFTable : {:#18x} |\n", g_pIConVarVFTable.GetPtr()); + spdlog::debug("| CON: g_pConVarVFTable : {:#18x} |\n", g_pConVarVFTable.GetPtr()); + spdlog::debug("| CON: g_pIConVarVFTable : {:#18x} |\n", g_pIConVarVFTable.GetPtr()); spdlog::debug("+----------------------------------------------------------------+\n"); } virtual void GetFun(void) const diff --git a/r5dev/tier1/cmd.h b/r5dev/tier1/cmd.h index c0041ae8..1ec86a4e 100644 --- a/r5dev/tier1/cmd.h +++ b/r5dev/tier1/cmd.h @@ -201,7 +201,7 @@ class VConCommand : public IDetour spdlog::debug("| FUN: CallbackStub : {:#18x} |\n", p_CallbackStub.GetPtr()); spdlog::debug("| FUN: NullSub : {:#18x} |\n", p_NullSub.GetPtr()); spdlog::debug("+----------------------------------------------------------------+\n"); - spdlog::debug("| VAR: g_pConCommandVFTable : {:#18x} |\n", g_pConCommandVFTable.GetPtr()); + spdlog::debug("| CON: g_pConCommandVFTable : {:#18x} |\n", g_pConCommandVFTable.GetPtr()); spdlog::debug("+----------------------------------------------------------------+\n"); } virtual void GetFun(void) const @@ -220,11 +220,11 @@ class VConCommand : public IDetour NullSub = p_NullSub.RCast(); /*C2 00 00 CC CC CC CC CC CC CC CC CC CC CC CC CC 40 53 48 83 EC 20 48 8D 05 ?? ?? ?? ??*/ CallbackStub = p_CallbackStub.RCast(); /*33 C0 C3 CC CC CC CC CC CC CC CC CC CC CC CC CC 80 49 68 08*/ /*UserMathErrorFunction*/ } - virtual void GetVar(void) const + virtual void GetVar(void) const { } + virtual void GetCon(void) const { g_pConCommandVFTable = g_GameDll.GetVirtualMethodTable(".?AVConCommand@@"); } - virtual void GetCon(void) const { } virtual void Attach(void) const { } virtual void Detach(void) const { } }; diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index dd0c3453..00eb2b3f 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -61,7 +61,7 @@ - + @@ -225,7 +225,7 @@ - + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index cded83a4..5984112f 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -597,7 +597,7 @@ sdk\game\client - + sdk\game\client @@ -1760,7 +1760,7 @@ sdk\public - + sdk\game\client diff --git a/r5dev/vstdlib/callback.cpp b/r5dev/vstdlib/callback.cpp index 2c3843cf..683d69e0 100644 --- a/r5dev/vstdlib/callback.cpp +++ b/r5dev/vstdlib/callback.cpp @@ -53,7 +53,7 @@ #include "game/server/detour_impl.h" #endif // !CLIENT_DLL #ifndef DEDICATED -#include "game/client/view.h" +#include "game/client/viewrender.h" #endif // !DEDICATED