-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathYSLB.cs
More file actions
88 lines (72 loc) · 2.35 KB
/
Copy pathYSLB.cs
File metadata and controls
88 lines (72 loc) · 2.35 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
#pragma warning disable IDE0017
#pragma warning disable IDE0063
namespace YuRis_Tool
{
class YSLB
{
public class Label
{
public string Name { get; set; }
public uint NameHash { get; set; }
public uint CommandIndex { get; set; }
public uint ScriptId { get; set; }
public byte Unk2 { get; set; }
public byte Unk3 { get; set; }
}
List<Label> _labels;
public void Load(string filePath)
{
using (var stream = File.OpenRead(filePath))
using (var reader = new BinaryReader(stream))
{
Read(reader);
}
}
public void Dump(string filePath)
{
using var textWriter = File.CreateText(filePath);
using var csvWriter = new CsvHelper.CsvWriter(textWriter, CultureInfo.InvariantCulture);
csvWriter.WriteRecords(_labels);
csvWriter.Flush();
}
void Read(BinaryReader reader)
{
var magic = reader.ReadInt32();
if (magic != 0x424C5359)
{
throw new Exception("Not a valid YSTB file.");
}
reader.ReadInt32(); // version
var count = reader.ReadInt32();
for (var i = 0; i < 256; i++)
{
reader.ReadInt32();
}
_labels = new List<Label>(count);
for (var i = 0; i < count; i++)
{
var lab = new Label();
lab.Name = reader.ReadAnsiString(reader.ReadByte());
lab.NameHash = reader.ReadUInt32();
lab.CommandIndex = reader.ReadUInt32();
lab.ScriptId = reader.ReadUInt16();
lab.Unk2 = reader.ReadByte();
lab.Unk3 = reader.ReadByte();
_labels.Add(lab);
}
Debug.Assert(reader.BaseStream.Position == reader.BaseStream.Length);
}
public List<Label> Find(int scriptId, int commandIndex)
{
return _labels.Where(
a => (a.ScriptId == scriptId) && (a.CommandIndex == commandIndex)
).ToList();
}
}
}