29 Commits

Author SHA1 Message Date
fed
3a492f51d9 Update functions.cpp 2023-02-27 01:24:02 +01:00
fed
d4ba37cde5 Remove this 2023-02-27 01:20:58 +01:00
fed
2ded4c6a2a Small fix 2023-02-27 01:20:08 +01:00
fed
24b3a9369e Fixes for pluto update 2023-02-27 01:18:50 +01:00
fed
1d94fdd88d Small fix 2022-12-28 01:07:53 +01:00
0af6b1cb13 Fix for update 2022-07-12 22:12:53 +02:00
d72c6f7057 Fix #16 2022-03-27 23:42:47 +02:00
39b9e7e352 Small change 2022-03-26 20:03:42 +01:00
36fefa6bb5 Remove this 2022-03-26 20:01:21 +01:00
4ffdb331b4 Use signature utils 2022-03-26 19:51:51 +01:00
7b995b3348 Add some string functions 2022-03-26 00:05:02 +01:00
14d0f401fb vs2022 build 2022-03-18 01:17:28 +01:00
df23604b1e Update pointers 2022-03-17 19:23:52 +01:00
fed
e2960bc895 Merge pull request #14 from diamante0018/main
Update Premake5, fix git modules.
2022-02-26 12:13:25 +01:00
db90d361a9 tabs 2022-02-26 11:12:55 +00:00
6ec0c5e23c .git 2022-02-26 11:00:11 +00:00
c84d681a3a Re add unfricked json 2022-02-26 10:58:51 +00:00
62d1c8671b Re add unfricked json 2022-02-26 10:58:41 +00:00
877adfa4b6 Fix json 2022-02-26 10:54:43 +00:00
12fd44d0da New gsc func + premake5 update 2022-02-26 10:51:20 +00:00
fed
12562eb8fd Merge pull request #13 from diamante0018/main
Clean up gsc functions with additional checks
2022-02-25 12:04:16 +01:00
286481cbcd Clean up gsc functions with additional checks 2022-02-24 19:25:58 +00:00
e9a877bd74 Update dllmain.cpp 2022-02-11 19:35:46 +01:00
3060df1f05 Update pointers 2022-02-07 02:00:15 +01:00
fed
aa1ae8c574 Merge pull request #12 from diamante0018/main 2022-02-02 15:25:52 +01:00
ccd8176c25 Remove assert 2022-02-02 15:24:20 +01:00
c230a1d916 Remove incorrect offset comments 2022-02-02 12:47:46 +01:00
2785a60dc0 Add function drop all bots 2022-02-02 12:45:07 +01:00
1b65bda323 Update pointers 2022-01-29 16:37:04 +01:00
28 changed files with 518 additions and 7580 deletions

7
.gitmodules vendored
View File

@ -4,12 +4,7 @@
[submodule "deps/GSL"]
path = deps/GSL
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"]
path = deps/json
url = https://github.com/nlohmann/json.git
branch = develop

2
deps/json vendored

Submodule deps/json updated: e10a3fac8a...e4643d1f1b

View File

@ -1,2 +1,3 @@
@echo off
tools\windows\premake5.exe vs2019
call git submodule update --init --recursive
tools\windows\premake5.exe vs2022

View File

@ -36,32 +36,35 @@ workspace "iw5-gsc-utils"
targetdir "%{wks.location}/bin/%{cfg.buildcfg}"
targetname "%{prj.name}"
configurations { "Debug", "Release", }
language "C++"
cppdialect "C++20"
architecture "x86"
buildoptions "/std:c++latest"
systemversion "latest"
symbols "On"
staticruntime "On"
editandcontinue "Off"
warnings "Extra"
characterset "ASCII"
flags
{
"NoIncrementalLink",
"MultiProcessorCompile",
}
configurations { "Debug", "Release", }
symbols "On"
configuration "Release"
filter "configurations:Release"
optimize "Full"
defines { "NDEBUG" }
configuration{}
filter {}
configuration "Debug"
filter "configurations:Debug"
optimize "Debug"
defines { "DEBUG", "_DEBUG" }
configuration {}
filter {}
startproject "iw5-gsc-utils"

View File

@ -49,6 +49,7 @@ namespace command
if (i > index) result.append(" ");
result.append(this->get(i));
}
return result;
}
@ -96,7 +97,6 @@ namespace command
public:
void post_unpack() override
{
}
};
}

View File

@ -21,13 +21,13 @@ namespace gsc
{
std::string method_name(unsigned int id)
{
const auto map = *game::plutonium::method_map_rev;
const auto& map = *game::plutonium::method_map_rev;
for (const auto& function : map)
{
if (function.second == id)
{
return function.first;
return function.first.data();
}
}
@ -36,13 +36,13 @@ namespace gsc
std::string function_name(unsigned int id)
{
const auto map = *game::plutonium::function_map_rev;
const auto& map = *game::plutonium::function_map_rev;
for (const auto& function : map)
{
if (function.second == id)
{
return function.first;
return function.first.data();
}
}
@ -53,8 +53,6 @@ namespace gsc
{
std::vector<scripting::script_value> args;
const auto top = game::scr_VmPub->top;
for (auto i = 0; i < game::scr_VmPub->outparamcount; i++)
{
const auto value = game::scr_VmPub->top[-i];
@ -194,7 +192,7 @@ namespace gsc
return scr_get_object_field_hook.invoke<void>(classnum, entnum, offset);
}
const auto field = custom_fields[classnum][offset];
const auto& field = custom_fields[classnum][offset];
try
{
@ -219,7 +217,7 @@ namespace gsc
}
const auto args = get_arguments();
const auto field = custom_fields[classnum][offset];
const auto& field = custom_fields[classnum][offset];
try
{
@ -253,7 +251,8 @@ namespace gsc
const auto index = function_map_start++;
functions[index] = func;
(*game::plutonium::function_map_rev)[name] = index;
const auto name_view = utils::memory::get_allocator()->duplicate_string(name);
(*game::plutonium::function_map_rev)[name_view] = index;
}
}
@ -264,7 +263,8 @@ namespace gsc
const auto index = method_map_start++;
methods[index] = func;
(*game::plutonium::method_map_rev)[name] = index;
const auto name_view = utils::memory::get_allocator()->duplicate_string(name);
(*game::plutonium::method_map_rev)[name_view] = index;
}
}
@ -274,11 +274,20 @@ namespace gsc
const std::function<scripting::script_value(unsigned int entnum)>& getter,
const std::function<void(unsigned int entnum, const scripting::script_value&)>& setter)
{
const auto token_id = token_map_start++;
const auto offset = field_offset_start++;
uint16_t token_id{};
auto& token_map = *game::plutonium::token_map_rev;
if (token_map.find(name) != token_map.end())
{
token_id = token_map.at(name);
}
else
{
token_id = token_map_start++;
token_map.insert(std::make_pair(name, token_id));
}
const auto offset = field_offset_start++;
custom_fields[classnum][offset] = {name, getter, setter};
(*game::plutonium::token_map_rev)[name] = token_id;
post_load_callbacks.push_back([classnum, name, token_id, offset]()
{
@ -322,7 +331,7 @@ namespace gsc
scr_set_object_field_hook.create(0x52BCC0, scr_set_object_field_stub);
scr_post_load_scripts_hook.create(0x628B50, scr_post_load_scripts_stub);
field::add(classid::entity, "flags",
field::add(classid::entity, "entityflags",
[](unsigned int entnum) -> scripting::script_value
{
const auto entity = &game::g_entities[entnum];
@ -380,6 +389,20 @@ namespace gsc
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
{
if (ent.classnum != 0)
@ -388,8 +411,13 @@ namespace gsc
}
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()));
return {};
@ -402,21 +430,23 @@ namespace gsc
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>();
auto flags = game::g_entities[client].client->ps.perks[0];
auto g_client = game::g_entities[num].client;
auto playerState = &g_client->ps;
auto flags = playerState->perks[0];
playerState->perks[0] = toggle
? flags | 0x4000u
: flags & ~0x4000u;
game::g_entities[client].client->ps.perks[0] = toggle
? flags | 0x4000u : flags & ~0x4000u;
return {};
});
method::add("isbot", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value
method::add("isbot", [](const game::scr_entref_t ent, const function_args&) -> scripting::script_value
{
if (ent.classnum != 0)
{
@ -424,16 +454,38 @@ namespace gsc
}
const auto client = ent.entnum;
if (game::g_entities[client].client == nullptr)
{
throw std::runtime_error("entity is not a player");
throw std::runtime_error("Not a player entity");
}
return game::svs_clients[client].bIsTestClient;
});
utils::hook::jump(0x56C8EB, call_builtin_stub);
utils::hook::jump(0x56CBDC, call_builtin_method_stub);
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);
});
}
};
}

View File

@ -14,7 +14,13 @@ namespace notifies
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);

View File

@ -95,7 +95,7 @@ namespace scripting
const auto file_id = atoi(filename);
if (file_id)
{
current_file = scripting::file_list[file_id];
current_file = scripting::find_file(file_id);
}
process_script_hook.invoke<void>(filename);

View File

@ -0,0 +1,98 @@
#include <stdinc.hpp>
#include "signatures.hpp"
#include <utils/hook.hpp>
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');
const auto base = reinterpret_cast<size_t>(GetModuleHandle("plutonium-bootstrapper-win32.exe"));
utils::hook::signature signature(base, get_image_size() - base);
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);
if (!string_ptr)
{
return 0;
}
std::memcpy(bytes, &string_ptr, sizeof(bytes));
return find_string_ptr({bytes, 4});
}
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 - 0x2B);
game::plutonium::function_map_rev.set(map_ptr);
game::plutonium::method_map_rev.set(map_ptr + 0x20);
game::plutonium::token_map_rev.set(map_ptr + 0xBC);
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();
return process_printf() && process_maps();
}
}

View File

@ -0,0 +1,6 @@
#pragma once
namespace signatures
{
bool process();
}

46
src/component/string.cpp Normal file
View 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)

View File

@ -92,26 +92,36 @@ namespace userinfo
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 || ent.entnum > 17)
if (ent.classnum != 0)
{
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;
game::ClientUserinfoChanged(ent.entnum);
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
{
if (ent.classnum != 0 || ent.entnum > 17)
if (ent.classnum != 0)
{
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");
game::ClientUserinfoChanged(ent.entnum);
@ -120,13 +130,18 @@ namespace userinfo
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 || ent.entnum > 17)
if (ent.classnum != 0)
{
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]["ec_TagText"] = name;
userinfo_overrides[ent.entnum]["ec_usingTag"] = "1";
@ -135,13 +150,18 @@ namespace userinfo
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
{
if (ent.classnum != 0 || ent.entnum > 17)
if (ent.classnum != 0)
{
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("ec_TagText");
userinfo_overrides[ent.entnum].erase("ec_usingTag");
@ -150,13 +170,18 @@ namespace userinfo
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");
}
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]["ec_TagText"] = "";
userinfo_overrides[ent.entnum]["ec_usingTag"] = "0";

View File

@ -1,22 +1,27 @@
#include <stdinc.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)
{
const auto value = *reinterpret_cast<DWORD*>(0x21000000);
if (value != 0x7AC6)
if (!signatures::process())
{
MessageBoxA(NULL,
"This version of iw5-gsc-utils is outdated.\n" \
"Download the latest dll from here: https://github.com/fedddddd/iw5-gsc-utils/releases" \
, "ERROR", MB_ICONERROR);
"Download the latest dll from here: https://github.com/fedddddd/iw5-gsc-utils/releases",
"ERROR", MB_ICONERROR);
return FALSE;
}
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), game::plutonium::printf);
if (game::plutonium::printf.get() != nullptr)
{
utils::hook::jump(reinterpret_cast<uintptr_t>(&printf), game::plutonium::printf);
}
component_loader::post_unpack();
}

View File

@ -2,5 +2,11 @@
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);
}
}
}

View File

@ -16,6 +16,11 @@ namespace game
return dedi_;
}
void set(const size_t dedi)
{
this->dedi_ = reinterpret_cast<T*>(dedi);
}
operator T* () const
{
return this->get();
@ -29,6 +34,8 @@ namespace game
private:
T* dedi_;
};
void SV_GameDropClient(int clientNum, const char* reason);
}
#include "symbols.hpp"

View File

@ -263,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 string_value = game::SL_GetString(key.data(), 0);
const auto value = value_.get_raw();
const auto variable_id = this->get_value_id(key);
if (!variable_id)
@ -284,9 +282,9 @@ namespace scripting
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);
if (!variable_id)

View File

@ -269,8 +269,6 @@ namespace scripting
{
return get_custom_field(entity, field);
}
return {};
}
unsigned int make_array()

File diff suppressed because it is too large Load Diff

View File

@ -7,27 +7,27 @@ namespace scripting
{
namespace
{
std::unordered_map<std::string, unsigned> lowercase_map(
const std::unordered_map<std::string, unsigned>& old_map)
std::unordered_map<std::string, uint16_t> lowercase_map(
const std::unordered_map<std::string_view, 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)
{
new_map[utils::string::to_lower(entry.first)] = entry.second;
new_map[utils::string::to_lower(entry.first.data())] = entry.second;
}
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;
}
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;
}
@ -73,6 +73,7 @@ namespace scripting
std::string find_token(unsigned int id)
{
const auto& token_map = *game::plutonium::token_map_rev;
for (const auto& token : token_map)
{
if (token.second == id)
@ -84,8 +85,14 @@ namespace scripting
return {};
}
std::string find_file(unsigned int id)
{
return find_token(id);
}
int find_token_id(const std::string& name)
{
const auto& token_map = *game::plutonium::token_map_rev;
const auto result = token_map.find(name);
if (result != token_map.end())

View File

@ -3,14 +3,10 @@
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);
script_function find_function(const std::string& name, const bool prefer_global);
int find_token_id(const std::string& name);
std::string find_token(unsigned int id);
std::string find_file(unsigned int id);
}

View File

@ -26,20 +26,35 @@ namespace game
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
{
int overflowed;
int readOnly;
char* data;
char* splitData;
unsigned char* data;
unsigned char* splitData;
int maxsize;
int cursize;
int splitSize;
int readcount;
int bit;
int lastEntityRef;
netsrc_t targetLocalNetID;
};
static_assert(sizeof(msg_t) == 0x2C);
struct XZoneInfo
{
const char* name;
@ -328,9 +343,82 @@ namespace game
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
{
char __pad0[0x41CB2];
clientHeader_t header;
const char* dropReason;
char userinfo[1024];
char __pad0[0x41242];
unsigned __int16 scriptId; // 269490
int bIsTestClient; // 269492
int serverId; // 269496

View File

@ -57,6 +57,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(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<unsigned int(unsigned int localId, const char* pos, unsigned int paramcount)> VM_Execute{0x56DFE0};
@ -79,15 +80,17 @@ namespace game
WEAK symbol<gentity_s> g_entities{0x1A66E28};
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
{
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> function_map_rev{0x206964D0};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> method_map_rev{0x206964F0};
WEAK symbol<std::unordered_map<std::string, std::uint16_t>> token_map_rev{0x20696530};
WEAK symbol<int(const char* fmt, ...)> printf{0x20887840};
WEAK symbol<void*> function_table{0x2068F210};
WEAK symbol<void*> method_table{0x2068F9E0};
WEAK symbol<std::unordered_map<std::string_view, std::uint16_t>> function_map_rev{0};
WEAK symbol<std::unordered_map<std::string_view, std::uint16_t>> method_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};
}
}
}

View File

@ -28,6 +28,7 @@
#include <map>
#include <csetjmp>
#include <atlcomcli.h>
#include <Psapi.h>
#pragma comment(lib, "urlmon.lib")

View File

@ -4,6 +4,48 @@
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
{
[[maybe_unused]] class _

View File

@ -4,6 +4,37 @@
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
{
public:

View File

@ -1,8 +1,14 @@
#include <stdinc.hpp>
#include <fstream>
#include "io.hpp"
namespace utils::io
{
bool remove_file(const std::string& file)
{
return DeleteFileA(file.data()) == TRUE;
}
bool file_exists(const std::string& file)
{
return std::ifstream(file).good();

View File

@ -6,6 +6,7 @@
namespace utils::io
{
bool remove_file(const std::string& file);
bool file_exists(const std::string& file);
bool write_file(const std::string& file, const std::string& data, bool append = false);
bool read_file(const std::string& file, std::string* data);

Binary file not shown.