mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2025-04-20 21:05:44 +00:00
This commit is contained in:
parent
e918bdf28f
commit
0ac5225114
@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
#include "game/scripting/array.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
|
||||
namespace gsc
|
||||
{
|
||||
|
@ -2,12 +2,6 @@
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include "game/scripting/event.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
#include "game/scripting/functions.hpp"
|
||||
#include "game/scripting/array.hpp"
|
||||
|
||||
#include "gsc.hpp"
|
||||
#include "json.hpp"
|
||||
|
||||
|
@ -2,12 +2,6 @@
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include "game/scripting/event.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
#include "game/scripting/functions.hpp"
|
||||
#include "game/scripting/array.hpp"
|
||||
|
||||
#include "gsc.hpp"
|
||||
#include "json.hpp"
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
#include <stdinc.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include "game/scripting/entity.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "gsc.hpp"
|
||||
#include "scripting.hpp"
|
||||
|
||||
namespace notifies
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::vector<scripting::function> say_callbacks;
|
||||
utils::hook::detour client_command_hook;
|
||||
|
||||
void client_command_stub(int clientNum)
|
||||
@ -17,19 +18,28 @@ namespace notifies
|
||||
|
||||
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
|
||||
|
||||
auto hidden = false;
|
||||
if (cmd == "say"s || cmd == "say_team"s)
|
||||
{
|
||||
std::string message = game::ConcatArgs(1);
|
||||
message.erase(0, 1);
|
||||
|
||||
const scripting::entity level{*game::levelEntityId};
|
||||
const auto player = scripting::call("getEntByNum", {clientNum}).as<scripting::entity>();
|
||||
for (const auto& callback : say_callbacks)
|
||||
{
|
||||
const auto entity_id = game::Scr_GetEntityId(clientNum, 0);
|
||||
const auto result = callback(entity_id, {message, cmd == "say_team"s});
|
||||
|
||||
scripting::notify(level, cmd, {player, message});
|
||||
scripting::notify(player, cmd, {message});
|
||||
if (result.is<int>())
|
||||
{
|
||||
hidden = result.as<int>() == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return client_command_hook.invoke<void>(clientNum);
|
||||
if (!hidden)
|
||||
{
|
||||
client_command_hook.invoke<void>(clientNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +49,18 @@ namespace notifies
|
||||
void post_unpack() override
|
||||
{
|
||||
client_command_hook.create(0x502CB0, client_command_stub);
|
||||
|
||||
scripting::on_shutdown([]()
|
||||
{
|
||||
say_callbacks.clear();
|
||||
});
|
||||
|
||||
gsc::function::add("onplayersay", [](const gsc::function_args& args) -> scripting::script_value
|
||||
{
|
||||
const auto function = args[0].as<scripting::function>();
|
||||
say_callbacks.push_back(function);
|
||||
return {};
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ namespace scripting
|
||||
|
||||
std::string current_file;
|
||||
|
||||
std::vector<std::function<void()>> shutdown_callbacks;
|
||||
|
||||
void vm_notify_stub(const unsigned int notify_list_owner_id, const unsigned int string_value,
|
||||
game::VariableValue* top)
|
||||
{
|
||||
@ -77,6 +79,13 @@ namespace scripting
|
||||
{
|
||||
userinfo::clear_overrides();
|
||||
command::clear_script_commands();
|
||||
|
||||
for (const auto& callback : shutdown_callbacks)
|
||||
{
|
||||
callback();
|
||||
}
|
||||
|
||||
shutdown_callbacks = {};
|
||||
g_shutdown_game_hook.invoke<void>(free_scripts);
|
||||
}
|
||||
|
||||
@ -106,6 +115,11 @@ namespace scripting
|
||||
}
|
||||
}
|
||||
|
||||
void on_shutdown(const std::function<void()>& callback)
|
||||
{
|
||||
shutdown_callbacks.push_back(callback);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
|
@ -4,4 +4,6 @@ namespace scripting
|
||||
{
|
||||
extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
|
||||
extern std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
|
||||
|
||||
void on_shutdown(const std::function<void()>& callback);
|
||||
}
|
@ -2,12 +2,6 @@
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include "game/scripting/event.hpp"
|
||||
#include "game/scripting/execution.hpp"
|
||||
#include "game/scripting/functions.hpp"
|
||||
#include "game/scripting/array.hpp"
|
||||
|
||||
#include "gsc.hpp"
|
||||
|
||||
namespace userinfo
|
||||
|
Loading…
x
Reference in New Issue
Block a user