void UpdateValveGlobals() { s_pGameRules = nullptr; const char *pszNetClass = g_pGameConf->GetKeyValue("GameRulesProxy"); const char *pszDTName = g_pGameConf->GetKeyValue("GameRulesDataTable"); if (pszNetClass && pszDTName) { sm_sendprop_info_t info; ServerClass *sc = UTIL_FindServerClass(pszNetClass); if (sc && UTIL_FindDataTable(sc->m_pTable, pszDTName, &info)) { auto proxyFn = info.prop->GetDataTableProxyFn(); if (proxyFn) { CSendProxyRecipients recp; s_pGameRules = proxyFn(nullptr, nullptr, nullptr, &recp, 0); } } } }
static bool UTIL_FindDataTable(SendTable *pTable, const char *name, sm_sendprop_info_t *info, unsigned int offset = 0) { const char *pname; int props = pTable->GetNumProps(); SendProp *prop; SendTable *table; for (int i = 0; i<props; i++) { prop = pTable->GetProp(i); if ((table = prop->GetDataTable()) != NULL) { pname = prop->GetName(); if (pname && strcmp(name, pname) == 0) { info->prop = prop; info->actual_offset = offset + info->prop->GetOffset(); return true; } if (UTIL_FindDataTable(table, name, info, offset + prop->GetOffset()) ) { return true; } } } return false; }
bool TF2Tools::SDK_OnLoad(char *error, size_t maxlength, bool late) { if (strcmp(g_pSM->GetGameFolderName(), "tf") != 0) { UTIL_Format(error, maxlength, "Cannot Load TF2 Extension on mods other than TF2"); return false; } ServerClass *sc = UTIL_FindServerClass("CTFPlayer"); if (sc == NULL) { UTIL_Format(error, maxlength, "Could not find CTFPlayer server class"); return false; } playerSharedOffset = new sm_sendprop_info_t; if (!UTIL_FindDataTable(sc->m_pTable, "DT_TFPlayerShared", playerSharedOffset, 0)) { UTIL_Format(error, maxlength, "Could not find DT_TFPlayerShared data table"); return false; } sharesys->AddDependency(myself, "bintools.ext", true, true); sharesys->AddDependency(myself, "sdkhooks.ext", true, true); sharesys->AddDependency(myself, "sdktools.ext", false, true); char conf_error[255] = ""; if (!gameconfs->LoadGameConfigFile("sm-tf2.games", &g_pGameConf, conf_error, sizeof(conf_error))) { if (conf_error[0]) { UTIL_Format(error, maxlength, "Could not read sm-tf2.games.txt: %s", conf_error); } return false; } CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf); sharesys->AddNatives(myself, g_TFNatives); sharesys->RegisterLibrary(myself, "tf2"); plsys->AddPluginsListener(this); playerhelpers->RegisterCommandTargetProcessor(this); g_critForward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef); g_addCondForward = forwards->CreateForward("TF2_OnConditionAdded", ET_Ignore, 2, NULL, Param_Cell, Param_Cell); g_removeCondForward = forwards->CreateForward("TF2_OnConditionRemoved", ET_Ignore, 2, NULL, Param_Cell, Param_Cell); g_waitingPlayersStartForward = forwards->CreateForward("TF2_OnWaitingForPlayersStart", ET_Ignore, 0, NULL); g_waitingPlayersEndForward = forwards->CreateForward("TF2_OnWaitingForPlayersEnd", ET_Ignore, 0, NULL); g_teleportForward = forwards->CreateForward("TF2_OnPlayerTeleport", ET_Hook, 3, NULL, Param_Cell, Param_Cell, Param_CellByRef); g_pCVar = icvar; m_CritDetoursEnabled = false; m_CondChecksEnabled = false; m_RulesDetoursEnabled = false; m_TeleportDetourEnabled = false; g_HolidayManager.OnSDKLoad(late); return true; }