Skip to content

Commit 227ddf6

Browse files
Full Label System
Finally labels are fully ready. Thou can decompile known commands with offsets to labels (and only to labels) and compile them to normal code. I don't know yes, how many issues it can solve. Need to test, to test and to test.
1 parent bbb8773 commit 227ddf6

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

gscScriptCompAndDecompiler.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,74 @@ def DecompileGscToTxt(self):
506506
def CompileTxtToGsc(self):
507507
Lines = self.File.read().split('\n')
508508
i = 0
509+
510+
#Обозначим все метки.
511+
Offset = 0
512+
LenOff = 0
513+
while (i < len(Lines)):
514+
if (Lines[i] == ''):
515+
i += 1
516+
continue
517+
if (Lines[i][0] == '@'):
518+
NotAnythingNew = 0
519+
LabelNumber = int(Lines[i][1:])
520+
for Marbas in self.Labels:
521+
if (LabelNumber == Marbas[0]):
522+
NotAnythingNew = 1
523+
break
524+
if (NotAnythingNew == 1):
525+
i += i
526+
continue
527+
self.Labels.append([])
528+
self.Labels[LenOff].append(LabelNumber)
529+
self.Labels[LenOff].append(Offset)
530+
LenOff += 1
531+
i += 1
532+
elif (Lines[i][0] == '#'):
533+
CommandDef = Lines[i][1:]
534+
DontKnow = 1
535+
iz = 0
536+
while (iz < len(self.CommandsLibrary)):
537+
if (CommandDef == str(self.CommandsLibrary[iz][0])):
538+
DontKnow = 0
539+
break
540+
elif (CommandDef == self.CommandsLibrary[iz][2]):
541+
DontKnow = 0
542+
CommandDef = str(self.CommandsLibrary[iz][0])
543+
break
544+
iz += 1
545+
CommandDef = int(CommandDef)
546+
Offset += 2
547+
if (DontKnow == 0):
548+
for OfferI in self.CommandsLibrary[iz][1]:
549+
if ((OfferI == 'h') or (OfferI == 'H')):
550+
Offset += 2
551+
elif ((OfferI == 'i') or (OfferI == 'I')):
552+
Offset += 4
553+
else:
554+
if ((CommandDef & 0xf000) == 0xf000):
555+
Offset += 4
556+
elif ((CommandDef & 0xf000) == 0x0000):
557+
Offset += 0
558+
else:
559+
Offset += 6
560+
i += 1
561+
else:
562+
i += 1
563+
continue
564+
565+
#Сделаем всё остальное.
566+
i = 0
509567
while (i < len(Lines)):
510568
if (Lines[i] == ''):
511569
i += 1
512570
continue
513571
if (Lines[i][0] == '<'): #Комментарии.
514572
i += 1
515573
continue
574+
if (Lines[i][0] == '@'): #Метки (забираются раньше).
575+
i += 1
576+
continue
516577
if (Lines[i][0] == '>'):
517578
String = ''
518579
i += 1
@@ -554,6 +615,21 @@ def CompileTxtToGsc(self):
554615
CommandCTR = []
555616
for ii in range(0, len(CommandCTR)):
556617
CommandNEW.append(int(CommandCTR[ii]))
618+
#Работаем с командами, где есть связанные со смещениями аргументы.
619+
Farba = 0
620+
while (Farba < len(self.ConnectedOffsetsLibrary)):
621+
if (CommandType == self.ConnectedOffsetsLibrary[Farba][0]):
622+
for NewZeland in self.ConnectedOffsetsLibrary[Farba][1]:
623+
Ermeg = 0
624+
Ermeg = CommandNEW[NewZeland]
625+
Ai = 0
626+
for Ai in self.Labels:
627+
if (Ermeg == Ai[0]):
628+
CommandNEW[NewZeland] = Ai[1]
629+
break
630+
Farba += 1
631+
632+
#Далее всё как обычно.
557633
self.CommandArgs.append(CommandNEW)
558634
i += 1
559635

0 commit comments

Comments
 (0)