Fix invalid pointer for 'VPK_Mount_f'

g_pFullFileSystem is a pointer to g_pFileSystem_Stdio in the compiled module.
Inherit CBaseFileSystem for CFileSystem_Stdio (second VFTable pointer).
Additional cleanup.
This commit is contained in:
Kawe Mazidjatari 2022-06-12 12:14:31 +02:00
parent e07f59adbe
commit 4cf43e0d61
4 changed files with 37 additions and 36 deletions

View File

@ -107,7 +107,7 @@ void CBaseFileSystem::Warning(CBaseFileSystem* pFileSystem, FileWarningLevel_t l
// *pszFilePath -
// Output : Handle to file on success, NULL on failure
//---------------------------------------------------------------------------------
FileHandle_t CBaseFileSystem::ReadFromVPK(CBaseFileSystem* pFileSystem, std::int64_t* pResults, char* pszFilePath)
FileHandle_t CBaseFileSystem::ReadFromVPK(CBaseFileSystem* pFileSystem, FileHandle_t pResults, char* pszFilePath)
{
std::string svFilePath = ConvertToWinPath(pszFilePath);
@ -122,8 +122,8 @@ FileHandle_t CBaseFileSystem::ReadFromVPK(CBaseFileSystem* pFileSystem, std::int
if (::FileExists(svFilePath.c_str()) /*|| ::FileExists(pszFilePath)*/)
{
*pResults = -1;
return (void*)pResults;
*reinterpret_cast<int64_t*>(pResults) = -1;
return pResults;
}
return CBaseFileSystem_LoadFromVPK(pFileSystem, pResults, pszFilePath);
}

View File

@ -1,5 +1,24 @@
#pragma once
#include "filesystem/filesystem.h"
typedef void* FileHandle_t;
enum class SearchPathAdd_t : int
{
PATH_ADD_TO_HEAD, // First path searched
PATH_ADD_TO_TAIL, // Last path searched
PATH_ADD_TO_TAIL_ATINDEX, // First path searched
};
enum class FileWarningLevel_t : int
{
FILESYSTEM_WARNING = -1, // A problem!
FILESYSTEM_WARNING_QUIET = 0, // Don't print anything
FILESYSTEM_WARNING_REPORTUNCLOSED, // On shutdown, report names of files left unclosed
FILESYSTEM_WARNING_REPORTUSAGE, // Report number of times a file was opened, closed
FILESYSTEM_WARNING_REPORTALLACCESSES, // Report all open/close events to console ( !slow! )
FILESYSTEM_WARNING_REPORTALLACCESSES_READ, // Report all open/close/read events to the console ( !slower! )
FILESYSTEM_WARNING_REPORTALLACCESSES_READWRITE, // Report all open/close/read/write events to the console ( !slower! )
FILESYSTEM_WARNING_REPORTALLACCESSES_ASYNC // Report all open/close/read/write events and all async I/O file events to the console ( !slower(est)! )
};
class CBaseFileSystem
{
@ -9,7 +28,7 @@ public:
void Close(FileHandle_t file);
bool FileExists(const char* pFileName, const char* pPathID);
static void Warning(CBaseFileSystem* pFileSystem, FileWarningLevel_t level, const char* fmt, ...);
static FileHandle_t ReadFromVPK(CBaseFileSystem* pVpk, std::int64_t* pResults, char* pszFilePath);
static FileHandle_t ReadFromVPK(CBaseFileSystem* pVpk, FileHandle_t pResults, char* pszFilePath);
static bool ReadFromCache(CBaseFileSystem* pFileSystem, char* pszFilePath, void* pResults);
static void AddSearchPath(CBaseFileSystem* pFileSystem, const char* pPath, const char* pPathID, SearchPathAdd_t addType);
static bool RemoveSearchPath(CBaseFileSystem* pFileSystem, const char* pPath, const char* pPathID);
@ -20,7 +39,7 @@ inline CMemory p_CBaseFileSystem_Warning;
inline auto CBaseFileSystem_Warning = p_CBaseFileSystem_Warning.RCast<void(*)(CBaseFileSystem* thisptr, FileWarningLevel_t level, const char* fmt, ...)>();
inline CMemory p_CBaseFileSystem_LoadFromVPK;
inline auto CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast<FileHandle_t(*)(CBaseFileSystem* thisptr, void* pResults, char* pszAssetName)>();
inline auto CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast<FileHandle_t(*)(CBaseFileSystem* thisptr, FileHandle_t pResults, char* pszAssetName)>();
inline CMemory p_CBaseFileSystem_LoadFromCache;
inline auto CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast<bool(*)(CBaseFileSystem* thisptr, char* pszAssetName, void* pResults)>();
@ -59,7 +78,7 @@ class VBaseFileSystem : public IDetour
p_CBaseFileSystem_RemoveSearchPath = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x55\x56\x57\x41\x54\x41\x56\x41\x57\x48\x81\xEC\x00\x00\x00\x00\xC6\x44\x24\x00\x00"), "xxxxxxxxxxxxxx????xxx??");
CBaseFileSystem_Warning = p_CBaseFileSystem_Warning.RCast<void(*)(CBaseFileSystem*, FileWarningLevel_t, const char*, ...)>(); /*4C 89 4C 24 20 C3 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 48*/
CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast<FileHandle_t(*)(CBaseFileSystem*, void*, char*)>(); /*48 89 5C 24 ?? 57 48 81 EC ?? ?? ?? ?? 49 8B C0 4C 8D 8C 24 ?? ?? ?? ??*/
CBaseFileSystem_LoadFromVPK = p_CBaseFileSystem_LoadFromVPK.RCast<FileHandle_t(*)(CBaseFileSystem*, FileHandle_t, char*)>(); /*48 89 5C 24 ?? 57 48 81 EC ?? ?? ?? ?? 49 8B C0 4C 8D 8C 24 ?? ?? ?? ??*/
CBaseFileSystem_LoadFromCache = p_CBaseFileSystem_LoadFromCache.RCast<bool(*)(CBaseFileSystem*, char*, void*)>(); /*40 53 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 49 8B D8*/
CBaseFileSystem_AddSearchPath = p_CBaseFileSystem_AddSearchPath.RCast<void(*)(CBaseFileSystem*, const char*, const char*, SearchPathAdd_t)>(); /*44 89 4C 24 ?? 48 89 4C 24 ?? 55 57*/
CBaseFileSystem_RemoveSearchPath = p_CBaseFileSystem_RemoveSearchPath.RCast<bool(*)(CBaseFileSystem*, const char*, const char*)>(); /*40 53 55 56 57 41 54 41 56 41 57 48 81 EC ?? ?? ?? ?? C6 44 24 ?? ??*/

View File

@ -1,43 +1,25 @@
#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#include "vpklib/packedstore.h"
#include "filesystem/basefilesystem.h"
#define GAMEINFOPATH_TOKEN "|gameinfo_path|"
#define BASESOURCEPATHS_TOKEN "|all_source_engine_paths|"
typedef void* FileHandle_t;
enum class SearchPathAdd_t : int
{
PATH_ADD_TO_HEAD, // First path searched
PATH_ADD_TO_TAIL, // Last path searched
PATH_ADD_TO_TAIL_ATINDEX, // First path searched
};
enum class FileWarningLevel_t : int
{
FILESYSTEM_WARNING = -1, // A problem!
FILESYSTEM_WARNING_QUIET = 0, // Don't print anything
FILESYSTEM_WARNING_REPORTUNCLOSED, // On shutdown, report names of files left unclosed
FILESYSTEM_WARNING_REPORTUSAGE, // Report number of times a file was opened, closed
FILESYSTEM_WARNING_REPORTALLACCESSES, // Report all open/close events to console ( !slow! )
FILESYSTEM_WARNING_REPORTALLACCESSES_READ, // Report all open/close/read events to the console ( !slower! )
FILESYSTEM_WARNING_REPORTALLACCESSES_READWRITE, // Report all open/close/read/write events to the console ( !slower! )
FILESYSTEM_WARNING_REPORTALLACCESSES_ASYNC // Report all open/close/read/write events and all async I/O file events to the console ( !slower(est)! )
};
class IFileSystem
{
public:
void AddSearchPath(const char* pPath, const char* pathID, SearchPathAdd_t addType);
void AddSearchPath(const char* pPath, const char* pPathID, SearchPathAdd_t addType);
bool RemoveSearchPath(const char* pPath, const char* pPathID);
bool ReadFromCache(const char* pPath, void* pResult);
VPKData_t* MountVPK(const char* vpkPath);
VPKData_t* MountVPK(const char* pVpkPath);
};
class CFileSystem_Stdio : public IFileSystem
class CFileSystem_Stdio : public IFileSystem, public CBaseFileSystem
{
};
extern IFileSystem* g_pFullFileSystem;
extern IFileSystem* g_pFullFileSystem; // Ptr to g_pFileSystem_Stdio.
extern CFileSystem_Stdio* g_pFileSystem_Stdio;
///////////////////////////////////////////////////////////////////////////////

View File

@ -687,12 +687,12 @@ void VPK_Mount_f(const CCommand& args)
return;
}
if (g_pFullFileSystem)
if (g_pFullFileSystem) // Initialized when g_pFileSystem_Stdio is initialized (global engine pointer).
{
VPKData_t* pPakData = g_pFullFileSystem->MountVPK(args.Arg(1));
VPKData_t* pPakData = g_pFileSystem_Stdio->MountVPK(args.Arg(1));
if (pPakData)
{
DevMsg(eDLL_T::FS, "Mounted VPK file '%s' with handle '%d'\n", args.Arg(1), pPakData->m_nHandle);
DevMsg(eDLL_T::FS, "Mounted VPK file '%s' with handle '%i'\n", args.Arg(1), pPakData->m_nHandle);
}
else
{
@ -701,7 +701,7 @@ void VPK_Mount_f(const CCommand& args)
}
else
{
Warning(eDLL_T::FS, "Unable to mount VPK file '%s': '%s' is not initalized\n", args.Arg(1), VAR_NAME(g_pFileSystem));
Warning(eDLL_T::FS, "Unable to mount VPK file '%s': '%s' is not initalized\n", args.Arg(1), VAR_NAME(g_pFullFileSystem));
}
}