Initial commit
This commit is contained in:
commit
0f86b0434b
38 changed files with 2370 additions and 0 deletions
68
LibDgf/Se/SeDatReader.cs
Normal file
68
LibDgf/Se/SeDatReader.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using LibDgf.Dat;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace LibDgf.Se
|
||||
{
|
||||
public class SeDatReader
|
||||
{
|
||||
DatReader dat;
|
||||
List<SeEntry> entries = new List<SeEntry>();
|
||||
byte[] seToc;
|
||||
byte[] seData;
|
||||
|
||||
public SeDatReader(DatReader dat)
|
||||
{
|
||||
this.dat = dat ?? throw new ArgumentNullException(nameof(dat));
|
||||
|
||||
seToc = dat.GetData(0);
|
||||
seData = dat.GetData(1);
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(seToc))
|
||||
{
|
||||
BinaryReader br = new BinaryReader(ms);
|
||||
while (true)
|
||||
{
|
||||
SeEntry entry = new SeEntry();
|
||||
entry.Read(br);
|
||||
if (entry.DataOffset == -1 && entry.DataLength == -1)
|
||||
break;
|
||||
entries.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int EntriesCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return entries.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] GetData(int index)
|
||||
{
|
||||
if (index < 0) throw new ArgumentOutOfRangeException(nameof(index), "Index cannot be negative.");
|
||||
if (index >= EntriesCount) throw new ArgumentOutOfRangeException(nameof(index), "Index cannot be greater than or equal to count.");
|
||||
|
||||
var entry = entries[index];
|
||||
byte[] data = new byte[entry.DataLength];
|
||||
Buffer.BlockCopy(seData, (int)entry.DataOffset, data, 0, data.Length);
|
||||
return data;
|
||||
}
|
||||
|
||||
public string GetDataAsString(int index)
|
||||
{
|
||||
var data = GetData(index);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte b in data)
|
||||
{
|
||||
if (b == 0) break;
|
||||
sb.Append((char)b);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
31
LibDgf/Se/SeEntry.cs
Normal file
31
LibDgf/Se/SeEntry.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace LibDgf.Se
|
||||
{
|
||||
public class SeEntry
|
||||
{
|
||||
public int DataOffset { get; set; }
|
||||
public int DataLength { get; set; }
|
||||
public uint SeLength { get; set; }
|
||||
public uint Unknown { get; set; }
|
||||
|
||||
public void Read(BinaryReader br)
|
||||
{
|
||||
DataOffset = br.ReadInt32();
|
||||
DataLength = br.ReadInt32();
|
||||
SeLength = br.ReadUInt32();
|
||||
Unknown = br.ReadUInt32();
|
||||
}
|
||||
|
||||
public void Write(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(DataOffset);
|
||||
bw.Write(DataLength);
|
||||
bw.Write(SeLength);
|
||||
bw.Write(Unknown);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue