Skip to content

Commit 9071a5e

Browse files
committed
Move all archive implementations to shared
1 parent 94b115a commit 9071a5e

File tree

12 files changed

+126
-801
lines changed

12 files changed

+126
-801
lines changed
Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.IO;
2+
using Yura.Shared.IO;
63

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

1512
public override void Open()
1613
{
17-
throw new NotImplementedException();
14+
var stream = File.OpenRead(Options.Path);
15+
var reader = new DataReader(stream, Options.Endianness);
16+
17+
// Read the number of files
18+
var numFiles = reader.ReadUInt16();
19+
20+
stream.Position += 2;
21+
22+
// Read the file name hashes
23+
var hashes = new uint[numFiles];
24+
25+
for (var i = 0; i < numFiles; i++)
26+
{
27+
hashes[i] = reader.ReadUInt32();
28+
}
29+
30+
// Read the file records
31+
for (var i = 0; i < numFiles; i++)
32+
{
33+
var record = new Record
34+
{
35+
Hash = hashes[i],
36+
37+
Size = reader.ReadUInt32(),
38+
Offset = reader.ReadUInt32()
39+
};
40+
41+
reader.Position += 4;
42+
43+
Records.Add(record);
44+
}
45+
46+
stream.Close();
1847
}
1948

2049
public override byte[] Read(ArchiveRecord record)
2150
{
22-
throw new NotImplementedException();
51+
var file = record as Record;
52+
53+
// Read the file
54+
var stream = File.OpenRead(Options.Path);
55+
var data = new byte[file.Size];
56+
57+
stream.Position = file.Offset;
58+
stream.ReadExactly(data);
59+
60+
stream.Close();
61+
62+
return data;
63+
}
64+
65+
private class Record : ArchiveRecord
66+
{
67+
public uint Offset { get; set; }
2368
}
2469
}
2570
}
Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,89 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
2+
using System.IO;
3+
using Yura.Shared.IO;
64

75
namespace Yura.Shared.Archive
86
{
97
public class DeusExArchive : ArchiveFile
108
{
9+
private uint _alignment;
10+
1111
public DeusExArchive(ArchiveOptions options) : base(options)
1212
{
1313
}
1414

1515
public override void Open()
1616
{
17-
throw new NotImplementedException();
17+
var stream = File.OpenRead(Options.Path);
18+
var reader = new DataReader(stream, Options.Endianness);
19+
20+
// Read the header
21+
_alignment = reader.ReadUInt32();
22+
23+
// Skip over the config name
24+
reader.Position += 64;
25+
26+
// Read the number of files
27+
var numRecords = reader.ReadUInt32();
28+
29+
if (numRecords > 1_000_000)
30+
{
31+
throw new ArgumentException("Bigfile has more than a million files, did you select the right endianness?");
32+
}
33+
34+
// Read the file name hashes
35+
var hashes = new uint[numRecords];
36+
37+
for (var i = 0; i < numRecords; i++)
38+
{
39+
hashes[i] = reader.ReadUInt32();
40+
}
41+
42+
// Read the file records
43+
for (var i = 0; i < numRecords; i++)
44+
{
45+
var record = new Record
46+
{
47+
Hash = hashes[i],
48+
49+
Size = reader.ReadUInt32(),
50+
Offset = reader.ReadUInt32(),
51+
Specialisation = reader.ReadUInt32(),
52+
CompressedSize = reader.ReadUInt32(),
53+
};
54+
55+
Records.Add(record);
56+
}
57+
58+
stream.Close();
1859
}
1960

2061
public override byte[] Read(ArchiveRecord record)
2162
{
22-
throw new NotImplementedException();
63+
var file = record as Record;
64+
65+
// Calculate the location of the file
66+
var offset = (long)file.Offset << 11;
67+
var part = offset / _alignment;
68+
69+
var path = GetFilePart((int)part);
70+
71+
// Read the file
72+
var stream = File.OpenRead(path);
73+
var data = new byte[file.Size];
74+
75+
stream.Position = offset % _alignment;
76+
stream.ReadExactly(data);
77+
78+
stream.Close();
79+
80+
return data;
81+
}
82+
83+
private class Record : ArchiveRecord
84+
{
85+
public uint Offset { get; set; }
86+
public uint CompressedSize { get; set; }
2387
}
2488
}
2589
}

Yura.Shared/Archive/LegendArchive.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.IO;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
73
using Yura.Shared.IO;
84

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

30-
// Read the file hashes
26+
// Read the file name hashes
3127
var hashes = new uint[numRecords];
3228

3329
for (var i = 0; i < numRecords; i++)

Yura.Shared/Archive/TigerArchive.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public override void Open()
3838
var numArchives = reader.ReadUInt32();
3939
var numRecords = reader.ReadUInt32();
4040

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

4344
// Skip over the config name
4445
reader.Position += 32;

Yura/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public App()
2929
// add information about open bigfile
3030
if (_window != null && _window.Bigfile != null)
3131
{
32-
sentryEvent.SetExtra("bigfile", _window.Bigfile.Filename);
32+
sentryEvent.SetExtra("bigfile", _window.Bigfile.Name);
3333
sentryEvent.SetExtra("game", _window.Game);
3434
}
3535

Yura/Archive/ArchiveFile.cs

Lines changed: 0 additions & 94 deletions
This file was deleted.

Yura/Archive/ArchiveRecord.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)