Skip to content

Commit 316770f

Browse files
committed
Restore support for all platforms
1 parent 80be47c commit 316770f

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

Yura.Shared/Archive/ArchiveFile.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ protected string GetFilePart(int part, string extension = "")
6868
return Path.Combine(directory, name + "." + part.ToString("000") + extension);
6969
}
7070

71+
/// <summary>
72+
/// From an offset and the alignment get the physical file and offset
73+
/// </summary>
74+
/// <param name="offset">The offset of the file</param>
75+
/// <returns>The file and offset</returns>
76+
protected (string, long) GetFileAndOffset(long offset)
77+
{
78+
// Check whether the archive is split over multiple files
79+
if (Path.GetExtension(Name) == ".000")
80+
{
81+
var part = offset / Options.Alignment;
82+
var path = GetFilePart((int)part);
83+
84+
return (path, offset % Options.Alignment);
85+
}
86+
87+
return (Name, offset);
88+
}
89+
7190
private static string[] Split(string path)
7291
{
7392
return path.Split('\\', StringSplitOptions.RemoveEmptyEntries);

Yura.Shared/Archive/DefianceArchive.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ public override byte[] Read(ArchiveRecord record)
5050
{
5151
var file = record as Record;
5252

53+
var (path, offset) = GetFileAndOffset(file.Offset);
54+
5355
// Read the file
54-
var stream = File.OpenRead(Options.Path);
56+
var stream = File.OpenRead(path);
5557
var data = new byte[file.Size];
5658

57-
stream.Position = file.Offset;
59+
stream.Position = offset;
5860
stream.ReadExactly(data);
5961

6062
stream.Close();

Yura.Shared/Archive/LegendArchive.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.IO.Compression;
34
using Yura.Shared.IO;
45

56
namespace Yura.Shared.Archive
@@ -54,24 +55,44 @@ public override byte[] Read(ArchiveRecord record)
5455
{
5556
var file = record as Record;
5657

57-
// Calculate the location of the file
58-
var offset = (long)file.Offset << 11;
59-
var part = offset / Options.Alignment;
58+
// Convert sectors to file position
59+
var position = (long)file.Offset << 11;
6060

61-
var path = GetFilePart((int)part);
61+
var (path, offset) = GetFileAndOffset(position);
6262

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

67-
stream.Position = offset % Options.Alignment;
68-
stream.ReadExactly(data);
67+
if (file.CompressedSize == 0)
68+
{
69+
stream.Position = offset;
70+
stream.ReadExactly(data);
71+
}
72+
else
73+
{
74+
ReadCompressed(stream, offset, file.CompressedSize, data);
75+
}
6976

7077
stream.Close();
7178

7279
return data;
7380
}
7481

82+
private static void ReadCompressed(Stream stream, long offset, uint size, Span<byte> buffer)
83+
{
84+
// Read the compressed data
85+
var data = new byte[size];
86+
87+
stream.Position = offset;
88+
stream.ReadExactly(data);
89+
90+
// Decompress the data
91+
var zlib = new ZLibStream(new MemoryStream(data), CompressionMode.Decompress);
92+
93+
zlib.ReadExactly(buffer);
94+
}
95+
7596
private class Record : ArchiveRecord
7697
{
7798
public uint Offset { get; set; }

Yura/OpenDialog.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<ComboBox Name="AlignmentField" Grid.Column="1" Grid.Row="4">
7070
<ComboBoxItem IsSelected="True">0x9600000</ComboBoxItem>
7171
<ComboBoxItem>0x7FF00000</ComboBoxItem>
72+
<ComboBoxItem>0xFA00000</ComboBoxItem>
7273
</ComboBox>
7374
<Image Source="Images/StatusInformation.png" Grid.Column="2" Grid.Row="4" Margin="5 0 0 0"
7475
ToolTip="The alignment of the bigfile, this is needed to calculate the right file offset.

Yura/OpenDialog.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class FileListItem
9797

9898
private void GameSelect_SelectionChanged(object sender, SelectionChangedEventArgs e)
9999
{
100-
AlignmentField.IsEnabled = GameSelect.SelectedIndex == (int)Game.Legend;
100+
AlignmentField.IsEnabled = GameSelect.SelectedIndex <= (int)Game.Legend;
101101
}
102102
}
103103

0 commit comments

Comments
 (0)