My goal is to accomplish what this plugin does, but different
https://forums.alliedmods.net/showthread.php?t=260532
I see three relevant functions:
CTeamSpawnPoint::IsValid
(I don't think I'm allowed to link the csgo leak, but it's in team_spawnpoint.cpp)
CGameRules::IsSpawnPointValid
CCSGameRules::IsSpawnPointValid
I used IDA Freeware to find the signatures for these three, and I wrote the following code to try it out.
Code:
"Games"
{
"csgo"
{
"Signatures"
{
"CTeamSpawnPoint::IsValid"
{
"library" "server"
"linux" "\x55\x89\xE5\x57\x56\x53\x81\xEC\x2C\x08\x00\x00\x8B\x5D\x08"
}
"CGameRules::IsSpawnPointValid"
{
"library" "server"
"linux" "\x55\x89\xE5\x57\x56\x53\x81\xEC\x2C\x08\x00\x00\x8B\x5D\x0C"
}
"CCSGameRules::IsSpawnPointValid"
{
"library" "server"
"linux" "\x55\x89\xE5\x81\xEC\x88\x00\x00\x00\x89\x5D\xF4\x8B\x5D\x0C\x8B\x55\x10"
}
}
"Functions"
{
"CTeamSpawnPoint::IsValid"
{
"signature" "CTeamSpawnPoint::IsValid"
"callconv" "thiscall"
"return" "bool"
"this" "ignore"
}
"CGameRules::IsSpawnPointValid"
{
"signature" "CGameRules::IsSpawnPointValid"
"callconv" "thiscall"
"return" "bool"
"this" "ignore"
}
"CCSGameRules::IsSpawnPointValid"
{
"signature" "CCSGameRules::IsSpawnPointValid"
"callconv" "thiscall"
"return" "bool"
"this" "ignore"
}
}
}
}
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <dhooks>
ConVar cvar_SolidTeammates;
Handle g_hGameData;
Handle g_dhIsSpawnPointValidDetour;
public void OnPluginStart()
{
cvar_SolidTeammates = FindConVar("mp_solid_teammates");
g_hGameData = LoadGameConfigFile("detour_csgo_spawns.games2");
if (g_hGameData == null)
{
SetFailState("failed to load game config file");
}
else
{
PrintToChatAll("gamedata is not null");
}
g_dhIsSpawnPointValidDetour = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Bool, ThisPointer_Ignore);
if (g_dhIsSpawnPointValidDetour == null)
{
SetFailState("failed to setup spawnpoint valid hook");
}
else
{
PrintToChatAll("hook setup success");
}
if (!DHookSetFromConf(g_dhIsSpawnPointValidDetour, g_hGameData, SDKConf_Signature, "<insert signature name here>"))
{
SetFailState("failed to load spawnpoint valid signature");
}
else
{
PrintToChatAll("hook load success");
}
if (!DHookEnableDetour(g_dhIsSpawnPointValidDetour, false, Detour_IsSpawnPointValid))
{
SetFailState("failed to detour spawnpoint valid");
}
else
{
PrintToChatAll("detour success");
}
}
public MRESReturn Detour_IsSpawnPointValid(Handle hReturn, Handle hParams)
{
if (!cvar_SolidTeammates.BoolValue)
{
PrintToChatAll("Detour_IsSpawnPointValid called, changing return value to true");
DHookSetReturn(hReturn, true);
return MRES_Override;
}
PrintToChatAll("Detour_IsSpawnPointValid called, not changing return value");
return MRES_Ignored;
}
There were no errors when I tried the first function. However, the detour never actually "occurs".
The latter two functions resulted in errors in DHookSetFromConf.
I'm not sure how to proceed from here, and am not sure if I am doing something wrong. Never attempted to use dhooks before this.