r5sdk/r5dev/filesystem/filesystem.h
Kawe Mazidjatari a618990937 Detour code refactor
This change was planned for a long time. This moves all REGISTER calls to a single translation unit, this is required as we currently added a very dirty workaround for not registering duplicates by checking if VFTable pointer was already present in the vector... Registering from single translation unit prevents duplicate instances that gets created if header is included by more cpp files.
Reworking this reduced 100kb+ of compiled code. This commit also reworked the way functions/variables/constant gets logged with their addresses; the new code formats them on the fly, and allows for resize at any time. Formatting is no longer required by programmer.

TODO: currently there are some compile errors for dedicated and client dll's. These will be resolved very soon as they need to be properly worked out still (server & client only stuff needs to be properly split). Use the 'main' (stable) branch for the time being if you need to compile these dll's.
2023-01-25 02:26:52 +01:00

60 lines
2.6 KiB
C++

#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#include "public/ifilesystem.h"
#include "public/ifile.h"
#include "filesystem/basefilesystem.h"
class CFileSystem_Stdio : public CBaseFileSystem
{
protected:
// implementation of CBaseFileSystem virtual functions
virtual FILE* FS_fopen(const char* filename, const char* options, unsigned flags, int64* size) = 0;
virtual void FS_setbufsize(FILE* fp, unsigned nBytes) = 0;
virtual void FS_fclose(FILE* fp) = 0;
virtual void FS_fseek(FILE* fp, int64 pos, int seekType) = 0;
virtual long FS_ftell(FILE* fp) = 0;
virtual int FS_feof(FILE* fp) = 0;
virtual size_t FS_fread(void* dest, size_t destSize, size_t size, FILE* fp) = 0;
virtual size_t FS_fwrite(const void* src, size_t size, FILE* fp) = 0;
virtual bool FS_setmode(FILE* fp, FileMode_t mode) = 0;
virtual size_t FS_vfprintf(FILE* fp, const char* fmt, va_list list) = 0;
virtual int FS_ferror(FILE* fp) = 0;
virtual int FS_fflush(FILE* fp) = 0;
virtual char* FS_fgets(char* dest, int destSize, FILE* fp) = 0;
virtual int FS_stat(const char* path, struct _stat* buf, bool* pbLoadedFromSteamCache = NULL) = 0;
virtual int FS_chmod(const char* path, int pmode) = 0;
virtual HANDLE FS_FindFirstFile(const char* findname, WIN32_FIND_DATA* dat) = 0;
virtual bool FS_FindNextFile(HANDLE handle, WIN32_FIND_DATA* dat) = 0;
virtual bool FS_FindClose(HANDLE handle) = 0;
virtual int FS_GetSectorSize(FILE*) = 0;
};
extern CFileSystem_Stdio** g_pFullFileSystem; // Ptr to g_pFileSystem_Stdio.
extern CFileSystem_Stdio* g_pFileSystem_Stdio;
CFileSystem_Stdio* FileSystem();
///////////////////////////////////////////////////////////////////////////////
class VFileSystem_Stdio : public IDetour
{
virtual void GetAdr(void) const
{
LogVarAdr("g_pFullFileSystem", reinterpret_cast<uintptr_t>(g_pFullFileSystem));
LogVarAdr("g_pFileSystem_Stdio", reinterpret_cast<uintptr_t>(g_pFileSystem_Stdio));
}
virtual void GetFun(void) const { }
virtual void GetVar(void) const
{
g_pFullFileSystem = g_GameDll.FindPatternSIMD("48 8B 0D ?? ?? ?? ?? 45 33 C0 48 83 C1 08 48 8B 01").ResolveRelativeAddressSelf(0x3, 0x7).RCast<CFileSystem_Stdio**>();
g_pFileSystem_Stdio = g_GameDll.FindPatternSIMD("48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? 48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? E9 ?? ?? ?? ??")
.FindPattern("48 89", CMemory::Direction::DOWN, 512, 1).ResolveRelativeAddressSelf(0x3, 0x7).RCast<CFileSystem_Stdio*>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }
};
///////////////////////////////////////////////////////////////////////////////
#endif // !FILESYSTEM_H