Add printtoconsole again but make it better

This commit is contained in:
FutureRave 2022-01-24 03:15:05 +00:00
parent 4c8198e687
commit 61c994cdda
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
6 changed files with 30 additions and 37 deletions

View File

@ -130,7 +130,7 @@ namespace Components
const auto* gentity = Script::GetEntFromEntRef(entref); const auto* gentity = Script::GetEntFromEntRef(entref);
auto* client = Script::GetClientFromEnt(gentity); auto* client = Script::GetClientFromEnt(gentity);
if (!client->isBot) if (!client->bIsTestClient)
{ {
Game::Scr_Error("^1SetPing: Can only call on a bot!\n"); Game::Scr_Error("^1SetPing: Can only call on a bot!\n");
return; return;
@ -144,7 +144,7 @@ namespace Components
const auto* gentity = Script::GetEntFromEntRef(entref); const auto* gentity = Script::GetEntFromEntRef(entref);
const auto* client = Script::GetClientFromEnt(gentity); 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: <bot> BotStop(); Script::AddFunction("BotStop", [](Game::scr_entref_t entref) // Usage: <bot> BotStop();
@ -152,7 +152,7 @@ namespace Components
const auto* gentity = Script::GetEntFromEntRef(entref); const auto* gentity = Script::GetEntFromEntRef(entref);
const auto* client = Script::GetClientFromEnt(gentity); const auto* client = Script::GetClientFromEnt(gentity);
if (!client->isBot) if (!client->bIsTestClient)
{ {
Game::Scr_Error("^1BotStop: Can only call on a bot!\n"); Game::Scr_Error("^1BotStop: Can only call on a bot!\n");
return; return;
@ -169,7 +169,7 @@ namespace Components
const auto* gentity = Script::GetEntFromEntRef(entref); const auto* gentity = Script::GetEntFromEntRef(entref);
const auto* client = Script::GetClientFromEnt(gentity); const auto* client = Script::GetClientFromEnt(gentity);
if (!client->isBot) if (!client->bIsTestClient)
{ {
Game::Scr_Error("^1BotWeapon: Can only call on a bot!\n"); Game::Scr_Error("^1BotWeapon: Can only call on a bot!\n");
return; return;
@ -198,7 +198,7 @@ namespace Components
const auto* gentity = Script::GetEntFromEntRef(entref); const auto* gentity = Script::GetEntFromEntRef(entref);
const auto* client = Script::GetClientFromEnt(gentity); const auto* client = Script::GetClientFromEnt(gentity);
if (!client->isBot) if (!client->bIsTestClient)
{ {
Game::Scr_Error("^1BotAction: Can only call on a bot!\n"); Game::Scr_Error("^1BotAction: Can only call on a bot!\n");
return; return;
@ -234,7 +234,7 @@ namespace Components
const auto* gentity = Script::GetEntFromEntRef(entref); const auto* gentity = Script::GetEntFromEntRef(entref);
const auto* client = Script::GetClientFromEnt(gentity); const auto* client = Script::GetClientFromEnt(gentity);
if (!client->isBot) if (!client->bIsTestClient)
{ {
Game::Scr_Error("^1BotMovement: Can only call on a bot!\n"); Game::Scr_Error("^1BotMovement: Can only call on a bot!\n");
return; return;
@ -257,7 +257,7 @@ namespace Components
if (client->state < Game::CS_CONNECTED) if (client->state < Game::CS_CONNECTED)
continue; continue;
if (!client->isBot) if (!client->bIsTestClient)
continue; continue;
Game::usercmd_s ucmd = {0}; Game::usercmd_s ucmd = {0};

View File

@ -315,7 +315,7 @@ namespace Components
{ {
if (Game::svs_clients[i].state >= 3) if (Game::svs_clients[i].state >= 3)
{ {
if (Game::svs_clients[i].isBot) ++botCount; if (Game::svs_clients[i].bIsTestClient) ++botCount;
else ++clientCount; else ++clientCount;
} }
} }

View File

@ -10,7 +10,7 @@ namespace Components
std::unordered_map<std::string, std::string> Script::ScriptStorage; std::unordered_map<std::string, std::string> Script::ScriptStorage;
std::unordered_map<int, std::string> Script::ScriptBaseProgramNum; std::unordered_map<int, std::string> Script::ScriptBaseProgramNum;
std::unordered_map<const char*, const char*> Script::ReplacedFunctions; std::unordered_map<const char*, const char*> Script::ReplacedFunctions;
const char* Script::ReplacedPos = 0; const char* Script::ReplacedPos = nullptr;
int Script::LastFrameTime = -1; int Script::LastFrameTime = -1;
Utils::Signal<Scheduler::Callback> Script::VMShutdownSignal; Utils::Signal<Scheduler::Callback> Script::VMShutdownSignal;
@ -433,30 +433,6 @@ namespace Components
return Game::Scr_GetNumParam(); 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<bool>();
if (!g_no_script_spam)
return;
const auto developer = Dvar::Var("developer").get<int>();
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) const char* Script::GetCodePosForParam(int index)
{ {
if (static_cast<unsigned int>(index) >= Game::scrVmPub->outparamcount) if (static_cast<unsigned int>(index) >= Game::scrVmPub->outparamcount)
@ -620,6 +596,23 @@ namespace Components
Command::Execute(str, false); Command::Execute(str, false);
}); });
// Allow printing to the console even when developer is 0
Script::AddFunction("PrintConsole", [](Game::scr_entref_t) // gsc: PrintConsole(<string>)
{
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 Storage Funcs
Script::AddFunction("StorageSet", [](Game::scr_entref_t) // gsc: StorageSet(<str key>, <str data>); Script::AddFunction("StorageSet", [](Game::scr_entref_t) // gsc: StorageSet(<str key>, <str data>);
{ {
@ -693,6 +686,8 @@ namespace Components
Utils::Hook(0x61E3AD, Script::RuntimeError, HOOK_CALL).install()->quick(); Utils::Hook(0x61E3AD, Script::RuntimeError, HOOK_CALL).install()->quick();
Utils::Hook(0x621976, Script::RuntimeError, HOOK_CALL).install()->quick(); Utils::Hook(0x621976, Script::RuntimeError, HOOK_CALL).install()->quick();
Utils::Hook(0x62246E, 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<BYTE>(0x5F8DA0, 0xC3);
Utils::Hook(0x612E8D, Script::FunctionError, HOOK_CALL).install()->quick(); Utils::Hook(0x612E8D, Script::FunctionError, HOOK_CALL).install()->quick();
Utils::Hook(0x612EA2, Script::FunctionError, HOOK_CALL).install()->quick(); Utils::Hook(0x612EA2, Script::FunctionError, HOOK_CALL).install()->quick();

View File

@ -73,8 +73,6 @@ namespace Components
static unsigned int SetExpFogStub(); static unsigned int SetExpFogStub();
static void PrintStub();
static const char* GetCodePosForParam(int index); static const char* GetCodePosForParam(int index);
static void GetReplacedPos(const char* pos); static void GetReplacedPos(const char* pos);
static void SetReplacedPos(const char* what, const char* with); static void SetReplacedPos(const char* what, const char* with);

View File

@ -21,7 +21,7 @@ namespace Game
return result; return result;
} }
AddRefToObject_t AddRefToObject = AddRefToObject_t(0x61C360); AddRefToObject_t AddRefToObject = AddRefToObject_t(0x61C360);
AllocObject_t AllocObject = AllocObject_t(0x434320); AllocObject_t AllocObject = AllocObject_t(0x434320);

View File

@ -5503,7 +5503,7 @@ namespace Game
int pureAuthentic; // 135896 int pureAuthentic; // 135896
char __pad7[133138]; // 135900 char __pad7[133138]; // 135900
short scriptID; // 269038 short scriptID; // 269038
int isBot; // 269040 int bIsTestClient; // 269040
int serverID; // 269044 int serverID; // 269044
char __pad8[9224]; // 269048 char __pad8[9224]; // 269048
unsigned __int64 steamID; // 278272 unsigned __int64 steamID; // 278272