Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
Continue work on setting up data structures and loading the json in
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDistructo committed Mar 3, 2024
1 parent 3779b49 commit 5694785
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 19 deletions.
32 changes: 20 additions & 12 deletions worlds/pokemon_platinum/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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]]:
Expand All @@ -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()
7 changes: 7 additions & 0 deletions worlds/pokemon_platinum/data/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tag": "ITEM_LOCATION_DESC",
"long_description": "Location - Item by Pond",
"location": "LOCATION_ROUTE",
"item_flag": "0x504",
"vanilla_item": 1
}
7 changes: 0 additions & 7 deletions worlds/pokemon_platinum/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions worlds/pokemon_platinum/rom_patcher.py
Original file line number Diff line number Diff line change
@@ -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


74 changes: 74 additions & 0 deletions worlds/pokemon_platinum/structs.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5694785

Please sign in to comment.