Compare commits

..

2 Commits

Author SHA1 Message Date
9dac498eba comment formatting 2024-12-20 13:20:58 +00:00
b1d8d49b72 add timescale dvar 2024-12-20 13:17:54 +00:00
56 changed files with 445 additions and 1903 deletions

2
deps/GSL vendored

@ -1 +1 @@
Subproject commit 355982daf6c54ccb11bef8a1c511be2622dec402
Subproject commit e64c97fc2cfc11992098bb38eda932de275e3f4d

2
deps/WinToast vendored

@ -1 +1 @@
Subproject commit a78ce469b456c06103b3b30d4bd37e7bb80da30c
Subproject commit 821c4818ade1aa4da56ac753285c159ce26fd597

2
deps/asmjit vendored

@ -1 +1 @@
Subproject commit cfc9f813cc6ccda63cad872edb32b38e0662bedb
Subproject commit 118ae6ced160f68dd142a0d758aa7efb4356196a

2
deps/gsc-tool vendored

@ -1 +1 @@
Subproject commit e4cb6a7819726d9ea33cd6a52f0dcd9382258b47
Subproject commit b8e30e6334aa33ea731caf8d0700a9e6c7794c09

2
deps/libtomcrypt vendored

@ -1 +1 @@
Subproject commit 2e9f2b5e44dd498dba60e5175c6c7effa5ff3728
Subproject commit 7e863d21429f94ed6a720e24499a12a3f852bb31

2
deps/libtommath vendored

@ -1 +1 @@
Subproject commit 5809141a3a6ec1bf3443c927c02b955e19224016
Subproject commit 8314bde5e5c8e5d9331460130a9d1066e324f091

2
deps/minhook vendored

@ -1 +1 @@
Subproject commit c1a7c3843bd1a5fe3eb779b64c0d823bca3dc339
Subproject commit f5485b8454544c2f034c78f8f127c1d03dea3636

2
deps/rapidjson vendored

@ -1 +1 @@
Subproject commit d621dc9e9c77f81e5c8a35b8dcc16dcd63351321
Subproject commit 6089180ecb704cb2b136777798fa1be303618975

2
deps/zlib vendored

@ -1 +1 @@
Subproject commit ef24c4c7502169f016dcd2a26923dbaf3216748c
Subproject commit 643e17b7498d12ab8d15565662880579692f769d

View File

@ -5,16 +5,14 @@
#include "auth.hpp"
#include "command.hpp"
#include "console.hpp"
#include "network.hpp"
#include "console.hpp"
#include <utils/cryptography.hpp>
#include <utils/hook.hpp>
#include <utils/info_string.hpp>
#include <utils/io.hpp>
#include <utils/properties.hpp>
#include <utils/smbios.hpp>
#include <utils/string.hpp>
#include <utils/smbios.hpp>
#include <utils/info_string.hpp>
#include <utils/cryptography.hpp>
namespace auth
{
@ -33,21 +31,13 @@ namespace auth
std::string get_hw_profile_guid()
{
auto hw_profile_path = (utils::properties::get_appdata_path() / "s1-guid.dat").generic_string();
if (utils::io::file_exists(hw_profile_path))
{
// Migration
utils::io::remove_file(hw_profile_path);
}
HW_PROFILE_INFO info;
if (!GetCurrentHwProfileA(&info))
{
return {};
}
auto hw_profile_info = std::string{ info.szHwProfileGuid, sizeof(info.szHwProfileGuid) };
return hw_profile_info;
return std::string{info.szHwProfileGuid, sizeof(info.szHwProfileGuid)};
}
std::string get_protected_data()
@ -57,7 +47,7 @@ namespace auth
DATA_BLOB data_in{}, data_out{};
data_in.pbData = reinterpret_cast<uint8_t*>(input.data());
data_in.cbData = static_cast<DWORD>(input.size());
if (CryptProtectData(&data_in, nullptr, nullptr, nullptr, nullptr, CRYPTPROTECT_LOCAL_MACHINE, &data_out) != TRUE)
if(CryptProtectData(&data_in, nullptr, nullptr, nullptr, nullptr, CRYPTPROTECT_LOCAL_MACHINE, &data_out) != TRUE)
{
return {};
}
@ -86,72 +76,9 @@ namespace auth
return entropy;
}
bool load_key(utils::cryptography::ecc::key& key)
utils::cryptography::ecc::key& get_key()
{
std::string data{};
auto key_path = (utils::properties::get_appdata_path() / "s1-private.key").generic_string();
if (!utils::io::read_file(key_path, &data))
{
return false;
}
key.deserialize(data);
if (!key.is_valid())
{
console::error("Loaded key is invalid!\n");
return false;
}
return true;
}
utils::cryptography::ecc::key generate_key()
{
auto key = utils::cryptography::ecc::generate_key(512, get_key_entropy());
if (!key.is_valid())
{
throw std::runtime_error("Failed to generate cryptographic key!");
}
auto key_path = (utils::properties::get_appdata_path() / "s1-private.key").generic_string();
if (!utils::io::write_file(key_path, key.serialize()))
{
console::error("Failed to write cryptographic key!\n");
}
console::info("Generated cryptographic key: %llX\n", key.get_hash());
return key;
}
utils::cryptography::ecc::key load_or_generate_key()
{
utils::cryptography::ecc::key key{};
if (load_key(key))
{
console::info("Loaded cryptographic key: %llX\n", key.get_hash());
return key;
}
return generate_key();
}
utils::cryptography::ecc::key get_key_internal()
{
auto key = load_or_generate_key();
auto key_path = (utils::properties::get_appdata_path() / "s1-public.key").generic_string();
if (!utils::io::write_file(key_path, key.get_public_key()))
{
console::error("Failed to write public key!\n");
}
return key;
}
const utils::cryptography::ecc::key& get_key()
{
static auto key = get_key_internal();
static auto key = utils::cryptography::ecc::generate_key(512, get_key_entropy());
return key;
}
@ -159,7 +86,7 @@ namespace auth
{
std::string connect_string(format, len);
game::SV_Cmd_TokenizeString(connect_string.data());
const auto _0 = gsl::finally([]()
const auto _ = gsl::finally([]()
{
game::SV_Cmd_EndTokenizedString();
});
@ -182,7 +109,7 @@ namespace auth
proto::network::connect_info info;
info.set_publickey(get_key().get_public_key());
info.set_signature(utils::cryptography::ecc::sign_message(get_key(), challenge));
info.set_signature(sign_message(get_key(), challenge));
info.set_infostring(connect_string);
network::send(*adr, "connect", info.SerializeAsString());
@ -224,14 +151,14 @@ namespace auth
utils::cryptography::ecc::key key;
key.set(info.publickey());
const auto xuid = std::strtoull(steam_id.data(), nullptr, 16);
const auto xuid = strtoull(steam_id.data(), nullptr, 16);
if (xuid != key.get_hash())
{
network::send(*from, "error", utils::string::va("XUID doesn't match the certificate: %llX != %llX", xuid, key.get_hash()), '\n');
return;
}
if (!key.is_valid() || !utils::cryptography::ecc::verify_message(key, challenge, info.signature()))
if (!key.is_valid() || !verify_message(key, challenge, info.signature()))
{
network::send(*from, "error", "Challenge signature was invalid!", '\n');
return;
@ -291,7 +218,7 @@ namespace auth
utils::hook::call(0x140208C54, send_connect_data_stub);
}
command::add("guid", []() -> void
command::add("guid", []
{
console::info("Your guid: %llX\n", steam::SteamUser()->GetSteamID().bits);
});

View File

@ -33,7 +33,9 @@ namespace bullet
return;
}
dvars::bg_surfacePenetration = game::Dvar_RegisterFloat("bg_surfacePenetration", 0.0f, 0.0f, std::numeric_limits<float>::max(), game::DVAR_FLAG_SAVED);
dvars::bg_surfacePenetration = game::Dvar_RegisterFloat("bg_surfacePenetration", 0.0f,
0.0f, std::numeric_limits<float>::max(), game::DVAR_FLAG_SAVED,
"Set to a value greater than 0 to override the surface penetration depth");
bg_get_surface_penetration_depth_hook.create(0x1401641A0, &bg_get_surface_penetration_depth_stub);
}
};

View File

@ -82,16 +82,7 @@ namespace colors
void com_clean_name_stub(const char* in, char* out, const int out_size)
{
// Check that the name is at least 3 char without colors
char name[32]{};
game::I_strncpyz(out, in, std::min<int>(out_size, sizeof(name)));
utils::string::strip(out, name, std::strlen(out) + 1);
if (std::strlen(name) < 3)
{
game::I_strncpyz(out, "UnnamedPlayer", std::min<int>(out_size, sizeof(name)));
}
strncpy_s(out, out_size, in, _TRUNCATE);
}
char* i_clean_str_stub(char* string)
@ -101,12 +92,14 @@ namespace colors
return string;
}
int cl_get_client_name_and_clan_tag_stub(const int local_client_num, const int index, char* name_buf, const int name_size, char* clan_tag_buf, int clan_tag_size)
size_t get_client_name_stub(const int local_client_num, const int index, char* buf, const int size,
const size_t unk, const size_t unk2)
{
// CL_GetClientNameAndClanTag -> CL_GetClientNameAndClanTagColorize
const auto result = utils::hook::invoke<int>(0x140213E60, local_client_num, index, name_buf, name_size, clan_tag_buf, clan_tag_size);
// CL_GetClientName (CL_GetClientNameAndClantag?)
const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, size_t, size_t)>(0x140213E60)(
local_client_num, index, buf, size, unk, unk2);
utils::string::strip(name_buf, name_buf, name_size);
utils::string::strip(buf, buf, static_cast<size_t>(size));
return result;
}
@ -155,11 +148,10 @@ namespace colors
if (!game::environment::is_sp())
{
// allows colored name in-game
utils::hook::call(0x1402DBD28, com_clean_name_stub);
utils::hook::call(0x1402DBD6D, com_clean_name_stub);
utils::hook::jump(0x1404C9510, com_clean_name_stub);
// don't apply colors to overhead names
utils::hook::call(0x1401891B0, cl_get_client_name_and_clan_tag_stub);
utils::hook::call(0x1401891B0, get_client_name_stub);
// patch I_CleanStr
utils::hook::jump(0x1404C99A0, i_clean_str_stub);

View File

@ -253,10 +253,7 @@ namespace command
void execute(std::string command, const bool sync)
{
if (!command.ends_with('\n'))
{
command += "\n";
}
command += "\n";
if (sync)
{

View File

@ -177,9 +177,9 @@ namespace dedicated
return;
}
game::Dvar_RegisterBool("dedicated", true, game::DVAR_FLAG_READ);
game::Dvar_RegisterBool("dedicated", true, game::DVAR_FLAG_READ, "Dedicated server");
sv_lanOnly = game::Dvar_RegisterBool("sv_lanOnly", false, game::DVAR_FLAG_NONE);
sv_lanOnly = game::Dvar_RegisterBool("sv_lanOnly", false, game::DVAR_FLAG_NONE, "Don't send heartbeat");
// Disable VirtualLobby
dvars::override::register_bool("virtualLobbyEnabled", false, game::DVAR_FLAG_NONE | game::DVAR_FLAG_READ);

View File

@ -19,28 +19,28 @@ namespace dedicated_info
scheduler::loop([]()
{
const auto* sv_running = game::Dvar_FindVar("sv_running");
auto* sv_running = game::Dvar_FindVar("sv_running");
if (!sv_running || !sv_running->current.enabled)
{
console::set_title("s1-mod Dedicated Server");
return;
}
const auto* sv_hostname = game::Dvar_FindVar("sv_hostname");
const auto* sv_maxclients = game::Dvar_FindVar("sv_maxclients");
const auto* mapname = game::Dvar_FindVar("mapname");
auto* const sv_hostname = game::Dvar_FindVar("sv_hostname");
auto* const sv_maxclients = game::Dvar_FindVar("sv_maxclients");
auto* const mapname = game::Dvar_FindVar("mapname");
auto bot_count = 0;
auto client_count = 0;
for (auto i = 0; i < sv_maxclients->current.integer; ++i)
for (auto i = 0; i < sv_maxclients->current.integer; i++)
{
auto* client = &game::mp::svs_clients[i];
auto* self = &game::mp::g_entities[i];
if (client->header.state >= 1 && self && self->client)
{
++client_count;
client_count++;
if (game::SV_BotIsBot(i))
{
++bot_count;

View File

@ -342,7 +342,7 @@ namespace demonware
void bd_logger_stub(const char* const function, const char* const msg, ...)
{
static const auto* bd_logger_enabled = game::Dvar_RegisterBool("bd_logger_enabled", false, game::DVAR_FLAG_NONE);
static const auto* bd_logger_enabled = game::Dvar_RegisterBool("bd_logger_enabled", false, game::DVAR_FLAG_NONE, "Enable bdLogger");
if (!bd_logger_enabled->current.enabled)
{
return;

View File

@ -181,7 +181,7 @@ namespace dvar_cheats
constexpr auto value = false;
#endif
dvars::sv_cheats = game::Dvar_RegisterBool("sv_cheats", value, game::DVAR_FLAG_REPLICATED);
dvars::sv_cheats = game::Dvar_RegisterBool("sv_cheats", value, game::DVAR_FLAG_REPLICATED, "Allow cheat commands and dvars on this server");
}
};
}

View File

@ -209,7 +209,7 @@ namespace dvars
utils::hook::detour dvar_set_int_hook;
utils::hook::detour dvar_set_string_hook;
game::dvar_t* dvar_register_bool_stub(const char* name, bool value, unsigned int flags)
game::dvar_t* dvar_register_bool_stub(const char* name, bool value, unsigned int flags, const char* description)
{
auto* var = find_dvar(override::register_bool_overrides, name);
if (var)
@ -218,10 +218,11 @@ namespace dvars
flags = var->flags;
}
return dvar_register_bool_hook.invoke<game::dvar_t*>(name, value, flags);
return dvar_register_bool_hook.invoke<game::dvar_t*>(name, value, flags, description);
}
game::dvar_t* dvar_register_float_stub(const char* name, float value, float min, float max, unsigned int flags)
game::dvar_t* dvar_register_float_stub(const char* name, float value, float min, float max, unsigned int flags,
const char* description)
{
auto* var = find_dvar(override::register_float_overrides, name);
if (var)
@ -232,10 +233,11 @@ namespace dvars
flags = var->flags;
}
return dvar_register_float_hook.invoke<game::dvar_t*>(name, value, min, max, flags);
return dvar_register_float_hook.invoke<game::dvar_t*>(name, value, min, max, flags, description);
}
game::dvar_t* dvar_register_int_stub(const char* name, int value, int min, int max, unsigned int flags)
game::dvar_t* dvar_register_int_stub(const char* name, int value, int min, int max, unsigned int flags,
const char* description)
{
auto* var = find_dvar(override::register_int_overrides, name);
if (var)
@ -246,10 +248,10 @@ namespace dvars
flags = var->flags;
}
return dvar_register_int_hook.invoke<game::dvar_t*>(name, value, min, max, flags);
return dvar_register_int_hook.invoke<game::dvar_t*>(name, value, min, max, flags, description);
}
game::dvar_t* dvar_register_string_stub(const char* name, const char* value, unsigned int flags)
game::dvar_t* dvar_register_string_stub(const char* name, const char* value, unsigned int flags, const char* description)
{
auto* var = find_dvar(override::register_string_overrides, name);
if (var)
@ -258,10 +260,11 @@ namespace dvars
flags = var->flags;
}
return dvar_register_string_hook.invoke<game::dvar_t*>(name, value, flags);
return dvar_register_string_hook.invoke<game::dvar_t*>(name, value, flags, description);
}
game::dvar_t* dvar_register_vector2_stub(const char* name, float x, float y, float min, float max, unsigned int flags)
game::dvar_t* dvar_register_vector2_stub(const char* name, float x, float y, float min, float max,
unsigned int flags, const char* description)
{
auto* var = find_dvar(override::register_vector2_overrides, name);
if (var)
@ -273,10 +276,11 @@ namespace dvars
flags = var->flags;
}
return dvar_register_vector2_hook.invoke<game::dvar_t*>(name, x, y, min, max, flags);
return dvar_register_vector2_hook.invoke<game::dvar_t*>(name, x, y, min, max, flags, description);
}
game::dvar_t* dvar_register_vector3_stub(const char* name, float x, float y, float z, float min, float max, unsigned int flags)
game::dvar_t* dvar_register_vector3_stub(const char* name, float x, float y, float z, float min,
float max, unsigned int flags, const char* description)
{
auto* var = find_dvar(override::register_vector3_overrides, name);
if (var)
@ -289,7 +293,7 @@ namespace dvars
flags = var->flags;
}
return dvar_register_vector3_hook.invoke<game::dvar_t*>(name, x, y, z, min, max, flags);
return dvar_register_vector3_hook.invoke<game::dvar_t*>(name, x, y, z, min, max, flags, description);
}
void dvar_set_bool_stub(game::dvar_t* dvar, bool boolean)

View File

@ -2,43 +2,18 @@
#include "loader/component_loader.hpp"
#include "game/dvars.hpp"
#include "fastfiles.hpp"
#include "command.hpp"
#include "console.hpp"
#include "fastfiles.hpp"
#include <utils/concurrency.hpp>
#include <utils/hook.hpp>
#include <utils/io.hpp>
#include <utils/string.hpp>
#include <utils/concurrency.hpp>
namespace fastfiles
{
static utils::concurrency::container<std::string> current_fastfile;
namespace
{
template <typename T>
inline void merge(std::vector<T>* target, T* source, size_t length)
{
if (source)
{
for (size_t i = 0; i < length; ++i)
{
target->push_back(source[i]);
}
}
}
template <typename T>
inline void merge(std::vector<T>* target, std::vector<T> source)
{
for (auto& entry : source)
{
target->push_back(entry);
}
}
}
namespace
{
utils::hook::detour db_try_load_x_file_internal_hook;
@ -46,21 +21,11 @@ namespace fastfiles
void db_try_load_x_file_internal(const char* zone_name, const int flags)
{
static std::unordered_map<std::string, std::string> zone_overrides = {};
auto override_zone_name = zone_overrides.find(zone_name);
if (override_zone_name != zone_overrides.end())
{
console::info("Overriding fastfile %s with %s\n", zone_name, override_zone_name->second.c_str());
zone_name = override_zone_name->second.c_str();
}
console::info("Loading fastfile %s\n", zone_name);
current_fastfile.access([&](std::string& fastfile)
{
fastfile = zone_name;
});
return db_try_load_x_file_internal_hook.invoke<void>(zone_name, flags);
}
@ -91,12 +56,10 @@ namespace fastfiles
const auto result = db_find_x_asset_header_hook.invoke<game::XAssetHeader>(type, name, allow_create_default);
const auto diff = game::Sys_Milliseconds() - start;
#ifdef DEBUG
if (type == game::ASSET_TYPE_SCRIPTFILE)
{
dump_gsc_script(name, result);
}
#endif
if (diff > 100)
{
@ -110,223 +73,6 @@ namespace fastfiles
return result;
}
utils::hook::detour db_link_xasset_entry1_hook;
game::XAssetEntry* db_link_xasset_entry1(game::XAssetType type, game::XAssetHeader* header)
{
if (type == game::ASSET_TYPE_SCRIPTFILE)
{
dump_gsc_script(header->scriptfile->name, *header);
}
return db_link_xasset_entry1_hook.invoke<game::XAssetEntry*>(type, header);
}
namespace mp
{
void skip_extra_zones_stub(utils::hook::assembler& a)
{
const auto skip = a.newLabel();
const auto original = a.newLabel();
a.pushad64();
a.test(esi, game::DB_ZONE_CUSTOM); // allocFlags
a.jnz(skip);
a.bind(original);
a.popad64();
a.mov(rdx, 0x140809D40);
a.mov(rcx, rbp);
a.call(0x1406FE120);
a.jmp(0x140271B63);
a.bind(skip);
a.popad64();
a.mov(r13d, game::DB_ZONE_CUSTOM);
a.not_(r13d);
a.and_(esi, r13d);
a.jmp(0x140271D02);
}
}
namespace sp
{
void skip_extra_zones_stub(utils::hook::assembler& a)
{
const auto skip = a.newLabel();
const auto original = a.newLabel();
a.pushad64();
a.test(edi, game::DB_ZONE_CUSTOM); // allocFlags
a.jnz(skip);
a.bind(original);
a.popad64();
a.call(0x140379360);
a.xor_(ecx, ecx);
a.test(eax, eax);
a.setz(cl);
a.jmp(0x1401802D6);
a.bind(skip);
a.popad64();
a.mov(r13d, game::DB_ZONE_CUSTOM);
a.not_(r13d);
a.and_(edi, r13d);
a.jmp(0x1401803EF);
}
}
utils::hook::detour db_read_stream_file_hook;
void db_read_stream_file_stub(int a1, int a2)
{
// always use lz4 compressor type when reading stream files
*game::g_compressor = 4;
return db_read_stream_file_hook.invoke<void>(a1, a2);
}
utils::hook::detour sys_createfile_hook;
HANDLE sys_create_file(game::Sys_Folder folder, const char* base_filename)
{
const auto* fs_basepath = game::Dvar_FindVar("fs_basepath");
const auto* fs_game = game::Dvar_FindVar("fs_game");
const std::string dir = fs_basepath ? fs_basepath->current.string : "";
const std::string mod_dir = fs_game ? fs_game->current.string : "";
const std::string name = base_filename;
if (name == "mod.ff")
{
if (!mod_dir.empty())
{
const auto path = utils::string::va("%s\\%s\\%s",
dir.data(), mod_dir.data(), base_filename);
if (utils::io::file_exists(path))
{
return CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, nullptr);
}
}
return INVALID_HANDLE_VALUE;
}
return sys_createfile_hook.invoke<HANDLE>(folder, base_filename);
}
HANDLE sys_create_file_stub(game::Sys_Folder folder, const char* base_filename)
{
return sys_create_file(folder, base_filename);
}
bool try_load_zone(std::string name, bool localized, bool game = false)
{
if (localized)
{
const auto language = game::SEH_GetCurrentLanguageCode();
try_load_zone(language + "_"s + name, false);
if (game::environment::is_mp())
{
try_load_zone(language + "_"s + name + "_mp"s, false);
}
}
if (!fastfiles::exists(name))
{
return false;
}
game::XZoneInfo info{};
info.name = name.data();
info.allocFlags = (game ? game::DB_ZONE_GAME : game::DB_ZONE_COMMON) | game::DB_ZONE_CUSTOM;
info.freeFlags = 0;
game::DB_LoadXAssets(&info, 1u, game::DBSyncMode::DB_LOAD_ASYNC);
return true;
}
void load_pre_gfx_zones(game::XZoneInfo* zoneInfo, unsigned int zoneCount, game::DBSyncMode syncMode)
{
//imagefiles::close_custom_handles();
std::vector<game::XZoneInfo> data;
merge(&data, zoneInfo, zoneCount);
// code_pre_gfx
//weapon::clear_modifed_enums();
try_load_zone("mod_pre_gfx", true);
try_load_zone("s1_mod_pre_gfx", true);
game::DB_LoadXAssets(data.data(), static_cast<std::uint32_t>(data.size()), syncMode);
}
void load_post_gfx_and_ui_and_common_zones(game::XZoneInfo* zoneInfo, unsigned int zoneCount, game::DBSyncMode syncMode)
{
std::vector<game::XZoneInfo> data;
merge(&data, zoneInfo, zoneCount);
// code_post_gfx
// ui
// common
try_load_zone("s1_mod_common", true);
game::DB_LoadXAssets(data.data(), static_cast<std::uint32_t>(data.size()), syncMode);
try_load_zone("mod_common", true);
}
void load_ui_zones(game::XZoneInfo* zoneInfo, unsigned int zoneCount, game::DBSyncMode syncMode)
{
std::vector<game::XZoneInfo> data;
merge(&data, zoneInfo, zoneCount);
// ui
game::DB_LoadXAssets(data.data(), static_cast<std::uint32_t>(data.size()), syncMode);
}
void load_lua_file_asset_stub(void* a1)
{
const auto fastfile = fastfiles::get_current_fastfile();
if (fastfile == "mod")
{
console::error("Mod tried to load a lua file!\n");
return;
}
// TODO: add usermap LUI loading checks
/*
const auto usermap = fastfiles::get_current_usermap();
if (usermap.has_value())
{
const auto& usermap_value = usermap.value();
const auto usermap_load = usermap_value + "_load";
if (fastfile == usermap_value || fastfile == usermap_load)
{
console::error("Usermap tried to load a lua file!\n");
return;
}
}
*/
utils::hook::invoke<void>(0x140276480, a1);
}
utils::hook::detour db_level_load_add_zone_hook;
void db_level_load_add_zone_stub(void* load, const char* name, const unsigned int alloc_flags,
const size_t size_est)
{
if (!strcmp(name, "mp_terminal_cls"))
{
db_level_load_add_zone_hook.invoke<void>(load, name, alloc_flags | game::DB_ZONE_CUSTOM, size_est);
return;
}
db_level_load_add_zone_hook.invoke<void>(load, name, alloc_flags, size_est);
; }
}
std::string get_current_fastfile()
@ -339,35 +85,37 @@ namespace fastfiles
return fastfile_copy;
}
bool exists(const std::string& zone)
constexpr int get_asset_type_size(const game::XAssetType type)
{
const auto is_localized = game::DB_IsLocalized(zone.data());
const auto handle = sys_create_file((is_localized ? game::SF_ZONE_LOC : game::SF_ZONE),
utils::string::va("%s.ff", zone.data()));
if (handle != INVALID_HANDLE_VALUE)
constexpr int asset_type_sizes[] =
{
CloseHandle(handle);
return true;
}
96, 88, 128, 56, 40, 216, 56, 680,
480, 32, 32, 32, 32, 32, 352, 1456,
104, 32, 24, 152, 152, 152, 16, 64,
640, 40, 16, 408, 24, 288, 176, 2800,
48, -1, 40, 24, 200, 88, 16, 120,
3560, 32, 64, 16, 16, -1, -1, -1,
-1, 24, 40, 24, 40, 24, 128, 2256,
136, 32, 72, 24, 64, 88, 48, 32,
96, 152, 64, 32,
};
return false;
return asset_type_sizes[type];
}
void reallocate_asset_pool(game::XAssetType Type, size_t Size)
template <game::XAssetType Type, size_t Size>
char* reallocate_asset_pool()
{
const size_t element_size = game::DB_GetXAssetTypeSize(Type);
auto* new_pool = utils::memory::get_allocator()->allocate(Size * element_size);
constexpr auto element_size = get_asset_type_size(Type);
static char new_pool[element_size * Size] = {0};
assert(get_asset_type_size(Type) == game::DB_GetXAssetTypeSize(Type));
std::memmove(new_pool, game::DB_XAssetPool[Type], game::g_poolSize[Type] * element_size);
game::DB_XAssetPool[Type] = new_pool;
game::g_poolSize[Type] = static_cast<int>(Size);
}
game::g_poolSize[Type] = Size;
template <game::XAssetType Type, size_t Multiplier>
void reallocate_asset_pool_multiplier()
{
reallocate_asset_pool(Type, Multiplier * game::g_poolSize[Type]);
return new_pool;
}
void enum_assets(const game::XAssetType type, const std::function<void(game::XAssetHeader)>& callback, const bool include_override)
@ -379,75 +127,6 @@ namespace fastfiles
}), &callback, include_override);
}
const char* get_zone_name(const unsigned int index)
{
if (game::environment::is_sp())
{
return "";
}
else
{
return game::g_zones[index].name;
}
}
void reallocate_asset_pools()
{
reallocate_asset_pool(game::ASSET_TYPE_FONT, 48);
if (!game::environment::is_sp())
{
reallocate_asset_pool_multiplier<game::ASSET_TYPE_LUA_FILE, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_WEAPON, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_LOCALIZE_ENTRY, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_XANIMPARTS, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_ATTACHMENT, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_FONT, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_SNDDRIVER_GLOBALS, 4>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_EQUIPMENT_SND_TABLE, 4>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_SOUND, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_LOADED_SOUND, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_LEADERBOARD, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_VERTEXDECL, 6>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_COMPUTESHADER, 4>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_REVERB_PRESET, 2>();
reallocate_asset_pool_multiplier<game::ASSET_TYPE_IMPACT_FX, 10>();
}
}
void enum_asset_entries(const game::XAssetType type, const std::function<void(game::XAssetEntry*)>& callback, bool include_override)
{
constexpr auto max_asset_count = 0x1D8A8;
auto hash = &game::db_hashTable[0];
for (auto c = 0; c < max_asset_count; c++)
{
for (auto i = *hash; i; )
{
const auto entry = &game::g_assetEntryPool[i];
if (entry->asset.type == type)
{
callback(entry);
if (include_override && entry->nextOverride)
{
auto next_ovveride = entry->nextOverride;
while (next_ovveride)
{
const auto override = &game::g_assetEntryPool[next_ovveride];
callback(override);
next_ovveride = override->nextOverride;
}
}
}
i = entry->nextHash;
}
++hash;
}
}
class component final : public component_interface
{
public:
@ -456,8 +135,7 @@ namespace fastfiles
db_try_load_x_file_internal_hook.create(SELECT_VALUE(0x1401816F0, 0x1402741C0), &db_try_load_x_file_internal);
db_find_x_asset_header_hook.create(game::DB_FindXAssetHeader, db_find_x_asset_header_stub);
db_link_xasset_entry1_hook.create(SELECT_VALUE(0x14017F390, 0x1402708F0), db_link_xasset_entry1);
dvars::g_dump_scripts = game::Dvar_RegisterBool("g_dumpScripts", false, game::DVAR_FLAG_NONE);
dvars::g_dump_scripts = game::Dvar_RegisterBool("g_dumpScripts", false, game::DVAR_FLAG_NONE, "Dump GSC scripts to binary format");
command::add("loadzone", [](const command::params& params)
{
@ -469,7 +147,7 @@ namespace fastfiles
game::XZoneInfo info{};
info.name = params.get(1);
info.allocFlags = game::DB_ZONE_COMMON | game::DB_ZONE_CUSTOM;
info.allocFlags = 1;
info.freeFlags = 0;
game::DB_LoadXAssets(&info, 1u, game::DBSyncMode::DB_LOAD_SYNC);
});
@ -482,50 +160,16 @@ namespace fastfiles
}
});
#ifdef DEBUG
//reallocate_asset_pools();
#endif
reallocate_asset_pool<game::ASSET_TYPE_FONT, 48>();
// Allow loading of unsigned fastfiles
if (!game::environment::is_sp())
{
utils::hook::nop(0x1402427A5, 2); // DB_InflateInit
}
// Don't load extra zones with loadzone
if (game::environment::is_sp())
{
utils::hook::nop(0x1401802CA, 12);
utils::hook::jump(0x1401802CA, utils::hook::assemble(sp::skip_extra_zones_stub), true);
}
else
{
utils::hook::nop(0x140271B54, 15);
utils::hook::jump(0x140271B54, utils::hook::assemble(mp::skip_extra_zones_stub), true);
// dont load localized zone for custom maps (proper patch for this is here: https://github.com/auroramod/h1-mod/blob/develop/src/client/component/fastfiles.cpp#L442)
db_level_load_add_zone_hook.create(0x1402705C0, db_level_load_add_zone_stub);
}
// Allow loading of mixed compressor types
utils::hook::nop(SELECT_VALUE(0x1401536D7, 0x140242DF7), 2);
// Fix compressor type on streamed file load
db_read_stream_file_hook.create(SELECT_VALUE(0x140187450, 0x14027AA70), db_read_stream_file_stub);
// Add custom zone paths
sys_createfile_hook.create(game::Sys_CreateFile, sys_create_file_stub);
// load our custom ui and common zones
utils::hook::call(SELECT_VALUE(0x140487CF8, 0x1405A562A), load_post_gfx_and_ui_and_common_zones);
// load our custom ui zones
utils::hook::call(SELECT_VALUE(0x1402F91D4, 0x1403D06FC), load_ui_zones);
// prevent mod.ff from loading lua files
if (game::environment::is_mp())
{
utils::hook::call(0x14024F1B4, load_lua_file_asset_stub);
const auto* xmodel_pool = reallocate_asset_pool<game::ASSET_TYPE_XMODEL, 8832>();
utils::hook::inject(0x14026FD63, xmodel_pool + 8);
utils::hook::inject(0x14026FDB3, xmodel_pool + 8);
utils::hook::inject(0x14026FFAC, xmodel_pool + 8);
utils::hook::inject(0x14027463C, xmodel_pool + 8);
utils::hook::inject(0x140274689, xmodel_pool + 8);
}
}
};

View File

@ -6,11 +6,5 @@ namespace fastfiles
{
std::string get_current_fastfile();
bool exists(const std::string& zone);
void enum_assets(game::XAssetType type, const std::function<void(game::XAssetHeader)>& callback, bool include_override);
const char* get_zone_name(const unsigned int index);
void enum_asset_entries(const game::XAssetType type, const std::function<void(game::XAssetEntry*)>& callback, bool include_override);
}

View File

@ -67,11 +67,6 @@ namespace filesystem
register_path("s1");
register_path(get_binary_directory() + "\\data");
if (get_binary_directory() != std::filesystem::current_path())
{
register_path(std::filesystem::current_path() / "data");
}
// game's search paths
register_path("devraw");
register_path("devraw_shared");

View File

@ -137,9 +137,9 @@ namespace fps
}
}
const game::dvar_t* cg_draw_fps_register_stub(const char* dvar_name, const char** value_list, const int default_index, unsigned int /*flags*/)
const game::dvar_t* cg_draw_fps_register_stub(const char* dvar_name, const char** value_list, const int default_index, unsigned int /*flags*/, const char* description)
{
cg_drawFPS = game::Dvar_RegisterEnum(dvar_name, value_list, default_index, game::DVAR_FLAG_SAVED);
cg_drawFPS = game::Dvar_RegisterEnum(dvar_name, value_list, default_index, game::DVAR_FLAG_SAVED, description);
return cg_drawFPS;
}
}
@ -173,12 +173,12 @@ namespace fps
scheduler::loop(cg_draw_fps, scheduler::pipeline::renderer);
if (game::environment::is_mp())
{
cg_drawPing = game::Dvar_RegisterInt("cg_drawPing", 0, 0, 1, game::DVAR_FLAG_SAVED);
cg_drawPing = game::Dvar_RegisterInt("cg_drawPing", 0, 0, 1, game::DVAR_FLAG_SAVED, "Draw ping");
scheduler::loop(cg_draw_ping, scheduler::pipeline::renderer);
}
game::Dvar_RegisterBool("cg_infobar_ping", false, game::DVAR_FLAG_SAVED);
game::Dvar_RegisterBool("cg_infobar_fps", false, game::DVAR_FLAG_SAVED);
game::Dvar_RegisterBool("cg_infobar_ping", false, game::DVAR_FLAG_SAVED, "Show server latency");
game::Dvar_RegisterBool("cg_infobar_fps", false, game::DVAR_FLAG_SAVED, "Show FPS counter");
}
};
}

View File

@ -746,30 +746,33 @@ namespace game_console
// add our dvars
dvars::con_inputBoxColor = game::Dvar_RegisterVec4("con_inputBoxColor", 0.2f, 0.2f, 0.2f, 0.9f, 0.0f, 1.0f,
game::DVAR_FLAG_SAVED);
game::DVAR_FLAG_SAVED,
"color of console input box");
dvars::con_inputHintBoxColor = game::Dvar_RegisterVec4("con_inputHintBoxColor", 0.3f, 0.3f, 0.3f, 1.0f,
0.0f, 1.0f,
game::DVAR_FLAG_SAVED);
game::DVAR_FLAG_SAVED, "color of console input hint box");
dvars::con_outputBarColor = game::Dvar_RegisterVec4("con_outputBarColor", 0.5f, 0.5f, 0.5f, 0.6f, 0.0f,
1.0f, game::DVAR_FLAG_SAVED);
1.0f, game::DVAR_FLAG_SAVED,
"color of console output bar");
dvars::con_outputSliderColor = game::Dvar_RegisterVec4("con_outputSliderColor", 1.0f, 0.8f, 0.0f, 1.0f,
0.0f, 1.0f,
game::DVAR_FLAG_SAVED);
game::DVAR_FLAG_SAVED, "color of console output slider");
dvars::con_outputWindowColor = game::Dvar_RegisterVec4("con_outputWindowColor", 0.25f, 0.25f, 0.25f, 0.85f,
0.0f,
1.0f, game::DVAR_FLAG_SAVED);
1.0f, game::DVAR_FLAG_SAVED, "color of console output window");
dvars::con_inputDvarMatchColor = game::Dvar_RegisterVec4("con_inputDvarMatchColor", 1.0f, 1.0f, 0.8f, 1.0f,
0.0f,
1.0f, game::DVAR_FLAG_SAVED);
1.0f, game::DVAR_FLAG_SAVED, "color of console matched dvar");
dvars::con_inputDvarValueColor = game::Dvar_RegisterVec4("con_inputDvarValueColor", 1.0f, 1.0f, 0.8f, 1.0f,
0.0f,
1.0f, game::DVAR_FLAG_SAVED);
1.0f, game::DVAR_FLAG_SAVED, "color of console matched dvar value");
dvars::con_inputDvarInactiveValueColor = game::Dvar_RegisterVec4(
"con_inputDvarInactiveValueColor", 0.8f, 0.8f,
0.8f, 1.0f, 0.0f, 1.0f, game::DVAR_FLAG_SAVED);
0.8f, 1.0f, 0.0f, 1.0f, game::DVAR_FLAG_SAVED,
"color of console inactive dvar value");
dvars::con_inputCmdMatchColor = game::Dvar_RegisterVec4("con_inputCmdMatchColor", 0.80f, 0.80f, 1.0f, 1.0f,
0.0f,
1.0f, game::DVAR_FLAG_SAVED);
1.0f, game::DVAR_FLAG_SAVED, "color of console matched command");
}
};
}

View File

@ -81,7 +81,7 @@ namespace game_log
scheduler::once([]
{
dvars::g_log = game::Dvar_RegisterString("g_log", "logs/games_mp.log", game::DVAR_FLAG_NONE);
dvars::g_log = game::Dvar_RegisterString("g_log", "logs/games_mp.log", game::DVAR_FLAG_NONE, "Log file name");
}, scheduler::pipeline::main);
scripting::on_init([]
@ -102,9 +102,9 @@ namespace game_log
g_log_printf("InitGame\n");
});
scripting::on_shutdown([](const int clear_scripts) -> void
scripting::on_shutdown([](int free_scripts)
{
console::info("==== ShutdownGame (%d) ====\n", clear_scripts);
console::info("==== ShutdownGame (%d) ====\n", free_scripts);
g_log_printf("ShutdownGame:\n");
g_log_printf("------------------------------------------------------------\n");

View File

@ -144,45 +144,64 @@ namespace gameplay
public:
void post_unpack() override
{
dvars::player_sustainAmmo = game::Dvar_RegisterBool("player_sustainAmmo", false, game::DVAR_FLAG_REPLICATED);
dvars::player_sustainAmmo = game::Dvar_RegisterBool("player_sustainAmmo", false,
game::DVAR_FLAG_REPLICATED, "Firing weapon will not decrease clip ammo");
pm_weapon_use_ammo_hook.create(SELECT_VALUE(0x1403DD050, 0x140162B20), &pm_weapon_use_ammo_stub);
if (game::environment::is_sp()) return;
// Implement player ejection dvar
dvars::g_playerEjection = game::Dvar_RegisterBool("g_playerEjection", true, game::DVAR_FLAG_REPLICATED);
dvars::g_playerEjection = game::Dvar_RegisterBool("g_playerEjection", true, game::DVAR_FLAG_REPLICATED,
"Flag whether player ejection is on or off");
utils::hook::call(0x1402D5E4A, stuck_in_client_stub);
// Implement player collision dvar
dvars::g_playerCollision = game::Dvar_RegisterBool("g_playerCollision", true, game::DVAR_FLAG_REPLICATED);
dvars::g_playerCollision = game::Dvar_RegisterBool("g_playerCollision", true, game::DVAR_FLAG_REPLICATED,
"Flag whether player collision is on or off");
utils::hook::call(0x1404563DA, cm_transformed_capsule_trace_stub); // SV_ClipMoveToEntity
utils::hook::call(0x1401F7F8F, cm_transformed_capsule_trace_stub); // CG_ClipMoveToEntity
// Implement bouncing dvar
utils::hook::jump(0x14014DF91, pm_bouncing_stub_mp, true);
dvars::pm_bouncing = game::Dvar_RegisterBool("pm_bouncing", false, game::DVAR_FLAG_REPLICATED);
dvars::pm_bouncing = game::Dvar_RegisterBool("pm_bouncing", false,
game::DVAR_FLAG_REPLICATED, "Enable bouncing");
// Change jump_slowdownEnable dvar flags to just "replicated"
utils::hook::set<uint8_t>(0x140135992, game::DVAR_FLAG_REPLICATED);
// Choosing the following min/max because the game would truncate larger values
dvars::g_gravity = game::Dvar_RegisterInt("g_gravity", 800, std::numeric_limits<short>::min(), std::numeric_limits<short>::max(), game::DVAR_FLAG_REPLICATED);
dvars::g_gravity = game::Dvar_RegisterInt("g_gravity", 800, std::numeric_limits<short>::min(),
std::numeric_limits<short>::max(), game::DVAR_FLAG_REPLICATED, "Gravity in inches per second per second");
utils::hook::jump(0x1402D5A5D, client_end_frame_stub, true);
utils::hook::nop(0x1402D5A69, 1); // Nop skipped opcode
// Choosing the following min/max because the game would truncate larger values
dvars::g_speed = game::Dvar_RegisterInt("g_speed", 190, std::numeric_limits<short>::min(), std::numeric_limits<short>::max(), game::DVAR_FLAG_REPLICATED);
dvars::g_speed = game::Dvar_RegisterInt("g_speed", 190,
std::numeric_limits<short>::min(), std::numeric_limits<short>::max(), game::DVAR_FLAG_REPLICATED, "Player speed");
utils::hook::jump(0x1402D6A8C, client_think_real_stub, true);
utils::hook::nop(0x1402D6A98, 4); // Nop skipped opcodes
dvars::jump_height = game::Dvar_RegisterFloat("jump_height", 39.0f, 0.0f, 1000.0f, game::DVAR_FLAG_REPLICATED);
auto* timescale = game::Dvar_RegisterFloat("timescale", 1.0f, 0.1f, 50.0f, game::DVAR_FLAG_REPLICATED, "Changes Timescale of the game");
utils::hook::inject(0x1403CF5B0 + 4, &timescale->current.value); // Com_GetTimeScale
utils::hook::inject(0x1403D0BDD + 6, &timescale->current.value); // Com_Restart
utils::hook::inject(0x1403D19C5 + 4, &timescale->current.value); // Com_SetSlowMotion
utils::hook::inject(0x1403D1A25 + 4, &timescale->current.value); // ^
utils::hook::inject(0x1403D1A6B + 4, &timescale->current.value); // ^
utils::hook::inject(0x1403D1E2C + 4, &timescale->current.value); // Com_TimeScaleMsec
utils::hook::inject(0x1403D219E + 4, &timescale->current.value); // Com_UpdateSlowMotion
utils::hook::inject(0x1403D21C8 + 4, &timescale->current.value); // ^
dvars::jump_height = game::Dvar_RegisterFloat("jump_height", 39.0f,
0.0f, 1000.0f, game::DVAR_FLAG_REPLICATED, "The maximum height of a player's jump");
utils::hook::call(0x1401352FF, jump_start_stub);
dvars::jump_ladderPushVel = game::Dvar_RegisterFloat("jump_ladderPushVel", 128.0f, 0.0f, 1024.0f, game::DVAR_FLAG_REPLICATED);
dvars::jump_ladderPushVel = game::Dvar_RegisterFloat("jump_ladderPushVel", 128.0f,
0.0f, 1024.0f, game::DVAR_FLAG_REPLICATED, "The velocity of a jump off of a ladder");
utils::hook::jump(0x1401358B3, jump_push_off_ladder, true);
utils::hook::nop(0x1401358BF, 4); // Nop skipped opcodes
dvars::g_elevators = game::Dvar_RegisterBool("g_elevators", false, game::DVAR_FLAG_REPLICATED);
dvars::g_elevators = game::Dvar_RegisterBool("g_elevators", false,
game::DVAR_FLAG_REPLICATED, "Enable elevators");
utils::hook::call(0x140146134, pm_player_trace_stub);
utils::hook::call(0x14014619B, pm_player_trace_stub);

View File

@ -186,6 +186,100 @@ namespace gsc
}
}
}
void scr_get_vector(unsigned int index, float* vector_value)
{
if (index < game::scr_VmPub->outparamcount)
{
auto* value = game::scr_VmPub->top - index;
if (value->type == game::VAR_VECTOR)
{
std::memcpy(vector_value, value->u.vectorValue, sizeof(std::float_t[3]));
return;
}
scr_error(va("Type %s is not a vector", var_typename[value->type]));
}
scr_error(va("Parameter %u does not exist", index + 1));
}
int scr_get_int(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
auto* value = game::scr_VmPub->top - index;
if (value->type == game::VAR_INTEGER)
{
return value->u.intValue;
}
scr_error(va("Type %s is not an int", var_typename[value->type]));
}
scr_error(va("Parameter %u does not exist", index + 1));
return 0;
}
float scr_get_float(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
auto* value = game::scr_VmPub->top - index;
if (value->type == game::VAR_FLOAT)
{
return value->u.floatValue;
}
if (value->type == game::VAR_INTEGER)
{
return static_cast<float>(value->u.intValue);
}
scr_error(va("Type %s is not a float", var_typename[value->type]));
}
scr_error(va("Parameter %u does not exist", index + 1));
return 0.0f;
}
int scr_get_pointer_type(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
if ((game::scr_VmPub->top - index)->type == game::VAR_POINTER)
{
return static_cast<int>(game::GetObjectType((game::scr_VmPub->top - index)->u.uintValue));
}
scr_error(va("Type %s is not an object", var_typename[(game::scr_VmPub->top - index)->type]));
}
scr_error(va("Parameter %u does not exist", index + 1));
return 0;
}
int scr_get_type(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
return (game::scr_VmPub->top - index)->type;
}
scr_error(va("Parameter %u does not exist", index + 1));
return 0;
}
const char* scr_get_type_name(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
return var_typename[(game::scr_VmPub->top - index)->type];
}
scr_error(va("Parameter %u does not exist", index + 1));
return nullptr;
}
}
std::optional<std::pair<std::string, std::string>> find_function(const char* pos)
@ -205,130 +299,34 @@ namespace gsc
return {};
}
void scr_get_vector(unsigned int index, float* vector_value)
{
if (index < game::scr_VmPub->outparamcount)
{
auto* value = game::scr_VmPub->top - index;
if (value->type == game::VAR_VECTOR)
{
std::memcpy(vector_value, value->u.vectorValue, sizeof(std::float_t[3]));
return;
}
scr_error(va("Type %s is not a vector", var_typename[value->type]));
}
scr_error(va("Parameter %u does not exist", index + 1));
}
int scr_get_int(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
auto* value = game::scr_VmPub->top - index;
if (value->type == game::VAR_INTEGER)
{
return value->u.intValue;
}
scr_error(va("Type %s is not an int", var_typename[value->type]));
}
scr_error(va("Parameter %u does not exist", index + 1));
return 0;
}
float scr_get_float(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
auto* value = game::scr_VmPub->top - index;
if (value->type == game::VAR_FLOAT)
{
return value->u.floatValue;
}
if (value->type == game::VAR_INTEGER)
{
return static_cast<float>(value->u.intValue);
}
scr_error(va("Type %s is not a float", var_typename[value->type]));
}
scr_error(va("Parameter %u does not exist", index + 1));
return 0.0f;
}
int scr_get_pointer_type(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
if ((game::scr_VmPub->top - index)->type == game::VAR_POINTER)
{
return static_cast<int>(game::GetObjectType((game::scr_VmPub->top - index)->u.uintValue));
}
scr_error(va("Type %s is not an object", var_typename[(game::scr_VmPub->top - index)->type]));
}
scr_error(va("Parameter %u does not exist", index + 1));
return 0;
}
int scr_get_type(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
return (game::scr_VmPub->top - index)->type;
}
scr_error(va("Parameter %u does not exist", index + 1));
return 0;
}
const char* scr_get_type_name(unsigned int index)
{
if (index < game::scr_VmPub->outparamcount)
{
return var_typename[(game::scr_VmPub->top - index)->type];
}
scr_error(va("Parameter %u does not exist", index + 1));
return nullptr;
}
class error final : public component_interface
{
public:
void post_unpack() override
{
scr_emit_function_hook.create(SELECT_VALUE(0x1403113D0, 0x1403ED900), &scr_emit_function_stub);
utils::hook::call(SELECT_VALUE(0x140311364, 0x1403ED894), compile_error_stub); // LinkFile
utils::hook::call(SELECT_VALUE(0x1403113B8, 0x1403ED8E8), compile_error_stub); // LinkFile
utils::hook::call(SELECT_VALUE(0x1403114AA, 0x1403ED9DB), find_variable_stub); // Scr_EmitFunction
// Restore basic error messages for commonly used scr functions
utils::hook::jump(SELECT_VALUE(0x14031BD80, 0x1403F8510), scr_get_const_string);
utils::hook::jump(game::Scr_GetInt, scr_get_int);
utils::hook::jump(game::Scr_GetFloat, scr_get_float);
utils::hook::jump(game::Scr_GetVector, scr_get_vector);
utils::hook::jump(SELECT_VALUE(0x14031C690, 0x1403F8D70), scr_get_type);
utils::hook::jump(SELECT_VALUE(0x14031C700, 0x1403F8DE0), scr_get_type_name);
if (game::environment::is_sp())
{
return;
}
scr_emit_function_hook.create(0x1403ED900, &scr_emit_function_stub);
utils::hook::call(0x1403ED894, compile_error_stub); // LinkFile
utils::hook::call(0x1403ED8E8, compile_error_stub); // LinkFile
utils::hook::call(0x1403ED9DB, find_variable_stub); // Scr_EmitFunction
// Restore basic error messages for commonly used scr functions
utils::hook::jump(0x1403F8990, scr_get_object);
utils::hook::jump(0x1403F8510, scr_get_const_string);
utils::hook::jump(0x1403F82F0, scr_get_const_istring);
utils::hook::jump(0x140327870, scr_validate_localized_string_ref);
utils::hook::jump(0x1403F8EC0, scr_get_vector);
utils::hook::jump(0x1403F88D0, scr_get_int);
utils::hook::jump(0x1403F8820, scr_get_float);
utils::hook::jump(0x1403F8BA0, scr_get_pointer_type);
utils::hook::jump(0x1403F8D70, scr_get_type);
utils::hook::jump(0x1403F8DE0, scr_get_type_name);
}
void pre_destroy() override

View File

@ -3,11 +3,4 @@
namespace gsc
{
std::optional<std::pair<std::string, std::string>> find_function(const char* pos);
void scr_get_vector(unsigned int index, float* vector_value);
int scr_get_int(unsigned int index);
float scr_get_float(unsigned int index);
int scr_get_pointer_type(unsigned int index);
int scr_get_type(unsigned int index);
const char* scr_get_type_name(unsigned int index);
}

View File

@ -5,15 +5,15 @@
#include "game/scripting/functions.hpp"
#include "component/command.hpp"
#include <utils/hook.hpp>
#include "component/console.hpp"
#include "component/notifies.hpp"
#include "component/command.hpp"
#include "script_error.hpp"
#include "script_extension.hpp"
#include "script_loading.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
namespace gsc
@ -39,60 +39,9 @@ namespace gsc
utils::hook::detour scr_register_function_hook;
std::vector<devmap_entry> devmap_entries{};
std::optional<devmap_entry> get_devmap_entry(const std::uint8_t* codepos)
{
const auto itr = std::ranges::find_if(devmap_entries, [codepos](const devmap_entry& entry) -> bool
{
return codepos >= entry.bytecode && codepos < entry.bytecode + entry.size;
});
if (itr != devmap_entries.end())
{
return *itr;
}
return {};
}
std::optional<std::pair<std::uint16_t, std::uint16_t>> get_line_and_col_for_codepos(const std::uint8_t* codepos)
{
const auto entry = get_devmap_entry(codepos);
if (!entry.has_value())
{
return {};
}
std::optional<std::pair<std::uint16_t, std::uint16_t>> best_line_info{};
std::uint32_t best_codepos = 0;
assert(codepos >= entry->bytecode);
const std::uint32_t codepos_offset = static_cast<std::uint32_t>(codepos - entry->bytecode);
for (const auto& instruction : entry->devmap)
{
if (instruction.codepos > codepos_offset)
{
continue;
}
if (best_line_info.has_value() && codepos_offset - instruction.codepos > codepos_offset - best_codepos)
{
continue;
}
best_line_info = { { instruction.line, instruction.col } };
best_codepos = instruction.codepos;
}
return best_line_info;
}
unsigned int scr_get_function_stub(const char** p_name, int* type)
{
const auto result = game::Scr_GetFunction(p_name, type);
const auto result = utils::hook::invoke<unsigned int>(0x1403318B0, p_name, type);
for (const auto& [name, func] : functions)
{
@ -173,36 +122,27 @@ namespace gsc
const auto pos = frame == game::scr_VmPub->function_frame ? game::scr_function_stack->pos : frame->fs.pos;
const auto function = find_function(frame->fs.pos);
const char* location;
if (function.has_value())
{
location = utils::string::va("function \"%s\" in file \"%s\"", function.value().first.data(), function.value().second.data());
console::warn("\tat function \"%s\" in file \"%s.gsc\"\n", function.value().first.data(), function.value().second.data());
}
else
{
location = utils::string::va("unknown location %p", pos);
console::warn("\tat unknown location %p\n", pos);
}
const auto line_info = get_line_and_col_for_codepos(reinterpret_cast<const std::uint8_t*>(pos));
if (line_info.has_value())
{
location = utils::string::va("%s line \"%d\" column \"%d\"", location, line_info->first, line_info->second);
}
console::warn("\tat %s\n", location);
}
}
void vm_error_stub(unsigned __int64 mark_pos)
void vm_error_stub(int mark_pos)
{
if (!dvars::com_developer_script->current.enabled && !force_error_print)
{
game::LargeLocalResetToMark(mark_pos);
utils::hook::invoke<void>(0x1404B6790, mark_pos);
return;
}
console::warn("******* script runtime error ********\n");
const auto opcode_id = *reinterpret_cast<std::uint8_t*>(SELECT_VALUE(0x14A19DE68, 0x148806768));
const auto opcode_id = *reinterpret_cast<std::uint8_t*>(0x148806768);
const std::string error = gsc_error_msg.has_value() ? std::format(": {}", gsc_error_msg.value()) : std::string();
@ -228,7 +168,7 @@ namespace gsc
print_callstack();
console::warn("************************************\n");
game::LargeLocalResetToMark(mark_pos);
utils::hook::invoke<void>(0x1404B6790, mark_pos);
}
void scr_register_function_stub(void* func, int type, unsigned int name)
@ -279,46 +219,6 @@ namespace gsc
{
scr_error(utils::string::va("Assert fail: %s", game::Scr_GetString(0)));
}
void scr_cmd_is_dedicated_server()
{
game::Scr_AddInt(game::environment::is_dedi());
}
const char* get_code_pos(const int index)
{
if (static_cast<unsigned int>(index) >= game::scr_VmPub->outparamcount)
{
scr_error("Scr_GetCodePos: index is out of range");
return "";
}
const auto* value = &game::scr_VmPub->top[-index];
if (value->type != game::VAR_FUNCTION)
{
scr_error("Scr_GetCodePos requires a function as parameter");
return "";
}
return value->u.codePosValue;
}
}
void add_devmap_entry(std::uint8_t* codepos, std::size_t size, const std::string& name, xsk::gsc::buffer devmap_buf)
{
std::vector<dev_map_instruction> devmap{};
const auto* devmap_ptr = reinterpret_cast<const dev_map*>(devmap_buf.data);
devmap.resize(devmap_ptr->num_instructions);
std::memcpy(devmap.data(), devmap_ptr->instructions, sizeof(dev_map_instruction) * devmap_ptr->num_instructions);
devmap_entries.emplace_back(codepos, size, name, std::move(devmap));
}
void clear_devmap()
{
devmap_entries.clear();
}
void scr_error(const char* error)
@ -352,40 +252,33 @@ namespace gsc
override_function("print", &scr_print);
override_function("println", &scr_print_ln);
utils::hook::set<std::uint32_t>(SELECT_VALUE(0x1403115BC, 0x1403EDAEC), 0x1000); // Scr_RegisterFunction
utils::hook::set<std::uint32_t>(SELECT_VALUE(0x1403115C2 + 4, 0x1403EDAF2 + 4), RVA(&func_table)); // Scr_RegisterFunction
utils::hook::set<std::uint32_t>(SELECT_VALUE(0x14031F097 + 3, 0x1403FB7F7 + 3), RVA(&func_table)); // VM_Execute_0
utils::hook::inject(SELECT_VALUE(0x140311964 + 3, 0x1403EDEE4 + 3), &func_table); // Scr_BeginLoadScripts
if (game::environment::is_sp())
{
return;
}
utils::hook::nop(0x1403FB7F7 + 5, 2);
utils::hook::call(0x1403FB7F7, vm_call_builtin_function);
utils::hook::call(0x1403FCAB0, vm_error_stub); // LargeLocalResetToMark
utils::hook::call(0x1403EDF1F, scr_get_function_stub);
override_function("assert", &assert_cmd);
override_function("assertex", &assert_ex_cmd);
override_function("assertmsg", &assert_msg_cmd);
override_function("isdedicatedserver", &scr_cmd_is_dedicated_server);
add_function("replacefunc", []
{
if (scr_get_type(0) != game::VAR_FUNCTION || scr_get_type(1) != game::VAR_FUNCTION)
{
throw gsc_error("Parameter must be a function");
}
notifies::set_gsc_hook(get_code_pos(0), get_code_pos(1));
});
add_function("executecommand", []() -> void
add_function("executecommand", []
{
const auto* cmd = game::Scr_GetString(0);
command::execute(cmd);
});
utils::hook::set<std::uint32_t>(SELECT_VALUE(0x1403115BC, 0x1403EDAEC), 0x1000); // Scr_RegisterFunction
utils::hook::set<std::uint32_t>(SELECT_VALUE(0x1403115C2 + 4, 0x1403EDAF2 + 4), RVA(&func_table)); // Scr_RegisterFunction
// utils::hook::set<std::uint32_t>(SELECT_VALUE(0x14031F097 + 3, 0x1403FB7F7 + 3), RVA(&func_table)); // VM_Execute_0
utils::hook::inject(SELECT_VALUE(0x140311964 + 3, 0x1403EDEE4 + 3), &func_table); // Scr_BeginLoadScripts
utils::hook::nop(SELECT_VALUE(0x14031F097 + 5, 0x1403FB7F7 + 5), 2);
utils::hook::call(SELECT_VALUE(0x14031F097, 0x1403FB7F7), vm_call_builtin_function);
utils::hook::call(SELECT_VALUE(0x14032034F, 0x1403FCAB0), vm_error_stub); // LargeLocalResetToMark
utils::hook::call(SELECT_VALUE(0x14031199F, 0x1403EDF1F), scr_get_function_stub);
}
};
}

View File

@ -1,36 +1,9 @@
#pragma once
#include <xsk/gsc/engine/s1_pc.hpp>
namespace gsc
{
extern void* func_table[0x1000];
#pragma pack(push, 1)
struct dev_map_instruction
{
std::uint32_t codepos;
std::uint16_t line;
std::uint16_t col;
};
struct dev_map
{
std::uint32_t num_instructions;
dev_map_instruction instructions[1];
};
#pragma pack(pop)
struct devmap_entry
{
const std::uint8_t* bytecode;
std::size_t size;
std::string script_name;
std::vector<dev_map_instruction> devmap;
};
void add_devmap_entry(std::uint8_t*, std::size_t, const std::string&, xsk::gsc::buffer);
void clear_devmap();
void scr_error(const char* error);
void override_function(const std::string& name, game::BuiltinFunction func);
void add_function(const std::string& name, game::BuiltinFunction function);

View File

@ -12,7 +12,6 @@
#include "component/console.hpp"
#include "component/scripting.hpp"
#include "script_extension.hpp"
#include "script_loading.hpp"
namespace gsc
@ -33,7 +32,6 @@ namespace gsc
init_handles.clear();
loaded_scripts.clear();
script_allocator.clear();
clear_devmap();
}
bool read_raw_script_file(const std::string& name, std::string* data)
@ -117,12 +115,6 @@ namespace gsc
loaded_scripts[real_name] = script_file_ptr;
const auto devmap = std::get<2>(output_script);
if (devmap.size > 0 && (gsc_ctx->build() & xsk::gsc::build::dev_maps) != xsk::gsc::build::prod)
{
add_devmap_entry(script_file_ptr->bytecode, byte_code_size, real_name, devmap);
}
return script_file_ptr;
}
catch (const std::exception& ex)
@ -189,10 +181,13 @@ namespace gsc
}
}
void load_scripts_from_folder(const std::filesystem::path& root_dir, const std::filesystem::path& script_dir)
void load_scripts(const std::filesystem::path& root_dir)
{
console::info("Scanning directory '%s' for custom GSC scripts...\n", script_dir.generic_string().data());
const std::filesystem::path script_dir = root_dir / "scripts";
if (!utils::io::directory_exists(script_dir.generic_string()))
{
return;
}
const auto scripts = utils::io::list_files(script_dir.generic_string());
for (const auto& script : scripts)
@ -210,44 +205,6 @@ namespace gsc
}
}
void load_scripts(const std::filesystem::path& root_dir)
{
const auto load = [&root_dir](const std::filesystem::path& folder) -> void
{
const std::filesystem::path script_dir = root_dir / folder;
if (utils::io::directory_exists(script_dir.generic_string()))
{
load_scripts_from_folder(root_dir, script_dir);
}
};
const std::filesystem::path base_dir = "scripts";
load(base_dir);
const auto* map_name = game::Dvar_FindVar("mapname");
if (game::environment::is_sp())
{
const std::filesystem::path game_folder = "sp";
load(base_dir / game_folder);
load(base_dir / game_folder / map_name->current.string);
}
else
{
const std::filesystem::path game_folder = "mp";
load(base_dir / game_folder);
load(base_dir / game_folder / map_name->current.string);
const auto* game_type = game::Dvar_FindVar("g_gametype");
load(base_dir / game_folder / game_type->current.string);
}
}
int db_is_x_asset_default(game::XAssetType type, const char* name)
{
if (loaded_scripts.contains(name))
@ -267,6 +224,8 @@ namespace gsc
return;
}
clear();
for (const auto& path : filesystem::get_search_paths())
{
load_scripts(path);
@ -300,38 +259,7 @@ namespace gsc
utils::hook::invoke<void>(0x1403380D0);
}
int g_scr_set_level_script_stub(game::ScriptFunctions* functions)
{
const auto result = utils::hook::invoke<int>(0x140262F60, functions);
for (const auto& path : filesystem::get_search_paths())
{
load_scripts(path);
}
return result;
}
void scr_load_level_singleplayer_stub()
{
for (auto& function_handle : main_handles)
{
console::info("Executing '%s::main'\n", function_handle.first.data());
const auto thread = game::Scr_ExecThread(static_cast<int>(function_handle.second), 0);
game::RemoveRefToObject(thread);
}
utils::hook::invoke<void>(0x140257720);
for (auto& function_handle : init_handles)
{
console::info("Executing '%s::init'\n", function_handle.first.data());
const auto thread = game::Scr_ExecThread(static_cast<int>(function_handle.second), 0);
game::RemoveRefToObject(thread);
}
}
void scr_load_level_multiplayer_stub()
void scr_load_level_stub()
{
utils::hook::invoke<void>(0x140325B90);
@ -430,32 +358,28 @@ namespace gsc
utils::hook::call(SELECT_VALUE(0x1403309E9, 0x1403309E9), scr_begin_load_scripts_stub); // GScr_LoadScripts
utils::hook::call(SELECT_VALUE(0x14023DA84, 0x140330B9C), scr_end_load_scripts_stub); // GScr_LoadScripts
// ProcessScript
utils::hook::call(SELECT_VALUE(0x14031AB47, 0x1403F7317), find_script);
utils::hook::call(SELECT_VALUE(0x14031AB57, 0x1403F7327), db_is_x_asset_default);
dvars::com_developer = game::Dvar_RegisterInt("developer", 0, 0, 2, game::DVAR_FLAG_NONE);
dvars::com_developer_script = game::Dvar_RegisterBool("developer_script", false, game::DVAR_FLAG_NONE);
dvars::com_developer = game::Dvar_RegisterInt("developer", 0, 0, 2, game::DVAR_FLAG_NONE, "Enable development options");
dvars::com_developer_script = game::Dvar_RegisterBool("developer_script", false, game::DVAR_FLAG_NONE, "Enable developer script comments");
if (game::environment::is_sp())
{
utils::hook::call(0x1402632A5, g_scr_set_level_script_stub);
utils::hook::call(0x140226931, scr_load_level_singleplayer_stub);
}
else
{
// GScr_LoadScripts
utils::hook::call(0x140330B97, gscr_post_load_scripts_stub);
// Exec script handles
utils::hook::call(0x1402F71AE, g_load_structs_stub);
utils::hook::call(0x1402F71C7, scr_load_level_multiplayer_stub);
return;
}
scripting::on_shutdown([](const int clear_scripts) -> void
// ProcessScript
utils::hook::call(0x1403F7317, find_script);
utils::hook::call(0x1403F7327, db_is_x_asset_default);
// GScr_LoadScripts
utils::hook::call(0x140330B97, gscr_post_load_scripts_stub);
// Exec script handles
utils::hook::call(0x1402F71AE, g_load_structs_stub);
utils::hook::call(0x1402F71C7, scr_load_level_stub);
scripting::on_shutdown([](int free_scripts)
{
if (clear_scripts)
if (free_scripts)
{
clear();
}

View File

@ -1,239 +0,0 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "console.hpp"
#include "filesystem.hpp"
#include "fastfiles.hpp"
#include "scheduler.hpp"
#include "imagefiles.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
#include <utils/io.hpp>
#include <utils/concurrency.hpp>
#define CUSTOM_IMAGE_FILE_INDEX 96
namespace imagefiles
{
namespace
{
utils::memory::allocator image_file_allocator;
std::unordered_map<std::string, HANDLE> image_file_handles;
std::string get_image_file_name()
{
return fastfiles::get_current_fastfile();
}
namespace mp
{
struct image_file_unk
{
char __pad0[112]; // 120 in H1
};
std::unordered_map<std::string, image_file_unk*> image_file_unk_map;
void* get_image_file_unk_mp(unsigned int index)
{
if (index != CUSTOM_IMAGE_FILE_INDEX)
{
return &reinterpret_cast<image_file_unk*>(
SELECT_VALUE(0x0, 0x143DC4E90))[index];
}
const auto name = get_image_file_name();
if (image_file_unk_map.find(name) == image_file_unk_map.end())
{
const auto unk = image_file_allocator.allocate<image_file_unk>();
image_file_unk_map[name] = unk;
return unk;
}
return image_file_unk_map[name];
}
}
/*
namespace sp
{
struct image_file_unk
{
char __pad0[96];
};
std::unordered_map<std::string, image_file_unk*> image_file_unk_map;
void* get_image_file_unk_mp(unsigned int index)
{
if (index != CUSTOM_IMAGE_FILE_INDEX)
{
return &reinterpret_cast<image_file_unk*>(
SELECT_VALUE(0x0, 0x143DC4E90))[index];
}
const auto name = get_image_file_name();
if (image_file_unk_map.find(name) == image_file_unk_map.end())
{
const auto unk = image_file_allocator.allocate<image_file_unk>();
image_file_unk_map[name] = unk;
return unk;
}
return image_file_unk_map[name];
}
}
*/
HANDLE get_image_file_handle(unsigned int index)
{
if (index != CUSTOM_IMAGE_FILE_INDEX)
{
return reinterpret_cast<HANDLE*>(
SELECT_VALUE(0x0, 0x143B74E80))[index];
}
const auto name = get_image_file_name();
return image_file_handles[name];
}
void db_create_gfx_image_stream_stub(utils::hook::assembler& a)
{
const auto handle_is_open = a.newLabel();
a.movzx(eax, cx);
a.mov(esi, eax);
a.imul(rsi, 0x70);
a.add(rsi, r15);
a.push(rax);
a.push(rax);
a.pushad64();
a.mov(rcx, rax);
a.call_aligned(mp::get_image_file_unk_mp);
a.mov(qword_ptr(rsp, 0x80), rax);
a.popad64();
a.pop(rax);
a.mov(rsi, rax);
a.pop(rax);
a.push(rax);
a.push(rax);
a.pushad64();
a.mov(rcx, rax);
a.call_aligned(get_image_file_handle);
a.mov(qword_ptr(rsp, 0x80), rax);
a.popad64();
a.pop(rax);
a.mov(r12, rax);
a.pop(rax);
a.cmp(r12, r13);
a.jnz(handle_is_open);
a.jmp(SELECT_VALUE(0x0, 0x140279C8B));
a.bind(handle_is_open);
a.jmp(SELECT_VALUE(0x0, 0x140279CDB));
}
void* pakfile_open_stub(void* /*handles*/, unsigned int count, int is_imagefile,
unsigned int index, short is_localized)
{
#ifdef DEBUG
console::info("Opening %s%d.pak (localized:%d)\n", is_imagefile ? "imagefile" : "soundfile", index, is_localized);
#endif
if (index != CUSTOM_IMAGE_FILE_INDEX)
{
return utils::hook::invoke<void*>(
SELECT_VALUE(0x0, 0x1404CC180),
SELECT_VALUE(0x0, 0x143B74E80),
count, is_imagefile, index, is_localized
);
}
const auto name = get_image_file_name();
const auto handle = game::Sys_CreateFile(is_localized ? game::SF_PAKFILE_LOC : game::SF_PAKFILE, utils::string::va("%s.pak", name.data()));
if (handle != nullptr)
{
image_file_handles[name] = handle;
}
return handle;
}
int com_sprintf_stub(char* buffer, const int len, const char* fmt, unsigned int index)
{
if (index != CUSTOM_IMAGE_FILE_INDEX)
{
return game::Com_sprintf(buffer, len, fmt, index);
}
const auto name = get_image_file_name();
return game::Com_sprintf(buffer, len, "%s.pak", name.data());
}
}
void close_custom_handles()
{
for (const auto& handle : image_file_handles)
{
if (handle.second != nullptr)
{
utils::hook::invoke<void>(0x140608A20, handle.second); // Sys_CloseFile
}
}
image_file_handles.clear();
//sp::image_file_unk_map.clear();
mp::image_file_unk_map.clear();
image_file_allocator.clear();
}
void close_handle(const std::string& fastfile)
{
if (!image_file_handles.contains(fastfile))
{
return;
}
const auto handle = image_file_handles[fastfile];
if (handle != nullptr)
{
utils::hook::invoke<void>(0x140608A20, handle);
}
image_file_handles.erase(fastfile);
if (game::environment::is_sp())
{
//image_file_allocator.free(sp::image_file_unk_map[fastfile]);
//sp::image_file_unk_map.erase(fastfile);
}
else
{
image_file_allocator.free(mp::image_file_unk_map[fastfile]);
mp::image_file_unk_map.erase(fastfile);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (!game::environment::is_mp())
{
return;
}
utils::hook::jump(SELECT_VALUE(0x0, 0x140279C79),
utils::hook::assemble(db_create_gfx_image_stream_stub), true);
utils::hook::call(SELECT_VALUE(0x0, 0x140279CBD), pakfile_open_stub);
utils::hook::call(SELECT_VALUE(0x0, 0x140279C9F), com_sprintf_stub);
}
};
}
REGISTER_COMPONENT(imagefiles::component)

View File

@ -1,7 +0,0 @@
#pragma once
namespace imagefiles
{
void close_custom_handles();
void close_handle(const std::string& fastfile);
}

View File

@ -164,7 +164,7 @@ namespace logger
com_error_hook.create(game::Com_Error, com_error_stub);
logger_dev = game::Dvar_RegisterBool("logger_dev", false, game::DVAR_FLAG_SAVED);
logger_dev = game::Dvar_RegisterBool("logger_dev", false, game::DVAR_FLAG_SAVED, "Print dev stuff");
}
};
}

View File

@ -113,7 +113,7 @@ namespace map_rotation
console::error("%s: %s contains invalid data!\n", ex.what(), sv_map_rotation->name);
}
#ifdef _DEBUG
console::info("dedicated_rotation size after parsing is '%zu'\n", dedicated_rotation.get_entries_size());
console::info("dedicated_rotation size after parsing is '%zu'", dedicated_rotation.get_entries_size());
#endif
}
@ -289,11 +289,11 @@ namespace map_rotation
scheduler::once([]
{
sv_map_rotation = game::Dvar_RegisterString("sv_mapRotation", "", game::DVAR_FLAG_NONE);
sv_map_rotation_current = game::Dvar_RegisterString("sv_mapRotationCurrent", "", game::DVAR_FLAG_NONE);
sv_map_rotation = game::Dvar_RegisterString("sv_mapRotation", "", game::DVAR_FLAG_NONE, "");
sv_map_rotation_current = game::Dvar_RegisterString("sv_mapRotationCurrent", "", game::DVAR_FLAG_NONE, "");
}, scheduler::pipeline::main);
sv_random_map_rotation = game::Dvar_RegisterBool("sv_randomMapRotation", false, game::DVAR_FLAG_NONE);
sv_random_map_rotation = game::Dvar_RegisterBool("sv_randomMapRotation", false, game::DVAR_FLAG_NONE, "Randomize map rotation");
command::add("map_rotate", &perform_map_rotation);

View File

@ -1,212 +0,0 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "console.hpp"
#include "filesystem.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
#include "gsc/script_loading.hpp"
namespace mapents
{
namespace
{
std::optional<std::string> parse_mapents(const std::string& source)
{
std::string out_buffer{};
const auto lines = utils::string::split(source, '\n');
auto in_map_ent = false;
auto empty = false;
auto in_comment = false;
for (auto i = 0; i < lines.size(); i++)
{
auto line_num = i+1;
auto line = lines[i];
if (line.ends_with('\r'))
{
line.pop_back();
}
if (line.starts_with("/*"))
{
in_comment = true;
continue;
}
if (line.ends_with("*/"))
{
in_comment = false;
continue;
}
if (in_comment)
{
continue;
}
if (line.starts_with("//"))
{
continue;
}
if (line[0] == '{' && !in_map_ent)
{
in_map_ent = true;
out_buffer.append("{\n");
continue;
}
if (line[0] == '{' && in_map_ent)
{
console::error("[map_ents parser] Unexpected '{' on line %i\n", line_num);
return {};
}
if (line[0] == '}' && in_map_ent)
{
if (empty)
{
out_buffer.append("\n}\n");
}
else if (i < static_cast<int>(lines.size()) - 1)
{
out_buffer.append("}\n");
}
else
{
out_buffer.append("}\0");
}
in_map_ent = false;
continue;
}
if (line[0] == '}' && !in_map_ent)
{
console::error("[map_ents parser] Unexpected '}' on line %i\n", line_num);
return {};
}
std::regex expr(R"~((.+) "(.*)")~");
std::smatch match{};
if (!std::regex_search(line, match, expr) && !line.empty())
{
console::warn("[map_ents parser] Failed to parse line %i (%s)\n", line_num, line.data());
continue;
}
auto key = utils::string::to_lower(match[1].str());
const auto value = match[2].str();
if (key.size() <= 0)
{
console::warn("[map_ents parser] Invalid key ('%s') on line %i (%s)\n", key.data(), line_num, line.data());
continue;
}
if (value.size() <= 0)
{
continue;
}
empty = false;
if (utils::string::is_numeric(key) || key.size() < 3 || !key.starts_with("\"") || !key.ends_with("\""))
{
out_buffer.append(line);
out_buffer.append("\n");
continue;
}
const auto key_ = key.substr(1, key.size() - 2);
const auto id = gsc::gsc_ctx->token_id(key_);
if (id == 0)
{
console::warn("[map_ents parser] Key '%s' not found, on line %i (%s)\n", key_.data(), line_num, line.data());
continue;
}
out_buffer.append(utils::string::va("%i \"%s\"\n", id, value.data()));
}
return {out_buffer};
}
std::string raw_ents;
bool load_raw_mapents()
{
auto mapents_name = utils::string::va("%s.ents", **reinterpret_cast<const char***>(SELECT_VALUE(0x0, 0x1479E6940)));
if (filesystem::exists(mapents_name))
{
try
{
console::info("Reading raw ents file \"%s\"\n", mapents_name);
raw_ents = filesystem::read_file(mapents_name);
if (!raw_ents.empty())
{
return true;
}
}
catch (const std::exception& ex)
{
console::error("Failed to read raw ents file \"%s\"\n%s\n", mapents_name, ex.what());
}
}
return false;
}
std::string entity_string;
const char* cm_entity_string_stub()
{
const char* ents = nullptr;
if (load_raw_mapents())
{
ents = raw_ents.data();
}
else
{
if (!entity_string.empty())
{
return entity_string.data();
}
ents = utils::hook::invoke<const char*>(SELECT_VALUE(0x0, 0x1403A1F30));
}
const auto parsed = parse_mapents(ents);
if (parsed.has_value())
{
entity_string = parsed.value();
return entity_string.data();
}
else
{
return ents;
}
}
void cm_unload_stub(void* clip_map)
{
entity_string.clear();
raw_ents.clear();
utils::hook::invoke<void>(SELECT_VALUE(0x0, 0x1403A1ED0), clip_map);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
utils::hook::call(SELECT_VALUE(0x0, 0x1402F5A54), cm_entity_string_stub);
utils::hook::call(SELECT_VALUE(0x0, 0x14026BF54), cm_unload_stub);
}
};
}
REGISTER_COMPONENT(mapents::component)

View File

@ -179,7 +179,7 @@ namespace network
game::dvar_t* register_netport_stub(const char* dvarName, int value, int min, int max, unsigned int flags,
const char* description)
{
auto dvar = game::Dvar_RegisterInt("net_port", 27016, 0, 0xFFFFu, game::DVAR_FLAG_LATCHED);
auto dvar = game::Dvar_RegisterInt("net_port", 27016, 0, 0xFFFFu, game::DVAR_FLAG_LATCHED, "Network port");
// read net_port from command line
command::read_startup_variable("net_port");

View File

@ -28,6 +28,8 @@ namespace notifies
char empty_function[2] = {0x32, 0x34}; // CHECK_CLEAR_PARAMS, END
const char* target_function = nullptr;
void client_command_stub(const int client_num)
{
if (game::mp::g_entities[client_num].client == nullptr)
@ -135,7 +137,7 @@ namespace notifies
a.lea(eax, dword_ptr(r15, -0x17));
a.mov(dword_ptr(rbp, 0x68), r15d);
a.jmp(SELECT_VALUE(0x14031D9E3, 0x1403FA143));
a.jmp(0x1403FA143);
a.bind(replace);
@ -183,22 +185,22 @@ namespace notifies
public:
void post_unpack() override
{
utils::hook::jump(SELECT_VALUE(0x14031D9D4, 0x1403FA134), utils::hook::assemble(vm_execute_stub), true);
scripting::on_shutdown([](const int clear_scripts) -> void
{
if (clear_scripts)
{
vm_execute_hooks.clear();
}
});
if (game::environment::is_sp())
{
return;
}
utils::hook::call(0x14043A9AD, client_command_stub);
utils::hook::jump(0x1403FA134, utils::hook::assemble(vm_execute_stub), true);
scripting::on_shutdown([](bool free_scripts)
{
if (free_scripts)
{
vm_execute_hooks.clear();
}
});
}
};
}

View File

@ -1,7 +1,6 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "party.hpp"
#include "console.hpp"
@ -34,29 +33,6 @@ namespace party
int sv_maxclients;
utils::info_string get_info()
{
utils::info_string info;
info.set("gamename", "S1");
info.set("hostname", dvars::get_dvar_string("sv_hostname"));
info.set("gametype", dvars::get_dvar_string("g_gametype"));
info.set("sv_motd", dvars::get_dvar_string("sv_motd"));
info.set("xuid", utils::string::va("%llX", steam::SteamUser()->GetSteamID().bits));
info.set("mapname", dvars::get_dvar_string("mapname"));
info.set("isPrivate", dvars::get_dvar_string("g_password").empty() ? "0" : "1");
info.set("clients", std::to_string(get_client_count()));
info.set("bots", std::to_string(get_bot_count()));
info.set("sv_maxclients", std::to_string(game::Dvar_FindVar("sv_maxclients")->current.integer));
info.set("protocol", std::to_string(PROTOCOL));
info.set("shortversion", SHORTVERSION);
info.set("playmode", utils::string::va("%i", game::Com_GetCurrentCoDPlayMode()));
info.set("sv_running", std::to_string(dvars::get_dvar_bool("sv_running")));
info.set("dedicated", std::to_string(dvars::get_dvar_bool("dedicated")));
return info;
}
void perform_game_initialization()
{
command::execute("onlinegame 1", true);
@ -103,7 +79,30 @@ namespace party
// CL_ConnectFromParty
char session_info[0x100] = {};
reinterpret_cast<void(*)(int, char*, const game::netadr_s*, const char*, const char*)>(0x140209360)(0, session_info, &target, mapname.data(), gametype.data());
reinterpret_cast<void(*)(int, char*, const game::netadr_s*, const char*, const char*)>(0x140209360)(
0, session_info, &target, mapname.data(), gametype.data());
}
std::string get_dvar_string(const std::string& dvar)
{
const auto* dvar_value = game::Dvar_FindVar(dvar.data());
if (dvar_value && dvar_value->current.string)
{
return {dvar_value->current.string};
}
return {};
}
bool get_dvar_bool(const std::string& dvar)
{
const auto* dvar_value = game::Dvar_FindVar(dvar.data());
if (dvar_value && dvar_value->current.enabled)
{
return dvar_value->current.enabled;
}
return false;
}
void didyouknow_stub(const char* dvar_name, const char* string)
@ -462,7 +461,8 @@ namespace party
scheduler::once([]()
{
game::Dvar_RegisterString("sv_sayName", "console", game::DVAR_FLAG_NONE);
game::Dvar_RegisterString("sv_sayName", "console", game::DvarFlags::DVAR_FLAG_NONE,
"The name to pose as for 'say' commands");
}, scheduler::pipeline::main);
command::add("tell", [](const command::params& params)
@ -529,55 +529,27 @@ namespace party
network::on("getInfo", [](const game::netadr_s& target, const std::string& data)
{
utils::info_string info = get_info();
utils::info_string info{};
info.set("challenge", data);
info.set("gamename", "S1");
info.set("hostname", get_dvar_string("sv_hostname"));
info.set("gametype", get_dvar_string("g_gametype"));
info.set("sv_motd", get_dvar_string("sv_motd"));
info.set("xuid", utils::string::va("%llX", steam::SteamUser()->GetSteamID().bits));
info.set("mapname", get_dvar_string("mapname"));
info.set("isPrivate", get_dvar_string("g_password").empty() ? "0" : "1");
info.set("clients", std::to_string(get_client_count()));
info.set("bots", std::to_string(get_bot_count()));
info.set("sv_maxclients", std::to_string(*game::mp::svs_numclients));
info.set("protocol", std::to_string(PROTOCOL));
info.set("playmode", utils::string::va("%i", game::Com_GetCurrentCoDPlayMode()));
info.set("sv_running", std::to_string(get_dvar_bool("sv_running")));
info.set("dedicated", std::to_string(get_dvar_bool("dedicated")));
info.set("shortversion", SHORTVERSION);
network::send(target, "infoResponse", info.build(), '\n');
});
network::on("getStatus", [](const game::netadr_s& target, const std::string& data)
{
std::string player_list;
utils::info_string info = get_info();
info.set("challenge", data);
const auto* sv_running = game::Dvar_FindVar("sv_running");
if (!sv_running || !sv_running->current.enabled)
{
return;
}
for (auto i = 0; i < game::Dvar_FindVar("sv_maxclients")->current.integer; ++i)
{
auto* client = &game::mp::svs_clients[i];
auto* self = &game::mp::g_entities[i];
if (client->header.state < 5)
{
continue;
}
if (!self || !self->client)
{
continue;
}
if (game::SV_BotIsBot(i))
{
continue;
}
const auto score = game::G_GetClientScore(i);
const auto ping = game::SV_GetClientPing(i);
const std::string name = game::mp::svs_clients[i].name;
player_list.append(std::format("{} {} \"{}\"\n", score, ping, name));
}
network::send(target, "statusResponse", info.build() + "\n"s + player_list + "\n"s, '\n');
});
if (game::environment::is_dedi())
{
return;

View File

@ -58,28 +58,28 @@ namespace patches
if (game::environment::is_mp())
{
// Make name save
game::Dvar_RegisterString("name", get_login_username().data(), game::DVAR_FLAG_SAVED);
game::Dvar_RegisterString("name", get_login_username().data(), game::DVAR_FLAG_SAVED, "Player name.");
// Disable data validation error popup
game::Dvar_RegisterInt("data_validation_allow_drop", 0, 0, 0, game::DVAR_FLAG_NONE);
game::Dvar_RegisterInt("data_validation_allow_drop", 0, 0, 0, game::DVAR_FLAG_NONE, "");
}
return com_register_dvars_hook.invoke<void>();
}
game::dvar_t* register_com_maxfps_stub(const char* name, int /*value*/, int /*min*/, int /*max*/, const unsigned int /*flags*/)
game::dvar_t* register_com_maxfps_stub(const char* name, int /*value*/, int /*min*/, int /*max*/, const unsigned int /*flags*/, const char* description)
{
return game::Dvar_RegisterInt(name, 0, 0, 1000, game::DVAR_FLAG_SAVED);
return game::Dvar_RegisterInt(name, 0, 0, 1000, game::DVAR_FLAG_SAVED, description);
}
game::dvar_t* register_cg_fov_stub(const char* name, float value, float min, float /*max*/, const unsigned int /*flags*/)
game::dvar_t* register_cg_fov_stub(const char* name, float value, float min, float /*max*/, const unsigned int /*flags*/, const char* description)
{
return game::Dvar_RegisterFloat(name, value, min, 160, game::DVAR_FLAG_SAVED);
return game::Dvar_RegisterFloat(name, value, min, 160, game::DVAR_FLAG_SAVED, description);
}
game::dvar_t* register_fovscale_stub(const char* name, float /*value*/, float /*min*/, float /*max*/, unsigned int /*flags*/)
game::dvar_t* register_fovscale_stub(const char* name, float /*value*/, float /*min*/, float /*max*/, unsigned int /*flags*/, const char* desc)
{
return game::Dvar_RegisterFloat(name, 1.0f, 0.2f, 5.0f, game::DVAR_FLAG_SAVED);
return game::Dvar_RegisterFloat(name, 1.0f, 0.2f, 5.0f, game::DVAR_FLAG_SAVED, desc);
}
int dvar_command_patch() // game makes this return an int and compares with eax instead of al -_-
@ -252,7 +252,7 @@ namespace patches
utils::hook::call(0x14026E63B, bsp_sys_error_stub);
// client side aim assist dvar
dvars::aimassist_enabled = game::Dvar_RegisterBool("aimassist_enabled", true, game::DVAR_FLAG_SAVED);
dvars::aimassist_enabled = game::Dvar_RegisterBool("aimassist_enabled", true, game::DVAR_FLAG_SAVED, "Enables aim assist for controllers");
utils::hook::call(0x140003609, aim_assist_add_to_target_list);
// isProfanity
@ -304,7 +304,7 @@ namespace patches
dvars::override::register_int("cl_connectTimeout", 120, 120, 1800, game::DVAR_FLAG_NONE); // Seems unused
dvars::override::register_int("sv_connectTimeout", 120, 120, 1800, game::DVAR_FLAG_NONE); // 60 - 0 - 1800
game::Dvar_RegisterInt("scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED);
game::Dvar_RegisterInt("scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED, "");
// Prevent clients from ending the game as non host by sending 'end_game' lui notification
cmd_lui_notify_server_hook.create(0x1402E9390, cmd_lui_notify_server_stub);

View File

@ -31,7 +31,7 @@ namespace ranked
dvars::override::register_bool("xblive_privatematch", false, game::DVAR_FLAG_REPLICATED | game::DVAR_FLAG_WRITE);
// Some dvar used in gsc
game::Dvar_RegisterBool("force_ranking", true, game::DVAR_FLAG_WRITE);
game::Dvar_RegisterBool("force_ranking", true, game::DVAR_FLAG_WRITE, "Force ranking");
}
// Always run bots, even if xblive_privatematch is 0

View File

@ -80,25 +80,23 @@ namespace rcon
{
const auto client = &game::mp::svs_clients[i];
if (client->header.state == game::CA_DISCONNECTED)
{
continue;
}
char clean_name[32]{};
strncpy_s(clean_name, client->name, _TRUNCATE);
game::I_CleanStr(clean_name);
buffer.append(utils::string::va("%3i %5i %3s %s %32s %16s %21s %5i\n",
i,
game::G_GetClientScore(i),
game::SV_BotIsBot(i) ? "Yes" : "No",
(client->header.state == 2) ? "CNCT" : (client->header.state == 1) ? "ZMBI" : utils::string::va("%4i", game::SV_GetClientPing(i)),
game::SV_GetGuid(i),
clean_name,
network::net_adr_to_string(client->header.remoteAddress),
client->header.remoteAddress.port)
);
if (client->header.state > game::CA_DISCONNECTED)
{
buffer.append(utils::string::va("%3i %5i %3s %s %32s %16s %21s %5i\n",
i,
game::G_GetClientScore(i),
game::SV_BotIsBot(i) ? "Yes" : "No",
(client->header.state == 2) ? "CNCT" : (client->header.state == 1) ? "ZMBI" : utils::string::va("%4i", game::SV_GetClientPing(i)),
game::SV_GetGuid(i),
clean_name,
network::net_adr_to_string(client->header.remoteAddress),
client->header.remoteAddress.port)
);
}
}
return buffer;
@ -130,7 +128,8 @@ namespace rcon
scheduler::once([]()
{
game::Dvar_RegisterString("rcon_password", "", game::DVAR_FLAG_NONE);
game::Dvar_RegisterString("rcon_password", "", game::DvarFlags::DVAR_FLAG_NONE,
"The password for remote console");
}, scheduler::pipeline::main);
command::add("status", []()

View File

@ -62,7 +62,7 @@ namespace renderer
return;
}
dvars::r_fullbright = game::Dvar_RegisterInt("r_fullbright", 0, 0, 3, game::DVAR_FLAG_SAVED);
dvars::r_fullbright = game::Dvar_RegisterInt("r_fullbright", 0, 0, 3, game::DVAR_FLAG_SAVED, "Toggles rendering without lighting");
r_init_draw_method_hook.create(SELECT_VALUE(0x14046C150, 0x140588B00), &r_init_draw_method_stub);
r_update_front_end_dvar_options_hook.create(SELECT_VALUE(0x1404A5330, 0x1405C3AE0), &r_update_front_end_dvar_options_stub);

View File

@ -49,9 +49,9 @@ namespace scripting
}
}
void g_shutdown_game_stub(const int clear_scripts)
void g_shutdown_game_stub(const int free_scripts)
{
if (clear_scripts)
if (free_scripts)
{
script_function_table_sort.clear();
script_function_table.clear();
@ -61,10 +61,10 @@ namespace scripting
for (const auto& callback : shutdown_callbacks)
{
callback(clear_scripts);
callback(free_scripts);
}
return g_shutdown_game_hook.invoke<void>(clear_scripts);
return g_shutdown_game_hook.invoke<void>(free_scripts);
}
void process_script_stub(const char* filename)
@ -182,6 +182,10 @@ namespace scripting
scr_set_thread_position_hook.create(SELECT_VALUE(0x1403115E0, 0x1403EDB10), &scr_set_thread_position_stub);
process_script_hook.create(SELECT_VALUE(0x14031AB30, 0x1403F7300), &process_script_stub);
sl_get_canonical_string_hook.create(game::SL_GetCanonicalString, &sl_get_canonical_string_stub);
scheduler::loop([]
{
}, scheduler::pipeline::server);
}
};
}

View File

@ -10,8 +10,6 @@ namespace security
{
namespace
{
utils::hook::detour ui_replace_directive_hook;
void set_cached_playerdata_stub(const int localclient, const int index1, const int index2)
{
if (index1 >= 0 && index1 < 18 && index2 >= 0 && index2 < 42)
@ -55,35 +53,6 @@ namespace security
utils::hook::invoke<void>(0x14043AA90, client, msg);
}
void ui_replace_directive_stub(const int local_client_num, const char* src_string, char* dst_string, const int dst_buffer_size)
{
assert(src_string);
if (!src_string)
{
return;
}
assert(dst_string);
if (!dst_string)
{
return;
}
assert(dst_buffer_size > 0);
if (dst_buffer_size <= 0)
{
return;
}
constexpr std::size_t MAX_HUDELEM_TEXT_LEN = 0x100;
if (std::strlen(src_string) > MAX_HUDELEM_TEXT_LEN)
{
return;
}
ui_replace_directive_hook.invoke<void>(local_client_num, src_string, dst_string, dst_buffer_size);
}
}
class component final : public component_interface
@ -101,8 +70,6 @@ namespace security
// It is possible to make the server hang if left unchecked
utils::hook::call(0x140443051, sv_execute_client_message_stub);
ui_replace_directive_hook.create(0x1404A9640, ui_replace_directive_stub);
}
};
}

View File

@ -2,9 +2,6 @@
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "command.hpp"
#include "console.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
@ -36,25 +33,6 @@ namespace slowmotion
game::SV_SetConfigstring(10, utils::string::va("%i %i %g %g", *game::mp::gameTime, duration, start, end));
game::Com_SetSlowMotion(start, end, duration);
}
void set_code_time_scale(float timescale)
{
assert(timescale > 0.0f);
*game::com_codeTimeScale = timescale;
}
void com_timescale_f(const command::params& params)
{
if (params.size() != 2)
{
console::info("timescale <rate>\n");
return;
}
const auto timescale = static_cast<float>(std::atof(params.get(1)));
console::info("timescale set to %f\n", timescale);
set_code_time_scale(timescale);
}
}
class component final : public component_interface
@ -62,13 +40,6 @@ namespace slowmotion
public:
void post_unpack() override
{
if (game::environment::is_sp())
{
return;
}
command::add("timescale", com_timescale_f);
if (!game::environment::is_dedi())
{
return;

View File

@ -75,9 +75,9 @@ namespace stats
else
{
// unlock all
cg_unlock_all_items = game::Dvar_RegisterBool("cg_unlockall_items", false, game::DVAR_FLAG_SAVED);
cg_unlock_all_loot = game::Dvar_RegisterBool("cg_unlockall_loot", false, game::DVAR_FLAG_SAVED);
game::Dvar_RegisterBool("cg_unlockall_classes", false, game::DVAR_FLAG_SAVED);
cg_unlock_all_items = game::Dvar_RegisterBool("cg_unlockall_items", false, game::DVAR_FLAG_SAVED, "Unlock items that are level-locked by the player's stats.");
cg_unlock_all_loot = game::Dvar_RegisterBool("cg_unlockall_loot", false, game::DVAR_FLAG_SAVED, "Unlock supply drop loot.");
game::Dvar_RegisterBool("cg_unlockall_classes", false, game::DVAR_FLAG_SAVED, "Unlock extra class slots.");
is_item_locked_hook1.create(0x1403BD790, is_item_locked_stub1); // LiveStorage_IsItemUnlockedFromTable_LocalClient
is_item_locked_hook2.create(0x1403BD290, is_item_locked_stub2); // LiveStorage_IsItemUnlockedFromTable

View File

@ -82,8 +82,8 @@ namespace virtuallobby
return;
}
virtualLobby_fov = game::Dvar_RegisterFloat("virtualLobby_fov", 40.0f, 1.0f, 170.0f, game::DVAR_FLAG_SAVED);
virtualLobby_fovscale = game::Dvar_RegisterFloat("virtualLobby_fovScale", 1.0f, 0.0f, 2.0f, game::DVAR_FLAG_SAVED);
virtualLobby_fov = game::Dvar_RegisterFloat("virtualLobby_fov", 40.0f, 1.0f, 170.0f, game::DVAR_FLAG_SAVED, "Field of view for the virtual lobby");
virtualLobby_fovscale = game::Dvar_RegisterFloat("virtualLobby_fovScale", 1.0f, 0.0f, 2.0f, game::DVAR_FLAG_SAVED, "Field of view scaled for the virtual lobby");
utils::hook::nop(0x1401D5AFB, 16);
utils::hook::jump(0x1401D5AFB, get_fov_stub, true);

View File

@ -1,113 +0,0 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "console.hpp"
#include "fastfiles.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include <utils/hook.hpp>
#include <utils/memory.hpp>
namespace weapon
{
namespace
{
utils::hook::detour g_setup_level_weapon_def_hook;
void g_setup_level_weapon_def_stub()
{
// precache level weapons first
g_setup_level_weapon_def_hook.invoke<void>();
std::vector<game::WeaponDef*> weapons;
// find all weapons in asset pools
fastfiles::enum_assets(game::ASSET_TYPE_WEAPON, [&weapons](game::XAssetHeader header)
{
weapons.push_back(reinterpret_cast<game::WeaponDef*>(header.data));
}, false);
// sort weapons
std::sort(weapons.begin(), weapons.end(), [](game::WeaponDef* weapon1, game::WeaponDef* weapon2)
{
return std::string_view(weapon1->name) <
std::string_view(weapon2->name);
});
// precache items
for (std::size_t i = 0; i < weapons.size(); i++)
{
//console::info("precaching weapon \"%s\"\n", weapons[i]->name);
game::G_GetWeaponForName(weapons[i]->name);
}
}
utils::hook::detour xmodel_get_bone_index_hook;
int xmodel_get_bone_index_stub(game::XModel* model, game::scr_string_t name, unsigned int offset, char* index)
{
auto result = xmodel_get_bone_index_hook.invoke<int>(model, name, offset, index);
if (result)
{
return result;
}
const auto original_index = *index;
const auto original_result = result;
if (name == game::SL_FindString("tag_weapon_right") ||
name == game::SL_FindString("tag_knife_attach"))
{
const auto tag_weapon = game::SL_FindString("tag_weapon");
result = xmodel_get_bone_index_hook.invoke<int>(model, tag_weapon, offset, index);
if (result)
{
console::info("using tag_weapon instead of %s (%s, %d, %d)\n", game::SL_ConvertToString(name), model->name, offset, *index);
return result;
}
}
*index = original_index;
result = original_result;
return result;
}
void cw_mismatch_error_stub(int, const char* msg, ...)
{
char buffer[0x100];
va_list ap;
va_start(ap, msg);
vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, msg, ap);
va_end(ap);
console::error(buffer);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (!game::environment::is_mp())
{
return;
}
// precache all weapons that are loaded in zones
g_setup_level_weapon_def_hook.create(0x140340DE0, g_setup_level_weapon_def_stub);
// use tag_weapon if tag_weapon_right or tag_knife_attach are not found on model
xmodel_get_bone_index_hook.create(0x1404E2A50, xmodel_get_bone_index_stub);
// make custom weapon index mismatch not drop in CG_SetupCustomWeapon
utils::hook::call(0x1401E973D, cw_mismatch_error_stub);
}
};
}
REGISTER_COMPONENT(weapon::component)

View File

@ -43,28 +43,6 @@ namespace dvars
game::dvar_t* com_developer = nullptr;
game::dvar_t* com_developer_script = nullptr;
std::string get_dvar_string(const std::string& dvar)
{
const auto* dvar_value = game::Dvar_FindVar(dvar.data());
if (dvar_value && dvar_value->current.string)
{
return { dvar_value->current.string };
}
return {};
}
bool get_dvar_bool(const std::string& dvar)
{
const auto* dvar_value = game::Dvar_FindVar(dvar.data());
if (dvar_value && dvar_value->current.enabled)
{
return dvar_value->current.enabled;
}
return false;
}
std::string dvar_get_vector_domain(const int components, const game::dvar_limits& domain)
{
if (domain.vector.min == -FLT_MAX)
@ -73,16 +51,22 @@ namespace dvars
{
return utils::string::va("Domain is any %iD vector", components);
}
return utils::string::va("Domain is any %iD vector with components %g or smaller", components, domain.vector.max);
else
{
return utils::string::va("Domain is any %iD vector with components %g or smaller", components,
domain.vector.max);
}
}
if (domain.vector.max == FLT_MAX)
else if (domain.vector.max == FLT_MAX)
{
return utils::string::va("Domain is any %iD vector with components %g or bigger", components, domain.vector.min);
return utils::string::va("Domain is any %iD vector with components %g or bigger", components,
domain.vector.min);
}
else
{
return utils::string::va("Domain is any %iD vector with components from %g to %g", components,
domain.vector.min, domain.vector.max);
}
return utils::string::va("Domain is any %iD vector with components from %g to %g", components, domain.vector.min, domain.vector.max);
}
std::string dvar_get_domain(const game::dvar_type type, const game::dvar_limits& domain)

View File

@ -42,9 +42,6 @@ namespace dvars
extern game::dvar_t* com_developer;
extern game::dvar_t* com_developer_script;
std::string get_dvar_string(const std::string& dvar);
bool get_dvar_bool(const std::string& dvar);
std::string dvar_get_vector_domain(int components, const game::dvar_limits& domain);
std::string dvar_get_domain(game::dvar_type type, const game::dvar_limits& domain);
}

View File

@ -60,13 +60,6 @@ namespace game
VAR_TOTAL_COUNT = 0x1B,
};
struct ScriptFunctions
{
int maxSize;
int count;
int* address;
};
struct VariableStackBuffer
{
const char* pos;
@ -221,6 +214,7 @@ namespace game
unsigned __int16 childVariableBucket[65536];
ChildVariableValue childVariableValue[384000];
};
// *
enum Sys_Folder
{
@ -1489,17 +1483,11 @@ namespace game
char __pad2[8];
int nextSnapshotTime; // 269024
char __pad3[544];
LiveClientDropType liveDropRequest; // 269572
LiveClientDropType liveDropRequest; //269572
char __pad4[24];
TestClientType testClient; // 269600
char __pad5[391700];
}; // size = 661304
static_assert(offsetof(client_t, gentity) == 0x41AB0);
static_assert(offsetof(client_t, nextSnapshotTime) == 0x41AE0);
static_assert(offsetof(client_t, liveDropRequest) == 0x41D04);
static_assert(offsetof(client_t, testClient) == 0x41D20);
static_assert(sizeof(client_t) == 0xA1738);
}
namespace sp
@ -1951,39 +1939,4 @@ namespace game
HksError m_error;
};
}
enum DBAllocFlags : std::int32_t
{
DB_ZONE_NONE = 0x0,
DB_ZONE_COMMON = 0x1,
DB_ZONE_UI = 0x2,
DB_ZONE_GAME = 0x4,
DB_ZONE_LOAD = 0x8,
DB_ZONE_DEV = 0x10,
DB_ZONE_BASEMAP = 0x20,
DB_ZONE_TRANSIENT_POOL = 0x40,
DB_ZONE_TRANSIENT_MASK = 0x40,
DB_ZONE_CUSTOM = 0x1000 // added for custom zone loading
};
struct XZone
{
char name[64];
char pad_0040[432];
};
static_assert(sizeof(XZone) == 496);
struct WeaponDef
{
union
{
const char* szInternalName;
const char* name;
};
};
struct XModel
{
const char* name; // 0
};
}

View File

@ -12,7 +12,7 @@ namespace game
WEAK symbol<void(unsigned int id)> AddRefToObject{0, 0x1403F1F10};
WEAK symbol<unsigned int(unsigned int id)> AllocThread{0, 0x1403F2270};
WEAK symbol<void(int type, VariableUnion u)> RemoveRefToValue{0x140317340, 0x1403F3A50};
WEAK symbol<void(unsigned int id)> RemoveRefToObject{0x140317230, 0x1403F3940};
WEAK symbol<void(unsigned int id)> RemoveRefToObject{0, 0x1403F3940};
WEAK symbol<void(void*, void*)> AimAssist_AddToTargetList{0, 0x140001730};
@ -23,7 +23,6 @@ namespace game
WEAK symbol<CodPlayMode()> Com_GetCurrentCoDPlayMode{0, 0x1404C9690};
WEAK symbol<void(float, float, int)> Com_SetSlowMotion{0, 0x1403D19B0};
WEAK symbol<void()> Com_Quit_f{0x1402F9390, 0x1403D08C0};
WEAK symbol<int(char* dest, int size, const char* fmt, ...)> Com_sprintf{0x0, 0x1404C97B0};
WEAK symbol<void(const char* cmdName, void (), cmd_function_s* allocedCmd)> Cmd_AddCommandInternal{0x1402EDDB0, 0x1403AF2C0};
WEAK symbol<void(int localClientNum, int controllerIndex, const char* text)> Cmd_ExecuteSingleCommand{0x1402EE350, 0x1403AF900};
@ -59,7 +58,6 @@ namespace game
WEAK symbol<int(const RawFile* rawfile)> DB_GetRawFileLen{0x14017E890, 0x14026FCC0};
WEAK symbol<void(const RawFile* rawfile, char* buf, int size)> DB_GetRawBuffer{0x14017E750, 0x14026FB90};
WEAK symbol<char*(const char* filename, char* buf, int size)> DB_ReadRawFile{0x140180E30, 0x140273080};
WEAK symbol<bool(const char* filename)> DB_IsLocalized{0x14017EC80, 0x140270190};
WEAK symbol<dvar_t*(const char* name)> Dvar_FindVar{0x140370860, 0x1404BF8B0};
WEAK symbol<void(const dvar_t* dvar)> Dvar_ClearModified{0x140370700, 0x1404BF690};
@ -72,14 +70,22 @@ namespace game
WEAK symbol<void(const char*, const char*, DvarSetSource)> Dvar_SetFromStringByNameFromSource{0x1403737D0, 0x1404C2E40};
WEAK symbol<const char*(dvar_t* dvar, dvar_value value)> Dvar_ValueToString{0x140374E10, 0x1404C47B0};
WEAK symbol<dvar_t*(const char* dvarName, bool value, unsigned int flags)> Dvar_RegisterBool{0x140371850, 0x1404C0BE0};
WEAK symbol<dvar_t*(const char* dvarName, const char** valueList, int defaultIndex, unsigned int flags)> Dvar_RegisterEnum{0x140371B30, 0x1404C0EC0};
WEAK symbol<dvar_t*(const char* dvarName, float value, float min, float max, unsigned int flags)> Dvar_RegisterFloat{0x140371C20, 0x1404C0FB0};
WEAK symbol<dvar_t*(const char* dvarName, int value, int min, int max, unsigned int flags)> Dvar_RegisterInt{0x140371CF0, 0x1404C1080};
WEAK symbol<dvar_t*(const char* dvarName, const char* value, unsigned int flags)> Dvar_RegisterString{0x140372050, 0x1404C1450};
WEAK symbol<dvar_t*(const char* dvarName, float x, float y, float min, float max, unsigned int flags)> Dvar_RegisterVec2{0x140372120, 0x1404C1520};
WEAK symbol<dvar_t*(const char* dvarName, float x, float y, float z, float min, float max, unsigned int flags)> Dvar_RegisterVec3{0x140372230, 0x1404C1600};
WEAK symbol<dvar_t*(const char* dvarName, float x, float y, float z, float w, float min, float max, unsigned int flags)> Dvar_RegisterVec4{0x140372430, 0x1404C1800};
WEAK symbol<dvar_t*(const char* dvarName, bool value, unsigned int flags, const char* description)>
Dvar_RegisterBool{0x140371850, 0x1404C0BE0};
WEAK symbol<dvar_t*(const char* dvarName, const char** valueList, int defaultIndex, unsigned int flags,
const char* description)> Dvar_RegisterEnum{0x140371B30, 0x1404C0EC0};
WEAK symbol<dvar_t*(const char* dvarName, float value, float min, float max, unsigned int flags,
const char* description)> Dvar_RegisterFloat{0x140371C20, 0x1404C0FB0};
WEAK symbol<dvar_t*(const char* dvarName, int value, int min, int max, unsigned int flags, const char* desc)>
Dvar_RegisterInt{0x140371CF0, 0x1404C1080};
WEAK symbol<dvar_t*(const char* dvarName, const char* value, unsigned int flags, const char* description)>
Dvar_RegisterString{0x140372050, 0x1404C1450};
WEAK symbol<dvar_t* (const char* dvarName, float x, float y, float min, float max,
unsigned int flags, const char* description)> Dvar_RegisterVec2{0x140372120, 0x1404C1520};
WEAK symbol<dvar_t* (const char* dvarName, float x, float y, float z, float min, float max,
unsigned int flags, const char* description)> Dvar_RegisterVec3{0x140372230, 0x1404C1600};
WEAK symbol<dvar_t*(const char* dvarName, float x, float y, float z, float w, float min, float max,
unsigned int flags, const char* description)> Dvar_RegisterVec4{0x140372430, 0x1404C1800};
WEAK symbol<DWOnlineStatus()> dwGetLogOnStatus{0, 0x14053CCB0};
@ -90,7 +96,7 @@ namespace game
WEAK symbol<void (const char *path, const char *dir)> FS_AddLocalizedGameDirectory{0x14035F5C0, 0x1404AD170};
WEAK symbol<void()> GScr_LoadConsts{0x140283970, 0x1403479C0};
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindVariable{0x1403166D0, 0x1403F2DC0};
WEAK symbol<unsigned int(unsigned int parentId, unsigned int name)> FindVariable{0x1403165D0, 0x1403F2DC0};
WEAK symbol<unsigned int(int entnum, unsigned int classnum)> FindEntityId{0x1403166D0, 0x1403F2CC0};
WEAK symbol<scr_string_t(unsigned int parentId, unsigned int id)> GetVariableName{0x1403170E0, 0x1403F37F0};
WEAK symbol<void(VariableValue* result, unsigned int classnum, int entnum, int offset)> GetEntityFieldValue{0x14031AAD0, 0x1403F72A0};
@ -146,23 +152,21 @@ namespace game
WEAK symbol<void(int value)> Scr_AddInt{0x0, 0x1403F7B30};
WEAK symbol<int(unsigned int index)> Scr_GetInt{0x14031C1F0, 0x1403F88D0};
WEAK symbol<float(unsigned int index)> Scr_GetFloat{0x14031C090, 0x1403F8820};
WEAK symbol<void(unsigned int index, float* vectorValue)> Scr_GetVector{0x14031C7E0, 0x1403F8EC0};
WEAK symbol<unsigned int()> Scr_GetNumParam{0x14031C2A0, 0x1403F8980};
WEAK symbol<void()> Scr_ClearOutParams{0x14031B7C0, 0x1403F8040};
WEAK symbol<scr_entref_t(unsigned int entId)> Scr_GetEntityIdRef{0x14031A0D0, 0x1403F68A0};
WEAK symbol<int(unsigned int classnum, int entnum, int offset)> Scr_SetObjectField{0x14026B620, 0x140339450};
WEAK symbol<void(void* ent, unsigned int stringValue, unsigned int paramcount)> Scr_Notify{0x0, 0x140339120};
WEAK symbol<void(unsigned int id, unsigned int stringValue, unsigned int paramcount)> Scr_NotifyId{0x14031CB80, 0x1403F92D0};
WEAK symbol<bool(VariableValue* value)> Scr_CastString{0x140317EA0, 0x1403F4500};
WEAK symbol<bool(VariableValue* value)> Scr_CastString{0x0, 0x1403F4500};
WEAK symbol<unsigned __int16(int handle, unsigned int paramcount)> Scr_ExecThread{0x14031B8C0, 0x1403F8120};
WEAK symbol<unsigned int(const char* name)> Scr_LoadScript{0x140311CD0, 0x1403EE250};
WEAK symbol<unsigned int(const char* filename, unsigned int name)> Scr_GetFunctionHandle{0x140311B50, 0x1403EE0D0};
WEAK symbol<unsigned __int16(int handle, unsigned int paramcount)> Scr_ExecThread{0x0, 0x1403F8120};
WEAK symbol<unsigned int(const char* name)> Scr_LoadScript{0x0, 0x1403EE250};
WEAK symbol<unsigned int(const char* script, unsigned int name)> Scr_GetFunctionHandle{0x0, 0x1403EE0D0};
WEAK symbol<unsigned int(void* func, int type, unsigned int name)> Scr_RegisterFunction{0x1403115B0, 0x1403EDAE0};
WEAK symbol<unsigned int(const char** pName, int* type)> Scr_GetFunction{0x140263E90, 0x1403318B0};
WEAK symbol<unsigned int(unsigned int localId, const char* pos, unsigned int paramcount)> VM_Execute{0x0, 0x1403F9E40};
WEAK symbol<void()> Scr_ErrorInternal{0x14031B840, 0x1403F80A0};
WEAK symbol<void()> Scr_ErrorInternal{0x0, 0x1403F80A0};
WEAK symbol<const char*(scr_string_t stringValue)> SL_ConvertToString{0x140314850, 0x1403F0F10};
WEAK symbol<scr_string_t(const char* str)> SL_FindString{0x140314AF0, 0x1403F11C0};
@ -198,7 +202,8 @@ namespace game
WEAK symbol<void(int index, const char* string)> SV_SetConfigstring{0, 0x14043FCA0};
WEAK symbol<void(char* path, int pathSize, Sys_Folder folder, const char* filename, const char* ext)> Sys_BuildAbsPath{0x14037BBE0, 0x1404CC7E0};
WEAK symbol<void(char* path, int pathSize, Sys_Folder folder, const char* filename, const char* ext)>
Sys_BuildAbsPath{0x14037BBE0, 0x1404CC7E0};
WEAK symbol<HANDLE(int folder, const char* baseFileName)> Sys_CreateFile{0x14037BCA0, 0x1404CC8A0};
WEAK symbol<void(const char* error, ...)> Sys_Error{0x14038C770, 0x1404D6260};
WEAK symbol<bool(const char* path)> Sys_FileExists{0x14038C810, 0x1404D6310};
@ -214,16 +219,11 @@ namespace game
WEAK symbol<void(unsigned int localClientNum, const char** args)> UI_RunMenuScript{0, 0x140490060};
WEAK symbol<int(const char* text, int maxChars, Font_s* font, float scale)> UI_TextWidth{0, 0x140492380};
WEAK symbol<const char* ()> SEH_GetCurrentLanguageCode{0x140339280, 0x140474560};
WEAK symbol<const char*()> SEH_GetCurrentLanguageName{0x140339300, 0x1404745C0};
WEAK symbol<void*(unsigned int size, unsigned int alignment, unsigned int type, int source)> PMem_AllocFromSource_NoDebug{0x1403775F0, 0x1404C7BA0};
WEAK symbol<void*(unsigned int size)> Hunk_AllocateTempMemoryHighInternal{0x140369D60, 0x1404B68B0};
WEAK symbol<void(unsigned __int64 markPos)> LargeLocalResetToMark{0x140369C40, 0x1404B6790};
WEAK symbol<void(char* dest, const char* src, int destsize)> I_strncpyz{0x1403793B0, 0x1404C9E60};
WEAK symbol<void*(jmp_buf* Buf, int Value)> longjmp{0x14059C5C0, 0x1406FD930};
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x14059CD00, 0x1406FE070};
@ -246,8 +246,6 @@ namespace game
WEAK symbol<jmp_buf> g_script_error{0x14A1917B0, 0x1487FA0C0};
WEAK symbol<scr_classStruct_t> g_classMap{0x14080A840, 0x1409BE1B0};
WEAK symbol<float> com_codeTimeScale{0x0, 0x147B754EC};
WEAK symbol<scrVarGlob_t> scr_VarGlob{0x149B1D680, 0x148185F80};
WEAK symbol<scrVmPub_t> scr_VmPub{0x14A1938C0, 0x1487FC1C0};
WEAK symbol<function_stack_t> scr_function_stack{0x14A19DE40, 0x148806740};
@ -263,7 +261,6 @@ namespace game
WEAK symbol<XAssetEntry> g_assetEntryPool{0x142CC2400, 0x14379F100};
WEAK symbol<int> g_poolSize{0x140804140, 0x1409B4B90};
WEAK symbol<const char*> g_assetNames{0x140803C90, 0x1409B3180};
WEAK symbol<int> g_compressor{0x141598580, 0x141E0B080};
WEAK symbol<DWORD> threadIds{0x149632EC0, 0x147DCEA30};
@ -271,9 +268,6 @@ namespace game
WEAK symbol<unsigned int> tls_index{0x14F65DAF0, 0x150085C44};
WEAK symbol<unsigned int> g_zoneCount{0x0, 0x14379DBCC};
WEAK symbol<XZone> g_zones{0x0, 0x143B50618};
namespace mp
{
WEAK symbol<gentity_s> g_entities{0, 0x144758C70};

View File

@ -1,25 +0,0 @@
#include "properties.hpp"
#include <gsl/gsl>
#include <ShlObj.h>
namespace utils::properties
{
std::filesystem::path get_appdata_path()
{
PWSTR path;
if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &path)))
{
throw std::runtime_error("Failed to read APPDATA path!");
}
auto _ = gsl::finally([&path]
{
CoTaskMemFree(path);
});
static auto appdata = std::filesystem::path(path) / "alterware";
return appdata;
}
}

View File

@ -1,7 +0,0 @@
#pragma once
#include <filesystem>
namespace utils::properties
{
std::filesystem::path get_appdata_path();
}

View File

@ -109,13 +109,13 @@ namespace utils::string
void strip(const char* in, char* out, size_t max)
{
if (!in || !out || !max) return;
if (!in || !out) return;
max--;
auto current = 0u;
while (*in != 0 && current < max)
{
const auto color_index = (static_cast<size_t>(*(in + 1) - 48)) >= 0xC ? 7 : (*(in + 1) - 48);
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);
if (*in == '^' && (color_index != 7 || *(in + 1) == '7'))
{
@ -176,52 +176,4 @@ namespace utils::string
return str;
}
bool is_numeric(const std::string& text)
{
return std::to_string(atoi(text.data())) == text;
}
bool find_lower(const std::string& a, const std::string& b)
{
return to_lower(a).find(to_lower(b)) != std::string::npos;
}
bool strstr_lower(const char* a, const char* b)
{
const char* a_ = a;
const char* b_ = b;
while (*a_ != '\0' && *b_ != '\0')
{
if (*b_ == '*' || std::tolower(*a_) == std::tolower(*b_))
{
b_++;
}
else
{
b_ = b;
}
a_++;
}
return *b_ == '\0';
}
void set_clipboard_data(const std::string& text)
{
const auto len = text.size() + 1;
const auto mem = GlobalAlloc(GMEM_MOVEABLE, len);
memcpy(GlobalLock(mem), text.data(), len);
GlobalUnlock(mem);
if (OpenClipboard(nullptr))
{
EmptyClipboard();
SetClipboardData(CF_TEXT, mem);
CloseClipboard();
}
}
}

View File

@ -95,12 +95,4 @@ namespace utils::string
std::wstring convert(const std::string& str);
std::string replace(std::string str, const std::string& from, const std::string& to);
bool is_numeric(const std::string& text);
bool find_lower(const std::string& a, const std::string& b);
bool strstr_lower(const char* a, const char* b);
void set_clipboard_data(const std::string& text);
}