Merge pull request #83 from Laupetin/feature/fix-menu-dumps-mistakes

Fix smaller menu dumping mistakes
This commit is contained in:
Jan 2024-01-07 15:47:27 +01:00 committed by GitHub
commit 48d320c99d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 450 additions and 257 deletions

View File

@ -2,6 +2,9 @@
#include "Utils/FileUtils.h"
// This is a redefinition to make this enum available on platforms without DirectX headers
namespace oat
{
enum D3DFORMAT
{
D3DFMT_UNKNOWN = 0,
@ -106,3 +109,4 @@ enum D3DFORMAT
D3DFMT_FORCE_DWORD = 0x7fffffff
};
} // namespace oat

View File

@ -103,7 +103,7 @@ enum DDS_HEADER_DXT10_MISC2
struct DDS_HEADER_DXT10
{
DXGI_FORMAT dxgiFormat;
oat::DXGI_FORMAT dxgiFormat;
D3D10_RESOURCE_DIMENSION resourceDimension;
uint32_t miscFlag;
uint32_t arraySize;

View File

@ -1,5 +1,6 @@
#pragma once
// Modified for OAT
/*
* Copyright 2016 Józef Kucia for CodeWeavers
*
@ -18,8 +19,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
namespace oat
{
const unsigned int DXGI_FORMAT_DEFINED = 1;
// This is a redefinition to make this enum available on platforms without DirectX headers
enum DXGI_FORMAT
{
DXGI_FORMAT_UNKNOWN = 0x00,
@ -145,3 +149,4 @@ enum DXGI_FORMAT
DXGI_FORMAT_FORCE_UINT = 0xffffffff,
};
} // namespace oat

View File

@ -1,6 +1,6 @@
#include "ImageFormat.h"
ImageFormat::ImageFormat(const ImageFormatId id, const D3DFORMAT d3dFormat, const DXGI_FORMAT dxgiFormat)
ImageFormat::ImageFormat(const ImageFormatId id, const oat::D3DFORMAT d3dFormat, const oat::DXGI_FORMAT dxgiFormat)
: m_id(id),
m_d3d_format(d3dFormat),
m_dxgi_format(dxgiFormat)
@ -12,19 +12,19 @@ ImageFormatId ImageFormat::GetId() const
return m_id;
}
D3DFORMAT ImageFormat::GetD3DFormat() const
oat::D3DFORMAT ImageFormat::GetD3DFormat() const
{
return m_d3d_format;
}
DXGI_FORMAT ImageFormat::GetDxgiFormat() const
oat::DXGI_FORMAT ImageFormat::GetDxgiFormat() const
{
return m_dxgi_format;
}
ImageFormatUnsigned::ImageFormatUnsigned(const ImageFormatId id,
const D3DFORMAT d3dFormat,
const DXGI_FORMAT dxgiFormat,
const oat::D3DFORMAT d3dFormat,
const oat::DXGI_FORMAT dxgiFormat,
const unsigned bitsPerPixel,
const unsigned rOffset,
const unsigned rSize,
@ -78,7 +78,7 @@ size_t ImageFormatUnsigned::GetSizeOfMipLevel(const unsigned mipLevel, const uns
}
ImageFormatBlockCompressed::ImageFormatBlockCompressed(
const ImageFormatId id, const D3DFORMAT d3dFormat, const DXGI_FORMAT dxgiFormat, const unsigned blockSize, const unsigned bitsPerBlock)
const ImageFormatId id, const oat::D3DFORMAT d3dFormat, const oat::DXGI_FORMAT dxgiFormat, const unsigned blockSize, const unsigned bitsPerBlock)
: ImageFormat(id, d3dFormat, dxgiFormat),
m_block_size(blockSize),
m_bits_per_block(bitsPerBlock)
@ -140,22 +140,23 @@ bool ImageFormatUnsigned::HasA() const
return m_a_size > 0;
}
const ImageFormatUnsigned ImageFormat::FORMAT_R8_G8_B8(ImageFormatId::R8_G8_B8, D3DFMT_R8G8B8, DXGI_FORMAT_UNKNOWN, 24, 0, 8, 8, 8, 16, 8, 0, 0);
const ImageFormatUnsigned ImageFormat::FORMAT_B8_G8_R8_X8(ImageFormatId::B8_G8_R8_X8, D3DFMT_X8R8G8B8, DXGI_FORMAT_B8G8R8X8_UNORM, 32, 16, 8, 8, 8, 0, 8, 0, 0);
const ImageFormatUnsigned ImageFormat::FORMAT_R8_G8_B8(ImageFormatId::R8_G8_B8, oat::D3DFMT_R8G8B8, oat::DXGI_FORMAT_UNKNOWN, 24, 0, 8, 8, 8, 16, 8, 0, 0);
const ImageFormatUnsigned
ImageFormat::FORMAT_R8_G8_B8_A8(ImageFormatId::R8_G8_B8_A8, D3DFMT_A8B8G8R8, DXGI_FORMAT_R8G8B8A8_UNORM, 32, 0, 8, 8, 8, 16, 8, 24, 8);
ImageFormat::FORMAT_B8_G8_R8_X8(ImageFormatId::B8_G8_R8_X8, oat::D3DFMT_X8R8G8B8, oat::DXGI_FORMAT_B8G8R8X8_UNORM, 32, 16, 8, 8, 8, 0, 8, 0, 0);
const ImageFormatUnsigned
ImageFormat::FORMAT_B8_G8_R8_A8(ImageFormatId::B8_G8_R8_A8, D3DFMT_A8R8G8B8, DXGI_FORMAT_B8G8R8A8_UNORM, 32, 16, 8, 8, 8, 0, 8, 24, 8);
const ImageFormatUnsigned ImageFormat::FORMAT_A8(ImageFormatId::A8, D3DFMT_A8, DXGI_FORMAT_A8_UNORM, 8, 0, 0, 0, 0, 0, 0, 0, 8);
ImageFormat::FORMAT_R8_G8_B8_A8(ImageFormatId::R8_G8_B8_A8, oat::D3DFMT_A8B8G8R8, oat::DXGI_FORMAT_R8G8B8A8_UNORM, 32, 0, 8, 8, 8, 16, 8, 24, 8);
const ImageFormatUnsigned
ImageFormat::FORMAT_B8_G8_R8_A8(ImageFormatId::B8_G8_R8_A8, oat::D3DFMT_A8R8G8B8, oat::DXGI_FORMAT_B8G8R8A8_UNORM, 32, 16, 8, 8, 8, 0, 8, 24, 8);
const ImageFormatUnsigned ImageFormat::FORMAT_A8(ImageFormatId::A8, oat::D3DFMT_A8, oat::DXGI_FORMAT_A8_UNORM, 8, 0, 0, 0, 0, 0, 0, 0, 8);
const ImageFormatUnsigned ImageFormat::FORMAT_R16_G16_B16_A16_FLOAT(
ImageFormatId::R16_G16_B16_A16_FLOAT, D3DFMT_A16B16G16R16F, DXGI_FORMAT_R16G16B16A16_FLOAT, 128, 0, 0, 0, 0, 0, 0, 0, 8);
const ImageFormatUnsigned ImageFormat::FORMAT_R8(ImageFormatId::R8, D3DFMT_L8, DXGI_FORMAT_R8_UNORM, 8, 0, 8, 0, 0, 0, 0, 0, 0);
const ImageFormatUnsigned ImageFormat::FORMAT_R8_A8(ImageFormatId::R8_A8, D3DFMT_A8L8, DXGI_FORMAT_UNKNOWN, 16, 0, 8, 0, 0, 0, 0, 8, 8);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC1(ImageFormatId::BC1, D3DFMT_DXT1, DXGI_FORMAT_BC1_UNORM, 4, 64);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC2(ImageFormatId::BC2, D3DFMT_DXT3, DXGI_FORMAT_BC2_UNORM, 4, 128);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC3(ImageFormatId::BC3, D3DFMT_DXT5, DXGI_FORMAT_BC3_UNORM, 4, 128);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC4(ImageFormatId::BC4, D3DFMT_UNKNOWN, DXGI_FORMAT_BC4_UNORM, 4, 64);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC5(ImageFormatId::BC5, D3DFMT_UNKNOWN, DXGI_FORMAT_BC5_UNORM, 4, 128);
ImageFormatId::R16_G16_B16_A16_FLOAT, oat::D3DFMT_A16B16G16R16F, oat::DXGI_FORMAT_R16G16B16A16_FLOAT, 128, 0, 0, 0, 0, 0, 0, 0, 8);
const ImageFormatUnsigned ImageFormat::FORMAT_R8(ImageFormatId::R8, oat::D3DFMT_L8, oat::DXGI_FORMAT_R8_UNORM, 8, 0, 8, 0, 0, 0, 0, 0, 0);
const ImageFormatUnsigned ImageFormat::FORMAT_R8_A8(ImageFormatId::R8_A8, oat::D3DFMT_A8L8, oat::DXGI_FORMAT_UNKNOWN, 16, 0, 8, 0, 0, 0, 0, 8, 8);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC1(ImageFormatId::BC1, oat::D3DFMT_DXT1, oat::DXGI_FORMAT_BC1_UNORM, 4, 64);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC2(ImageFormatId::BC2, oat::D3DFMT_DXT3, oat::DXGI_FORMAT_BC2_UNORM, 4, 128);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC3(ImageFormatId::BC3, oat::D3DFMT_DXT5, oat::DXGI_FORMAT_BC3_UNORM, 4, 128);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC4(ImageFormatId::BC4, oat::D3DFMT_UNKNOWN, oat::DXGI_FORMAT_BC4_UNORM, 4, 64);
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC5(ImageFormatId::BC5, oat::D3DFMT_UNKNOWN, oat::DXGI_FORMAT_BC5_UNORM, 4, 128);
const ImageFormat* const ImageFormat::ALL_FORMATS[static_cast<unsigned>(ImageFormatId::MAX)]{
&FORMAT_R8_G8_B8,

View File

@ -39,18 +39,18 @@ class ImageFormatBlockCompressed;
class ImageFormat
{
ImageFormatId m_id;
D3DFORMAT m_d3d_format;
DXGI_FORMAT m_dxgi_format;
oat::D3DFORMAT m_d3d_format;
oat::DXGI_FORMAT m_dxgi_format;
protected:
ImageFormat(ImageFormatId id, D3DFORMAT d3dFormat, DXGI_FORMAT dxgiFormat);
ImageFormat(ImageFormatId id, oat::D3DFORMAT d3dFormat, oat::DXGI_FORMAT dxgiFormat);
public:
virtual ~ImageFormat() = default;
ImageFormatId GetId() const;
D3DFORMAT GetD3DFormat() const;
DXGI_FORMAT GetDxgiFormat() const;
oat::D3DFORMAT GetD3DFormat() const;
oat::DXGI_FORMAT GetDxgiFormat() const;
virtual ImageFormatType GetType() const = 0;
virtual size_t GetPitch(unsigned mipLevel, unsigned width) const = 0;
@ -86,8 +86,8 @@ public:
unsigned m_a_size;
ImageFormatUnsigned(ImageFormatId id,
D3DFORMAT d3dFormat,
DXGI_FORMAT dxgiFormat,
oat::D3DFORMAT d3dFormat,
oat::DXGI_FORMAT dxgiFormat,
unsigned bitsPerPixel,
unsigned rOffset,
unsigned rSize,
@ -114,7 +114,7 @@ public:
unsigned m_block_size;
unsigned m_bits_per_block;
ImageFormatBlockCompressed(ImageFormatId id, D3DFORMAT d3dFormat, DXGI_FORMAT dxgiFormat, unsigned blockSize, unsigned bitsPerBlock);
ImageFormatBlockCompressed(ImageFormatId id, oat::D3DFORMAT d3dFormat, oat::DXGI_FORMAT dxgiFormat, unsigned blockSize, unsigned bitsPerBlock);
ImageFormatType GetType() const override;
size_t GetPitch(unsigned mipLevel, unsigned width) const override;

View File

@ -88,7 +88,7 @@ void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
else
textureLoader.Type(TextureType::T_2D);
textureLoader.Format(static_cast<D3DFORMAT>(loadDef->format));
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef->format));
textureLoader.HasMipMaps(!(loadDef->flags & iwi6::IMG_FLAG_NOMIPMAPS));
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);

View File

@ -130,7 +130,7 @@ void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
else
textureLoader.Type(TextureType::T_2D);
textureLoader.Format(static_cast<D3DFORMAT>(loadDef->format));
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef->format));
textureLoader.HasMipMaps(!(loadDef->flags & iwi8::IMG_FLAG_NOMIPMAPS));
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);

View File

@ -106,7 +106,7 @@ void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
else
textureLoader.Type(TextureType::T_2D);
textureLoader.Format(static_cast<D3DFORMAT>(loadDef->format));
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef->format));
textureLoader.HasMipMaps(!(loadDef->flags & iwi8::IMG_FLAG_NOMIPMAPS));
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);

View File

@ -95,7 +95,7 @@ void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
else
textureLoader.Type(TextureType::T_2D);
textureLoader.Format(static_cast<D3DFORMAT>(loadDef->format));
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef->format));
textureLoader.HasMipMaps(!(loadDef->flags & iwi13::IMG_FLAG_NOMIPMAPS));
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);

View File

@ -351,7 +351,7 @@ namespace T6
else
textureLoader.Type(TextureType::T_2D);
textureLoader.Format(static_cast<DXGI_FORMAT>(loadDef->format));
textureLoader.Format(static_cast<oat::DXGI_FORMAT>(loadDef->format));
textureLoader.HasMipMaps(!(loadDef->flags & iwi27::IMG_FLAG_NOMIPMAPS));
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);

View File

@ -4,7 +4,7 @@
Dx12TextureLoader::Dx12TextureLoader(MemoryManager* memoryManager)
: m_memory_manager(memoryManager),
m_format(DXGI_FORMAT_UNKNOWN),
m_format(oat::DXGI_FORMAT_UNKNOWN),
m_type(TextureType::T_2D),
m_has_mip_maps(false),
m_width(1u),
@ -24,7 +24,7 @@ const ImageFormat* Dx12TextureLoader::GetFormatForDx12Format() const
return nullptr;
}
Dx12TextureLoader& Dx12TextureLoader::Format(const DXGI_FORMAT format)
Dx12TextureLoader& Dx12TextureLoader::Format(const oat::DXGI_FORMAT format)
{
m_format = format;
return *this;

View File

@ -12,7 +12,7 @@ class Dx12TextureLoader
static std::unordered_map<ImageFormatId, ImageFormatId> m_conversion_table;
MemoryManager* m_memory_manager;
DXGI_FORMAT m_format;
oat::DXGI_FORMAT m_format;
TextureType m_type;
bool m_has_mip_maps;
size_t m_width;
@ -24,7 +24,7 @@ class Dx12TextureLoader
public:
explicit Dx12TextureLoader(MemoryManager* memoryManager);
Dx12TextureLoader& Format(DXGI_FORMAT format);
Dx12TextureLoader& Format(oat::DXGI_FORMAT format);
Dx12TextureLoader& Type(TextureType textureType);
Dx12TextureLoader& HasMipMaps(bool hasMipMaps);
Dx12TextureLoader& Width(size_t width);

View File

@ -4,7 +4,7 @@
Dx9TextureLoader::Dx9TextureLoader(MemoryManager* memoryManager)
: m_memory_manager(memoryManager),
m_format(D3DFMT_UNKNOWN),
m_format(oat::D3DFMT_UNKNOWN),
m_type(TextureType::T_2D),
m_has_mip_maps(false),
m_width(1u),
@ -24,7 +24,7 @@ const ImageFormat* Dx9TextureLoader::GetFormatForDx9Format() const
return nullptr;
}
Dx9TextureLoader& Dx9TextureLoader::Format(const D3DFORMAT format)
Dx9TextureLoader& Dx9TextureLoader::Format(const oat::D3DFORMAT format)
{
m_format = format;
return *this;

View File

@ -10,7 +10,7 @@
class Dx9TextureLoader
{
MemoryManager* m_memory_manager;
D3DFORMAT m_format;
oat::D3DFORMAT m_format;
TextureType m_type;
bool m_has_mip_maps;
size_t m_width;
@ -22,7 +22,7 @@ class Dx9TextureLoader
public:
explicit Dx9TextureLoader(MemoryManager* memoryManager);
Dx9TextureLoader& Format(D3DFORMAT format);
Dx9TextureLoader& Format(oat::D3DFORMAT format);
Dx9TextureLoader& Type(TextureType textureType);
Dx9TextureLoader& HasMipMaps(bool hasMipMaps);
Dx9TextureLoader& Width(size_t width);

View File

@ -9,7 +9,16 @@
using namespace IW4;
size_t MenuDumper::FindStatementClosingParenthesis(const Statement_s* statement, size_t openingParenthesisPosition)
// Uncomment this macro to skip interpretative expression dumping
// #define DUMP_NAIVE
#ifdef DUMP_NAIVE
#define DUMP_FUNC WriteStatementNaive
#else
#define DUMP_FUNC WriteStatementSkipInitialUnnecessaryParenthesis
#endif
size_t MenuDumper::FindStatementClosingParenthesis(const Statement_s* statement, const size_t openingParenthesisPosition)
{
assert(statement->numEntries >= 0);
assert(openingParenthesisPosition < static_cast<size_t>(statement->numEntries));
@ -158,7 +167,7 @@ void MenuDumper::WriteStatementOperandFunction(const Statement_s* statement, con
}
if (functionIndex >= 0)
m_stream << "FUNC_" << functionIndex << "()";
m_stream << "FUNC_" << functionIndex;
else
m_stream << "INVALID_FUNC";
m_stream << "()";
@ -206,7 +215,7 @@ void MenuDumper::WriteStatementOperand(const Statement_s* statement, size_t& cur
spaceNext = true;
}
void MenuDumper::WriteStatementEntryRange(const Statement_s* statement, size_t startOffset, size_t endOffset) const
void MenuDumper::WriteStatementEntryRange(const Statement_s* statement, const size_t startOffset, const size_t endOffset) const
{
assert(startOffset <= endOffset);
assert(endOffset <= static_cast<size_t>(statement->numEntries));
@ -260,6 +269,91 @@ void MenuDumper::WriteStatementSkipInitialUnnecessaryParenthesis(const Statement
}
}
void MenuDumper::WriteStatementNaive(const Statement_s* statement) const
{
const auto entryCount = static_cast<unsigned>(statement->numEntries);
const auto missingClosingParenthesis = statement->numEntries > 0 && statement->entries[0].type == EET_OPERATOR
&& statement->entries[0].data.op == OP_LEFTPAREN
&& FindStatementClosingParenthesis(statement, 0) >= static_cast<size_t>(statement->numEntries);
for (auto i = 0u; i < entryCount; i++)
{
const auto& entry = statement->entries[i];
if (entry.type == EET_OPERAND)
{
size_t pos = i;
bool discard = false;
WriteStatementOperand(statement, pos, discard);
}
else if (entry.data.op >= EXP_FUNC_STATIC_DVAR_INT && entry.data.op <= EXP_FUNC_STATIC_DVAR_STRING)
{
switch (entry.data.op)
{
case EXP_FUNC_STATIC_DVAR_INT:
m_stream << "dvarint";
break;
case EXP_FUNC_STATIC_DVAR_BOOL:
m_stream << "dvarbool";
break;
case EXP_FUNC_STATIC_DVAR_FLOAT:
m_stream << "dvarfloat";
break;
case EXP_FUNC_STATIC_DVAR_STRING:
m_stream << "dvarstring";
break;
default:
break;
}
// Functions do not have opening parenthesis in the entries. We can just pretend they do though
const auto closingParenPos = FindStatementClosingParenthesis(statement, i);
m_stream << "(";
if (closingParenPos - i + 1 >= 1)
{
const auto& staticDvarEntry = statement->entries[i + 1];
if (staticDvarEntry.type == EET_OPERAND && staticDvarEntry.data.operand.dataType == VAL_INT)
{
if (statement->supportingData && statement->supportingData->staticDvarList.staticDvars && staticDvarEntry.data.operand.internals.intVal >= 0
&& staticDvarEntry.data.operand.internals.intVal < statement->supportingData->staticDvarList.numStaticDvars)
{
const auto* staticDvar = statement->supportingData->staticDvarList.staticDvars[staticDvarEntry.data.operand.internals.intVal];
if (staticDvar && staticDvar->dvarName)
m_stream << staticDvar->dvarName;
}
else
{
m_stream << "#INVALID_DVAR_INDEX";
}
}
else
{
m_stream << "#INVALID_DVAR_OPERAND";
}
}
m_stream << ")";
i = closingParenPos;
}
else
{
assert(entry.data.op >= 0 && static_cast<unsigned>(entry.data.op) < std::extent_v<decltype(g_expFunctionNames)>);
if (entry.data.op >= 0 && static_cast<unsigned>(entry.data.op) < std::extent_v<decltype(g_expFunctionNames)>)
m_stream << g_expFunctionNames[entry.data.op];
if (entry.data.op >= OP_COUNT)
m_stream << "(";
}
}
if (missingClosingParenthesis)
m_stream << ")";
}
void MenuDumper::WriteStatementProperty(const std::string& propertyKey, const Statement_s* statementValue, bool isBooleanStatement) const
{
if (statementValue == nullptr || statementValue->numEntries < 0)
@ -271,12 +365,12 @@ void MenuDumper::WriteStatementProperty(const std::string& propertyKey, const St
if (isBooleanStatement)
{
m_stream << "when(";
WriteStatementSkipInitialUnnecessaryParenthesis(statementValue);
DUMP_FUNC(statementValue);
m_stream << ");\n";
}
else
{
WriteStatementSkipInitialUnnecessaryParenthesis(statementValue);
DUMP_FUNC(statementValue);
m_stream << ";\n";
}
}
@ -728,7 +822,6 @@ void MenuDumper::WriteItemData(const itemDef_s* item)
WriteItemKeyHandlerProperty(item->onKey);
WriteStatementProperty("exp text", item->textExp, false);
WriteStatementProperty("exp material", item->materialExp, false);
WriteStatementProperty("exp disabled", item->disabledExp, false);
WriteFloatExpressionsProperty(item->floatExpressions, item->floatExpressionCount);
WriteIntProperty("gamemsgwindowindex", item->gameMsgWindowIndex, 0);
WriteIntProperty("gamemsgwindowmode", item->gameMsgWindowMode, 0);

View File

@ -11,6 +11,8 @@ namespace IW4
{
static size_t FindStatementClosingParenthesis(const Statement_s* statement, size_t openingParenthesisPosition);
void WriteStatementNaive(const Statement_s* statement) const;
void WriteStatementOperator(const Statement_s* statement, size_t& currentPos, bool& spaceNext) const;
void WriteStatementOperandFunction(const Statement_s* statement, size_t currentPos) const;
void WriteStatementOperand(const Statement_s* statement, size_t& currentPos, bool& spaceNext) const;

View File

@ -9,6 +9,15 @@
using namespace IW5;
// Uncomment this macro to skip interpretative expression dumping
// #define DUMP_NAIVE
#ifdef DUMP_NAIVE
#define DUMP_FUNC WriteStatementNaive
#else
#define DUMP_FUNC WriteStatementSkipInitialUnnecessaryParenthesis
#endif
size_t MenuDumper::FindStatementClosingParenthesis(const Statement_s* statement, size_t openingParenthesisPosition)
{
assert(statement->numEntries >= 0);
@ -158,9 +167,10 @@ void MenuDumper::WriteStatementOperandFunction(const Statement_s* statement, con
}
if (functionIndex >= 0)
m_stream << "FUNC_" << functionIndex << "()";
m_stream << "FUNC_" << functionIndex;
else
m_stream << "INVALID_FUNC";
m_stream << "()";
}
else
{
@ -227,6 +237,83 @@ void MenuDumper::WriteStatementEntryRange(const Statement_s* statement, size_t s
}
}
void MenuDumper::WriteStatementNaive(const Statement_s* statement) const
{
const auto entryCount = static_cast<unsigned>(statement->numEntries);
for (auto i = 0u; i < entryCount; i++)
{
const auto& entry = statement->entries[i];
if (entry.type == EET_OPERAND)
{
size_t pos = i;
bool discard = false;
WriteStatementOperand(statement, pos, discard);
}
else if (entry.data.op >= EXP_FUNC_STATIC_DVAR_INT && entry.data.op <= EXP_FUNC_STATIC_DVAR_STRING)
{
switch (entry.data.op)
{
case EXP_FUNC_STATIC_DVAR_INT:
m_stream << "dvarint";
break;
case EXP_FUNC_STATIC_DVAR_BOOL:
m_stream << "dvarbool";
break;
case EXP_FUNC_STATIC_DVAR_FLOAT:
m_stream << "dvarfloat";
break;
case EXP_FUNC_STATIC_DVAR_STRING:
m_stream << "dvarstring";
break;
default:
break;
}
// Functions do not have opening parenthesis in the entries. We can just pretend they do though
const auto closingParenPos = FindStatementClosingParenthesis(statement, i);
m_stream << "(";
if (closingParenPos - i + 1 >= 1)
{
const auto& staticDvarEntry = statement->entries[i + 1];
if (staticDvarEntry.type == EET_OPERAND && staticDvarEntry.data.operand.dataType == VAL_INT)
{
if (statement->supportingData && statement->supportingData->staticDvarList.staticDvars && staticDvarEntry.data.operand.internals.intVal >= 0
&& staticDvarEntry.data.operand.internals.intVal < statement->supportingData->staticDvarList.numStaticDvars)
{
const auto* staticDvar = statement->supportingData->staticDvarList.staticDvars[staticDvarEntry.data.operand.internals.intVal];
if (staticDvar && staticDvar->dvarName)
m_stream << staticDvar->dvarName;
}
else
{
m_stream << "#INVALID_DVAR_INDEX";
}
}
else
{
m_stream << "#INVALID_DVAR_OPERAND";
}
}
m_stream << ")";
i = closingParenPos;
}
else
{
assert(entry.data.op >= 0 && static_cast<unsigned>(entry.data.op) < std::extent_v<decltype(g_expFunctionNames)>);
if (entry.data.op >= 0 && static_cast<unsigned>(entry.data.op) < std::extent_v<decltype(g_expFunctionNames)>)
m_stream << g_expFunctionNames[entry.data.op];
if (entry.data.op >= OP_COUNT)
m_stream << "(";
}
}
}
void MenuDumper::WriteStatement(const Statement_s* statement) const
{
if (statement == nullptr || statement->numEntries < 0)
@ -270,12 +357,12 @@ void MenuDumper::WriteStatementProperty(const std::string& propertyKey, const St
if (isBooleanStatement)
{
m_stream << "when(";
WriteStatementSkipInitialUnnecessaryParenthesis(statementValue);
DUMP_FUNC(statementValue);
m_stream << ");\n";
}
else
{
WriteStatementSkipInitialUnnecessaryParenthesis(statementValue);
DUMP_FUNC(statementValue);
m_stream << ";\n";
}
}
@ -730,7 +817,6 @@ void MenuDumper::WriteItemData(const itemDef_s* item)
WriteStatementProperty("exp text", item->textExp, false);
WriteStatementProperty("exp textaligny", item->textAlignYExp, false);
WriteStatementProperty("exp material", item->materialExp, false);
WriteStatementProperty("exp disabled", item->disabledExp, false);
WriteFloatExpressionsProperty(item->floatExpressions, item->floatExpressionCount);
WriteIntProperty("gamemsgwindowindex", item->gameMsgWindowIndex, 0);
WriteIntProperty("gamemsgwindowmode", item->gameMsgWindowMode, 0);

View File

@ -11,6 +11,8 @@ namespace IW5
{
static size_t FindStatementClosingParenthesis(const Statement_s* statement, size_t openingParenthesisPosition);
void WriteStatementNaive(const Statement_s* statement) const;
void WriteStatementOperator(const Statement_s* statement, size_t& currentPos, bool& spaceNext) const;
void WriteStatementOperandFunction(const Statement_s* statement, size_t currentPos) const;
void WriteStatementOperand(const Statement_s* statement, size_t& currentPos, bool& spaceNext) const;

View File

@ -39,13 +39,13 @@ class DdsWriterInternal
// Use standard pixel format for DXT1-5 for maximum compatibility and only otherwise use DX10 extension
switch (format->GetDxgiFormat())
{
case DXGI_FORMAT_BC1_UNORM:
case oat::DXGI_FORMAT_BC1_UNORM:
pf.dwFourCC = MakeFourCc('D', 'X', 'T', '1');
break;
case DXGI_FORMAT_BC2_UNORM:
case oat::DXGI_FORMAT_BC2_UNORM:
pf.dwFourCC = MakeFourCc('D', 'X', 'T', '3');
break;
case DXGI_FORMAT_BC3_UNORM:
case oat::DXGI_FORMAT_BC3_UNORM:
pf.dwFourCC = MakeFourCc('D', 'X', 'T', '5');
break;
default: