Add nullgraphics rvar and fix EC printer

This commit is contained in:
LightCat 2019-03-19 21:26:45 +01:00
parent e78e1bc9a3
commit 597543c44c
7 changed files with 31 additions and 30 deletions

View File

@ -39,7 +39,6 @@ set(VACBypass 0 CACHE BOOL "Textmode VAC bypass")
set(Textmode 0 CACHE BOOL "Various textmode-only features for bots")
set(EnableTextmodeStdin 0 CACHE BOOL "Textmode Stdin -> Console bridge (EXPERIMENTAL)")
set(EnableWarnings 0 CACHE BOOL "Enable compile warnings")
set(EnableNullGraphics 0 CACHE BOOL "Enable experimental textmode hooks (CRASHES)")
set(EnableOnlineFeatures 0 CACHE BOOL "Enable online features (WIP)")
set(EnableIRC 1 CACHE BOOL "Enable IRC for messaging and ignore-cathook")

View File

@ -14,7 +14,6 @@
#define DATA_PATH "@DataPath@"
#define ENABLE_VAC_BYPASS @VACBypass@
#define ENABLE_TEXTMODE_STDIN @EnableTextmodeStdin@
#define ENABLE_NULL_GRAPHICS @EnableNullGraphics@
#define TEXTMODE @Textmode@
#define ENABLE_PROFILER @EnableProfiler@
#define ENABLE_ONLINE @EnableOnlineFeatures@

View File

@ -90,9 +90,7 @@ extern CGameRules *g_pGameRules;
extern IEngineVGui *g_IEngineVGui;
extern IUniformRandomStream *g_pUniformStream;
extern int *g_PredictionRandomSeed;
#if ENABLE_NULL_GRAPHICS
extern IFileSystem *g_IFileSystem;
extern IMDLCache *g_IMDLCache;
#endif
void CreateInterfaces();

View File

@ -82,7 +82,6 @@ DECLARE_HOOKED_METHOD(RandomInt, int, IUniformRandomStream *, int, int);
// wontfix.club
#if 0
#if ENABLE_NULL_GRAPHICS
typedef ITexture *(*FindTexture_t)(void *, const char *, const char *, bool,
int);
typedef IMaterial *(*FindMaterialEx_t)(void *, const char *, const char *, int,
@ -108,6 +107,5 @@ typedef IMaterial *(*FindMaterial_t)(void *, const char *, const char *, bool,
const char *pTextureGroupName,
int nContext, bool complain,
const char *pComplainPrefix);
#endif
#endif

View File

@ -52,10 +52,8 @@ CGameRules *g_pGameRules = nullptr;
IEngineVGui *g_IEngineVGui = nullptr;
IUniformRandomStream *g_pUniformStream = nullptr;
int *g_PredictionRandomSeed = nullptr;
#if ENABLE_NULL_GRAPHICS
IFileSystem *g_IFileSystem = nullptr;
IMDLCache *g_IMDLCache = nullptr;
#endif
template <typename T> T *BruteforceInterface(std::string name, sharedobj::SharedObject &object, int start = 0)
{
@ -132,7 +130,7 @@ void CreateInterfaces()
// FIXME SIGNATURE
g_ISteamFriends = g_ISteamClient->GetISteamFriends(su, sp, "SteamFriends002");
}
rg_GlobalVars = *reinterpret_cast<CGlobalVarsBase ***>(gSignatures.GetClientSignature("8B 15 ? ? ? ? F3 0F 10 88 D0 08 00 00") + 2);
rg_GlobalVars = *reinterpret_cast<CGlobalVarsBase ***>(gSignatures.GetClientSignature("8B 15 ? ? ? ? F3 0F 10 88 D0 08 00 00") + 2);
g_IPrediction = BruteforceInterface<IPrediction>("VClientPrediction", sharedobj::client());
g_IGameMovement = BruteforceInterface<IGameMovement>("GameMovement", sharedobj::client());
IF_GAME(IsTF2())
@ -158,10 +156,8 @@ void CreateInterfaces()
g_pGameRules = *reinterpret_cast<CGameRules **>(g_pGameRules_sig + 8);
}
g_IMaterialSystem = BruteforceInterface<IMaterialSystemFixed>("VMaterialSystem", sharedobj::materialsystem());
#if ENABLE_NULL_GRAPHICS
g_IFileSystem = BruteforceInterface<IFileSystem>("VFileSystem", sharedobj::filesystem_stdio());
g_IMDLCache = BruteforceInterface<IMDLCache>("MDLCache", sharedobj::datacache());
#endif
g_IFileSystem = BruteforceInterface<IFileSystem>("VFileSystem", sharedobj::filesystem_stdio());
g_IMDLCache = BruteforceInterface<IMDLCache>("MDLCache", sharedobj::datacache());
#if ENABLE_VISUALS
g_pUniformStream = **(IUniformRandomStream ***) (gSignatures.GetVstdSignature("A3 ? ? ? ? C3 89 F6") + 0x1);

View File

@ -143,14 +143,10 @@ void critical_error_handler(int signum)
::raise(SIGABRT);
}
#if ENABLE_NULL_GRAPHICS
static bool blacklist_file(const char *filename)
{
const static char *blacklist[] = { ".vtx", ".vtf", ".pcf", ".mdl" };
if (!filename || !std::strcmp(filename, "models/error.mdl") ||
!std::strcmp(filename, "models/vgui/competitive_badge.mdl") ||
!std::strcmp(filename, "models/vgui/12v12_badge.mdl") ||
!std::strncmp(filename, "models/player/", 14))
if (!filename || !std::strcmp(filename, "models/error.mdl") || !std::strcmp(filename, "models/vgui/competitive_badge.mdl") || !std::strcmp(filename, "models/vgui/12v12_badge.mdl") || !std::strncmp(filename, "models/player/", 14))
return false;
std::size_t len = std::strlen(filename);
@ -164,33 +160,33 @@ static bool blacklist_file(const char *filename)
return false;
}
static bool (*FSorig_ReadFile)(void*, const char *, const char *, void *, int, int, void *);
static bool FSHook_ReadFile(void *this_, const char *pFileName, const char *pPath,
void *buf, int nMaxBytes, int nStartingByte, void *pfnAlloc)
static bool (*FSorig_ReadFile)(void *, const char *, const char *, void *, int, int, void *);
static bool FSHook_ReadFile(void *this_, const char *pFileName, const char *pPath, void *buf, int nMaxBytes, int nStartingByte, void *pfnAlloc)
{
//fprintf(stderr, "ReadFile: %s\n", pFileName);
// fprintf(stderr, "ReadFile: %s\n", pFileName);
if (blacklist_file(pFileName))
return false;
return FSorig_ReadFile(this_, pFileName, pPath, buf, nMaxBytes, nStartingByte, pfnAlloc);
}
#endif
static hooks::VMTHook /*fs_hook,*/ fs_hook2;
static void ReduceRamUsage()
{
#if ENABLE_NULL_GRAPHICS
static hooks::VMTHook /*fs_hook,*/ fs_hook2;
fs_hook2.Set(reinterpret_cast<void *>(g_IFileSystem), 4);
fs_hook2.HookMethod(FSHook_ReadFile, 14, &FSorig_ReadFile);
fs_hook2.Apply();
/* ERROR: Must be called from texture thread */
//g_IMaterialSystem->ReloadTextures();
// g_IMaterialSystem->ReloadTextures();
g_IBaseClient->InvalidateMdlCache();
#endif
}
static void UnHookFs()
{
fs_hook2.Release();
g_IBaseClient->InvalidateMdlCache();
}
static settings::Bool null_graphics("hack.nullgraphics", "false");
static void InitRandom()
{
int rand_seed;
@ -246,8 +242,13 @@ free(logname);*/
InitRandom();
sharedobj::LoadAllSharedObjects();
CreateInterfaces();
ReduceRamUsage();
CDumper dumper;
null_graphics.installChangeCallback([](settings::VariableBase<bool> &, bool after) {
if (after)
ReduceRamUsage();
else
UnHookFs();
});
dumper.SaveDump();
logging::Info("Is TF2? %d", IsTF2());
logging::Info("Is TF2C? %d", IsTF2C());

View File

@ -17,6 +17,16 @@ struct EventCallbackData
};
static std::vector<EventCallbackData> events[ec_types::EcTypesSize];
CatCommand evt_print("debug_print_events", "Print EC events", []() {
for (int i = 0; i < int(ec_types::EcTypesSize); ++i)
{
logging::Info("%d events:", i);
for (auto it = events[i].begin(); it != events[i].end(); ++it)
logging::Info("%s", it->event_name.c_str());
logging::Info("");
}
});
void Register(enum ec_types type, const EventFunction &function, const std::string &name, enum ec_priority priority)
{