From 3d75566515821b7748672e75db89f8da35d55bfe Mon Sep 17 00:00:00 2001 From: SuperSonic16 <25761885+thesupersonic16@users.noreply.github.com> Date: Sun, 8 Sep 2024 13:27:32 +1000 Subject: [PATCH] Fixed issues with saving STSC2 files --- DALTools/DALLib/File/STSC2File.cs | 14 +++++++++++--- DALTools/DALLib/Scripting/STSC2Sequence.cs | 2 +- DALTools/ScriptDialogueEditor/MainWindow.xaml.cs | 1 + DALTools/ScriptDialogueEditor/STSC2FileDialogue.cs | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/DALTools/DALLib/File/STSC2File.cs b/DALTools/DALLib/File/STSC2File.cs index af0177b..9d8d4c0 100644 --- a/DALTools/DALLib/File/STSC2File.cs +++ b/DALTools/DALLib/File/STSC2File.cs @@ -162,9 +162,17 @@ public override void Load(ExtendedBinaryReader reader, bool keepOpen = false) if (CheckFlag(STSC2Flags.Security)) _data = SecurityDecode(_data, _data.Length, 0); - // Decompress stream - using (var deflate = new DeflateStream(new MemoryStream(_data, 2, _data.Length - 2), CompressionMode.Decompress, false)) - scriptStream = new VirtualStream(deflate.CacheStream(), keepOpen); + // Decompress stream + using (var deflate = new DeflateStream(new MemoryStream(_data, 2, _data.Length - 2), CompressionMode.Decompress, false)) + { + var memoryStream = deflate.CacheStream(); + + // Test + //System.IO.File.WriteAllBytes("out.bin", memoryStream.ToArray()); + //memoryStream.Position = 0; + + scriptStream = new VirtualStream(memoryStream, keepOpen); + } } else { diff --git a/DALTools/DALLib/Scripting/STSC2Sequence.cs b/DALTools/DALLib/Scripting/STSC2Sequence.cs index 7b80433..bac29d3 100644 --- a/DALTools/DALLib/Scripting/STSC2Sequence.cs +++ b/DALTools/DALLib/Scripting/STSC2Sequence.cs @@ -69,7 +69,7 @@ public void WriteSequence(ExtendedBinaryWriter writer, bool incudeCmdLineInfo) foreach (var line in Lines) for (int i = 0; i < line.arguments.Count; i++) if (line.arguments[i] is STSC2Commands.Command refLine) - writer.FillInOffset($"{line.GetHashCode()}{refLine.GetHashCode()}", lines[line]); + writer.FillInOffset($"{line.GetHashCode()}{refLine.GetHashCode()}", lines[refLine]); // TODO: Handle trees diff --git a/DALTools/ScriptDialogueEditor/MainWindow.xaml.cs b/DALTools/ScriptDialogueEditor/MainWindow.xaml.cs index d2c1109..5a1e487 100644 --- a/DALTools/ScriptDialogueEditor/MainWindow.xaml.cs +++ b/DALTools/ScriptDialogueEditor/MainWindow.xaml.cs @@ -95,6 +95,7 @@ public void LoadScriptDatabase() if (File.Exists(path)) { CharacterNames.Clear(); + CharacterNames.Add(0xFF, "None"); var table = new TableFile(); table.Load(path); var entries = table.ToObject(); diff --git a/DALTools/ScriptDialogueEditor/STSC2FileDialogue.cs b/DALTools/ScriptDialogueEditor/STSC2FileDialogue.cs index 4ec174d..2f15656 100644 --- a/DALTools/ScriptDialogueEditor/STSC2FileDialogue.cs +++ b/DALTools/ScriptDialogueEditor/STSC2FileDialogue.cs @@ -37,7 +37,7 @@ public override void Save(ExtendedBinaryWriter writer) case "Voice": break; case "Mes": - line.arguments[3] = code.Text; + line.arguments[3] = code.Text.Replace("\\n", "\n"); break; case "Script": break;