mirror of
https://github.com/pret/pokemon-reverse-engineering-tools.git
synced 2026-08-09 10:47:24 -05:00
crystal.py: no more relative paths
This commit is contained in:
parent
001b6bc850
commit
3496b81eb3
|
|
@ -61,6 +61,9 @@ import item_constants
|
|||
import wram
|
||||
import exceptions
|
||||
|
||||
import config
|
||||
conf = config.Config()
|
||||
|
||||
from map_names import map_names
|
||||
|
||||
# ---- script_parse_table explanation ----
|
||||
|
|
@ -106,17 +109,21 @@ def map_name_cleaner(input):
|
|||
|
||||
rom = romstr.RomStr(None)
|
||||
|
||||
def direct_load_rom(filename="../baserom.gbc"):
|
||||
def direct_load_rom(filename=None):
|
||||
"""loads bytes into memory"""
|
||||
if filename == None:
|
||||
filename = os.path.join(conf.path, "baserom.gbc")
|
||||
global rom
|
||||
file_handler = open(filename, "rb")
|
||||
rom = romstr.RomStr(file_handler.read())
|
||||
file_handler.close()
|
||||
return rom
|
||||
|
||||
def load_rom(filename="../baserom.gbc"):
|
||||
def load_rom(filename=None):
|
||||
"""checks that the loaded rom matches the path
|
||||
and then loads the rom if necessary."""
|
||||
if filename == None:
|
||||
filename = os.path.join(conf.path, "baserom.gbc")
|
||||
global rom
|
||||
if rom != romstr.RomStr(None) and rom != None:
|
||||
return rom
|
||||
|
|
@ -125,14 +132,18 @@ def load_rom(filename="../baserom.gbc"):
|
|||
elif os.lstat(filename).st_size != len(rom):
|
||||
return direct_load_rom(filename)
|
||||
|
||||
def direct_load_asm(filename="../main.asm"):
|
||||
def direct_load_asm(filename=None):
|
||||
if filename == None:
|
||||
filename = os.path.join(conf.path, "main.asm")
|
||||
"""returns asm source code (AsmList) from a file"""
|
||||
asm = open(filename, "r").read().split("\n")
|
||||
asm = romstr.AsmList(asm)
|
||||
return asm
|
||||
|
||||
def load_asm(filename="../main.asm"):
|
||||
def load_asm(filename=None):
|
||||
"""returns asm source code (AsmList) from a file (uses a global)"""
|
||||
if filename == None:
|
||||
filename = os.path.join(conf.path, "main.asm")
|
||||
global asm
|
||||
asm = direct_load_asm(filename=filename)
|
||||
return asm
|
||||
|
|
@ -3185,7 +3196,9 @@ effect_classes = create_effect_command_classes()
|
|||
|
||||
|
||||
|
||||
def generate_macros(filename="../script_macros.asm"):
|
||||
def generate_macros(filename=None):
|
||||
if filename == None:
|
||||
filename = os.path.join(conf.path, "script_macros.asm")
|
||||
"""generates all macros based on commands
|
||||
this is dumped into script_macros.asm"""
|
||||
output = "; This file is generated by generate_macros.\n"
|
||||
|
|
@ -5985,7 +5998,7 @@ def old_parse_second_map_header_at(address, map_group=None, map_id=None, debug=T
|
|||
|
||||
class MapBlockData:
|
||||
base_label = "MapBlockData_"
|
||||
maps_path = os.path.realpath(os.path.join(os.path.realpath("."), "../maps"))
|
||||
maps_path = os.path.realpath(os.path.join(conf.path, "maps"))
|
||||
|
||||
def __init__(self, address, map_group=None, map_id=None, debug=True, bank=None, label=None, width=None, height=None):
|
||||
self.address = address
|
||||
|
|
@ -6887,9 +6900,11 @@ def reset_incbins():
|
|||
isolate_incbins(asm=asm)
|
||||
process_incbins()
|
||||
|
||||
def find_incbin_to_replace_for(address, debug=False, rom_file="../baserom.gbc"):
|
||||
def find_incbin_to_replace_for(address, debug=False, rom_file=None):
|
||||
"""returns a line number for which incbin to edit
|
||||
if you were to insert bytes into main.asm"""
|
||||
if rom_file == None:
|
||||
rom_file = os.path.join(conf.path, "baserom.gbc")
|
||||
if type(address) == str: address = int(address, 16)
|
||||
if not (0 <= address <= os.lstat(rom_file).st_size):
|
||||
raise IndexError("address is out of bounds")
|
||||
|
|
@ -6917,7 +6932,7 @@ def find_incbin_to_replace_for(address, debug=False, rom_file="../baserom.gbc"):
|
|||
return incbin_key
|
||||
return None
|
||||
|
||||
def split_incbin_line_into_three(line, start_address, byte_count, rom_file="../baserom.gbc"):
|
||||
def split_incbin_line_into_three(line, start_address, byte_count, rom_file=None):
|
||||
"""
|
||||
splits an incbin line into three pieces.
|
||||
you can replace the middle one with the new content of length bytecount
|
||||
|
|
@ -6925,6 +6940,8 @@ def split_incbin_line_into_three(line, start_address, byte_count, rom_file="../b
|
|||
start_address: where you want to start inserting bytes
|
||||
byte_count: how many bytes you will be inserting
|
||||
"""
|
||||
if rom_file == None:
|
||||
rom_file = os.path.join(conf.path, "baserom.gbc")
|
||||
if type(start_address) == str: start_address = int(start_address, 16)
|
||||
if not (0 <= start_address <= os.lstat(rom_file).st_size):
|
||||
raise IndexError("start_address is out of bounds")
|
||||
|
|
@ -6984,9 +7001,9 @@ def generate_diff_insert(line_number, newline, debug=False):
|
|||
CalledProcessError = None
|
||||
|
||||
try:
|
||||
diffcontent = subprocess.check_output("diff -u ../main.asm " + newfile_filename, shell=True)
|
||||
diffcontent = subprocess.check_output("diff -u " + os.path.join(conf.path, "main.asm") + " " + newfile_filename, shell=True)
|
||||
except (AttributeError, CalledProcessError):
|
||||
p = subprocess.Popen(["diff", "-u", "../main.asm", newfile_filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
p = subprocess.Popen(["diff", "-u", os.path.join(conf.path, "main.asm"), newfile_filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = p.communicate()
|
||||
diffcontent = out
|
||||
|
||||
|
|
@ -7006,8 +7023,8 @@ def apply_diff(diff, try_fixing=True, do_compile=True):
|
|||
fh.close()
|
||||
|
||||
# apply the patch
|
||||
os.system("cp ../main.asm ../main1.asm")
|
||||
os.system("patch ../main.asm temp.patch")
|
||||
os.system("cp " + os.path.join(conf.path, "main.asm") + " " + os.path.join(conf.path, "main1.asm"))
|
||||
os.system("patch " + os.path.join(conf.path, "main.asm") + " " + "temp.patch")
|
||||
|
||||
# remove the patch
|
||||
os.system("rm temp.patch")
|
||||
|
|
@ -7015,11 +7032,11 @@ def apply_diff(diff, try_fixing=True, do_compile=True):
|
|||
# confirm it's working
|
||||
if do_compile:
|
||||
try:
|
||||
subprocess.check_call("cd ../; make clean; make", shell=True)
|
||||
subprocess.check_call("cd " + conf.path + "; make clean; make", shell=True)
|
||||
return True
|
||||
except Exception, exc:
|
||||
if try_fixing:
|
||||
os.system("mv ../main1.asm ../main.asm")
|
||||
os.system("mv " + os.path.join(conf.path, "main1.asm") + " " + os.path.join(conf.path, "main.asm"))
|
||||
return False
|
||||
|
||||
class AsmLine:
|
||||
|
|
@ -7151,8 +7168,10 @@ class AsmSection:
|
|||
return self.line
|
||||
|
||||
new_asm = None
|
||||
def load_asm2(filename="../main.asm", force=False):
|
||||
def load_asm2(filename=None, force=False):
|
||||
"""loads the asm source code into memory"""
|
||||
if filename == None:
|
||||
filename = os.path.join(conf.path, "main.asm")
|
||||
global new_asm
|
||||
if new_asm == None or force:
|
||||
new_asm = Asm(filename=filename)
|
||||
|
|
@ -7160,7 +7179,9 @@ def load_asm2(filename="../main.asm", force=False):
|
|||
|
||||
class Asm:
|
||||
"""controls the overall asm output"""
|
||||
def __init__(self, filename="../main.asm", debug=True):
|
||||
def __init__(self, filename=None, debug=True):
|
||||
if filename == None:
|
||||
filename = os.path.join(conf.path, "main.asm")
|
||||
self.parts = []
|
||||
self.labels = []
|
||||
self.filename = filename
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user