mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2025-07-03 09:41:51 +00:00
Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
4ffdb331b4 | |||
7b995b3348 | |||
14d0f401fb | |||
df23604b1e | |||
e2960bc895 | |||
db90d361a9 | |||
6ec0c5e23c | |||
c84d681a3a | |||
62d1c8671b | |||
877adfa4b6 | |||
12fd44d0da | |||
12562eb8fd | |||
286481cbcd | |||
e9a877bd74 | |||
3060df1f05 | |||
aa1ae8c574 | |||
ccd8176c25
|
|||
c230a1d916
|
|||
2785a60dc0
|
|||
1b65bda323 | |||
9ca07aca55 | |||
10b45027d0 | |||
d5c0063fee
|
|||
31920b0692 | |||
89e4edc00b | |||
379a21ff7e | |||
0ac5225114 | |||
e918bdf28f | |||
50b83787e7 | |||
e6ca925562 | |||
0f92a7ce25 | |||
d4d91de80f | |||
a508a7e3a4 |
7
.gitmodules
vendored
7
.gitmodules
vendored
@ -4,12 +4,7 @@
|
|||||||
[submodule "deps/GSL"]
|
[submodule "deps/GSL"]
|
||||||
path = deps/GSL
|
path = deps/GSL
|
||||||
url = https://github.com/microsoft/GSL.git
|
url = https://github.com/microsoft/GSL.git
|
||||||
[submodule "deps/sol2"]
|
|
||||||
path = deps/sol2
|
|
||||||
url = https://github.com/ThePhD/sol2.git
|
|
||||||
[submodule "deps/lua"]
|
|
||||||
path = deps/lua
|
|
||||||
url = https://github.com/lua/lua.git
|
|
||||||
[submodule "deps/json"]
|
[submodule "deps/json"]
|
||||||
path = deps/json
|
path = deps/json
|
||||||
url = https://github.com/nlohmann/json.git
|
url = https://github.com/nlohmann/json.git
|
||||||
|
branch = develop
|
||||||
|
2
deps/json
vendored
2
deps/json
vendored
Submodule deps/json updated: e10a3fac8a...e4643d1f1b
@ -1,2 +1,3 @@
|
|||||||
@echo off
|
@echo off
|
||||||
tools\windows\premake5.exe vs2019
|
call git submodule update --init --recursive
|
||||||
|
tools\windows\premake5.exe vs2022
|
21
premake5.lua
21
premake5.lua
@ -36,32 +36,35 @@ workspace "iw5-gsc-utils"
|
|||||||
targetdir "%{wks.location}/bin/%{cfg.buildcfg}"
|
targetdir "%{wks.location}/bin/%{cfg.buildcfg}"
|
||||||
targetname "%{prj.name}"
|
targetname "%{prj.name}"
|
||||||
|
|
||||||
|
configurations { "Debug", "Release", }
|
||||||
|
|
||||||
language "C++"
|
language "C++"
|
||||||
|
cppdialect "C++20"
|
||||||
|
|
||||||
architecture "x86"
|
architecture "x86"
|
||||||
|
|
||||||
buildoptions "/std:c++latest"
|
|
||||||
systemversion "latest"
|
systemversion "latest"
|
||||||
|
symbols "On"
|
||||||
|
staticruntime "On"
|
||||||
|
editandcontinue "Off"
|
||||||
|
warnings "Extra"
|
||||||
|
characterset "ASCII"
|
||||||
|
|
||||||
flags
|
flags
|
||||||
{
|
{
|
||||||
"NoIncrementalLink",
|
"NoIncrementalLink",
|
||||||
"MultiProcessorCompile",
|
"MultiProcessorCompile",
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations { "Debug", "Release", }
|
|
||||||
|
|
||||||
symbols "On"
|
|
||||||
|
|
||||||
configuration "Release"
|
filter "configurations:Release"
|
||||||
optimize "Full"
|
optimize "Full"
|
||||||
defines { "NDEBUG" }
|
defines { "NDEBUG" }
|
||||||
configuration{}
|
filter {}
|
||||||
|
|
||||||
configuration "Debug"
|
filter "configurations:Debug"
|
||||||
optimize "Debug"
|
optimize "Debug"
|
||||||
defines { "DEBUG", "_DEBUG" }
|
defines { "DEBUG", "_DEBUG" }
|
||||||
configuration {}
|
filter {}
|
||||||
|
|
||||||
startproject "iw5-gsc-utils"
|
startproject "iw5-gsc-utils"
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ namespace command
|
|||||||
if (i > index) result.append(" ");
|
if (i > index) result.append(" ");
|
||||||
result.append(this->get(i));
|
result.append(this->get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +97,6 @@ namespace command
|
|||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,6 @@ namespace gsc
|
|||||||
{
|
{
|
||||||
std::vector<scripting::script_value> args;
|
std::vector<scripting::script_value> args;
|
||||||
|
|
||||||
const auto top = game::scr_VmPub->top;
|
|
||||||
|
|
||||||
for (auto i = 0; i < game::scr_VmPub->outparamcount; i++)
|
for (auto i = 0; i < game::scr_VmPub->outparamcount; i++)
|
||||||
{
|
{
|
||||||
const auto value = game::scr_VmPub->top[-i];
|
const auto value = game::scr_VmPub->top[-i];
|
||||||
@ -93,7 +91,7 @@ namespace gsc
|
|||||||
{
|
{
|
||||||
if (id < 0x200)
|
if (id < 0x200)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<builtin_function*>(0x20689DD8)[id]();
|
return reinterpret_cast<builtin_function*>(game::plutonium::function_table.get())[id]();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -119,7 +117,7 @@ namespace gsc
|
|||||||
{
|
{
|
||||||
if (id < 0x8400)
|
if (id < 0x8400)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<builtin_method*>(0x2068A5A8)[id - 0x8000](ent);
|
return reinterpret_cast<builtin_method*>(game::plutonium::method_table.get())[id - 0x8000](ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -270,7 +268,7 @@ namespace gsc
|
|||||||
|
|
||||||
namespace field
|
namespace field
|
||||||
{
|
{
|
||||||
void add(classid classnum, const std::string& name,
|
void add(const classid classnum, const std::string& name,
|
||||||
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
||||||
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
|
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
|
||||||
{
|
{
|
||||||
@ -380,6 +378,20 @@ namespace gsc
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function::add("dropallbots", [](const function_args&) -> scripting::script_value
|
||||||
|
{
|
||||||
|
for (auto i = 0; i < *game::svs_clientCount; i++)
|
||||||
|
{
|
||||||
|
if (game::svs_clients[i].header.state != game::CS_FREE
|
||||||
|
&& game::svs_clients[i].header.netchan.remoteAddress.type == game::NA_BOT)
|
||||||
|
{
|
||||||
|
game::SV_GameDropClient(i, "GAME_GET_TO_COVER");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
|
||||||
method::add("tell", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value
|
method::add("tell", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
if (ent.classnum != 0)
|
if (ent.classnum != 0)
|
||||||
@ -388,8 +400,13 @@ namespace gsc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto client = ent.entnum;
|
const auto client = ent.entnum;
|
||||||
const auto message = args[0].as<std::string>();
|
|
||||||
|
|
||||||
|
if (game::g_entities[client].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto message = args[0].as<std::string>();
|
||||||
game::SV_GameSendServerCommand(client, 0, utils::string::va("%c \"%s\"", 84, message.data()));
|
game::SV_GameSendServerCommand(client, 0, utils::string::va("%c \"%s\"", 84, message.data()));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@ -402,22 +419,62 @@ namespace gsc
|
|||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto num = ent.entnum;
|
const auto client = ent.entnum;
|
||||||
|
|
||||||
|
if (game::g_entities[client].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
const auto toggle = args[0].as<int>();
|
const auto toggle = args[0].as<int>();
|
||||||
|
auto flags = game::g_entities[client].client->ps.perks[0];
|
||||||
|
|
||||||
auto g_client = game::g_entities[num].client;
|
game::g_entities[client].client->ps.perks[0] = toggle
|
||||||
auto playerState = &g_client->ps;
|
? flags | 0x4000u : flags & ~0x4000u;
|
||||||
auto flags = playerState->perks[0];
|
|
||||||
|
|
||||||
playerState->perks[0] = toggle
|
|
||||||
? flags | 0x4000u
|
|
||||||
: flags & ~0x4000u;
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
utils::hook::jump(0x56C8EB, call_builtin_stub);
|
method::add("isbot", [](const game::scr_entref_t ent, const function_args&) -> scripting::script_value
|
||||||
utils::hook::jump(0x56CBDC, call_builtin_method_stub);
|
{
|
||||||
|
if (ent.classnum != 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto client = ent.entnum;
|
||||||
|
|
||||||
|
if (game::g_entities[client].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
return game::svs_clients[client].bIsTestClient;
|
||||||
|
});
|
||||||
|
|
||||||
|
method::add("arecontrolsfrozen", [](const game::scr_entref_t ent, const function_args&) -> scripting::script_value
|
||||||
|
{
|
||||||
|
if (ent.classnum != 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto client = ent.entnum;
|
||||||
|
|
||||||
|
if (game::g_entities[client].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {(game::g_entities[client].client->flags & 4) != 0};
|
||||||
|
});
|
||||||
|
|
||||||
|
// let other plugins read the pointers
|
||||||
|
post_load_callbacks.push_back([]()
|
||||||
|
{
|
||||||
|
utils::hook::jump(0x56C8EB, call_builtin_stub);
|
||||||
|
utils::hook::jump(0x56CBDC, call_builtin_method_stub);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "game/scripting/array.hpp"
|
||||||
|
#include "game/scripting/execution.hpp"
|
||||||
|
|
||||||
namespace gsc
|
namespace gsc
|
||||||
{
|
{
|
||||||
@ -46,7 +48,7 @@ namespace gsc
|
|||||||
|
|
||||||
namespace field
|
namespace field
|
||||||
{
|
{
|
||||||
void add(classid classnum, const std::string& name,
|
void add(const classid classnum, const std::string& name,
|
||||||
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
const std::function<scripting::script_value(unsigned int entnum)>& getter,
|
||||||
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter);
|
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter);
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,6 @@
|
|||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
#include "scheduler.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 "gsc.hpp"
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
|
||||||
|
@ -2,12 +2,6 @@
|
|||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
#include "scheduler.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 "gsc.hpp"
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
|
||||||
|
@ -1,35 +1,51 @@
|
|||||||
#include <stdinc.hpp>
|
#include <stdinc.hpp>
|
||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
#include "scheduler.hpp"
|
|
||||||
|
|
||||||
#include "game/scripting/entity.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "game/scripting/execution.hpp"
|
#include "gsc.hpp"
|
||||||
|
#include "scripting.hpp"
|
||||||
|
|
||||||
namespace notifies
|
namespace notifies
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
std::vector<scripting::function> say_callbacks;
|
||||||
utils::hook::detour client_command_hook;
|
utils::hook::detour client_command_hook;
|
||||||
|
|
||||||
void client_command_stub(int clientNum)
|
void client_command_stub(int clientNum)
|
||||||
{
|
{
|
||||||
char cmd[1024] = { 0 };
|
char cmd[1024] = {0};
|
||||||
|
const auto* entity = &game::g_entities[clientNum];
|
||||||
|
|
||||||
|
if (entity->client == nullptr)
|
||||||
|
{
|
||||||
|
return; // Client is not fully in game yet
|
||||||
|
}
|
||||||
|
|
||||||
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
|
game::SV_Cmd_ArgvBuffer(0, cmd, 1024);
|
||||||
|
|
||||||
|
auto hidden = false;
|
||||||
if (cmd == "say"s || cmd == "say_team"s)
|
if (cmd == "say"s || cmd == "say_team"s)
|
||||||
{
|
{
|
||||||
std::string message = game::ConcatArgs(1);
|
std::string message = game::ConcatArgs(1);
|
||||||
message.erase(0, 1);
|
message.erase(0, 1);
|
||||||
|
|
||||||
const scripting::entity level{*game::levelEntityId};
|
for (const auto& callback : say_callbacks)
|
||||||
const auto player = scripting::call("getEntByNum", {clientNum}).as<scripting::entity>();
|
{
|
||||||
|
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});
|
if (result.is<int>() && !hidden)
|
||||||
scripting::notify(player, cmd, {message});
|
{
|
||||||
|
hidden = result.as<int>() == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return client_command_hook.invoke<void>(clientNum);
|
if (!hidden)
|
||||||
|
{
|
||||||
|
client_command_hook.invoke<void>(clientNum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +55,18 @@ namespace notifies
|
|||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
client_command_hook.create(0x502CB0, client_command_stub);
|
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::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,
|
void vm_notify_stub(const unsigned int notify_list_owner_id, const unsigned int string_value,
|
||||||
game::VariableValue* top)
|
game::VariableValue* top)
|
||||||
{
|
{
|
||||||
@ -77,6 +79,12 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
userinfo::clear_overrides();
|
userinfo::clear_overrides();
|
||||||
command::clear_script_commands();
|
command::clear_script_commands();
|
||||||
|
|
||||||
|
for (const auto& callback : shutdown_callbacks)
|
||||||
|
{
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
g_shutdown_game_hook.invoke<void>(free_scripts);
|
g_shutdown_game_hook.invoke<void>(free_scripts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +95,7 @@ namespace scripting
|
|||||||
const auto file_id = atoi(filename);
|
const auto file_id = atoi(filename);
|
||||||
if (file_id)
|
if (file_id)
|
||||||
{
|
{
|
||||||
current_file = scripting::file_list[file_id];
|
current_file = scripting::find_file(file_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
process_script_hook.invoke<void>(filename);
|
process_script_hook.invoke<void>(filename);
|
||||||
@ -106,6 +114,11 @@ namespace scripting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void on_shutdown(const std::function<void()>& callback)
|
||||||
|
{
|
||||||
|
shutdown_callbacks.push_back(callback);
|
||||||
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -4,4 +4,6 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
|
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;
|
extern std::unordered_map<std::string, std::unordered_map<std::string, const char*>> script_function_table;
|
||||||
|
|
||||||
|
void on_shutdown(const std::function<void()>& callback);
|
||||||
}
|
}
|
108
src/component/signatures.cpp
Normal file
108
src/component/signatures.cpp
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
#include <stdinc.hpp>
|
||||||
|
#include "signatures.hpp"
|
||||||
|
#include <utils/hook.hpp>
|
||||||
|
|
||||||
|
#define PAYLOAD_SIZE 0x20000000
|
||||||
|
|
||||||
|
namespace signatures
|
||||||
|
{
|
||||||
|
size_t load_image_size()
|
||||||
|
{
|
||||||
|
MODULEINFO info{};
|
||||||
|
GetModuleInformation(GetCurrentProcess(),
|
||||||
|
GetModuleHandle("plutonium-bootstrapper-win32.exe"), &info, sizeof(MODULEINFO));
|
||||||
|
return info.SizeOfImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t get_image_size()
|
||||||
|
{
|
||||||
|
static const auto image_size = load_image_size();
|
||||||
|
return image_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_function_tables()
|
||||||
|
{
|
||||||
|
static const auto ptr = *reinterpret_cast<size_t*>(0x56CBDC + 0x1) + 0x56CBDC + 0x5;
|
||||||
|
static const auto function_table = *reinterpret_cast<size_t*>(0x56C8EB + 0x3);
|
||||||
|
static const auto method_table = *reinterpret_cast<size_t*>(ptr + 0xA);
|
||||||
|
|
||||||
|
game::plutonium::function_table.set(function_table);
|
||||||
|
game::plutonium::method_table.set(method_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t find_string_ptr(const std::string& string)
|
||||||
|
{
|
||||||
|
const char* string_ptr = nullptr;
|
||||||
|
std::string mask(string.size(), 'x');
|
||||||
|
utils::hook::signature signature(PAYLOAD_SIZE, get_image_size() - PAYLOAD_SIZE);
|
||||||
|
|
||||||
|
signature.add({
|
||||||
|
string,
|
||||||
|
mask,
|
||||||
|
[&](char* address)
|
||||||
|
{
|
||||||
|
string_ptr = address;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
signature.process();
|
||||||
|
return reinterpret_cast<size_t>(string_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t find_string_ref(const std::string& string)
|
||||||
|
{
|
||||||
|
char bytes[4] = {0};
|
||||||
|
const auto string_ptr = find_string_ptr(string);
|
||||||
|
memcpy(bytes, &string_ptr, sizeof(size_t));
|
||||||
|
return find_string_ptr(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_maps()
|
||||||
|
{
|
||||||
|
const auto string_ref = find_string_ref("Couldn't resolve builtin function id for name '%s'!");
|
||||||
|
if (!string_ref)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto map_ptr = *reinterpret_cast<size_t*>(string_ref - 0x3A);
|
||||||
|
game::plutonium::function_map_rev.set(map_ptr);
|
||||||
|
game::plutonium::method_map_rev.set(map_ptr + 0x20);
|
||||||
|
game::plutonium::file_map_rev.set(map_ptr + 0x40);
|
||||||
|
game::plutonium::token_map_rev.set(map_ptr + 0x60);
|
||||||
|
|
||||||
|
for (const auto& function : *game::plutonium::function_map_rev)
|
||||||
|
{
|
||||||
|
utils::io::write_file("functions.txt", function.first, true);
|
||||||
|
utils::io::write_file("functions.txt", "\n", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& function : *game::plutonium::method_map_rev)
|
||||||
|
{
|
||||||
|
utils::io::write_file("methods.txt", function.first, true);
|
||||||
|
utils::io::write_file("methods.txt", "\n", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_printf()
|
||||||
|
{
|
||||||
|
const auto string_ref = find_string_ref("A critical exception occured!\n");
|
||||||
|
if (!string_ref)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto offset = *reinterpret_cast<size_t*>(string_ref + 5);
|
||||||
|
game::plutonium::printf.set(string_ref + 4 + 5 + offset);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process()
|
||||||
|
{
|
||||||
|
load_function_tables();
|
||||||
|
process_printf();
|
||||||
|
return process_maps();
|
||||||
|
}
|
||||||
|
}
|
6
src/component/signatures.hpp
Normal file
6
src/component/signatures.hpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace signatures
|
||||||
|
{
|
||||||
|
bool process();
|
||||||
|
}
|
46
src/component/string.cpp
Normal file
46
src/component/string.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <stdinc.hpp>
|
||||||
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
|
#include "gsc.hpp"
|
||||||
|
|
||||||
|
#include <utils/string.hpp>
|
||||||
|
|
||||||
|
namespace string
|
||||||
|
{
|
||||||
|
class component final : public component_interface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void post_unpack() override
|
||||||
|
{
|
||||||
|
gsc::function::add("toupper", [](const gsc::function_args& args)
|
||||||
|
{
|
||||||
|
return utils::string::to_upper(args[0].as<std::string>());
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::function::add("getchar", [](const gsc::function_args& args)
|
||||||
|
{
|
||||||
|
auto index = 0;
|
||||||
|
if (args.size() > 1)
|
||||||
|
{
|
||||||
|
index = args[1].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto string = args[0].as<std::string>();
|
||||||
|
if (index >= static_cast<int>(string.size()))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Char index out of bounds");
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<int>(string[index]);
|
||||||
|
});
|
||||||
|
|
||||||
|
gsc::function::add("chartostring", [](const gsc::function_args& args)
|
||||||
|
{
|
||||||
|
const auto char_ = static_cast<char>(args[0].as<int>());
|
||||||
|
return std::string(1, char_);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
REGISTER_COMPONENT(string::component)
|
@ -2,12 +2,6 @@
|
|||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
#include "scheduler.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 "gsc.hpp"
|
||||||
|
|
||||||
namespace userinfo
|
namespace userinfo
|
||||||
@ -19,12 +13,17 @@ namespace userinfo
|
|||||||
{
|
{
|
||||||
utils::hook::detour sv_getuserinfo_hook;
|
utils::hook::detour sv_getuserinfo_hook;
|
||||||
|
|
||||||
userinfo_map userinfo_to_map(const std::string& userinfo)
|
userinfo_map userinfo_to_map(std::string userinfo)
|
||||||
{
|
{
|
||||||
userinfo_map map;
|
userinfo_map map{};
|
||||||
const auto args = utils::string::split(userinfo, '\\');
|
|
||||||
|
|
||||||
for (auto i = 1; i < args.size() - 1; i += 2)
|
if (userinfo[0] == '\\')
|
||||||
|
{
|
||||||
|
userinfo = userinfo.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto args = utils::string::split(userinfo, '\\');
|
||||||
|
for (size_t i = 0; !args.empty() && i < (args.size() - 1); i += 2)
|
||||||
{
|
{
|
||||||
map[args[i]] = args[i + 1];
|
map[args[i]] = args[i + 1];
|
||||||
}
|
}
|
||||||
@ -34,7 +33,7 @@ namespace userinfo
|
|||||||
|
|
||||||
std::string map_to_userinfo(const userinfo_map& map)
|
std::string map_to_userinfo(const userinfo_map& map)
|
||||||
{
|
{
|
||||||
std::string buffer;
|
std::string buffer{};
|
||||||
|
|
||||||
for (const auto& value : map)
|
for (const auto& value : map)
|
||||||
{
|
{
|
||||||
@ -49,9 +48,8 @@ namespace userinfo
|
|||||||
|
|
||||||
void sv_getuserinfo_stub(int index, char* buffer, int bufferSize)
|
void sv_getuserinfo_stub(int index, char* buffer, int bufferSize)
|
||||||
{
|
{
|
||||||
char _buffer[1024];
|
sv_getuserinfo_hook.invoke<void>(index, buffer, bufferSize);
|
||||||
sv_getuserinfo_hook.invoke<void>(index, _buffer, 1024);
|
auto map = userinfo_to_map(buffer);
|
||||||
auto map = userinfo_to_map(_buffer);
|
|
||||||
|
|
||||||
if (userinfo_overrides.find(index) == userinfo_overrides.end())
|
if (userinfo_overrides.find(index) == userinfo_overrides.end())
|
||||||
{
|
{
|
||||||
@ -94,28 +92,36 @@ namespace userinfo
|
|||||||
|
|
||||||
gsc::method::add("setname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("setname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto name = args[0].as<std::string>();
|
if (ent.classnum != 0)
|
||||||
|
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto name = args[0].as<std::string>();
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum]["name"] = name;
|
userinfo_overrides[ent.entnum]["name"] = name;
|
||||||
game::ClientUserinfoChanged(ent.entnum);
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::method::add("resetname", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("resetname", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto name = args[0].as<std::string>();
|
if (ent.classnum != 0)
|
||||||
|
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum].erase("name");
|
userinfo_overrides[ent.entnum].erase("name");
|
||||||
game::ClientUserinfoChanged(ent.entnum);
|
game::ClientUserinfoChanged(ent.entnum);
|
||||||
|
|
||||||
@ -124,13 +130,18 @@ namespace userinfo
|
|||||||
|
|
||||||
gsc::method::add("setclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("setclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto name = args[0].as<std::string>();
|
if (ent.classnum != 0)
|
||||||
|
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto name = args[0].as<std::string>();
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum]["clantag"] = name;
|
userinfo_overrides[ent.entnum]["clantag"] = name;
|
||||||
userinfo_overrides[ent.entnum]["ec_TagText"] = name;
|
userinfo_overrides[ent.entnum]["ec_TagText"] = name;
|
||||||
userinfo_overrides[ent.entnum]["ec_usingTag"] = "1";
|
userinfo_overrides[ent.entnum]["ec_usingTag"] = "1";
|
||||||
@ -139,15 +150,18 @@ namespace userinfo
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::method::add("resetclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("resetclantag", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
|
||||||
{
|
{
|
||||||
const auto name = args[0].as<std::string>();
|
if (ent.classnum != 0)
|
||||||
|
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum].erase("clantag");
|
userinfo_overrides[ent.entnum].erase("clantag");
|
||||||
userinfo_overrides[ent.entnum].erase("ec_TagText");
|
userinfo_overrides[ent.entnum].erase("ec_TagText");
|
||||||
userinfo_overrides[ent.entnum].erase("ec_usingTag");
|
userinfo_overrides[ent.entnum].erase("ec_usingTag");
|
||||||
@ -156,13 +170,18 @@ namespace userinfo
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::method::add("removeclantag", [](const game::scr_entref_t ent, const gsc::function_args& args) -> scripting::script_value
|
gsc::method::add("removeclantag", [](const game::scr_entref_t ent, const gsc::function_args&) -> scripting::script_value
|
||||||
{
|
{
|
||||||
if (ent.classnum != 0 || ent.entnum > 17)
|
if (ent.classnum != 0)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid entity");
|
throw std::runtime_error("Invalid entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::g_entities[ent.entnum].client == nullptr)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Not a player entity");
|
||||||
|
}
|
||||||
|
|
||||||
userinfo_overrides[ent.entnum]["clantag"] = "";
|
userinfo_overrides[ent.entnum]["clantag"] = "";
|
||||||
userinfo_overrides[ent.entnum]["ec_TagText"] = "";
|
userinfo_overrides[ent.entnum]["ec_TagText"] = "";
|
||||||
userinfo_overrides[ent.entnum]["ec_usingTag"] = "0";
|
userinfo_overrides[ent.entnum]["ec_usingTag"] = "0";
|
||||||
|
@ -1,20 +1,27 @@
|
|||||||
#include <stdinc.hpp>
|
#include <stdinc.hpp>
|
||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
#include "component/signatures.hpp"
|
||||||
|
|
||||||
|
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/)
|
||||||
{
|
{
|
||||||
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
|
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
|
||||||
{
|
{
|
||||||
const auto value = *reinterpret_cast<DWORD*>(0x20800000);
|
if (!signatures::process())
|
||||||
if (value != 0xB9C9566)
|
|
||||||
{
|
{
|
||||||
printf("\x1b[31m\n**************************************************************************************\n\n");
|
MessageBoxA(NULL,
|
||||||
printf("This version of \x1b[33miw5-gsc-utils\x1b[31m is outdated.\n");
|
"This version of iw5-gsc-utils is outdated.\n" \
|
||||||
printf("Download the latest dll from here:\x1b[34m https://github.com/fedddddd/iw5-gsc-utils/releases \x1b[31m\n");
|
"Download the latest dll from here: https://github.com/fedddddd/iw5-gsc-utils/releases",
|
||||||
printf("\n**************************************************************************************\n\n\x1b[37m");
|
"ERROR", MB_ICONERROR);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (game::plutonium::printf.get() != nullptr)
|
||||||
|
{
|
||||||
|
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), game::plutonium::printf);
|
||||||
|
}
|
||||||
|
|
||||||
component_loader::post_unpack();
|
component_loader::post_unpack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,5 +2,11 @@
|
|||||||
|
|
||||||
namespace game
|
namespace game
|
||||||
{
|
{
|
||||||
|
void SV_GameDropClient(int clientNum, const char* reason)
|
||||||
|
{
|
||||||
|
if (clientNum >= 0 && clientNum < sv_maxclients->current.integer)
|
||||||
|
{
|
||||||
|
SV_DropClient(&svs_clients[clientNum], reason, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,11 @@ namespace game
|
|||||||
return dedi_;
|
return dedi_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set(const size_t dedi)
|
||||||
|
{
|
||||||
|
this->dedi_ = reinterpret_cast<T*>(dedi);
|
||||||
|
}
|
||||||
|
|
||||||
operator T* () const
|
operator T* () const
|
||||||
{
|
{
|
||||||
return this->get();
|
return this->get();
|
||||||
@ -29,6 +34,8 @@ namespace game
|
|||||||
private:
|
private:
|
||||||
T* dedi_;
|
T* dedi_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void SV_GameDropClient(int clientNum, const char* reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "symbols.hpp"
|
#include "symbols.hpp"
|
@ -60,13 +60,11 @@ namespace scripting
|
|||||||
array::array()
|
array::array()
|
||||||
{
|
{
|
||||||
this->id_ = make_array();
|
this->id_ = make_array();
|
||||||
this->add();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
array::array(std::vector<script_value> values)
|
array::array(std::vector<script_value> values)
|
||||||
{
|
{
|
||||||
this->id_ = make_array();
|
this->id_ = make_array();
|
||||||
this->add();
|
|
||||||
|
|
||||||
for (const auto& value : values)
|
for (const auto& value : values)
|
||||||
{
|
{
|
||||||
@ -77,7 +75,6 @@ namespace scripting
|
|||||||
array::array(std::unordered_map<std::string, script_value> values)
|
array::array(std::unordered_map<std::string, script_value> values)
|
||||||
{
|
{
|
||||||
this->id_ = make_array();
|
this->id_ = make_array();
|
||||||
this->add();
|
|
||||||
|
|
||||||
for (const auto& value : values)
|
for (const auto& value : values)
|
||||||
{
|
{
|
||||||
@ -266,11 +263,9 @@ namespace scripting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void array::set(const std::string& key, const script_value& _value) const
|
void array::set(const std::string& key, const script_value& value_) const
|
||||||
{
|
{
|
||||||
const auto value = _value.get_raw();
|
const auto value = value_.get_raw();
|
||||||
|
|
||||||
const auto string_value = game::SL_GetString(key.data(), 0);
|
|
||||||
const auto variable_id = this->get_value_id(key);
|
const auto variable_id = this->get_value_id(key);
|
||||||
|
|
||||||
if (!variable_id)
|
if (!variable_id)
|
||||||
@ -287,9 +282,9 @@ namespace scripting
|
|||||||
variable->u.u = value.u;
|
variable->u.u = value.u;
|
||||||
}
|
}
|
||||||
|
|
||||||
void array::set(const unsigned int index, const script_value& _value) const
|
void array::set(const unsigned int index, const script_value& value_) const
|
||||||
{
|
{
|
||||||
const auto value = _value.get_raw();
|
const auto value = value_.get_raw();
|
||||||
const auto variable_id = this->get_value_id(index);
|
const auto variable_id = this->get_value_id(index);
|
||||||
|
|
||||||
if (!variable_id)
|
if (!variable_id)
|
||||||
|
@ -269,8 +269,6 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
return get_custom_field(entity, field);
|
return get_custom_field(entity, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int make_array()
|
unsigned int make_array()
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -7,10 +7,10 @@ namespace scripting
|
|||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, unsigned> lowercase_map(
|
std::unordered_map<std::string, uint16_t> lowercase_map(
|
||||||
const std::unordered_map<std::string, unsigned>& old_map)
|
const std::unordered_map<std::string, uint16_t>& old_map)
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, unsigned> new_map{};
|
std::unordered_map<std::string, uint16_t> new_map{};
|
||||||
for (auto& entry : old_map)
|
for (auto& entry : old_map)
|
||||||
{
|
{
|
||||||
new_map[utils::string::to_lower(entry.first)] = entry.second;
|
new_map[utils::string::to_lower(entry.first)] = entry.second;
|
||||||
@ -19,15 +19,15 @@ namespace scripting
|
|||||||
return new_map;
|
return new_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::unordered_map<std::string, unsigned>& get_methods()
|
const std::unordered_map<std::string, uint16_t>& get_methods()
|
||||||
{
|
{
|
||||||
static auto methods = lowercase_map(method_map);
|
static auto methods = lowercase_map(*game::plutonium::method_map_rev);
|
||||||
return methods;
|
return methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::unordered_map<std::string, unsigned>& get_functions()
|
const std::unordered_map<std::string, uint16_t>& get_functions()
|
||||||
{
|
{
|
||||||
static auto function = lowercase_map(function_map);
|
static auto function = lowercase_map(*game::plutonium::function_map_rev);
|
||||||
return function;
|
return function;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,8 +59,8 @@ namespace scripting
|
|||||||
|
|
||||||
script_function get_function_by_index(const unsigned index)
|
script_function get_function_by_index(const unsigned index)
|
||||||
{
|
{
|
||||||
static const auto function_table = 0x20689DD8;
|
static const auto function_table = game::plutonium::function_table.get();
|
||||||
static const auto method_table = 0x2068A5A8;
|
static const auto method_table = game::plutonium::method_table.get();
|
||||||
|
|
||||||
if (index < 0x1C7)
|
if (index < 0x1C7)
|
||||||
{
|
{
|
||||||
@ -71,8 +71,23 @@ namespace scripting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string find_file(unsigned int id)
|
||||||
|
{
|
||||||
|
const auto& file_map = *game::plutonium::file_map_rev;
|
||||||
|
for (const auto& file : file_map)
|
||||||
|
{
|
||||||
|
if (file.second == id)
|
||||||
|
{
|
||||||
|
return file.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::string find_token(unsigned int id)
|
std::string find_token(unsigned int id)
|
||||||
{
|
{
|
||||||
|
const auto& token_map = *game::plutonium::token_map_rev;
|
||||||
for (const auto& token : token_map)
|
for (const auto& token : token_map)
|
||||||
{
|
{
|
||||||
if (token.second == id)
|
if (token.second == id)
|
||||||
@ -86,6 +101,7 @@ namespace scripting
|
|||||||
|
|
||||||
int find_token_id(const std::string& name)
|
int find_token_id(const std::string& name)
|
||||||
{
|
{
|
||||||
|
const auto& token_map = *game::plutonium::token_map_rev;
|
||||||
const auto result = token_map.find(name);
|
const auto result = token_map.find(name);
|
||||||
|
|
||||||
if (result != token_map.end())
|
if (result != token_map.end())
|
||||||
|
@ -3,14 +3,10 @@
|
|||||||
|
|
||||||
namespace scripting
|
namespace scripting
|
||||||
{
|
{
|
||||||
extern std::unordered_map<std::string, unsigned> method_map;
|
|
||||||
extern std::unordered_map<std::string, unsigned> function_map;
|
|
||||||
extern std::unordered_map<std::string, unsigned> token_map;
|
|
||||||
extern std::unordered_map<unsigned, std::string> file_list;
|
|
||||||
|
|
||||||
using script_function = void(*)(game::scr_entref_t);
|
using script_function = void(*)(game::scr_entref_t);
|
||||||
|
|
||||||
script_function find_function(const std::string& name, const bool prefer_global);
|
script_function find_function(const std::string& name, const bool prefer_global);
|
||||||
int find_token_id(const std::string& name);
|
int find_token_id(const std::string& name);
|
||||||
std::string find_token(unsigned int id);
|
std::string find_token(unsigned int id);
|
||||||
|
std::string find_file(unsigned int id);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace scripting::safe_execution
|
|||||||
bool call(const script_function function, const game::scr_entref_t& entref)
|
bool call(const script_function function, const game::scr_entref_t& entref)
|
||||||
{
|
{
|
||||||
*game::g_script_error_level += 1;
|
*game::g_script_error_level += 1;
|
||||||
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level]))
|
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
|
||||||
{
|
{
|
||||||
*game::g_script_error_level -= 1;
|
*game::g_script_error_level -= 1;
|
||||||
return false;
|
return false;
|
||||||
@ -39,7 +39,7 @@ namespace scripting::safe_execution
|
|||||||
bool set_entity_field(const game::scr_entref_t& entref, const int offset)
|
bool set_entity_field(const game::scr_entref_t& entref, const int offset)
|
||||||
{
|
{
|
||||||
*game::g_script_error_level += 1;
|
*game::g_script_error_level += 1;
|
||||||
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level]))
|
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
|
||||||
{
|
{
|
||||||
*game::g_script_error_level -= 1;
|
*game::g_script_error_level -= 1;
|
||||||
return false;
|
return false;
|
||||||
@ -54,7 +54,7 @@ namespace scripting::safe_execution
|
|||||||
bool get_entity_field(const game::scr_entref_t& entref, const int offset, game::VariableValue* value)
|
bool get_entity_field(const game::scr_entref_t& entref, const int offset, game::VariableValue* value)
|
||||||
{
|
{
|
||||||
*game::g_script_error_level += 1;
|
*game::g_script_error_level += 1;
|
||||||
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level]))
|
if (game::_setjmp(&game::g_script_error[*game::g_script_error_level], 0, 0, 0))
|
||||||
{
|
{
|
||||||
value->type = game::SCRIPT_NONE;
|
value->type = game::SCRIPT_NONE;
|
||||||
value->u.intValue = 0;
|
value->u.intValue = 0;
|
||||||
|
@ -82,6 +82,11 @@ namespace scripting
|
|||||||
return "array";
|
return "array";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info == typeid(function))
|
||||||
|
{
|
||||||
|
return "function";
|
||||||
|
}
|
||||||
|
|
||||||
if (info == typeid(vector))
|
if (info == typeid(vector))
|
||||||
{
|
{
|
||||||
return "vector";
|
return "vector";
|
||||||
|
@ -26,20 +26,35 @@ namespace game
|
|||||||
const char** argv[8];
|
const char** argv[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum netsrc_t
|
||||||
|
{
|
||||||
|
NS_CLIENT1 = 0x0,
|
||||||
|
NS_CLIENT2 = 0x1,
|
||||||
|
NS_CLIENT3 = 0x2,
|
||||||
|
NS_CLIENT4 = 0x3,
|
||||||
|
NS_MAXCLIENTS = 0x4,
|
||||||
|
NS_SERVER = 0x4,
|
||||||
|
NS_PACKET = 0x5,
|
||||||
|
NS_INVALID_NETSRC = 0x6
|
||||||
|
};
|
||||||
|
|
||||||
struct msg_t
|
struct msg_t
|
||||||
{
|
{
|
||||||
int overflowed;
|
int overflowed;
|
||||||
int readOnly;
|
int readOnly;
|
||||||
char* data;
|
unsigned char* data;
|
||||||
char* splitData;
|
unsigned char* splitData;
|
||||||
int maxsize;
|
int maxsize;
|
||||||
int cursize;
|
int cursize;
|
||||||
int splitSize;
|
int splitSize;
|
||||||
int readcount;
|
int readcount;
|
||||||
int bit;
|
int bit;
|
||||||
int lastEntityRef;
|
int lastEntityRef;
|
||||||
|
netsrc_t targetLocalNetID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(msg_t) == 0x2C);
|
||||||
|
|
||||||
struct XZoneInfo
|
struct XZoneInfo
|
||||||
{
|
{
|
||||||
const char* name;
|
const char* name;
|
||||||
@ -327,4 +342,88 @@ namespace game
|
|||||||
int flags;
|
int flags;
|
||||||
char __pad2[0xEC];
|
char __pad2[0xEC];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum netadrtype_t
|
||||||
|
{
|
||||||
|
NA_BOT = 0x0,
|
||||||
|
NA_BAD = 0x1,
|
||||||
|
NA_LOOPBACK = 0x2,
|
||||||
|
NA_BROADCAST = 0x3,
|
||||||
|
NA_IP = 0x4
|
||||||
|
};
|
||||||
|
|
||||||
|
struct netadr_s
|
||||||
|
{
|
||||||
|
netadrtype_t type;
|
||||||
|
unsigned char ip[4];
|
||||||
|
unsigned __int16 port;
|
||||||
|
unsigned char ipx[10];
|
||||||
|
unsigned int addrHandleIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(netadr_s) == 24);
|
||||||
|
|
||||||
|
struct netchan_t
|
||||||
|
{
|
||||||
|
int outgoingSequence;
|
||||||
|
netsrc_t sock;
|
||||||
|
int dropped;
|
||||||
|
int incomingSequence;
|
||||||
|
netadr_s remoteAddress;
|
||||||
|
int qport;
|
||||||
|
int fragmentSequence;
|
||||||
|
int fragmentLength;
|
||||||
|
unsigned char* fragmentBuffer;
|
||||||
|
int fragmentBufferSize;
|
||||||
|
int unsentFragments;
|
||||||
|
int unsentFragmentStart;
|
||||||
|
int unsentLength;
|
||||||
|
unsigned char* unsentBuffer;
|
||||||
|
int unsentBufferSize;
|
||||||
|
unsigned char __pad0[0x5E0];
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(netchan_t) == 0x630);
|
||||||
|
|
||||||
|
enum clientState_t
|
||||||
|
{
|
||||||
|
CS_FREE = 0,
|
||||||
|
CS_ZOMBIE = 1,
|
||||||
|
CS_RECONNECTING = 2,
|
||||||
|
CS_CONNECTED = 3,
|
||||||
|
CS_CLIENTLOADING = 4,
|
||||||
|
CS_ACTIVE = 5
|
||||||
|
};
|
||||||
|
|
||||||
|
struct clientHeader_t
|
||||||
|
{
|
||||||
|
clientState_t state; // 0
|
||||||
|
int sendAsActive; // 4
|
||||||
|
int deltaMessage; // 8
|
||||||
|
int rateDealyed; // 12
|
||||||
|
int hasAckedBaselineData; // 16
|
||||||
|
int hugeSnapshotSent; // 20
|
||||||
|
netchan_t netchan; // 24
|
||||||
|
vec3_t predictedOrigin;
|
||||||
|
int predictedOriginServerTime;
|
||||||
|
int migrationState;
|
||||||
|
vec3_t predictedVehicleOrigin;
|
||||||
|
int predictedVehicleServerTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(clientHeader_t) == 0x66C);
|
||||||
|
|
||||||
|
struct client_s
|
||||||
|
{
|
||||||
|
clientHeader_t header;
|
||||||
|
const char* dropReason;
|
||||||
|
char userinfo[1024];
|
||||||
|
char __pad0[0x41242];
|
||||||
|
unsigned __int16 scriptId; // 269490
|
||||||
|
int bIsTestClient; // 269492
|
||||||
|
int serverId; // 269496
|
||||||
|
char __pad1[0x369DC];
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(client_s) == 0x78698);
|
||||||
}
|
}
|
@ -57,12 +57,13 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<void(int clientNum, int type, const char* command)> SV_GameSendServerCommand{0x573220};
|
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(int arg, char* buffer, int bufferLength)> SV_Cmd_ArgvBuffer{0x5459F0};
|
||||||
|
WEAK symbol<void(client_s* drop, const char* reason, bool tellThem)> SV_DropClient{0x570980};
|
||||||
|
|
||||||
WEAK symbol<void(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top)> VM_Notify{0x569720};
|
WEAK symbol<void(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top)> VM_Notify{0x569720};
|
||||||
WEAK symbol<unsigned int(unsigned int localId, const char* pos, unsigned int paramcount)> VM_Execute{0x56DFE0};
|
WEAK symbol<unsigned int(unsigned int localId, const char* pos, unsigned int paramcount)> VM_Execute{0x56DFE0};
|
||||||
|
|
||||||
WEAK symbol<void* (jmp_buf* Buf, int Value)> longjmp{0x7363BC};
|
WEAK symbol<void* (jmp_buf* Buf, int Value)> longjmp{0x7363BC};
|
||||||
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x734CF8};
|
WEAK symbol<int(jmp_buf* Buf, int a2, int a3, int a4)> _setjmp{0x734CF8};
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
|
||||||
@ -79,10 +80,18 @@ namespace game
|
|||||||
WEAK symbol<gentity_s> g_entities{0x1A66E28};
|
WEAK symbol<gentity_s> g_entities{0x1A66E28};
|
||||||
WEAK symbol<unsigned int> levelEntityId{0x208E1A4};
|
WEAK symbol<unsigned int> levelEntityId{0x208E1A4};
|
||||||
|
|
||||||
|
WEAK symbol<dvar_t> sv_maxclients{0x1BA0E4C};
|
||||||
|
WEAK symbol<int> svs_clientCount{0x4B5CF8C};
|
||||||
|
WEAK symbol<client_s> svs_clients{0x4B5CF90};
|
||||||
|
|
||||||
namespace plutonium
|
namespace plutonium
|
||||||
{
|
{
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> function_map_rev{0x20691228};
|
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> function_map_rev{0};
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> method_map_rev{0x20691248};
|
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> method_map_rev{0};
|
||||||
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0x20691288};
|
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> file_map_rev{0};
|
||||||
|
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0};
|
||||||
|
WEAK symbol<int(const char* fmt, ...)> printf{0};
|
||||||
|
WEAK symbol<void*> function_table{0};
|
||||||
|
WEAK symbol<void*> method_table{0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <csetjmp>
|
#include <csetjmp>
|
||||||
#include <atlcomcli.h>
|
#include <atlcomcli.h>
|
||||||
|
#include <Psapi.h>
|
||||||
|
|
||||||
#pragma comment(lib, "urlmon.lib")
|
#pragma comment(lib, "urlmon.lib")
|
||||||
|
|
||||||
|
@ -4,6 +4,48 @@
|
|||||||
|
|
||||||
namespace utils::hook
|
namespace utils::hook
|
||||||
{
|
{
|
||||||
|
// open-iw5
|
||||||
|
|
||||||
|
void signature::process()
|
||||||
|
{
|
||||||
|
if (this->signatures_.empty()) return;
|
||||||
|
|
||||||
|
const auto start = static_cast<char*>(this->start_);
|
||||||
|
|
||||||
|
const unsigned int sig_count = this->signatures_.size();
|
||||||
|
const auto containers = this->signatures_.data();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < this->length_; ++i)
|
||||||
|
{
|
||||||
|
const auto address = start + i;
|
||||||
|
|
||||||
|
for (unsigned int k = 0; k < sig_count; ++k)
|
||||||
|
{
|
||||||
|
const auto container = &containers[k];
|
||||||
|
|
||||||
|
unsigned int j;
|
||||||
|
for (j = 0; j < static_cast<unsigned int>(container->mask.size()); ++j)
|
||||||
|
{
|
||||||
|
if (container->mask[j] != '?' && container->signature[j] != address[j])
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j == container->mask.size())
|
||||||
|
{
|
||||||
|
container->callback(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void signature::add(const container& container)
|
||||||
|
{
|
||||||
|
signatures_.push_back(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
[[maybe_unused]] class _
|
[[maybe_unused]] class _
|
||||||
|
@ -4,6 +4,37 @@
|
|||||||
|
|
||||||
namespace utils::hook
|
namespace utils::hook
|
||||||
{
|
{
|
||||||
|
class signature final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct container final
|
||||||
|
{
|
||||||
|
std::string signature;
|
||||||
|
std::string mask;
|
||||||
|
std::function<void(char*)> callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
signature(void* start, const size_t length) : start_(start), length_(length)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
signature(const DWORD start, const size_t length) : signature(reinterpret_cast<void*>(start), length)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
signature() : signature(0x400000, 0x800000)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void process();
|
||||||
|
void add(const container& container);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void* start_;
|
||||||
|
size_t length_;
|
||||||
|
std::vector<container> signatures_;
|
||||||
|
};
|
||||||
|
|
||||||
class detour
|
class detour
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user