mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-18 18:57:57 -05:00
ZoneWriting stuff
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
#include "AssetWriter.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
AssetWriter::AssetWriter(XAssetInfoGeneric* asset, Zone* zone, IZoneOutputStream* stream)
|
||||
: ContentWriterBase(zone, stream),
|
||||
m_asset(asset),
|
||||
varScriptString(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
scr_string_t AssetWriter::UseScriptString(const scr_string_t scrString) const
|
||||
{
|
||||
if (m_asset->m_zone == m_zone)
|
||||
return scrString;
|
||||
|
||||
const auto strValue = m_asset->m_zone->m_script_strings[scrString];
|
||||
const auto scrStringEntry = std::find(m_zone->m_script_strings.begin(), m_zone->m_script_strings.end(), strValue);
|
||||
assert(scrStringEntry != m_zone->m_script_strings.end());
|
||||
|
||||
if (scrStringEntry != m_zone->m_script_strings.end())
|
||||
{
|
||||
return static_cast<scr_string_t>(std::distance(scrStringEntry, m_zone->m_script_strings.begin()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AssetWriter::WriteScriptStringArray(const bool atStreamStart, const size_t count)
|
||||
{
|
||||
assert(varScriptString != nullptr);
|
||||
|
||||
if (atStreamStart)
|
||||
varScriptString = m_stream->Write<scr_string_t>(varScriptString, count);
|
||||
|
||||
auto* ptr = varScriptString;
|
||||
for (size_t index = 0; index < count; index++)
|
||||
{
|
||||
*ptr = UseScriptString(*ptr);
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
class AssetWriter
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Zone/Zone.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "ContentWriterBase.h"
|
||||
|
||||
class AssetWriter : public ContentWriterBase
|
||||
{
|
||||
|
||||
};
|
||||
XAssetInfoGeneric* m_asset;
|
||||
|
||||
protected:
|
||||
scr_string_t* varScriptString;
|
||||
|
||||
AssetWriter(XAssetInfoGeneric* asset, Zone* zone, IZoneOutputStream* stream);
|
||||
|
||||
_NODISCARD scr_string_t UseScriptString(scr_string_t scrString) const;
|
||||
void WriteScriptStringArray(bool atStreamStart, size_t count);
|
||||
};
|
||||
|
@ -0,0 +1,47 @@
|
||||
#include "ContentWriterBase.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
ContentWriterBase::ContentWriterBase()
|
||||
: varXString(nullptr),
|
||||
m_zone(nullptr),
|
||||
m_stream(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ContentWriterBase::ContentWriterBase(Zone* zone, IZoneOutputStream* stream)
|
||||
: varXString(nullptr),
|
||||
m_zone(zone),
|
||||
m_stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
void ContentWriterBase::WriteXString(const bool atStreamStart)
|
||||
{
|
||||
assert(varXString != nullptr);
|
||||
|
||||
if (atStreamStart)
|
||||
varXString = m_stream->Write<const char*>(varXString);
|
||||
|
||||
if (m_stream->ReusableShouldWrite(varXString))
|
||||
{
|
||||
m_stream->Align(alignof(const char));
|
||||
m_stream->WriteNullTerminated(*varXString);
|
||||
|
||||
m_stream->MarkFollowing(*varXString);
|
||||
}
|
||||
}
|
||||
|
||||
void ContentWriterBase::WriteXStringArray(const bool atStreamStart, const size_t count)
|
||||
{
|
||||
assert(varXString != nullptr);
|
||||
|
||||
if (atStreamStart)
|
||||
varXString = m_stream->Write<const char*>(varXString, count);
|
||||
|
||||
for (size_t index = 0; index < count; index++)
|
||||
{
|
||||
WriteXString(false);
|
||||
varXString++;
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,6 @@
|
||||
class ContentWriterBase
|
||||
{
|
||||
protected:
|
||||
static constexpr void* PTR_FOLLOWING = reinterpret_cast<void*>(-1);
|
||||
static constexpr void* PTR_INSERT = reinterpret_cast<void*>(-2);
|
||||
|
||||
const char** varXString;
|
||||
|
||||
Zone* m_zone;
|
||||
@ -17,7 +14,7 @@ protected:
|
||||
ContentWriterBase();
|
||||
ContentWriterBase(Zone* zone, IZoneOutputStream* stream);
|
||||
|
||||
void WriteXString(bool atStreamStart) const;
|
||||
void WriteXString(bool atStreamStart);
|
||||
void WriteXStringArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user