mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Merge pull request #142 from Laupetin/feature/t6-weapon-camo
feat: dump t6 WeaponCamo asset as json
This commit is contained in:
commit
fc9f265f0c
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Game/T6/T6.h"
|
#include "Game/T6/T6.h"
|
||||||
#include "Utils/JsonOptional.h"
|
|
||||||
|
|
||||||
|
#include "Json/JsonOptional.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
55
src/ObjCommon/Game/T6/Json/JsonWeaponCamo.h
Normal file
55
src/ObjCommon/Game/T6/Json/JsonWeaponCamo.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
|
||||||
|
#include "Json/JsonCommon.h"
|
||||||
|
#include "Json/JsonOptional.h"
|
||||||
|
#include <memory>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
|
class JsonWeaponCamoSet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::optional<std::string> solidCamoImage;
|
||||||
|
std::optional<std::string> patternCamoImage;
|
||||||
|
JsonVec2 patternOffset;
|
||||||
|
float patternScale;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(JsonWeaponCamoSet, solidCamoImage, patternCamoImage, patternOffset, patternScale);
|
||||||
|
|
||||||
|
class JsonWeaponCamoMaterial
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
unsigned replaceFlags;
|
||||||
|
std::vector<std::string> baseMaterials;
|
||||||
|
std::vector<std::string> camoMaterials;
|
||||||
|
std::array<float, 8> shaderConsts;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(JsonWeaponCamoMaterial, replaceFlags, baseMaterials, camoMaterials, shaderConsts);
|
||||||
|
|
||||||
|
class JsonWeaponCamoMaterialSet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::vector<JsonWeaponCamoMaterial> materials;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(JsonWeaponCamoMaterialSet, materials);
|
||||||
|
|
||||||
|
class JsonWeaponCamo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::optional<std::string> solidBaseImage;
|
||||||
|
std::optional<std::string> patternBaseImage;
|
||||||
|
std::vector<JsonWeaponCamoSet> camoSets;
|
||||||
|
std::vector<JsonWeaponCamoMaterialSet> camoMaterials;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(JsonWeaponCamo, solidBaseImage, patternBaseImage, camoSets, camoMaterials);
|
||||||
|
} // namespace T6
|
33
src/ObjCommon/Json/JsonCommon.h
Normal file
33
src/ObjCommon/Json/JsonCommon.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
class JsonVec2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(JsonVec2, x, y);
|
||||||
|
|
||||||
|
class JsonVec3
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(JsonVec3, x, y, z);
|
||||||
|
|
||||||
|
class JsonVec4
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
float w;
|
||||||
|
};
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(JsonVec4, x, y, z, w);
|
@ -1,7 +1,7 @@
|
|||||||
#include "JsonMaterialLoader.h"
|
#include "JsonMaterialLoader.h"
|
||||||
|
|
||||||
#include "Game/T6/CommonT6.h"
|
#include "Game/T6/CommonT6.h"
|
||||||
#include "Game/T6/Material/JsonMaterial.h"
|
#include "Game/T6/Json/JsonMaterial.h"
|
||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
#include "AssetDumperWeaponCamo.h"
|
||||||
|
|
||||||
|
#include "Game/T6/WeaponCamo/JsonWeaponCamoWriter.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
using namespace T6;
|
||||||
|
|
||||||
|
bool AssetDumperWeaponCamo::ShouldDump(XAssetInfo<WeaponCamo>* asset)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetDumperWeaponCamo::DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponCamo>* asset)
|
||||||
|
{
|
||||||
|
const auto fileName = std::format("camo/{}.json", asset->m_name);
|
||||||
|
const auto assetFile = context.OpenAssetFile(fileName);
|
||||||
|
|
||||||
|
if (!assetFile)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DumpWeaponCamoAsJson(*assetFile, asset->Asset());
|
||||||
|
}
|
14
src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponCamo.h
Normal file
14
src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponCamo.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Dumping/AbstractAssetDumper.h"
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
|
class AssetDumperWeaponCamo final : public AbstractAssetDumper<WeaponCamo>
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
bool ShouldDump(XAssetInfo<WeaponCamo>* asset) override;
|
||||||
|
void DumpAsset(AssetDumpingContext& context, XAssetInfo<WeaponCamo>* asset) override;
|
||||||
|
};
|
||||||
|
} // namespace T6
|
@ -1,15 +1,16 @@
|
|||||||
#include "JsonMaterialWriter.h"
|
#include "JsonMaterialWriter.h"
|
||||||
|
|
||||||
#include "Game/T6/CommonT6.h"
|
#include "Game/T6/CommonT6.h"
|
||||||
#include "Game/T6/Material/JsonMaterial.h"
|
#include "Game/T6/Json/JsonMaterial.h"
|
||||||
#include "MaterialConstantZoneState.h"
|
#include "MaterialConstantZoneState.h"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
using namespace T6;
|
||||||
|
|
||||||
namespace T6
|
namespace
|
||||||
{
|
{
|
||||||
class JsonDumper
|
class JsonDumper
|
||||||
{
|
{
|
||||||
@ -236,7 +237,10 @@ namespace T6
|
|||||||
std::ostream& m_stream;
|
std::ostream& m_stream;
|
||||||
const MaterialConstantZoneState& m_material_constants;
|
const MaterialConstantZoneState& m_material_constants;
|
||||||
};
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
void DumpMaterialAsJson(std::ostream& stream, const Material* material, AssetDumpingContext& context)
|
void DumpMaterialAsJson(std::ostream& stream, const Material* material, AssetDumpingContext& context)
|
||||||
{
|
{
|
||||||
const JsonDumper dumper(context, stream);
|
const JsonDumper dumper(context, stream);
|
||||||
|
113
src/ObjWriting/Game/T6/WeaponCamo/JsonWeaponCamoWriter.cpp
Normal file
113
src/ObjWriting/Game/T6/WeaponCamo/JsonWeaponCamoWriter.cpp
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
#include "JsonWeaponCamoWriter.h"
|
||||||
|
|
||||||
|
#include "Game/T6/CommonT6.h"
|
||||||
|
#include "Game/T6/Json/JsonWeaponCamo.h"
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
using namespace nlohmann;
|
||||||
|
using namespace T6;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class JsonDumper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit JsonDumper(std::ostream& stream)
|
||||||
|
: m_stream(stream)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dump(const WeaponCamo* weaponCamo) const
|
||||||
|
{
|
||||||
|
JsonWeaponCamo jsonWeaponCamo;
|
||||||
|
CreateJsonWeaponCamo(jsonWeaponCamo, *weaponCamo);
|
||||||
|
json jRoot = jsonWeaponCamo;
|
||||||
|
|
||||||
|
jRoot["_type"] = "weaponCamo";
|
||||||
|
jRoot["_version"] = 1;
|
||||||
|
|
||||||
|
m_stream << std::setw(4) << jRoot << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const char* AssetName(const char* input)
|
||||||
|
{
|
||||||
|
if (input && input[0] == ',')
|
||||||
|
return &input[1];
|
||||||
|
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CreateJsonWeaponCamoSet(JsonWeaponCamoSet& jWeaponCamoSet, const WeaponCamoSet& weaponCamoSet)
|
||||||
|
{
|
||||||
|
if (weaponCamoSet.solidCamoImage && weaponCamoSet.solidCamoImage->name)
|
||||||
|
jWeaponCamoSet.solidCamoImage = AssetName(weaponCamoSet.solidCamoImage->name);
|
||||||
|
|
||||||
|
if (weaponCamoSet.patternCamoImage && weaponCamoSet.patternCamoImage->name)
|
||||||
|
jWeaponCamoSet.patternCamoImage = AssetName(weaponCamoSet.patternCamoImage->name);
|
||||||
|
|
||||||
|
jWeaponCamoSet.patternOffset.x = weaponCamoSet.patternOffset.x;
|
||||||
|
jWeaponCamoSet.patternOffset.y = weaponCamoSet.patternOffset.y;
|
||||||
|
jWeaponCamoSet.patternScale = weaponCamoSet.patternScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CreateJsonWeaponCamoMaterial(JsonWeaponCamoMaterial& jWeaponCamoMaterial, const WeaponCamoMaterial& weaponCamoMaterial)
|
||||||
|
{
|
||||||
|
jWeaponCamoMaterial.replaceFlags = weaponCamoMaterial.replaceFlags;
|
||||||
|
|
||||||
|
jWeaponCamoMaterial.baseMaterials.resize(weaponCamoMaterial.numBaseMaterials);
|
||||||
|
for (auto i = 0u; i < weaponCamoMaterial.numBaseMaterials; i++)
|
||||||
|
{
|
||||||
|
if (weaponCamoMaterial.baseMaterials[i] && weaponCamoMaterial.baseMaterials[i]->info.name)
|
||||||
|
jWeaponCamoMaterial.baseMaterials[i] = AssetName(weaponCamoMaterial.baseMaterials[i]->info.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
jWeaponCamoMaterial.camoMaterials.resize(weaponCamoMaterial.numBaseMaterials);
|
||||||
|
for (auto i = 0u; i < weaponCamoMaterial.numBaseMaterials; i++)
|
||||||
|
{
|
||||||
|
if (weaponCamoMaterial.camoMaterials[i] && weaponCamoMaterial.camoMaterials[i]->info.name)
|
||||||
|
jWeaponCamoMaterial.camoMaterials[i] = AssetName(weaponCamoMaterial.camoMaterials[i]->info.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto i = 0u; i < std::extent_v<decltype(WeaponCamoMaterial::shaderConsts)>; i++)
|
||||||
|
jWeaponCamoMaterial.shaderConsts[i] = weaponCamoMaterial.shaderConsts[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CreateJsonWeaponCamoMaterialSet(JsonWeaponCamoMaterialSet& jWeaponCamoMaterialSet, const WeaponCamoMaterialSet& weaponCamoMaterialSet)
|
||||||
|
{
|
||||||
|
jWeaponCamoMaterialSet.materials.resize(weaponCamoMaterialSet.numMaterials);
|
||||||
|
for (auto i = 0u; i < weaponCamoMaterialSet.numMaterials; i++)
|
||||||
|
CreateJsonWeaponCamoMaterial(jWeaponCamoMaterialSet.materials[i], weaponCamoMaterialSet.materials[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CreateJsonWeaponCamo(JsonWeaponCamo& jWeaponCamo, const WeaponCamo& weaponCamo)
|
||||||
|
{
|
||||||
|
if (weaponCamo.solidBaseImage && weaponCamo.solidBaseImage->name)
|
||||||
|
jWeaponCamo.solidBaseImage = AssetName(weaponCamo.solidBaseImage->name);
|
||||||
|
|
||||||
|
if (weaponCamo.patternBaseImage && weaponCamo.patternBaseImage->name)
|
||||||
|
jWeaponCamo.patternBaseImage = AssetName(weaponCamo.patternBaseImage->name);
|
||||||
|
|
||||||
|
jWeaponCamo.camoSets.resize(weaponCamo.numCamoSets);
|
||||||
|
for (auto i = 0u; i < weaponCamo.numCamoSets; i++)
|
||||||
|
CreateJsonWeaponCamoSet(jWeaponCamo.camoSets[i], weaponCamo.camoSets[i]);
|
||||||
|
|
||||||
|
jWeaponCamo.camoMaterials.resize(weaponCamo.numCamoMaterials);
|
||||||
|
for (auto i = 0u; i < weaponCamo.numCamoMaterials; i++)
|
||||||
|
CreateJsonWeaponCamoMaterialSet(jWeaponCamo.camoMaterials[i], weaponCamo.camoMaterials[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& m_stream;
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
|
void DumpWeaponCamoAsJson(std::ostream& stream, const WeaponCamo* weaponCamo)
|
||||||
|
{
|
||||||
|
const JsonDumper dumper(stream);
|
||||||
|
dumper.Dump(weaponCamo);
|
||||||
|
}
|
||||||
|
} // namespace T6
|
11
src/ObjWriting/Game/T6/WeaponCamo/JsonWeaponCamoWriter.h
Normal file
11
src/ObjWriting/Game/T6/WeaponCamo/JsonWeaponCamoWriter.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Dumping/AssetDumpingContext.h"
|
||||||
|
#include "Game/T6/T6.h"
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
namespace T6
|
||||||
|
{
|
||||||
|
void DumpWeaponCamoAsJson(std::ostream& stream, const WeaponCamo* weaponCamo);
|
||||||
|
} // namespace T6
|
@ -19,6 +19,7 @@
|
|||||||
#include "AssetDumpers/AssetDumperWeapon.h"
|
#include "AssetDumpers/AssetDumperWeapon.h"
|
||||||
#include "AssetDumpers/AssetDumperWeaponAttachment.h"
|
#include "AssetDumpers/AssetDumperWeaponAttachment.h"
|
||||||
#include "AssetDumpers/AssetDumperWeaponAttachmentUnique.h"
|
#include "AssetDumpers/AssetDumperWeaponAttachmentUnique.h"
|
||||||
|
#include "AssetDumpers/AssetDumperWeaponCamo.h"
|
||||||
#include "AssetDumpers/AssetDumperXModel.h"
|
#include "AssetDumpers/AssetDumperXModel.h"
|
||||||
#include "AssetDumpers/AssetDumperZBarrier.h"
|
#include "AssetDumpers/AssetDumperZBarrier.h"
|
||||||
#include "Game/T6/GameAssetPoolT6.h"
|
#include "Game/T6/GameAssetPoolT6.h"
|
||||||
@ -68,7 +69,7 @@ bool ZoneDumper::DumpZone(AssetDumpingContext& context) const
|
|||||||
DUMP_ASSET_POOL(AssetDumperWeapon, m_weapon, ASSET_TYPE_WEAPON)
|
DUMP_ASSET_POOL(AssetDumperWeapon, m_weapon, ASSET_TYPE_WEAPON)
|
||||||
DUMP_ASSET_POOL(AssetDumperWeaponAttachment, m_attachment, ASSET_TYPE_ATTACHMENT)
|
DUMP_ASSET_POOL(AssetDumperWeaponAttachment, m_attachment, ASSET_TYPE_ATTACHMENT)
|
||||||
DUMP_ASSET_POOL(AssetDumperWeaponAttachmentUnique, m_attachment_unique, ASSET_TYPE_ATTACHMENT_UNIQUE)
|
DUMP_ASSET_POOL(AssetDumperWeaponAttachmentUnique, m_attachment_unique, ASSET_TYPE_ATTACHMENT_UNIQUE)
|
||||||
// DUMP_ASSET_POOL(AssetDumperWeaponCamo, m_camo, ASSET_TYPE_WEAPON_CAMO)
|
DUMP_ASSET_POOL(AssetDumperWeaponCamo, m_camo, ASSET_TYPE_WEAPON_CAMO)
|
||||||
DUMP_ASSET_POOL(AssetDumperSndDriverGlobals, m_snd_driver_globals, ASSET_TYPE_SNDDRIVER_GLOBALS)
|
DUMP_ASSET_POOL(AssetDumperSndDriverGlobals, m_snd_driver_globals, ASSET_TYPE_SNDDRIVER_GLOBALS)
|
||||||
// DUMP_ASSET_POOL(AssetDumperFxEffectDef, m_fx, ASSET_TYPE_FX)
|
// DUMP_ASSET_POOL(AssetDumperFxEffectDef, m_fx, ASSET_TYPE_FX)
|
||||||
// DUMP_ASSET_POOL(AssetDumperFxImpactTable, m_fx_impact_table, ASSET_TYPE_IMPACT_FX)
|
// DUMP_ASSET_POOL(AssetDumperFxImpactTable, m_fx_impact_table, ASSET_TYPE_IMPACT_FX)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user