-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathYSCM.cs
More file actions
132 lines (104 loc) · 3.33 KB
/
Copy pathYSCM.cs
File metadata and controls
132 lines (104 loc) · 3.33 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
#pragma warning disable IDE0017
#pragma warning disable IDE0063
namespace YuRis_Tool
{
class YSCM
{
public enum ExprEvalResult : byte
{
Integer,
String,
Decimal,
Raw
}
public enum ResultValidateMode : byte
{
ValidateMinimum,
}
public class ExpressionInfo
{
public string Keyword;
public ExprEvalResult ResultType;
public ResultValidateMode ValidateMode;
public override string ToString()
{
return $"Arg({Keyword}), Type:({ResultType})";
}
}
public ExpressionInfo GetExprInfo(int commandId, int exprId)
{
var cmd = _commandsInfo[commandId];
if (cmd.ArgExprs.Count <= exprId)
{
return null;
}
return cmd.ArgExprs[exprId];
}
public class CommandInfo
{
public string Name;
public List<ExpressionInfo> ArgExprs;
public override string ToString()
{
return $"Cmd({Name}), ArgExprs:({ArgExprs.Count})";
}
}
List<CommandInfo> _commandsInfo;
List<string> _errorMessage;
byte[] _unknowBlock;
public IReadOnlyList<CommandInfo> CommandsInfo
{
get => _commandsInfo;
}
public void Load(string filePath)
{
using (var stream = File.OpenRead(filePath))
using (var reader = new BinaryReader(stream))
{
Read(reader);
}
CommandIDGenerator.GenerateType(this);
}
void Read(BinaryReader reader)
{
var magic = reader.ReadInt32();
if (magic != 0x4D435359)
{
throw new Exception("Not a valid YSCM file.");
}
reader.ReadInt32(); // version
var count = reader.ReadInt32();
reader.ReadInt32(); // zero
_commandsInfo = new List<CommandInfo>(count);
for (var i = 0; i < count; i++)
{
var cmd = new CommandInfo();
cmd.Name = reader.ReadAnsiString();
//Debug.WriteLine($"{i:X2} {cmd.Name}");
var actionCount = reader.ReadByte();
cmd.ArgExprs = new List<ExpressionInfo>(actionCount);
for (var j = 0; j < actionCount; j++)
{
var act = new ExpressionInfo();
act.Keyword = reader.ReadAnsiString();
act.ResultType = (ExprEvalResult)reader.ReadByte();
act.ValidateMode = (ResultValidateMode)reader.ReadByte();
cmd.ArgExprs.Add(act);
}
_commandsInfo.Add(cmd);
}
_errorMessage = new List<string>(37);
for (var i = 0; i < 37; i++)
{
var s = reader.ReadAnsiString();
_errorMessage.Add(s);
}
_unknowBlock = reader.ReadBytes(256);
Debug.Assert(reader.BaseStream.Position == reader.BaseStream.Length);
}
}
}