From 56947858346194939a77f72cc9d21b86b14ff700 Mon Sep 17 00:00:00 2001 From: MaxDistructo Date: Sun, 3 Mar 2024 07:41:52 -0700 Subject: [PATCH] Continue work on setting up data structures and loading the json in --- worlds/pokemon_platinum/data.py | 32 ++++++----- worlds/pokemon_platinum/data/test.json | 7 +++ worlds/pokemon_platinum/options.py | 7 --- worlds/pokemon_platinum/rom_patcher.py | 7 +++ worlds/pokemon_platinum/structs.py | 74 ++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 19 deletions(-) create mode 100644 worlds/pokemon_platinum/data/test.json create mode 100644 worlds/pokemon_platinum/rom_patcher.py create mode 100644 worlds/pokemon_platinum/structs.py diff --git a/worlds/pokemon_platinum/data.py b/worlds/pokemon_platinum/data.py index ae633e947411..10b33926c53c 100644 --- a/worlds/pokemon_platinum/data.py +++ b/worlds/pokemon_platinum/data.py @@ -4,20 +4,25 @@ defined data (like location labels or usable pokemon species), some cleanup and sorting, and Warp methods. """ -from dataclasses import dataclass import copy -from enum import IntEnum import orjson from typing import Dict, List, NamedTuple, Optional, Set, FrozenSet, Tuple, Any, Union import pkgutil -import pkg_resources +from .structs import ItemEntry, LocationEntry, TriggerEntry, TrainerEntry from BaseClasses import ItemClassification -SAVE_FILE_OFFSET = 0x27E000 FLAGS_OFFSET = 0xFEC PKTCH_OFFSET = 0x1163 -BASE_OFFSET = 0x38C750 + +# These are all to data 001, not 000 +# Trainer Pokemon Data +TRPOKE_DATA_OFFSET = 0x372633C +# Trainer Data +TRDATA_DATA_OFFSET = 0x371FD48 +# Map Event Data (needed to change what items are given) +EVENT_DATA_OFFSET = 0x471C2F4 + class SpeciesData: name: str @@ -35,8 +40,8 @@ class PokemonPlatinumData: rom_addresses: Dict[str, int] # #regions: Dict[str, RegionData] - #locations: Dict[str, LocationData] - #items: Dict[int, ItemData] + locations: Dict[LocationEntry] + items: Dict[ItemEntry] #species: List[Optional[SpeciesData]] #static_encounters: List[StaticEncounterData] #tmhm_moves: List[int] @@ -59,14 +64,14 @@ def __init__(self) -> None: self.tmhm_moves = [] self.abilities = [] self.maps = [] - self.warps = {} - self.warp_map = {} + #self.warps = {} + #self.warp_map = {} self.trainers = [] self.rom_addresses["globalPtr"] = 0xBA8 # Set on game load self.rom_addresses["versionPtr"] = 0x0 - self.rom_addresses["safefileBase"] = 0x0 + self.rom_addresses["savefileBase"] = 0x0 def load_json_data(data_name: str) -> Union[List[Any], Dict[str, Any]]: @@ -83,11 +88,14 @@ def create_data_copy() -> PokemonPlatinumData: new_copy.maps = copy.deepcopy(data.maps) new_copy.static_encounters = copy.deepcopy(data.static_encounters) new_copy.trainers = copy.deepcopy(data.trainers) + return new_copy def _init() -> None: + data.items = load_json_data("items.json") + data.items.append(load_json_data("hidden_items.json")) + data.locations = load_json_data("locations.json") + data.trainers = load_json_data("trainers.json") print('unimplemented') - - _init() diff --git a/worlds/pokemon_platinum/data/test.json b/worlds/pokemon_platinum/data/test.json new file mode 100644 index 000000000000..990df54e0fe6 --- /dev/null +++ b/worlds/pokemon_platinum/data/test.json @@ -0,0 +1,7 @@ +{ + "tag": "ITEM_LOCATION_DESC", + "long_description": "Location - Item by Pond", + "location": "LOCATION_ROUTE", + "item_flag": "0x504", + "vanilla_item": 1 + } \ No newline at end of file diff --git a/worlds/pokemon_platinum/options.py b/worlds/pokemon_platinum/options.py index daeef4e6ecf0..1eeef5574fe5 100644 --- a/worlds/pokemon_platinum/options.py +++ b/worlds/pokemon_platinum/options.py @@ -127,13 +127,6 @@ class DarkCavesRequireFlash(DefaultOnToggle): display_name = "Require Flash" -class EnableFerry(Toggle): - """ - The ferry between Slateport, Lilycove, and the Battle Frontier can be used if you have the S.S. Ticket - """ - display_name = "Enable Ferry" - - class EliteFourRequirement(Choice): """ Sets the requirements to challenge the elite four diff --git a/worlds/pokemon_platinum/rom_patcher.py b/worlds/pokemon_platinum/rom_patcher.py new file mode 100644 index 000000000000..21c6143dc5df --- /dev/null +++ b/worlds/pokemon_platinum/rom_patcher.py @@ -0,0 +1,7 @@ + +def write_level_script(): + # Load existing level script data + print("read file") + # Append on our script data, this causes it to run our script every time the variable is set to say we have an item + + diff --git a/worlds/pokemon_platinum/structs.py b/worlds/pokemon_platinum/structs.py new file mode 100644 index 000000000000..50967a7444ea --- /dev/null +++ b/worlds/pokemon_platinum/structs.py @@ -0,0 +1,74 @@ +from ctypes import * + + +# Entry in trdata specifies this +class TrainerData: + type: c_uint8 + trainer_class: c_uint8 + sprite: c_uint8 + party_size: c_uint8 + items: c_uint16 + ai_mask: c_uint32 + battle_type: c_uint32 + + +# Entries in trpoke specify this +class TrainerPokemonData: + # WHY IS THIS A u16? It's a value from 0-255 + dv: c_uint16 + # WHY IS THIS A u16? 1-100 FITS IN A u8 + level: c_uint16 + # Composite mask of the Pokemon's level (least-significant 10 bits) and form (most-significant 6 bits) + species: c_uint16 + # Optional + item: c_uint16 + # Optional + moves: c_uint16[4] + seal: c_uint16 + + +# Regular scripts should be PRE-PATCHED as a part of the base patch, this is so we can automate patching. +# There is 2 types of LevelScript. First, IDs 2, 3, and 4 are structured as so: +class LevelScript: + id: c_uint8 + value: c_int32 + + +# ID 1 type, the type we inject, is structured as so +# Level scripts are padded at the end to fill the word (this is why we need to know the format) +class LevelScriptWithVar: + id: c_uint8 + # This is ALWAYS 1 + value: c_int32 + padding: c_uint8 + variable_id: c_uint16 + expected_val: c_uint16 + script_id: c_uint32 + + +class LocationEntry: + tag: str + connections: list + access_requirements: list + + +class ItemEntry: + tag: str + long_desc: str + location: str + item_flag: int + vanilla_item: int + classification: str + + +class TriggerEntry: + tag: str + location: str + trigger_flag: int + trigger_group: str + + +class TrainerEntry: + tag: str + location: str + flag: int