Move IW4 MaterialDumper code to IW4 MaterialDecompiler

This commit is contained in:
Jan 2023-07-29 11:55:11 +02:00
parent d48e0519ac
commit 2088118b4a
6 changed files with 1574 additions and 1491 deletions

View File

@ -52,6 +52,7 @@ function ObjLoading:project()
self:include(includes)
Crypto:include(includes)
Utils:include(includes)
json:include(includes)
minilzo:include(includes)
minizip:include(includes)
zlib:include(includes)

View File

@ -0,0 +1,42 @@
#pragma once
#include <string>
#include <ostream>
#include <memory>
#include <typeindex>
#include "IZoneDecompilingState.h"
#include "Utils/ClassUtils.h"
#include "Obj/Gdt/GdtStream.h"
#include "Zone/Zone.h"
class DecompilingContext
{
std::unordered_map<std::type_index, std::unique_ptr<IZoneDecompilingState>> m_zone_decompiling_states;
public:
Zone* m_zone;
std::string m_base_path;
std::unique_ptr<GdtOutputStream> m_gdt;
DecompilingContext();
_NODISCARD std::unique_ptr<std::ostream> OpenAssetFile(const std::string& fileName) const;
template<typename T>
T* GetZoneDecompilingState()
{
static_assert(std::is_base_of_v<IZoneDecompilingState, T>, "T must inherit IZoneDecompilingState");
// T must also have a public default constructor
const auto foundEntry = m_zone_decompiling_states.find(typeid(T));
if (foundEntry != m_zone_decompiling_states.end())
return dynamic_cast<T*>(foundEntry->second.get());
auto newState = std::make_unique<T>();
newState->SetZone(m_zone);
auto* newStatePtr = newState.get();
m_zone_decompiling_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneDecompilingState>>(typeid(T), std::move(newState)));
return newStatePtr;
}
};

View File

@ -0,0 +1,20 @@
#pragma once
#include "Zone/Zone.h"
class IZoneDecompilingState
{
protected:
IZoneDecompilingState() = default;
public:
virtual ~IZoneDecompilingState() = default;
IZoneDecompilingState(const IZoneDecompilingState& other) = default;
IZoneDecompilingState(IZoneDecompilingState&& other) noexcept = default;
IZoneDecompilingState& operator=(const IZoneDecompilingState& other) = default;
IZoneDecompilingState& operator=(IZoneDecompilingState&& other) noexcept = default;
virtual void SetZone(Zone* zone)
{
// Do nothing by default
}
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
#pragma once
#include "Decompiling/DecompilingContext.h"
#include "Game/IW4/IW4.h"
namespace IW4
{
class DecompilerMaterial
{
protected:
void DumpAsset(DecompilingContext& context, XAssetInfo<Material>* asset);
};
}

File diff suppressed because it is too large Load Diff