Browse Source

Add support for dumping usermessages

FlaminSarge demanded this
nosoop 6 years ago
parent
commit
5b21c23684
1 changed files with 26 additions and 2 deletions
  1. 26 2
      scripting/csrd_data_dump.sp

+ 26 - 2
scripting/csrd_data_dump.sp

@@ -13,7 +13,7 @@
 #include <stocksoup/files>
 #include <stocksoup/version>
 
-#define PLUGIN_VERSION "1.1.5"
+#define PLUGIN_VERSION "1.2.0"
 public Plugin myinfo = {
 	name = "[CSRD] SRCDS Automatic Data Dumper",
 	author = "nosoop",
@@ -45,6 +45,7 @@ StringMap g_ConCommandFlagCache;
 
 public APLRes AskPluginLoad2(Handle hPluginSelf, bool bLateLoaded, char[] error, int err_max) {
 	if (bLateLoaded) {
+		// skip dump on late load because muh consistency
 		g_DumpAction = DumpAction_None;
 	} else {
 		g_DumpAction = DumpAction_UpdateCheck;
@@ -130,6 +131,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);
 	
 	/**
 	 * spawns all entities, server will crash on map change -- make sure there are 1400-ish
@@ -138,7 +140,7 @@ void PerformDataDump(RequestFrameCallback postDumpCallback = INVALID_FUNCTION, a
 	ServerCommand("sm_dump_datamaps %s/%d.datamaps.txt", outputDirectory, version);
 	
 	// TODO replace this with just filtering the appropriate lines from datamaps?
-	// match expr /^[A-Za-z0-9_]+ - [A-Za-z0-9_]+$/
+	// match expr /^\w+ - \w+$/
 	ServerCommand("sm_dump_classes %s/%d.classes.txt", outputDirectory, version);
 	
 	ServerCommand("sm_dump_teprops %s/%d.tempents.txt", outputDirectory, version);
@@ -285,7 +287,29 @@ void DumpServerConVars(const char[] format, any ...) {
 	delete outputFile;
 }
 
+/**
+ * Dumps user message names to a path created by the format string.
+ */
+void DumpUserMessageNames(const char[] format, any ...) {
+	char outputPath[PLATFORM_MAX_PATH];
+	VFormat(outputPath, sizeof(outputPath), format, 2);
+	
+	File outputFile = OpenFile(outputPath, "w");
+	outputFile.WriteLine("\"%s\",\"%s\"", "Index", "Name");
+	
+	char umName[128];
+	for (int um = 0; GetUserMessageName(view_as<UserMsg>(um), umName, sizeof(umName)); um++) {
+		outputFile.WriteLine("\"%d\",\"%s\"", um, umName);
+	}
+	
+	delete outputFile;
+}
+
+/** 
+ * Converts bitflags from a ConCommandBase to a space-separated list of flag descriptions.
+ */
 char[] GetCommandFlagString(int flags) {
+	// static array of flag descriptions, index mapped to corresponding bit
 	static char s_flagStrings[][] = {
 		"UNREGISTERED",
 		"DEVELOPMENTONLY",