Skip to content

Commit

Permalink
Add Xbox support for Legacy of Kain Defiance
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jul 19, 2023
1 parent 54692e7 commit 2e60d87
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
24 changes: 21 additions & 3 deletions Yura/Archive/DefianceArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ namespace Yura.Archive
{
class DefianceArchive : ArchiveFile
{
private const int XboxAlignment = 0xFA00000;

private string _file;
private TextureFormat _platform;
private bool _littleEndian;

private List<DefianceRecord> _files;

public DefianceArchive(string path, bool littleEndian = true)
public DefianceArchive(string path, TextureFormat platform, bool littleEndian = true)
: base(path)
{
_file = path;
_platform = platform;
_littleEndian = littleEndian;

_files = new List<DefianceRecord>();
Expand Down Expand Up @@ -74,10 +78,24 @@ public override byte[] Read(ArchiveRecord record)
{
var file = record as DefianceRecord;

var stream = File.OpenRead(_file);
var filename = _file;
var offset = file.Offset;

if (_platform == TextureFormat.Xbox)
{
// xbox bigfiles in this game are spread over multiple physical files
// calculate the bigfile this file is in
var bigfile = offset / XboxAlignment;
offset = offset % XboxAlignment;

var name = Path.GetFileNameWithoutExtension(_file);
filename = Path.GetDirectoryName(_file) + Path.DirectorySeparatorChar + name + "." + bigfile.ToString("000");
}

var stream = File.OpenRead(filename);
var bytes = new byte[file.Size];

stream.Position = file.Offset;
stream.Position = offset;
stream.Read(bytes, 0, (int)file.Size);

stream.Close();
Expand Down
2 changes: 1 addition & 1 deletion Yura/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void OpenBigfile(string bigfile, IFileSettings settings)
_bigfile = new DeusExArchive(bigfile, _littleEndian);
break;
case Game.Defiance:
_bigfile = new DefianceArchive(bigfile, _littleEndian);
_bigfile = new DefianceArchive(bigfile, settings.TextureFormat, _littleEndian);
break;
case Game.Tiger:
_bigfile = new TigerArchive(bigfile, _littleEndian);
Expand Down
4 changes: 3 additions & 1 deletion Yura/OpenDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
<Label Grid.Column="0" Grid.Row="3">Platform</Label>
<ComboBox Name="TextureFormatSelect" Grid.Column="1" Grid.Row="3">
<ComboBoxItem IsSelected="True">PC</ComboBoxItem>
<ComboBoxItem>Wii</ComboBoxItem>
<ComboBoxItem>PS2</ComboBoxItem>
<ComboBoxItem>PS3</ComboBoxItem>
<ComboBoxItem>Xbox</ComboBoxItem>
<ComboBoxItem>Wii</ComboBoxItem>
</ComboBox>

<Label Grid.Column="0" Grid.Row="4">Alignment</Label>
Expand Down
8 changes: 5 additions & 3 deletions Yura/OpenDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@ public class FileListItem

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

public enum TextureFormat
{
Pc,
Wii,
Ps3
Ps2,
Ps3,
Xbox,
Wii
}

public enum Game
Expand Down
24 changes: 13 additions & 11 deletions Yura/TextureViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ private void CreateImage(int width, int height, StreamReader reader)
var textureData = new byte[width + height * stride];
reader.BaseStream.Read(textureData);

BitmapSource image = null;
BitmapSource image;

if (TextureFormat == TextureFormat.Pc)
switch (TextureFormat)
{
image = BitmapSource.Create(width, height, 96, 96, PixelFormats.Bgra32, null, textureData, stride);
}
else if (TextureFormat == TextureFormat.Wii)
{
image = new CMPRTexture(width, height, textureData);
}
else if (TextureFormat == TextureFormat.Ps3)
{
image = new PS3Texture(width, height, textureData);
case TextureFormat.Wii:
image = new CMPRTexture(width, height, textureData);
break;

case TextureFormat.Ps3:
image = new CMPRTexture(width, height, textureData);
break;

default:
image = BitmapSource.Create(width, height, 96, 96, PixelFormats.Bgra32, null, textureData, stride);
break;
}

TextureImage.Source = image;
Expand Down
2 changes: 1 addition & 1 deletion Yura/Yura.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Yura.ico</ApplicationIcon>
<Version>1.4</Version>
<Version>1.5</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 2e60d87

Please sign in to comment.