mirror of
https://github.com/thornAvery/kep-hack.git
synced 2025-11-14 09:06:41 +13:00
merge
hg-commit-id: ed3014e00c72
This commit is contained in:
commit
a17ab4b56a
|
|
@ -18,6 +18,9 @@ syntax: glob
|
||||||
#swap files for vim
|
#swap files for vim
|
||||||
.*.swp
|
.*.swp
|
||||||
|
|
||||||
|
#no data from extras/
|
||||||
|
extras/*.json
|
||||||
|
|
||||||
#for any of the poor souls with save game files in their working directory
|
#for any of the poor souls with save game files in their working directory
|
||||||
baserom.sgm
|
baserom.sgm
|
||||||
baserom.sav
|
baserom.sav
|
||||||
|
|
@ -27,5 +30,3 @@ pokered.sav
|
||||||
#for vim configuration
|
#for vim configuration
|
||||||
#url: http://www.vim.org/scripts/script.php?script_id=441
|
#url: http://www.vim.org/scripts/script.php?script_id=441
|
||||||
.lvimrc
|
.lvimrc
|
||||||
|
|
||||||
*.exe
|
|
||||||
578
common.asm
578
common.asm
File diff suppressed because it is too large
Load diff
|
|
@ -6,6 +6,7 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import json
|
||||||
from extract_maps import rom, assert_rom, load_rom, calculate_pointer, load_map_pointers, read_all_map_headers, map_headers
|
from extract_maps import rom, assert_rom, load_rom, calculate_pointer, load_map_pointers, read_all_map_headers, map_headers
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -259,7 +260,7 @@ def is_probably_pointer(input):
|
||||||
label_errors = ""
|
label_errors = ""
|
||||||
def get_labels_between(start_line_id, end_line_id, bank_id):
|
def get_labels_between(start_line_id, end_line_id, bank_id):
|
||||||
labels = []
|
labels = []
|
||||||
#line = {
|
#label = {
|
||||||
# "line_number": 15,
|
# "line_number": 15,
|
||||||
# "bank_id": 32,
|
# "bank_id": 32,
|
||||||
# "label": "PalletTownText1",
|
# "label": "PalletTownText1",
|
||||||
|
|
@ -345,9 +346,17 @@ def get_labels_between(start_line_id, end_line_id, bank_id):
|
||||||
local_pointer = hex((address % 0x4000) + 0x4000).replace("0x", "$")
|
local_pointer = hex((address % 0x4000) + 0x4000).replace("0x", "$")
|
||||||
|
|
||||||
print line_label + " is at " + hex(address)
|
print line_label + " is at " + hex(address)
|
||||||
|
|
||||||
|
label = {
|
||||||
|
"line_number": line_id,
|
||||||
|
"bank_id": bank_id,
|
||||||
|
"label": line_label,
|
||||||
|
"local_pointer": local_pointer,
|
||||||
|
"address": address
|
||||||
|
}
|
||||||
|
labels.append(label)
|
||||||
|
|
||||||
current_line_offset += 1
|
current_line_offset += 1
|
||||||
|
|
||||||
label_errors += errors
|
label_errors += errors
|
||||||
return labels
|
return labels
|
||||||
|
|
||||||
|
|
@ -364,6 +373,7 @@ def scan_for_predefined_labels():
|
||||||
to grab all label addresses better than this script..
|
to grab all label addresses better than this script..
|
||||||
"""
|
"""
|
||||||
bank_intervals = {}
|
bank_intervals = {}
|
||||||
|
all_labels = []
|
||||||
|
|
||||||
#figure out line numbers for each bank
|
#figure out line numbers for each bank
|
||||||
for bank_id in range(0x2d):
|
for bank_id in range(0x2d):
|
||||||
|
|
@ -394,7 +404,16 @@ def scan_for_predefined_labels():
|
||||||
end_line_id = bank_data["end"]
|
end_line_id = bank_data["end"]
|
||||||
|
|
||||||
labels = get_labels_between(start_line_id, end_line_id, bank_id)
|
labels = get_labels_between(start_line_id, end_line_id, bank_id)
|
||||||
bank_intervals[bank_id]["labels"] = labels
|
#bank_intervals[bank_id]["labels"] = labels
|
||||||
|
all_labels.extend(labels)
|
||||||
|
|
||||||
|
write_all_labels(all_labels)
|
||||||
|
return all_labels
|
||||||
|
|
||||||
|
def write_all_labels(all_labels):
|
||||||
|
fh = open("labels.json", "w")
|
||||||
|
fh.write(json.dumps(all_labels))
|
||||||
|
fh.close()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
#load map headers
|
#load map headers
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#author: Bryan Bishop <kanzure@gmail.com>
|
#author: Bryan Bishop <kanzure@gmail.com>
|
||||||
#date: 2012-01-09
|
#date: 2012-01-09
|
||||||
import extract_maps
|
import extract_maps
|
||||||
|
import os
|
||||||
|
import json
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
from pretty_map_headers import random_hash, map_name_cleaner
|
from pretty_map_headers import random_hash, map_name_cleaner
|
||||||
from ctypes import c_int8
|
from ctypes import c_int8
|
||||||
|
|
@ -552,24 +554,32 @@ relative_unconditional_jumps = [0xc3, 0x18]
|
||||||
#TODO: replace call and a pointer with call and a label
|
#TODO: replace call and a pointer with call and a label
|
||||||
call_commands = [0xdc, 0xd4, 0xc4, 0xcc, 0xcd]
|
call_commands = [0xdc, 0xd4, 0xc4, 0xcc, 0xcd]
|
||||||
|
|
||||||
asm_commands = {
|
|
||||||
"3c49": "PrintText",
|
all_labels = {}
|
||||||
"35d6": "Bankswitch",
|
|
||||||
"3927": "AddPokemonToParty",
|
def load_labels(filename="labels.json"):
|
||||||
"3e48": "GivePokemon",
|
global all_labels
|
||||||
"3dd7": "Delay3",
|
if os.path.exists(filename):
|
||||||
"3e2e": "GiveItem",
|
all_labels = json.loads(open(filename, "r").read())
|
||||||
"2f9e": "GetMonName",
|
else:
|
||||||
"3e6d": "Predef", #library of pre-defined asm routines
|
print "You must run analyze_incbins.scan_for_predefined_labels() to create \"labels.json\"."
|
||||||
"00b5": "CopyData",
|
load_labels()
|
||||||
"2ff3": "GetMachineName",
|
|
||||||
"24d7": "TextScriptEnd",
|
def find_label(local_address, bank_id=0):
|
||||||
"3e5c": "GenRandom", #bank 4
|
global all_labels
|
||||||
"6581": "ItemUseNotTime",
|
|
||||||
"3a87": "AddNTimes",
|
#turn local_address into a string
|
||||||
"3dab": "IsInArray", #bank 3
|
if type(local_address) == str:
|
||||||
"039e": "HandleMidJump",
|
if "0x" in local_address: local_address = local_address.replace("0x", "$")
|
||||||
}
|
elif not "$" in local_address: local_address = "$" + local_address
|
||||||
|
if type(local_address) == int:
|
||||||
|
local_address = "$%.2x" % (local_address)
|
||||||
|
local_address = local_address.upper()
|
||||||
|
|
||||||
|
for label_entry in all_labels:
|
||||||
|
if label_entry["local_pointer"].upper() == local_address:
|
||||||
|
return label_entry["label"]
|
||||||
|
return None
|
||||||
|
|
||||||
def random_asm_label():
|
def random_asm_label():
|
||||||
return ".ASM_" + random_hash()
|
return ".ASM_" + random_hash()
|
||||||
|
|
@ -587,6 +597,10 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
|
||||||
#ad = end_address
|
#ad = end_address
|
||||||
#a, oa = current_byte_number
|
#a, oa = current_byte_number
|
||||||
|
|
||||||
|
bank_id = 0
|
||||||
|
if original_offset > 0x4000:
|
||||||
|
bank_id = original_offset / 0x4000
|
||||||
|
|
||||||
last_hl_address = None #for when we're scanning the main map script
|
last_hl_address = None #for when we're scanning the main map script
|
||||||
last_a_address = None
|
last_a_address = None
|
||||||
used_3d97 = False
|
used_3d97 = False
|
||||||
|
|
@ -726,8 +740,9 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
|
||||||
|
|
||||||
insertion = "$%.4x" % (number)
|
insertion = "$%.4x" % (number)
|
||||||
if maybe_byte in call_commands or current_byte in relative_unconditional_jumps or current_byte in relative_jumps:
|
if maybe_byte in call_commands or current_byte in relative_unconditional_jumps or current_byte in relative_jumps:
|
||||||
if insertion[1:] in asm_commands:
|
result = find_label(insertion[1:], bank_id)
|
||||||
insertion = asm_commands[insertion[1:]]
|
if result != None:
|
||||||
|
insertion = result
|
||||||
|
|
||||||
opstr = opstr[:opstr.find("?")].lower() + insertion + opstr[opstr.find("?")+1:].lower()
|
opstr = opstr[:opstr.find("?")].lower() + insertion + opstr[opstr.find("?")+1:].lower()
|
||||||
output += spacing + opstr #+ " ; " + hex(offset)
|
output += spacing + opstr #+ " ; " + hex(offset)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue