-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dat.cs
76 lines (52 loc) · 1.71 KB
/
Dat.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace Nitemare3D
{
public sealed class Dat
{
public const string UifDir = "data/UIF.DAT";
public const string SndDir = "data/SND.DAT";
public static List<byte[]> Snd = new List<byte[]>();
public static List<byte[]> Uif = new List<byte[]>();
public static byte[] Pal = new byte[768];
static List<byte[]> LoadDat(string file)
{
List<UInt32> offsets = new List<UInt32>();
List<UInt16> lengths = new List<UInt16>();
List<byte[]> output = new List<byte[]>();
using (var reader = new BinaryReader(File.OpenRead(file), Encoding.Default, true))
{
while (true)
{
var length = reader.ReadUInt16();
var offset = reader.ReadUInt32();
offsets.Add(offset);
lengths.Add(length);
if (offset + length == reader.BaseStream.Length)
break;
}
for (int i = 0; i < offsets.Count; i++)
{
var offset = offsets[i];
var length = lengths[i];
reader.BaseStream.Position = offset;
output.Add(reader.ReadBytes(length));
}
}
return output;
}
public static void Unload()
{
Uif.Clear();
Snd.Clear();
GC.Collect();
}
public static void Load()
{
Uif = LoadDat(UifDir);
Snd = LoadDat(SndDir);
}
}
}