Skip to content

Commit

Permalink
a little code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxor4d committed Feb 16, 2024
1 parent 5a9c0c8 commit 2ea90da
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 415 deletions.
2 changes: 0 additions & 2 deletions src/components/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace components
std::vector<component*> loader::components_;
utils::memory::allocator loader::component_allocator_;

#define USE_MODULE(name, state) active.##name = state

void loader::initialize_()
{
loader::component_allocator_.clear();
Expand Down
4 changes: 2 additions & 2 deletions src/components/loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ namespace components
public:
component() = default;
virtual ~component() = default;
virtual const char* get_name() { return "unknown"; };
virtual const char* get_name() { return "unknown"; }
};

class loader
{
public:
static void initialize_();
static void uninitialize_();
static void register_(component* component);//, bool& registered);
static void register_(component* component);
static bool is_registered(const char *componentName);

static utils::memory::allocator* get_alloctor();
Expand Down
15 changes: 0 additions & 15 deletions src/components/modules/_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@ namespace components
{
void on_disconnect()
{
/*if (Components::active.Mvm)
{
const auto& cl_avidemo = Game::Dvar_FindVar("cl_avidemo");
if (cl_avidemo && cl_avidemo->current.integer)
{
Game::Dvar_SetValue(cl_avidemo, 0);
}
if (dvars::cl_avidemo_streams && dvars::cl_avidemo_streams->current.integer)
{
Game::Dvar_SetValue(dvars::cl_avidemo_streams, 0);
}
}*/

game::glob::mainmenu_fade_done = false;
game::glob::loaded_main_menu = false;

Expand Down
28 changes: 14 additions & 14 deletions src/components/modules/_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace components
call force_dvars_on_init;
popad;

mov ecx, 0Ch; // overwritten op
mov ecx, 0xC; // overwritten op
jmp retn_addr;
}
}
Expand All @@ -121,7 +121,7 @@ namespace components
const static uint32_t retn_addr = 0x56B3A1;
__asm
{
movzx eax, word ptr[edi + 8]; // overwritten op
movzx eax, word ptr [edi + 8]; // overwritten op
jmp retn_addr;
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@ namespace components
// ---------------------------------------------------------------------------------------------------------

// if addon_menu loading is enabled
if (FF_LOAD_ADDON_MENU)
if constexpr (FF_LOAD_ADDON_MENU)
{
// if the fastfile exists
if (FF_ADDON_MENU_NAME && game::DB_FileExists(FF_ADDON_MENU_NAME, game::DB_FILE_EXISTS_PATH::DB_PATH_ZONE))
Expand Down Expand Up @@ -190,7 +190,7 @@ namespace components
}

// if addon_menu loading is enabled and file not found
else if (FF_LOAD_ADDON_MENU)
else if constexpr (FF_LOAD_ADDON_MENU)
{
game::Com_PrintMessage(0, utils::va("^1DB_LoadCommonFastFiles^7:: %s.ff not found. \n", FF_ADDON_MENU_NAME), 0);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ namespace components
// ------------------------------------

// load user addon zone
if (FF_LOAD_ADDON_OPT)
if constexpr (FF_LOAD_ADDON_OPT)
{
// custom addon file
if (game::DB_FileExists(FF_ADDON_OPT_NAME, game::DB_FILE_EXISTS_PATH::DB_PATH_ZONE))
Expand Down Expand Up @@ -274,7 +274,7 @@ namespace components
}

// load required addon fastfile last, if addon_required loading enabled
if (FF_LOAD_ADDON_REQ)
if constexpr (FF_LOAD_ADDON_REQ)
{
// if the fastfile exists
if (FF_ADDON_REQ_NAME && game::DB_FileExists(FF_ADDON_REQ_NAME, game::DB_FILE_EXISTS_PATH::DB_PATH_ZONE))
Expand Down Expand Up @@ -307,7 +307,7 @@ namespace components
game::XZoneInfo XZoneInfoStack[2];

// if addon menu loading is enabled
if (FF_LOAD_ADDON_MENU)
if constexpr (FF_LOAD_ADDON_MENU)
{
// if the fastfile exists
if (FF_ADDON_MENU_NAME && game::DB_FileExists(FF_ADDON_MENU_NAME, game::DB_FILE_EXISTS_PATH::DB_PATH_ZONE))
Expand All @@ -325,7 +325,7 @@ namespace components
}

// if addon menu loading is enabled and file not found
else if (FF_LOAD_ADDON_MENU)
else if constexpr (FF_LOAD_ADDON_MENU)
{
game::Com_PrintMessage(0, utils::va("^1Com_StartHunkUsers^7:: %s.ff not found. \n", FF_ADDON_MENU_NAME), 0);
}
Expand Down Expand Up @@ -407,7 +407,7 @@ namespace components
MATCH:
mov ebx, [ebp - 4]; // whatever df that is
mov [ebp - 8], 1; // set qLocalized to true ;)
mov [ebp - 0Ch], esi; // whatever df that is
mov [ebp - 0xC], esi; // whatever df that is
jmp retn_addr;
}
}
Expand All @@ -419,7 +419,7 @@ namespace components
void _common::db_realloc_entry_pool()
{
const size_t ALLOC_SIZE = 789312;
game::XAssetEntry* entry_pool = utils::memory::get_allocator()->allocate_array<game::XAssetEntry>(ALLOC_SIZE);
const auto entry_pool = utils::memory::get_allocator()->allocate_array<game::XAssetEntry>(ALLOC_SIZE);

// Apply new size
utils::hook::set<DWORD>(0x488F50, ALLOC_SIZE);
Expand All @@ -434,9 +434,9 @@ namespace components
0x48B4A4, 0x48B4F8
};

for (int i = 0; i < ARRAYSIZE(asset_entry_pool_patches); ++i)
for (const auto addr : asset_entry_pool_patches)
{
utils::hook::set<game::XAssetEntry*>(asset_entry_pool_patches[i], entry_pool);
utils::hook::set<game::XAssetEntry*>(addr, entry_pool);
}

utils::hook::set<game::XAssetEntry*>(0x488F31, entry_pool + 1);
Expand Down Expand Up @@ -520,10 +520,10 @@ namespace components
}

game::XZoneInfo info[2];
std::string zone = params[1];
const std::string zone = params[1];

// unload
info[0].name = 0;
info[0].name = nullptr;
info[0].allocFlags = game::XZONE_FLAGS::XZONE_ZERO;
info[0].freeFlags = game::XZONE_FLAGS::XZONE_MOD;

Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/_ggame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace components

bool _ggame::get_entity_token(char* buffer, int buffer_size)
{
char* s = game::Com_Parse(&game::g_entityBeginParsePoint);
const char* s = game::Com_Parse(&game::g_entityBeginParsePoint);
utils::q_strncpyz(buffer, s, buffer_size);

if (!game::g_entityBeginParsePoint)
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace components
{
// overwritten op's
add esp, 8;
and esi, 0FFFFFFF0h;
and esi, 0xFFFFFFF0;

call _map::on_load;
jmp retn_addr;
Expand Down
Loading

0 comments on commit 2ea90da

Please sign in to comment.