Cleanup, use component loader, fps component

This commit is contained in:
Federico Cecchetto 2021-04-23 20:57:21 +02:00
parent eadd83551a
commit 457605c2b2
27 changed files with 558 additions and 298 deletions

View File

@ -1,15 +1,16 @@
#include <stdinc.hpp>
#include "chat.hpp"
#include "scheduler.hpp"
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "chat.hpp"
#include "scheduler.hpp"
#include <utils/string.hpp>
#include <utils/hook.hpp>
#define chat_font game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25)
#define material_white game::Material_RegisterHandle("white")
namespace chat
{
@ -78,11 +79,17 @@ namespace chat
history.push_front(m);
}
void init()
class component final : public component_interface
{
scheduler::loop([]()
public:
void post_unpack() override
{
draw_chat();
}, scheduler::pipeline::renderer);
}
}
scheduler::loop([]()
{
draw_chat();
}, scheduler::pipeline::renderer);
}
};
}
REGISTER_COMPONENT(chat::component)

View File

@ -3,6 +3,4 @@
namespace chat
{
void print(const std::string& msg);
void init();
}

View File

@ -1,7 +1,12 @@
#include <stdinc.hpp>
#include "command.hpp"
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "command.hpp"
#include "game_console.hpp"
#include "chat.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
@ -142,137 +147,77 @@ namespace command
}
}
void init()
class component final : public component_interface
{
utils::hook::jump(game::base_address + 0x5A74F0, dvar_command_stub, true);
add("say", [](const params& params)
public:
void post_unpack() override
{
chat::print(params.join(1));
});
utils::hook::jump(game::base_address + 0x5A74F0, dvar_command_stub, true);
add("listassetpool", [](const params& params)
{
if (params.size() < 2)
add("say", [](const params& params)
{
game_console::print(game_console::con_type_info, "listassetpool <poolnumber>: list all the assets in the specified pool\n");
chat::print(params.join(1));
});
for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++)
add("listassetpool", [](const params& params)
{
if (params.size() < 2)
{
game_console::print(game_console::con_type_info, "%d %s\n", i, game::g_assetNames[i]);
game_console::print(game_console::con_type_info, "listassetpool <poolnumber>: list all the assets in the specified pool\n");
for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++)
{
game_console::print(game_console::con_type_info, "%d %s\n", i, game::g_assetNames[i]);
}
}
}
else
{
const auto type = static_cast<game::XAssetType>(atoi(params.get(1)));
if (type < 0 || type >= game::XAssetType::ASSET_TYPE_COUNT)
else
{
game_console::print(game_console::con_type_info, "Invalid pool passed must be between [%d, %d]\n", 0, game::XAssetType::ASSET_TYPE_COUNT - 1);
return;
const auto type = static_cast<game::XAssetType>(atoi(params.get(1)));
if (type < 0 || type >= game::XAssetType::ASSET_TYPE_COUNT)
{
game_console::print(game_console::con_type_info, "Invalid pool passed must be between [%d, %d]\n", 0, game::XAssetType::ASSET_TYPE_COUNT - 1);
return;
}
game_console::print(game_console::con_type_info, "Listing assets in pool %s\n", game::g_assetNames[type]);
enum_assets(type, [type](const game::XAssetHeader header)
{
const auto asset = game::XAsset{ type, header };
const auto* const asset_name = game::DB_GetXAssetName(&asset);
//const auto entry = game::DB_FindXAssetEntry(type, asset_name);
//TODO: display which zone the asset is from
game_console::print(game_console::con_type_info, "%s\n", asset_name);
}, true);
}
});
add("baseAddress", []()
{
printf("%p\n", (void*)game::base_address);
});
add("commandDump", []()
{
printf("======== Start command dump =========\n");
game::cmd_function_s* cmd = (*game::cmd_functions);
while (cmd)
{
if (cmd->name)
{
game_console::print(game_console::con_type_info, "%s\n", cmd->name);
}
cmd = cmd->next;
}
game_console::print(game_console::con_type_info, "Listing assets in pool %s\n", game::g_assetNames[type]);
enum_assets(type, [type](const game::XAssetHeader header)
{
const auto asset = game::XAsset{ type, header };
const auto* const asset_name = game::DB_GetXAssetName(&asset);
//const auto entry = game::DB_FindXAssetEntry(type, asset_name);
//TODO: display which zone the asset is from
game_console::print(game_console::con_type_info, "%s\n", asset_name);
}, true);
}
});
add("baseAddress", []()
{
printf("%p\n", (void*)game::base_address);
});
add("commandDump", []()
{
printf("======== Start command dump =========\n");
game::cmd_function_s* cmd = (*game::cmd_functions);
while (cmd)
{
if (cmd->name)
{
game_console::print(game_console::con_type_info, "%s\n", cmd->name);
}
cmd = cmd->next;
}
printf("======== End command dump =========\n");
});
/*add("noclip", [&]()
{
if (!game::SV_Loaded())
{
return;
}
game::sp::g_entities[0].client->flags ^= 1;
game::CG_GameMessage(0, utils::string::va("noclip %s",
game::sp::g_entities[0].client->flags & 1
? "^2on"
: "^1off"));
});
add("ufo", [&]()
{
if (!game::SV_Loaded())
{
return;
}
game::sp::g_entities[0].client->flags ^= 2;
game::CG_GameMessage(
0, utils::string::va("ufo %s", game::sp::g_entities[0].client->flags & 2 ? "^2on" : "^1off"));
});
add("give", [](const params& params)
{
if (!game::SV_Loaded())
{
return;
}
if (params.size() < 2)
{
game::CG_GameMessage(0, "You did not specify a weapon name");
return;
}
auto ps = game::SV_GetPlayerstateForClientNum(0);
auto wp = game::G_GetWeaponForName(params.get(1));
if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0))
{
game::G_InitializeAmmo(ps, wp, 0);
game::G_SelectWeapon(0, wp);
}
});
add("take", [](const params& params)
{
if (!game::SV_Loaded())
{
return;
}
if (params.size() < 2)
{
game::CG_GameMessage(0, "You did not specify a weapon name");
return;
}
auto ps = game::SV_GetPlayerstateForClientNum(0);
auto wp = game::G_GetWeaponForName(params.get(1));
game::G_TakePlayerWeapon(ps, wp);
});*/
}
printf("======== End command dump =========\n");
});
}
};
}
REGISTER_COMPONENT(command::component)

View File

@ -25,6 +25,4 @@ namespace command
void add(const char* name, const std::function<void()>& callback);
void execute(std::string command, bool sync = false);
void init();
}

62
src/component/fps.cpp Normal file
View File

@ -0,0 +1,62 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "chat.hpp"
#include "scheduler.hpp"
#include <utils/string.hpp>
#include <utils/hook.hpp>
#define fps_font game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25)
namespace fps
{
namespace
{
std::chrono::nanoseconds frametime;
auto lastframe = std::chrono::high_resolution_clock::now();
float fps_color_good[4] = { 0.6f, 1.0f, 0.0f, 1.0f };
float fps_color_ok[4] = { 1.0f, 0.7f, 0.3f, 1.0f };
float fps_color_bad[4] = { 1.0f, 0.3f, 0.3f, 1.0f };
float screen_max[2];
void check_resize()
{
screen_max[0] = game::ScrPlace_GetViewPlacement()->realViewportSize[0];
screen_max[1] = game::ScrPlace_GetViewPlacement()->realViewportSize[1];
}
void draw_fps()
{
check_resize();
const auto now = std::chrono::high_resolution_clock::now();
const auto frametime = now - lastframe;
lastframe = now;
const int fps = 1000000000 / frametime.count();
const auto fps_string = utils::string::va("%i", fps);
const auto x = screen_max[0] - 15.f - game::R_TextWidth(fps_string, 0x7FFFFFFF, fps_font);
game::R_AddCmdDrawText(fps_string, 0x7FFFFFFF, fps_font, x, 25.f, 1.0f, 1.0f, 0.0f,
fps >= 60 ? fps_color_good : (fps >= 30 ? fps_color_ok : fps_color_bad), 0);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
scheduler::loop(draw_fps, scheduler::pipeline::renderer);
}
};
}
REGISTER_COMPONENT(fps::component)

View File

@ -1,18 +1,19 @@
#include <stdinc.hpp>
#include "game_console.hpp"
#include "command.hpp"
#include "scheduler.hpp"
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "game_console.hpp"
#include "command.hpp"
#include "scheduler.hpp"
#include "game/scripting/event.hpp"
#include "game/scripting/execution.hpp"
#include "game/scripting/lua/engine.hpp"
#include <utils/string.hpp>
#include <utils/hook.hpp>
#include <deque>
#define console_font game::R_RegisterFont("fonts/fira_mono_regular.ttf", 18)
#define material_white game::Material_RegisterHandle("white")
@ -620,82 +621,96 @@ namespace game_console
return true;
}
void init()
class component final : public component_interface
{
scheduler::loop(draw_console, scheduler::pipeline::renderer);
con.cursor = 0;
con.visible_line_count = 0;
con.output_visible = false;
con.display_line_offset = 0;
con.line_count = 0;
strncpy_s(con.buffer, "", 256);
con.globals.x = 0.0f;
con.globals.y = 0.0f;
con.globals.left_x = 0.0f;
con.globals.font_height = 0.0f;
con.globals.may_auto_complete = false;
con.globals.info_line_count = 0;
strncpy_s(con.globals.auto_complete_choice, "", 64);
// add clear command
command::add("clear", [&]()
public:
void post_unpack() override
{
clear();
scheduler::loop(draw_console, scheduler::pipeline::renderer);
con.cursor = 0;
con.visible_line_count = 0;
con.output_visible = false;
con.display_line_offset = 0;
con.line_count = 0;
con.output.clear();
history_index = -1;
history.clear();
});
strncpy_s(con.buffer, "", 256);
char a2[1] = {};
con.globals.x = 0.0f;
con.globals.y = 0.0f;
con.globals.left_x = 0.0f;
con.globals.font_height = 0.0f;
con.globals.may_auto_complete = false;
con.globals.info_line_count = 0;
strncpy_s(con.globals.auto_complete_choice, "", 64);
// add our dvars
dvars::con_inputBoxColor = game::Dvar_RegisterVec4(game::generateHashValue("con_inputBoxColor"), a2,
0.2f, 0.2f, 0.2f, 0.9f,
0.0f, 1.0f,
1);
// add clear command
command::add("clear", [&]()
{
clear();
con.line_count = 0;
con.output.clear();
history_index = -1;
history.clear();
});
dvars::con_inputHintBoxColor = game::Dvar_RegisterVec4(game::generateHashValue("con_inputHintBoxColor"), a2,
0.3f, 0.3f, 0.3f, 1.0f,
0.0f, 1.0f,
1);
char a2[1] = {};
dvars::con_outputBarColor = game::Dvar_RegisterVec4(game::generateHashValue("con_outputBarColor"), a2,
0.5f, 0.5f, 0.5f, 0.6f,
0.0f, 1.0f,
1);
// add our dvars
dvars::con_inputBoxColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_inputBoxColor"), a2,
0.2f, 0.2f, 0.2f, 0.9f,
0.0f, 1.0f,
1);
dvars::con_outputSliderColor = game::Dvar_RegisterVec4(game::generateHashValue("con_outputSliderColor"), a2,
0.0f, 0.7f, 1.0f, 1.00f,
0.0f, 1.0f,
1);
dvars::con_inputHintBoxColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_inputHintBoxColor"), a2,
0.3f, 0.3f, 0.3f, 1.0f,
0.0f, 1.0f,
1);
dvars::con_outputWindowColor = game::Dvar_RegisterVec4(game::generateHashValue("con_outputWindowColor"), a2,
0.25f, 0.25f, 0.25f, 0.85f,
0.0f, 1.0f,
1);
dvars::con_outputBarColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_outputBarColor"), a2,
0.5f, 0.5f, 0.5f, 0.6f,
0.0f, 1.0f,
1);
dvars::con_inputDvarMatchColor = game::Dvar_RegisterVec4(game::generateHashValue("con_inputDvarMatchColor"), a2,
1.0f, 1.0f, 0.8f, 1.0f,
0.0f, 1.0f,
1);
dvars::con_outputSliderColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_outputSliderColor"), a2,
0.0f, 0.7f, 1.0f, 1.00f,
0.0f, 1.0f,
1);
dvars::con_inputDvarValueColor = game::Dvar_RegisterVec4(game::generateHashValue("con_inputDvarValueColor"), a2,
1.0f, 1.0f, 0.8f, 1.0f,
0.0f, 1.0f,
1);
dvars::con_outputWindowColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_outputWindowColor"), a2,
0.25f, 0.25f, 0.25f, 0.85f,
0.0f, 1.0f,
1);
dvars::con_inputDvarInactiveValueColor = game::Dvar_RegisterVec4(game::generateHashValue("con_inputDvarInactiveValueColor"), a2,
0.8f, 0.8f, 0.8f, 1.0f,
0.0f, 1.0f,
1);
dvars::con_inputDvarMatchColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_inputDvarMatchColor"), a2,
1.0f, 1.0f, 0.8f, 1.0f,
0.0f, 1.0f,
1);
dvars::con_inputCmdMatchColor = game::Dvar_RegisterVec4(game::generateHashValue("con_inputCmdMatchColor"), a2,
0.80f, 0.80f, 1.0f, 1.0f,
0.0f, 1.0f,
1);
dvars::con_inputDvarValueColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_inputDvarValueColor"), a2,
1.0f, 1.0f, 0.8f, 1.0f,
0.0f, 1.0f,
1);
}
dvars::con_inputDvarInactiveValueColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_inputDvarInactiveValueColor"), a2,
0.8f, 0.8f, 0.8f, 1.0f,
0.0f, 1.0f,
1);
dvars::con_inputCmdMatchColor = game::Dvar_RegisterVec4(
game::generateHashValue("con_inputCmdMatchColor"), a2,
0.80f, 0.80f, 1.0f, 1.0f,
0.0f, 1.0f,
1);
}
};
}
REGISTER_COMPONENT(game_console::component)

View File

@ -15,6 +15,4 @@ namespace game_console
bool console_key_event(int local_client_num, int key, int down);
void execute(const char* cmd);
void init();
}

View File

@ -1,4 +1,5 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
@ -34,9 +35,15 @@ namespace input
}
}
void init()
class component final : public component_interface
{
cl_char_event_hook.create(game::base_address + 0x3D27B0, cl_char_event_stub);
cl_key_event_hook.create(game::base_address + 0x3D2AE0, cl_key_event_stub);
}
public:
void post_unpack() override
{
cl_char_event_hook.create(game::base_address + 0x3D27B0, cl_char_event_stub);
cl_key_event_hook.create(game::base_address + 0x3D2AE0, cl_key_event_stub);
}
};
}
REGISTER_COMPONENT(input::component)

View File

@ -1,6 +0,0 @@
#pragma once
namespace input
{
void init();
}

29
src/component/patches.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
namespace patches
{
namespace
{
}
class component final : public component_interface
{
public:
void post_unpack() override
{
// Unlock fps in main menu
utils::hook::set<BYTE>(game::base_address + 0x3D8E1B, 0xEB);
// Disable battle net popup
utils::hook::set(game::base_address + 0xBE7F83C, true);
}
};
}
REGISTER_COMPONENT(patches::component)

View File

@ -1,6 +1,9 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
@ -135,18 +138,24 @@ namespace scheduler
}, type, delay);
}
void init()
class component final : public component_interface
{
thread = std::thread([]()
public:
void post_unpack() override
{
while (!kill)
thread = std::thread([]()
{
execute(pipeline::async);
std::this_thread::sleep_for(10ms);
}
});
while (!kill)
{
execute(pipeline::async);
std::this_thread::sleep_for(10ms);
}
});
r_end_frame_hook.create(game::base_address + 0x76D7B0, scheduler::r_end_frame_stub);
g_run_frame_hook.create(game::base_address + 0x4CB030, scheduler::server_frame_stub);
}
r_end_frame_hook.create(game::base_address + 0x76D7B0, scheduler::r_end_frame_stub);
g_run_frame_hook.create(game::base_address + 0x4CB030, scheduler::server_frame_stub);
}
};
}
REGISTER_COMPONENT(scheduler::component)

View File

@ -28,6 +28,4 @@ namespace scheduler
std::chrono::milliseconds delay = 0ms);
void once(const std::function<void()>& callback, pipeline type = pipeline::async,
std::chrono::milliseconds delay = 0ms);
void init();
}

View File

@ -1,13 +1,15 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
#include "scheduler.hpp"
#include "game/scripting/event.hpp"
#include "game/scripting/execution.hpp"
#include "game/scripting/lua/engine.hpp"
#include "scheduler.hpp"
#include <utils/hook.hpp>
namespace scripting
{
@ -77,18 +79,24 @@ namespace scripting
}
}
void init()
class component final : public component_interface
{
vm_notify_hook.create(game::base_address + 0x5CC450, vm_notify_stub);
scr_load_level_hook.create(game::base_address + 0x520AB0, scr_load_level_stub);
g_shutdown_game_hook.create(game::base_address + 0x4CBAD0, g_shutdown_game_stub);
scr_add_class_field_hook.create(game::base_address + 0x5C2C30, scr_add_class_field_stub);
scheduler::loop([]()
public:
void post_unpack() override
{
lua::engine::run_frame();
}, scheduler::pipeline::server);
}
vm_notify_hook.create(game::base_address + 0x5CC450, vm_notify_stub);
scr_load_level_hook.create(game::base_address + 0x520AB0, scr_load_level_stub);
g_shutdown_game_hook.create(game::base_address + 0x4CBAD0, g_shutdown_game_stub);
scr_add_class_field_hook.create(game::base_address + 0x5C2C30, scr_add_class_field_stub);
scheduler::loop([]()
{
lua::engine::run_frame();
}, scheduler::pipeline::server);
}
};
}
REGISTER_COMPONENT(scripting::component)

View File

@ -3,6 +3,4 @@
namespace scripting
{
extern std::unordered_map<int, std::unordered_map<std::string, int>> fields_table;
void init();
}

View File

@ -1,8 +1,14 @@
#include "stdinc.hpp"
#include <stdinc.hpp>
#include "game/game.hpp"
#include "component/game_console.hpp"
#include "loader/component_loader.hpp"
#pragma warning(disable:4996)
DWORD WINAPI dwConsole(LPVOID)
DWORD WINAPI console(LPVOID)
{
AllocConsole();
AttachConsole(GetCurrentProcessId());
@ -25,18 +31,11 @@ DWORD WINAPI dwConsole(LPVOID)
void init()
{
CreateThread(0, 0, dwConsole, 0, 0, 0);
CreateThread(0, 0, console, 0, 0, 0);
game::load_base_address();
utils::hook::set(game::base_address + 0xBE7F83C, true); // disable bnet popup
command::init();
input::init();
scheduler::init();
game_console::init();
scripting::init();
chat::init();
component_loader::post_unpack();
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)

View File

@ -1,5 +1,7 @@
#pragma once
#include "structs.hpp"
namespace game
{
extern uint64_t base_address;

View File

@ -7,6 +7,7 @@
#include "../functions.hpp"
#include "../../../component/command.hpp"
#include "../../../component/chat.hpp"
#include <utils/string.hpp>

View File

@ -0,0 +1,35 @@
#pragma once
class component_interface
{
public:
virtual ~component_interface()
{
}
virtual void post_start()
{
}
virtual void post_load()
{
}
virtual void pre_destroy()
{
}
virtual void post_unpack()
{
}
virtual void* load_import([[maybe_unused]] const std::string& library, [[maybe_unused]] const std::string& function)
{
return nullptr;
}
virtual bool is_supported()
{
return true;
}
};

View File

@ -0,0 +1,127 @@
#include <stdinc.hpp>
#include "component_loader.hpp"
void component_loader::register_component(std::unique_ptr<component_interface>&& component_)
{
get_components().push_back(std::move(component_));
}
bool component_loader::post_start()
{
static auto handled = false;
if (handled) return true;
handled = true;
try
{
for (const auto& component_ : get_components())
{
component_->post_start();
}
}
catch (premature_shutdown_trigger&)
{
return false;
}
return true;
}
bool component_loader::post_load()
{
static auto handled = false;
if (handled) return true;
handled = true;
clean();
try
{
for (const auto& component_ : get_components())
{
component_->post_load();
}
}
catch (premature_shutdown_trigger&)
{
return false;
}
return true;
}
void component_loader::post_unpack()
{
static auto handled = false;
if (handled) return;
handled = true;
for (const auto& component_ : get_components())
{
component_->post_unpack();
}
}
void component_loader::pre_destroy()
{
static auto handled = false;
if (handled) return;
handled = true;
for (const auto& component_ : get_components())
{
component_->pre_destroy();
}
}
void component_loader::clean()
{
auto& components = get_components();
for (auto i = components.begin(); i != components.end();)
{
if (!(*i)->is_supported())
{
(*i)->pre_destroy();
i = components.erase(i);
}
else
{
++i;
}
}
}
void* component_loader::load_import(const std::string& library, const std::string& function)
{
void* function_ptr = nullptr;
for (const auto& component_ : get_components())
{
auto* const component_function_ptr = component_->load_import(library, function);
if (component_function_ptr)
{
function_ptr = component_function_ptr;
}
}
return function_ptr;
}
void component_loader::trigger_premature_shutdown()
{
throw premature_shutdown_trigger();
}
std::vector<std::unique_ptr<component_interface>>& component_loader::get_components()
{
using component_vector = std::vector<std::unique_ptr<component_interface>>;
using component_vector_container = std::unique_ptr<component_vector, std::function<void(component_vector*)>>;
static component_vector_container components(new component_vector, [](component_vector* component_vector)
{
pre_destroy();
delete component_vector;
});
return *components;
}

View File

@ -0,0 +1,61 @@
#pragma once
#include "component_interface.hpp"
class component_loader final
{
public:
class premature_shutdown_trigger final : public std::exception
{
[[nodiscard]] const char* what() const noexcept override
{
return "Premature shutdown requested";
}
};
template <typename T>
class installer final
{
static_assert(std::is_base_of<component_interface, T>::value, "component has invalid base class");
public:
installer()
{
register_component(std::make_unique<T>());
}
};
template <typename T>
static T* get()
{
for (const auto& component_ : get_components())
{
if (typeid(*component_.get()) == typeid(T))
{
return reinterpret_cast<T*>(component_.get());
}
}
return nullptr;
}
static void register_component(std::unique_ptr<component_interface>&& component);
static bool post_start();
static bool post_load();
static void post_unpack();
static void pre_destroy();
static void clean();
static void* load_import(const std::string& library, const std::string& function);
static void trigger_premature_shutdown();
private:
static std::vector<std::unique_ptr<component_interface>>& get_components();
};
#define REGISTER_COMPONENT(name) \
namespace \
{ \
static component_loader::installer<name> __component; \
}

View File

@ -34,21 +34,4 @@
#include <MinHook.h>
#include <gsl/gsl>
using namespace std::literals;
#include "utils/memory.hpp"
#include "utils/string.hpp"
#include "utils/hook.hpp"
#include "utils/string.hpp"
#include "utils/io.hpp"
#include "game/structs.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "component/command.hpp"
#include "component/scripting.hpp"
#include "component/scheduler.hpp"
#include "component/input.hpp"
#include "component/game_console.hpp"
#include "component/chat.hpp"
using namespace std::literals;

View File

@ -1,4 +1,5 @@
#include "stdinc.hpp"
#include <stdinc.hpp>
#include "hook.hpp"
#include "string.hpp"

View File

@ -1,4 +1,5 @@
#include <stdinc.hpp>
#include "io.hpp"
#include <fstream>

View File

@ -1,6 +1,8 @@
// https://github.com/momo5502/open-iw5
#include "stdinc.hpp"
#include <stdinc.hpp>
#include "memory.hpp"
namespace utils
{
@ -54,15 +56,6 @@ namespace utils
return this->pool_.empty();
}
/*char* memory::allocator::duplicate_string(const std::string& string)
{
std::lock_guard _(this->mutex_);
const auto data = memory::duplicate_string(string);
this->pool_.push_back(data);
return data;
}*/
void* memory::allocate(const size_t length)
{
const auto data = calloc(length, 1);
@ -70,13 +63,6 @@ namespace utils
return data;
}
/*char* memory::duplicate_string(const std::string& string)
{
const auto new_string = allocate_array<char>(string.size() + 1);
std::memcpy(new_string, string.data(), string.size());
return new_string;
}*/
void memory::free(void* data)
{
if (data)

View File

@ -34,8 +34,6 @@ namespace utils
bool empty() const;
//char* duplicate_string(const std::string& string);
private:
std::mutex mutex_;
std::vector<void*> pool_;
@ -55,8 +53,6 @@ namespace utils
return static_cast<T*>(allocate(count * sizeof(T)));
}
//static char* duplicate_string(const std::string& string);
static void free(void* data);
static void free(const void* data);

View File

@ -1,6 +1,9 @@
// iw6x-client
#include "stdinc.hpp"
#include <stdinc.hpp>
#include "memory.hpp"
#include "string.hpp"
namespace utils::string
{

View File

@ -1,5 +1,4 @@
#pragma once
#include "stdinc.hpp"
namespace utils::string
{