mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-17 02:13:02 +00:00
refactor: use ZoneOutputOffset for written variables
This commit is contained in:
@@ -79,11 +79,14 @@ void ContentWriter::WriteScriptStringList(const bool atStreamStart)
|
||||
|
||||
void ContentWriter::WriteXAsset(const bool atStreamStart)
|
||||
{
|
||||
#ifdef ARCH_x86
|
||||
static_assert(offsetof(XAsset, header.data) == 4u);
|
||||
#endif
|
||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||
writer.Write(&varXAsset->header.headerEntry); \
|
||||
writer.Write(varXAsset->header.headerEntry, varXAssetWritten.WithInnerOffset(4)); \
|
||||
break; \
|
||||
}
|
||||
#define SKIP_ASSET(type_index, typeName, headerEntry) \
|
||||
|
||||
@@ -79,11 +79,14 @@ void ContentWriter::WriteScriptStringList(const bool atStreamStart)
|
||||
|
||||
void ContentWriter::WriteXAsset(const bool atStreamStart)
|
||||
{
|
||||
#ifdef ARCH_x86
|
||||
static_assert(offsetof(XAsset, header.data) == 4u);
|
||||
#endif
|
||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||
writer.Write(&varXAsset->header.headerEntry); \
|
||||
writer.Write(varXAsset->header.headerEntry, varXAssetWritten.WithInnerOffset(4)); \
|
||||
break; \
|
||||
}
|
||||
#define SKIP_ASSET(type_index, typeName, headerEntry) \
|
||||
|
||||
@@ -79,11 +79,14 @@ void ContentWriter::WriteScriptStringList(const bool atStreamStart)
|
||||
|
||||
void ContentWriter::WriteXAsset(const bool atStreamStart)
|
||||
{
|
||||
#ifdef ARCH_x86
|
||||
static_assert(offsetof(XAsset, header.data) == 4u);
|
||||
#endif
|
||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||
writer.Write(&varXAsset->header.headerEntry); \
|
||||
writer.Write(varXAsset->header.headerEntry, varXAssetWritten.WithInnerOffset(4)); \
|
||||
break; \
|
||||
}
|
||||
#define SKIP_ASSET(type_index, typeName, headerEntry) \
|
||||
|
||||
@@ -79,11 +79,14 @@ void ContentWriter::WriteScriptStringList(const bool atStreamStart)
|
||||
|
||||
void ContentWriter::WriteXAsset(const bool atStreamStart)
|
||||
{
|
||||
#ifdef ARCH_x86
|
||||
static_assert(offsetof(XAsset, header.data) == 4u);
|
||||
#endif
|
||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||
writer.Write(&varXAsset->header.headerEntry); \
|
||||
writer.Write(varXAsset->header.headerEntry, varXAssetWritten.WithInnerOffset(4)); \
|
||||
break; \
|
||||
}
|
||||
#define SKIP_ASSET(type_index, typeName, headerEntry) \
|
||||
|
||||
@@ -82,11 +82,14 @@ void ContentWriter::WriteScriptStringList(const bool atStreamStart)
|
||||
|
||||
void ContentWriter::WriteXAsset(const bool atStreamStart)
|
||||
{
|
||||
#ifdef ARCH_x86
|
||||
static_assert(offsetof(XAsset, header.data) == 4u);
|
||||
#endif
|
||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||
writer.Write(&varXAsset->header.headerEntry); \
|
||||
writer.Write(varXAsset->header.headerEntry, varXAssetWritten.WithInnerOffset(4)); \
|
||||
break; \
|
||||
}
|
||||
|
||||
|
||||
@@ -18,16 +18,16 @@ const char* AssetWriter::NonReferenceAssetName(const char* assetName)
|
||||
return assetName;
|
||||
}
|
||||
|
||||
scr_string_t AssetWriter::UseScriptString(const scr_string_t scrString) const
|
||||
void AssetWriter::UseScriptString(const scr_string_t scrString, const ZoneOutputOffset written) const
|
||||
{
|
||||
assert(scrString < m_asset->m_zone->m_script_strings.Count());
|
||||
|
||||
if (m_asset->m_zone == &m_zone)
|
||||
return scrString;
|
||||
return;
|
||||
|
||||
// The asset comes from a different zone, we need to translate it
|
||||
const auto strValue = m_asset->m_zone->m_script_strings.CValue(scrString);
|
||||
return m_zone.m_script_strings.GetScriptString(strValue);
|
||||
*static_cast<scr_string_t*>(written.Offset()) = m_zone.m_script_strings.GetScriptString(strValue);
|
||||
}
|
||||
|
||||
void AssetWriter::WriteScriptStringArray(const bool atStreamStart, const size_t count)
|
||||
@@ -42,7 +42,7 @@ void AssetWriter::WriteScriptStringArray(const bool atStreamStart, const size_t
|
||||
|
||||
for (size_t index = 0; index < count; index++)
|
||||
{
|
||||
*static_cast<scr_string_t*>(varScriptStringWritten.Offset()) = UseScriptString(*varScriptString);
|
||||
UseScriptString(*varScriptString, varScriptStringWritten);
|
||||
|
||||
varScriptString++;
|
||||
varScriptStringWritten.Inc(sizeof(scr_string_t));
|
||||
|
||||
@@ -11,7 +11,7 @@ protected:
|
||||
AssetWriter(XAssetInfoGeneric* asset, const Zone& zone, ZoneOutputStream& stream);
|
||||
|
||||
[[nodiscard]] static const char* NonReferenceAssetName(const char* assetName);
|
||||
[[nodiscard]] scr_string_t UseScriptString(scr_string_t scrString) const;
|
||||
void UseScriptString(scr_string_t scrString, ZoneOutputOffset written) const;
|
||||
void WriteScriptStringArray(bool atStreamStart, size_t count);
|
||||
|
||||
XAssetInfoGeneric* m_asset;
|
||||
|
||||
@@ -220,9 +220,10 @@ namespace
|
||||
{
|
||||
assert((reinterpret_cast<uintptr_t>(ptr) - reinterpret_cast<uintptr_t>(entry.m_start_ptr)) % entrySize == 0);
|
||||
const auto finalZonePointer = entry.m_start_zone_ptr + (reinterpret_cast<uintptr_t>(ptr) - reinterpret_cast<uintptr_t>(entry.m_start_ptr));
|
||||
auto* writtenPtrOffset = outputOffset.Offset();
|
||||
|
||||
for (auto i = 0u; i < m_pointer_byte_count; i++)
|
||||
static_cast<char*>(ptr)[i] = reinterpret_cast<const char*>(&finalZonePointer)[i];
|
||||
static_cast<char*>(writtenPtrOffset)[i] = reinterpret_cast<const char*>(&finalZonePointer)[i];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user