diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs b/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs index f5d0488..54d2857 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs @@ -530,7 +530,7 @@ namespace Il2CppInspector // Load from a binary stream and metadata stream // Must be a seekable stream otherwise we catch a System.IO.NotSupportedException - public static List LoadFromStream(Stream binaryStream, Stream metadataStream, EventHandler statusCallback = null, bool silent = false) { + public static List LoadFromStream(Stream binaryStream, MemoryStream metadataStream, EventHandler statusCallback = null, bool silent = false) { // Silent operation if requested var stdout = Console.Out; diff --git a/Il2CppInspector.Common/IL2CPP/Metadata.cs b/Il2CppInspector.Common/IL2CPP/Metadata.cs index dc15504..2d86e51 100644 --- a/Il2CppInspector.Common/IL2CPP/Metadata.cs +++ b/Il2CppInspector.Common/IL2CPP/Metadata.cs @@ -48,7 +48,7 @@ namespace Il2CppInspector // Set if something in the metadata has been modified / decrypted public bool IsModified { get; } = false; - public Metadata(Stream stream, EventHandler statusCallback = null) : base(stream) + public Metadata(MemoryStream stream, EventHandler statusCallback = null) : base(stream) { // Read magic bytes if (ReadUInt32() != 0xFAB11BAF) { @@ -192,6 +192,15 @@ namespace Il2CppInspector var decryptedString = Encoding.GetString(encryptedString.Select(b => (byte) (b ^ xorKey)).ToArray()); Strings.Add(offset.current, decryptedString); } + + // Write changes back in case the user wants to save the metadata file + using (var sw = new StreamWriter(BaseStream, System.Text.Encoding.UTF8, bufferSize: -1, leaveOpen: true)) { + sw.BaseStream.Position = Header.stringOffset; + foreach (var str in Strings.OrderBy(s => s.Key)) + sw.Write(str.Value + "\0"); + sw.Flush(); + } + IsModified = true; } diff --git a/Il2CppInspector.GUI/App.xaml.cs b/Il2CppInspector.GUI/App.xaml.cs index ea0d86b..f54f7ca 100644 --- a/Il2CppInspector.GUI/App.xaml.cs +++ b/Il2CppInspector.GUI/App.xaml.cs @@ -70,7 +70,7 @@ namespace Il2CppInspectorGUI return await LoadMetadataAsync(stream); } - public Task LoadMetadataAsync(Stream metadataStream) => + public Task LoadMetadataAsync(MemoryStream metadataStream) => Task.Run(() => { try { OnStatusUpdate?.Invoke(this, "Processing metadata");