mirror of
https://github.com/Skeli789/Dynamic-Pokemon-Expansion.git
synced 2026-09-02 23:30:30 -05:00
TM/HM & Move Tutor Expansion
This commit is contained in:
@@ -1,37 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: cp437 -*-
|
||||
|
||||
import sys
|
||||
from insert import TryProcessFileInclusion, TryProcessConditionalCompilation
|
||||
|
||||
CharMap = "charmap.tbl"
|
||||
|
||||
SpecialBuffers = {
|
||||
"." : ["B0"],
|
||||
"BUFFER" : ["FD"],
|
||||
"ATTACKER" : ["FD", "0F"],
|
||||
"TARGET" : ["FD", "10"],
|
||||
"EFFECT_BANK" : ["FD", "11"],
|
||||
"SCRIPTING_BANK" : ["FD", "13"],
|
||||
"CURRENT_MOVE" : ["FD", "14"],
|
||||
"LAST_ITEM" : ["FD", "16"],
|
||||
"LAST_ABILITY" : ["FD", "17"],
|
||||
"ATTACKER_ABILITY" : ["FD", "18"],
|
||||
"TARGET_ABILITY" : ["FD", "19"],
|
||||
"SCRIPTING_BANK_ABILITY" : ["FD", "1A"],
|
||||
"PLAYER_NAME" : ["FD", "23"],
|
||||
".": ["B0"],
|
||||
"BUFFER": ["FD"],
|
||||
"ATTACKER": ["FD", "0F"],
|
||||
"TARGET": ["FD", "10"],
|
||||
"EFFECT_BANK": ["FD", "11"],
|
||||
"SCRIPTING_BANK": ["FD", "13"],
|
||||
"CURRENT_MOVE": ["FD", "14"],
|
||||
"LAST_ITEM": ["FD", "16"],
|
||||
"LAST_ABILITY": ["FD", "17"],
|
||||
"ATTACKER_ABILITY": ["FD", "18"],
|
||||
"TARGET_ABILITY": ["FD", "19"],
|
||||
"SCRIPTING_BANK_ABILITY": ["FD", "1A"],
|
||||
"PLAYER_NAME": ["FD", "23"],
|
||||
|
||||
"PLAYER": ["FD", "01"],
|
||||
"BUFFER1": ["FD", "02"],
|
||||
"BUFFER2": ["FD", "03"],
|
||||
"BUFFER3": ["FD", "04"],
|
||||
"RIVAL": ["FD", "06"],
|
||||
"WHITE": ["FC", "01", "01"],
|
||||
"BLACK": ["FC", "01", "02"],
|
||||
"GRAY": ["FC", "01", "03"],
|
||||
"RED": ["FC", "01", "04"],
|
||||
"ORANGE": ["FC", "01", "05"],
|
||||
"GREEN": ["FC", "01", "06"],
|
||||
"LIGHT_GREEN": ["FC", "01", "07"],
|
||||
"BLUE": ["FC", "01", "08"],
|
||||
"LIGHT_BLUE": ["FC", "01", "09"],
|
||||
|
||||
"ARROW_UP": ["79"],
|
||||
"ARROW_DOWN": ["7A"],
|
||||
"ARROW_LEFT": ["7B"],
|
||||
"ARROW_RIGHT": ["7C"],
|
||||
|
||||
"ALIGN": ["FC", "13"],
|
||||
"SHRINK": ["FC", "06", "00"]
|
||||
}
|
||||
|
||||
def StringFileConverter(filename):
|
||||
|
||||
def StringFileConverter(fileName: str):
|
||||
stringToWrite = ".thumb\n.text\n.align 2\n\n"
|
||||
with open(filename, 'r') as file:
|
||||
with open(fileName, 'r') as file:
|
||||
maxLength = 0
|
||||
fillFF = False
|
||||
readingState = 0
|
||||
|
||||
lineNum = 0
|
||||
definesDict = {}
|
||||
conditionals = []
|
||||
|
||||
for line in file:
|
||||
line = line.rstrip("\n\r") #Remove only newline characters
|
||||
if line == "" or line[:2] == "//": #Ignore blank lines and comment lines
|
||||
lineNum += 1
|
||||
line = line.rstrip("\n\r") # Remove only newline characters
|
||||
if TryProcessFileInclusion(line, definesDict):
|
||||
continue
|
||||
if TryProcessConditionalCompilation(line, definesDict, conditionals):
|
||||
continue
|
||||
if line.strip() == "" or line[:2] == "//": # Ignore blank lines and comment lines
|
||||
continue
|
||||
|
||||
if readingState == 0: #Only when the file starts
|
||||
if readingState == 0: # Only when the file starts
|
||||
line = line.strip()
|
||||
if line[:6].upper() == "#ORG @" and line[6:] != "":
|
||||
title = line[6:]
|
||||
@@ -41,14 +76,16 @@ def StringFileConverter(filename):
|
||||
try:
|
||||
maxLength = int(line.split("=")[1])
|
||||
except:
|
||||
print('Error reading max length in line: "' + line + '" in file: "' + filename + '"')
|
||||
print('Error reading max length on line ' + str(lineNum) + ' in file: "' + fileName + '"')
|
||||
sys.exit(0)
|
||||
elif "FILL_FF" in line and "=" in line:
|
||||
try:
|
||||
fillFF = bool(line.split("=")[1])
|
||||
except:
|
||||
print('Error reading FF fill in line: "' + line + '" in file: "' + filename + '"')
|
||||
print('Error reading FF fill on line ' + str(lineNum) + ' in file: "' + fileName + '"')
|
||||
sys.exit(0)
|
||||
else:
|
||||
print('Warning! Error with line: "' + line + '" in file: "' + filename + '"')
|
||||
print('Warning! Error on line ' + str(lineNum) + ' in file: "' + fileName + '"')
|
||||
|
||||
elif readingState == 1:
|
||||
if line[:6].upper() == "#ORG @" and line[6:] != "":
|
||||
@@ -56,14 +93,15 @@ def StringFileConverter(filename):
|
||||
title = line[6:]
|
||||
stringToWrite += ".global " + title + "\n" + title + ":\n"
|
||||
else:
|
||||
stringToWrite += ProcessString(line, maxLength, fillFF)
|
||||
stringToWrite += "0xFF\n\n" #Only print line in everything went alright
|
||||
stringToWrite += ProcessString(line, lineNum, maxLength, fillFF)
|
||||
stringToWrite += "0xFF\n\n" # Only print line in everything went alright
|
||||
|
||||
output = open(filename.split(".string")[0] + '.s', 'w') #Only open file once we know everything went okay.
|
||||
output = open(fileName.split(".string")[0] + '.s', 'w') # Only open file once we know everything went okay.
|
||||
output.write(stringToWrite)
|
||||
output.close()
|
||||
|
||||
def ProcessString(string, maxLength = 0, fillWithFF = False):
|
||||
|
||||
|
||||
def ProcessString(string: str, lineNum: int, maxLength=0, fillWithFF=False) -> str:
|
||||
charMap = PokeByteTableMaker()
|
||||
stringToWrite = ".byte "
|
||||
buffer = False
|
||||
@@ -72,23 +110,29 @@ def ProcessString(string, maxLength = 0, fillWithFF = False):
|
||||
strLen = 0
|
||||
|
||||
for char in string:
|
||||
if maxLength > 0 and strLen >= maxLength:
|
||||
print('Warning: The string "' + string + '" has exceeded the maximum length of ' + str(maxLength) + ' and has been truncated!')
|
||||
if 0 < maxLength <= strLen:
|
||||
print('Warning: The string "' + string + '" has exceeded the maximum length of '
|
||||
+ str(maxLength) + ' and has been truncated!')
|
||||
break
|
||||
|
||||
|
||||
if buffer is True:
|
||||
if char == ']':
|
||||
buffer = False
|
||||
|
||||
if bufferChars in SpecialBuffers:
|
||||
for bufferChar in SpecialBuffers[bufferChars]:
|
||||
if maxLength > 0 and strLen >= maxLength: #End buffer in middle
|
||||
print('Warning: The string buffer "' + bufferChars + '" has exceeded the maximum length of ' + str(maxLength) + ' and has been truncated!')
|
||||
if 0 < maxLength <= strLen: # End buffer in middle
|
||||
print('Warning: The string buffer "' + bufferChars + '" has exceeded the maximum length of '
|
||||
+ str(maxLength) + ' and has been truncated!')
|
||||
break
|
||||
|
||||
|
||||
stringToWrite += ("0x" + bufferChar + ", ")
|
||||
strLen += 1
|
||||
|
||||
|
||||
elif len(bufferChars) > 2: # Unrecognized buffer
|
||||
print('Warning: The string buffer "' + bufferChars + '" is not recognized!')
|
||||
stringToWrite += "0x0, " # Place whitespace where the buffer should have gone
|
||||
strLen += 1
|
||||
else:
|
||||
stringToWrite += ("0x" + bufferChars + ", ")
|
||||
strLen += 1
|
||||
@@ -104,8 +148,8 @@ def ProcessString(string, maxLength = 0, fillWithFF = False):
|
||||
strLen += 1
|
||||
|
||||
except KeyError:
|
||||
print('Error parsing string: "' + string + '"')
|
||||
break
|
||||
print('Error parsing string: "' + string + '" (Line ' + str(lineNum) + ')')
|
||||
sys.exit(0)
|
||||
|
||||
else:
|
||||
try:
|
||||
@@ -113,39 +157,41 @@ def ProcessString(string, maxLength = 0, fillWithFF = False):
|
||||
strLen += 1
|
||||
|
||||
except KeyError:
|
||||
if (char == '['):
|
||||
if char == '[':
|
||||
buffer = True
|
||||
elif (char == '\\'):
|
||||
elif char == '\\':
|
||||
escapeChar = True
|
||||
elif char == '"':
|
||||
stringToWrite += hex(charMap["\\" + char])
|
||||
strLen += 1
|
||||
else:
|
||||
print('Error parsing string: "' + string + '"' + ' at character "' + char + '".')
|
||||
break
|
||||
print('Error parsing string on line ' + str(lineNum) + ' at character "' + char + '".')
|
||||
sys.exit(1)
|
||||
|
||||
if strLen < maxLength and fillWithFF:
|
||||
while strLen < maxLength:
|
||||
stringToWrite += "0xFF, "
|
||||
strLen += 1
|
||||
|
||||
|
||||
return stringToWrite
|
||||
|
||||
|
||||
def PokeByteTableMaker():
|
||||
dicty = {}
|
||||
dictionary = {}
|
||||
with open(CharMap) as file:
|
||||
for line in file:
|
||||
if line.strip() != "/FF" and line.strip() != "":
|
||||
if (line[2] == '=' and line[3] != ""):
|
||||
try:
|
||||
if line[3] == '\\':
|
||||
dicty[line[3] + line[4]] = int(line.split('=')[0], 16)
|
||||
else:
|
||||
dicty[line[3]] = int(line.split('=')[0], 16)
|
||||
except:
|
||||
pass
|
||||
dicty[' '] = 0
|
||||
|
||||
dicty["<EFBFBD>"] = 0xB0
|
||||
dicty["<EFBFBD>"] = 0xB1
|
||||
return dicty
|
||||
for line in file:
|
||||
if line.strip() != "/FF" and line.strip() != "":
|
||||
if line[2] == '=' and line[3] != "":
|
||||
try:
|
||||
if line[3] == '\\':
|
||||
dictionary[line[3] + line[4]] = int(line.split('=')[0], 16)
|
||||
else:
|
||||
dictionary[line[3]] = int(line.split('=')[0], 16)
|
||||
except:
|
||||
pass
|
||||
dictionary[' '] = 0
|
||||
|
||||
dictionary["<EFBFBD>"] = 0xB4
|
||||
dictionary["<EFBFBD>"] = 0xB0
|
||||
dictionary["<EFBFBD>"] = 0xB1
|
||||
return dictionary
|
||||
|
||||
Reference in New Issue
Block a user