diff --git a/CSharp/Libraries/UniversalEditor.Core/Accessors/FileAccessor.cs b/CSharp/Libraries/UniversalEditor.Core/Accessors/FileAccessor.cs index 9f8e990e..82200924 100644 --- a/CSharp/Libraries/UniversalEditor.Core/Accessors/FileAccessor.cs +++ b/CSharp/Libraries/UniversalEditor.Core/Accessors/FileAccessor.cs @@ -12,7 +12,8 @@ namespace UniversalEditor.Accessors public override long Position { get { return mvarFileStream.Position; } - set { mvarFileStream.Position = value; } + set { mvarFileStream.Position = value; + } } public override long Length { diff --git a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/AGGDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/AGGDataFormat.cs deleted file mode 100644 index ceb17d40..00000000 --- a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/AGGDataFormat.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using UniversalEditor.Checksum; -using UniversalEditor.Checksum.Modules.CRC32; - -using UniversalEditor.ObjectModels.FileSystem; - -namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing -{ - public class AGGDataFormat : DataFormat - { - private struct AGGFileEntry - { - public uint hash; - public uint offset; - public uint size; - public string name; - } - - private static DataFormatReference _dfr = null; - public override DataFormatReference MakeReference() - { - if (_dfr == null) - { - _dfr = base.MakeReference(); - _dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All); - _dfr.Filters.Add("Heroes of Might and Magic II AGG archive", new string[] { "*.agg" }); - } - return _dfr; - } - - protected override void LoadInternal(ref ObjectModel objectModel) - { - FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); - if (fsom == null) return; - - IO.BinaryReader br = base.Stream.BinaryReader; - ushort fileCount = br.ReadUInt16(); - - AGGFileEntry[] files = new AGGFileEntry[fileCount]; - for (ushort i = 0; i < fileCount; i++) - { - files[i].hash = br.ReadUInt32(); - files[i].offset = br.ReadUInt32(); - files[i].size = br.ReadUInt32(); - } - br.BaseStream.Seek(-(fileCount * 15), System.IO.SeekOrigin.End); - for (ushort i = 0; i < fileCount; i++) - { - files[i].name = br.ReadFixedLengthString(15); - files[i].name = files[i].name.TrimNull(); - - File file = new File(); - file.Name = files[i].name; - file.Size = files[i].size; - file.Properties.Add("InternalData", files[i]); - file.Properties.Add("BinaryReader", br); - file.DataRequest += file_DataRequest; - fsom.Files.Add(file); - } - - - // 43341516 - } - - void file_DataRequest(object sender, DataRequestEventArgs e) - { - File file = (sender as File); - - AGGFileEntry entry = (AGGFileEntry)file.Properties["InternalData"]; - IO.BinaryReader br = (IO.BinaryReader)file.Properties["BinaryReader"]; - - br.BaseStream.Seek(entry.offset, System.IO.SeekOrigin.Begin); - e.Data = br.ReadBytes(entry.size); - - //.Initialize(UniversalEditor.Common.Hashing.CRC32.Keys.ReversedReciprocal); - uint hash = (uint)CRC32ChecksumModule.Calculate(e.Data); - - } - - protected override void SaveInternal(ObjectModel objectModel) - { - FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); - if (fsom == null) return; - - IO.BinaryWriter bw = base.Stream.BinaryWriter; - ushort fileCount = (ushort)fsom.Files.Count; - bw.Write(fileCount); - - uint offset = (uint)(bw.BaseStream.Position + (12 * fsom.Files.Count)); - foreach (File file in fsom.Files) - { - uint hash = 0; - uint size = (uint)file.Size; - - bw.Write(hash); - bw.Write(offset); - bw.Write(size); - - offset += size; - } - - for (ushort i = 0; i < fileCount; i++) - { - bw.Write(fsom.Files[i].GetDataAsByteArray()); - } - - foreach (File file in fsom.Files) - { - bw.WriteFixedLengthString(file.Name, 15); - } - } - } -} diff --git a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/Heroes3SNDDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/Heroes3SNDDataFormat.cs index b4ac5448..5e6f6fd4 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/Heroes3SNDDataFormat.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/Heroes3SNDDataFormat.cs @@ -25,19 +25,19 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); if (fsom == null) return; - IO.Reader br = base.Accessor.Reader; - uint fileCount = br.ReadUInt32(); + IO.Reader reader = base.Accessor.Reader; + uint fileCount = reader.ReadUInt32(); for (uint i = 0; i < fileCount; i++) { File file = new File(); - file.Name = String.Join(".", br.ReadFixedLengthString(12).Split(new char[] { '\0' })); + file.Name = String.Join(".", reader.ReadFixedLengthString(12).Split(new char[] { '\0' })); - byte[] unknown28 = br.ReadBytes(28); - uint offset = br.ReadUInt32(); - uint length = br.ReadUInt32(); - - offsets.Add(file, offset); - lengths.Add(file, length); + byte[] unknown28 = reader.ReadBytes(28); + uint offset = reader.ReadUInt32(); + uint length = reader.ReadUInt32(); + file.Properties.Add("offset", offset); + file.Properties.Add("length", length); + file.Properties.Add("reader", reader); file.DataRequest += new DataRequestEventHandler(file_DataRequest); file.Size = length; @@ -46,8 +46,6 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing } #region Data Request - private Dictionary offsets = new Dictionary(); - private Dictionary lengths = new Dictionary(); private void file_DataRequest(object sender, DataRequestEventArgs e) { string FileName = String.Empty; @@ -55,12 +53,13 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing { FileName = (Accessor as FileAccessor).FileName; } - - IO.Reader br = new IO.Reader(new FileAccessor(FileName)); - File send = (sender as File); - br.Accessor.Position = offsets[send]; - e.Data = br.ReadBytes(lengths[send]); - br.Close(); + + File file = (sender as File); + IO.Reader reader = (IO.Reader)file.Properties["reader"]; + uint offset = (uint)file.Properties["offset"]; + uint length = (uint)file.Properties["length"]; + reader.Seek(offset, IO.SeekOrigin.Begin); + e.Data = reader.ReadBytes(length); } #endregion diff --git a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/Heroes3VIDDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/Heroes3VIDDataFormat.cs index 69751ea9..38d80397 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/Heroes3VIDDataFormat.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/Heroes3VIDDataFormat.cs @@ -25,21 +25,21 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); if (fsom == null) return; - IO.Reader br = base.Accessor.Reader; - uint fileCount = br.ReadUInt32(); + IO.Reader reader = base.Accessor.Reader; + uint fileCount = reader.ReadUInt32(); uint offset = 0; for (uint i = 0; i < fileCount; i++) { File file = new File(); - file.Name = br.ReadNullTerminatedString(40); + file.Name = reader.ReadNullTerminatedString(40); - uint length = br.ReadUInt32(); - - offsets.Add(file, offset); - lengths.Add(file, length); + uint length = reader.ReadUInt32(); file.DataRequest += new DataRequestEventHandler(file_DataRequest); file.Size = length; + file.Properties.Add("offset", offset); + file.Properties.Add("length", length); + file.Properties.Add("reader", reader); fsom.Files.Add(file); offset += length; @@ -66,8 +66,6 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing } #region Data Request - private Dictionary offsets = new Dictionary(); - private Dictionary lengths = new Dictionary(); private void file_DataRequest(object sender, DataRequestEventArgs e) { string FileName = String.Empty; @@ -75,12 +73,13 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing { FileName = (Accessor as FileAccessor).FileName; } - - IO.Reader br = new IO.Reader(new FileAccessor(FileName)); - File send = (sender as File); - br.Accessor.Position = offsets[send]; - e.Data = br.ReadBytes(lengths[send]); - br.Close(); + + File file = (sender as File); + IO.Reader reader = (IO.Reader)file.Properties["reader"]; + uint offset = (uint)file.Properties["offset"]; + uint length = (uint)file.Properties["length"]; + reader.Seek(offset, IO.SeekOrigin.Begin); + e.Data = reader.ReadBytes(length); } #endregion } diff --git a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/LOD/Heroes3LODDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/LOD/Heroes3LODDataFormat.cs index c0085a4b..953ebd42 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/LOD/Heroes3LODDataFormat.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/LOD/Heroes3LODDataFormat.cs @@ -25,28 +25,29 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing.LOD FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); if (fsom == null) return; - IO.Reader br = base.Accessor.Reader; - string magic = br.ReadFixedLengthString(4); // LOD\0 + IO.Reader reader = base.Accessor.Reader; + string magic = reader.ReadFixedLengthString(4); // LOD\0 if (magic != "LOD\0") throw new InvalidDataFormatException("File does not begin with LOD\\0"); - uint unknown1 = br.ReadUInt32(); - uint fileCount = br.ReadUInt32(); + uint unknown1 = reader.ReadUInt32(); + uint fileCount = reader.ReadUInt32(); - byte[] unknown = br.ReadBytes(80); + byte[] unknown = reader.ReadBytes(80); for (int i = 0; i < fileCount; i++) { File f = new File(); - f.Name = br.ReadFixedLengthString(16); + f.Name = reader.ReadFixedLengthString(16); f.Name = f.Name.TrimNull(); - uint offset = br.ReadUInt32(); + uint offset = reader.ReadUInt32(); - uint u1 = br.ReadUInt32(); - uint u2 = br.ReadUInt32(); + uint u1 = reader.ReadUInt32(); + uint u2 = reader.ReadUInt32(); - uint length = br.ReadUInt32(); - offsets.Add(f, offset); - lengths.Add(f, length); + uint length = reader.ReadUInt32(); + f.Properties.Add("offset", offset); + f.Properties.Add("length", length); + f.Properties.Add("reader", reader); f.Size = length; f.DataRequest += new DataRequestEventHandler(f_DataRequest); @@ -55,8 +56,6 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing.LOD } #region Data Request - private Dictionary offsets = new Dictionary(); - private Dictionary lengths = new Dictionary(); private void f_DataRequest(object sender, DataRequestEventArgs e) { string FileName = String.Empty; @@ -64,15 +63,16 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing.LOD { FileName = (Accessor as FileAccessor).FileName; } - - IO.Reader br = new IO.Reader(new FileAccessor(FileName)); - File send = (sender as File); - br.Accessor.Position = offsets[send]; - byte[] compressedData = br.ReadBytes(lengths[send]); + + File file = (sender as File); + IO.Reader reader = (IO.Reader)file.Properties["reader"]; + uint offset = (uint)file.Properties["offset"]; + uint length = (uint)file.Properties["length"]; + reader.Seek(offset, IO.SeekOrigin.Begin); + byte[] compressedData = reader.ReadBytes(length); byte[] uncompressedData = UniversalEditor.Compression.CompressionModule.FromKnownCompressionMethod(Compression.CompressionMethod.Zlib).Decompress(compressedData); e.Data = uncompressedData; - br.Close(); } #endregion diff --git a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/LOD/Magic6LODDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/LOD/Magic6LODDataFormat.cs index 87fb0ea6..f5aae636 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/LOD/Magic6LODDataFormat.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/FileSystem/NewWorldComputing/LOD/Magic6LODDataFormat.cs @@ -17,46 +17,47 @@ namespace UniversalEditor.DataFormats.FileSystem.NewWorldComputing.LOD FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel); if (fsom == null) return; - IO.Reader br = base.Accessor.Reader; - string magic = br.ReadFixedLengthString(4); // LOD\0 + IO.Reader reader = base.Accessor.Reader; + string magic = reader.ReadFixedLengthString(4); // LOD\0 if (magic != "LOD\0") throw new InvalidDataFormatException("File does not begin with \"LOD\\0\""); - string gameID = br.ReadFixedLengthString(9); - byte[] unknown = br.ReadBytes(256 - 13); - string dir = br.ReadFixedLengthString(16); + string gameID = reader.ReadFixedLengthString(9); + byte[] unknown = reader.ReadBytes(256 - 13); + string dir = reader.ReadFixedLengthString(16); - uint dirstart = br.ReadUInt32(); - uint dirlength = br.ReadUInt32(); - uint unknown2 = br.ReadUInt32(); - uint fileCount = br.ReadUInt32(); + uint dirstart = reader.ReadUInt32(); + uint dirlength = reader.ReadUInt32(); + uint unknown2 = reader.ReadUInt32(); + uint fileCount = reader.ReadUInt32(); - br.Accessor.Position = dirstart; + reader.Accessor.Position = dirstart; for (uint i = 0; i < fileCount; i++) { File f = new File(); - f.Name = br.ReadFixedLengthString(16); + f.Name = reader.ReadFixedLengthString(16); - uint offset = br.ReadUInt32(); - uint length = br.ReadUInt32(); - offsets.Add(f, offset); - lengths.Add(f, length); + uint offset = reader.ReadUInt32(); + uint length = reader.ReadUInt32(); + f.Properties.Add("offset", offset); + f.Properties.Add("length", length); + f.Properties.Add("reader", reader); f.Size = length; f.DataRequest += new DataRequestEventHandler(f_DataRequest); - uint u1 = br.ReadUInt32(); - uint u2 = br.ReadUInt32(); + uint u1 = reader.ReadUInt32(); + uint u2 = reader.ReadUInt32(); } } #region Data Request - private Dictionary offsets = new Dictionary(); - private Dictionary lengths = new Dictionary(); private void f_DataRequest(object sender, DataRequestEventArgs e) { - IO.Reader br = base.Accessor.Reader; - File send = (sender as File); - br.Accessor.Position = offsets[send]; - e.Data = br.ReadBytes(lengths[send]); + File file = (sender as File); + IO.Reader reader = (IO.Reader)file.Properties["reader"]; + uint offset = (uint)file.Properties["offset"]; + uint length = (uint)file.Properties["length"]; + reader.Seek(offset, IO.SeekOrigin.Begin); + e.Data = reader.ReadBytes(length); } #endregion diff --git a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/UniversalEditor.Plugins.NewWorldComputing.csproj b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/UniversalEditor.Plugins.NewWorldComputing.csproj index 2cf82a98..2043a052 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/UniversalEditor.Plugins.NewWorldComputing.csproj +++ b/CSharp/Plugins/UniversalEditor.Plugins.NewWorldComputing/UniversalEditor.Plugins.NewWorldComputing.csproj @@ -38,8 +38,6 @@ - - @@ -54,7 +52,6 @@ - @@ -106,7 +103,9 @@ - + + +