mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-27 02:10:38 +00:00
refactor: streamline weapon dumping
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class AssetDumperWeapon final : public AbstractAssetDumper<WeaponCompleteDef>
|
||||
{
|
||||
static void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef);
|
||||
static InfoString CreateInfoString(XAssetInfo<WeaponCompleteDef>* asset);
|
||||
static void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<WeaponCompleteDef>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset) override;
|
||||
};
|
||||
} // namespace IW5
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "AssetDumperWeaponAttachment.h"
|
||||
|
||||
#include "Game/IW5/Weapon/JsonWeaponAttachmentWriter.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
bool AssetDumperWeaponAttachment::ShouldDump(XAssetInfo<WeaponAttachment>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperWeaponAttachment::DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponAttachment>* asset)
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile(std::format("attachment/{}.json", asset->m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
DumpWeaponAttachmentAsJson(*assetFile, asset->Asset(), context);
|
||||
}
|
||||
+20
-8
@@ -1,20 +1,22 @@
|
||||
#include "JsonWeaponAttachmentWriter.h"
|
||||
#include "AttachmentJsonDumperIW5.h"
|
||||
|
||||
#include "Game/IW5/CommonIW5.h"
|
||||
#include "Game/IW5/Weapon/JsonWeaponAttachment.h"
|
||||
#include "Weapon/AttachmentCommon.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
using namespace IW5;
|
||||
using namespace ::attachment;
|
||||
|
||||
namespace
|
||||
{
|
||||
class JsonDumper
|
||||
class JsonDumperImpl
|
||||
{
|
||||
public:
|
||||
JsonDumper(AssetDumpingContext& context, std::ostream& stream)
|
||||
JsonDumperImpl(AssetDumpingContext& context, std::ostream& stream)
|
||||
: m_stream(stream)
|
||||
{
|
||||
}
|
||||
@@ -392,11 +394,21 @@ namespace
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace IW5
|
||||
namespace IW5::attachment
|
||||
{
|
||||
void DumpWeaponAttachmentAsJson(std::ostream& stream, const WeaponAttachment* attachment, AssetDumpingContext& context)
|
||||
bool JsonDumper::ShouldDump(XAssetInfo<WeaponAttachment>* asset)
|
||||
{
|
||||
const JsonDumper dumper(context, stream);
|
||||
dumper.Dump(attachment);
|
||||
return true;
|
||||
}
|
||||
} // namespace IW5
|
||||
|
||||
void JsonDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponAttachment>* asset)
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile(GetJsonFileNameForAssetName(asset->m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
const JsonDumperImpl dumper(context, *assetFile);
|
||||
dumper.Dump(asset->Asset());
|
||||
}
|
||||
} // namespace IW5::attachment
|
||||
+3
-3
@@ -3,12 +3,12 @@
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
namespace IW5
|
||||
namespace IW5::attachment
|
||||
{
|
||||
class AssetDumperWeaponAttachment final : public AbstractAssetDumper<WeaponAttachment>
|
||||
class JsonDumper final : public AbstractAssetDumper<WeaponAttachment>
|
||||
{
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<WeaponAttachment>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponAttachment>* asset) override;
|
||||
};
|
||||
} // namespace IW5
|
||||
} // namespace IW5::attachment
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AssetDumpingContext.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
void DumpWeaponAttachmentAsJson(std::ostream& stream, const WeaponAttachment* attachment, AssetDumpingContext& context);
|
||||
} // namespace IW5
|
||||
+205
-197
@@ -1,10 +1,11 @@
|
||||
#include "AssetDumperWeapon.h"
|
||||
#include "WeaponDumperIW5.h"
|
||||
|
||||
#include "Game/IW5/CommonIW5.h"
|
||||
#include "Game/IW5/InfoString/InfoStringFromStructConverter.h"
|
||||
#include "Game/IW5/ObjConstantsIW5.h"
|
||||
#include "Game/IW5/Weapon/WeaponFields.h"
|
||||
#include "Weapon/AccuracyGraphWriter.h"
|
||||
#include "Weapon/WeaponCommon.h"
|
||||
|
||||
#include <bit>
|
||||
#include <cassert>
|
||||
@@ -14,8 +15,9 @@
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace IW5;
|
||||
using namespace ::weapon;
|
||||
|
||||
namespace IW5
|
||||
namespace
|
||||
{
|
||||
class InfoStringFromWeaponConverter final : public InfoStringFromStructConverter
|
||||
{
|
||||
@@ -551,211 +553,217 @@ namespace IW5
|
||||
|
||||
return graph;
|
||||
}
|
||||
} // namespace IW5
|
||||
|
||||
void AssetDumperWeapon::CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef)
|
||||
{
|
||||
fullDef->weapCompleteDef = *weapon;
|
||||
|
||||
if (weapon->weapDef)
|
||||
void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef)
|
||||
{
|
||||
fullDef->weapDef = *weapon->weapDef;
|
||||
fullDef->weapCompleteDef.weapDef = &fullDef->weapDef;
|
||||
fullDef->weapCompleteDef = *weapon;
|
||||
|
||||
if (weapon->weapDef)
|
||||
{
|
||||
fullDef->weapDef = *weapon->weapDef;
|
||||
fullDef->weapCompleteDef.weapDef = &fullDef->weapDef;
|
||||
}
|
||||
|
||||
if (weapon->hideTags)
|
||||
{
|
||||
memcpy(fullDef->hideTags, weapon->hideTags, sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::hideTags)>);
|
||||
fullDef->weapCompleteDef.hideTags = fullDef->hideTags;
|
||||
}
|
||||
|
||||
if (weapon->szXAnims)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::szXAnims)> == WEAP_ANIM_COUNT);
|
||||
memcpy(fullDef->szXAnims, weapon->szXAnims, sizeof(void*) * WEAP_ANIM_COUNT);
|
||||
fullDef->weapCompleteDef.szXAnims = fullDef->szXAnims;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.gunXModel)
|
||||
{
|
||||
memcpy(fullDef->gunXModel, fullDef->weapDef.gunXModel, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::gunXModel)>);
|
||||
fullDef->weapDef.gunXModel = fullDef->gunXModel;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.szXAnimsRightHanded)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::szXAnimsRightHanded)> == WEAP_ANIM_COUNT);
|
||||
memcpy(fullDef->szXAnimsRightHanded, fullDef->weapDef.szXAnimsRightHanded, sizeof(void*) * WEAP_ANIM_COUNT);
|
||||
fullDef->weapDef.szXAnimsRightHanded = fullDef->szXAnimsRightHanded;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.szXAnimsLeftHanded)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::szXAnimsLeftHanded)> == WEAP_ANIM_COUNT);
|
||||
memcpy(fullDef->szXAnimsLeftHanded, fullDef->weapDef.szXAnimsLeftHanded, sizeof(void*) * WEAP_ANIM_COUNT);
|
||||
fullDef->weapDef.szXAnimsLeftHanded = fullDef->szXAnimsLeftHanded;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.notetrackSoundMapKeys)
|
||||
{
|
||||
memcpy(fullDef->notetrackSoundMapKeys,
|
||||
fullDef->weapDef.notetrackSoundMapKeys,
|
||||
sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)>);
|
||||
fullDef->weapDef.notetrackSoundMapKeys = fullDef->notetrackSoundMapKeys;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.notetrackSoundMapValues)
|
||||
{
|
||||
memcpy(fullDef->notetrackSoundMapValues,
|
||||
fullDef->weapDef.notetrackSoundMapValues,
|
||||
sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::notetrackSoundMapValues)>);
|
||||
fullDef->weapDef.notetrackSoundMapValues = fullDef->notetrackSoundMapValues;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.notetrackRumbleMapKeys)
|
||||
{
|
||||
memcpy(fullDef->notetrackRumbleMapKeys,
|
||||
fullDef->weapDef.notetrackRumbleMapKeys,
|
||||
sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::notetrackRumbleMapKeys)>);
|
||||
fullDef->weapDef.notetrackRumbleMapKeys = fullDef->notetrackRumbleMapKeys;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.notetrackRumbleMapValues)
|
||||
{
|
||||
memcpy(fullDef->notetrackRumbleMapValues,
|
||||
fullDef->weapDef.notetrackRumbleMapValues,
|
||||
sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::notetrackRumbleMapValues)>);
|
||||
fullDef->weapDef.notetrackRumbleMapValues = fullDef->notetrackRumbleMapValues;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.worldModel)
|
||||
{
|
||||
memcpy(fullDef->worldModel, fullDef->weapDef.worldModel, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::worldModel)>);
|
||||
fullDef->weapDef.worldModel = fullDef->worldModel;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.parallelBounce)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::parallelBounce)> == SURF_TYPE_COUNT);
|
||||
assert(sizeof(WeaponFullDef::parallelBounce) >= sizeof(float) * std::extent_v<decltype(WeaponFullDef::parallelBounce)>);
|
||||
memcpy(fullDef->parallelBounce, fullDef->weapDef.parallelBounce, sizeof(float) * std::extent_v<decltype(WeaponFullDef::parallelBounce)>);
|
||||
fullDef->weapDef.parallelBounce = fullDef->parallelBounce;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.perpendicularBounce)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::perpendicularBounce)> == SURF_TYPE_COUNT);
|
||||
assert(sizeof(WeaponFullDef::perpendicularBounce) >= sizeof(float) * std::extent_v<decltype(WeaponFullDef::perpendicularBounce)>);
|
||||
memcpy(fullDef->perpendicularBounce,
|
||||
fullDef->weapDef.perpendicularBounce,
|
||||
sizeof(float) * std::extent_v<decltype(WeaponFullDef::perpendicularBounce)>);
|
||||
fullDef->weapDef.perpendicularBounce = fullDef->perpendicularBounce;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.locationDamageMultipliers)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::locationDamageMultipliers)> == HITLOC_COUNT);
|
||||
assert(sizeof(WeaponFullDef::locationDamageMultipliers) >= sizeof(float) * std::extent_v<decltype(WeaponFullDef::locationDamageMultipliers)>);
|
||||
memcpy(fullDef->locationDamageMultipliers,
|
||||
fullDef->weapDef.locationDamageMultipliers,
|
||||
sizeof(float) * std::extent_v<decltype(WeaponFullDef::locationDamageMultipliers)>);
|
||||
fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers;
|
||||
}
|
||||
|
||||
if (fullDef->weapCompleteDef.scopes)
|
||||
{
|
||||
memcpy(fullDef->scopes, fullDef->weapCompleteDef.scopes, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::scopes)>);
|
||||
fullDef->weapCompleteDef.scopes = fullDef->scopes;
|
||||
}
|
||||
|
||||
if (fullDef->weapCompleteDef.underBarrels)
|
||||
{
|
||||
memcpy(fullDef->underBarrels, fullDef->weapCompleteDef.underBarrels, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::underBarrels)>);
|
||||
fullDef->weapCompleteDef.underBarrels = fullDef->underBarrels;
|
||||
}
|
||||
|
||||
if (fullDef->weapCompleteDef.others)
|
||||
{
|
||||
memcpy(fullDef->others, fullDef->weapCompleteDef.others, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::others)>);
|
||||
fullDef->weapCompleteDef.others = fullDef->others;
|
||||
}
|
||||
}
|
||||
|
||||
if (weapon->hideTags)
|
||||
InfoString CreateInfoString(XAssetInfo<WeaponCompleteDef>* asset)
|
||||
{
|
||||
memcpy(fullDef->hideTags, weapon->hideTags, sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::hideTags)>);
|
||||
fullDef->weapCompleteDef.hideTags = fullDef->hideTags;
|
||||
const auto fullDef = std::make_unique<WeaponFullDef>();
|
||||
memset(fullDef.get(), 0, sizeof(WeaponFullDef));
|
||||
CopyToFullDef(asset->Asset(), fullDef.get());
|
||||
|
||||
InfoStringFromWeaponConverter converter(fullDef.get(),
|
||||
weapon_fields,
|
||||
std::extent_v<decltype(weapon_fields)>,
|
||||
[asset](const scr_string_t scrStr) -> std::string
|
||||
{
|
||||
assert(scrStr < asset->m_zone->m_script_strings.Count());
|
||||
if (scrStr >= asset->m_zone->m_script_strings.Count())
|
||||
return "";
|
||||
|
||||
return asset->m_zone->m_script_strings[scrStr];
|
||||
});
|
||||
|
||||
return converter.Convert();
|
||||
}
|
||||
|
||||
if (weapon->szXAnims)
|
||||
void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::szXAnims)> == WEAP_ANIM_COUNT);
|
||||
memcpy(fullDef->szXAnims, weapon->szXAnims, sizeof(void*) * WEAP_ANIM_COUNT);
|
||||
fullDef->weapCompleteDef.szXAnims = fullDef->szXAnims;
|
||||
}
|
||||
auto* accuracyGraphWriter = context.GetZoneAssetDumperState<AccuracyGraphWriter>();
|
||||
const auto weapon = asset->Asset();
|
||||
const auto* weapDef = weapon->weapDef;
|
||||
|
||||
if (fullDef->weapDef.gunXModel)
|
||||
{
|
||||
memcpy(fullDef->gunXModel, fullDef->weapDef.gunXModel, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::gunXModel)>);
|
||||
fullDef->weapDef.gunXModel = fullDef->gunXModel;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.szXAnimsRightHanded)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::szXAnimsRightHanded)> == WEAP_ANIM_COUNT);
|
||||
memcpy(fullDef->szXAnimsRightHanded, fullDef->weapDef.szXAnimsRightHanded, sizeof(void*) * WEAP_ANIM_COUNT);
|
||||
fullDef->weapDef.szXAnimsRightHanded = fullDef->szXAnimsRightHanded;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.szXAnimsLeftHanded)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::szXAnimsLeftHanded)> == WEAP_ANIM_COUNT);
|
||||
memcpy(fullDef->szXAnimsLeftHanded, fullDef->weapDef.szXAnimsLeftHanded, sizeof(void*) * WEAP_ANIM_COUNT);
|
||||
fullDef->weapDef.szXAnimsLeftHanded = fullDef->szXAnimsLeftHanded;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.notetrackSoundMapKeys)
|
||||
{
|
||||
memcpy(fullDef->notetrackSoundMapKeys,
|
||||
fullDef->weapDef.notetrackSoundMapKeys,
|
||||
sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)>);
|
||||
fullDef->weapDef.notetrackSoundMapKeys = fullDef->notetrackSoundMapKeys;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.notetrackSoundMapValues)
|
||||
{
|
||||
memcpy(fullDef->notetrackSoundMapValues,
|
||||
fullDef->weapDef.notetrackSoundMapValues,
|
||||
sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::notetrackSoundMapValues)>);
|
||||
fullDef->weapDef.notetrackSoundMapValues = fullDef->notetrackSoundMapValues;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.notetrackRumbleMapKeys)
|
||||
{
|
||||
memcpy(fullDef->notetrackRumbleMapKeys,
|
||||
fullDef->weapDef.notetrackRumbleMapKeys,
|
||||
sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::notetrackRumbleMapKeys)>);
|
||||
fullDef->weapDef.notetrackRumbleMapKeys = fullDef->notetrackRumbleMapKeys;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.notetrackRumbleMapValues)
|
||||
{
|
||||
memcpy(fullDef->notetrackRumbleMapValues,
|
||||
fullDef->weapDef.notetrackRumbleMapValues,
|
||||
sizeof(scr_string_t) * std::extent_v<decltype(WeaponFullDef::notetrackRumbleMapValues)>);
|
||||
fullDef->weapDef.notetrackRumbleMapValues = fullDef->notetrackRumbleMapValues;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.worldModel)
|
||||
{
|
||||
memcpy(fullDef->worldModel, fullDef->weapDef.worldModel, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::worldModel)>);
|
||||
fullDef->weapDef.worldModel = fullDef->worldModel;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.parallelBounce)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::parallelBounce)> == SURF_TYPE_COUNT);
|
||||
assert(sizeof(WeaponFullDef::parallelBounce) >= sizeof(float) * std::extent_v<decltype(WeaponFullDef::parallelBounce)>);
|
||||
memcpy(fullDef->parallelBounce, fullDef->weapDef.parallelBounce, sizeof(float) * std::extent_v<decltype(WeaponFullDef::parallelBounce)>);
|
||||
fullDef->weapDef.parallelBounce = fullDef->parallelBounce;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.perpendicularBounce)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::perpendicularBounce)> == SURF_TYPE_COUNT);
|
||||
assert(sizeof(WeaponFullDef::perpendicularBounce) >= sizeof(float) * std::extent_v<decltype(WeaponFullDef::perpendicularBounce)>);
|
||||
memcpy(fullDef->perpendicularBounce, fullDef->weapDef.perpendicularBounce, sizeof(float) * std::extent_v<decltype(WeaponFullDef::perpendicularBounce)>);
|
||||
fullDef->weapDef.perpendicularBounce = fullDef->perpendicularBounce;
|
||||
}
|
||||
|
||||
if (fullDef->weapDef.locationDamageMultipliers)
|
||||
{
|
||||
static_assert(std::extent_v<decltype(WeaponFullDef::locationDamageMultipliers)> == HITLOC_COUNT);
|
||||
assert(sizeof(WeaponFullDef::locationDamageMultipliers) >= sizeof(float) * std::extent_v<decltype(WeaponFullDef::locationDamageMultipliers)>);
|
||||
memcpy(fullDef->locationDamageMultipliers,
|
||||
fullDef->weapDef.locationDamageMultipliers,
|
||||
sizeof(float) * std::extent_v<decltype(WeaponFullDef::locationDamageMultipliers)>);
|
||||
fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers;
|
||||
}
|
||||
|
||||
if (fullDef->weapCompleteDef.scopes)
|
||||
{
|
||||
memcpy(fullDef->scopes, fullDef->weapCompleteDef.scopes, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::scopes)>);
|
||||
fullDef->weapCompleteDef.scopes = fullDef->scopes;
|
||||
}
|
||||
|
||||
if (fullDef->weapCompleteDef.underBarrels)
|
||||
{
|
||||
memcpy(fullDef->underBarrels, fullDef->weapCompleteDef.underBarrels, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::underBarrels)>);
|
||||
fullDef->weapCompleteDef.underBarrels = fullDef->underBarrels;
|
||||
}
|
||||
|
||||
if (fullDef->weapCompleteDef.others)
|
||||
{
|
||||
memcpy(fullDef->others, fullDef->weapCompleteDef.others, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::others)>);
|
||||
fullDef->weapCompleteDef.others = fullDef->others;
|
||||
}
|
||||
}
|
||||
|
||||
InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo<WeaponCompleteDef>* asset)
|
||||
{
|
||||
const auto fullDef = std::make_unique<WeaponFullDef>();
|
||||
memset(fullDef.get(), 0, sizeof(WeaponFullDef));
|
||||
CopyToFullDef(asset->Asset(), fullDef.get());
|
||||
|
||||
InfoStringFromWeaponConverter converter(fullDef.get(),
|
||||
weapon_fields,
|
||||
std::extent_v<decltype(weapon_fields)>,
|
||||
[asset](const scr_string_t scrStr) -> std::string
|
||||
{
|
||||
assert(scrStr < asset->m_zone->m_script_strings.Count());
|
||||
if (scrStr >= asset->m_zone->m_script_strings.Count())
|
||||
return "";
|
||||
|
||||
return asset->m_zone->m_script_strings[scrStr];
|
||||
});
|
||||
|
||||
return converter.Convert();
|
||||
}
|
||||
|
||||
void AssetDumperWeapon::DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset)
|
||||
{
|
||||
auto* accuracyGraphWriter = context.GetZoneAssetDumperState<AccuracyGraphWriter>();
|
||||
const auto weapon = asset->Asset();
|
||||
const auto* weapDef = weapon->weapDef;
|
||||
|
||||
if (!weapDef)
|
||||
return;
|
||||
|
||||
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots
|
||||
&& accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName))
|
||||
{
|
||||
AccuracyGraphWriter::DumpAiVsAiGraph(
|
||||
context,
|
||||
ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount));
|
||||
}
|
||||
|
||||
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots
|
||||
&& accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName))
|
||||
{
|
||||
AccuracyGraphWriter::DumpAiVsPlayerGraph(context,
|
||||
ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName,
|
||||
weapDef->originalAiVsPlayerAccuracyGraphKnots,
|
||||
weapDef->originalAiVsPlayerAccuracyGraphKnotCount));
|
||||
}
|
||||
}
|
||||
|
||||
bool AssetDumperWeapon::ShouldDump(XAssetInfo<WeaponCompleteDef>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperWeapon::DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset)
|
||||
{
|
||||
// TODO: only dump infostring fields when non-default
|
||||
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
{
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_WEAPON);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON, gdtEntry);
|
||||
context.m_gdt->WriteEntry(gdtEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile("weapons/" + asset->m_name);
|
||||
|
||||
if (!assetFile)
|
||||
if (!weapDef)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots
|
||||
&& accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName))
|
||||
{
|
||||
AccuracyGraphWriter::DumpAiVsAiGraph(context,
|
||||
ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName,
|
||||
weapDef->originalAiVsAiAccuracyGraphKnots,
|
||||
weapDef->originalAiVsAiAccuracyGraphKnotCount));
|
||||
}
|
||||
|
||||
if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots
|
||||
&& accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName))
|
||||
{
|
||||
AccuracyGraphWriter::DumpAiVsPlayerGraph(context,
|
||||
ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName,
|
||||
weapDef->originalAiVsPlayerAccuracyGraphKnots,
|
||||
weapDef->originalAiVsPlayerAccuracyGraphKnotCount));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace IW5::weapon
|
||||
{
|
||||
bool Dumper::ShouldDump(XAssetInfo<WeaponCompleteDef>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
DumpAccuracyGraphs(context, asset);
|
||||
}
|
||||
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset)
|
||||
{
|
||||
// TODO: only dump infostring fields when non-default
|
||||
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
{
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_WEAPON);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON, gdtEntry);
|
||||
context.m_gdt->WriteEntry(gdtEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile(GetFileNameForAssetName(asset->m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
}
|
||||
|
||||
DumpAccuracyGraphs(context, asset);
|
||||
}
|
||||
} // namespace IW5::weapon
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace IW5::weapon
|
||||
{
|
||||
class Dumper final : public AbstractAssetDumper<WeaponCompleteDef>
|
||||
{
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<WeaponCompleteDef>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponCompleteDef>* asset) override;
|
||||
};
|
||||
} // namespace IW5::weapon
|
||||
Reference in New Issue
Block a user