I've tried to recreate
this MetaMod: Source plugin in SourcePawn with the use of DHooks, this is my attempt:
Code:
#include <sourcemod>
#include <dhooks>
#pragma newdecls required
#pragma semicolon 1
#define PLUGIN_VERSION "1.0"
// dhooks
Handle gH_SetDataRate = null;
// convars
ConVar gCV_Rate = null;
float gF_Rate = 224000.0;
public Plugin myinfo =
{
name = "CS:GO Rate Forcer",
author = "shavit",
description = "Supposedly fixes high choke%% for CS:GO.",
version = PLUGIN_VERSION,
url = "https://github.com/shavitush"
}
public void OnPluginStart()
{
Handle hGameData = LoadGameConfigFile("csgorates.games");
if(hGameData != null)
{
gH_SetDataRate = DHookCreate(GameConfGetOffset(hGameData, "SetDataRate"), HookType_Entity, ReturnType_Float, ThisPointer_Ignore, DHook_SetDataRate);
}
else
{
SetFailState("Can't load gamedata/csgorates.games.txt");
}
delete hGameData;
ConVar cvMinrate = FindConVar("sv_minrate");
cvMinrate.SetBounds(ConVarBound_Upper, false);
cvMinrate.FloatValue = 140800.0;
ConVar cvMaxrate = FindConVar("sv_maxrate");
cvMaxrate.SetBounds(ConVarBound_Upper, false);
cvMaxrate.FloatValue = 307200.0;
CreateConVar("csgorates_version", PLUGIN_VERSION, "Plugin version.", FCVAR_DONTRECORD|FCVAR_NOTIFY);
gCV_Rate = CreateConVar("csgorates_rate", "224000.0", "Rates to force on players.\nDecrease this value if internet usage is very high!", 0, true, 140800.0, true, 307200.0);
gCV_Rate.AddChangeHook(OnConVarChanged);
AutoExecConfig();
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && IsClientInGame(i))
{
OnClientPutInServer(i);
}
}
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
gF_Rate = StringToFloat(newValue);
}
public void OnClientPutInServer(int client)
{
if(IsFakeClient(client))
{
return;
}
if(gH_SetDataRate != null)
{
DHookEntity(gH_SetDataRate, true, client);
PrintToServer("hooked %N", client);
}
}
public MRESReturn DHook_SetDataRate(Handle hReturn)
{
DHookSetReturn(hReturn, view_as<float>(gF_Rate));
PrintToServer("rate %f", gF_Rate);
return MRES_Override;
}
Gamedata:
Code:
"Games"
{
"csgo"
{
"Offsets"
{
"SetDataRate"
{
"windows" "28"
"linux" "29"
"mac" "29"
}
}
}
}
This gets called:
Code:
PrintToServer("hooked %N", client);
But this never gets called:
Code:
PrintToServer("rate %f", gF_Rate);
And I noticed that the changes I tried to apply didn't take effect at all as
status still reports 128000 rate.
Am I not using hooking correctly? Can anyone guide me please or at least tell me what's wrong?
__________________