represent active pokemon in enum
This commit is contained in:
parent
33d5fb29f3
commit
0c83161f85
|
@ -147,6 +147,9 @@ dependencies = [
|
|||
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ferretro 0.1.0",
|
||||
"libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sdl2 0.32.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -201,6 +204,48 @@ dependencies = [
|
|||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-bigint 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-complex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.41"
|
||||
|
@ -220,6 +265,17 @@ dependencies = [
|
|||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-bigint 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.10"
|
||||
|
@ -574,8 +630,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753"
|
||||
"checksum libretro-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "207b060b02cecbcee6df3d0f5ed38691d5c4df1379dd1acd5c49c9b25d20b439"
|
||||
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
|
||||
"checksum num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf4825417e1e1406b3782a8ce92f4d53f26ec055e3622e1881ca8e9f5f9e08db"
|
||||
"checksum num-bigint 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f9c3f34cdd24f334cb265d9bf8bfa8a241920d026916785747a92f0e55541a1a"
|
||||
"checksum num-complex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fcb0cf31fb3ff77e6d2a6ebd6800df7fdcd106f2ad89113c9130bcd07f93dffc"
|
||||
"checksum num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c8b15b261814f992e33760b1fca9fe8b693d8a65299f20c9901688636cfb746"
|
||||
"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
|
||||
"checksum num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e"
|
||||
"checksum num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2885278d5fe2adc2f75ced642d52d879bffaceb5a2e0b1d4309ffdfb239b454"
|
||||
"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4"
|
||||
"checksum num_enum 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "be601e38e20a6f3d01049d85801cb9b7a34a8da7a0da70df507bbde7735058c8"
|
||||
"checksum num_enum_derive 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b59f30f6a043f2606adbd0addbf1eef6f2e28e8c4968918b63b7ff97ac0db2a7"
|
||||
|
|
|
@ -11,6 +11,9 @@ cc = "^1"
|
|||
ferretro = { path = "../rustro-2" }
|
||||
failure = "^0.1"
|
||||
libloading = "^0.5"
|
||||
num = "0.2"
|
||||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
# example: sdl2_emulator
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
extern crate ferretro;
|
||||
extern crate num;
|
||||
|
||||
#[macro_use]
|
||||
extern crate num_derive;
|
||||
|
||||
pub mod sync;
|
|
@ -3,28 +3,48 @@ use std::fmt::Display;
|
|||
use crate::sync::memory_rw::MemoryRw;
|
||||
use ferretro::retro::wrapper::LibretroWrapper; // want LibretroWrapper.api : LibretroApi.get_memory()
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SyncedPokemonRedBlue {
|
||||
raw: Raw,
|
||||
battle_context: BattleContext,
|
||||
}
|
||||
|
||||
struct Raw {
|
||||
active_pokemon_raw: [u8; 0x27],
|
||||
player_and_party: [u8; 0x19e],
|
||||
pokemon_out: u8,
|
||||
}
|
||||
|
||||
struct BattleContext {
|
||||
active_pokemon: Pokemon,
|
||||
|
||||
}
|
||||
|
||||
impl SyncedPokemonRedBlue {
|
||||
pub fn copy_from_emu<T: MemoryRw>(emu: &T) -> SyncedPokemonRedBlue {
|
||||
let result = SyncedPokemonRedBlue {
|
||||
let raw = Raw {
|
||||
active_pokemon_raw: *emu.peek_region(0xd009, 0).unwrap_or_else(|| &[0; 0x27]),
|
||||
player_and_party: *emu.peek_region(0xd158, 0).unwrap_or_else(|| &[0; 0x19e]),
|
||||
pokemon_out: *emu.peek_region(0xcc2f, 0).unwrap_or(&0),
|
||||
};
|
||||
|
||||
let battle_context = BattleContext {
|
||||
active_pokemon: num::FromPrimitive::from_u8(raw.active_pokemon_raw[0xB]).unwrap_or(Pokemon::Unknown)
|
||||
};
|
||||
|
||||
let result = SyncedPokemonRedBlue {
|
||||
raw: raw,
|
||||
battle_context: battle_context,
|
||||
};
|
||||
|
||||
println!("{}", result);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SyncedPokemonRedBlue {
|
||||
impl Default for Raw {
|
||||
fn default() -> Self {
|
||||
SyncedPokemonRedBlue {
|
||||
Raw {
|
||||
active_pokemon_raw: [0; 0x27],
|
||||
player_and_party: [0; 0x19e],
|
||||
pokemon_out: 0,
|
||||
|
@ -32,8 +52,171 @@ impl Default for SyncedPokemonRedBlue {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for BattleContext {
|
||||
fn default() -> Self {
|
||||
BattleContext {
|
||||
active_pokemon: Pokemon::Rhydon
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SyncedPokemonRedBlue {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "active: pk#{} HP {:?}", &self.active_pokemon_raw[0xB], &self.active_pokemon_raw[0xC..0xE])
|
||||
write!(f, "active: pk {:?} {:?}", &self.battle_context.active_pokemon, &self.raw.active_pokemon_raw[0xB])
|
||||
}
|
||||
}
|
||||
#[derive(FromPrimitive, Debug)]
|
||||
enum Pokemon {
|
||||
Unknown = 0x0,
|
||||
Abra = 0x94,
|
||||
Aerodactyl = 0xAB,
|
||||
Alakazam = 0x95,
|
||||
Arbok = 0x2D,
|
||||
Arcanine = 0x14,
|
||||
Articuno = 0x4A,
|
||||
Beedrill = 0x72,
|
||||
Bellsprout = 0xBC,
|
||||
Blastoise = 0x1C,
|
||||
Bulbasaur = 0x99,
|
||||
Butterfree = 0x7D,
|
||||
Caterpie = 0x7B,
|
||||
Chansey = 0x28,
|
||||
Charizard = 0xB4,
|
||||
Charmander = 0xB0,
|
||||
Charmeleon = 0xB2,
|
||||
Clefable = 0x8E,
|
||||
Clefairy = 0x04,
|
||||
Cloyster = 0x8B,
|
||||
Cubone = 0x11,
|
||||
Dewgong = 0x78,
|
||||
Diglett = 0x3B,
|
||||
Ditto = 0x4C,
|
||||
Dodrio = 0x74,
|
||||
Doduo = 0x46,
|
||||
Dragonair = 0x59,
|
||||
Dragonite = 0x42,
|
||||
Dratini = 0x58,
|
||||
Drowzee = 0x30,
|
||||
Dugtrio = 0x76,
|
||||
Eevee = 0x66,
|
||||
Ekans = 0x6C,
|
||||
Electabuzz = 0x35,
|
||||
Electrode = 0x8D,
|
||||
Exeggcute = 0x0C,
|
||||
Exeggutor = 0x0A,
|
||||
Farfetchd = 0x40,
|
||||
Fearow = 0x23,
|
||||
Flareon = 0x67,
|
||||
Gastly = 0x19,
|
||||
Gengar = 0x0E,
|
||||
Geodude = 0xA9,
|
||||
Gloom = 0xBA,
|
||||
Golbat = 0x82,
|
||||
Goldeen = 0x9D,
|
||||
Golduck = 0x80,
|
||||
Golem = 0x31,
|
||||
Graveler = 0x27,
|
||||
Grimer = 0x0D,
|
||||
Growlithe = 0x21,
|
||||
Gyarados = 0x16,
|
||||
Haunter = 0x93,
|
||||
Hitmonchan = 0x2C,
|
||||
Hitmonlee = 0x2B,
|
||||
Horsea = 0x5C,
|
||||
Hypno = 0x81,
|
||||
Ivysaur = 0x09,
|
||||
Jigglypuff = 0x64,
|
||||
Jolteon = 0x68,
|
||||
Jynx = 0x48,
|
||||
Kabuto = 0x5A,
|
||||
Kabutops = 0x5B,
|
||||
Kadabra = 0x26,
|
||||
Kakuna = 0x71,
|
||||
Kangaskhan = 0x02,
|
||||
Kingler = 0x8A,
|
||||
Koffing = 0x37,
|
||||
Krabby = 0x4E,
|
||||
Lapras = 0x13,
|
||||
Lickitung = 0x0B,
|
||||
Machamp = 0x7E,
|
||||
Machoke = 0x29,
|
||||
Machop = 0x6A,
|
||||
Magikarp = 0x85,
|
||||
Magmar = 0x33,
|
||||
Magnemite = 0xAD,
|
||||
Magneton = 0x36,
|
||||
Mankey = 0x39,
|
||||
Marowak = 0x91,
|
||||
Meowth = 0x4D,
|
||||
Metapod = 0x7C,
|
||||
Mew = 0x15,
|
||||
Mewtwo = 0x83,
|
||||
Moltres = 0x49,
|
||||
MrMime = 0x2A,
|
||||
Muk = 0x88,
|
||||
Nidoking = 0x07,
|
||||
Nidoqueen = 0x10,
|
||||
NidoranF = 0x0F,
|
||||
NidoranM = 0x03,
|
||||
Nidorino = 0xA7,
|
||||
Nidorina = 0xA8,
|
||||
Ninetales = 0x53,
|
||||
Oddish = 0xB9,
|
||||
Omanyte = 0x62,
|
||||
Omastar = 0x63,
|
||||
Onix = 0x22,
|
||||
Paras = 0x6D,
|
||||
Parasect = 0x2E,
|
||||
Persian = 0x90,
|
||||
Pidgeot = 0x97,
|
||||
Pidgeotto = 0x96,
|
||||
Pidgey = 0x24,
|
||||
Pikachu = 0x54,
|
||||
Pinsir = 0x1D,
|
||||
Poliwag = 0x47,
|
||||
Poliwhirl = 0x6E,
|
||||
Poliwrath = 0x6F,
|
||||
Ponyta = 0xA3,
|
||||
Porygon = 0xAA,
|
||||
Primeape = 0x75,
|
||||
Psyduck = 0x2F,
|
||||
Raichu = 0x55,
|
||||
Rapidash = 0xA4,
|
||||
Raticate = 0xA6,
|
||||
Rattata = 0xA5,
|
||||
Rhydon = 0x01,
|
||||
Rhyhorn = 0x12,
|
||||
Sandshrew = 0x60,
|
||||
Sandslash = 0x61,
|
||||
Scyther = 0x1A,
|
||||
Seadra = 0x5D,
|
||||
Seaking = 0x9E,
|
||||
Seel = 0x3A,
|
||||
Shellder = 0x17,
|
||||
Slowbro = 0x08,
|
||||
Slowpoke = 0x25,
|
||||
Snorlax = 0x84,
|
||||
Spearow = 0x05,
|
||||
Squirtle = 0xB1,
|
||||
Starmie = 0x98,
|
||||
Staryu = 0x1B,
|
||||
Tangela = 0x1E,
|
||||
Tauros = 0x3C,
|
||||
Tentacool = 0x18,
|
||||
Tentacruel = 0x9B,
|
||||
Vaporeon = 0x69,
|
||||
Venomoth = 0x77,
|
||||
Venonat = 0x41,
|
||||
Venusaur = 0x9A,
|
||||
Victreebell = 0xBE,
|
||||
Vileplume = 0xBB,
|
||||
Voltorb = 0x06,
|
||||
Vulpix = 0x52,
|
||||
Wartortle = 0xB3,
|
||||
Weedle = 0x70,
|
||||
Weepinbell = 0xBD,
|
||||
Weezing = 0x8F,
|
||||
Wigglytuff = 0x65,
|
||||
Zapdos = 0x4B,
|
||||
Zubat = 0x6B,
|
||||
}
|
Loading…
Reference in New Issue