Browse Source

Support reading ETFCond names

Might as well automate getting this data for quick references.
nosoop 5 years ago
parent
commit
a3f7824994
3 changed files with 61 additions and 3 deletions
  1. 2 1
      README.md
  2. 14 0
      gamedata/csrd.data_dump.txt
  3. 45 2
      scripting/csrd_data_dump.sp

+ 2 - 1
README.md

@@ -11,11 +11,12 @@ version in the game directory's `steam.inf` file.
 
 Currently dumps the following information:
 
-* SourceMod-included dump files: `sm_dump_datamaps`, `sm_dump_netprops`, `sm_dump_classes`
+* SourceMod-included dump files: `sm_dump_datamaps`, `sm_dump_netprops`, `sm_dump_tempents`
 * Custom dump functions that also dump ConVars and ConCommands into separate CSV files.
 Newlines in the description are replaced with forward slashes, double quotes are replaced with
 single quotes, and the default values for each ConVar are saved (instead of using the current
 values as the built-in `cvarlist` does.
+* Additional support for usermessages and ETFCond names.
 
 It also updates `data/datadump/.server-version` with the newest server version, allowing
 programs that monitor the filesystem to start [processing the dumps][dump-proc].

+ 14 - 0
gamedata/csrd.data_dump.txt

@@ -0,0 +1,14 @@
+"Games"
+{
+	"tf"
+	{
+		"Signatures"
+		{
+			"GetTFConditionName()"
+			{
+				"library"		"server"
+				"linux"			"@_Z18GetTFConditionName7ETFCond"
+			}
+		}
+	}
+}

+ 45 - 2
scripting/csrd_data_dump.sp

@@ -7,13 +7,14 @@
 #include <sourcemod>
 
 #tryinclude <steamtools>
+#include <sdktools>
 
 #pragma newdecls required
 #include <stocksoup/log_server>
 #include <stocksoup/files>
 #include <stocksoup/version>
 
-#define PLUGIN_VERSION "1.4.0"
+#define PLUGIN_VERSION "1.5.0"
 public Plugin myinfo = {
 	name = "[CSRD] SRCDS Automatic Data Dumper",
 	author = "nosoop",
@@ -43,9 +44,11 @@ enum DumpAction {
 DumpAction g_DumpAction;
 StringMap g_ConCommandFlagCache;
 
+Handle g_SDKCallGetTFConditionName, g_SDKCallGetTFConditionNamePtr;
+
 public APLRes AskPluginLoad2(Handle hPluginSelf, bool bLateLoaded, char[] error, int err_max) {
 	if (bLateLoaded) {
-		// skip dump on late load because muh consistency
+		// skip dump on late load because it's too late to cache flags for consistency
 		g_DumpAction = DumpAction_None;
 	} else {
 		g_DumpAction = DumpAction_UpdateCheck;
@@ -74,6 +77,27 @@ public APLRes AskPluginLoad2(Handle hPluginSelf, bool bLateLoaded, char[] error,
 }
 
 public void OnPluginStart() {
+	Handle hGameConf = LoadGameConfigFile("csrd.data_dump");
+	if (!hGameConf) {
+		SetFailState("Failed to load gamedata (csrd.data_dump).");
+	}
+	
+	// we call and fetch the pointer to work around alliedmodders/sourcemod#874
+	// we could read the pointer directly, but ain't got time for that
+	StartPrepSDKCall(SDKCall_Static);
+	PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "GetTFConditionName()");
+	PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
+	PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
+	g_SDKCallGetTFConditionNamePtr = EndPrepSDKCall();
+	
+	StartPrepSDKCall(SDKCall_Static);
+	PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "GetTFConditionName()");
+	PrepSDKCall_SetReturnInfo(SDKType_String, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL);
+	PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
+	g_SDKCallGetTFConditionName = EndPrepSDKCall();
+	
+	delete hGameConf;
+	
 	RegAdminCmd("csrd_force_data_dump", ForceDataDump, ADMFLAG_ROOT);
 }
 
@@ -150,6 +174,7 @@ void PerformDataDump(RequestFrameCallback postDumpCallback = INVALID_FUNCTION, a
 	DumpServerCommands("%s/%d.commands.txt", outputDirectory, version);
 	DumpServerConVars("%s/%d.convars.txt", outputDirectory, version);
 	DumpUserMessageNames("%s/%d.usermessages.txt", outputDirectory, version);
+	DumpTFCondNames("%s/%d.tf_conds.txt", outputDirectory, version);
 	
 	/**
 	 * Spawns all entities, server will crash on map change -- make sure there are 700-ish
@@ -320,6 +345,24 @@ void DumpUserMessageNames(const char[] format, any ...) {
 	delete outputFile;
 }
 
+void DumpTFCondNames(const char[] format, any ...) {
+	char outputPath[PLATFORM_MAX_PATH];
+	VFormat(outputPath, sizeof(outputPath), format, 2);
+	
+	File outputFile = OpenFile(outputPath, "w");
+	outputFile.WriteLine("\"%s\",\"%s\"", "Condition Index", "Name");
+	
+	char condName[64];
+	int cond;
+	while (SDKCall(g_SDKCallGetTFConditionNamePtr, cond)
+			&& SDKCall(g_SDKCallGetTFConditionName, condName, sizeof(condName), cond)) {
+		outputFile.WriteLine("\"%d\",\"%s\"", cond, condName);
+		cond++;
+	}
+	
+	delete outputFile;
+}
+
 /** 
  * Converts bitflags from a ConCommandBase to a space-separated list of flag descriptions.
  */