Skip to content

Commit

Permalink
Merge pull request #129 from DaddyKermit/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
maecry authored Dec 11, 2024
2 parents 2632a4c + 667a220 commit 3f0d475
Show file tree
Hide file tree
Showing 8 changed files with 90 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.7")
#define CS_PRODUCTSTRINGVERSION CS_XOR("1.40.5.5")

/*
* game's modules
Expand Down
29 changes: 16 additions & 13 deletions cstrike/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,28 @@

bool CORE::GetWorkingPath(wchar_t* wszDestination)
{
const wchar_t* wszModuleName = MEM::GetModuleBaseFileName(static_cast<HMODULE>(hDll), true);
CRT::StringCopy(wszDestination, wszModuleName);
bool bSuccess = false;
PWSTR wszPathToDocuments = nullptr;

// remove the module name
if (wchar_t* pwszLastSlash = CRT::StringCharR(wszDestination, L'\\'); pwszLastSlash != nullptr)
*pwszLastSlash = L'\0';

CRT::StringCat(wszDestination, L"\\.asphyxia\\");
// create directory if it doesn't exist
if (!::CreateDirectoryW(wszDestination, nullptr))
// get path to user documents
if (SUCCEEDED(::SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, nullptr, &wszPathToDocuments)))
{
if (const DWORD dwError = ::GetLastError(); dwError != ERROR_ALREADY_EXISTS)
CRT::StringCat(CRT::StringCopy(wszDestination, wszPathToDocuments), CS_XOR(L"\\.asphyxia\\"));
bSuccess = true;

// create directory if it doesn't exist
if (!::CreateDirectoryW(wszDestination, nullptr))
{
L_PRINT(LOG_ERROR) << CS_XOR("failed to create default working directory, because one or more intermediate directories don't exist");
return false;
if (::GetLastError() != ERROR_ALREADY_EXISTS)
{
L_PRINT(LOG_ERROR) << CS_XOR("failed to create default working directory, because one or more intermediate directories don't exist");
bSuccess = false;
}
}
}
::CoTaskMemFree(wszPathToDocuments);

return true;
return bSuccess;
}

static bool Setup(HMODULE hModule)
Expand Down
32 changes: 18 additions & 14 deletions cstrike/core/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,17 @@ bool H::Setup()
return false;
L_PRINT(LOG_INFO) << CS_XOR("\"FrameStageNotify\" hook has been created");

// @ida: ClientModeShared -> #STR: "mapname", "transition", "game_newmap"
// in ida it will go in order as
// @ida: #STR: ; "game_newmap"
// @ida: #STR: ; "mapname"
// @ida: #STR: ; "transition"
// and the pattern is in the first one "game_newmap"
if (!hkLevelInit.Create(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 89 5C 24 ? 56 48 83 EC ? 48 8B 0D ? ? ? ? 48 8B F2")), reinterpret_cast<void*>(&LevelInit)))
return false;
L_PRINT(LOG_INFO) << CS_XOR("\"LevelInit\" hook has been created");

// @ida: ClientModeShared -> #STR: "map_shutdown"
if (!hkLevelShutdown.Create(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 83 EC ? 48 8B 0D ? ? ? ? 48 8D 15 ? ? ? ? 45 33 C9 45 33 C0 48 8B 01 FF 50 ? 48 85 C0 74 ? 48 8B 0D ? ? ? ? 48 8B D0 4C 8B 01 41 FF 50 ? 48 83 C4")), reinterpret_cast<void*>(&LevelShutdown)))
if (!hkLevelShutdown.Create(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 83 EC ? 48 8B 0D ? ? ? ? 48 8D 15 ? ? ? ? 45 33 C9 45 33 C0 48 8B 01 FF 50 ? 48 85 C0 74 ? 48 8B 0D ? ? ? ? 48 8B D0 4C 8B 01 41 FF 50 ? 48 83 C4 28 E9 C3 20 01 ?")), reinterpret_cast<void*>(&LevelShutdown)))
return false;
L_PRINT(LOG_INFO) << CS_XOR("\"LevelShutdown\" hook has been created");

Expand All @@ -115,12 +119,12 @@ bool H::Setup()
//*(float*)(pSetup + 0x494) = -v21; // m_OrthoLeft
//*(float*)(pSetup + 0x498) = -v22; // m_OrthoTop
//*(float*)(pSetup + 0x4A0) = v22; // m_OrthoBottom
//if (!hkOverrideView.Create(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC ? 48 8B FA E8")), reinterpret_cast<void*>(&OverrideView)))
// return false;
if (!hkOverrideView.Create(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC ? 48 8B FA E8 20 1E ED FF")), reinterpret_cast<void*>(&OverrideView)))
return false;

//L_PRINT(LOG_INFO) << CS_XOR("\"OverrideView\" hook has been created");

if (!hkDrawObject.Create(MEM::FindPattern(SCENESYSTEM_DLL, CS_XOR("48 8B C4 53 41 54 41 55 48 81 EC ? ? ? ? 4D 63 E1")), reinterpret_cast<void*>(&DrawObject)))
if (!hkDrawObject.Create(MEM::FindPattern(SCENESYSTEM_DLL, CS_XOR("48 8B C4 53 41 56 48 83 EC 38 4D 8B F0 48 8B DA 48 85 C9 0F 84 99 01 ? ?")), reinterpret_cast<void*>(&DrawObject)))
return false;
L_PRINT(LOG_INFO) << CS_XOR("\"DrawObject\" hook has been created");

Expand Down Expand Up @@ -199,19 +203,19 @@ 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, CUserCmd* cmd)
{
const auto oCreateMove = hkCreateMove.GetOriginal();
const bool bResult = oCreateMove(pInput, nSlot, bActive);
const bool bResult = oCreateMove(pInput, nSlot, cmd);

if (!I::Engine->IsConnected() || !I::Engine->IsInGame())
return bResult;

CUserCmd* pCmd = SDK::Cmd = pInput->GetUserCmd();
if (pCmd == nullptr)
SDK::Cmd = cmd;
if (SDK::Cmd == nullptr)
return bResult;

CBaseUserCmdPB* pBaseCmd = pCmd->csgoUserCmd.pBaseCmd;
CBaseUserCmdPB* pBaseCmd = SDK::Cmd->csgoUserCmd.pBaseCmd;
if (pBaseCmd == nullptr)
return bResult;

Expand All @@ -223,11 +227,11 @@ bool CS_FASTCALL H::CreateMove(CCSGOInput* pInput, int nSlot, bool bActive)
if (SDK::LocalPawn == nullptr)
return bResult;

F::OnCreateMove(pCmd, pBaseCmd, SDK::LocalController);
F::OnCreateMove(SDK::Cmd, pBaseCmd, SDK::LocalController);

CRC::Save(pBaseCmd);
if (CRC::CalculateCRC(pBaseCmd) == true)
CRC::Apply(pCmd);
CRC::Apply(SDK::Cmd);

return bResult;
}
Expand All @@ -251,8 +255,8 @@ __int64* CS_FASTCALL H::LevelInit(void* pClientModeShared, const char* szNewMap)
const auto oLevelInit = hkLevelInit.GetOriginal();
// if global variables are not captured during I::Setup or we join a new game, recapture it
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));

I::GlobalVars = *reinterpret_cast<IGlobalVars**>(MEM::ResolveRelativeAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 8B 0D 99 C7 0D 01 4C 8D 05 42 CB 0D 01")), 0x3, 0x7));
// disable model occlusion
I::PVS->Set(false);

Expand Down
17 changes: 13 additions & 4 deletions cstrike/core/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,25 @@ namespace VTABLE
{
enum
{
CREATEMOVE = 5U,
MOUSEINPUTENABLED = 16U,
CREATEMOVE = 21U,
MOUSEINPUTENABLED = 19U,
FRAMESTAGENOTIFY = 36U,
};
}

namespace INPUT
{
enum
{
VALID_VIEWANGLE = 7U,
};
}

namespace INPUTSYSTEM
{
enum
{
ISRELATIVEMOUSEMODE = 78U,
ISRELATIVEMOUSEMODE = 76U,
};
}
}
Expand All @@ -53,6 +61,7 @@ class CRenderGameSystem;
class IViewRender;
class CCSGOInput;
class CViewSetup;
class CUserCmd;
class CMeshData;

namespace H
Expand All @@ -69,7 +78,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, CUserCmd* cmd);
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
20 changes: 13 additions & 7 deletions cstrike/core/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ bool I::Setup()
#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"
SwapChain = **reinterpret_cast<ISwapChainDx11***>(MEM::ResolveRelativeAddress(MEM::FindPattern(RENDERSYSTEM_DLL, CS_XOR("66 0F 7F 0D ? ? ? ? 66 0F 7F 05 ? ? ? ? 0F 1F 40")), 0x4, 0x8));
// https://media.discordapp.net/attachments/1055004763328106558/1315619131109937152/image.png?ex=6758114b&is=6756bfcb&hm=a568636a5292e2a04f94972f5781d8ad88f170a38ec2a1ce82135726dec23fac&=&format=webp&quality=lossless
SwapChain = **reinterpret_cast<ISwapChainDx11***>(MEM::ResolveRelativeAddress(MEM::FindPattern(RENDERSYSTEM_DLL, CS_XOR("66 0F 7F 0D 83 C9 43 ? 48 8B F7 66 0F 7F 05 88 C9 43 ?")), 0x4, 0x8));
bSuccess &= (SwapChain != nullptr);

// grab's d3d11 interfaces for later use
Expand All @@ -168,18 +169,23 @@ bool I::Setup()
Device->GetImmediateContext(&DeviceContext);
}
bSuccess &= (Device != nullptr && DeviceContext != nullptr);

Input = *reinterpret_cast<CCSGOInput**>(MEM::ResolveRelativeAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 8B 0D ? ? ? ? E8 ? ? ? ? 8B BE 84 12 00 00")), 0x3, 0x7));

// #STR: CSGOInput
Input = *reinterpret_cast<CCSGOInput**>(MEM::ResolveRelativeAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 8B 0D D1 3A 29 01 4C 8D 8F E0 05 ? ? 45 33 FF")), 0x3, 0x7));
bSuccess &= (Input != nullptr);

// @ida: STR '%s: %f tick(%d) curtime(%f) OnSequenceCycleChanged: %s : %d=[%s]'
GlobalVars = *reinterpret_cast<IGlobalVars**>(MEM::ResolveRelativeAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 89 0D ? ? ? ? 48 89 41")), 0x3, 0x7));
// @ida: #STR: "gpGlocals->rendertime() called while IsInSimulation() is true, "gpGlocals->curtime() called while IsInSimulation() is false
// @ida: #STR: "C_SceneEntity::SetupClientOnlyScene: C" then go up until you see it
GlobalVars = *reinterpret_cast<IGlobalVars**>(MEM::ResolveRelativeAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 8B 0D 99 C7 0D 01 4C 8D 05 42 CB 0D 01")), 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));
// @ida: #STR: "CRenderingWorldSession::OnLoopActivate" go down just a bit
PVS = reinterpret_cast<CPVS*>(MEM::ResolveRelativeAddress(MEM::FindPattern(ENGINE2_DLL, CS_XOR("48 8D 0D ? ? ? ? 33 ? FF 50")), 0x3, 0x7));
bSuccess &= (PVS != nullptr);

GameTraceManager = *reinterpret_cast<CGameTraceManager**>(MEM::GetAbsoluteAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("4C 8B 3D ? ? ? ? 24 C9 0C 49 66 0F 7F 45")), 0x3, 0x0));
// @ida: #STR: "Physics/TraceShape (Client)"
// @ida: #STR: "Weapon_Knife.Stab" then go up
GameTraceManager = *reinterpret_cast<CGameTraceManager**>(MEM::GetAbsoluteAddress(MEM::FindPattern(CLIENT_DLL, CS_XOR("48 8B 1D ? ? ? ? 24 ? 0C ? F3 0F 7F 45")), 0x3, 0x0));
bSuccess &= (GameTraceManager != nullptr);

return bSuccess;
Expand Down
1 change: 1 addition & 0 deletions cstrike/cstrike.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<LanguageStandard>stdcpp20</LanguageStandard>
<ConformanceMode>true</ConformanceMode>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
<DisableSpecificWarnings>4267;4244;4172;4067;4146;</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
26 changes: 26 additions & 0 deletions cstrike/sdk/datatypes/usercmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ struct RepeatedPtrField_t
int nCurrentSize;
int nTotalSize;
Rep_t* pRep;

// @ida: #STR: "cl: CreateMove clamped invalid attack h" go down a bit and you will find it
// @ida: #STR: "cl: CreateMove - Invalid player history [ %d, %d, %.3f ] f
template <typename T>
T* add(T* element)
{
// Define the function pointer correctly
static auto add_to_rep_addr = reinterpret_cast<T * (__fastcall*)(RepeatedPtrField_t*, T*)>(MEM::GetAbsoluteAddress(MEM::FindPattern(CLIENT_DLL, "E8 ? ? ? ? 4C 8B E0 48 8B 44 24 ? 4C 8B CF"), 0x1));

// Use the function pointer to call the function
return add_to_rep_addr(this, element);
}
};

class CBasePB
Expand Down Expand Up @@ -216,6 +228,20 @@ class CBaseUserCmdPB : public CBasePB
std::int32_t nCmdFlags;
std::uint32_t nPawnEntityHandle;

CSubtickMoveStep* add_subtick_move()
{
using fn_add_subtick_move_step = CSubtickMoveStep* (__fastcall*)(void*);
static fn_add_subtick_move_step fn_create_new_subtick_move_step = reinterpret_cast<fn_add_subtick_move_step>(MEM::GetAbsoluteAddress(MEM::FindPattern(CLIENT_DLL, "E8 ? ? ? ? 48 8B D0 48 8D 4F 18 E8 ? ? ? ? 48 8B D0"), 0x1));

if (subtickMovesField.pRep && subtickMovesField.nCurrentSize < subtickMovesField.pRep->nAllocatedSize)
return subtickMovesField.pRep->tElements[subtickMovesField.nCurrentSize++];

CSubtickMoveStep* subtick = fn_create_new_subtick_move_step(nullptr);
subtickMovesField.add(subtick);

return subtick;
}

int CalculateCmdCRCSize()
{
return MEM::CallVFunc<int, 7U>(this);
Expand Down
4 changes: 2 additions & 2 deletions cstrike/sdk/interfaces/iengineclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class IEngineClient
{
int nIndex = -1;

MEM::CallVFunc<void, 47U>(this, std::ref(nIndex), 0);
MEM::CallVFunc<void, 49U>(this, std::ref(nIndex), 0);

return nIndex + 1;
}
Expand All @@ -62,6 +62,6 @@ class IEngineClient

[[nodiscard]] const char* GetProductVersionString()
{
return MEM::CallVFunc<const char*, 82U>(this);
return MEM::CallVFunc<const char*, 84U>(this);
}
};

0 comments on commit 3f0d475

Please sign in to comment.