improvements from s1x
This commit is contained in:
parent
7045e352ca
commit
91a1cd4d06
@ -39,16 +39,10 @@ namespace ui_scripting
|
|||||||
utils::hook::detour hks_shutdown_hook;
|
utils::hook::detour hks_shutdown_hook;
|
||||||
utils::hook::detour hks_package_require_hook;
|
utils::hook::detour hks_package_require_hook;
|
||||||
|
|
||||||
struct script
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
std::string root;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct globals_t
|
struct globals_t
|
||||||
{
|
{
|
||||||
std::string in_require_script;
|
std::string in_require_script;
|
||||||
std::vector<script> loaded_scripts;
|
std::unordered_map<std::string, std::string> loaded_scripts;
|
||||||
bool load_raw_script{};
|
bool load_raw_script{};
|
||||||
std::string raw_script_name{};
|
std::string raw_script_name{};
|
||||||
};
|
};
|
||||||
@ -57,28 +51,13 @@ namespace ui_scripting
|
|||||||
|
|
||||||
bool is_loaded_script(const std::string& name)
|
bool is_loaded_script(const std::string& name)
|
||||||
{
|
{
|
||||||
for (auto i = globals.loaded_scripts.begin(); i != globals.loaded_scripts.end(); ++i)
|
return globals.loaded_scripts.contains(name);
|
||||||
{
|
|
||||||
if (i->name == name)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_root_script(const std::string& name)
|
std::string get_root_script(const std::string& name)
|
||||||
{
|
{
|
||||||
for (auto i = globals.loaded_scripts.begin(); i != globals.loaded_scripts.end(); ++i)
|
const auto itr = globals.loaded_scripts.find(name);
|
||||||
{
|
return itr == globals.loaded_scripts.end() ? std::string() : itr->second;
|
||||||
if (i->name == name)
|
|
||||||
{
|
|
||||||
return i->root;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table get_globals()
|
table get_globals()
|
||||||
@ -124,7 +103,7 @@ namespace ui_scripting
|
|||||||
|
|
||||||
void load_script(const std::string& name, const std::string& data)
|
void load_script(const std::string& name, const std::string& data)
|
||||||
{
|
{
|
||||||
globals.loaded_scripts.push_back({name, name});
|
globals.loaded_scripts[name] = name;
|
||||||
|
|
||||||
const auto lua = get_globals();
|
const auto lua = get_globals();
|
||||||
const auto load_results = lua["loadstring"](data, name);
|
const auto load_results = lua["loadstring"](data, name);
|
||||||
@ -454,14 +433,11 @@ namespace ui_scripting
|
|||||||
if (globals.load_raw_script)
|
if (globals.load_raw_script)
|
||||||
{
|
{
|
||||||
globals.load_raw_script = false;
|
globals.load_raw_script = false;
|
||||||
globals.loaded_scripts.push_back({globals.raw_script_name, globals.in_require_script});
|
globals.loaded_scripts[globals.raw_script_name] = globals.in_require_script;
|
||||||
return load_buffer(globals.raw_script_name, utils::io::read_file(globals.raw_script_name));
|
return load_buffer(globals.raw_script_name, utils::io::read_file(globals.raw_script_name));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return utils::hook::invoke<int>(0x1402D9410, state, compiler_options, reader, reader_data, chunk_name);
|
||||||
return utils::hook::invoke<int>(0x1402D9410, state, compiler_options, reader,
|
|
||||||
reader_data, chunk_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string current_error;
|
std::string current_error;
|
||||||
@ -478,7 +454,7 @@ namespace ui_scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto closure = value.v.cClosure;
|
const auto closure = value.v.cClosure;
|
||||||
if (converted_functions.find(closure) == converted_functions.end())
|
if (!converted_functions.contains(closure))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ namespace game
|
|||||||
WEAK symbol<int(void* ps, unsigned int weapon, int a3, int a4, __int64 a5, int a6)>
|
WEAK symbol<int(void* ps, unsigned int weapon, int a3, int a4, __int64 a5, int a6)>
|
||||||
G_GivePlayerWeapon{0x14051B660};
|
G_GivePlayerWeapon{0x14051B660};
|
||||||
WEAK symbol<void(void* ps, const unsigned int weapon, int hadWeapon)> G_InitializeAmmo{0x1404C4110};
|
WEAK symbol<void(void* ps, const unsigned int weapon, int hadWeapon)> G_InitializeAmmo{0x1404C4110};
|
||||||
WEAK symbol<void(int clientNum, const unsigned int weapon)> G_SelectWeapon{0x14051C0D0};
|
WEAK symbol<void(int localClientNum, const unsigned int weapon)> G_SelectWeapon{0x14051C0D0};
|
||||||
WEAK symbol<bool(int localClientNum, ScreenPlacement* screenPlacement, const float* worldDir, float* outScreenPos)> WorldPosToScreenPos{0x14036F310};
|
WEAK symbol<bool(int localClientNum, ScreenPlacement* screenPlacement, const float* worldDir, float* outScreenPos)> WorldPosToScreenPos{0x14036F310};
|
||||||
|
|
||||||
WEAK symbol<char*(char* string)> I_CleanStr{0x140620660};
|
WEAK symbol<char*(char* string)> I_CleanStr{0x140620660};
|
||||||
@ -101,15 +101,15 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<const char*(int, int, int)> Key_KeynumToString{0x1403D32D0};
|
WEAK symbol<const char*(int, int, int)> Key_KeynumToString{0x1403D32D0};
|
||||||
|
|
||||||
WEAK symbol<void(int clientNum, const char* menu, int a3, int a4, unsigned int a5)> LUI_OpenMenu{0x1405F0EE0};
|
WEAK symbol<void(int localClientNum, const char* menuName, int a3, int a4, unsigned int a5)> LUI_OpenMenu{0x1405F0EE0};
|
||||||
WEAK symbol<bool(int clientNum, const char* name, hks::lua_State* s)> LUI_BeginEvent{0x1403155E0};
|
WEAK symbol<bool(int localClientNum, const char* name, hks::lua_State* s)> LUI_BeginEvent{0x1403155E0};
|
||||||
WEAK symbol<bool(int clientNum, int lui_event_cache, hks::lua_State* s)> LUI_BeginCachedEvent{0x1403153E0};
|
WEAK symbol<bool(int localClientNum, int lui_event_cache, hks::lua_State* s)> LUI_BeginCachedEvent{0x1403153E0};
|
||||||
WEAK symbol<void(const char* name, int value, hks::lua_State* s)> LUI_SetTableInt{0x140320060};
|
WEAK symbol<void(const char* name, int value, hks::lua_State* s)> LUI_SetTableInt{0x140320060};
|
||||||
WEAK symbol<void(const char* name, const char* value, hks::lua_State* s)> LUI_SetTableString{0x1403201F0};
|
WEAK symbol<void(const char* name, const char* value, hks::lua_State* s)> LUI_SetTableString{0x1403201F0};
|
||||||
WEAK symbol<void(hks::lua_State* s)> LUI_EndEvent{0x140316890};
|
WEAK symbol<void(hks::lua_State* s)> LUI_EndEvent{0x140316890};
|
||||||
WEAK symbol<void()> LUI_EnterCriticalSection{0x140316980};
|
WEAK symbol<void()> LUI_EnterCriticalSection{0x140316980};
|
||||||
WEAK symbol<void()> LUI_LeaveCriticalSection{0x14031BC20};
|
WEAK symbol<void()> LUI_LeaveCriticalSection{0x14031BC20};
|
||||||
WEAK symbol<bool(int clientNum, const char* menu)> Menu_IsMenuOpenAndVisible{0x1405EE1A0};
|
WEAK symbol<bool(int localClientNum, const char* menuName)> Menu_IsMenuOpenAndVisible{0x1405EE1A0};
|
||||||
|
|
||||||
WEAK symbol<Material*(const char* material)> Material_RegisterHandle{0x140759BA0};
|
WEAK symbol<Material*(const char* material)> Material_RegisterHandle{0x140759BA0};
|
||||||
|
|
||||||
@ -273,6 +273,6 @@ namespace game
|
|||||||
WEAK symbol<int(lua_State* s, const char* what, lua_Debug* ar)> hksi_lua_getinfo{0x1402DD1F0};
|
WEAK symbol<int(lua_State* s, const char* what, lua_Debug* ar)> hksi_lua_getinfo{0x1402DD1F0};
|
||||||
WEAK symbol<int(lua_State* s, int level, lua_Debug* ar)> hksi_lua_getstack{0x1402DD4C0};
|
WEAK symbol<int(lua_State* s, int level, lua_Debug* ar)> hksi_lua_getstack{0x1402DD4C0};
|
||||||
WEAK symbol<void(lua_State* s, const char* fmt, ...)> hksi_luaL_error{0x1402E3E40};
|
WEAK symbol<void(lua_State* s, const char* fmt, ...)> hksi_luaL_error{0x1402E3E40};
|
||||||
WEAK symbol<const char*> typenames{0x140BE9F50};
|
WEAK symbol<const char*> s_compilerTypeName{0x140BE9F50};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -70,7 +70,7 @@ namespace ui_scripting
|
|||||||
values.push_back(v);
|
values.push_back(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (values.size() == 0)
|
if (values.empty())
|
||||||
{
|
{
|
||||||
values.push_back({});
|
values.push_back({});
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ namespace ui_scripting
|
|||||||
values.push_back(v);
|
values.push_back(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (values.size() == 0)
|
if (values.empty())
|
||||||
{
|
{
|
||||||
values.push_back({});
|
values.push_back({});
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ namespace ui_scripting
|
|||||||
{
|
{
|
||||||
if (!this->is<T>())
|
if (!this->is<T>())
|
||||||
{
|
{
|
||||||
const auto hks_typename = game::hks::typenames[this->get_raw().t + 2];
|
const auto hks_typename = game::hks::s_compilerTypeName[this->get_raw().t + 2];
|
||||||
const auto typename_ = get_typename<T>();
|
const auto typename_ = get_typename<T>();
|
||||||
|
|
||||||
throw std::runtime_error(utils::string::va("%s expected, got %s",
|
throw std::runtime_error(utils::string::va("%s expected, got %s",
|
||||||
|
Loading…
Reference in New Issue
Block a user