From ae6d50dad8342dd47e5396a869a2d986f060f1ab Mon Sep 17 00:00:00 2001 From: Edo Date: Mon, 27 Mar 2023 12:51:00 +0100 Subject: [PATCH] [String]: Add IString func (#877) --- .../Modules/GSC/ScriptExtension.cpp | 4 ++-- src/Components/Modules/GSC/String.cpp | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/GSC/ScriptExtension.cpp b/src/Components/Modules/GSC/ScriptExtension.cpp index 635f1e82..2d8919ed 100644 --- a/src/Components/Modules/GSC/ScriptExtension.cpp +++ b/src/Components/Modules/GSC/ScriptExtension.cpp @@ -35,14 +35,14 @@ namespace Components::GSC void ScriptExtension::GScr_AddFieldsForEntityStub() { - for (const auto& [offset, field] : CustomEntityFields) + for (const auto& field : CustomEntityFields | std::views::values) { Game::Scr_AddClassField(Game::ClassNum::CLASS_NUM_ENTITY, field.name, field.ofs); } Utils::Hook::Call(0x4A7CF0)(); // GScr_AddFieldsForClient - for (const auto& [offset, field] : CustomClientFields) + for (const auto& field : CustomClientFields | std::views::values) { Game::Scr_AddClassField(Game::ClassNum::CLASS_NUM_ENTITY, field.name, field.ofs); } diff --git a/src/Components/Modules/GSC/String.cpp b/src/Components/Modules/GSC/String.cpp index bb497a69..b967f28a 100644 --- a/src/Components/Modules/GSC/String.cpp +++ b/src/Components/Modules/GSC/String.cpp @@ -5,6 +5,8 @@ namespace Components::GSC { + using namespace Utils::String; + void String::AddScriptFunctions() { Script::AddFunction("ToUpper", [] // gsc: ToUpper() @@ -122,7 +124,7 @@ namespace Components::GSC Game::Scr_AddFloat(static_cast(Game::Scr_GetInt(0))); break; default: - Game::Scr_ParamError(0, Utils::String::VA("cannot cast %s to float", Game::Scr_GetTypeName(0))); + Game::Scr_ParamError(0, VA("cannot cast %s to float", Game::Scr_GetTypeName(0))); break; } }); @@ -141,6 +143,22 @@ namespace Components::GSC Game::Scr_AddInt(result); }); + + Script::AddFunction("IString", [] // gsc: IString() + { + if (Game::Scr_GetType(0) != Game::VAR_STRING) + { + Game::Scr_ParamError(0, VA("cannot cast %s to istring", Game::Scr_GetTypeName(0))); + return; + } + + const auto value = Game::Scr_GetConstString(0); + + Game::SL_AddRefToString(value); + Game::Scr_AddIString(Game::Scr_GetString(0)); + + Game::SL_RemoveRefToString(value); + }); } String::String()