Fixed issues with outdated file referencing conventions
This commit is contained in:
parent
ce8b297f53
commit
5450f082c1
@ -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
|
||||
{
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<File, uint> offsets = new Dictionary<File, uint>();
|
||||
private Dictionary<File, uint> lengths = new Dictionary<File, uint>();
|
||||
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
|
||||
|
||||
|
||||
@ -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<File, uint> offsets = new Dictionary<File, uint>();
|
||||
private Dictionary<File, uint> lengths = new Dictionary<File, uint>();
|
||||
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
|
||||
}
|
||||
|
||||
@ -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<File, uint> offsets = new Dictionary<File, uint>();
|
||||
private Dictionary<File, uint> lengths = new Dictionary<File, uint>();
|
||||
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
|
||||
|
||||
|
||||
@ -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<File, uint> offsets = new Dictionary<File, uint>();
|
||||
private Dictionary<File, uint> lengths = new Dictionary<File, uint>();
|
||||
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
|
||||
|
||||
|
||||
@ -38,8 +38,6 @@
|
||||
<Compile Include="DataFormats\FileSystem\NewWorldComputing\AGG\AGGDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Multimedia\Palette\NewWorldComputing\KBPaletteDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Multimedia\Picture\NewWorldComputing\ICN\ICNDataFormat.cs" />
|
||||
<Compile Include="DataFormats\NWCSceneLayout\NewWorldComputing\BIN\BINContainerType.cs" />
|
||||
<Compile Include="DataFormats\NWCSceneLayout\NewWorldComputing\BIN\BINDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Multimedia\Picture\NewWorldComputing\BMP\BMPDataFormat.cs" />
|
||||
<Compile Include="DataFormats\NewWorldComputing\CC\CCDataFormat.cs" />
|
||||
<Compile Include="DataFormats\NewWorldComputing\CC\Internal\FileInfo.cs" />
|
||||
@ -54,7 +52,6 @@
|
||||
<Compile Include="DataFormats\NewWorldComputing\Save\Heroes4SaveDataFormat.cs" />
|
||||
<Compile Include="DataFormats\FileSystem\NewWorldComputing\Heroes3SNDDataFormat.cs" />
|
||||
<Compile Include="DataFormats\FileSystem\NewWorldComputing\Heroes3VIDDataFormat.cs" />
|
||||
<Compile Include="DataFormats\NWCSceneLayout\NewWorldComputing\BIN\BINObjectType.cs" />
|
||||
<Compile Include="HoMM2Palette.cs" />
|
||||
<Compile Include="ObjectModels\NWCSceneLayout\NWCSceneLayoutObjectModel.cs" />
|
||||
<Compile Include="ObjectModels\NewWorldComputing\Campaign\CampaignObjectModel.cs" />
|
||||
@ -106,7 +103,9 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="ObjectModels\NewWorldComputing\Map\MapLoseCondition.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="DataFormats\NWCSceneLayout\NewWorldComputing\BIN\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user