2023-07-25 16:33:45 +09:30
|
|
|
extends Node
|
|
|
|
|
2023-08-07 01:17:45 +09:30
|
|
|
const STRUCT := preload('res://scripts/struct.gd')
|
|
|
|
const STRUCT_SNES := preload('res://scripts/loaders/snes/structs.gd')
|
|
|
|
var structdefs := {}
|
2023-08-01 23:22:31 +09:30
|
|
|
const loader_cd_image := preload('res://scripts/loaders/cd/image.gd')
|
|
|
|
var psx_productcode_regex := RegEx.new()
|
|
|
|
const psx_ff5_productcodes = [
|
|
|
|
'SLUS_008.79', # US Anthology, both 1.0 and 1.1
|
|
|
|
'SCES_138.40', # EU/Aus Anthology
|
|
|
|
'SLPM_860.81', # JP
|
|
|
|
'SCPS_452.14', # JP original, untested
|
|
|
|
]
|
|
|
|
|
2023-07-25 16:33:45 +09:30
|
|
|
var ROM_filename := 'FF5_SCC_WepTweaks_Inus_Dash.sfc' # 'Final Fantasy V (Japan).sfc'
|
|
|
|
var GBA_filename := '2564 - Final Fantasy V Advance (U)(Independent).gba'
|
|
|
|
|
|
|
|
var rom_snes := File.new()
|
2023-08-07 01:17:45 +09:30
|
|
|
var snes_data := {}
|
2023-07-26 21:52:54 +09:30
|
|
|
var thread := Thread.new()
|
2023-07-25 16:33:45 +09:30
|
|
|
|
|
|
|
func load_snes_rom(filename: String):
|
|
|
|
var error := rom_snes.open(filename, File.READ)
|
|
|
|
if error == OK:
|
2023-08-07 01:17:45 +09:30
|
|
|
# Copy entire SNES ROM to a buffer for StreamPeerBuffer usage.
|
|
|
|
# Unfortunately, the File API is different and slightly worse than the StreamPeer API.
|
|
|
|
var bytes := rom_snes.get_buffer(rom_snes.get_len())
|
|
|
|
var buffer = StreamPeerBuffer.new()
|
|
|
|
buffer.data_array = bytes
|
2023-08-07 21:20:35 +09:30
|
|
|
# SpriteLoader.load_snes_rom(rom_snes)
|
|
|
|
# MapLoader.load_snes_rom(rom_snes)
|
2023-08-04 18:17:08 +09:30
|
|
|
StringLoader.load_snes_rom(rom_snes, true)
|
2023-08-07 01:17:45 +09:30
|
|
|
# Don't do this concurrently, avoid file pointer conflicts
|
2023-08-07 19:34:46 +09:30
|
|
|
#var _thread_error = thread.start(SoundLoader, 'parse_rom', rom_snes)
|
2023-08-07 01:17:45 +09:30
|
|
|
# Can concurrently work with the preloaded StreamPeerBuffer though
|
|
|
|
for key in Common.SNES_PSX_addresses:
|
|
|
|
var d = Common.SNES_PSX_addresses[key]
|
|
|
|
if d.format:
|
|
|
|
var s: STRUCT.StructType
|
|
|
|
if d.format in structdefs:
|
|
|
|
s = structdefs[d.format]
|
|
|
|
else:
|
|
|
|
s = STRUCT.get_structarraytype(d.format, structdefs)
|
|
|
|
structdefs[d.format] = s
|
|
|
|
if not s:
|
|
|
|
assert(false, 'Invalid StructType: "%s"' % d.format)
|
|
|
|
buffer.seek(d.SNES)
|
2023-08-07 21:20:35 +09:30
|
|
|
if '.' in key:
|
|
|
|
var keysplit: PoolStringArray = key.split('.', 1)
|
|
|
|
var k0 := keysplit[0]
|
|
|
|
var k1 = keysplit[1]
|
|
|
|
if k1.is_valid_integer():
|
|
|
|
k1 = int(k1)
|
|
|
|
if not (k0 in snes_data):
|
|
|
|
snes_data[k0] = {k1: s.get_value(buffer, [0, 0])}
|
|
|
|
else:
|
|
|
|
snes_data[k0][k1] = s.get_value(buffer, [0, 0])
|
|
|
|
else:
|
|
|
|
snes_data[key] = s.get_value(buffer, [0, 0])
|
|
|
|
SpriteLoader.load_from_structs(snes_data)
|
|
|
|
MapLoader.load_snes_rom(rom_snes)
|
2023-07-25 16:33:45 +09:30
|
|
|
|
2023-08-01 23:22:31 +09:30
|
|
|
func load_psx_folder(_dirname: String):
|
|
|
|
pass
|
|
|
|
|
|
|
|
func load_psx_image(filename: String):
|
|
|
|
# While it would technically be possible to load everything with no temporary files,
|
|
|
|
# It is more convenient to unpack the small files we care about to the user:// directory
|
|
|
|
var rom_psx := File.new()
|
|
|
|
var error := rom_psx.open(filename, File.READ)
|
|
|
|
if error == OK:
|
|
|
|
var cd := loader_cd_image.new(rom_psx)
|
|
|
|
for key in cd.directory:
|
|
|
|
var s = key.trim_prefix('./')
|
|
|
|
var re_match := psx_productcode_regex.search(s)
|
|
|
|
if re_match:
|
|
|
|
print(re_match.get_string(0))
|
|
|
|
print(cd.directory)
|
|
|
|
|
|
|
|
|
2023-07-25 16:33:45 +09:30
|
|
|
func _ready():
|
2023-08-07 01:17:45 +09:30
|
|
|
structdefs.merge(STRUCT.get_base_structarraytypes())
|
|
|
|
structdefs.merge(STRUCT_SNES.get_structtypes())
|
|
|
|
STRUCT.parse_struct_definitions_from_tsv_filename('res://data/SNES_save.tsv', structdefs)
|
2023-08-07 19:34:46 +09:30
|
|
|
STRUCT.parse_struct_definitions_from_tsv_filename('res://data/SNES_other.tsv', structdefs)
|
2023-08-01 23:22:31 +09:30
|
|
|
var _error := psx_productcode_regex.compile('(S[A-Z]{3}_\\d{3}\\.\\d{2});(\\d)')
|
2023-07-25 16:33:45 +09:30
|
|
|
load_snes_rom(ROM_filename)
|
2023-08-07 19:34:46 +09:30
|
|
|
# Debugging breakpoint
|
|
|
|
pass
|
2023-07-25 16:33:45 +09:30
|
|
|
|
2023-07-26 21:52:54 +09:30
|
|
|
func _exit_tree() -> void:
|
|
|
|
thread.wait_to_finish()
|