extensions/sdktools/tempents.cpp
changeset 1052 a2de25952811
parent 1039 71e55e3fd8f7
child 1059 255bb3a2f47b
     1.1 --- a/extensions/sdktools/tempents.cpp	Sat Jul 07 18:46:40 2007 +0000
     1.2 +++ b/extensions/sdktools/tempents.cpp	Sat Jul 07 20:45:48 2007 +0000
     1.3 @@ -26,6 +26,42 @@
     1.4  TempEntityManager g_TEManager;
     1.5  ICallWrapper *g_GetServerClass = NULL;
     1.6  
     1.7 +CON_COMMAND(sm_print_telist, "Prints the temp entity list")
     1.8 +{
     1.9 +	if (!g_TEManager.IsAvailable())
    1.10 +	{
    1.11 +		META_CONPRINT("The tempent portion of SDKTools failed to load.\n");
    1.12 +		META_CONPRINT("Check that you have the latest sdktools.games.txt file!\n");
    1.13 +		return;
    1.14 +	}
    1.15 +	g_TEManager.DumpList();
    1.16 +}
    1.17 +
    1.18 +CON_COMMAND(sm_dump_teprops, "Dumps tempentity props to a file")
    1.19 +{
    1.20 +	if (!g_TEManager.IsAvailable())
    1.21 +	{
    1.22 +		META_CONPRINT("The tempent portion of SDKTools failed to load.\n");
    1.23 +		META_CONPRINT("Check that you have the latest sdktools.games.txt file!\n");
    1.24 +		return;
    1.25 +	}
    1.26 +	int argc = engine->Cmd_Argc();
    1.27 +	if (argc < 2)
    1.28 +	{
    1.29 +		META_CONPRINT("Usage: sm_dump_teprops <file>\n");
    1.30 +		return;
    1.31 +	}
    1.32 +	const char *arg = engine->Cmd_Argv(1);
    1.33 +	FILE *fp = NULL;
    1.34 +	if (!arg || arg[0] == '\0' || ((fp = fopen(arg, "wt")) == NULL))
    1.35 +	{
    1.36 +		META_CONPRINTF("Could not open file \"%s\"\n", arg);
    1.37 +		return;
    1.38 +	}
    1.39 +	g_TEManager.DumpProps(fp);
    1.40 +	fclose(fp);
    1.41 +}
    1.42 +
    1.43  /*************************
    1.44  *                        *
    1.45  * Temp Entities Wrappers *
    1.46 @@ -44,6 +80,11 @@
    1.47  	return m_Name.c_str();
    1.48  }
    1.49  
    1.50 +ServerClass *TempEntityInfo::GetServerClass()
    1.51 +{
    1.52 +	return m_Sc;
    1.53 +}
    1.54 +
    1.55  bool TempEntityInfo::IsValidProp(const char *name)
    1.56  {
    1.57  	return (g_pGameHelpers->FindInSendTable(m_Sc->GetName(), name)) ? true : false;
    1.58 @@ -263,3 +304,95 @@
    1.59  
    1.60  	return te;
    1.61  }
    1.62 +
    1.63 +void TempEntityManager::DumpList()
    1.64 +{
    1.65 +	unsigned int index = 0;
    1.66 +	META_CONPRINT("Listing temp entities:\n");
    1.67 +	void *iter = m_ListHead;
    1.68 +	while (iter)
    1.69 +	{
    1.70 +		const char *realname = *(const char **)((unsigned char *)iter + m_NameOffs);
    1.71 +		if (!realname)
    1.72 +		{
    1.73 +			break;
    1.74 +		}
    1.75 +		TempEntityInfo *info = GetTempEntityInfo(realname);
    1.76 +		if (!info)
    1.77 +		{
    1.78 +			continue;
    1.79 +		}
    1.80 +		ServerClass *sc = info->GetServerClass();
    1.81 +		META_CONPRINTF("[%02d] %s (%s)\n", index++, realname, sc->GetName());
    1.82 +		iter = *(void **)((unsigned char *)iter + m_NextOffs);
    1.83 +	}
    1.84 +	META_CONPRINTF("%d tempent%s found.\n", index, (index == 1) ? " was" : "s were");
    1.85 +}
    1.86 +
    1.87 +const char *SendPropTypeToString(SendPropType type)
    1.88 +{
    1.89 +	if (type == DPT_Int)
    1.90 +	{
    1.91 +		return "int";
    1.92 +	} else if (type == DPT_Float) {
    1.93 +		return "float";
    1.94 +	} else if (type == DPT_Vector) {
    1.95 +		return "vector";
    1.96 +	} else if (type == DPT_String) {
    1.97 +		return "string";
    1.98 +	} else if (type == DPT_Array) {
    1.99 +		return "array";
   1.100 +	} else if (type == DPT_DataTable) {
   1.101 +		return "datatable";
   1.102 +	} else {
   1.103 +		return "unknown";
   1.104 +	}
   1.105 +}
   1.106 +
   1.107 +void _DumpProps(FILE *fp, SendTable *pTable)
   1.108 +{
   1.109 +	SendTable *pOther;
   1.110 +	for (int i=0; i<pTable->GetNumProps(); i++)
   1.111 +	{
   1.112 +		SendProp *prop = pTable->GetProp(i);
   1.113 +		if ((pOther = prop->GetDataTable()) != NULL)
   1.114 +		{
   1.115 +			_DumpProps(fp, pOther);
   1.116 +		} else {
   1.117 +			fprintf(fp, "\t\t\t\"%s\"\t\t\"%s\"\n", 
   1.118 +				prop->GetName() ? prop->GetName() : "unknown",
   1.119 +				SendPropTypeToString(prop->GetType()));
   1.120 +		}
   1.121 +	}
   1.122 +}
   1.123 +
   1.124 +void TempEntityManager::DumpProps(FILE *fp)
   1.125 +{
   1.126 +	unsigned int index = 0;
   1.127 +	void *iter = m_ListHead;
   1.128 +	fprintf(fp, "\"TempEnts\"\n{\n");
   1.129 +	while (iter)
   1.130 +	{
   1.131 +		const char *realname = *(const char **)((unsigned char *)iter + m_NameOffs);
   1.132 +		if (!realname)
   1.133 +		{
   1.134 +			break;
   1.135 +		}
   1.136 +		TempEntityInfo *info = GetTempEntityInfo(realname);
   1.137 +		if (!info)
   1.138 +		{
   1.139 +			continue;
   1.140 +		}
   1.141 +		ServerClass *sc = info->GetServerClass();
   1.142 +		fprintf(fp, "\t\"%s\"\n", sc->GetName());
   1.143 +		fprintf(fp, "\t{\n");
   1.144 +		fprintf(fp, "\t\t\"name\"\t\t\"%s\"\n", realname);
   1.145 +		fprintf(fp, "\t\t\"index\"\t\t\"%d\"\n", index++);
   1.146 +		fprintf(fp, "\t\t\"SendTable\"\n\t\t{\n");
   1.147 +		_DumpProps(fp, sc->m_pTable);
   1.148 +		fprintf(fp, "\t\t}\n\t}\n");
   1.149 +		iter = *(void **)((unsigned char *)iter + m_NextOffs);
   1.150 +	}
   1.151 +	fprintf(fp, "}\n");
   1.152 +	META_CONPRINTF("%d tempent%s written to file.\n", index, (index == 1) ? " was" : "s were");
   1.153 +}