Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
与metamod兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
huoji120 committed Oct 10, 2023
1 parent 0376637 commit d55d0f5
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 31 deletions.
1 change: 1 addition & 0 deletions csgo2/csgo2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpplatest</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
1 change: 1 addition & 0 deletions csgo2/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ auto init(void* ctx) -> bool {

Sleep(200);
}
global::isMetaModInit = (GetModuleHandleA("metamod.2.cs2.dll") != nullptr);
if (Offset::Init() == false) {
LOG("Offset::Init() == false !\n");
return false;
Expand Down
1 change: 1 addition & 0 deletions csgo2/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ namespace global {
CGlobalVars* GlobalVars;
float m_flUniversalTime;
float m_flLastTickedTime;
bool isMetaModInit;
}
1 change: 1 addition & 0 deletions csgo2/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ namespace global {
extern CGlobalVars* GlobalVars;
extern float m_flUniversalTime;
extern float m_flLastTickedTime;
extern bool isMetaModInit;
}
23 changes: 23 additions & 0 deletions csgo2/memory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "memory.h"
namespace Memory {
auto PathVscript() -> void {
CModule vscript_old("vscript_old.dll");
CModule vscript("vscript.dll");

uint64_t vscriptPathAddr = 0;
if (vscript_old.IsLoaded() == true) {
vscript_old.FindPattern(Offset::pattern_VscriptPath).Get(vscriptPathAddr);
}
else {
vscript.FindPattern(Offset::pattern_VscriptPath).Get(vscriptPathAddr);
}
if (vscriptPathAddr != 0) {
const static char PatchVScriptEnable[] = { 0xBE, 0x02 };
DWORD oldProtect;
VirtualProtect(reinterpret_cast<void*>(vscriptPathAddr), sizeof(PatchVScriptEnable), PAGE_EXECUTE_READWRITE, &oldProtect);
memcpy(reinterpret_cast<void*>(vscriptPathAddr), PatchVScriptEnable, sizeof(PatchVScriptEnable));
VirtualProtect(reinterpret_cast<void*>(vscriptPathAddr), sizeof(PatchVScriptEnable), oldProtect, &oldProtect);
LOG("success patch vscript at %llx \n", vscriptPathAddr);
}
}
};
2 changes: 1 addition & 1 deletion csgo2/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ namespace Memory {
ReadProcessMemory(GetCurrentProcess(), (void*)address, &buffer, sizeof(T), 0);
return buffer;
}

auto PathVscript() -> void;
};
45 changes: 35 additions & 10 deletions csgo2/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "head.h"
#define IS_WINDOWS 1
class InterfaceReg;
//cancer fix me plz
namespace global {
extern bool isMetaModInit;
};
// Pointer arithmetic utility class.
struct UTILPtr {
public:
Expand Down Expand Up @@ -65,10 +69,8 @@ class CModule {
UTILPtr GetProcAddress(const char* procName) const {
UTILPtr rv = 0;
if (this->IsLoaded()) {
#ifdef IS_WINDOWS
rv = ::GetProcAddress(static_cast<HMODULE>(this->m_handle),
procName);
#endif
}
return rv;
}
Expand All @@ -77,11 +79,7 @@ class CModule {
if (this->IsLoaded()) {
UTILPtr pCreateInterface = this->GetProcAddress("CreateInterface");
if (!pCreateInterface.IsValid()) return rv;

InterfaceReg* s_pInterfaceRegs = pCreateInterface.ToAbsolute(3, 0)
.Dereference(1)
.Get<InterfaceReg*>();

auto s_pInterfaceRegs = pCreateInterface.ToAbsolute(3, 0).Dereference(1).Get<InterfaceReg*>();
for (; s_pInterfaceRegs;
s_pInterfaceRegs = s_pInterfaceRegs->m_pNext) {
if (strcmp(version, s_pInterfaceRegs->m_pName) == 0) {
Expand Down Expand Up @@ -121,9 +119,36 @@ class CModule {

private:
void InitializeHandle() {
#ifdef IS_WINDOWS
this->m_handle = static_cast<void*>(GetModuleHandleA(this->GetName()));
#endif
if (global::isMetaModInit == false) {
this->m_handle = static_cast<void*>(GetModuleHandleA(this->GetName()));
return;
}

HANDLE hProcess = GetCurrentProcess();
DWORD cbNeeded;

// Call EnumProcessModules with a null hMods parameter to get the needed size.
EnumProcessModules(hProcess, nullptr, 0, &cbNeeded);
int moduleCount = cbNeeded / sizeof(HMODULE);
std::vector<HMODULE> hMods(moduleCount);

if (EnumProcessModules(hProcess, hMods.data(), cbNeeded, &cbNeeded))
{
for (const auto& hMod : hMods)
{
char szModName[MAX_PATH];

if (GetModuleFileNameExA(hProcess, hMod, szModName, sizeof(szModName) / sizeof(char)))
{
const auto fullModulePath = std::string(szModName);
if (fullModulePath.find("metamod") == std::string::npos && fullModulePath.ends_with(this->GetName()) == true) {
this->m_handle = static_cast<void*>(hMod);
break;
}
}
}
}
CloseHandle(hProcess);
}
void InitializeBounds() {
if (!this->IsLoaded()) return;
Expand Down
21 changes: 1 addition & 20 deletions csgo2/offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,14 @@ auto SafeDelayInit(void* ctx) -> void {
LOG("m_bForceTeamChangeSilent: %d \n",
InterFaces::CCSGameRulesInterFace->m_bForceTeamChangeSilent());
}
auto PathVscript() -> void {
CModule vscript_old("vscript_old.dll");
CModule vscript("vscript.dll");

uint64_t vscriptPathAddr = 0;
if (vscript_old.IsLoaded() == true) {
vscript_old.FindPattern(pattern_VscriptPath).Get(vscriptPathAddr);
}
else {
vscript.FindPattern(pattern_VscriptPath).Get(vscriptPathAddr);
}
if (vscriptPathAddr != 0) {
const static char PatchVScriptEnable[] = {0xBE, 0x02};
DWORD oldProtect;
VirtualProtect(reinterpret_cast<void*>(vscriptPathAddr), sizeof(PatchVScriptEnable), PAGE_EXECUTE_READWRITE, &oldProtect);
memcpy(reinterpret_cast<void*>(vscriptPathAddr), PatchVScriptEnable, sizeof(PatchVScriptEnable));
VirtualProtect(reinterpret_cast<void*>(vscriptPathAddr), sizeof(PatchVScriptEnable), oldProtect, &oldProtect);
LOG("success patch vscript at %llx \n", vscriptPathAddr);
}
}
auto Init() -> bool {
CModule server("server.dll");
CModule schemasystem("schemasystem.dll");
CModule engine("engine2.dll");
CModule localize("localize.dll");
CModule tier0("tier0.dll");
PathVscript();
Memory::PathVscript();

// engine.dll
engine.FindPattern(pattern_MaxPlayerNumsPtr)
Expand Down

0 comments on commit d55d0f5

Please sign in to comment.