This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathESD.bt
203 lines (180 loc) · 6.76 KB
/
ESD.bt
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//------------------------------------------------
//--- 010 Editor v7.0.2 Binary Template
//
// File: ESD.bt
// Authors: TKGP
// Version: 1.03
// Purpose: EzState
// Category: Dark Souls
// File Mask: *.esd
// ID Bytes: 66 [+1] 53 4C 01 00 00 00 [+8] 54 00 00 00
// History:
//------------------------------------------------
local int VARINT_LONG = 0;
#include "Util.bt"
LittleEndian();
struct Header {
char magic[4]; Assert(magic == "fSSL" || magic == "fsSL");
VARINT_LONG = magic == "fsSL";
int unk04; Assert(unk04 == 1);
int numberOfDarkSoulses1;
Assert(numberOfDarkSoulses1 == 1 || numberOfDarkSoulses1 == 2 || numberOfDarkSoulses1 == 3);
int numberOfDarkSoulses2;
Assert(numberOfDarkSoulses2 == numberOfDarkSoulses1);
int unk10 <format=hex>; Assert(unk10 == 0x54);
int dataSize;
int blockCount; Assert(blockCount == 6);
int dataHeaderSize <format=hex>; Assert(dataHeaderSize == (VARINT_LONG ? 0x48 : 0x2C));
int dataHeaderCount; Assert(dataHeaderCount == 1);
int stateGroupSize <format=hex>; Assert(stateGroupSize == (VARINT_LONG ? 0x20 : 0x10));
int stateGroupCount;
int stateSize <format=hex>; Assert(stateSize == (VARINT_LONG ? 0x48 : 0x24));
int stateCount;
int conditionSize <format=hex>; Assert(conditionSize == (VARINT_LONG ? 0x38 : 0x1C));
int conditionCount;
int commandCallSize <format=hex>; Assert(commandCallSize == (VARINT_LONG ? 0x18 : 0x10));
int commandCallCount;
int commandArgSize <format=hex>; Assert(commandArgSize == (VARINT_LONG ? 0x10 : 0x8));
int commandArgCount;
int conditionOffsetsOffset <format=hex>;
int conditionOffsetCount;
// Please note that this is not actually the name offset, it's the end of the
// bytecode block, which may be off by a byte due to padding for UTF-16
int nameBlockOffset <format=hex>;
int nameLength;
// These are never used
int unkDataOffset2 <format=hex>;
int unkDataCount2; Assert(unkDataCount2 == 0);
int unkDataOffset3 <format=hex>;
int unkDataCount3; Assert(unkDataCount3 == 0);
} header <bgcolor=cRed>;
// 0x6C
local quad dataStart = FTell();
struct DataHeader {
int unk6C; Assert(unk6C == 1);
int unk70[4] <format=hex, bgcolor=cBlack, fgcolor=cWhite>;
if (VARINT_LONG) {
int unk80; Assert(unk80 == 0);
}
Varint dataHeaderSize; Assert(dataHeaderSize.val == (VARINT_LONG ? 0x48 : 0x2C));
Varint stateGroupCount; Assert(stateGroupCount.val == header.stateGroupCount);
Varint nameOffset;
Varint nameLength;
Varint unkNull1; Assert(unkNull1.val == 0 || unkNull1.val == -1);
Varint unkNull2; Assert(unkNull2.val == unkNull1.val);
if (nameLength.val > 0) {
local quad pos = FTell();
FSeek(0x6C + nameOffset.val);
wchar_t name[nameLength.val];
FSeek(pos);
}
} dataHeader <bgcolor=cLtRed>;
struct CommandArg {
// Bytecode expression returning a value
Varint dataOffset;
Varint dataSize;
if (dataSize.val > 0) {
local quad pos = FTell();
FSeek(dataStart + dataOffset.val);
byte data[dataSize.val] <format=hex, bgcolor=cBlack, fgcolor=cWhite>;
FSeek(pos);
}
};
struct CommandCall {
// Only 1 in DS1
int unk00; Assert(unk00 == 1 || unk00 == 5 || unk00 == 6 || unk00 == 7);
// ID of the function to call
int commandID;
Varint commandArgsOffset;
Varint commandArgCount;
if (commandArgCount.val > 0) {
local quad pos = FTell();
FSeek(dataStart + commandArgsOffset.val);
CommandArg args[commandArgCount.val] <bgcolor=cAqua, optimize=false>;
FSeek(pos);
}
};
struct State {
Varint id;
// Conditions are checked each frame, state switches to
// the first one that passes (if any)
Varint conditionOffsetsOffset;
Varint conditionOffsetCount;
// On commands run when the state is entered
Varint onCommandsOffset;
Varint onCommandCount;
// Off commands run when the state is exited
Varint offCommandsOffset;
Varint offCommandCount;
// Not used in DS1; perhaps run every frame?
Varint unkCommandsOffset;
Varint unkCommandCount;
local quad pos = FTell();
if (conditionOffsetCount.val > 0) {
FSeek(dataStart + conditionOffsetsOffset.val);
Varint conditionOffsets[conditionOffsetCount.val] <format=hex, bgcolor=cDkGreen, optimize=true>;
}
if (onCommandCount.val > 0) {
FSeek(dataStart + onCommandsOffset.val);
CommandCall onCommands[onCommandCount.val] <bgcolor=cLtBlue, optimize=false>;
}
if (offCommandCount.val > 0) {
FSeek(dataStart + offCommandsOffset.val);
CommandCall offCommands[offCommandCount.val] <bgcolor=cLtBlue, optimize=false>;
}
if (unkCommandCount.val > 0) {
FSeek(dataStart + unkCommandsOffset.val);
CommandCall unkCommands[unkCommandCount.val] <bgcolor=cLtBlue, optimize=false>;
}
FSeek(pos);
};
struct StateGroup {
Varint id;
Varint unkOffset1;
Varint stateCount;
// One of these is probably "entry state" or something.
Varint unkOffset2; Assert(unkOffset2.val == unkOffset1.val);
local quad pos = FTell();
FSeek(dataStart + unkOffset1.val);
struct StatesGroup {
State states[stateCount.val] <bgcolor=cGreen, optimize=false>;
} statesGroup;
State transitionState <bgcolor=cDkGreen>;
FSeek(pos);
};
struct StateGroupsGroup {
StateGroup stateGroups[dataHeader.stateGroupCount.val] <bgcolor=cSilver, optimize=false>;
} stateGroupsGroup;
struct Condition {
// State to enter if the condition passes
Varint stateOffset;
// Commands run when the condition passes
Varint commandsOffset;
Varint commandCount;
// If the condition passes, evaluation will continue to these conditions
Varint conditionOffsetsOffset;
Varint conditionOffsetCount;
// Bytecode that evaluates the condition
Varint dataOffset;
Varint dataSize;
local quad pos = FTell();
if (commandCount.val > 0) {
FSeek(dataStart + commandsOffset.val);
CommandCall commands[commandCount.val] <bgcolor=cLtBlue, optimize=false>;
}
if (conditionOffsetCount.val > 0) {
FSeek(dataStart + conditionOffsetsOffset.val);
Varint conditionOffsets[conditionOffsetCount.val] <format=hex, bgcolor=cDkGreen, optimize=true>;
}
if (dataSize.val > 0) {
FSeek(dataStart + dataOffset.val);
byte data[dataSize.val] <format=hex, bgcolor=cBlack, fgcolor=cWhite>;
}
FSeek(pos);
};
// Skip past all the states because we read them from their groups before
FSeek(FTell() + header.stateCount * header.stateSize);
struct ConditionsGroup {
Condition conditions[header.conditionCount] <bgcolor=cLtGreen, optimize=false>;
} conditionsGroup;
// In DS2, the file is padded with garbage to 0x10