Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triple layer metatiles #5282

Open
wants to merge 29 commits into
base: upcoming
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d5a3dbd
first implementation
pkmnsnfrn Aug 28, 2024
1e71c04
first implementation
pkmnsnfrn Aug 28, 2024
1df3813
first implementation
pkmnsnfrn Aug 28, 2024
9026fb3
first
pkmnsnfrn Aug 28, 2024
efc1547
first
pkmnsnfrn Aug 28, 2024
bbd6226
Fixed shop.c
pkmnsnfrn Aug 29, 2024
ee5ae2e
Updated migration scripts
pkmnsnfrn Aug 29, 2024
42204f9
Updated migration scripts
pkmnsnfrn Aug 29, 2024
a046600
Updated migration scripts
pkmnsnfrn Aug 29, 2024
240e55c
updated overworld config
pkmnsnfrn Aug 29, 2024
2fa1327
Updated readme
pkmnsnfrn Aug 29, 2024
8738871
Updated readme
pkmnsnfrn Aug 29, 2024
2e5cb1c
Removed hex
pkmnsnfrn Aug 29, 2024
41c2271
Removed hex
pkmnsnfrn Aug 29, 2024
a66e0e0
first version of consolidation
pkmnsnfrn Aug 30, 2024
c9cdebd
next version of consolidation
pkmnsnfrn Aug 30, 2024
fa003e1
FRLG fixes
pkmnsnfrn Aug 30, 2024
1718cf0
FRLG fixes
pkmnsnfrn Aug 30, 2024
168de91
got down to a single layer function
pkmnsnfrn Aug 30, 2024
9f5d8ac
removed config
pkmnsnfrn Aug 31, 2024
f0f7228
removed triple function
pkmnsnfrn Aug 31, 2024
2d6f73e
Merge branch 'upcoming' into tripleLayerMetatiles
pkmnsnfrn Aug 31, 2024
3999179
Merge branch 'upcoming' into tripleLayerMetatiles
pkmnsnfrn Sep 1, 2024
2b32f4c
Merge branch 'upcoming' into tripleLayerMetatiles
pkmnsnfrn Sep 6, 2024
7006370
Merge branch 'upcoming' into tripleLayerMetatiles
pkmnsnfrn Sep 12, 2024
3870444
Fixed spelling of transparent thanks to Jaizu
pkmnsnfrn Sep 22, 2024
fcd4685
Merge branch 'upcoming' into tripleLayerMetatiles
pkmnsnfrn Sep 22, 2024
8373572
Merge branch 'upcoming' into tripleLayerMetatiles
pkmnsnfrn Sep 30, 2024
64f8b71
Merge branch 'upcoming' into tripleLayerMetatiles
pkmnsnfrn Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/fieldmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define NUM_PALS_TOTAL 13
#define MAX_MAP_DATA_SIZE 10240

#define NUM_TILES_PER_METATILE 8
#define NUM_TILES_PER_METATILE 12

// Map coordinates are offset by 7 when using the map
// buffer because it needs to load sufficient border
Expand Down
105 changes: 105 additions & 0 deletions migration_scripts/1.10/frlg_triple_layer_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import os
import struct

layer_type_mask = 0x60000000
layer_type_shift = 29
tileset_root = './data/tilesets'

if not os.path.exists("Makefile"):
print("Please run this script from the root folder containing the Makefile.")
exit(1)

primary_path = os.path.join(tileset_root, 'primary')
secondary_path = os.path.join(tileset_root, 'secondary')

if not os.path.exists(primary_path):
print(f"[ERR] The primary folder does not exist within {tileset_root}, aborting.")
exit(1)

if not os.path.exists(secondary_path):
print(f"[ERR] The secondary folder does not exist within {tileset_root}, aborting.")
exit(1)

tileset_dirs = []

_, dirs, _ = next(os.walk(primary_path))
tileset_dirs += [os.path.join(primary_path, d) for d in dirs]
_, dirs, _ = next(os.walk(secondary_path))
tileset_dirs += [os.path.join(secondary_path, d) for d in dirs]

for tileset_dir in tileset_dirs:
tileset_name = os.path.basename(tileset_dir)
metatiles_path = os.path.join(tileset_dir, 'metatiles.bin')
metatile_attributes_path = os.path.join(tileset_dir, 'metatile_attributes.bin')

if not os.path.exists(metatiles_path):
print(f"[SKIP] {tileset_name} skipped because metatiles.bin was not found.")
continue
if not os.path.exists(metatile_attributes_path):
print(f"[SKIP] {tileset_name} skipped because metatile_attributes.bin was not found.")
continue
if os.path.getsize(metatiles_path) != 4*os.path.getsize(metatile_attributes_path):
print(f"[SKIP] {tileset_name} skipped because metatiles.bin is not four times the size of metatile_attributes.bin (already converted?)")
continue

layer_types = []
meta_attributes = []
with open(metatile_attributes_path, 'rb') as fileobj:
for chunk in iter(lambda: fileobj.read(4), ''):
if chunk == b'':
break
metatile_attribute = struct.unpack('<I', chunk)[0]
meta_attributes.append(metatile_attribute & 0x9FFFFFFF)
layer_types.append((metatile_attribute & layer_type_mask) >> layer_type_shift)

i = 0
new_metatile_data = []

with open(metatiles_path, 'rb') as fileobj:
for chunk in iter(lambda: fileobj.read(16), ''):
if chunk == b'':
break
metatile_data = struct.unpack('<HHHHHHHH', chunk)
if layer_types[i] == 0:
new_metatile_data += [0]*4
new_metatile_data += metatile_data
elif layer_types[i] == 1:
new_metatile_data += metatile_data
new_metatile_data += [0]*4
elif layer_types[i] == 2:
new_metatile_data += metatile_data[:4]
new_metatile_data += [0]*4
new_metatile_data += metatile_data[4:]
else:
new_metatile_data += [0]*12
i += 1

metatile_buffer = struct.pack(f'<{len(new_metatile_data)}H', *new_metatile_data)
metatile_attribute_buffer = struct.pack(f'<{len(meta_attributes)}I', *meta_attributes)
with open(metatiles_path, 'wb') as fileobj:
fileobj.write(metatile_buffer)
with open(metatile_attributes_path, 'wb') as fileobj:
fileobj.write(metatile_attribute_buffer)
print(f'[OK] Converted {tileset_name}')

config_path = './porymap.project.cfg'

if os.path.exists(config_path):
with open(config_path, 'r') as file:
config_lines = file.readlines()

modified = False
for i, line in enumerate(config_lines):
if "enable_triple_layer_metatiles=0" in line:
config_lines[i] = "enable_triple_layer_metatiles=1\n"
modified = True

if modified:
with open(config_path, 'w') as file:
file.writelines(config_lines)
print("[OK] Porymap has been changed to enable triple layer metatiles. If you have the program open, please close it and open it again.")
else:
print("[OK] Porymap already enabled triple layer metatiles.")
else:
print("[WARN] Porymap's project config file could not be found to automatically enable triple layer metatiles.")

100 changes: 100 additions & 0 deletions migration_scripts/1.10/rse_triple_layer_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import os
import struct

layer_type_mask = 0xF000
layer_type_shift = 12
tileset_root = './data/tilesets'

if not os.path.exists("Makefile"):
print("Please run this script from the root folder containing the Makefile.")
exit(1)

primary_path = os.path.join(tileset_root, 'primary')
secondary_path = os.path.join(tileset_root, 'secondary')

if not os.path.exists(primary_path):
print(f"[ERR] The primary folder does not exist within {tileset_root}, aborting.")
exit(1)

if not os.path.exists(secondary_path):
print(f"[ERR] The secondary folder does not exist within {tileset_root}, aborting.")
exit(1)

tileset_dirs = []

_, dirs, _ = next(os.walk(primary_path))
tileset_dirs += [os.path.join(primary_path, d) for d in dirs]
_, dirs, _ = next(os.walk(secondary_path))
tileset_dirs += [os.path.join(secondary_path, d) for d in dirs]

for tileset_dir in tileset_dirs:
tileset_name = os.path.basename(tileset_dir)
metatiles_path = os.path.join(tileset_dir, 'metatiles.bin')
metatile_attributes_path = os.path.join(tileset_dir, 'metatile_attributes.bin')

if not os.path.exists(metatiles_path):
print(f"[SKIP] {tileset_name} skipped because metatiles.bin was not found.")
continue
if not os.path.exists(metatile_attributes_path):
print(f"[SKIP] {tileset_name} skipped because metatile_attributes.bin was not found.")
continue
if os.path.getsize(metatiles_path) != 8 * os.path.getsize(metatile_attributes_path):
print(f"[SKIP] {tileset_name} skipped because metatiles.bin is not eight times the size of metatile_attributes.bin (already converted?)")
continue

layer_types = []
meta_attributes = []
with open(metatile_attributes_path, 'rb') as fileobj:
while (chunk := fileobj.read(2)):
metatile_attribute = struct.unpack('<H', chunk)[0]
meta_attributes.append(metatile_attribute & 0x0FFF)
layer_types.append((metatile_attribute & layer_type_mask) >> layer_type_shift)

i = 0
new_metatile_data = []

with open(metatiles_path, 'rb') as fileobj:
while (chunk := fileobj.read(16)):
metatile_data = struct.unpack('<HHHHHHHH', chunk)
if layer_types[i] == 0:
new_metatile_data += [0]*4
new_metatile_data += metatile_data
elif layer_types[i] == 1:
new_metatile_data += metatile_data
new_metatile_data += [0]*4
elif layer_types[i] == 2:
new_metatile_data += metatile_data[:4]
new_metatile_data += [0]*4
new_metatile_data += metatile_data[4:]
else:
new_metatile_data += [0]*12
i += 1

metatile_buffer = struct.pack(f'<{len(new_metatile_data)}H', *new_metatile_data)
metatile_attribute_buffer = struct.pack(f'<{len(meta_attributes)}H', *meta_attributes)
with open(metatiles_path, 'wb') as fileobj:
fileobj.write(metatile_buffer)
with open(metatile_attributes_path, 'wb') as fileobj:
fileobj.write(metatile_attribute_buffer)
print(f'[OK] Converted {tileset_name}')

config_path = './porymap.project.cfg'

if os.path.exists(config_path):
with open(config_path, 'r') as file:
config_lines = file.readlines()

modified = False
for i, line in enumerate(config_lines):
if "enable_triple_layer_metatiles=0" in line:
config_lines[i] = "enable_triple_layer_metatiles=1\n"
modified = True

if modified:
with open(config_path, 'w') as file:
file.writelines(config_lines)
print("[OK] Porymap has been changed to enable triple layer metatiles. If you have the program open, please close it and open it again.")
else:
print("[OK] Porymap already enabled triple layer metatiles.")
else:
print("[WARN] Porymap's project config file could not be found to automatically enable triple layer metatiles.")
33 changes: 33 additions & 0 deletions migration_scripts/1.10/triple_layer_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import subprocess

# Define the paths to the scripts
rse_script_path = 'migration_scripts/1.10/rse_triple_layer_converter.py'
frlg_script_path = 'migration_scripts/1.10/frlg_triple_layer_converter.py'

# Ask the user to select a mode
print("What style metatiles is your project using?")
print("1. Emerald (if you are unsure, select this one.")
print("2. FRLG")
mode = input("Enter your choice (1 or 2): ")

# Determine the script to run based on the user's choice
if mode == '1':
script_path = rse_script_path
elif mode == '2':
script_path = frlg_script_path
else:
print("Invalid selection, aborting.")
exit(1)

# Check if the script file exists
if not os.path.exists(script_path):
print(f"[ERR] The script {script_path} does not exist, aborting.")
exit(1)

# Run the selected script
try:
subprocess.run(['python3', script_path], check=True)
except subprocess.CalledProcessError as e:
print(f"[ERR] Failed to run {script_path}: {e}")

11 changes: 10 additions & 1 deletion migration_scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ python3 migration_scripts/*.py ; #run the migration script

`*` will need to be replaced with the name of the appropriate script.

## 1.9.x to 1.10.x+

### Triple Metatile Layers

* Filepath [`migration_scripts/1.10/triple_layer_converter.py`](1.10/triple_layer_converter.py)
* Introduced in https://github.com/rh-hideout/pokeemerald-expansion/pull/5282

With Triple Metatile Layers, developers have full control over all the BG layers in the overworld, as opposed to the default 2. This script needs to be run for all projects not currently using Triple Metatile Layers.

## 1.8.x to 1.9.x+

### Battle Anim Moves
Expand Down Expand Up @@ -356,4 +365,4 @@ Replaces itemTableId with heldItem and evSpread with ev.
+ .ev = TRAINER_PARTY_EVS(252, 0, 0, 0, 252, 0),
.nature = NATURE_RELAXED
},
```
```
Loading
Loading