mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Add 'KeyValues::RecursiveSaveToFile' to the SDK
Relies on the engine's implementation of 'KeyValues::RecursiveSaveToFile'. The IFileSystem methods have been fixed up with the CUtlBuffer class rebuild in which we could call these to write a KV memory structure as a file to the disk.
This commit is contained in:
parent
843cc6f4ca
commit
a82674bbc8
@ -13,6 +13,7 @@
|
||||
#include "engine/cmodel_bsp.h"
|
||||
#include "rtech/rtech_utils.h"
|
||||
#include "rtech/rtech_game.h"
|
||||
#include "vpc/keyvalues.h"
|
||||
#include "datacache/mdlcache.h"
|
||||
#include "filesystem/filesystem.h"
|
||||
|
||||
|
@ -4,20 +4,24 @@
|
||||
#include <tier0/annotations.h>
|
||||
#include <tier0/threadtools.h>
|
||||
#include <appframework/iappsystem.h>
|
||||
#include <vpc/keyvalues.h>
|
||||
#include <vpc/interfaces.h>
|
||||
#include <vpklib/packedstore.h>
|
||||
#include <public/ipackedstore.h>
|
||||
|
||||
typedef void* FileHandle_t;
|
||||
typedef void* FileNameHandle_t; // !TODO: Check if this is 4 or 8 bytes (model_t was 4 bytes in mem).
|
||||
typedef void* FileCacheHandle_t;
|
||||
typedef int FileFindHandle_t;
|
||||
|
||||
#define FILESYSTEM_INVALID_HANDLE ( FileHandle_t )0
|
||||
#define FILESYSTEM_INVALID_HANDLE ( FileHandle_t )nullptr
|
||||
|
||||
#define GAMEINFOPATH_TOKEN "|gameinfo_path|"
|
||||
#define BASESOURCEPATHS_TOKEN "|all_source_engine_paths|"
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// Purpose: Forward declarations
|
||||
//---------------------------------------------------------------------------------
|
||||
class KeyValues;
|
||||
class CUtlBuffer;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures used by the interface
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -163,8 +167,8 @@ public:
|
||||
//--------------------------------------------------------
|
||||
// Reads/writes files to utlbuffers. Use this for optimal read performance when doing open/read/close.
|
||||
//--------------------------------------------------------
|
||||
virtual bool ReadFile(const char* pFileName, const char* pPath, void* buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) = 0; // !FIXME [AMOS]: buf = CUtlBuffer&!
|
||||
virtual bool WriteFile(const char* pFileName, const char* pPath, void* buf) = 0; // !FIXME [AMOS]: buf = CUtlBuffer&!
|
||||
virtual bool ReadFile(const char* pFileName, const char* pPath, CUtlBuffer& buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) = 0;
|
||||
virtual bool WriteFile(const char* pFileName, const char* pPath, CUtlBuffer& buf) = 0;
|
||||
virtual bool UnzipFile(const char* pFileName, const char* pPath, const char* pDestination) = 0;
|
||||
};
|
||||
|
||||
@ -372,7 +376,7 @@ public:
|
||||
|
||||
//--------------------------------------------------------
|
||||
//--------------------------------------------------------
|
||||
virtual bool ReadToBuffer(FileHandle_t hFile, void* buf, int nMaxBytes = 0, FSAllocFunc_t pfnAlloc = NULL) = 0; // !TODO: buf = 'CUtlBuffer&'
|
||||
virtual bool ReadToBuffer(FileHandle_t hFile, CUtlBuffer& buf, int nMaxBytes = 0, FSAllocFunc_t pfnAlloc = NULL) = 0;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Optimal IO operations
|
||||
|
@ -1116,6 +1116,25 @@ void KeyValues::RecursiveCopyKeyValues(KeyValues& src)
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
// Input : &buf -
|
||||
// nIndentLevel -
|
||||
//-----------------------------------------------------------------------------
|
||||
void KeyValues::RecursiveSaveToFile(CUtlBuffer& buf, int nIndentLevel)
|
||||
{
|
||||
RecursiveSaveToFile(NULL, FILESYSTEM_INVALID_HANDLE, &buf, nIndentLevel);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Save keyvalues from disk, if subkey values are detected, calls
|
||||
// itself to save those
|
||||
//-----------------------------------------------------------------------------
|
||||
void KeyValues::RecursiveSaveToFile(IBaseFileSystem* pFileSystem, FileHandle_t pHandle, CUtlBuffer* pBuf, int nIndentLevel)
|
||||
{
|
||||
KeyValues_RecursiveSaveToFile(this, pFileSystem, pHandle, pBuf, nIndentLevel);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Make a new copy of all subkeys, add them all to the passed-in keyvalues
|
||||
// Input : *pParent -
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include "mathlib/color.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "public/ifilesystem.h"
|
||||
|
||||
#define MAKE_3_BYTES_FROM_1_AND_2( x1, x2 ) (( (( uint16_t )x2) << 8 ) | (uint8_t)(x1))
|
||||
#define SPLIT_3_BYTES_INTO_1_AND_2( x1, x2, x3 ) do { x1 = (uint8)(x3); x2 = (uint16)( (x3) >> 8 ); } while( 0 )
|
||||
@ -15,6 +17,7 @@ inline std::mutex g_PlaylistsVecMutex;
|
||||
//---------------------------------------------------------------------------------
|
||||
class KeyValues;
|
||||
class CFileSystem_Stdio;
|
||||
class IBaseFileSystem;
|
||||
|
||||
/* ==== KEYVALUES ======================================================================================================================================================= */
|
||||
inline CMemory p_KeyValues_FindKey;
|
||||
@ -32,6 +35,9 @@ inline auto KeyValues_GetCurrentPlaylist = p_KeyValues_GetCurrentPlaylist.RCast<
|
||||
inline CMemory p_KeyValues_ReadKeyValuesFile;
|
||||
inline auto KeyValues_ReadKeyValuesFile = p_KeyValues_ReadKeyValuesFile.RCast<KeyValues* (*)(CFileSystem_Stdio* pFileSystem, const char* pFileName)>();
|
||||
|
||||
inline CMemory p_KeyValues_RecursiveSaveToFile;
|
||||
inline auto KeyValues_RecursiveSaveToFile = p_KeyValues_RecursiveSaveToFile.RCast<void (*)(KeyValues* thisptr, IBaseFileSystem* pFileSystem, FileHandle_t pHandle, CUtlBuffer* pBuf, int nIndentLevel)>();
|
||||
|
||||
enum KeyValuesTypes_t : char
|
||||
{
|
||||
TYPE_NONE = 0x0,
|
||||
@ -134,8 +140,12 @@ public:
|
||||
void SetStringValue(char const* pszValue);
|
||||
void SetColor(const char* pszKeyName, Color color);
|
||||
void SetFloat(const char* pszKeyName, float flValue);
|
||||
void SetBool(const char* pszKeyName, bool bValue) { SetInt(pszKeyName, bValue ? 1 : 0); }
|
||||
|
||||
void RecursiveCopyKeyValues(KeyValues& src);
|
||||
void RecursiveSaveToFile(CUtlBuffer& buf, int nIndentLevel);
|
||||
void RecursiveSaveToFile(IBaseFileSystem* pFileSystem, FileHandle_t pHandle, CUtlBuffer* pBuf, int nIndentLevel);
|
||||
|
||||
void CopySubkeys(KeyValues* pParent) const;
|
||||
KeyValues* MakeCopy(void) const;
|
||||
|
||||
@ -184,6 +194,7 @@ class VKeyValues : public IDetour
|
||||
spdlog::debug("| FUN: KeyValues::ParsePlaylists : {:#18x} |\n", p_KeyValues_ParsePlaylists.GetPtr());
|
||||
spdlog::debug("| FUN: KeyValues::GetCurrentPlaylist : {:#18x} |\n", p_KeyValues_GetCurrentPlaylist.GetPtr());
|
||||
spdlog::debug("| FUN: KeyValues::ReadKeyValuesFile : {:#18x} |\n", p_KeyValues_ReadKeyValuesFile.GetPtr());
|
||||
spdlog::debug("| FUN: KeyValues::RecursiveSaveToFile : {:#18x} |\n", p_KeyValues_RecursiveSaveToFile.GetPtr());
|
||||
spdlog::debug("| VAR: g_pPlaylistKeyValues : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pPlaylistKeyValues));
|
||||
spdlog::debug("+----------------------------------------------------------------+\n");
|
||||
}
|
||||
@ -200,12 +211,14 @@ class VKeyValues : public IDetour
|
||||
#endif
|
||||
p_KeyValues_LoadPlaylists = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x56\x57\x41\x56\x48\x83\xEC\x40\x48\x8B\xF1"), "xxxx?xxxx?xxxxxxxxxxx");
|
||||
p_KeyValues_ParsePlaylists = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\xE8\x00\x00\x00\x00\x80\x3D\x00\x00\x00\x00\x00\x74\x0C"), "x????xx?????xx").FollowNearCallSelf();
|
||||
p_KeyValues_RecursiveSaveToFile = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x8B\xC4\x53\x00\x57\x41\x55\x41\x00\x48\x83"), "xxxx?xxxx?xx");
|
||||
|
||||
KeyValues_FindKey = p_KeyValues_FindKey.RCast<void* (*)(KeyValues*, const char*, bool)>(); /*40 56 57 41 57 48 81 EC 30 01 00 00 45 0F B6 F8*/
|
||||
KeyValues_LoadPlaylists = p_KeyValues_ParsePlaylists.RCast<bool (*)(const char*)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 56 57 41 56 48 83 EC 40 48 8B F1*/
|
||||
KeyValues_ParsePlaylists = p_KeyValues_ParsePlaylists.RCast<bool (*)(const char*)>(); /*E8 ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 74 0C*/
|
||||
KeyValues_GetCurrentPlaylist = p_KeyValues_GetCurrentPlaylist.RCast<const char* (*)(void)>(); /*48 8B 05 ?? ?? ?? ?? 48 85 C0 75 08 48 8D 05 ?? ?? ?? ?? C3 0F B7 50 2A*/
|
||||
KeyValues_ReadKeyValuesFile = p_KeyValues_ReadKeyValuesFile.RCast<KeyValues* (*)(CFileSystem_Stdio*, const char*)>(); /*48 8B C4 55 53 57 41 54 48 8D 68 A1*/
|
||||
KeyValues_RecursiveSaveToFile = p_KeyValues_RecursiveSaveToFile.RCast<void (*)(KeyValues*, IBaseFileSystem*, FileHandle_t, CUtlBuffer*, int)>(); /*48 8B C4 53 ?? 57 41 55 41 ?? 48 83*/
|
||||
}
|
||||
virtual void GetVar(void) const
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user