diff --git a/ConverterApp/Properties/AssemblyInfo.cs b/ConverterApp/Properties/AssemblyInfo.cs index 74225f9d..908ddd1a 100644 --- a/ConverterApp/Properties/AssemblyInfo.cs +++ b/ConverterApp/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.15.7.0")] -[assembly: AssemblyFileVersion("1.15.7.0")] +[assembly: AssemblyVersion("1.15.8.0")] +[assembly: AssemblyFileVersion("1.15.8.0")] diff --git a/LSLib/LS/Common.cs b/LSLib/LS/Common.cs index f8aa7593..1bd8d396 100644 --- a/LSLib/LS/Common.cs +++ b/LSLib/LS/Common.cs @@ -9,7 +9,7 @@ public static class Common public const int MinorVersion = 15; - public const int PatchVersion = 7; + public const int PatchVersion = 8; /// /// Returns the version number of the LSLib library diff --git a/LSLib/LS/Enums/Game.cs b/LSLib/LS/Enums/Game.cs index 8beffe97..da43875f 100644 --- a/LSLib/LS/Enums/Game.cs +++ b/LSLib/LS/Enums/Game.cs @@ -35,7 +35,7 @@ public static FileVersion LSFVersion(this Game game) } else { - return FileVersion.VerBG3; + return FileVersion.VerExtendedHeader; } } } diff --git a/LSLib/LS/LSFWriter.cs b/LSLib/LS/LSFWriter.cs index 978037eb..a0e65188 100644 --- a/LSLib/LS/LSFWriter.cs +++ b/LSLib/LS/LSFWriter.cs @@ -30,11 +30,13 @@ public class LSFWriter private List> StringHashMap; private bool ExtendedNodes = false; + private List NextSiblingIndices; public LSFWriter(Stream stream, FileVersion version) { this.Stream = stream; this.Version = (uint) version; + this.ExtendedNodes = (this.Version >= (uint)FileVersion.VerExtendedNodes); } public void Write(Resource resource) @@ -62,12 +64,18 @@ public void Write(Resource resource) NextNodeIndex = 0; NextAttributeIndex = 0; NodeIndices = new Dictionary(); + NextSiblingIndices = null; StringHashMap = new List>(StringHashMapSize); while (StringHashMap.Count < StringHashMapSize) { StringHashMap.Add(new List()); } + if (ExtendedNodes) + { + ComputeSiblingIndices(resource); + } + WriteRegions(resource); byte[] stringBuffer = null; @@ -122,6 +130,8 @@ public void Write(Resource resource) meta.Unknown3 = 0; meta.Extended = ExtendedNodes ? 1u : 0u; + BinUtils.WriteStruct
(Writer, ref header); + if (header.Version < (ulong)FileVersion.VerExtendedHeader) { BinUtils.WriteStruct(Writer, ref meta); @@ -141,8 +151,51 @@ public void Write(Resource resource) } } + private int ComputeSiblingIndices(Node node) + { + int index = NextNodeIndex; + NextNodeIndex++; + NextSiblingIndices.Add(-1); + + int lastSiblingIndex = -1; + foreach (var children in node.Children) + { + foreach (var child in children.Value) + { + int childIndex = ComputeSiblingIndices(child); + if (lastSiblingIndex != -1) + { + NextSiblingIndices[lastSiblingIndex] = childIndex; + } + + lastSiblingIndex = childIndex; + } + } + + return index; + } + + private void ComputeSiblingIndices(Resource resource) + { + NextNodeIndex = 0; + NextSiblingIndices = new List(); + + int lastRegionIndex = -1; + foreach (var region in resource.Regions) + { + int regionIndex = ComputeSiblingIndices(region.Value); + if (lastRegionIndex != -1) + { + NextSiblingIndices[lastRegionIndex] = regionIndex; + } + + lastRegionIndex = regionIndex; + } + } + private void WriteRegions(Resource resource) { + NextNodeIndex = 0; foreach (var region in resource.Regions) { if (Version >= (ulong) FileVersion.VerExtendedNodes @@ -197,7 +250,7 @@ private void WriteNodeAttributesV3(Node node) { attributeInfo.NextAttributeIndex = NextAttributeIndex + 1; } - attributeInfo.Offset = (UInt32)ValueStream.Position; + attributeInfo.Offset = lastOffset; BinUtils.WriteStruct(AttributeWriter, ref attributeInfo); NextAttributeIndex++; @@ -269,6 +322,9 @@ private void WriteNodeV3(Node node) nodeInfo.NameHashTableIndex = AddStaticString(node.Name); + // Assumes we calculated indices first using ComputeSiblingIndices() + nodeInfo.NextSiblingIndex = NextSiblingIndices[NextNodeIndex]; + if (node.Attributes.Count > 0) { nodeInfo.FirstAttributeIndex = NextAttributeIndex; @@ -279,9 +335,6 @@ private void WriteNodeV3(Node node) nodeInfo.FirstAttributeIndex = -1; } - // FIXME! - throw new Exception("Writing uncompressed LSFv3 is not supported yet"); - nodeInfo.NextSiblingIndex = -1; BinUtils.WriteStruct(NodeWriter, ref nodeInfo); NodeIndices[node] = NextNodeIndex; NextNodeIndex++; diff --git a/LSLib/Properties/AssemblyInfo.cs b/LSLib/Properties/AssemblyInfo.cs index 9697dc08..c5662fee 100644 --- a/LSLib/Properties/AssemblyInfo.cs +++ b/LSLib/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.15.7.0")] -[assembly: AssemblyFileVersion("1.15.7.0")] +[assembly: AssemblyVersion("1.15.8.0")] +[assembly: AssemblyFileVersion("1.15.8.0")]