mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
151 lines
4.3 KiB
C++
151 lines
4.3 KiB
C++
|
//=============================================================================//
|
||
|
//
|
||
|
// Purpose: Standalone VPK tool
|
||
|
//
|
||
|
//=============================================================================//
|
||
|
#include "core/logdef.h"
|
||
|
#include "core/logger.h"
|
||
|
#include "tier0/fasttimer.h"
|
||
|
#include "tier1/cmd.h"
|
||
|
#include "tier1/keyvalues.h"
|
||
|
#include "windows/console.h"
|
||
|
#include "vpklib/packedstore.h"
|
||
|
|
||
|
#include "vstdlib/keyvaluessystem.h"
|
||
|
#include "filesystem/filesystem_std.h"
|
||
|
|
||
|
#define PACK_COMMAND "pack"
|
||
|
#define UNPACK_COMMAND "unpack"
|
||
|
|
||
|
static CKeyValuesSystem s_KeyValuesSystem;
|
||
|
static CFileSystem_Stdio g_FullFileSystem;
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// Purpose: filesystem singleton accessor
|
||
|
//-----------------------------------------------------------------------------
|
||
|
CFileSystem_Stdio* FileSystem()
|
||
|
{
|
||
|
return &g_FullFileSystem;
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// Purpose: init
|
||
|
//-----------------------------------------------------------------------------
|
||
|
static void ReVPK_Init()
|
||
|
{
|
||
|
// Assign global kv accessor to static singleton object as we aren't linked
|
||
|
// to the game!!!
|
||
|
g_pKeyValuesSystem = &s_KeyValuesSystem;
|
||
|
|
||
|
g_CoreMsgVCallback = EngineLoggerSink;
|
||
|
lzham_enable_fail_exceptions(true);
|
||
|
|
||
|
Console_Init(true);
|
||
|
SpdLog_Init(true);
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// Purpose: shutdown
|
||
|
//-----------------------------------------------------------------------------
|
||
|
static void ReVPK_Shutdown()
|
||
|
{
|
||
|
// Must be done to flush all buffers.
|
||
|
SpdLog_Shutdown();
|
||
|
Console_Shutdown();
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// Purpose: logs tool's usage
|
||
|
//-----------------------------------------------------------------------------
|
||
|
static void ReVPK_Usage()
|
||
|
{
|
||
|
Warning(eDLL_T::FS, "Usage:\n");
|
||
|
Warning(eDLL_T::FS, " revpk " PACK_COMMAND " <locale> <context> <levelName>\n");
|
||
|
Warning(eDLL_T::FS, " revpk " UNPACK_COMMAND " <fileName> <sanitize>\n");
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// Purpose: packs VPK files into 'SHIP' VPK directory
|
||
|
//-----------------------------------------------------------------------------
|
||
|
static void ReVPK_Pack(const CCommand& args)
|
||
|
{
|
||
|
if (args.ArgC() < 5)
|
||
|
{
|
||
|
ReVPK_Usage();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
VPKPair_t pair(args.Arg(2), args.Arg(3), args.Arg(4), NULL);
|
||
|
CFastTimer timer;
|
||
|
|
||
|
Msg(eDLL_T::FS, "*** Starting VPK build command for: '%s'\n", pair.m_DirName.Get());
|
||
|
timer.Start();
|
||
|
|
||
|
g_pPackedStore->InitLzCompParams();
|
||
|
g_pPackedStore->PackWorkspace(pair, "ship/", "vpk/");
|
||
|
|
||
|
timer.End();
|
||
|
Msg(eDLL_T::FS, "*** Time elapsed: '%lf' seconds\n", timer.GetDuration().GetSeconds());
|
||
|
Msg(eDLL_T::FS, "\n");
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// Purpose: unpacks VPK files into workspace directory
|
||
|
//-----------------------------------------------------------------------------
|
||
|
static void ReVPK_Unpack(const CCommand& args)
|
||
|
{
|
||
|
if (args.ArgC() < 3)
|
||
|
{
|
||
|
ReVPK_Usage();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
CUtlString arg = args.Arg(2);
|
||
|
|
||
|
VPKDir_t vpk(arg, (args.ArgC() > 3));
|
||
|
CFastTimer timer;
|
||
|
|
||
|
Msg(eDLL_T::FS, "*** Starting VPK extraction command for: '%s'\n", arg.Get());
|
||
|
timer.Start();
|
||
|
|
||
|
g_pPackedStore->InitLzDecompParams();
|
||
|
g_pPackedStore->UnpackWorkspace(vpk, "ship/");
|
||
|
|
||
|
timer.End();
|
||
|
Msg(eDLL_T::FS, "*** Time elapsed: '%lf' seconds\n", timer.GetDuration().GetSeconds());
|
||
|
Msg(eDLL_T::FS, "\n");
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// Purpose:
|
||
|
//-----------------------------------------------------------------------------
|
||
|
int main(int argc, char* argv[])
|
||
|
{
|
||
|
ReVPK_Init();
|
||
|
|
||
|
CCommand args;
|
||
|
CUtlString str;
|
||
|
|
||
|
for (int i = 0; i < argc; i++)
|
||
|
{
|
||
|
str.Append(argv[i]);
|
||
|
str.Append(' ');
|
||
|
}
|
||
|
|
||
|
args.Tokenize(str.Get(), cmd_source_t::kCommandSrcCode);
|
||
|
|
||
|
if (!args.ArgC())
|
||
|
ReVPK_Usage();
|
||
|
else
|
||
|
{
|
||
|
if (strcmp(args.Arg(1), PACK_COMMAND) == NULL)
|
||
|
ReVPK_Pack(args);
|
||
|
else if (strcmp(args.Arg(1), UNPACK_COMMAND) == NULL)
|
||
|
ReVPK_Unpack(args);
|
||
|
else
|
||
|
ReVPK_Usage();
|
||
|
}
|
||
|
|
||
|
ReVPK_Shutdown();
|
||
|
}
|