mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
Add dumper and reader for IW4 GfxLightDef
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#include "AssetLoaderGfxLightDef.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "ObjLoading.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
@ -8,6 +10,15 @@
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
std::string AssetLoaderGfxLightDef::GetAssetFilename(const std::string& assetName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << "lights/" << assetName;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
|
||||
{
|
||||
auto* lightDef = memory->Create<GfxLightDef>();
|
||||
@ -15,3 +26,46 @@ void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, Mem
|
||||
lightDef->name = memory->Dup(assetName.c_str());
|
||||
return lightDef;
|
||||
}
|
||||
|
||||
bool AssetLoaderGfxLightDef::CanLoadFromRaw() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssetLoaderGfxLightDef::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
|
||||
{
|
||||
const auto filename = GetAssetFilename(assetName);
|
||||
const auto file = searchPath->Open(filename);
|
||||
if (!file.IsOpen())
|
||||
return false;
|
||||
|
||||
const auto imageNameSize = file.m_length - sizeof(char) - sizeof(char);
|
||||
if (imageNameSize < 0 || imageNameSize > MAX_IMAGE_NAME_SIZE)
|
||||
return false;
|
||||
|
||||
std::string imageName(static_cast<size_t>(imageNameSize), '\0');
|
||||
|
||||
int8_t samplerState;
|
||||
int8_t lmapLookupStart;
|
||||
file.m_stream->read(reinterpret_cast<char*>(&samplerState), sizeof(int8_t));
|
||||
file.m_stream->read(&imageName[0], static_cast<size_t>(imageNameSize));
|
||||
file.m_stream->read(reinterpret_cast<char*>(&lmapLookupStart), sizeof(int8_t));
|
||||
|
||||
auto* imageDependency = reinterpret_cast<XAssetInfo<GfxImage>*>(manager->LoadDependency(ASSET_TYPE_IMAGE, imageName));
|
||||
|
||||
if(!imageDependency)
|
||||
{
|
||||
std::cerr << "Could not load GfxLightDef \"" << assetName << "\" due to missing image \"" << imageName << "\"\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* lightDef = memory->Create<GfxLightDef>();
|
||||
lightDef->name = memory->Dup(assetName.c_str());
|
||||
lightDef->attenuation.samplerState = samplerState;
|
||||
lightDef->attenuation.image = imageDependency->Asset();
|
||||
lightDef->lmapLookupStart = static_cast<int>(static_cast<uint8_t>(lmapLookupStart));
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_LIGHT_DEF, assetName, lightDef);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -8,7 +8,13 @@ namespace IW4
|
||||
{
|
||||
class AssetLoaderGfxLightDef final : public BasicAssetLoader<ASSET_TYPE_LIGHT_DEF, GfxLightDef>
|
||||
{
|
||||
static constexpr auto MAX_IMAGE_NAME_SIZE = 0x800;
|
||||
|
||||
static std::string GetAssetFilename(const std::string& assetName);
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
@ -648,6 +648,9 @@ namespace IW4
|
||||
std::vector<MenuEventHandler*> elements;
|
||||
ConvertEventHandlerElements(elements, eventHandlerSet, menu, item);
|
||||
|
||||
if (elements.empty())
|
||||
return nullptr;
|
||||
|
||||
auto* outputSet = static_cast<MenuEventHandlerSet*>(m_memory->Alloc(sizeof(MenuEventHandlerSet) + sizeof(void*) * elements.size()));
|
||||
auto* outputElements = reinterpret_cast<MenuEventHandler**>(reinterpret_cast<int8_t*>(outputSet) + sizeof(MenuEventHandlerSet));
|
||||
memcpy(outputElements, &elements[0], sizeof(void*) * elements.size());
|
||||
|
Reference in New Issue
Block a user