summaryrefslogtreecommitdiff
path: root/utils/dmxconvert
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/dmxconvert
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'utils/dmxconvert')
-rw-r--r--utils/dmxconvert/dmxconvert.cpp181
-rw-r--r--utils/dmxconvert/dmxconvert.vpc27
2 files changed, 208 insertions, 0 deletions
diff --git a/utils/dmxconvert/dmxconvert.cpp b/utils/dmxconvert/dmxconvert.cpp
new file mode 100644
index 0000000..12691d3
--- /dev/null
+++ b/utils/dmxconvert/dmxconvert.cpp
@@ -0,0 +1,181 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// The copyright to the contents herein is the property of Valve, L.L.C.
+// The contents may be used and/or copied only with the written permission of
+// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
+// the agreement/contract under which the contents have been supplied.
+//
+// $Header: $
+// $NoKeywords: $
+//
+// Converts from any one DMX file format to another
+// Can also output SMD or a QCI header from DMX input
+//
+//=============================================================================
+
+#include "tier0/dbg.h"
+#include "tier0/icommandline.h"
+#include "datamodel/idatamodel.h"
+#include "filesystem.h"
+#include "appframework/appframework.h"
+#include "tier1/utlbuffer.h"
+#include "dmserializers/idmserializers.h"
+#include "tier1/utlstring.h"
+#include "datamodel/dmattribute.h"
+#include "datamodel/dmelement.h"
+#include "tier2/tier2.h"
+
+
+class CDmElement;
+
+
+//-----------------------------------------------------------------------------
+// Standard spew functions
+//-----------------------------------------------------------------------------
+static SpewRetval_t DMXConvertOutputFunc( SpewType_t spewType, char const *pMsg )
+{
+ printf( pMsg );
+ fflush( stdout );
+
+ if (spewType == SPEW_ERROR)
+ return SPEW_ABORT;
+ return (spewType == SPEW_ASSERT) ? SPEW_DEBUGGER : SPEW_CONTINUE;
+}
+
+
+//-----------------------------------------------------------------------------
+// The application object
+//-----------------------------------------------------------------------------
+class CDmxConvertApp : public CDefaultAppSystemGroup<CSteamAppSystemGroup>
+{
+public:
+ // Methods of IApplication
+ virtual bool Create();
+ virtual bool PreInit( );
+ virtual int Main();
+ virtual void PostShutdown();
+};
+
+DEFINE_CONSOLE_STEAM_APPLICATION_OBJECT( CDmxConvertApp );
+
+
+//-----------------------------------------------------------------------------
+// The application object
+//-----------------------------------------------------------------------------
+bool CDmxConvertApp::Create()
+{
+ SpewOutputFunc( DMXConvertOutputFunc );
+ AddSystem( g_pDataModel, VDATAMODEL_INTERFACE_VERSION );
+ AddSystem( g_pDmSerializers, DMSERIALIZERS_INTERFACE_VERSION );
+ return true;
+}
+
+bool CDmxConvertApp::PreInit( )
+{
+ CreateInterfaceFn factory = GetFactory();
+ ConnectTier1Libraries( &factory, 1 );
+ ConnectTier2Libraries( &factory, 1 );
+
+ if ( !g_pFullFileSystem || !g_pDataModel )
+ {
+ Warning( "DMXConvert is missing a required interface!\n" );
+ return false;
+ }
+ return true;
+}
+
+
+void CDmxConvertApp::PostShutdown()
+{
+ DisconnectTier2Libraries();
+ DisconnectTier1Libraries();
+}
+
+
+//-----------------------------------------------------------------------------
+// The application object
+//-----------------------------------------------------------------------------
+int CDmxConvertApp::Main()
+{
+ g_pDataModel->OnlyCreateUntypedElements( true );
+ g_pDataModel->SetDefaultElementFactory( NULL );
+
+ // This bit of hackery allows us to access files on the harddrive
+ g_pFullFileSystem->AddSearchPath( "", "LOCAL", PATH_ADD_TO_HEAD );
+
+ const char *pInFileName = CommandLine()->ParmValue("-i" );
+ const char *pOutFileName = CommandLine()->ParmValue("-o" );
+ const char *pInFormat = CommandLine()->ParmValue("-if" );
+ const char *pOutFormat = CommandLine()->ParmValue("-of" );
+ const char *pOutEncoding = CommandLine()->ParmValue("-oe" );
+
+ if ( !pInFileName )
+ {
+ Msg( "Usage: dmxconvert -i <in file> [-if <in format_hint>] [-o <out file>] [-oe <out encoding>] [-of <out format>]\n" );
+ Msg( "If no output file is specified, dmx to dmx conversion will overwrite the input\n" );
+ Msg( "Supported DMX file encodings:\n" );
+ for ( int i = 0; i < g_pDataModel->GetEncodingCount(); ++i )
+ {
+ Msg( " %s\n", g_pDataModel->GetEncodingName( i ) );
+ }
+
+ Msg( "Supported DMX file formats:\n" );
+ for ( int i = 0; i < g_pDataModel->GetFormatCount(); ++i )
+ {
+ Msg( " %s\n", g_pDataModel->GetFormatName( i ) );
+ }
+
+ return -1;
+ }
+
+ // When reading, keep the CRLF; this will make ReadFile read it in binary format
+ // and also append a couple 0s to the end of the buffer.
+ DmxHeader_t header;
+ CDmElement *pRoot;
+ if ( g_pDataModel->RestoreFromFile( pInFileName, NULL, pInFormat, &pRoot, CR_DELETE_NEW, &header ) == DMFILEID_INVALID )
+ {
+ Error( "Encountered an error reading file \"%s\"!\n", pInFileName );
+ return -1;
+ }
+
+ if ( !pOutFormat )
+ {
+ pOutFormat = header.formatName;
+ if ( !g_pDataModel->FindFormatUpdater( pOutFormat ) )
+ {
+ pOutFormat = "dmx"; // default to generic dmx format for legacy files
+ }
+ }
+
+ if ( !pOutEncoding )
+ {
+ pOutEncoding = g_pDataModel->GetDefaultEncoding( pOutFormat );
+ if ( !pOutEncoding )
+ {
+ // no default encoding was found, try to convert the file to the generic dmx format
+ pOutFormat = GENERIC_DMX_FORMAT;
+ pOutEncoding = g_pDataModel->GetDefaultEncoding( pOutFormat );
+ }
+ }
+
+ if ( !pOutFileName )
+ {
+ pOutFileName = pInFileName;
+ }
+
+ // TODO - in theory, at some point, we may have converters from pInFormat to pOutFormat
+ // until then, treat it as a noop, and hope for the best
+
+ if ( !g_pDataModel->SaveToFile( pOutFileName, NULL, pOutEncoding, pOutFormat, pRoot ) )
+ {
+ Error( "Encountered an error writing file \"%s\"!\n", pOutFileName );
+ return -1;
+ }
+
+ g_pDataModel->RemoveFileId( pRoot->GetFileId() );
+
+ return 0;
+}
+
+
+
diff --git a/utils/dmxconvert/dmxconvert.vpc b/utils/dmxconvert/dmxconvert.vpc
new file mode 100644
index 0000000..dfb6f21
--- /dev/null
+++ b/utils/dmxconvert/dmxconvert.vpc
@@ -0,0 +1,27 @@
+//-----------------------------------------------------------------------------
+// DMXCONVERT.VPC
+//
+// Project Script
+//-----------------------------------------------------------------------------
+
+$Macro SRCDIR "..\.."
+$Macro OUTBINDIR "$SRCDIR\..\game\bin"
+
+$Include "$SRCDIR\vpc_scripts\source_exe_con_base.vpc"
+
+$Project "Dmxconvert"
+{
+ $Folder "Source Files"
+ {
+ $File "dmxconvert.cpp"
+ }
+
+ $Folder "Link Libraries"
+ {
+ $Lib appframework
+ $Lib datamodel
+ $Lib dmserializers
+ $Lib mathlib
+ $Lib tier2
+ }
+}