From 61c994cddab49b62f3e9e2bdde86cf8efc6fcd71 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Mon, 24 Jan 2022 03:15:05 +0000 Subject: [PATCH] Add printtoconsole again but make it better --- src/Components/Modules/Bots.cpp | 14 +++++----- src/Components/Modules/Party.cpp | 2 +- src/Components/Modules/Script.cpp | 45 ++++++++++++++----------------- src/Components/Modules/Script.hpp | 2 -- src/Game/Functions.cpp | 2 +- src/Game/Structs.hpp | 2 +- 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index a3181a48..e9b2d3e8 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -130,7 +130,7 @@ namespace Components const auto* gentity = Script::GetEntFromEntRef(entref); auto* client = Script::GetClientFromEnt(gentity); - if (!client->isBot) + if (!client->bIsTestClient) { Game::Scr_Error("^1SetPing: Can only call on a bot!\n"); return; @@ -144,7 +144,7 @@ namespace Components const auto* gentity = Script::GetEntFromEntRef(entref); const auto* client = Script::GetClientFromEnt(gentity); - Game::Scr_AddBool(client->isBot == 1); + Game::Scr_AddBool(client->bIsTestClient == 1); }); Script::AddFunction("BotStop", [](Game::scr_entref_t entref) // Usage: BotStop(); @@ -152,7 +152,7 @@ namespace Components const auto* gentity = Script::GetEntFromEntRef(entref); const auto* client = Script::GetClientFromEnt(gentity); - if (!client->isBot) + if (!client->bIsTestClient) { Game::Scr_Error("^1BotStop: Can only call on a bot!\n"); return; @@ -169,7 +169,7 @@ namespace Components const auto* gentity = Script::GetEntFromEntRef(entref); const auto* client = Script::GetClientFromEnt(gentity); - if (!client->isBot) + if (!client->bIsTestClient) { Game::Scr_Error("^1BotWeapon: Can only call on a bot!\n"); return; @@ -198,7 +198,7 @@ namespace Components const auto* gentity = Script::GetEntFromEntRef(entref); const auto* client = Script::GetClientFromEnt(gentity); - if (!client->isBot) + if (!client->bIsTestClient) { Game::Scr_Error("^1BotAction: Can only call on a bot!\n"); return; @@ -234,7 +234,7 @@ namespace Components const auto* gentity = Script::GetEntFromEntRef(entref); const auto* client = Script::GetClientFromEnt(gentity); - if (!client->isBot) + if (!client->bIsTestClient) { Game::Scr_Error("^1BotMovement: Can only call on a bot!\n"); return; @@ -257,7 +257,7 @@ namespace Components if (client->state < Game::CS_CONNECTED) continue; - if (!client->isBot) + if (!client->bIsTestClient) continue; Game::usercmd_s ucmd = {0}; diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 4d7bc515..26eab431 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -315,7 +315,7 @@ namespace Components { if (Game::svs_clients[i].state >= 3) { - if (Game::svs_clients[i].isBot) ++botCount; + if (Game::svs_clients[i].bIsTestClient) ++botCount; else ++clientCount; } } diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index d00fbf73..b2cb91fc 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -10,7 +10,7 @@ namespace Components std::unordered_map Script::ScriptStorage; std::unordered_map Script::ScriptBaseProgramNum; std::unordered_map Script::ReplacedFunctions; - const char* Script::ReplacedPos = 0; + const char* Script::ReplacedPos = nullptr; int Script::LastFrameTime = -1; Utils::Signal Script::VMShutdownSignal; @@ -433,30 +433,6 @@ namespace Components return Game::Scr_GetNumParam(); } - // Allow printing to the console even when developer is 0 - void Script::PrintStub() - { - const auto g_no_script_spam = Dvar::Var("g_no_script_spam").get(); - - if (!g_no_script_spam) - return; - - const auto developer = Dvar::Var("developer").get(); - - for (auto i = 0u; i < Game::Scr_GetNumParam(); i++) - { - const auto str = (developer) ? Game::Scr_GetDebugString(i) : Game::Scr_GetString(i); - - if (str == nullptr) - { - Game::Scr_ParamError(i, "^1PrintConsole: Illegal parameters!\n"); - return; - } - - Logger::Print(*Game::level_scriptPrintChannel, "%s", str); - } - } - const char* Script::GetCodePosForParam(int index) { if (static_cast(index) >= Game::scrVmPub->outparamcount) @@ -620,6 +596,23 @@ namespace Components Command::Execute(str, false); }); + // Allow printing to the console even when developer is 0 + Script::AddFunction("PrintConsole", [](Game::scr_entref_t) // gsc: PrintConsole() + { + for (auto i = 0u; i < Game::Scr_GetNumParam(); i++) + { + const auto str = Game::Scr_GetString(i); + + if (str == nullptr) + { + Game::Scr_ParamError(i, "^1PrintConsole: Illegal parameters!\n"); + return; + } + + Logger::Print(*Game::level_scriptPrintChannel, "%s", str); + } + }); + // Script Storage Funcs Script::AddFunction("StorageSet", [](Game::scr_entref_t) // gsc: StorageSet(, ); { @@ -693,6 +686,8 @@ namespace Components Utils::Hook(0x61E3AD, Script::RuntimeError, HOOK_CALL).install()->quick(); Utils::Hook(0x621976, Script::RuntimeError, HOOK_CALL).install()->quick(); Utils::Hook(0x62246E, Script::RuntimeError, HOOK_CALL).install()->quick(); + // Nullsub GScr_CheckAllowedToSetPersistentData like it's done on IW5 to prevent spam + Utils::Hook::Set(0x5F8DA0, 0xC3); Utils::Hook(0x612E8D, Script::FunctionError, HOOK_CALL).install()->quick(); Utils::Hook(0x612EA2, Script::FunctionError, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Script.hpp b/src/Components/Modules/Script.hpp index 4c7b5f50..ce514a37 100644 --- a/src/Components/Modules/Script.hpp +++ b/src/Components/Modules/Script.hpp @@ -73,8 +73,6 @@ namespace Components static unsigned int SetExpFogStub(); - static void PrintStub(); - static const char* GetCodePosForParam(int index); static void GetReplacedPos(const char* pos); static void SetReplacedPos(const char* what, const char* with); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index dd50dd9e..abac4966 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -21,7 +21,7 @@ namespace Game return result; } - + AddRefToObject_t AddRefToObject = AddRefToObject_t(0x61C360); AllocObject_t AllocObject = AllocObject_t(0x434320); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 5baead0d..2aaee789 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -5503,7 +5503,7 @@ namespace Game int pureAuthentic; // 135896 char __pad7[133138]; // 135900 short scriptID; // 269038 - int isBot; // 269040 + int bIsTestClient; // 269040 int serverID; // 269044 char __pad8[9224]; // 269048 unsigned __int64 steamID; // 278272