Allow OnLoad unsubscription, weapon implementation fixes, formattting

This commit is contained in:
Roxanne 2023-11-17 14:06:21 +01:00
parent cc895c766e
commit cdb8a9b9c4
8 changed files with 569 additions and 446 deletions

@ -1 +1 @@
Subproject commit 6af596a010eebf727e5d914bf9a01903c14ae128
Subproject commit fa074d9ba5f61c200db05878bb9fba5ee37a8994

View File

@ -349,9 +349,13 @@ namespace Components
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);
return [callback](){
AssetHandler::RestrictSignal.disconnect(callback);
};
}
void AssetHandler::ClearRelocations()

View File

@ -23,7 +23,7 @@ namespace Components
~AssetHandler();
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 Relocate(void* start, void* to, DWORD size = 4);

View File

@ -3,8 +3,16 @@
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
if (Components::FileSystem::File(std::format("weapons/mp/{}", name)))
{
@ -193,6 +201,33 @@ namespace Assets
LoadWeapSound(missileConeSoundAlias);
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->dpadIcon) // 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)

View File

@ -6,6 +6,7 @@
namespace Components
{
const Game::dvar_t* Weapon::BGWeaponOffHandFix;
Game::XModel* Weapon::G_ModelIndexReallocated[G_MODELINDEX_LIMIT];
Game::WeaponCompleteDef* Weapon::LoadWeaponCompleteDef(const char* name)
{
@ -433,6 +434,20 @@ namespace Components
Utils::Hook::Set<DWORD>(0x4F76FB, 0x12EC + (sizeof(bg_sharedAmmoCaps) - (1200 * 4)));
// Move arg4 pointers
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);
}
void* Weapon::LoadNoneWeaponHook()
@ -636,6 +651,10 @@ namespace Components
Utils::Hook::Nop(0x408230, 5); // is asset default
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
Utils::Hook::Set<BYTE>(0x4081FD, 0xEB);

View File

@ -4,6 +4,9 @@
// Was 1200 before
#define WEAPON_LIMIT 2400
#define MAX_CONFIGSTRINGS (4139 - 1200 + WEAPON_LIMIT)
#define G_MODELINDEX_LIMIT (526 + WEAPON_LIMIT - 1200)
#define G_MODELINDEX_HAS_BEEN_REALLOCATED
namespace Components
{
@ -11,6 +14,7 @@ namespace Components
{
public:
Weapon();
static Game::XModel* G_ModelIndexReallocated[G_MODELINDEX_LIMIT];
private:
static const Game::dvar_t* BGWeaponOffHandFix;

File diff suppressed because it is too large Load Diff

View File

@ -82,6 +82,31 @@ namespace Utils
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)
{
std::lock_guard<std::recursive_mutex> _(this->mutex);