mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-06 11:11:50 +00:00
IW5 menu dumping initial commit
This commit is contained in:
76
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperMenuDef.cpp
Normal file
76
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperMenuDef.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include "AssetDumperMenuDef.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "ObjWriting.h"
|
||||
#include "Game/IW5/GameAssetPoolIW5.h"
|
||||
#include "Game/IW5/Menu/MenuDumperIW5.h"
|
||||
#include "Menu/AbstractMenuDumper.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
const MenuList* AssetDumperMenuDef::GetParentMenuList(XAssetInfo<menuDef_t>* asset)
|
||||
{
|
||||
const auto* menu = asset->Asset();
|
||||
const auto* gameAssetPool = dynamic_cast<GameAssetPoolIW5*>(asset->m_zone->m_pools.get());
|
||||
for (const auto* menuList : *gameAssetPool->m_menu_list)
|
||||
{
|
||||
const auto* menuListAsset = menuList->Asset();
|
||||
|
||||
for (auto menuIndex = 0; menuIndex < menuListAsset->menuCount; menuIndex++)
|
||||
{
|
||||
if (menuListAsset->menus[menuIndex] == menu)
|
||||
return menuListAsset;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string AssetDumperMenuDef::GetPathForMenu(XAssetInfo<menuDef_t>* asset)
|
||||
{
|
||||
const auto* list = GetParentMenuList(asset);
|
||||
|
||||
if (!list)
|
||||
return "ui_mp/" + std::string(asset->Asset()->window.name) + ".menu";
|
||||
|
||||
const fs::path p(list->name);
|
||||
std::string parentPath;
|
||||
if (p.has_parent_path())
|
||||
parentPath = p.parent_path().string() + "/";
|
||||
|
||||
return parentPath + std::string(asset->Asset()->window.name) + ".menu";
|
||||
}
|
||||
|
||||
bool AssetDumperMenuDef::ShouldDump(XAssetInfo<menuDef_t>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperMenuDef::DumpAsset(AssetDumpingContext& context, XAssetInfo<menuDef_t>* asset)
|
||||
{
|
||||
const auto* menu = asset->Asset();
|
||||
const auto menuFilePath = GetPathForMenu(asset);
|
||||
|
||||
if(ObjWriting::ShouldHandleAssetType(ASSET_TYPE_MENULIST))
|
||||
{
|
||||
// Don't dump menu file separately if the name matches the menu list
|
||||
const auto* menuListParent = GetParentMenuList(asset);
|
||||
if (menuListParent && menuFilePath == menuListParent->name)
|
||||
return;
|
||||
}
|
||||
|
||||
const auto assetFile = context.OpenAssetFile(menuFilePath);
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
MenuDumper menuDumper(*assetFile);
|
||||
|
||||
menuDumper.Start();
|
||||
menuDumper.WriteMenu(menu);
|
||||
menuDumper.End();
|
||||
}
|
17
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperMenuDef.h
Normal file
17
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperMenuDef.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class AssetDumperMenuDef final : public AbstractAssetDumper<menuDef_t>
|
||||
{
|
||||
static const MenuList* GetParentMenuList(XAssetInfo<menuDef_t>* asset);
|
||||
static std::string GetPathForMenu(XAssetInfo<menuDef_t>* asset);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<menuDef_t>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<menuDef_t>* asset) override;
|
||||
};
|
||||
}
|
120
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperMenuList.cpp
Normal file
120
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperMenuList.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
#include "AssetDumperMenuList.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
|
||||
#include "ObjWriting.h"
|
||||
#include "Game/IW5/Menu/MenuDumperIW5.h"
|
||||
#include "Menu/AbstractMenuDumper.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
std::vector<const ExpressionSupportingData*> AssetDumperMenuList::GetAllUniqueExpressionSupportingData(const MenuList* menuList)
|
||||
{
|
||||
std::vector<const ExpressionSupportingData*> result;
|
||||
std::set<const ExpressionSupportingData*> alreadyAddedSupportingData;
|
||||
|
||||
if (menuList->menus == nullptr)
|
||||
return result;
|
||||
|
||||
for(auto i = 0; i < menuList->menuCount; i++)
|
||||
{
|
||||
if(menuList->menus[i] == nullptr)
|
||||
continue;
|
||||
|
||||
const auto* menu = menuList->menus[i];
|
||||
|
||||
if(menu->data == nullptr || menu->data->expressionData == nullptr)
|
||||
continue;
|
||||
|
||||
if(alreadyAddedSupportingData.find(menu->data->expressionData) == alreadyAddedSupportingData.end())
|
||||
{
|
||||
result.push_back(menu->data->expressionData);
|
||||
alreadyAddedSupportingData.emplace(menu->data->expressionData);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AssetDumperMenuList::DumpFunctions(MenuDumper& menuDumper, const MenuList* menuList)
|
||||
{
|
||||
const auto allSupportingData = GetAllUniqueExpressionSupportingData(menuList);
|
||||
auto functionIndex = 0u;
|
||||
|
||||
assert(allSupportingData.size() <= 1);
|
||||
|
||||
for (const auto* supportingData : allSupportingData)
|
||||
{
|
||||
if (supportingData->uifunctions.functions == nullptr)
|
||||
continue;
|
||||
|
||||
for(auto i = 0; i < supportingData->uifunctions.totalFunctions; i++)
|
||||
{
|
||||
const auto* function = supportingData->uifunctions.functions[i];
|
||||
if(function == nullptr)
|
||||
continue;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "FUNC_" << functionIndex;
|
||||
|
||||
menuDumper.WriteFunctionDef(ss.str(), function);
|
||||
|
||||
functionIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AssetDumperMenuList::DumpMenus(MenuDumper& menuDumper, const MenuList* menuList)
|
||||
{
|
||||
const fs::path p(menuList->name);
|
||||
|
||||
std::string parentPath;
|
||||
if (p.has_parent_path())
|
||||
parentPath = p.parent_path().string() + "/";
|
||||
|
||||
for (auto menuNum = 0; menuNum < menuList->menuCount; menuNum++)
|
||||
{
|
||||
const auto* menu = menuList->menus[menuNum];
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << parentPath << menu->window.name << ".menu";
|
||||
|
||||
const auto menuName = ss.str();
|
||||
|
||||
// If the menu was embedded directly as menu list write its data in the menu list file
|
||||
if (menuName == menuList->name)
|
||||
menuDumper.WriteMenu(menu);
|
||||
else
|
||||
menuDumper.IncludeMenu(ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
bool AssetDumperMenuList::ShouldDump(XAssetInfo<MenuList>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperMenuList::DumpAsset(AssetDumpingContext& context, XAssetInfo<MenuList>* asset)
|
||||
{
|
||||
const auto* menuList = asset->Asset();
|
||||
const auto assetFile = context.OpenAssetFile(asset->m_name);
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
MenuDumper menuDumper(*assetFile);
|
||||
|
||||
menuDumper.Start();
|
||||
|
||||
if(!ObjWriting::Configuration.MenuLegacyMode)
|
||||
DumpFunctions(menuDumper, menuList);
|
||||
|
||||
DumpMenus(menuDumper, menuList);
|
||||
|
||||
menuDumper.End();
|
||||
}
|
20
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperMenuList.h
Normal file
20
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperMenuList.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Game/IW5/Menu/MenuDumperIW5.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class AssetDumperMenuList final : public AbstractAssetDumper<MenuList>
|
||||
{
|
||||
static std::vector<const ExpressionSupportingData*> GetAllUniqueExpressionSupportingData(const MenuList* menuList);
|
||||
|
||||
static void DumpFunctions(MenuDumper& menuDumper, const MenuList* menuList);
|
||||
static void DumpMenus(MenuDumper& menuDumper, const MenuList* menuList);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<MenuList>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<MenuList>* asset) override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user