Merge branch 'develop' into dependabot/submodules/deps/zlib-643e17b

This commit is contained in:
Louve 2024-01-11 23:25:57 +01:00 committed by GitHub
commit 17e193fd46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 737 additions and 478 deletions

2
deps/GSL vendored

@ -1 +1 @@
Subproject commit 4300304ef24c247b3db0255763f46b9f95c3a83d Subproject commit e64c97fc2cfc11992098bb38eda932de275e3f4d

@ -1 +1 @@
Subproject commit aaf4455bdac1ccd07c6eeeac993b7800124244c0 Subproject commit 700a2ae858c27568d95e21ce8c5f941d36c4a6c4

2
deps/libtommath vendored

@ -1 +1 @@
Subproject commit 3746c58f29a1ebea15046932bbc9dacc35b4b214 Subproject commit 8314bde5e5c8e5d9331460130a9d1066e324f091

View File

@ -349,9 +349,13 @@ namespace Components
AssetHandler::TypeCallbacks[type] = callback; AssetHandler::TypeCallbacks[type] = callback;
} }
void AssetHandler::OnLoad(Utils::Slot<AssetHandler::RestrictCallback> callback) std::function<void()> AssetHandler::OnLoad(Utils::Slot<AssetHandler::RestrictCallback> callback)
{ {
AssetHandler::RestrictSignal.connect(callback); AssetHandler::RestrictSignal.connect(callback);
return [callback](){
AssetHandler::RestrictSignal.disconnect(callback);
};
} }
void AssetHandler::ClearRelocations() void AssetHandler::ClearRelocations()

View File

@ -23,7 +23,7 @@ namespace Components
~AssetHandler(); ~AssetHandler();
static void OnFind(Game::XAssetType type, Utils::Slot<Callback> callback); static void OnFind(Game::XAssetType type, Utils::Slot<Callback> callback);
static void OnLoad(Utils::Slot<RestrictCallback> callback); static std::function<void()> OnLoad(Utils::Slot<RestrictCallback> callback);
static void ClearRelocations(); static void ClearRelocations();
static void Relocate(void* start, void* to, DWORD size = 4); static void Relocate(void* start, void* to, DWORD size = 4);

View File

@ -3,9 +3,9 @@
namespace Assets namespace Assets
{ {
void ITracerDef::load(Game::XAssetHeader* /*header*/, const std::string& /*name*/, Components::ZoneBuilder::Zone* /*builder*/) void ITracerDef::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
{ {
// don't load from filesystem right now header->tracerDef = builder->getIW4OfApi()->read<Game::TracerDef>(Game::XAssetType::ASSET_TYPE_TRACER, name);
} }
void ITracerDef::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) void ITracerDef::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)

View File

@ -3,8 +3,16 @@
namespace Assets namespace Assets
{ {
void IWeapon::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* /*builder*/) void IWeapon::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
{ {
header->weapon = builder->getIW4OfApi()->read<Game::WeaponCompleteDef>(Game::XAssetType::ASSET_TYPE_WEAPON, name);
if (header->weapon)
{
return;
}
// Try loading raw weapon // Try loading raw weapon
if (Components::FileSystem::File(std::format("weapons/mp/{}", name))) if (Components::FileSystem::File(std::format("weapons/mp/{}", name)))
{ {
@ -121,7 +129,10 @@ namespace Assets
if (asset->weapDef->projIgnitionEffect) builder->loadAsset(Game::XAssetType::ASSET_TYPE_FX, asset->weapDef->projIgnitionEffect); if (asset->weapDef->projIgnitionEffect) builder->loadAsset(Game::XAssetType::ASSET_TYPE_FX, asset->weapDef->projIgnitionEffect);
if (asset->weapDef->turretOverheatEffect) builder->loadAsset(Game::XAssetType::ASSET_TYPE_FX, asset->weapDef->turretOverheatEffect); if (asset->weapDef->turretOverheatEffect) builder->loadAsset(Game::XAssetType::ASSET_TYPE_FX, asset->weapDef->turretOverheatEffect);
#define LoadWeapSound(sound) if (asset->weapDef->##sound##) builder->loadAsset(Game::XAssetType::ASSET_TYPE_SOUND, asset->weapDef->##sound##)
// They are not subassets, because they don't get loaded automatically
#define LoadWeapSound(sound) if (asset->weapDef->##sound##) builder->loadAsset(Game::XAssetType::ASSET_TYPE_SOUND, asset->weapDef->##sound##, false)
LoadWeapSound(pickupSound); LoadWeapSound(pickupSound);
LoadWeapSound(pickupSoundPlayer); LoadWeapSound(pickupSoundPlayer);
@ -193,6 +204,33 @@ namespace Assets
LoadWeapSound(missileConeSoundAlias); LoadWeapSound(missileConeSoundAlias);
LoadWeapSound(missileConeSoundAliasAtBase); LoadWeapSound(missileConeSoundAliasAtBase);
for (size_t i = 0; i < 37; i++)
{
{
const auto anim = asset->weapDef->szXAnimsLeftHanded[i];
if (anim && strnlen(anim, 1) > 0) {
builder->loadAssetByName(Game::XAssetType::ASSET_TYPE_XANIMPARTS, anim, false);
}
}
{
const auto anim = asset->weapDef->szXAnimsRightHanded[i];
if (anim && strnlen(anim, 1) > 0) {
builder->loadAssetByName(Game::XAssetType::ASSET_TYPE_XANIMPARTS, anim, false);
}
}
{
const auto anim = asset->szXAnims[i];
if (anim && strnlen(anim, 1) > 0) {
builder->loadAssetByName(Game::XAssetType::ASSET_TYPE_XANIMPARTS, anim, false);
}
}
}
if (asset->szAltWeaponName && *asset->szAltWeaponName != 0 && asset->weapDef->ammoCounterClip != Game::AMMO_COUNTER_CLIP_ALTWEAPON) // A very bad way to check if this is already an alt
{
builder->loadAssetByName(Game::XAssetType::ASSET_TYPE_WEAPON, asset->szAltWeaponName, false);
}
} }
void IWeapon::writeWeaponDef(Game::WeaponDef* def, Components::ZoneBuilder::Zone* builder, Utils::Stream* buffer) void IWeapon::writeWeaponDef(Game::WeaponDef* def, Components::ZoneBuilder::Zone* builder, Utils::Stream* buffer)
@ -782,4 +820,26 @@ namespace Assets
buffer->popBlock(); buffer->popBlock();
} }
IWeapon::IWeapon()
{
Components::Command::Add("dumpweapon", [](const Components::Command::Params* params)
{
if (params->size() < 2) return;
std::string weapon = params->get(1);
const auto header = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_WEAPON, weapon.data());
if (header.data)
{
Components::ZoneBuilder::RefreshExporterWorkDirectory();
Components::ZoneBuilder::GetExporter()->write(Game::XAssetType::ASSET_TYPE_WEAPON, header.data);
}
else
{
Components::Logger::Print("Could not find weapon {}!\n", weapon);
}
}
);
}
} }

View File

@ -6,6 +6,7 @@ namespace Assets
{ {
public: public:
Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_WEAPON; } Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_WEAPON; }
IWeapon();
void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; void mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;

View File

@ -21,7 +21,8 @@ namespace Components
{ {
0xf4d2c30b712ac6e3, 0xf4d2c30b712ac6e3,
0xf7e33c4081337fa3, 0xf7e33c4081337fa3,
0x6f5597f103cc50e9 0x6f5597f103cc50e9,
0xecd542eee54ffccf,
}; };
bool Auth::HasAccessToReservedSlot; bool Auth::HasAccessToReservedSlot;

View File

@ -27,6 +27,9 @@ namespace Components
std::int8_t forward; std::int8_t forward;
std::int8_t right; std::int8_t right;
std::uint16_t weapon; std::uint16_t weapon;
std::uint16_t lastAltWeapon;
std::uint8_t meleeDist;
float meleeYaw;
bool active; bool active;
}; };
@ -291,6 +294,23 @@ namespace Components
g_botai[entref.entnum].right = static_cast<int8_t>(rightInt); g_botai[entref.entnum].right = static_cast<int8_t>(rightInt);
g_botai[entref.entnum].active = true; g_botai[entref.entnum].active = true;
}); });
GSC::Script::AddMethod("BotMeleeParams", [](const Game::scr_entref_t entref) // Usage: <bot> BotMeleeParams(<float>, <float>);
{
const auto* ent = GSC::Script::Scr_GetPlayerEntity(entref);
if (!Game::SV_IsTestClient(ent->s.number))
{
Game::Scr_Error("BotMeleeParams: Can only call on a bot!");
return;
}
const auto yaw = Game::Scr_GetFloat(0);
const auto dist = std::clamp<int>(static_cast<int>(Game::Scr_GetFloat(1)), std::numeric_limits<unsigned char>::min(), std::numeric_limits<unsigned char>::max());
g_botai[entref.entnum].meleeYaw = yaw;
g_botai[entref.entnum].meleeDist = static_cast<int8_t>(dist);
g_botai[entref.entnum].active = true;
});
} }
void Bots::BotAiAction(Game::client_s* cl) void Bots::BotAiAction(Game::client_s* cl)
@ -300,8 +320,10 @@ namespace Components
return; return;
} }
auto clientNum = cl - Game::svs_clients;
// Keep test client functionality // Keep test client functionality
if (!g_botai[cl - Game::svs_clients].active) if (!g_botai[clientNum].active)
{ {
Game::SV_BotUserMove(cl); Game::SV_BotUserMove(cl);
return; return;
@ -312,10 +334,13 @@ namespace Components
userCmd.serverTime = *Game::svs_time; userCmd.serverTime = *Game::svs_time;
userCmd.buttons = g_botai[cl - Game::svs_clients].buttons; userCmd.buttons = g_botai[clientNum].buttons;
userCmd.forwardmove = g_botai[cl - Game::svs_clients].forward; userCmd.forwardmove = g_botai[clientNum].forward;
userCmd.rightmove = g_botai[cl - Game::svs_clients].right; userCmd.rightmove = g_botai[clientNum].right;
userCmd.weapon = g_botai[cl - Game::svs_clients].weapon; userCmd.weapon = g_botai[clientNum].weapon;
userCmd.primaryWeaponForAltMode = g_botai[clientNum].lastAltWeapon;
userCmd.meleeChargeYaw = g_botai[clientNum].meleeYaw;
userCmd.meleeChargeDist = g_botai[clientNum].meleeDist;
userCmd.angles[0] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[0] - cl->gentity->client->ps.delta_angles[0])); userCmd.angles[0] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[0] - cl->gentity->client->ps.delta_angles[0]));
userCmd.angles[1] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[1] - cl->gentity->client->ps.delta_angles[1])); userCmd.angles[1] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[1] - cl->gentity->client->ps.delta_angles[1]));
@ -339,11 +364,38 @@ namespace Components
} }
} }
void Bots::G_SelectWeaponIndex(int clientNum, int iWeaponIndex) void Bots::G_SelectWeaponIndex(int clientNum, unsigned int iWeaponIndex)
{ {
if (g_botai[clientNum].active) if (g_botai[clientNum].active)
{ {
g_botai[clientNum].weapon = static_cast<uint16_t>(iWeaponIndex); g_botai[clientNum].weapon = static_cast<uint16_t>(iWeaponIndex);
g_botai[clientNum].lastAltWeapon = 0;
auto* def = Game::BG_GetWeaponCompleteDef(iWeaponIndex);
if (def && def->weapDef->inventoryType == Game::WEAPINVENTORY_ALTMODE)
{
auto* ps = &Game::g_entities[clientNum].client->ps;
auto numWeaps = Game::BG_GetNumWeapons();
for (auto i = 1u; i < numWeaps; i++)
{
if (!Game::BG_PlayerHasWeapon(ps, i))
{
continue;
}
auto* thisDef = Game::BG_GetWeaponCompleteDef(i);
if (!thisDef || thisDef->altWeaponIndex != iWeaponIndex)
{
continue;
}
g_botai[clientNum].lastAltWeapon = static_cast<uint16_t>(i);
break;
}
}
} }
} }
@ -472,6 +524,11 @@ namespace Components
}); });
} }
bool Bots::Player_UpdateActivate_stub(int)
{
return false;
}
Bots::Bots() Bots::Bots()
{ {
AssertOffset(Game::client_s, bIsTestClient, 0x41AF0); AssertOffset(Game::client_s, bIsTestClient, 0x41AF0);
@ -489,6 +546,9 @@ namespace Components
Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick(); Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick();
// fix bots using objects (SV_IsClientBot)
Utils::Hook(0x4D79C5, Player_UpdateActivate_stub, HOOK_CALL).install()->quick();
Utils::Hook(0x459654, SV_GetClientPing_Hk, HOOK_CALL).install()->quick(); Utils::Hook(0x459654, SV_GetClientPing_Hk, HOOK_CALL).install()->quick();
sv_randomBotNames = Game::Dvar_RegisterBool("sv_randomBotNames", false, Game::DVAR_NONE, "Randomize the bots' names"); sv_randomBotNames = Game::Dvar_RegisterBool("sv_randomBotNames", false, Game::DVAR_NONE, "Randomize the bots' names");

View File

@ -32,9 +32,11 @@ namespace Components
static void BotAiAction(Game::client_s* cl); static void BotAiAction(Game::client_s* cl);
static void SV_BotUserMove_Hk(); static void SV_BotUserMove_Hk();
static void G_SelectWeaponIndex(int clientNum, int iWeaponIndex); static void G_SelectWeaponIndex(int clientNum, unsigned int iWeaponIndex);
static void G_SelectWeaponIndex_Hk(); static void G_SelectWeaponIndex_Hk();
static bool Player_UpdateActivate_stub(int);
static int SV_GetClientPing_Hk(int clientNum); static int SV_GetClientPing_Hk(int clientNum);
static bool IsFull(); static bool IsFull();

View File

@ -1,6 +1,8 @@
#include <STDInclude.hpp> #include <STDInclude.hpp>
#include "ClientCommand.hpp" #include "ClientCommand.hpp"
#include "Weapon.hpp"
#include "GSC/Script.hpp" #include "GSC/Script.hpp"
using namespace Utils::String; using namespace Utils::String;
@ -382,7 +384,14 @@ namespace Components
Game::XModel* model = nullptr; Game::XModel* model = nullptr;
if (ent->model) if (ent->model)
{ {
model = Game::G_GetModel(ent->model); if (Components::Weapon::GModelIndexHasBeenReallocated)
{
model = Components::Weapon::G_ModelIndexReallocated[ent->model];
}
else
{
model = Game::G_GetModel(ent->model);
}
} }
Game::vec3_t point, angles; Game::vec3_t point, angles;

View File

@ -30,12 +30,20 @@ namespace Components::GSC
std::filesystem::path IO::BuildPath(const char* path) std::filesystem::path IO::BuildPath(const char* path)
{ {
const std::filesystem::path fsGame = (*Game::fs_gameDirVar)->current.string; const std::filesystem::path fsGame = (*Game::fs_gameDirVar)->current.string;
if (!fsGame.empty())
// check if we need to append scriptdata folder, for backwards compat
std::string spath = path;
if (!spath.starts_with(Game::SCRIPTDATA_DIR + "/"s) && !spath.starts_with(Game::SCRIPTDATA_DIR + "\\"s))
{ {
return fsGame / "scriptdata"s / path; spath = Game::SCRIPTDATA_DIR + "/"s + spath;
} }
return DefaultDestPath / "scriptdata"s / path; if (!fsGame.empty())
{
return fsGame / spath;
}
return DefaultDestPath / spath;
} }
void IO::GScr_OpenFile() void IO::GScr_OpenFile()
@ -154,7 +162,7 @@ namespace Components::GSC
return; return;
} }
file = file.substr(0, 1024 - 1); // 1024 is the max string size for the SL system file = file.substr(0, (1 << 16) - 1); // 65535 is the max string size for the SL system
Game::Scr_AddString(file.data()); Game::Scr_AddString(file.data());
}); });

View File

@ -194,7 +194,16 @@ namespace Components::GSC
unsigned int ScriptError::Scr_GetPrevSourcePos(const char* codePos, unsigned int index) unsigned int ScriptError::Scr_GetPrevSourcePos(const char* codePos, unsigned int index)
{ {
return ScrParserGlob.sourcePosLookup[index + Scr_GetPrevSourcePosOpcodeLookup(codePos)->sourcePosIndex].sourcePos; const auto prevIndex = Scr_GetPrevSourcePosOpcodeLookup(codePos)->sourcePosIndex;
const auto sPos = ScrParserGlob.sourcePosLookup[index + prevIndex].sourcePos;
// I'm not sure why this is necessary - when given a valid codePos, sometimes
// the sourcePos ends up being a negative number (got a case where it was -2)
// which will output a giantic unsigned number and crash
// So we make sure it's not gonna happen here by clamping the number
const auto uPos = static_cast<unsigned int>(std::max(0, static_cast<int>(sPos)));
return uPos;
} }
Game::OpcodeLookup* ScriptError::Scr_GetPrevSourcePosOpcodeLookup(const char* codePos) Game::OpcodeLookup* ScriptError::Scr_GetPrevSourcePosOpcodeLookup(const char* codePos)
@ -326,7 +335,9 @@ namespace Components::GSC
if (Game::scrVarPub->programBuffer && Scr_IsInOpcodeMemory(codePos)) if (Game::scrVarPub->programBuffer && Scr_IsInOpcodeMemory(codePos))
{ {
auto bufferIndex = Scr_GetSourceBuffer(codePos - 1); auto bufferIndex = Scr_GetSourceBuffer(codePos - 1);
Scr_PrintSourcePos(channel, ScrParserPub.sourceBufferLookup[bufferIndex].buf, ScrParserPub.sourceBufferLookup[bufferIndex].sourceBuf, Scr_GetPrevSourcePos(codePos - 1, index)); const auto prevSourcePos = Scr_GetPrevSourcePos(codePos - 1, index);
Scr_PrintSourcePos(channel, ScrParserPub.sourceBufferLookup[bufferIndex].buf, ScrParserPub.sourceBufferLookup[bufferIndex].sourceBuf, prevSourcePos);
return; return;
} }
} }

View File

@ -84,12 +84,12 @@ namespace Components::GSC
const nlohmann::json json = Data; const nlohmann::json json = Data;
FileSystem::FileWriter("scriptdata/scriptstorage.json").write(json.dump()); FileSystem::FileWriter(Game::SCRIPTDATA_DIR + "/scriptstorage.json"s).write(json.dump());
}); });
Script::AddFunction("StorageLoad", [] // gsc: StorageLoad(); Script::AddFunction("StorageLoad", [] // gsc: StorageLoad();
{ {
FileSystem::File storageFile("scriptdata/scriptstorage.json"); FileSystem::File storageFile(Game::SCRIPTDATA_DIR + "/scriptstorage.json"s);
if (!storageFile.exists()) if (!storageFile.exists())
{ {
return; return;

View File

@ -105,14 +105,15 @@ namespace Components
{ {
std::string data = RawFiles::ReadRawFile(name, buffer, size); std::string data = RawFiles::ReadRawFile(name, buffer, size);
if (Maps::UserMap.isValid()) if (Maps::UserMap.isValid())
{ {
const auto mapname = Maps::UserMap.getName(); const auto mapname = Maps::UserMap.getName();
const auto arena = GetArenaPath(mapname); const auto arena = GetArenaPath(mapname);
if (Utils::IO::FileExists(arena)) if (Utils::IO::FileExists(arena))
{ {
data.append(Utils::IO::ReadFile(arena)); // Replace all arenas with just this one
data = Utils::IO::ReadFile(arena);
} }
} }
@ -204,8 +205,7 @@ namespace Components
void Maps::LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* restrict) void Maps::LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* restrict)
{ {
if (std::find(Maps::CurrentDependencies.begin(), Maps::CurrentDependencies.end(), FastFiles::Current()) != Maps::CurrentDependencies.end() if (std::find(Maps::CurrentDependencies.begin(), Maps::CurrentDependencies.end(), FastFiles::Current()) != Maps::CurrentDependencies.end()) // Shipment is a special case
&& (FastFiles::Current() != "mp_shipment_long" || Maps::CurrentMainZone != "mp_shipment")) // Shipment is a special case
{ {
switch (type) switch (type)
{ {
@ -314,6 +314,7 @@ namespace Components
} }
} }
// TODO : Remove hook entirely?
void Maps::GetBSPName(char* buffer, size_t size, const char* format, const char* mapname) void Maps::GetBSPName(char* buffer, size_t size, const char* format, const char* mapname)
{ {
if (!Utils::String::StartsWith(mapname, "mp_")) if (!Utils::String::StartsWith(mapname, "mp_"))
@ -321,12 +322,6 @@ namespace Components
format = "maps/%s.d3dbsp"; format = "maps/%s.d3dbsp";
} }
// TODO: Remove this hack by using CoD4 version of the map
if (std::strcmp(mapname, "mp_shipment") == 0)
{
mapname = "mp_shipment_long";
}
_snprintf_s(buffer, size, _TRUNCATE, format, mapname); _snprintf_s(buffer, size, _TRUNCATE, format, mapname);
} }
@ -850,6 +845,14 @@ namespace Components
// Load usermap arena file // Load usermap arena file
Utils::Hook(0x630A88, Maps::LoadArenaFileStub, HOOK_CALL).install()->quick(); Utils::Hook(0x630A88, Maps::LoadArenaFileStub, HOOK_CALL).install()->quick();
// Always refresh arena when loading or unloading a zone
Utils::Hook::Nop(0x485017, 2);
Utils::Hook::Nop(0x4FD8C7, 2); // Gametypes
Utils::Hook::Nop(0x4BDFB7, 2); // Unknown
Utils::Hook::Nop(0x45ED6F, 2); // loadGameInfo
Utils::Hook::Nop(0x4A5888, 2); // UI_InitOnceForAllClients
// Allow hiding specific smodels // Allow hiding specific smodels
Utils::Hook(0x50E67C, Maps::HideModelStub, HOOK_CALL).install()->quick(); Utils::Hook(0x50E67C, Maps::HideModelStub, HOOK_CALL).install()->quick();

View File

@ -6,6 +6,8 @@
namespace Components namespace Components
{ {
const Game::dvar_t* Weapon::BGWeaponOffHandFix; const Game::dvar_t* Weapon::BGWeaponOffHandFix;
Game::XModel* Weapon::G_ModelIndexReallocated[G_MODELINDEX_LIMIT];
bool Weapon::GModelIndexHasBeenReallocated;
Game::WeaponCompleteDef* Weapon::LoadWeaponCompleteDef(const char* name) Game::WeaponCompleteDef* Weapon::LoadWeaponCompleteDef(const char* name)
{ {
@ -433,6 +435,21 @@ namespace Components
Utils::Hook::Set<DWORD>(0x4F76FB, 0x12EC + (sizeof(bg_sharedAmmoCaps) - (1200 * 4))); Utils::Hook::Set<DWORD>(0x4F76FB, 0x12EC + (sizeof(bg_sharedAmmoCaps) - (1200 * 4)));
// Move arg4 pointers // Move arg4 pointers
Utils::Hook::Set<DWORD>(0x4F7630, 0x12DC + (sizeof(bg_sharedAmmoCaps) - (1200 * 4))); Utils::Hook::Set<DWORD>(0x4F7630, 0x12DC + (sizeof(bg_sharedAmmoCaps) - (1200 * 4)));
// Reallocate G_ModelIndex
Utils::Hook::Set(0x420654 + 3, G_ModelIndexReallocated);
Utils::Hook::Set(0x43BCE4 + 3, G_ModelIndexReallocated);
Utils::Hook::Set(0x44F27B + 3, G_ModelIndexReallocated);
Utils::Hook::Set(0x479087 + 1, G_ModelIndexReallocated);
Utils::Hook::Set(0x48069D + 3, G_ModelIndexReallocated);
Utils::Hook::Set(0x48F088 + 3, G_ModelIndexReallocated);
Utils::Hook::Set(0x4F457C + 3, G_ModelIndexReallocated);
Utils::Hook::Set(0x5FC762 + 3, G_ModelIndexReallocated);
Utils::Hook::Set(0x5FC7BE + 3, G_ModelIndexReallocated);
Utils::Hook::Set<DWORD>(0x44F256 + 2, G_MODELINDEX_LIMIT);
GModelIndexHasBeenReallocated = true;
} }
void* Weapon::LoadNoneWeaponHook() void* Weapon::LoadNoneWeaponHook()
@ -636,6 +653,10 @@ namespace Components
Utils::Hook::Nop(0x408230, 5); // is asset default Utils::Hook::Nop(0x408230, 5); // is asset default
Utils::Hook::Nop(0x40823A, 2); // jump Utils::Hook::Nop(0x40823A, 2); // jump
// Automatically register weapons, even if the level is not loading
Utils::Hook::Nop(0x49E547, 2);
Utils::Hook::Set<BYTE>(0x44F240, 0xEB);
// Skip double loading for fs_game // Skip double loading for fs_game
Utils::Hook::Set<BYTE>(0x4081FD, 0xEB); Utils::Hook::Set<BYTE>(0x4081FD, 0xEB);

View File

@ -5,12 +5,20 @@
#define WEAPON_LIMIT 2400 #define WEAPON_LIMIT 2400
#define MAX_CONFIGSTRINGS (4139 - 1200 + WEAPON_LIMIT) #define MAX_CONFIGSTRINGS (4139 - 1200 + WEAPON_LIMIT)
// Double the limit to allow loading of some heavy-duty MW3 maps
#define ADDITIONAL_GMODELS 512
#define G_MODELINDEX_LIMIT (512 + WEAPON_LIMIT - 1200 + ADDITIONAL_GMODELS)
namespace Components namespace Components
{ {
class Weapon : public Component class Weapon : public Component
{ {
public: public:
Weapon(); Weapon();
static Game::XModel* G_ModelIndexReallocated[G_MODELINDEX_LIMIT];
static bool GModelIndexHasBeenReallocated;
private: private:
static const Game::dvar_t* BGWeaponOffHandFix; static const Game::dvar_t* BGWeaponOffHandFix;

File diff suppressed because it is too large Load Diff

View File

@ -11,4 +11,6 @@ namespace Game
BG_IsWeaponValid_t BG_IsWeaponValid = BG_IsWeaponValid_t(0x415BA0); BG_IsWeaponValid_t BG_IsWeaponValid = BG_IsWeaponValid_t(0x415BA0);
BG_GetEquippedWeaponIndex_t BG_GetEquippedWeaponIndex = BG_GetEquippedWeaponIndex_t(0x4D8BA0); BG_GetEquippedWeaponIndex_t BG_GetEquippedWeaponIndex = BG_GetEquippedWeaponIndex_t(0x4D8BA0);
BG_GetEquippedWeaponState_t BG_GetEquippedWeaponState = BG_GetEquippedWeaponState_t(0x4E79E0); BG_GetEquippedWeaponState_t BG_GetEquippedWeaponState = BG_GetEquippedWeaponState_t(0x4E79E0);
BG_PlayerHasWeapon_t BG_PlayerHasWeapon = BG_PlayerHasWeapon_t(0x4AB530);
BG_GetWeaponCompleteDef_t BG_GetWeaponCompleteDef = BG_GetWeaponCompleteDef_t(0x44CE00);
} }

View File

@ -28,4 +28,10 @@ namespace Game
typedef PlayerEquippedWeaponState*(*BG_GetEquippedWeaponState_t)(playerState_s* ps, unsigned int weaponIndex); typedef PlayerEquippedWeaponState*(*BG_GetEquippedWeaponState_t)(playerState_s* ps, unsigned int weaponIndex);
extern BG_GetEquippedWeaponState_t BG_GetEquippedWeaponState; extern BG_GetEquippedWeaponState_t BG_GetEquippedWeaponState;
typedef int*(*BG_PlayerHasWeapon_t)(playerState_s* ps, unsigned int weaponIndex);
extern BG_PlayerHasWeapon_t BG_PlayerHasWeapon;
typedef Game::WeaponCompleteDef*(*BG_GetWeaponCompleteDef_t)(unsigned int weaponIndex);
extern BG_GetWeaponCompleteDef_t BG_GetWeaponCompleteDef;
} }

View File

@ -221,6 +221,8 @@ namespace Game
constexpr auto LOCAL_VAR_STACK_SIZE = 64; constexpr auto LOCAL_VAR_STACK_SIZE = 64;
constexpr auto SCRIPTDATA_DIR = "scriptdata";
extern void IncInParam(); extern void IncInParam();
extern void Scr_AddBool(int value); extern void Scr_AddBool(int value);

View File

@ -82,6 +82,31 @@ namespace Utils
Utils::Merge(&this->slots, obj.getSlots()); Utils::Merge(&this->slots, obj.getSlots());
} }
void disconnect(const Slot<T> slot)
{
std::lock_guard<std::recursive_mutex> _(this->mutex);
if (slot)
{
this->slots.erase(
std::remove_if(
this->slots.begin(),
this->slots.end(),
[&](std::function<T>& a)
{
if (a.target<T>() == slot.target<T>())
{
return true;
}
return false;
}
), this->slots.end()
);
}
}
void connect(const Slot<T> slot) void connect(const Slot<T> slot)
{ {
std::lock_guard<std::recursive_mutex> _(this->mutex); std::lock_guard<std::recursive_mutex> _(this->mutex);