From 8e0f8e82a4589c8f809c2fabc749beaedee662f0 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 5 Jul 2021 23:39:25 +0200 Subject: [PATCH] Add updatetext method --- src/game/scripting/execution.cpp | 8 +++++ src/game/scripting/execution.hpp | 2 ++ src/game/scripting/lua/context.cpp | 21 ++++++++++++ src/game/structs.hpp | 54 ++++++++++++++++++++++++++++++ src/game/symbols.hpp | 6 +++- 5 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/game/scripting/execution.cpp b/src/game/scripting/execution.cpp index 25bd307..ea74dab 100644 --- a/src/game/scripting/execution.cpp +++ b/src/game/scripting/execution.cpp @@ -298,4 +298,12 @@ namespace scripting return {}; } + + void check_thread() + { + if (std::this_thread::get_id() == scheduler::async_thread_id) + { + throw std::runtime_error("Not in server thread"); + } + } } \ No newline at end of file diff --git a/src/game/scripting/execution.hpp b/src/game/scripting/execution.hpp index ce35a94..1f8dc2d 100644 --- a/src/game/scripting/execution.hpp +++ b/src/game/scripting/execution.hpp @@ -35,4 +35,6 @@ namespace scripting script_value get_entity_field(const entity& entity, const std::string& field); void notify(const entity& entity, const std::string& event, const std::vector& arguments); + + void check_thread(); } diff --git a/src/game/scripting/lua/context.cpp b/src/game/scripting/lua/context.cpp index fa207ff..0bbd1a7 100644 --- a/src/game/scripting/lua/context.cpp +++ b/src/game/scripting/lua/context.cpp @@ -303,6 +303,27 @@ namespace scripting::lua } ); + entity_type["updatetext"] = [](const entity& entity, const sol::this_state s, + const std::string& text) + { + check_thread(); + + const auto entref = entity.get_entity_reference(); + if (entref.classnum != 1) + { + return; + } + + auto elem = &game::g_hudelems[entref.entnum].elem; + if (!elem->text) + { + entity.call("settext", {text}); + return; + } + + game::SV_SetConfigstring(elem->text + 469, text.data()); + }; + struct game { }; diff --git a/src/game/structs.hpp b/src/game/structs.hpp index ed8c43f..7fceadd 100644 --- a/src/game/structs.hpp +++ b/src/game/structs.hpp @@ -303,6 +303,60 @@ namespace game dvar_t* hashNext; }; + struct hudelem_s + { + int type; + float x; + float y; + float z; + int targetEntNum; + float fontScale; + float fromFontScale; + int fontScaleStartTime; + int fontScaleTime; + int font; + int alignOrg; + int alignScreen; + int color; + int fromColor; + int fadeStartTime; + int fadeTime; + int label; + int width; + int height; + int materialIndex; + int fromWidth; + int fromHeight; + int scaleStartTime; + int scaleTime; + float fromX; + float fromY; + int fromAlignOrg; + int fromAlignScreen; + int moveStartTime; + int moveTime; + int time; + int duration; + float value; + int text; + float sort; + int glowColor; + int fxBirthTime; + int fxLetterTime; + int fxDecayStartTime; + int fxDecayDuration; + int soundID; + int flags; + }; + + struct game_hudelem_s + { + hudelem_s elem; + int clientNum; + int team; + int archived; + }; + struct gclient_s { char __pad0[0x35CC]; diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index 08576d8..f10cea7 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -24,6 +24,8 @@ namespace game WEAK symbol I_CleanStr{0x0}; + WEAK symbol G_LocalizedStringIndex{0x52D900}; + WEAK symbol GetEntityFieldValue{0x56AF20}; WEAK symbol FindVariable{0x5651F0}; WEAK symbol FindObject{0x565BD0}; @@ -44,6 +46,7 @@ namespace game WEAK symbol SV_GameSendServerCommand{0x573220}; WEAK symbol SV_Cmd_ArgvBuffer{0x5459F0}; + WEAK symbol SV_SetConfigstring{0x574BD0}; WEAK symbol VM_Notify{0x569720}; WEAK symbol VM_Execute{0x56DFE0}; @@ -60,12 +63,13 @@ namespace game WEAK symbol scr_VmPub{0x20B4A80}; WEAK symbol scr_VarGlob{0x1E72180}; - WEAK symbol scr_function_stack{0x20B4A5C}; + WEAK symbol scr_function_stack{0x20B4A5C}; WEAK symbol g_classMap{0x8B4300}; WEAK symbol g_entities{0x1A66E28}; WEAK symbol svs_clients{0x4B5CF90}; + WEAK symbol g_hudelems{0x1A39E00}; WEAK symbol levelEntityId{0x208E1A4}; WEAK symbol gameEntityId{0x208E1A8};