mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
Merge pull request #448 from diamante0018/develop
gsc: fix print & println (& more)
This commit is contained in:
commit
16d8af4e13
69
src/client/component/gsc/script_extension.cpp
Normal file
69
src/client/component/gsc/script_extension.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
|
||||
#include "component/console.hpp"
|
||||
|
||||
#include <xsk/gsc/types.hpp>
|
||||
#include <xsk/resolver.hpp>
|
||||
|
||||
namespace gsc
|
||||
{
|
||||
namespace
|
||||
{
|
||||
typedef void(*builtin_function)();
|
||||
std::unordered_map<std::uint32_t, builtin_function> builtin_funcs_overrides;
|
||||
|
||||
utils::hook::detour scr_register_function_hook;
|
||||
|
||||
void override_function(const std::string& name, builtin_function func)
|
||||
{
|
||||
const auto id = xsk::gsc::s1::resolver::function_id(name);
|
||||
builtin_funcs_overrides.emplace(id, func);
|
||||
}
|
||||
|
||||
void scr_register_function_stub(void* func, int type, unsigned int name)
|
||||
{
|
||||
if (const auto got = builtin_funcs_overrides.find(name); got != builtin_funcs_overrides.end())
|
||||
{
|
||||
func = got->second;
|
||||
}
|
||||
|
||||
scr_register_function_hook.invoke<void>(func, type, name);
|
||||
}
|
||||
|
||||
void scr_print()
|
||||
{
|
||||
for (auto i = 0u; i < game::Scr_GetNumParam(); ++i)
|
||||
{
|
||||
console::info("%s", game::Scr_GetString(i));
|
||||
}
|
||||
}
|
||||
|
||||
void scr_print_ln()
|
||||
{
|
||||
for (auto i = 0u; i < game::Scr_GetNumParam(); ++i)
|
||||
{
|
||||
console::info("%s", game::Scr_GetString(i));
|
||||
}
|
||||
|
||||
console::info("\n");
|
||||
}
|
||||
}
|
||||
|
||||
class extension final : public component_interface
|
||||
{
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
scr_register_function_hook.create(game::Scr_RegisterFunction, &scr_register_function_stub);
|
||||
|
||||
override_function("print", &scr_print);
|
||||
override_function("println", &scr_print_ln);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_COMPONENT(gsc::extension)
|
@ -185,7 +185,7 @@ namespace gsc
|
||||
real_name = xsk::gsc::s1::resolver::token_name(id);
|
||||
}
|
||||
|
||||
const auto script = load_custom_script(name, real_name);
|
||||
auto* script = load_custom_script(name, real_name);
|
||||
if (script)
|
||||
{
|
||||
return script;
|
||||
|
@ -158,10 +158,10 @@ namespace game
|
||||
|
||||
WEAK symbol<unsigned int()> Scr_AllocArray{0x140317C50, 0x1403F4280};
|
||||
WEAK symbol<const float*(const float* v)> Scr_AllocVector{0x140317D10, 0x1403F4370};
|
||||
WEAK symbol<const char*(int index)> Scr_GetString{0x14031C570, 0x1403F8C50};
|
||||
WEAK symbol<unsigned int()> Scr_GetInt{0x14031C1F0, 0x1403F88D0};
|
||||
WEAK symbol<float(int index)> Scr_GetFloat{0x14031C090, 0x1403F8820};
|
||||
WEAK symbol<int()> Scr_GetNumParam{0x14031C2A0, 0x1403F8980};
|
||||
WEAK symbol<const char*(unsigned int index)> Scr_GetString{0x14031C570, 0x1403F8C50};
|
||||
WEAK symbol<int(unsigned int index)> Scr_GetInt{0x14031C1F0, 0x1403F88D0};
|
||||
WEAK symbol<float(unsigned int index)> Scr_GetFloat{0x14031C090, 0x1403F8820};
|
||||
WEAK symbol<unsigned int()> Scr_GetNumParam{0x14031C2A0, 0x1403F8980};
|
||||
WEAK symbol<void()> Scr_ClearOutParams{0x14031B7C0, 0x1403F8040};
|
||||
WEAK symbol<scr_entref_t(unsigned int entId)> Scr_GetEntityIdRef{0x14031A0D0, 0x1403F68A0};
|
||||
WEAK symbol<int(unsigned int classnum, int entnum, int offset)> Scr_SetObjectField{0x14026B620, 0x140339450};
|
||||
@ -170,7 +170,7 @@ namespace game
|
||||
WEAK symbol<unsigned __int16(int handle, unsigned int paramcount)> Scr_ExecThread{0x0, 0x1403F8120};
|
||||
WEAK symbol<unsigned int(const char* name)> Scr_LoadScript{0x0, 0x1403EE250};
|
||||
WEAK symbol<unsigned int(const char* script, unsigned int name)> Scr_GetFunctionHandle{0x0, 0x1403EE0D0};
|
||||
WEAK symbol<unsigned int(void* func, int type, unsigned int name)> Scr_RegisterFunction{0x0, 0x1403EDAE0};
|
||||
WEAK symbol<unsigned int(void* func, int type, unsigned int name)> Scr_RegisterFunction{0x1403115B0, 0x1403EDAE0};
|
||||
|
||||
WEAK symbol<unsigned int(unsigned int localId, const char* pos, unsigned int paramcount)> VM_Execute{0x0, 0x1403F9E40};
|
||||
|
||||
|
BIN
tools/protoc.exe
BIN
tools/protoc.exe
Binary file not shown.
Loading…
Reference in New Issue
Block a user