CGameServer::SpawnServer
0x001fde70 · 2952 bytes · __thiscall
_ZN11CGameServer11SpawnServerEPcS0_
Decompiled
undefined (3 params)
/* CGameServer::SpawnServer(char*, char*) */
undefined4 __thiscall CGameServer::SpawnServer(CGameServer *this,char *param_1,char *param_2)
{
code *pcVar1;
undefined *this_00;
float fVar2;
char cVar3;
undefined1 uVar4;
int *piVar5;
int iVar6;
edict_t *peVar7;
int iVar8;
model_t *pmVar9;
undefined4 uVar10;
KeyValues *this_01;
char *pcVar11;
int iVar12;
int in_GS_OFFSET;
longdouble lVar13;
KeyValues *pKVar14;
undefined1 *local_2ac;
undefined1 *local_2a8;
bool local_2a4;
char local_28d [5];
char local_288 [96];
char local_228 [260];
char local_124 [260];
int local_20;
local_20 = *(int *)(in_GS_OFFSET + 0x14);
piVar5 = (int *)CommandLine_Tier0();
iVar6 = (**(code **)(*piVar5 + 0x28))(piVar5,"-NoLoadPluginsForClient");
this_00 = g_pServerPluginHandler;
if ((iVar6 != 0) && (this[0x260] == (CGameServer)0x0)) {
this[0x260] = (CGameServer)0x1;
CServerPlugin::LoadPlugins((CServerPlugin *)this_00);
}
cVar3 = (**(code **)(*(int *)this + 0x60))(this);
if (cVar3 != '\0') {
ConVar::SetValue(0x3ede60);
}
ReloadWhitelist(this,param_1);
COM_TimestampedLog("SV_SpawnServer(%s)",param_1);
COM_SetupLogDir(param_1);
CLog::Open((CLog *)g_Log);
CLog::Printf((CLog *)g_Log,"Loading map \"%s\"\n",param_1);
CLog::PrintServerVars((CLog *)g_Log);
if (param_2 == (char *)0x0) {
ConDMsg("Spawn Server: %s\n",param_1);
}
else {
ConDMsg("Spawn Server: %s: [%s]\n",param_1,param_2);
}
gHostSpawnCount = *(int *)(this + 0x108) + 1;
*(int *)(this + 0x108) = gHostSpawnCount;
(**(code **)(*(int *)this + 0x68))(this);
ConVar::SetValue(0x3a10a0);
if (*(int *)(coop._28_4_ + 0x30) != 0) {
ConVar::SetValue(0x3a10a0);
}
iVar6 = 0;
if (-1 < current_skill) {
iVar6 = current_skill;
}
if (3 < iVar6) {
iVar6 = 3;
}
current_skill = iVar6;
ConVar::SetValue(5.33323e-39);
ExecGameTypeCfg(this,param_1);
COM_TimestampedLog("StaticPropMgr()->LevelShutdown()");
piVar5 = (int *)StaticPropMgr();
(**(code **)(*piVar5 + 0x14))(piVar5);
if ((hltv != (int *)0x0) && (cVar3 = (**(code **)(*hltv + 0x54))(hltv), cVar3 == '\0')) {
(**(code **)(*hltv + 0x14))(hltv);
}
COM_TimestampedLog("Host_FreeToLowMark");
Host_FreeStateAndWorld(true);
Host_FreeToLowMark(true);
g_ServerGlobalVariables._64_4_ = 0;
COM_TimestampedLog("sv.Clear()");
(**(code **)(*(int *)this + 0xa8))(this);
COM_TimestampedLog("framesnapshotmanager->LevelChanged()");
(**(code **)(*(int *)framesnapshotmanager + 8))(framesnapshotmanager);
V_strncpy((char *)(this + 0x10),param_1,0x40);
if (param_2 == (char *)0x0) {
this[0x1c9] = (CGameServer)0x0;
}
else {
V_strncpy((char *)(this + 0x1c9),param_2,0x40);
}
SV_FlushMemoryIfMarked();
iVar12 = 0x10;
(**(code **)(*(int *)g_pFileSystem + 0x124))(g_pFileSystem);
(**(code **)(*g_pMDLCache + 0x94))(g_pMDLCache,0);
g_ServerGlobalVariables._80_4_ = 0x800;
*(undefined4 *)(this + 0x210) = 0x800;
g_ServerGlobalVariables._20_4_ = (**(code **)(*(int *)this + 0x18))(this);
iVar6 = (**(code **)(*(int *)this + 0x18))(this);
*(int *)(this + 0x20c) = iVar6 + 1;
COM_TimestampedLog("SV_AllocateEdicts");
DAT_003b8174 = Hunk_AllocName(DAT_003b8170 << 4,"edicts",true);
ED_ClearTimes();
DAT_003b8178 = Hunk_AllocName(DAT_003b8170 << 2,"edictchangeinfo",true);
this[0x224] = (CGameServer)0x1;
*(undefined4 *)(this + 0xf8) = 0;
g_ServerGlobalVariables._88_4_ = *(undefined4 *)(this + 0x214);
*(undefined4 *)(this + 0xfc) = 0;
AssignClassIds(this);
COM_TimestampedLog("Set up players");
for (iVar6 = 0; iVar8 = (**(code **)(*(int *)this + 0x20))(this), iVar6 < iVar8; iVar6 = iVar6 + 1
) {
peVar7 = (edict_t *)(*(int *)(this + 0x214) + iVar12);
iVar12 = iVar12 + 0x10;
*(edict_t **)((int)&__DT_REL[0x14c5].r_offset + *(int *)(*(int *)(this + 0x114) + iVar6 * 4)) =
peVar7;
InitializeEntityDLLFields(peVar7);
}
COM_TimestampedLog("Set up players(done)");
*(undefined4 *)(this + 4) = 1;
CBaseServer::SendReservationStatus((CBaseServer *)&sv);
fVar2 = DAT_003a1730;
*(float *)(this + 0x10c) = DAT_003a1730;
*(int *)(this + 0xc) = (int)(1.0 / fVar2) + 1;
piVar5 = (int *)CommandLine_Tier0();
lVar13 = (longdouble)(**(code **)(*piVar5 + 0x20))(piVar5,"-servertime",0xbf800000);
if ((float)lVar13 == -1.0) {
g_ServerGlobalVariables._24_4_ = *(undefined4 *)(this + 0xc);
}
else {
iVar6 = (int)((float)lVar13 / DAT_003a1730);
g_ServerGlobalVariables._24_4_ = 1;
if (0 < iVar6) {
g_ServerGlobalVariables._24_4_ = iVar6 + 1;
}
*(undefined4 *)(this + 0xc) = g_ServerGlobalVariables._24_4_;
}
lVar13 = (longdouble)(**(code **)(*(int *)this + 0x28))(this);
g_ServerGlobalVariables._12_4_ = (undefined4)lVar13;
V_snprintf(local_228,0x104,"maps/%s.bsp",param_1);
GetMapPathNameOnDisk(local_124,local_228,0x104);
(**(code **)(*(int *)g_pFileSystem + 0x1c))(g_pFileSystem,local_124,&DAT_002a076d,0,0);
(**(code **)(*(int *)g_pFileSystem + 0x154))(g_pFileSystem);
piVar5 = (int *)CommandLine_Tier0();
iVar6 = (**(code **)(*piVar5 + 0x28))(piVar5,"-allowstalezip");
if ((iVar6 == 0) &&
(cVar3 = (**(code **)(*(int *)(g_pFileSystem + 4) + 0x28))
(g_pFileSystem + 4,"stale.txt",&DAT_002a076d), cVar3 != '\0')) {
Warning(
"This map is not final!! Needs to be rebuilt without -keepstalezip and without -onlyents\n"
);
}
COM_TimestampedLog("modelloader->GetModelForName(%s) -- Start",local_228);
pmVar9 = (model_t *)(**(code **)(*(int *)modelloader + 0x1c))(modelloader,local_228,2);
CCommonHostState::SetWorldModel((CCommonHostState *)&host_state,pmVar9);
if (host_state == (model_t *)0x0) {
ConMsg("Couldn\'t spawn server %s\n",local_228);
pKVar14 = g_pFileSystem;
*(undefined4 *)(this + 4) = 0;
(**(code **)(*(int *)pKVar14 + 0x158))(pKVar14);
uVar10 = 0;
}
else {
COM_TimestampedLog("modelloader->GetModelForName(%s) -- Finished");
cVar3 = (**(code **)(*(int *)this + 0x68))(this);
if (cVar3 == '\0') {
*(undefined4 *)(this + 0xb0) = 0;
*(undefined4 *)(this + 0xb4) = 0;
}
else {
CRC32_Init((ulong *)(this + 0xb0));
uVar10 = CRC_MapFile((ulong *)(this + 0xb0),local_124);
if ((char)uVar10 == '\0') {
ConMsg("Couldn\'t CRC server map: %s\n",local_124);
pKVar14 = g_pFileSystem;
*(undefined4 *)(this + 4) = 0;
(**(code **)(*(int *)pKVar14 + 0x158))(pKVar14);
goto LAB_001fe7df;
}
V_snprintf(local_288,0x60,"bin\\client.dll");
V_FixSlashes(local_288,'/');
cVar3 = CRC_File((ulong *)(this + 0xb4),local_288);
if (cVar3 == '\0') {
*(undefined4 *)(this + 0xb4) = 0xffffffff;
}
}
iVar6 = 1;
*(undefined **)(this + 0xbc) = networkStringTableContainerServer;
COM_TimestampedLog("SV_CreateNetworkStringTables");
SV_CreateNetworkStringTables(param_1);
uVar10 = (**(code **)(*(int *)g_pStringTableDictionary + 8))(g_pStringTableDictionary);
*(undefined4 *)(this + 0xb8) = uVar10;
PrecacheModel(this,"",0,(model_t *)0x0);
PrecacheGeneric(this,"",0);
PrecacheSound(this,"",0);
COM_TimestampedLog("Precache world model (%s)",local_228);
PrecacheModel(this,local_228,3,host_state);
COM_TimestampedLog("Precache brush models");
if (1 < *DAT_003a172c) {
do {
iVar12 = iVar6 + 1;
V_snprintf(local_28d,5,"*%i",iVar6);
pmVar9 = (model_t *)(**(code **)(*(int *)modelloader + 0x1c))(modelloader,local_28d,2);
PrecacheModel(this,local_28d,3,pmVar9);
iVar6 = iVar12;
} while (iVar12 < *DAT_003a172c);
}
COM_TimestampedLog("SV_ClearWorld");
SV_ClearWorld();
COM_TimestampedLog("InitializeEntityDLLFields");
InitializeEntityDLLFields(*(edict_t **)(this + 0x214));
**(uint **)(this + 0x214) = **(uint **)(this + 0x214) & 0xfffffffd;
if (*(float *)(coop._28_4_ + 0x2c) == 0.0) {
g_ServerGlobalVariables[0x4d] = *(int *)(deathmatch._28_4_ + 0x30) != 0;
}
else {
g_ServerGlobalVariables[0x4e] = *(int *)(coop._28_4_ + 0x30) != 0;
}
g_ServerGlobalVariables._60_4_ = (CGameServer *)0x0;
if (this[0x10] != (CGameServer)0x0) {
g_ServerGlobalVariables._60_4_ = this + 0x10;
}
g_ServerGlobalVariables._68_4_ = (CGameServer *)0x0;
if (this[0x1c9] != (CGameServer)0x0) {
g_ServerGlobalVariables._68_4_ = this + 0x1c9;
}
CTestScriptMgr::CheckPoint((CTestScriptMgr *)g_TestScriptMgr,"map_load");
piVar5 = (int *)(**(code **)(*g_pMatchFramework + 0x28))(g_pMatchFramework);
this_01 = (KeyValues *)(**(code **)(*piVar5 + 4))(piVar5,0);
if (this_01 == (KeyValues *)0x0) {
local_2ac = &DAT_002c79d4;
local_2a8 = &DAT_002c79d4;
local_2a4 = false;
}
else {
/* try { // try from 001fe590 to 001fe5d3 has its CatchHandler @ 001fea38 */
iVar6 = KeyValues::GetInt(this_01,"Game/vanilla",0);
local_2a4 = iVar6 != 0;
local_2a8 = (undefined1 *)KeyValues::GetString(this_01,"Game/campaign","");
local_2ac = (undefined1 *)KeyValues::GetString(this_01,"Game/mode","");
}
/* try { // try from 001fe602 to 001fe7bb has its CatchHandler @ 001fea50 */
piVar5 = (int *)(**(code **)(s_GameEventManager + 0x1c))(&s_GameEventManager,"server_spawn",0,0)
;
if (piVar5 != (int *)0x0) {
pcVar11 = "FCVAR_NEVER_AS_STRING";
if ((host_name[0x15] & 0x10) == 0) {
pcVar11 = "";
if (*(char **)(host_name._28_4_ + 0x24) != (char *)0x0) {
pcVar11 = *(char **)(host_name._28_4_ + 0x24);
}
}
(**(code **)(*piVar5 + 0x3c))(piVar5,"hostname",pcVar11);
pcVar1 = *(code **)(*piVar5 + 0x3c);
uVar10 = netadr_s::ToString((netadr_s *)&net_local_adr,false);
(*pcVar1)(piVar5,"address",uVar10);
pcVar1 = *(code **)(*piVar5 + 0x30);
uVar10 = (**(code **)(*(int *)this + 0x24))(this);
(*pcVar1)(piVar5,"port",uVar10);
(**(code **)(*piVar5 + 0x3c))(piVar5,"game",com_gamedir);
pcVar1 = *(code **)(*piVar5 + 0x3c);
uVar10 = (**(code **)(*(int *)this + 0x3c))(this);
(*pcVar1)(piVar5,"mapname",uVar10);
pcVar1 = *(code **)(*piVar5 + 0x30);
uVar10 = (**(code **)(*(int *)this + 0x18))(this);
(*pcVar1)(piVar5,"maxplayers",uVar10);
(**(code **)(*piVar5 + 0x30))(piVar5,"password",0);
(**(code **)(*piVar5 + 0x3c))(piVar5,&DAT_002cd203,"LINUX");
pcVar1 = *(code **)(*piVar5 + 0x30);
uVar4 = (**(code **)(*(int *)this + 0x60))(this);
(*pcVar1)(piVar5,"dedicated",uVar4);
(**(code **)(*piVar5 + 0x2c))(piVar5,"vanilla",local_2a4);
(**(code **)(*piVar5 + 0x3c))(piVar5,"mission",local_2a8);
(**(code **)(*piVar5 + 0x3c))(piVar5,"gamemode",local_2ac);
(**(code **)(s_GameEventManager + 0x20))(&s_GameEventManager,piVar5,0);
}
COM_TimestampedLog("SV_SpawnServer -- Finished");
pKVar14 = g_pFileSystem;
(**(code **)(*(int *)g_pFileSystem + 0x158))(g_pFileSystem);
uVar10 = 1;
if (this_01 != (KeyValues *)0x0) {
KeyValues::deleteThis();
uVar10 = 1;
pKVar14 = this_01;
}
}
LAB_001fe7df:
if (local_20 != *(int *)(in_GS_OFFSET + 0x14)) {
/* WARNING: Subroutine does not return */
__stack_chk_fail(pKVar14);
}
return uVar10;
}
SourceMod gamedata
paste intoaddons/sourcemod/gamedata/<your_plugin>.txt
used as the SourceMod key — change to fit your plugin's convention
SourceMod library name (server / engine / matchmaking)
Just a Signatures{} block, ready to drop into a gamedata
file. Wire it up in your plugin however you like - SDKCall, DHooks,
raw memory ops, or anything else.
Signatures + Functions block. The plugin uses
DHookCreateFromConf - DHooks reads return type, this-type,
calling convention, and argument types straight from the gamedata. Less
boilerplate in the plugin, types travel with the gamedata.
Gamedata KeyValues
DHooks plugin example
Type inference is best-effort from the C signature - sanity-check the DHooks types before shipping.