summaryrefslogtreecommitdiff
path: root/utils/xbox/dumpobj
diff options
context:
space:
mode:
Diffstat (limited to 'utils/xbox/dumpobj')
-rw-r--r--utils/xbox/dumpobj/dumpobj.cpp407
-rw-r--r--utils/xbox/dumpobj/dumpobj.vcproj156
2 files changed, 563 insertions, 0 deletions
diff --git a/utils/xbox/dumpobj/dumpobj.cpp b/utils/xbox/dumpobj/dumpobj.cpp
new file mode 100644
index 0000000..e074d25
--- /dev/null
+++ b/utils/xbox/dumpobj/dumpobj.cpp
@@ -0,0 +1,407 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+/*****************************************************************************
+ DUMPOBJ.CPP
+
+*****************************************************************************/
+#include "..\toollib\toollib.h"
+
+typedef struct section_s
+{
+ int size;
+ char* name;
+ section_s* nextPtr;
+} section_t;
+
+typedef struct obj_s
+{
+ char* filename;
+ section_t* sectionPtr;
+ obj_s* nextPtr;
+} obj_t;
+
+obj_t* g_obj_head;
+char g_sectionName[128];
+bool g_bVerbose;
+
+typedef struct
+{
+ char* filename;
+ int size;
+} entry_t;
+
+/***********************************************************
+ _SortCallback
+
+***********************************************************/
+int _SortCallback(const void *a, const void *b)
+{
+ entry_t* aPtr;
+ entry_t* bPtr;
+
+ aPtr = (entry_t*)a;
+ bPtr = (entry_t*)b;
+
+ return (aPtr->size-bPtr->size);
+}
+
+/***********************************************************
+ FreeInfo
+
+***********************************************************/
+void FreeInfo()
+{
+ obj_t* objPtr;
+ obj_t* nextObjPtr;
+ section_t* sectionPtr;
+ section_t* nextSectionPtr;
+
+ objPtr = g_obj_head;
+ while (objPtr)
+ {
+ nextObjPtr = objPtr->nextPtr;
+ sectionPtr = objPtr->sectionPtr;
+ while (sectionPtr)
+ {
+ nextSectionPtr = sectionPtr->nextPtr;
+
+ TL_Free(sectionPtr->name);
+ TL_Free(sectionPtr);
+
+ sectionPtr = nextSectionPtr;
+ }
+
+ TL_Free(objPtr->filename);
+ TL_Free(objPtr);
+
+ objPtr = nextObjPtr;
+ }
+}
+
+/***********************************************************
+ AnalyzeData
+
+***********************************************************/
+void AnalyzeData()
+{
+ obj_t* objPtr;
+ section_t* sectionPtr;
+ char* sections[128];
+ int totals[128];
+ int numSections;
+ int i;
+ int index;
+ int numEntries;
+ entry_t* entries;
+ int total;
+
+ printf("\n");
+
+ memset(totals, 0, sizeof(totals));
+
+ // determine unique sections
+ numSections = 0;
+ objPtr = g_obj_head;
+ while (objPtr)
+ {
+ sectionPtr = objPtr->sectionPtr;
+ while (sectionPtr)
+ {
+ for (i=0; i<numSections; i++)
+ {
+ if (!stricmp(sections[i],sectionPtr->name))
+ break;
+ }
+ if (i >= numSections)
+ {
+ // add it
+ sections[numSections] = sectionPtr->name;
+ numSections++;
+ assert(numSections < 128);
+
+ index = numSections-1;
+ }
+ else
+ index = i;
+
+ totals[index] += sectionPtr->size;
+
+ sectionPtr = sectionPtr->nextPtr;
+ }
+ objPtr = objPtr->nextPtr;
+ }
+
+ if (g_sectionName[0])
+ {
+ // dump only matching section
+ printf("Section: %s\n", g_sectionName);
+ printf("-------------------------\n");
+
+ // tally entries
+ numEntries = 0;
+ objPtr = g_obj_head;
+ while (objPtr)
+ {
+ sectionPtr = objPtr->sectionPtr;
+ while (sectionPtr)
+ {
+ if (!stricmp(g_sectionName, sectionPtr->name))
+ numEntries++;
+ sectionPtr = sectionPtr->nextPtr;
+ }
+ objPtr = objPtr->nextPtr;
+ }
+
+ // fill entries
+ if (numEntries)
+ {
+ entries = (entry_t*)TL_Malloc(numEntries*sizeof(entry_t));
+ numEntries = 0;
+ objPtr = g_obj_head;
+ while (objPtr)
+ {
+ sectionPtr = objPtr->sectionPtr;
+ while (sectionPtr)
+ {
+ if (!stricmp(g_sectionName, sectionPtr->name))
+ {
+ entries[numEntries].size = sectionPtr->size;
+ entries[numEntries].filename = objPtr->filename;
+ numEntries++;
+ }
+ sectionPtr = sectionPtr->nextPtr;
+ }
+ objPtr = objPtr->nextPtr;
+ }
+
+ // sort
+ qsort(entries, numEntries, sizeof(entry_t), _SortCallback);
+
+ // display results
+ int total = 0;
+ for (i=0; i<numEntries; i++)
+ {
+ printf("%8d %s\n", entries[i].size, entries[i].filename);
+ total += entries[i].size;
+ }
+ printf("-------------------------\n");
+ printf("%8d Total\n", total);
+
+ TL_Free(entries);
+ }
+ }
+ else
+ {
+ // dump all sections
+ printf("Sections:\n");
+ printf("---------\n");
+ total = 0;
+ for (i=0; i<numSections; i++)
+ {
+ printf("%8d %s\n", totals[i], sections[i]);
+ total += totals[i];
+ }
+ printf("---------\n");
+ printf("%8d\n", total);
+ }
+}
+
+
+/***********************************************************
+ LocalExec
+
+***********************************************************/
+int LocalExec(const char* batfilename, const char* arg1)
+{
+ intptr_t pid;
+ int errcode;
+ const char* args[8];
+
+ args[0] = batfilename;
+ args[1] = arg1;
+ args[2] = NULL;
+
+ pid = _spawnvp(P_NOWAIT, batfilename, args);
+ _cwait(&errcode, pid, 0);
+
+ return (errcode);
+}
+
+/*****************************************************************************
+ GetInfo
+
+*****************************************************************************/
+void GetInfo(char* objFilename, char* batFilename, char* logFilename)
+{
+ char buff[TL_MAXPATH];
+ int size;
+ char name[128];
+ char* ptr;
+ int errcode;
+ char* token;
+ obj_t* objPtr;
+ section_t* sectionPtr;
+
+ if (g_bVerbose)
+ printf("%s\n", objFilename);
+
+ ptr = objFilename;
+ if (!strnicmp(objFilename,".\\",2))
+ {
+ ptr += 2;
+
+ getcwd(buff, sizeof(buff));
+ TL_AddSeperatorToPath(buff, buff);
+
+ strcat(buff, ptr);
+ }
+ else
+ strcpy(buff, objFilename);
+
+ // exec the batch file with the obj file
+ errcode = LocalExec(batFilename, buff);
+ if (errcode)
+ {
+ printf("Failed on %s\n", buff);
+ return;
+ }
+
+ // add new object node
+ objPtr = (obj_t*)TL_Malloc(sizeof(obj_t));
+ objPtr->filename = (char*)TL_Malloc((int)strlen(objFilename)+1);
+ strcpy(objPtr->filename, objFilename);
+
+ // link it in
+ objPtr->nextPtr = g_obj_head;
+ g_obj_head = objPtr;
+
+ // read the results
+ TL_LoadScriptFile(logFilename);
+
+ while (1)
+ {
+ token = TL_GetToken(true);
+ if (!token || !token[0])
+ break;
+
+ if (!stricmp(token, "summary"))
+ break;
+ else
+ TL_SkipRestOfLine();
+ }
+
+ while (1)
+ {
+ token = TL_GetToken(true);
+ if (!token || !token[0])
+ break;
+ sscanf(token, "%x", &size);
+
+ token = TL_GetToken(true);
+ if (!token || !token[0])
+ break;
+ strcpy(name, token);
+
+ // add new section node
+ sectionPtr = (section_t*)TL_Malloc(sizeof(section_t));
+ sectionPtr->name = (char*)TL_Malloc((int)strlen(name)+1);
+ strcpy(sectionPtr->name, name);
+ sectionPtr->size = size;
+
+ // link it in
+ sectionPtr->nextPtr = objPtr->sectionPtr;
+ objPtr->sectionPtr = sectionPtr;
+ }
+
+ TL_FreeScriptFile();
+}
+
+/*****************************************************************************
+ Usage
+
+*****************************************************************************/
+void Usage(void)
+{
+ printf("usage: dumpobj <*.obj> [-s section] [-r] [-v]\n");
+ exit(-1);
+}
+
+/*****************************************************************************
+ main
+
+*****************************************************************************/
+int main(int argc, char* argv[])
+{
+ tlfile_t** filelist;
+ int filecount;
+ int i;
+ int recurse;
+ int section;
+ FILE* fp;
+ char* vcvarsPath;
+ char batFilename[TL_MAXPATH];
+ char txtFilename[TL_MAXPATH];
+
+ batFilename[0] = '\0';
+ txtFilename[0] = '\0';
+
+ TL_Setup("DUMPOBJ",argc,argv);
+
+ // find critical path to vcvars32.bat
+ vcvarsPath = "c:\\Program Files\\Microsoft Visual Studio .Net 2003\\Vc7\\bin\\vcvars32.bat";
+ if (!TL_Exists(vcvarsPath))
+ TL_Error("Cannot find: %s\n", vcvarsPath);
+
+ if (argc < 2)
+ Usage();
+
+ recurse = TL_CheckParm("r");
+ filecount = TL_FindFiles2(argv[1], recurse != 0, &filelist);
+
+ g_bVerbose = TL_CheckParm("v") != 0;
+
+ section = TL_CheckParm("s");
+ if (section && section+1 < argc)
+ strcpy(g_sectionName, argv[section+1]);
+ else
+ g_sectionName[0] = '\0';
+
+ strcpy(batFilename,"c:\\");
+ TL_TempFilename(batFilename);
+ TL_ReplaceDosExtension(batFilename, ".bat");
+
+ strcpy(txtFilename,"c:\\");
+ TL_TempFilename(txtFilename);
+ TL_ReplaceDosExtension(txtFilename, ".txt");
+
+ if (filecount)
+ {
+ // create bat file
+ fp = fopen(batFilename, "wt+");
+ if (!fp)
+ TL_Error("Could not open bat file '%s'", batFilename);
+
+ fprintf(fp, "@echo off\n");
+ fprintf(fp, "@call \"%s\" > nul: \n", vcvarsPath);
+ fprintf(fp, "@dumpbin %%1 > %s\n", txtFilename);
+ fclose(fp);
+ }
+
+ for (i=0; i<filecount; i++)
+ GetInfo(filelist[i]->filename, batFilename, txtFilename);
+
+ if (filecount)
+ AnalyzeData();
+
+ if (filecount)
+ {
+ FreeInfo();
+ unlink(batFilename);
+ unlink(txtFilename);
+ }
+
+ TL_FreeFileList(filecount,filelist);
+
+ TL_End(false);
+
+ return (0);
+} \ No newline at end of file
diff --git a/utils/xbox/dumpobj/dumpobj.vcproj b/utils/xbox/dumpobj/dumpobj.vcproj
new file mode 100644
index 0000000..2227140
--- /dev/null
+++ b/utils/xbox/dumpobj/dumpobj.vcproj
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="dumpobj"
+ ProjectGUID="{620FC3E4-31D4-49F4-A66C-089A543FB140}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="FALSE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"
+ CommandLine="if exist $(TargetPath) copy $(TargetPath) c:\bin_utils\$(TargetFileName)"
+ Outputs="c:\bin_utils\$(TargetFileName)"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/dumpobj.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/dumpobj.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="4"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="FALSE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"
+ CommandLine="if exist ..\..\..\..\game\bin\&quot;$(TargetName)&quot;.exe attrib -r ..\..\..\..\game\bin\&quot;$(TargetName)&quot;.exe
+if exist &quot;$(TargetPath)&quot; copy &quot;$(TargetPath)&quot; ..\..\..\..\game\bin
+"
+ Outputs="..\..\..\..\game\bin\$(TargetName).exe"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/dumpobj.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath=".\dumpobj.cpp">
+ <FileConfiguration
+ Name="Debug|Win32">
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"/>
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\toollib\scriplib.cpp">
+ </File>
+ <File
+ RelativePath="..\toollib\toollib.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ <File
+ RelativePath="..\toollib\scriplib.h">
+ </File>
+ <File
+ RelativePath="..\toollib\toollib.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>