Skip to content

Commit

Permalink
Add updatetext method
Browse files Browse the repository at this point in the history
  • Loading branch information
alicealys committed Jul 5, 2021
1 parent c2d5edd commit 8e0f8e8
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/game/scripting/execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
2 changes: 2 additions & 0 deletions src/game/scripting/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<script_value>& arguments);

void check_thread();
}
21 changes: 21 additions & 0 deletions src/game/scripting/lua/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
};
Expand Down
54 changes: 54 additions & 0 deletions src/game/structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 5 additions & 1 deletion src/game/symbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace game

WEAK symbol<char*(const char*)> I_CleanStr{0x0};

WEAK symbol<unsigned int(const char* name)> G_LocalizedStringIndex{0x52D900};

WEAK symbol<VariableValue(unsigned int classnum, int entnum, int offset)> GetEntityFieldValue{0x56AF20};
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindVariable{0x5651F0};
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindObject{0x565BD0};
Expand All @@ -44,6 +46,7 @@ namespace game

WEAK symbol<void(int clientNum, int type, const char* command)> SV_GameSendServerCommand{0x573220};
WEAK symbol<void(int arg, char* buffer, int bufferLength)> SV_Cmd_ArgvBuffer{0x5459F0};
WEAK symbol<void(unsigned int index, const char* val)> SV_SetConfigstring{0x574BD0};

WEAK symbol<void(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top)> VM_Notify{0x569720};
WEAK symbol<unsigned int(unsigned int localId, unsigned int pos, unsigned int paramcount)> VM_Execute{0x56DFE0};
Expand All @@ -60,12 +63,13 @@ namespace game

WEAK symbol<scrVmPub_t> scr_VmPub{0x20B4A80};
WEAK symbol<scrVarGlob_t> scr_VarGlob{0x1E72180};
WEAK symbol<function_stack_t> scr_function_stack{0x20B4A5C};
WEAK symbol<function_stack_t> scr_function_stack{0x20B4A5C};

WEAK symbol<scr_classStruct_t*> g_classMap{0x8B4300};

WEAK symbol<gentity_s> g_entities{0x1A66E28};
WEAK symbol<client_t> svs_clients{0x4B5CF90};
WEAK symbol<game_hudelem_s> g_hudelems{0x1A39E00};

WEAK symbol<unsigned int> levelEntityId{0x208E1A4};
WEAK symbol<unsigned int> gameEntityId{0x208E1A8};
Expand Down

0 comments on commit 8e0f8e8

Please sign in to comment.