fix(file_system): small leak
This commit is contained in:
parent
c5e6d6f1a0
commit
bab81a44de
@ -7,6 +7,8 @@ namespace dvars
|
||||
const game::native::dvar_t** com_sv_running;
|
||||
|
||||
const game::native::dvar_t** sv_maxclients;
|
||||
const game::native::dvar_t** sv_g_gametype;
|
||||
const game::native::dvar_t** sv_mapname;
|
||||
|
||||
const game::native::dvar_t** loc_language;
|
||||
|
||||
@ -15,6 +17,8 @@ namespace dvars
|
||||
com_sv_running = reinterpret_cast<const game::native::dvar_t**>(SELECT_VALUE(0x1769F50, 0x1CEF588));
|
||||
|
||||
sv_maxclients = reinterpret_cast<const game::native::dvar_t**>(SELECT_VALUE(0x0, 0x21223C0));
|
||||
sv_g_gametype = reinterpret_cast<const game::native::dvar_t**>(SELECT_VALUE(0x0, 0x21223F8));
|
||||
sv_mapname = reinterpret_cast<const game::native::dvar_t**>(SELECT_VALUE(0x47D7C6, 0x58D4784));
|
||||
|
||||
loc_language = reinterpret_cast<const game::native::dvar_t**>(SELECT_VALUE(0x1BF6938, 0x58D5A90));
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ namespace dvars
|
||||
extern const game::native::dvar_t** com_sv_running;
|
||||
|
||||
extern const game::native::dvar_t** sv_maxclients;
|
||||
extern const game::native::dvar_t** sv_g_gametype;
|
||||
extern const game::native::dvar_t** sv_mapname;
|
||||
|
||||
extern const game::native::dvar_t** loc_language;
|
||||
|
||||
|
@ -78,6 +78,8 @@ namespace game
|
||||
Hunk_AllocateTempMemoryHighInternal_t Hunk_AllocateTempMemoryHighInternal;
|
||||
Hunk_FreeTempMemory_t Hunk_FreeTempMemory;
|
||||
|
||||
Hunk_UserDestroy_t Hunk_UserDestroy;
|
||||
|
||||
VM_Notify_t VM_Notify;
|
||||
|
||||
BG_NetDataChecksum_t BG_NetDataChecksum;
|
||||
@ -805,6 +807,8 @@ namespace game
|
||||
native::Hunk_AllocateTempMemoryHighInternal = native::Hunk_AllocateTempMemoryHighInternal_t(SELECT_VALUE(0x517870, 0x5B6C60));
|
||||
native::Hunk_FreeTempMemory = native::Hunk_FreeTempMemory_t(SELECT_VALUE(0x434A40, 0x5B6F90));
|
||||
|
||||
native::Hunk_UserDestroy = native::Hunk_UserDestroy_t(SELECT_VALUE(0x50FE20, 0x5B7520));
|
||||
|
||||
native::VM_Notify = native::VM_Notify_t(SELECT_VALUE(0x610200, 0x569720));
|
||||
|
||||
native::BG_NetDataChecksum = native::BG_NetDataChecksum_t(SELECT_VALUE(0x0, 0x41BB20));
|
||||
|
@ -173,6 +173,9 @@ namespace game
|
||||
typedef void (*Hunk_FreeTempMemory_t)(void* buf);
|
||||
extern Hunk_FreeTempMemory_t Hunk_FreeTempMemory;
|
||||
|
||||
typedef void (*Hunk_UserDestroy_t)(HunkUser* user);
|
||||
extern Hunk_UserDestroy_t Hunk_UserDestroy;
|
||||
|
||||
typedef void (*VM_Notify_t)(unsigned int notifyListOwnerId, unsigned int stringValue, VariableValue* top);
|
||||
extern VM_Notify_t VM_Notify;
|
||||
|
||||
|
@ -632,6 +632,16 @@ char** file_system::list_files(const char* path, const char* extension, game::na
|
||||
return game::native::FS_ListFilteredFiles(*game::native::fs_searchpaths, path, extension, nullptr, behavior, numfiles, allocTrackType);
|
||||
}
|
||||
|
||||
void file_system::free_file_list(char** list)
|
||||
{
|
||||
if (!list)
|
||||
{
|
||||
return;
|
||||
}
|
||||
--list;
|
||||
game::native::Hunk_UserDestroy(reinterpret_cast<game::native::HunkUser*>(*list));
|
||||
}
|
||||
|
||||
void file_system::post_load()
|
||||
{
|
||||
fs_homepath = reinterpret_cast<const game::native::dvar_t**>(SELECT_VALUE(0x1C2B538, 0x59ADD18));
|
||||
|
@ -11,4 +11,5 @@ public:
|
||||
static int write(const char* buffer, int len, int h);
|
||||
|
||||
static char** list_files(const char* path, const char* extension, game::native::FsListBehavior_e behavior, int* numfiles, int allocTrackType);
|
||||
static void free_file_list(char** list);
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <std_include.hpp>
|
||||
#include <loader/module_loader.hpp>
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
#include "script_loading.hpp"
|
||||
|
||||
@ -11,6 +12,7 @@
|
||||
#include <utils/compression.hpp>
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/memory.hpp>
|
||||
#include <utils/string.hpp>
|
||||
|
||||
#include <gsc_interface.hpp>
|
||||
|
||||
@ -156,19 +158,23 @@ namespace gsc
|
||||
return game::native::DB_IsXAssetDefault(type, name);
|
||||
}
|
||||
|
||||
void load_scripts()
|
||||
void load_scripts_from_folder(const char* dir)
|
||||
{
|
||||
char path[game::native::MAX_OSPATH]{};
|
||||
char search_path[game::native::MAX_OSPATH]{};
|
||||
|
||||
strncpy_s(search_path, dir, _TRUNCATE);
|
||||
strncat_s(search_path, "/", _TRUNCATE);
|
||||
|
||||
auto num_files = 0;
|
||||
auto** files = file_system::list_files("scripts/", "gsc", game::native::FS_LIST_ALL, &num_files, 10);
|
||||
auto** list = file_system::list_files(search_path, "gsc", game::native::FS_LIST_ALL, &num_files, 10);
|
||||
|
||||
for (auto i = 0; i < num_files; ++i)
|
||||
{
|
||||
const auto* script_file = files[i];
|
||||
const auto* script_file = list[i];
|
||||
console::info("Loading script %s...\n", script_file);
|
||||
|
||||
const auto len = sprintf_s(path, "%s/%s", "scripts", script_file);
|
||||
const auto len = sprintf_s(path, "%s/%s", dir, script_file);
|
||||
if (len == -1)
|
||||
{
|
||||
continue;
|
||||
@ -199,6 +205,18 @@ namespace gsc
|
||||
init_handles[path] = init_handle;
|
||||
}
|
||||
}
|
||||
|
||||
file_system::free_file_list(list);
|
||||
}
|
||||
|
||||
void load_scripts()
|
||||
{
|
||||
// Both SP & MP
|
||||
load_scripts_from_folder("scripts");
|
||||
|
||||
// Game specific
|
||||
const auto* game_dir = game::is_mp() ? "scripts/mp" : "scripts/sp";
|
||||
load_scripts_from_folder(game_dir);
|
||||
}
|
||||
|
||||
void g_scr_load_scripts_mp_stub()
|
||||
|
@ -163,8 +163,8 @@ __declspec(naked) void test_clients::reset_reliable_mp()
|
||||
|
||||
bool test_clients::check_timeouts(const game::native::mp::client_t* client)
|
||||
{
|
||||
return (!client->bIsTestClient || client->header.state == game::native::clientState_t::CS_ZOMBIE) &&
|
||||
client->header.netchan.remoteAddress.type != game::native::netadrtype_t::NA_LOOPBACK;
|
||||
return (!client->bIsTestClient || client->header.state == game::native::CS_ZOMBIE) &&
|
||||
client->header.netchan.remoteAddress.type != game::native::NA_LOOPBACK;
|
||||
}
|
||||
|
||||
__declspec(naked) void test_clients::check_timeouts_stub_mp()
|
||||
|
Loading…
Reference in New Issue
Block a user