Skip to content

Commit

Permalink
Move all archive implementations to shared
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jan 25, 2025
1 parent 94b115a commit 9071a5e
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 801 deletions.
59 changes: 52 additions & 7 deletions Yura.Shared/Archive/DefianceArchive.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Yura.Shared.IO;

namespace Yura.Shared.Archive
{
Expand All @@ -14,12 +11,60 @@ public DefianceArchive(ArchiveOptions options) : base(options)

public override void Open()
{
throw new NotImplementedException();
var stream = File.OpenRead(Options.Path);
var reader = new DataReader(stream, Options.Endianness);

// Read the number of files
var numFiles = reader.ReadUInt16();

stream.Position += 2;

// Read the file name hashes
var hashes = new uint[numFiles];

for (var i = 0; i < numFiles; i++)
{
hashes[i] = reader.ReadUInt32();
}

// Read the file records
for (var i = 0; i < numFiles; i++)
{
var record = new Record
{
Hash = hashes[i],

Size = reader.ReadUInt32(),
Offset = reader.ReadUInt32()
};

reader.Position += 4;

Records.Add(record);
}

stream.Close();
}

public override byte[] Read(ArchiveRecord record)
{
throw new NotImplementedException();
var file = record as Record;

// Read the file
var stream = File.OpenRead(Options.Path);
var data = new byte[file.Size];

Check warning on line 55 in Yura.Shared/Archive/DefianceArchive.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

stream.Position = file.Offset;
stream.ReadExactly(data);

stream.Close();

return data;
}

private class Record : ArchiveRecord
{
public uint Offset { get; set; }
}
}
}
76 changes: 70 additions & 6 deletions Yura.Shared/Archive/DeusExArchive.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Yura.Shared.IO;

namespace Yura.Shared.Archive
{
public class DeusExArchive : ArchiveFile
{
private uint _alignment;

public DeusExArchive(ArchiveOptions options) : base(options)
{
}

public override void Open()
{
throw new NotImplementedException();
var stream = File.OpenRead(Options.Path);
var reader = new DataReader(stream, Options.Endianness);

// Read the header
_alignment = reader.ReadUInt32();

// Skip over the config name
reader.Position += 64;

// Read the number of files
var numRecords = reader.ReadUInt32();

if (numRecords > 1_000_000)
{
throw new ArgumentException("Bigfile has more than a million files, did you select the right endianness?");
}

// Read the file name hashes
var hashes = new uint[numRecords];

for (var i = 0; i < numRecords; i++)
{
hashes[i] = reader.ReadUInt32();
}

// Read the file records
for (var i = 0; i < numRecords; i++)
{
var record = new Record
{
Hash = hashes[i],

Size = reader.ReadUInt32(),
Offset = reader.ReadUInt32(),
Specialisation = reader.ReadUInt32(),
CompressedSize = reader.ReadUInt32(),
};

Records.Add(record);
}

stream.Close();
}

public override byte[] Read(ArchiveRecord record)
{
throw new NotImplementedException();
var file = record as Record;

// Calculate the location of the file
var offset = (long)file.Offset << 11;

Check warning on line 66 in Yura.Shared/Archive/DeusExArchive.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
var part = offset / _alignment;

var path = GetFilePart((int)part);

// Read the file
var stream = File.OpenRead(path);
var data = new byte[file.Size];

stream.Position = offset % _alignment;
stream.ReadExactly(data);

stream.Close();

return data;
}

private class Record : ArchiveRecord
{
public uint Offset { get; set; }
public uint CompressedSize { get; set; }
}
}
}
6 changes: 1 addition & 5 deletions Yura.Shared/Archive/LegendArchive.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yura.Shared.IO;

namespace Yura.Shared.Archive
Expand All @@ -27,7 +23,7 @@ public override void Open()
throw new ArgumentException("Bigfile has more than a million files, did you select the right endianness?");
}

// Read the file hashes
// Read the file name hashes
var hashes = new uint[numRecords];

for (var i = 0; i < numRecords; i++)
Expand Down
3 changes: 2 additions & 1 deletion Yura.Shared/Archive/TigerArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public override void Open()
var numArchives = reader.ReadUInt32();
var numRecords = reader.ReadUInt32();

reader.Position += 4;
// Skip 4 bytes, or 8 in version 5 or later
reader.Position += version < 5 ? 4 : 8;

// Skip over the config name
reader.Position += 32;
Expand Down
2 changes: 1 addition & 1 deletion Yura/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public App()
// add information about open bigfile
if (_window != null && _window.Bigfile != null)
{
sentryEvent.SetExtra("bigfile", _window.Bigfile.Filename);
sentryEvent.SetExtra("bigfile", _window.Bigfile.Name);
sentryEvent.SetExtra("game", _window.Game);
}

Expand Down
94 changes: 0 additions & 94 deletions Yura/Archive/ArchiveFile.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Yura/Archive/ArchiveRecord.cs

This file was deleted.

Loading

0 comments on commit 9071a5e

Please sign in to comment.