extensions/sdktools/vhelpers.cpp
changeset 1636 c13834955093
parent 1628 3fd76ba845b8
child 1640 a644ed81b457
     1.1 --- a/extensions/sdktools/vhelpers.cpp	Mon Oct 22 07:27:48 2007 +0000
     1.2 +++ b/extensions/sdktools/vhelpers.cpp	Mon Oct 22 07:41:57 2007 +0000
     1.3 @@ -272,3 +272,222 @@
     1.4  	s_Teleport.Shutdown();
     1.5  	s_GetVelocity.Shutdown();
     1.6  }
     1.7 +
     1.8 +const char *GetDTTypeName(int type)
     1.9 +{
    1.10 +	switch (type)
    1.11 +	{
    1.12 +	case DPT_Int:
    1.13 +		{
    1.14 +			return "integer";
    1.15 +		}
    1.16 +	case DPT_Float:
    1.17 +		{
    1.18 +			return "float";
    1.19 +		}
    1.20 +	case DPT_Vector:
    1.21 +		{
    1.22 +			return "vector";
    1.23 +		}
    1.24 +	case DPT_String:
    1.25 +		{
    1.26 +			return "string";
    1.27 +		}
    1.28 +	case DPT_Array:
    1.29 +		{
    1.30 +			return "array";
    1.31 +		}
    1.32 +	case DPT_DataTable:
    1.33 +		{
    1.34 +			return "datatable";
    1.35 +		}
    1.36 +	default:
    1.37 +		{
    1.38 +			return NULL;
    1.39 +		}
    1.40 +	}
    1.41 +
    1.42 +	return NULL;
    1.43 +}
    1.44 +
    1.45 +void UTIL_DrawSendTable_XML(FILE *fp, SendTable *pTable, int space_count)
    1.46 +{
    1.47 +	char spaces[255];
    1.48 +
    1.49 +	for (int i = 0; i < space_count; i++)
    1.50 +	{
    1.51 +		spaces[i] = ' ';
    1.52 +	}
    1.53 +	spaces[space_count] = '\0';
    1.54 +
    1.55 +	const char *type_name;
    1.56 +	SendTable *pOtherTable;
    1.57 +	SendProp *pProp;
    1.58 +
    1.59 +	fprintf(fp, " %s<sendtable name=\"%s\">\n", spaces, pTable->GetName());
    1.60 +	for (int i = 0; i < pTable->GetNumProps(); i++)
    1.61 +	{
    1.62 +		pProp = pTable->GetProp(i);
    1.63 +
    1.64 +		fprintf(fp, "  %s<property name=\"%s\">\n", spaces, pProp->GetName());
    1.65 +
    1.66 +		if ((type_name = GetDTTypeName(pProp->GetType())) != NULL)
    1.67 +		{
    1.68 +			fprintf(fp, "   %s<type>%s</type>\n", spaces, type_name);
    1.69 +		}
    1.70 +		else
    1.71 +		{
    1.72 +			fprintf(fp, "   %s<type>%d</type>\n", spaces, pProp->GetType());
    1.73 +		}
    1.74 +
    1.75 +		fprintf(fp, "   %s<offset>%d</offset>\n", spaces, pProp->GetOffset());
    1.76 +		fprintf(fp, "   %s<bits>%d</bits>\n", spaces, pProp->m_nBits);
    1.77 +
    1.78 +		if ((pOtherTable = pTable->GetProp(i)->GetDataTable()) != NULL)
    1.79 +		{
    1.80 +			UTIL_DrawSendTable_XML(fp, pOtherTable, space_count + 3);
    1.81 +		}
    1.82 +
    1.83 +		fprintf(fp, "  %s</property>\n", spaces);
    1.84 +	}
    1.85 +	fprintf(fp, " %s</sendtable>\n", spaces);
    1.86 +}
    1.87 +
    1.88 +void UTIL_DrawServerClass_XML(FILE *fp, ServerClass *sc)
    1.89 +{
    1.90 +	fprintf(fp, "<serverclass name=\"%s\">\n", sc->GetName());
    1.91 +	UTIL_DrawSendTable_XML(fp, sc->m_pTable, 0);
    1.92 +	fprintf(fp, "</serverclass>\n");
    1.93 +}
    1.94 +
    1.95 +void UTIL_DrawSendTable(FILE *fp, SendTable *pTable, int level)
    1.96 +{
    1.97 +	char spaces[255];
    1.98 +	for (int i=0; i<level; i++)
    1.99 +		spaces[i] = ' ';
   1.100 +	spaces[level] = '\0';
   1.101 +
   1.102 +	const char *name, *type;
   1.103 +	SendProp *pProp;
   1.104 +
   1.105 +	fprintf(fp, "%sSub-Class Table (%d Deep): %s\n", spaces, level, pTable->GetName());
   1.106 +
   1.107 +	for (int i=0; i<pTable->GetNumProps(); i++)
   1.108 +	{
   1.109 +		pProp = pTable->GetProp(i);
   1.110 +		name = pProp->GetName();
   1.111 +		if (pProp->GetDataTable())
   1.112 +		{
   1.113 +			UTIL_DrawSendTable(fp, pProp->GetDataTable(), level + 1);
   1.114 +		}
   1.115 +		else
   1.116 +		{
   1.117 +			type = GetDTTypeName(pProp->GetType());
   1.118 +
   1.119 +			if (type != NULL)
   1.120 +			{
   1.121 +				fprintf(fp,
   1.122 +					"%s-Member: %s (offset %d) (type %s) (bits %d)\n", 
   1.123 +					spaces, 
   1.124 +					pProp->GetName(),
   1.125 +					pProp->GetOffset(),
   1.126 +					type,
   1.127 +					pProp->m_nBits);
   1.128 +			}
   1.129 +			else
   1.130 +			{
   1.131 +				fprintf(fp,
   1.132 +					"%s-Member: %s (offset %d) (type %d) (bits %d)\n", 
   1.133 +					spaces, 
   1.134 +					pProp->GetName(),
   1.135 +					pProp->GetOffset(),
   1.136 +					pProp->GetType(),
   1.137 +					pProp->m_nBits);
   1.138 +			}
   1.139 +		}
   1.140 +	}
   1.141 +}
   1.142 +
   1.143 +CON_COMMAND(sm_dump_netprops_xml, "Dumps the networkable property table as an XML file")
   1.144 +{
   1.145 +#if !defined ORANGEBOX_BUILD
   1.146 +	CCommand args;
   1.147 +#endif
   1.148 +
   1.149 +	if (args.ArgC() < 2)
   1.150 +	{
   1.151 +		META_CONPRINT("Usage: sm_dump_netprops_xml <file>\n");
   1.152 +		return;
   1.153 +	}
   1.154 +
   1.155 +	const char *file = args.Arg(1);
   1.156 +	if (!file || file[0] == '\0')
   1.157 +	{
   1.158 +		META_CONPRINT("Usage: sm_dump_netprops_xml <file>\n");
   1.159 +		return;
   1.160 +	}
   1.161 +
   1.162 +	char path[PLATFORM_MAX_PATH];
   1.163 +	g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", file);
   1.164 +
   1.165 +	FILE *fp = NULL;
   1.166 +	if ((fp = fopen(path, "wt")) == NULL)
   1.167 +	{
   1.168 +		META_CONPRINTF("Could not open file \"%s\"\n", path);
   1.169 +		return;
   1.170 +	}
   1.171 +
   1.172 +	fprintf(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
   1.173 +	fprintf(fp, "<!-- Dump of all network properties for \"%s\" follows -->\n\n", g_pSM->GetGameFolderName());
   1.174 +
   1.175 +	ServerClass *pBase = gamedll->GetAllServerClasses();
   1.176 +	while (pBase != NULL)
   1.177 +	{
   1.178 +		UTIL_DrawServerClass_XML(fp, pBase);
   1.179 +		pBase = pBase->m_pNext;
   1.180 +	}
   1.181 +
   1.182 +	fclose(fp);
   1.183 +}
   1.184 +
   1.185 +CON_COMMAND(sm_dump_netprops, "Dumps the networkable property table as a text file")
   1.186 +{
   1.187 +#if !defined ORANGEBOX_BUILD
   1.188 +	CCommand args;
   1.189 +#endif
   1.190 +
   1.191 +	if (args.ArgC() < 2)
   1.192 +	{
   1.193 +		META_CONPRINT("Usage: sm_dump_netprops <file>\n");
   1.194 +		return;
   1.195 +	}
   1.196 +
   1.197 +	const char *file = args.Arg(1);
   1.198 +	if (!file || file[0] == '\0')
   1.199 +	{
   1.200 +		META_CONPRINT("Usage: sm_dump_netprops <file>\n");
   1.201 +		return;
   1.202 +	}
   1.203 +
   1.204 +	char path[PLATFORM_MAX_PATH];
   1.205 +	g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", file);
   1.206 +
   1.207 +	FILE *fp = NULL;
   1.208 +	if ((fp = fopen(path, "wt")) == NULL)
   1.209 +	{
   1.210 +		META_CONPRINTF("Could not open file \"%s\"\n", path);
   1.211 +		return;
   1.212 +	}
   1.213 +
   1.214 +	fprintf(fp, "// Dump of all network properties for \"%s\" follows\n//\n\n", g_pSM->GetGameFolderName());
   1.215 +
   1.216 +	ServerClass *pBase = gamedll->GetAllServerClasses();
   1.217 +	while (pBase != NULL)
   1.218 +	{
   1.219 +		UTIL_DrawSendTable(fp, pBase->m_pTable, 1);
   1.220 +		pBase = pBase->m_pNext;
   1.221 +	}
   1.222 +
   1.223 +	fclose(fp);
   1.224 +}
   1.225 +