mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-12 07:48:16 -05:00
Split InfoString classes into multiple files depending on loading and writing code
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "Game/IW4/CommonIW4.h"
|
||||
#include "Game/IW4/InfoStringIW4.h"
|
||||
#include "Game/IW4/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "Game/IW4/CommonIW4.h"
|
||||
#include "Game/IW4/InfoStringIW4.h"
|
||||
#include "Game/IW4/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
|
@ -0,0 +1,159 @@
|
||||
#include "InfoStringFromStructConverter.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
void InfoStringFromStructConverter::FillFromBaseField(const cspField_t& field)
|
||||
{
|
||||
switch (static_cast<csParseFieldType_t>(field.iFieldType))
|
||||
{
|
||||
case CSPFT_STRING:
|
||||
FillFromString(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_STRING_MAX_STRING_CHARS:
|
||||
FillFromStringBuffer(std::string(field.szName), field.iOffset, 1024);
|
||||
break;
|
||||
|
||||
case CSPFT_STRING_MAX_QPATH:
|
||||
FillFromStringBuffer(std::string(field.szName), field.iOffset, 64);
|
||||
break;
|
||||
|
||||
case CSPFT_STRING_MAX_OSPATH:
|
||||
FillFromStringBuffer(std::string(field.szName), field.iOffset, 256);
|
||||
break;
|
||||
|
||||
case CSPFT_INT:
|
||||
FillFromInt(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_QBOOLEAN:
|
||||
FillFromQBoolean(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_BOOL:
|
||||
FillFromBool(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_FLOAT:
|
||||
FillFromFloat(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_MPH_TO_INCHES_PER_SEC:
|
||||
{
|
||||
const auto* num = reinterpret_cast<float*>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::to_string(*num / 17.6f));
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_MILLISECONDS:
|
||||
FillFromMilliseconds(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_FX:
|
||||
{
|
||||
const auto* fx = *reinterpret_cast<FxEffectDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
|
||||
if (fx)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(fx->name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_XMODEL:
|
||||
{
|
||||
const auto* model = *reinterpret_cast<XModel**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
|
||||
if (model)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(model->name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_MATERIAL:
|
||||
{
|
||||
const auto* material = *reinterpret_cast<Material**>(reinterpret_cast<uintptr_t>(m_structure) + field.
|
||||
iOffset);
|
||||
|
||||
if (material)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(material->info.name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_PHYS_COLLMAP:
|
||||
{
|
||||
const auto* physCollMap = *reinterpret_cast<PhysCollmap**>(reinterpret_cast<uintptr_t>(m_structure) + field.
|
||||
iOffset);
|
||||
|
||||
if (physCollMap)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(physCollMap->name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_SOUND:
|
||||
{
|
||||
const auto* sndAlias = reinterpret_cast<SndAliasCustom*>(reinterpret_cast<uintptr_t>(m_structure) + field.
|
||||
iOffset);
|
||||
|
||||
if (sndAlias->name)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(sndAlias->name->soundName));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_TRACER:
|
||||
{
|
||||
const auto* tracer = *reinterpret_cast<TracerDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.
|
||||
iOffset);
|
||||
|
||||
if (tracer)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(tracer->name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_NUM_BASE_FIELD_TYPES:
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverter::FillInfoString()
|
||||
{
|
||||
for (auto fieldIndex = 0u; fieldIndex < m_field_count; fieldIndex++)
|
||||
{
|
||||
const auto& field = m_fields[fieldIndex];
|
||||
assert(field.iFieldType >= 0);
|
||||
|
||||
if (field.iFieldType < CSPFT_NUM_BASE_FIELD_TYPES)
|
||||
FillFromBaseField(field);
|
||||
else
|
||||
FillFromExtensionField(field);
|
||||
}
|
||||
}
|
||||
|
||||
InfoStringFromStructConverter::InfoStringFromStructConverter(const void* structure, const cspField_t* fields,
|
||||
const size_t fieldCount)
|
||||
: InfoStringFromStructConverterBase(structure),
|
||||
m_fields(fields),
|
||||
m_field_count(fieldCount)
|
||||
{
|
||||
}
|
||||
|
||||
InfoStringFromStructConverter::InfoStringFromStructConverter(const void* structure, const cspField_t* fields, const size_t fieldCount,
|
||||
std::function<std::string(scr_string_t)> scriptStringValueCallback)
|
||||
: InfoStringFromStructConverterBase(structure, std::move(scriptStringValueCallback)),
|
||||
m_fields(fields),
|
||||
m_field_count(fieldCount)
|
||||
{
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "InfoString/InfoStringFromStructConverterBase.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class InfoStringFromStructConverter : public InfoStringFromStructConverterBase
|
||||
{
|
||||
protected:
|
||||
const cspField_t* m_fields;
|
||||
size_t m_field_count;
|
||||
|
||||
virtual void FillFromExtensionField(const cspField_t& field) = 0;
|
||||
void FillFromBaseField(const cspField_t& field);
|
||||
void FillInfoString() override;
|
||||
|
||||
public:
|
||||
InfoStringFromStructConverter(const void* structure, const cspField_t* fields, size_t fieldCount);
|
||||
InfoStringFromStructConverter(const void* structure, const cspField_t* fields, size_t fieldCount, std::function<std::string(scr_string_t)> scriptStringValueCallback);
|
||||
};
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Utils/InfoString.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
|
@ -0,0 +1,156 @@
|
||||
#include "InfoStringFromStructConverter.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
void InfoStringFromStructConverter::FillFromBaseField(const cspField_t& field)
|
||||
{
|
||||
switch (static_cast<csParseFieldType_t>(field.iFieldType))
|
||||
{
|
||||
case CSPFT_STRING:
|
||||
FillFromString(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_STRING_MAX_STRING_CHARS:
|
||||
FillFromStringBuffer(std::string(field.szName), field.iOffset, 1024);
|
||||
break;
|
||||
|
||||
case CSPFT_STRING_MAX_QPATH:
|
||||
FillFromStringBuffer(std::string(field.szName), field.iOffset, 64);
|
||||
break;
|
||||
|
||||
case CSPFT_STRING_MAX_OSPATH:
|
||||
FillFromStringBuffer(std::string(field.szName), field.iOffset, 256);
|
||||
break;
|
||||
|
||||
case CSPFT_INT:
|
||||
FillFromInt(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_UINT:
|
||||
FillFromUint(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_BOOL:
|
||||
FillFromBool(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_QBOOLEAN:
|
||||
FillFromQBoolean(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_FLOAT:
|
||||
FillFromFloat(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_MILLISECONDS:
|
||||
FillFromMilliseconds(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_FX:
|
||||
{
|
||||
const auto* fx = *reinterpret_cast<FxEffectDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
|
||||
if (fx)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(fx->name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_XMODEL:
|
||||
{
|
||||
const auto* model = *reinterpret_cast<XModel**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
|
||||
if (model)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(model->name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_MATERIAL:
|
||||
case CSPFT_MATERIAL_STREAM:
|
||||
{
|
||||
const auto* material = *reinterpret_cast<Material**>(reinterpret_cast<uintptr_t>(m_structure) + field.
|
||||
iOffset);
|
||||
|
||||
if (material)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(material->info.name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_PHYS_PRESET:
|
||||
{
|
||||
const auto* physPreset = *reinterpret_cast<PhysPreset**>(reinterpret_cast<uintptr_t>(m_structure) + field.
|
||||
iOffset);
|
||||
|
||||
if (physPreset)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(physPreset->name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_SCRIPT_STRING:
|
||||
FillFromScriptString(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case CSPFT_TRACER:
|
||||
{
|
||||
const auto* tracer = *reinterpret_cast<TracerDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
|
||||
if (tracer)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(tracer->name)));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_SOUND_ALIAS_ID:
|
||||
{
|
||||
// TODO: Search sound files for files matching the hash
|
||||
const auto* hash = reinterpret_cast<unsigned*>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "@" + std::to_string(*hash));
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_NUM_BASE_FIELD_TYPES:
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverter::FillInfoString()
|
||||
{
|
||||
for (auto fieldIndex = 0u; fieldIndex < m_field_count; fieldIndex++)
|
||||
{
|
||||
const auto& field = m_fields[fieldIndex];
|
||||
assert(field.iFieldType >= 0);
|
||||
|
||||
if (field.iFieldType < CSPFT_NUM_BASE_FIELD_TYPES)
|
||||
FillFromBaseField(field);
|
||||
else
|
||||
FillFromExtensionField(field);
|
||||
}
|
||||
}
|
||||
|
||||
InfoStringFromStructConverter::InfoStringFromStructConverter(const void* structure, const cspField_t* fields,
|
||||
const size_t fieldCount)
|
||||
: InfoStringFromStructConverterBase(structure),
|
||||
m_fields(fields),
|
||||
m_field_count(fieldCount)
|
||||
{
|
||||
}
|
||||
|
||||
InfoStringFromStructConverter::InfoStringFromStructConverter(const void* structure, const cspField_t* fields, const size_t fieldCount,
|
||||
std::function<std::string(scr_string_t)> scriptStringValueCallback)
|
||||
: InfoStringFromStructConverterBase(structure, std::move(scriptStringValueCallback)),
|
||||
m_fields(fields),
|
||||
m_field_count(fieldCount)
|
||||
{
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "InfoString/InfoStringFromStructConverterBase.h"
|
||||
#include "Game/T6/T6.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class InfoStringFromStructConverter : public InfoStringFromStructConverterBase
|
||||
{
|
||||
protected:
|
||||
const cspField_t* m_fields;
|
||||
size_t m_field_count;
|
||||
|
||||
virtual void FillFromExtensionField(const cspField_t& field) = 0;
|
||||
void FillFromBaseField(const cspField_t& field);
|
||||
void FillInfoString() override;
|
||||
|
||||
public:
|
||||
InfoStringFromStructConverter(const void* structure, const cspField_t* fields, size_t fieldCount);
|
||||
InfoStringFromStructConverter(const void* structure, const cspField_t* fields, size_t fieldCount, std::function<std::string(scr_string_t)> scriptStringValueCallback);
|
||||
};
|
||||
}
|
109
src/ObjWriting/InfoString/InfoStringFromStructConverterBase.cpp
Normal file
109
src/ObjWriting/InfoString/InfoStringFromStructConverterBase.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
#include "InfoStringFromStructConverterBase.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void* structure)
|
||||
: m_structure(structure),
|
||||
m_get_scr_string([](scr_string_t)
|
||||
{
|
||||
assert(false);
|
||||
return "";
|
||||
})
|
||||
{
|
||||
}
|
||||
|
||||
InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void* structure, std::function<std::string(scr_string_t)> scriptStringValueCallback)
|
||||
: m_structure(structure),
|
||||
m_get_scr_string(std::move(scriptStringValueCallback))
|
||||
{
|
||||
}
|
||||
|
||||
InfoStringFromStructConverterBase::~InfoStringFromStructConverterBase()
|
||||
= default;
|
||||
|
||||
InfoString InfoStringFromStructConverterBase::Convert()
|
||||
{
|
||||
FillInfoString();
|
||||
return std::move(m_info_string);
|
||||
}
|
||||
|
||||
const char* InfoStringFromStructConverterBase::AssetName(const char* name)
|
||||
{
|
||||
if (name && name[0] == ',')
|
||||
return &name[1];
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromString(const std::string& key, const size_t offset)
|
||||
{
|
||||
const auto* str = *reinterpret_cast<const char**>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
|
||||
if (str)
|
||||
m_info_string.SetValueForKey(key, std::string(str));
|
||||
else
|
||||
m_info_string.SetValueForKey(key, "");
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromStringBuffer(const std::string& key, const size_t offset,
|
||||
const size_t bufferSize)
|
||||
{
|
||||
const auto* str = reinterpret_cast<const char*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
const auto strLen = strnlen(str, bufferSize);
|
||||
m_info_string.SetValueForKey(key, std::string(str, strLen));
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromInt(const std::string& key, const size_t offset)
|
||||
{
|
||||
const auto* num = reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
m_info_string.SetValueForKey(key, std::to_string(*num));
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromUint(const std::string& key, const size_t offset)
|
||||
{
|
||||
const auto* num = reinterpret_cast<unsigned int*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
m_info_string.SetValueForKey(key, std::to_string(*num));
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromBool(const std::string& key, const size_t offset)
|
||||
{
|
||||
const auto* bBool = reinterpret_cast<bool*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
m_info_string.SetValueForKey(key, *bBool ? "1" : "0");
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromQBoolean(const std::string& key, const size_t offset)
|
||||
{
|
||||
const auto* iBool = reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
m_info_string.SetValueForKey(key, *iBool != 0 ? "1" : "0");
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromFloat(const std::string& key, const size_t offset)
|
||||
{
|
||||
const auto* num = reinterpret_cast<float*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
m_info_string.SetValueForKey(key, std::to_string(*num));
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromMilliseconds(const std::string& key, const size_t offset)
|
||||
{
|
||||
const auto* millis = reinterpret_cast<unsigned int*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
m_info_string.SetValueForKey(key, std::to_string(static_cast<float>(*millis) / 1000.0f));
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromScriptString(const std::string& key, const size_t offset)
|
||||
{
|
||||
const auto* scrStr = reinterpret_cast<scr_string_t*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
m_info_string.SetValueForKey(key, m_get_scr_string(*scrStr));
|
||||
}
|
||||
|
||||
void InfoStringFromStructConverterBase::FillFromEnumInt(const std::string& key, const size_t offset,
|
||||
const char** enumValues, const size_t enumSize)
|
||||
{
|
||||
const auto num = *reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(m_structure) + offset);
|
||||
|
||||
assert(num >= 0 && num < static_cast<int>(enumSize));
|
||||
|
||||
if (num >= 0 && num < static_cast<int>(enumSize))
|
||||
m_info_string.SetValueForKey(key, std::string(enumValues[num]));
|
||||
else
|
||||
m_info_string.SetValueForKey(key, "");
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
class InfoStringFromStructConverterBase
|
||||
{
|
||||
protected:
|
||||
InfoString m_info_string;
|
||||
const void* m_structure;
|
||||
const std::function<std::string(scr_string_t)> m_get_scr_string;
|
||||
|
||||
static const char* AssetName(const char* name);
|
||||
void FillFromString(const std::string& key, size_t offset);
|
||||
void FillFromStringBuffer(const std::string& key, size_t offset, size_t bufferSize);
|
||||
void FillFromInt(const std::string& key, size_t offset);
|
||||
void FillFromUint(const std::string&, size_t offset);
|
||||
void FillFromBool(const std::string&, size_t offset);
|
||||
void FillFromQBoolean(const std::string& key, size_t offset);
|
||||
void FillFromFloat(const std::string& key, size_t offset);
|
||||
void FillFromMilliseconds(const std::string& key, size_t offset);
|
||||
void FillFromScriptString(const std::string& key, size_t offset);
|
||||
void FillFromEnumInt(const std::string& key, size_t offset, const char** enumValues, size_t enumSize);
|
||||
|
||||
virtual void FillInfoString() = 0;
|
||||
|
||||
public:
|
||||
explicit InfoStringFromStructConverterBase(const void* structure);
|
||||
InfoStringFromStructConverterBase(const void* structure, std::function<std::string(scr_string_t)> scriptStringValueCallback);
|
||||
virtual ~InfoStringFromStructConverterBase();
|
||||
InfoStringFromStructConverterBase(const InfoStringFromStructConverterBase& other) = delete;
|
||||
InfoStringFromStructConverterBase(InfoStringFromStructConverterBase&& other) noexcept = delete;
|
||||
InfoStringFromStructConverterBase& operator=(const InfoStringFromStructConverterBase& other) = delete;
|
||||
InfoStringFromStructConverterBase& operator=(InfoStringFromStructConverterBase&& other) noexcept = delete;
|
||||
|
||||
InfoString Convert();
|
||||
};
|
Reference in New Issue
Block a user