Skip to content

Commit

Permalink
major update
Browse files Browse the repository at this point in the history
etc some minor fixes
added disable model occlusion( set PVS to false )
  • Loading branch information
lagcompensation committed Jul 12, 2024
1 parent 25da2e8 commit 0387a9f
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cstrike/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* - used to verify game version
*/

#define CS_PRODUCTSTRINGVERSION CS_XOR("1.40.2.0")
#define CS_PRODUCTSTRINGVERSION CS_XOR("1.40.2.1")

/*
* game's modules
Expand Down
42 changes: 22 additions & 20 deletions cstrike/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
// used: product version
#include "sdk/interfaces/iengineclient.h"

// used: jthread
#include <thread>

bool CORE::GetWorkingPath(wchar_t* wszDestination)
{
const wchar_t* wszModuleName = MEM::GetModuleBaseFileName(static_cast<HMODULE>(hDll), true);
Expand All @@ -60,20 +57,20 @@ bool CORE::GetWorkingPath(wchar_t* wszDestination)
return true;
}

static void Setup()
static bool Setup(HMODULE hModule)
{
#ifdef CS_LOG_CONSOLE
if (!L::AttachConsole(CS_XOR(L"asphyxia developer-mode")))
{
CS_ASSERT(false); // failed to attach console
return;
return false;
}
#endif
#ifdef CS_LOG_FILE
if (!L::OpenFile(CS_XOR(L"asphyxia.log")))
{
CS_ASSERT(false); // failed to open file
return;
return false;
}
#endif
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("logging system initialization completed");
Expand All @@ -82,37 +79,37 @@ static void Setup()
if (!MEM::Setup())
{
CS_ASSERT(false); // failed to setup memory system
return;
return false;
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("memory system initialization completed");

if (!MATH::Setup())
{
CS_ASSERT(false); // failed to setup math system
return;
return false;
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("math system initialization completed");

// grab game's interfaces
if (!I::Setup())
{
CS_ASSERT(false); // failed to setup interfaces
return;
return false;
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("interfaces initialization completed");

if (!SDK::Setup())
{
CS_ASSERT(false); // failed to setup sdk
return;
return false;
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("sdk initialization completed");

// setup input system and replace game's window messages processor with our
if (!IPT::Setup())
{
CS_ASSERT(false); // failed to setup input system
return;
return false;
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("input system initialization completed");

Expand All @@ -127,7 +124,7 @@ static void Setup()
if (!F::Setup())
{
CS_ASSERT(false); // failed to setup features
return;
return false;
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("features initialization completed");

Expand All @@ -138,30 +135,30 @@ static void Setup()
if (!SCHEMA::Setup(CS_XOR(L"schema.txt"), szModule.c_str()))
{
CS_ASSERT(false); // failed to setup schema system
return;
return false;
}
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("schema system initialization completed");

if (!CONVAR::Dump(CS_XOR(L"convars.txt")))
{
CS_ASSERT(false); // failed to setup convars system
return;
return false;
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("convars dumped completed, output: \"convars.txt\"");

if (!CONVAR::Setup())
{
CS_ASSERT(false); // failed to setup convars system
return;
return false;
}
L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_GREEN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("convars system initialization completed");

// setup hooks
if (!H::Setup())
{
CS_ASSERT(false); // failed to setup hooks
return;
return false;
}
L_PRINT(LOG_NONE) << CS_XOR("hooks initialization completed");

Expand All @@ -177,6 +174,7 @@ static void Setup()
L_PRINT(LOG_WARNING) << L::SetColor(LOG_COLOR_FORE_YELLOW | LOG_COLOR_FORE_INTENSITY) << CS_XOR("version mismatch! local CS2 version: ") << CS_PRODUCTSTRINGVERSION << CS_XOR(", current CS2 version: ") << I::Engine->GetProductVersionString() << CS_XOR(". asphyxia might not function as normal.");

L_PRINT(LOG_NONE) << L::SetColor(LOG_COLOR_FORE_CYAN | LOG_COLOR_FORE_INTENSITY) << CS_XOR("asphyxia initialization completed, version: ") << CS_STRINGIFY(CS_VERSION);
return true;
}

// @todo: some of those may crash while closing process, because we dont have any dependencies from the game modules, it means them can be unloaded and destruct interfaces etc before our module | modify ldrlist?
Expand Down Expand Up @@ -216,7 +214,7 @@ extern "C" BOOL WINAPI _CRT_INIT(HMODULE hModule, DWORD dwReason, LPVOID lpReser

BOOL APIENTRY CoreEntryPoint(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
// disables the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications for the specified dynamic-link library (DLL)
// Disables the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications for the specified dynamic-link library (DLL). This can reduce the size of the working set for some applications
DisableThreadLibraryCalls(hModule);

// process destroy of the cheat before crt calls atexit table
Expand Down Expand Up @@ -245,11 +243,15 @@ BOOL APIENTRY CoreEntryPoint(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
// save our module handle
CORE::hDll = hModule;

// create main thread
std::jthread{ []() { Setup(); } }.detach();
// check did we perform main initialization successfully
if (!Setup(hModule))
{
// undo the things we've done
Destroy();
return FALSE;
}

// create panic thread, it isn't critical error if it fails
// UPD: idc about std::jthread for panic thread btw he didn't work anyway
if (const HANDLE hThread = ::CreateThread(nullptr, 0U, &PanicThread, hModule, 0UL, nullptr); hThread != nullptr)
::CloseHandle(hThread);
}
Expand Down
6 changes: 5 additions & 1 deletion cstrike/core/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../sdk/interfaces/inetworkclientservice.h"
#include "../sdk/interfaces/iglobalvars.h"
#include "../sdk/interfaces/imaterialsystem.h"
#include "../sdk/interfaces/ipvs.h"

// used: viewsetup
#include "../sdk/datatypes/viewsetup.h"
Expand Down Expand Up @@ -123,7 +124,7 @@ bool H::Setup()
return false;
L_PRINT(LOG_INFO) << CS_XOR("\"DrawObject\" hook has been created");

if (!hkIsRelativeMouseMode.Create(MEM::GetVFunc(I::InputSystem, VTABLE::SDL::ISRELATIVEMOUSEMODE), reinterpret_cast<void*>(&IsRelativeMouseMode)))
if (!hkIsRelativeMouseMode.Create(MEM::GetVFunc(I::InputSystem, VTABLE::INPUTSYSTEM::ISRELATIVEMOUSEMODE), reinterpret_cast<void*>(&IsRelativeMouseMode)))
return false;
L_PRINT(LOG_INFO) << CS_XOR("\"IsRelativeMouseMode\" hook has been created");

Expand Down Expand Up @@ -252,6 +253,9 @@ __int64* CS_FASTCALL H::LevelInit(void* pClientModeShared, const char* szNewMap)
if (I::GlobalVars == nullptr)
I::GlobalVars = *reinterpret_cast<IGlobalVars**>(MEM::ResolveRelativeAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 89 0D ? ? ? ? 48 89 41")), 0x3, 0x7));

// disable model occlusion
I::PVS->Set(false);

return oLevelInit(pClientModeShared, szNewMap);
}

Expand Down
6 changes: 2 additions & 4 deletions cstrike/core/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ namespace VTABLE
};
}

namespace SDL
namespace INPUTSYSTEM
{
enum
{
ISRELATIVEMOUSEMODE = 78u,
ISRELATIVEMOUSEMODE = 78U,
};
}
}
Expand Down Expand Up @@ -76,8 +76,6 @@ namespace H
__int64 CS_FASTCALL LevelShutdown(void* pClientModeShared);
void CS_FASTCALL OverrideView(void* pClientModeCSNormal, CViewSetup* pSetup);
void CS_FASTCALL DrawObject(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2);

// sdl functions
void* IsRelativeMouseMode(void* pThisptr, bool bActive);

/* @section: managers */
Expand Down
3 changes: 3 additions & 0 deletions cstrike/core/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ bool I::Setup()
GlobalVars = *reinterpret_cast<IGlobalVars**>(MEM::ResolveRelativeAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 89 0D ? ? ? ? 48 89 41")), 0x3, 0x7));
bSuccess &= (GlobalVars != nullptr);

PVS = reinterpret_cast<CPVS*>(MEM::ResolveRelativeAddress(MEM::FindPattern(ENGINE2_DLL, CS_XOR("48 8D 0D ? ? ? ? 33 D2 FF 50")), 0x3, 0x7));
bSuccess &= (PVS != nullptr);

return bSuccess;
}

Expand Down
2 changes: 2 additions & 0 deletions cstrike/core/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class INetworkClientService;
class IMaterialSystem2;
class IResourceSystem;
class CResourceHandleUtils;
class CPVS;

// [d3d] struct
struct ID3D11Device;
Expand Down Expand Up @@ -72,4 +73,5 @@ namespace I
inline IMaterialSystem2* MaterialSystem2 = nullptr;
inline IResourceSystem* ResourceSystem = nullptr;
inline CResourceHandleUtils* ResourceHandleUtils = nullptr;
inline CPVS* PVS = nullptr;
}
1 change: 1 addition & 0 deletions cstrike/cstrike.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<ClInclude Include="features\visuals.h" />
<ClInclude Include="features\visuals\chams.h" />
<ClInclude Include="features\visuals\overlay.h" />
<ClInclude Include="sdk\interfaces\ipvs.h" />
<ClInclude Include="sdk\const.h" />
<ClInclude Include="sdk\datatypes\color.h" />
<ClInclude Include="sdk\datatypes\keyvalue3.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 @@ -308,6 +308,9 @@
</ClInclude>
<ClInclude Include="sdk\datatypes\utlbuffer.h" />
<ClInclude Include="features\CRC.h" />
<ClInclude Include="sdk\interfaces\ipvs.h">
<Filter>sdk\interfaces</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\dependencies\imgui\imgui.cpp">
Expand Down
8 changes: 4 additions & 4 deletions cstrike/features/visuals/chams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ bool F::VISUALS::CHAMS::OnDrawObject(void* pAnimatableSceneObjectDesc, void* pDx
if (CRT::StringCompare(pClassInfo->szName, CS_XOR("C_CSPlayerPawn")) != 0)
return false;

auto pPawn = I::GameResourceService->pGameEntitySystem->Get<C_CSPlayerPawn>(hOwner);
if (pPawn == nullptr)
auto pPlayerPawn = I::GameResourceService->pGameEntitySystem->Get<C_CSPlayerPawn>(hOwner);
if (pPlayerPawn == nullptr)
return false;

if (!pPawn->IsOtherEnemy(SDK::LocalPawn))
if (!pPlayerPawn->IsOtherEnemy(SDK::LocalPawn))
return false;

// alive state
if (pPawn->GetHealth() == 0)
if (pPlayerPawn->GetHealth() <= 0)
return false;

return OverrideMaterial(pAnimatableSceneObjectDesc, pDx11, arrMeshDraw, nDataCount, pSceneView, pSceneLayer, pUnk, pUnk2);
Expand Down
12 changes: 6 additions & 6 deletions cstrike/sdk/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ CCSPlayerController* CCSPlayerController::GetLocalPlayerController()

const Vector_t& CCSPlayerController::GetPawnOrigin()
{
CBaseHandle hPawn = this->GetPawnHandle();
if (!hPawn.IsValid())
CBaseHandle hPawnHandle = this->GetPawnHandle();
if (!hPawnHandle.IsValid())
return vecEmpty;

C_CSPlayerPawn* pPawn = I::GameResourceService->pGameEntitySystem->Get<C_CSPlayerPawn>(hPawn);
if (pPawn == nullptr)
C_CSPlayerPawn* pPlayerPawn = I::GameResourceService->pGameEntitySystem->Get<C_CSPlayerPawn>(hPawnHandle);
if (pPlayerPawn == nullptr)
return vecEmpty;

return pPawn->GetSceneOrigin();
return pPlayerPawn->GetSceneOrigin();
}

C_BaseEntity* C_BaseEntity::GetLocalPlayer()
Expand Down Expand Up @@ -101,7 +101,7 @@ bool C_CSWeaponBaseGun::CanPrimaryAttack(const int nWeaponType, const float flSe
if (nWeaponType == WEAPONTYPE_KNIFE)
return true;

// check do weapon have ammo
// check do weapon have ammo
if (this->GetClip1() <= 0)
return false;

Expand Down
13 changes: 13 additions & 0 deletions cstrike/sdk/interfaces/ipvs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

// used: MEM::CallVFunc
#include "../../utilities/memory.h"

class CPVS
{
public:
void Set(bool bState)
{
MEM::CallVFunc<void*, 7U>(this, bState);
}
};
7 changes: 2 additions & 5 deletions cstrike/utilities/fnv1a.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ namespace FNV1A
const std::size_t nLength = CRT::StringLength(szString);

for (std::size_t i = 0U; i < nLength; ++i)
{
uKey ^= szString[i];
uKey *= ullPrime;
}
uKey = (uKey ^ szString[i]) * ullPrime;

return uKey;
}
}
}

0 comments on commit 0387a9f

Please sign in to comment.