diff --git a/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg b/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg index b77ecf33..f4b7bc7c 100644 --- a/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg +++ b/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg @@ -40,7 +40,12 @@ $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference) $\n$ varScriptString = $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$;$\n$ +$if(!member.IsReusable)$ LoadScriptStringArray(true, $PrintEvaluation(reference.ArrayPointerCountEvaluation)$); +$else$ +LoadScriptStringArrayRealloc(true, $PrintEvaluation(reference.ArrayPointerCountEvaluation)$);$\n$ +$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$ = varScriptString; +$endif$ %> @@ -70,6 +75,11 @@ if($TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(referen else { $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$ = m_stream->ConvertOffsetToPointer($TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$); + $if(member.IsScriptString)$ + varScriptString = $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$; + LoadScriptStringArrayRealloc(false, $PrintEvaluation(reference.ArrayPointerCountEvaluation)$); + $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$ = varScriptString; + $endif$ }$\\$ $endif$ >> diff --git a/src/ZoneLoading/Loading/AssetLoader.cpp b/src/ZoneLoading/Loading/AssetLoader.cpp index 4c19608c..a608b0ee 100644 --- a/src/ZoneLoading/Loading/AssetLoader.cpp +++ b/src/ZoneLoading/Loading/AssetLoader.cpp @@ -52,10 +52,30 @@ void AssetLoader::LoadScriptStringArray(const bool atStreamStart, const size_t c if (atStreamStart) m_stream->Load(varScriptString, count); + auto* ptr = varScriptString; for (size_t index = 0; index < count; index++) { - *varScriptString = UseScriptString(*varScriptString); - varScriptString++; + *ptr = UseScriptString(*ptr); + ptr++; + } +} + +void AssetLoader::LoadScriptStringArrayRealloc(const bool atStreamStart, const size_t count) +{ + assert(varScriptString != nullptr); + + if (atStreamStart) + m_stream->Load(varScriptString, count); + + auto* scriptStringsNew = static_cast(m_zone->GetMemory()->Alloc(sizeof scr_string_t * count)); + memcpy_s(scriptStringsNew, sizeof scr_string_t * count, varScriptString, sizeof scr_string_t * count); + varScriptString = scriptStringsNew; + + auto* ptr = varScriptString; + for (size_t index = 0; index < count; index++) + { + *ptr = UseScriptString(*ptr); + ptr++; } } diff --git a/src/ZoneLoading/Loading/AssetLoader.h b/src/ZoneLoading/Loading/AssetLoader.h index df9b70bf..e2d32188 100644 --- a/src/ZoneLoading/Loading/AssetLoader.h +++ b/src/ZoneLoading/Loading/AssetLoader.h @@ -22,6 +22,7 @@ protected: scr_string_t UseScriptString(scr_string_t scrString); void LoadScriptStringArray(bool atStreamStart, size_t count); + void LoadScriptStringArrayRealloc(bool atStreamStart, size_t count); XAssetInfoGeneric* LinkAsset(std::string name, void* asset);