2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-30 16:27:47 +00:00

feat: load iw5 weapon attachments from raw

This commit is contained in:
Jan
2024-04-14 17:47:06 +02:00
parent 28949f4ee8
commit d3c0325fea
5 changed files with 722 additions and 1 deletions

View File

@@ -0,0 +1,47 @@
#include "AssetLoaderWeaponAttachment.h"
#include "Game/IW5/IW5.h"
#include "Game/IW5/Weapon/JsonWeaponAttachmentLoader.h"
#include "Pool/GlobalAssetPool.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace IW5;
void* AssetLoaderWeaponAttachment::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
{
auto* attachment = memory->Create<WeaponAttachment>();
memset(attachment, 0, sizeof(WeaponAttachment));
attachment->szInternalName = memory->Dup(assetName.c_str());
return attachment;
}
bool AssetLoaderWeaponAttachment::CanLoadFromRaw() const
{
return true;
}
bool AssetLoaderWeaponAttachment::LoadFromRaw(
const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
{
const auto file = searchPath->Open(std::format("attachment/{}.json", assetName));
if (!file.IsOpen())
return false;
auto* attachment = static_cast<WeaponAttachment*>(memory->Alloc(sizeof(WeaponAttachment)));
memset(attachment, 0, sizeof(Material));
attachment->szInternalName = memory->Dup(assetName.c_str());
std::vector<XAssetInfoGeneric*> dependencies;
std::vector<IndirectAssetReference> indirectAssetReferences;
if (LoadWeaponAttachmentAsJson(*file.m_stream, *attachment, memory, manager, dependencies, indirectAssetReferences))
manager->AddAsset(
ASSET_TYPE_ATTACHMENT, assetName, attachment, std::move(dependencies), std::vector<scr_string_t>(), std::move(indirectAssetReferences));
else
std::cerr << "Failed to load attachment \"" << assetName << "\"\n";
return true;
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "AssetLoading/BasicAssetLoader.h"
#include "AssetLoading/IAssetLoadingManager.h"
#include "Game/IW5/IW5.h"
#include "SearchPath/ISearchPath.h"
namespace IW5
{
class AssetLoaderWeaponAttachment final : public BasicAssetLoader<ASSET_TYPE_ATTACHMENT, WeaponAttachment>
{
public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
_NODISCARD bool CanLoadFromRaw() const override;
bool
LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
};
} // namespace IW5