Allow OnLoad unsubscription, weapon implementation fixes, formattting
This commit is contained in:
parent
cc895c766e
commit
cdb8a9b9c4
2
deps/iw4-open-formats
vendored
2
deps/iw4-open-formats
vendored
@ -1 +1 @@
|
||||
Subproject commit 6af596a010eebf727e5d914bf9a01903c14ae128
|
||||
Subproject commit fa074d9ba5f61c200db05878bb9fba5ee37a8994
|
@ -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()
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -787,6 +787,14 @@ namespace Components
|
||||
return AssetHandler::FindAssetForZone(static_cast<Game::XAssetType>(type), name, this).data;
|
||||
};
|
||||
|
||||
params.request_mark_asset = [this](int type, void* data) -> void
|
||||
{
|
||||
Game::XAsset asset {static_cast<Game::XAssetType>(type), {data}};
|
||||
|
||||
AssetHandler::ZoneMark(asset, this);
|
||||
this->addRawAsset(static_cast<Game::XAssetType>(type), data);
|
||||
};
|
||||
|
||||
params.fs_read_file = [](const std::string& filename) -> std::string
|
||||
{
|
||||
auto file = FileSystem::File(filename);
|
||||
@ -1106,13 +1114,8 @@ namespace Components
|
||||
|
||||
params.find_other_asset = [](int type, const std::string& name) -> void*
|
||||
{
|
||||
if (ZoneBuilder::DumpingZone.empty())
|
||||
{
|
||||
return Game::DB_FindXAssetHeader(static_cast<Game::XAssetType>(type), name.data()).data;
|
||||
}
|
||||
|
||||
// Do not deadlock the DB
|
||||
return nullptr;
|
||||
return Game::DB_FindXAssetHeader(static_cast<Game::XAssetType>(type), name.data()).data;
|
||||
};
|
||||
|
||||
params.fs_read_file = [](const std::string& filename) -> std::string
|
||||
@ -1255,7 +1258,7 @@ namespace Components
|
||||
// don't remap techsets
|
||||
Utils::Hook::Nop(0x5BC791, 5);
|
||||
|
||||
AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* /*restrict*/)
|
||||
AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader /* asset*/, const std::string& name, bool* /*restrict*/)
|
||||
{
|
||||
if (!ZoneBuilder::TraceZone.empty() && ZoneBuilder::TraceZone == FastFiles::Current())
|
||||
{
|
||||
@ -1264,15 +1267,6 @@ namespace Components
|
||||
OutputDebugStringA(Utils::String::Format("%s\n", name));
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!ZoneBuilder::DumpingZone.empty())
|
||||
{
|
||||
if (ExporterAPI.is_type_supported(type) && name[0] != ',')
|
||||
{
|
||||
ExporterAPI.write(type, asset.data);
|
||||
Components::Logger::Print(".");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Command::Add("dumpzone", [](const Command::Params* params)
|
||||
@ -1288,11 +1282,53 @@ namespace Components
|
||||
info.allocFlags = Game::DB_ZONE_MOD;
|
||||
info.freeFlags = 0;
|
||||
|
||||
Logger::Print("Dumping zone '{}'...\n", zone);
|
||||
Logger::Print("Loading zone '{}'...\n", zone);
|
||||
|
||||
{
|
||||
struct asset_t
|
||||
{
|
||||
Game::XAssetType type;
|
||||
char name[128];
|
||||
};
|
||||
|
||||
std::vector<asset_t> assets{};
|
||||
const auto handle = AssetHandler::OnLoad([&](Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* /*restrict*/)
|
||||
{
|
||||
if (ExporterAPI.is_type_supported(type) && name[0] != ',')
|
||||
{
|
||||
Game::XAsset xasset = { type, asset };
|
||||
asset_t assetIdentifier{};
|
||||
|
||||
// Fetch name
|
||||
const auto assetName = Game::DB_GetXAssetName(&xasset);
|
||||
std::memcpy(assetIdentifier.name, assetName, strnlen(assetName, ARRAYSIZE(assetIdentifier.name) - 1));
|
||||
assetIdentifier.name[ARRAYSIZE(assetIdentifier.name) - 1] = '\x00';
|
||||
|
||||
assetIdentifier.type = type;
|
||||
|
||||
assets.push_back(assetIdentifier);
|
||||
}
|
||||
});
|
||||
|
||||
Game::DB_LoadXAssets(&info, 1, true);
|
||||
AssetHandler::FindOriginalAsset(Game::ASSET_TYPE_RAWFILE, zone.data()); // Lock until zone is loaded
|
||||
|
||||
Logger::Print("Dumping zone '{}'...\n", zone);
|
||||
handle(); // Release
|
||||
for (const auto& asset : assets)
|
||||
{
|
||||
const auto assetHeader = Game::DB_FindXAssetHeader(asset.type, asset.name);
|
||||
if (assetHeader.data)
|
||||
{
|
||||
ExporterAPI.write(asset.type, assetHeader.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Warning(Game::conChannel_t::CON_CHANNEL_ERROR, "Asset {} has disappeared while dumping!", asset.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger::Print("Unloading zone '{}'...\n", zone);
|
||||
info.freeFlags = Game::DB_ZONE_MOD;
|
||||
info.allocFlags = 0;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user