Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maecry committed Nov 13, 2023
1 parent c77b6e4 commit 71cc796
Show file tree
Hide file tree
Showing 21 changed files with 245 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cstrike/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define SCENESYSTEM_DLL CS_XOR(L"scenesystem.dll")
#define MATERIAL_SYSTEM2_DLL CS_XOR(L"materialsystem2.dll")
#define MATCHMAKING_DLL CS_XOR(L"matchmaking.dll")

#define RESOURCESYSTEM_DLL CS_XOR(L"resourcesystem.dll")
/*
* define to specify default string encryption
*/
Expand Down
3 changes: 3 additions & 0 deletions cstrike/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ static void Destroy()
// destroy renderer backend
D::Destroy();

// destroy chams dependent stuff
F::Destroy();

#ifdef CS_LOG_CONSOLE
L::DetachConsole();
#endif
Expand Down
4 changes: 2 additions & 2 deletions cstrike/core/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ ViewMatrix_t* CS_FASTCALL H::GetMatrixForView(CRenderGameSystem* pRenderGameSyst
return matResult;
}

bool CS_FASTCALL H::CreateMove(CCSGOInput* pInput, int nSlot, bool bActive)
bool CS_FASTCALL H::CreateMove(CCSGOInput* pInput, int nSlot, bool bActive, std::byte unk)
{
const auto oCreateMove = hkCreateMove.GetOriginal();
const bool bResult = oCreateMove(pInput, nSlot, bActive);
const bool bResult = oCreateMove(pInput, nSlot, bActive, unk);

if (!I::Engine->IsConnected() || !I::Engine->IsInGame())
return bResult;
Expand Down
2 changes: 1 addition & 1 deletion cstrike/core/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace H

// game's functions
ViewMatrix_t* CS_FASTCALL GetMatrixForView(CRenderGameSystem* pRenderGameSystem, IViewRender* pViewRender, ViewMatrix_t* pOutWorldToView, ViewMatrix_t* pOutViewToProjection, ViewMatrix_t* pOutWorldToProjection, ViewMatrix_t* pOutWorldToPixels);
bool CS_FASTCALL CreateMove(CCSGOInput* pInput, int nSlot, bool bActive);
bool CS_FASTCALL CreateMove(CCSGOInput* pInput, int nSlot, bool bActive, std::byte unk);
bool CS_FASTCALL MouseInputEnabled(void* pThisptr);
void CS_FASTCALL FrameStageNotify(void* rcx, int nFrameStage);
__int64* CS_FASTCALL LevelInit(void* pClientModeShared, const char* szNewMap);
Expand Down
14 changes: 14 additions & 0 deletions cstrike/core/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// used: iswapchaindx11
#include "../sdk/interfaces/iswapchaindx11.h"
#include "../sdk/interfaces/iresourcesystem.h"

#pragma region interfaces_get

Expand Down Expand Up @@ -134,6 +135,19 @@ bool I::Setup()
MaterialSystem2 = Capture<IMaterialSystem2>(pMaterialSystem2Register, MATERIAL_SYSTEM2);
bSuccess &= (MaterialSystem2 != nullptr);

const auto pResourceSystemRegisterList = GetRegisterList(RESOURCESYSTEM_DLL);
if (pResourceSystemRegisterList == nullptr)
return false;

ResourceSystem = Capture<IResourceSystem>(pResourceSystemRegisterList, RESOURCE_SYSTEM);
bSuccess &= (ResourceSystem != nullptr);

if (ResourceSystem != nullptr)
{
ResourceHandleUtils = reinterpret_cast<CResourceHandleUtils*>(ResourceSystem->QueryInterface(RESOURCE_HANDLE_UTILS));
bSuccess &= (ResourceHandleUtils != nullptr);
}

#pragma endregion

// @ida: #STR: "r_gpu_mem_stats", "-threads", "CTSListBase: Misaligned list\n", "CTSQueue: Misaligned queue\n", "Display GPU memory usage.", "-r_max_device_threads"
Expand Down
6 changes: 6 additions & 0 deletions cstrike/core/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#define LOCALIZE CS_XOR("Localize_00")
#define NETWORK_CLIENT_SERVICE CS_XOR("NetworkClientService_00")
#define MATERIAL_SYSTEM2 CS_XOR("VMaterialSystem2_00")
#define RESOURCE_SYSTEM CS_XOR("ResourceSystem013")
#define RESOURCE_HANDLE_UTILS CS_XOR("ResourceHandleUtils001")

// @source: master/game/shared/shareddefs.h
#define TICK_INTERVAL (SDK::GlobalVars->m_flIntervalPerTick)
Expand All @@ -34,6 +36,8 @@ class IEngineClient;
class IEngineCVar;
class INetworkClientService;
class IMaterialSystem2;
class IResourceSystem;
class CResourceHandleUtils;

// [d3d] struct
struct ID3D11Device;
Expand Down Expand Up @@ -64,4 +68,6 @@ namespace I
inline IEngineCVar* Cvar = nullptr;
inline INetworkClientService* NetworkClientService = nullptr;
inline IMaterialSystem2* MaterialSystem2 = nullptr;
inline IResourceSystem* ResourceSystem = nullptr;
inline CResourceHandleUtils* ResourceHandleUtils = nullptr;
}
2 changes: 1 addition & 1 deletion cstrike/core/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void T::Visuals()
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(style.FramePadding.x, 0));

ImGui::Checkbox(CS_XOR("enable##chams"), &C_GET(bool, Vars.bVisualChams));
ImGui::Combo(CS_XOR("materials"), &C_GET(int, Vars.nVisualChamMaterial), CS_XOR("white\0wireframe\0\0"));
ImGui::Combo(CS_XOR("materials"), &C_GET(int, Vars.nVisualChamMaterial), CS_XOR("white\0wireframe\0"));
ImGui::Checkbox(CS_XOR("enable invisible chams##chams"), &C_GET(bool, Vars.bVisualChamsIgnoreZ));

ImGui::ColorEdit4(CS_XOR("visible color"), &C_GET(Color_t, Vars.colVisualChams));
Expand Down
3 changes: 3 additions & 0 deletions cstrike/cstrike.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@
<ClInclude Include="features\visuals\overlay.h" />
<ClInclude Include="sdk\const.h" />
<ClInclude Include="sdk\datatypes\color.h" />
<ClInclude Include="sdk\datatypes\keyvalue3.h" />
<ClInclude Include="sdk\datatypes\matrix.h" />
<ClInclude Include="sdk\datatypes\qangle.h" />
<ClInclude Include="sdk\datatypes\quaternion.h" />
<ClInclude Include="sdk\datatypes\stronghandle.h" />
<ClInclude Include="sdk\datatypes\transform.h" />
<ClInclude Include="sdk\datatypes\usercmd.h" />
<ClInclude Include="sdk\datatypes\utlfixedmemory.h" />
Expand All @@ -189,6 +191,7 @@
<ClInclude Include="sdk\interfaces\imaterialsystem.h" />
<ClInclude Include="sdk\interfaces\imemalloc.h" />
<ClInclude Include="sdk\interfaces\inetworkclientservice.h" />
<ClInclude Include="sdk\interfaces\iresourcesystem.h" />
<ClInclude Include="sdk\interfaces\ischemasystem.h" />
<ClInclude Include="sdk\interfaces\iswapchaindx11.h" />
<ClInclude Include="sdk\interfaces\iviewrender.h" />
Expand Down
3 changes: 3 additions & 0 deletions cstrike/cstrike.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@
<ClInclude Include="utilities\pe64.h">
<Filter>utilities</Filter>
</ClInclude>
<ClInclude Include="sdk\datatypes\stronghandle.h" />
<ClInclude Include="sdk\interfaces\iresourcesystem.h" />
<ClInclude Include="sdk\datatypes\keyvalue3.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\dependencies\imgui\imgui.cpp">
Expand Down
5 changes: 5 additions & 0 deletions cstrike/features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ bool F::Setup()
return true;
}

void F::Destroy()
{
VISUALS::OnDestroy();
}

void F::OnPresent()
{
if (!D::bInitialized)
Expand Down
2 changes: 2 additions & 0 deletions cstrike/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CMeshData;
namespace F
{
bool Setup();
void Destroy();

void OnPresent();
void OnFrameStageNotify(int nStage);
void OnCreateMove(CUserCmd* pCmd, CCSPlayerController* pLocalController);
Expand Down
5 changes: 5 additions & 0 deletions cstrike/features/visuals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ bool F::VISUALS::Setup()
return true;
}

void F::VISUALS::OnDestroy()
{
CHAMS::Destroy();
}

void VISUALS::OnFrame(const int nStage)
{
if (nStage == FRAME_RENDER_END)
Expand Down
2 changes: 2 additions & 0 deletions cstrike/features/visuals.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class CMeshData;
namespace F::VISUALS
{
bool Setup();
void OnDestroy();

void OnFrame(const int nStage);
bool OnDrawObject(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2);
}
107 changes: 98 additions & 9 deletions cstrike/features/visuals/chams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../../sdk/interfaces/imaterialsystem.h"
#include "../../sdk/interfaces/igameresourceservice.h"
#include "../../sdk/interfaces/cgameentitysystem.h"
#include "../../sdk/interfaces/iresourcesystem.h"
#include "../../core/sdk.h"
#include "../../sdk/entity.h"

Expand All @@ -16,8 +17,8 @@

struct CustomMaterial_t
{
CMaterial2* pMaterial = nullptr;
//CMaterial2* pMaterialInvisible = nullptr;
CMaterial2* pMaterial;
CMaterial2* pMaterialInvisible;

//bool bIsOwner = false;
};
Expand All @@ -32,24 +33,34 @@ bool F::VISUALS::CHAMS::Initialize()

arrMaterials[VISUAL_MATERIAL_PRIMARY_WHITE] = CustomMaterial_t{
.pMaterial = CreateMaterial(CS_XOR("primary_white"), CS_XOR("materials/dev/primary_white.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, false),
//.pMaterialInvisible = CreateMaterial(CS_XOR("primary_white_invisible"), CS_XOR("materials/dev/primary_white.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, true)
.pMaterialInvisible = CreateMaterial(CS_XOR("primary_white_invisible"), CS_XOR("materials/dev/primary_white.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, true)
};

arrMaterials[VISUAL_MATERIAL_WIREFRAME] = CustomMaterial_t{
.pMaterial = CreateMaterial(CS_XOR("wireframe"), CS_XOR("materials/dev/debug_wireframe.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, false),
//.pMaterialInvisible = CreateMaterial(CS_XOR("wireframe_invisible"), CS_XOR("materials/dev/debug_wireframe.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, true)
.pMaterialInvisible = CreateMaterial(CS_XOR("wireframe_invisible"), CS_XOR("materials/dev/debug_wireframe.vmat"), CS_XOR("csgo_unlitgeneric.vfx"), true, true, true)
};

bInitialized = true;
for (auto& [pMaterial] : arrMaterials)
for (auto& [pMaterial, pMaterialInvisible] : arrMaterials)
{
if (pMaterial == nullptr)
if (pMaterial == nullptr || pMaterialInvisible == nullptr)
bInitialized = false;
}

return bInitialized;
}

void F::VISUALS::CHAMS::Destroy()
{
#ifdef TEST_CREATE_CHAMS
for (auto& [pMaterial] : arrMaterials)
{
if (pMaterial != nullptr)
I::ResourceHandleUtils->DeleteResource(pMaterial.pBinding);
}
#endif
}

bool F::VISUALS::CHAMS::OnDrawObject(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2)
{
if (!bInitialized)
Expand Down Expand Up @@ -92,6 +103,78 @@ bool F::VISUALS::CHAMS::OnDrawObject(void* pAnimatableSceneObjectDesc, void* pDx
return OverrideMaterial(pAnimatableSceneObjectDesc, pDx11, arrMeshDraw, nDataCount, pSceneView, pSceneLayer, pUnk, pUnk2);
}

#ifdef TEST_CREATE_CHAMS
CStrongHandle<CMaterial2> F::VISUALS::CHAMS::CreateMaterial(const char* szName)
{
const char szVmatBuffer[] = R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
{
Shader = "csgo_unlitgeneric.vfx"
F_DISABLE_Z_BUFFERING = 0
g_flBumpStrength = 1
g_vColorTint = [1.000000, 1.000000, 1.000000, 0.000000]
g_vGlossinessRange = [0.000000, 1.000000, 0.000000, 0.000000]
g_vNormalTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
g_vTexCoordOffset = [0.000000, 0.000000, 0.000000, 0.000000]
g_vTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
g_tColor = resource:"materials/dev/primary_white_color_tga_f7b257f6.vtex"
g_tNormal = resource:"materials/default/default_normal_tga_7652cb.vtex"
g_tRoughness = resource:"materials/default/default_normal_tga_b3f4ec4c.vtex"
})";

auto buffer = new unsigned char[0x100 + sizeof(CKeyValues3)];
CRT::MemorySet(buffer, 0, sizeof(buffer));
CKeyValues3* kv3 = (CKeyValues3*)(buffer + 0x100);

KV3ID_t kv3ID;
kv3ID.szName = "generic";
kv3ID.unk0 = 0x469806E97412167C;
kv3ID.unk1 = 0xE73790B53EE6F2AF;

if (!MEM::fnLoadKV3(kv3, nullptr, szVmatBuffer, &kv3ID, nullptr))
throw;

CStrongHandle<CMaterial2> custom_material;
MEM::fnCreateMaterial(nullptr, &custom_material, szName, kv3, 0, 1);

return custom_material;
}

CStrongHandle<CMaterial2> F::VISUALS::CHAMS::CreateMaterialInvis(const char* szName)
{
const char szVmatBuffer[] = R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
{
Shader = "csgo_unlitgeneric.vfx"
F_DISABLE_Z_BUFFERING = 1
g_flBumpStrength = 1
g_vColorTint = [1.000000, 1.000000, 1.000000, 0.000000]
g_vGlossinessRange = [0.000000, 1.000000, 0.000000, 0.000000]
g_vNormalTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
g_vTexCoordOffset = [0.000000, 0.000000, 0.000000, 0.000000]
g_vTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
g_tColor = resource:"materials/dev/primary_white_color_tga_f7b257f6.vtex"
g_tNormal = resource:"materials/default/default_normal_tga_7652cb.vtex"
g_tRoughness = resource:"materials/default/default_normal_tga_b3f4ec4c.vtex"
})";

auto buffer = new unsigned char[0x100 + sizeof(CKeyValues3)];
CRT::MemorySet(buffer, 0, sizeof(buffer));
CKeyValues3* kv3 = (CKeyValues3*)(buffer + 0x100);

KV3ID_t kv3ID;
kv3ID.szName = "csgo_unlitgeneric2";
kv3ID.unk0 = 0x469806E97412167C;
kv3ID.unk1 = 0xE73790B53EE6F2AF;

if (!MEM::fnLoadKV3(kv3, nullptr, szVmatBuffer, &kv3ID, nullptr))
throw;

CStrongHandle<CMaterial2> custom_material;
MEM::fnCreateMaterial(nullptr, &custom_material, szName, kv3, 0, 1);

return custom_material;
}
#endif

CMaterial2* F::VISUALS::CHAMS::CreateMaterial(const char* szName, const char* szMaterialVMAT, const char* szShaderType, bool bBlendMode, bool bTranslucent, bool bDisableZBuffering)
{
CMeshData* pData = reinterpret_cast<CMeshData*>(static_cast<std::byte*>(MEM_STACKALLOC(0x200)) + 0x50);
Expand All @@ -100,8 +183,7 @@ CMaterial2* F::VISUALS::CHAMS::CreateMaterial(const char* szName, const char* sz
I::MaterialSystem2->FindOrCreateFromResource(&pMatPrototype, szMaterialVMAT);
if (pMatPrototype == nullptr)
return nullptr;

// idk why SetCreateDataByMaterial failed on release build
// @note: SetCreateDataByMaterial failed on release build idk why
#ifdef _DEBUG
I::MaterialSystem2->SetCreateDataByMaterial(pData, &pMatPrototype);
pData->SetShaderType(szShaderType);
Expand All @@ -122,6 +204,13 @@ bool F::VISUALS::CHAMS::OverrideMaterial(void* pAnimatableSceneObjectDesc, void*
const auto oDrawObject = H::hkDrawObject.GetOriginal();
const CustomMaterial_t customMaterial = arrMaterials[C_GET(int, Vars.nVisualChamMaterial)];

if (C_GET(bool, Vars.bVisualChamsIgnoreZ))
{
arrMeshDraw->pMaterial = customMaterial.pMaterialInvisible;
arrMeshDraw->colValue = C_GET(Color_t, Vars.colVisualChamsIgnoreZ);
oDrawObject(pAnimatableSceneObjectDesc, pDx11, arrMeshDraw, nDataCount, pSceneView, pSceneLayer, pUnk, pUnk2);
}

arrMeshDraw->pMaterial = customMaterial.pMaterial;
arrMeshDraw->colValue = C_GET(Color_t, Vars.colVisualChams);
oDrawObject(pAnimatableSceneObjectDesc, pDx11, arrMeshDraw, nDataCount, pSceneView, pSceneLayer, pUnk, pUnk2);
Expand Down
10 changes: 10 additions & 0 deletions cstrike/features/visuals/chams.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
#pragma once

#include "../../sdk/datatypes/stronghandle.h"



class CMaterial2;
class CMeshData;

namespace F::VISUALS::CHAMS
{
bool Initialize();
void Destroy();

bool OnDrawObject(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2);

// @note: bDisableZBuffering == true to create invisible material
#ifdef TEST_CREATE_CHAMS
CStrongHandle<CMaterial2> CreateMaterial(const char* szName);
CStrongHandle<CMaterial2> CreateMaterialInvis(const char* szName);
#endif
CMaterial2* CreateMaterial(const char* szName, const char* szMaterialVMAT, const char* szShaderType, bool bBlendMode, bool bTranslucent, bool bDisableZBuffering);

bool OverrideMaterial(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2);
Expand Down
17 changes: 17 additions & 0 deletions cstrike/sdk/datatypes/keyvalue3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

class CKeyValues3
{
public:
std::uint64_t uKey;
void* pValue;

std::byte pad[0x8];
};

struct KV3ID_t
{
const char* szName;
std::uint64_t unk0;
std::uint64_t unk1;
};
Loading

0 comments on commit 71cc796

Please sign in to comment.