int Utils::GetStringHash(const char* name)
{
int codes[256];
DWORD convar_name_hash_table = mem->read<DWORD>(mem->FindSignature(G.vstdlib, G.vstdlib_size, AY_OBFUSCATE("\x8B\x3C\x85"), AY_OBFUSCATE("xxx")) + 3) - G.vstdlib;
mem->rvm(G.vstdlib + convar_name_hash_table, &codes);
int v2 = 0;
int v3 = 0;
for (int i = 0; i < strlen(name); i += 2)
{
v3 = codes[v2 ^ toupper(name[i])];
if (i + 1 == strlen(name))
break;
v2 = codes[v3 ^ toupper(name[i + 1])];
}
return v2 | (v3 << 8);
}
DWORD Utils::GetConVarAddress(const char* name)
{
int hash = GetStringHash(name);
DWORD interface_engine_cvar = mem->read<DWORD>(mem->FindSignature(G.vstdlib, G.vstdlib_size, AY_OBFUSCATE("\x8B\x0D\x00\x00\x00\x00\xC7\x05"), AY_OBFUSCATE("xx????xx")) + 0x2) - G.vstdlib;
DWORD CvarEngine = mem->read<DWORD>(G.vstdlib + interface_engine_cvar);
DWORD Pointer = mem->read<DWORD>(mem->read<DWORD>(CvarEngine + 0x34) + ((BYTE)hash * 4));
while (Pointer)
{
if (mem->read<DWORD>(Pointer) == hash)
{
DWORD ConVarPointer = mem->read<DWORD>(Pointer + 0x4);
char* varname[32];
mem->rvm(mem->read<DWORD>(ConVarPointer + 0xC), &varname);
if (!strcmp((char*)varname, name))
{
return ConVarPointer;
}
}
Pointer = mem->read<DWORD>(Pointer + 0xC);
}
}
std::string Utils::getValue(const char* name)
{
char dummy[255];
mem->rvm(mem->read<DWORD>(GetConVarAddress(name) + 0x24), &dummy);
return std::string(dummy);
}
void Utils::SetValue(const char* name, float val)
{
DWORD addr = GetConVarAddress(name);
mem->write<int>(addr + 0x2C, *(int*)&val ^ addr);
}
void Utils::SetValue(const char* name, int val)
{
DWORD addr = GetConVarAddress(name);
mem->write<int>(addr + 0x30, val ^ addr);
}