Skip to content

Commit 5aa2a04

Browse files
committed
Finalizing macros before stablization
1 parent b4eead3 commit 5aa2a04

File tree

4 files changed

+62
-45
lines changed

4 files changed

+62
-45
lines changed

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ antlr4-python3-runtime==4.9.3
22
Brotli==1.0.9
33
etcpak==0.9.3
44
lz4==3.1.10
5+
marshmallow==3.14.1
6+
marshmallow-dataclass==8.5.3
57
Pillow==8.4.0
68
tabulate==0.8.9
79
texture2ddecoder==1.0.2
8-
UnityPy==1.7.25
10+
UnityPy==1.7.25

src/evAssembler.py

+53-43
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from ev_argtype import EvArgType
99
from ev_macro import EvMacroType
10-
from msbt import ForceGrmID, GroupTagID, LabelData, MsgEventID, StyleInfo, TagData, TagPatternID, WordData, WordDataPatternID
10+
import msbt
1111
if __name__ is not None and "." in __name__:
1212
from .evParser import evParser
1313
else:
@@ -23,6 +23,11 @@
2323
MAX_FLAG = 4000
2424
MAX_SYS_FLAG = 1000
2525

26+
MACRO_NAME_CMD_TABLE = {
27+
EvCmdType._POKE_TYPE_NAME : msbt.TagID.PokeType,
28+
EvCmdType._NUMBER_NAME : msbt.TagID.Number
29+
}
30+
2631
@dataclass
2732
class EvArg:
2833
argType: int
@@ -156,11 +161,10 @@ def parseText(self, origText):
156161
if origText.endswith('\\r'):
157162
origText = origText[:-2]
158163
text = origText
159-
splitters = ['\\n', '\\r', '\\f', '%']
164+
splitters = ['\\n', '\\r', '\\f', '{', '}']
160165
items = {}
161166
indicators = {}
162167
lastIndex = 0
163-
tagOpen = False
164168
while True:
165169
indices = {}
166170
for splitter in splitters:
@@ -177,13 +181,10 @@ def parseText(self, origText):
177181
indicator = Indicator.NewLine
178182
if splitter == '\\f':
179183
indicator = Indicator.ScrollLine
180-
if splitter == '%':
181-
if tagOpen:
182-
indicator = Indicator.TagEnd
183-
tagOpen = False
184-
else:
185-
indicator = Indicator.TagStart
186-
tagOpen = True
184+
if splitter == '}':
185+
indicator = Indicator.TagEnd
186+
if splitter == '{':
187+
indicator = Indicator.TagStart
187188
indicators[text.index(splitter)+lastIndex] = indicator
188189
items[text.index(splitter)+lastIndex] = text[:text.index(splitter)]
189190
lastIndex = text.index(splitter)+lastIndex
@@ -202,7 +203,7 @@ def parseText(self, origText):
202203
"indicators" : indicators
203204
}
204205

205-
def genLabelData(self, labelName, text):
206+
def genLabelData(self, labelName, text, tags):
206207
TAG_COMMANDS = {
207208
"PLAYER",
208209
"RIVAL",
@@ -224,8 +225,8 @@ def genLabelData(self, labelName, text):
224225
# ACCE_NAME
225226
# IMC_BG_NAME
226227
}
227-
styleInfo = StyleInfo.default()
228-
attributeValueArray = LabelData.defaultAttributeValueArray()
228+
styleInfo = msbt.StyleInfo.default()
229+
attributeValueArray = msbt.LabelData.defaultAttributeValueArray()
229230
tagDataArray = []
230231
wordDataArray = []
231232

@@ -236,36 +237,36 @@ def genLabelData(self, labelName, text):
236237
item: str = items[pos]
237238
indicator = indicators[pos]
238239
if indicator == Indicator.NewLine:
239-
wordDataArray.append(WordData(
240-
WordDataPatternID.Event,
241-
MsgEventID.NewLine,
240+
wordDataArray.append(msbt.WordData(
241+
msbt.WordDataPatternID.Event,
242+
msbt.MsgEventID.NewLine,
242243
-1,
243244
0.0,
244245
item,
245246
calculateStrWidth(item)
246247
))
247248
if indicator == Indicator.ScrollLine:
248-
wordDataArray.append(WordData(
249-
WordDataPatternID.Event,
250-
MsgEventID.ScrollLine,
249+
wordDataArray.append(msbt.WordData(
250+
msbt.WordDataPatternID.Event,
251+
msbt.MsgEventID.ScrollLine,
251252
-1,
252253
0.0,
253254
item,
254255
calculateStrWidth(item)
255256
))
256257
if indicator == Indicator.ScrollPage:
257-
wordDataArray.append(WordData(
258-
WordDataPatternID.Event,
259-
MsgEventID.ScrollPage,
258+
wordDataArray.append(msbt.WordData(
259+
msbt.WordDataPatternID.Event,
260+
msbt.MsgEventID.ScrollPage,
260261
-1,
261262
0.0,
262263
item,
263264
calculateStrWidth(item)
264265
))
265266
if indicator == Indicator.TagStart:
266-
wordDataArray.append(WordData(
267-
WordDataPatternID.Str,
268-
MsgEventID.NONE,
267+
wordDataArray.append(msbt.WordData(
268+
msbt.WordDataPatternID.Str,
269+
msbt.MsgEventID.NONE,
269270
-1,
270271
0.0,
271272
item,
@@ -280,35 +281,38 @@ def genLabelData(self, labelName, text):
280281
# This tag index seems to be the index into the
281282
# tagData array whereas the other tagIndex is the
282283
#
283-
wordDataArray.append(WordData(
284-
WordDataPatternID.WordTag,
285-
MsgEventID.NONE,
284+
wordDataArray.append(msbt.WordData(
285+
msbt.WordDataPatternID.WordTag,
286+
msbt.MsgEventID.NONE,
286287
len(tagDataArray),
287288
0.0,
288289
"",
289290
-1.0
290291
))
291-
tagDataArray.append(TagData(
292+
tagID = msbt.TagID.Default
293+
if tagIndex in tags:
294+
tagID = tags[tagIndex]
295+
tagDataArray.append(msbt.TagData(
292296
tagIndex,
293-
GroupTagID.Name,
294-
tagIndex, #?
295-
TagPatternID.Word,
297+
msbt.GroupTagID.Name,
298+
tagID,
299+
msbt.TagPatternID.Word,
296300
0,
297301
0,
298302
[],
299-
ForceGrmID.NONE
303+
msbt.ForceGrmID.NONE
300304
))
301305
if indicator == Indicator.End:
302-
wordDataArray.append(WordData(
303-
WordDataPatternID.Str,
304-
MsgEventID.End,
306+
wordDataArray.append(msbt.WordData(
307+
msbt.WordDataPatternID.Str,
308+
msbt.MsgEventID.End,
305309
-1,
306310
0.0,
307311
item,
308312
calculateStrWidth(item)
309313
))
310314

311-
return LabelData(
315+
return msbt.LabelData(
312316
0,
313317
0,
314318
labelName.data,
@@ -318,7 +322,7 @@ def genLabelData(self, labelName, text):
318322
wordDataArray
319323
)
320324

321-
def processTextMacro(self, cmdType, macro, commands, strTbl):
325+
def processTextMacro(self, cmdType, macro, commands, strTbl, tags):
322326
# TODO: Add a list of valid msg files
323327
try:
324328
msgFile: EvArg = macro.args[0]
@@ -347,7 +351,7 @@ def processTextMacro(self, cmdType, macro, commands, strTbl):
347351
# if strVal in self.msg_keys:
348352
# raise RuntimeError("EvMacro: {}. Label `{}` is already used at {}:{}:{}".format(macro.cmdType.name, strVal, self.fileName, text.line, text.column))
349353
macroCommands = []
350-
labelData = self.genLabelData(label, text)
354+
labelData = self.genLabelData(label, text, tags)
351355

352356
if strVal not in strTbl:
353357
strTbl.append(strVal)
@@ -363,7 +367,7 @@ def processTextMacro(self, cmdType, macro, commands, strTbl):
363367
commands.extend(macroCommands)
364368
return len(macroCommands)
365369

366-
def process(self, macro, commands, strTbl):
370+
def process(self, macro, commands, strTbl, tags):
367371
if macro.cmdType == EvMacroType.Invalid:
368372
raise RuntimeError("Invalid EvCmd or EvMacro: {} at {}:{}:{}".format(macro, self.fileName, macro.line, macro.column))
369373
textMacroMap = {
@@ -375,7 +379,7 @@ def process(self, macro, commands, strTbl):
375379

376380
if macro.cmdType in textMacroMap:
377381
evCmdType = textMacroMap[macro.cmdType]
378-
return self.processTextMacro(evCmdType, macro, commands, strTbl)
382+
return self.processTextMacro(evCmdType, macro, commands, strTbl, tags)
379383

380384
raise RuntimeError("Invalid EvMacro: {} at {}:{}:{}".format(macro, self.fileName, macro.line, macro.column))
381385

@@ -389,6 +393,7 @@ def __init__(self, fileName):
389393
self.strTbl = []
390394
self.currCmdIdx = -1
391395
self.writer = EndianBinaryWriter()
396+
self.tags = {}
392397

393398
def enterLbl(self, ctx: evParser.LblContext):
394399
lbl = ctx.getChild(0).getChild(0)
@@ -401,12 +406,13 @@ def enterLbl(self, ctx: evParser.LblContext):
401406
self.currentLabel = lblName
402407
self.scripts[self.currentLabel] = []
403408
self.currCmdIdx = -1
409+
self.tags = {}
404410

405411
# Enter a parse tree produced by evParser#instruction.
406412
def enterInstruction(self, ctx:evParser.InstructionContext):
407413
name = str(ctx.getChild(0).getChild(0))
408414
if self.macro.isValid():
409-
self.currCmdIdx += self.macroAssembler.process(self.macro, self.scripts[self.currentLabel], self.strTbl)
415+
self.currCmdIdx += self.macroAssembler.process(self.macro, self.scripts[self.currentLabel], self.strTbl, self.tags)
410416
self.macro = EvMacro(EvMacroType.Invalid, [], ctx.start.line, ctx.start.column)
411417

412418
if hasattr(EvMacroType, name):
@@ -435,7 +441,11 @@ def enterNumber(self, ctx: evParser.NumberContext):
435441
EvArg(EvArgType.Value, argVal, ctx.start.line, ctx.start.column)
436442
)
437443
else:
438-
self.scripts[self.currentLabel][self.currCmdIdx].args.append(
444+
evCmd = self.scripts[self.currentLabel][self.currCmdIdx]
445+
if evCmd.cmdType in MACRO_NAME_CMD_TABLE:
446+
tagIndex = argVal
447+
self.tags[tagIndex] = MACRO_NAME_CMD_TABLE[evCmd.cmdType]
448+
evCmd.args.append(
439449
EvArg(EvArgType.Value, argVal, ctx.start.line, ctx.start.column)
440450
)
441451

src/msbt.py

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class ForceGrmID(IntEnum):
5757
Masculine = 3
5858
InitialCap = 4
5959

60+
class TagID(IntEnum):
61+
Default = 0
62+
PokeType = 3
63+
Number = 4
64+
6065
@dataclass
6166
class UnityGameObject:
6267
m_FileID: int

src/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name = "ev-as",
15-
version = "1.0",
15+
version = "1.1",
1616
options = {"build_exe": build_exe_options},
1717
description = "Pre-Compiled version of ev-as",
1818
executables = [Executable("ev_parse.py"), Executable("ev_as.py")])

0 commit comments

Comments
 (0)