Skip to content

Commit

Permalink
Restore support for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jan 25, 2025
1 parent 80be47c commit 316770f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
19 changes: 19 additions & 0 deletions Yura.Shared/Archive/ArchiveFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ protected string GetFilePart(int part, string extension = "")
return Path.Combine(directory, name + "." + part.ToString("000") + extension);

Check warning on line 68 in Yura.Shared/Archive/ArchiveFile.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'path1' in 'string Path.Combine(string path1, string path2)'.

Check warning on line 68 in Yura.Shared/Archive/ArchiveFile.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'path1' in 'string Path.Combine(string path1, string path2)'.
}

/// <summary>
/// From an offset and the alignment get the physical file and offset
/// </summary>
/// <param name="offset">The offset of the file</param>
/// <returns>The file and offset</returns>
protected (string, long) GetFileAndOffset(long offset)
{
// Check whether the archive is split over multiple files
if (Path.GetExtension(Name) == ".000")
{
var part = offset / Options.Alignment;
var path = GetFilePart((int)part);

return (path, offset % Options.Alignment);
}

return (Name, offset);
}

private static string[] Split(string path)
{
return path.Split('\\', StringSplitOptions.RemoveEmptyEntries);
Expand Down
6 changes: 4 additions & 2 deletions Yura.Shared/Archive/DefianceArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ public override byte[] Read(ArchiveRecord record)
{
var file = record as Record;

var (path, offset) = GetFileAndOffset(file.Offset);

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

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

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

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

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

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

stream.Close();
Expand Down
33 changes: 27 additions & 6 deletions Yura.Shared/Archive/LegendArchive.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.IO.Compression;
using Yura.Shared.IO;

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

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

Check warning on line 59 in Yura.Shared/Archive/LegendArchive.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 59 in Yura.Shared/Archive/LegendArchive.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

var path = GetFilePart((int)part);
var (path, offset) = GetFileAndOffset(position);

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

stream.Position = offset % Options.Alignment;
stream.ReadExactly(data);
if (file.CompressedSize == 0)
{
stream.Position = offset;
stream.ReadExactly(data);
}
else
{
ReadCompressed(stream, offset, file.CompressedSize, data);
}

stream.Close();

return data;
}

private static void ReadCompressed(Stream stream, long offset, uint size, Span<byte> buffer)
{
// Read the compressed data
var data = new byte[size];

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

// Decompress the data
var zlib = new ZLibStream(new MemoryStream(data), CompressionMode.Decompress);

zlib.ReadExactly(buffer);
}

private class Record : ArchiveRecord
{
public uint Offset { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Yura/OpenDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<ComboBox Name="AlignmentField" Grid.Column="1" Grid.Row="4">
<ComboBoxItem IsSelected="True">0x9600000</ComboBoxItem>
<ComboBoxItem>0x7FF00000</ComboBoxItem>
<ComboBoxItem>0xFA00000</ComboBoxItem>
</ComboBox>
<Image Source="Images/StatusInformation.png" Grid.Column="2" Grid.Row="4" Margin="5 0 0 0"
ToolTip="The alignment of the bigfile, this is needed to calculate the right file offset.
Expand Down
2 changes: 1 addition & 1 deletion Yura/OpenDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class FileListItem

private void GameSelect_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
AlignmentField.IsEnabled = GameSelect.SelectedIndex == (int)Game.Legend;
AlignmentField.IsEnabled = GameSelect.SelectedIndex <= (int)Game.Legend;
}
}

Expand Down

0 comments on commit 316770f

Please sign in to comment.