Skip to content

Commit fb99a31

Browse files
committed
Fix SM starter npc count
1 parent 8270fa3 commit fb99a31

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

reader_core/src/gen7/reader.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{game_lib, hook};
22
use crate::pnp;
3+
use core::num::{NonZeroU32, NonZeroU8};
34
use pkm_rs::{Pk7, PokeCrypto};
45

56
struct Gen7Addresses {
@@ -21,6 +22,7 @@ struct Gen7Addresses {
2122
id: u32,
2223
box_cursor: u32,
2324
npc_list: u32,
25+
npc_head_blinking_offset: u32,
2426
}
2527

2628
const SM_ADDRESSES: Gen7Addresses = Gen7Addresses {
@@ -41,7 +43,8 @@ const SM_ADDRESSES: Gen7Addresses = Gen7Addresses {
4143
shiny_charm: 0x330d5930,
4244
id: 0x330d67d0,
4345
box_cursor: 0x30000298,
44-
npc_list: 0x341977b8,
46+
npc_list: 0x341977c4,
47+
npc_head_blinking_offset: 0x2f4,
4548
};
4649

4750
const USUM_ADDRESSES: Gen7Addresses = Gen7Addresses {
@@ -63,6 +66,7 @@ const USUM_ADDRESSES: Gen7Addresses = Gen7Addresses {
6366
id: 0x33012818,
6467
box_cursor: 0x30000298,
6568
npc_list: 0x33f81438,
69+
npc_head_blinking_offset: 0x2fc,
6670
};
6771

6872
pub struct Gen7Reader {
@@ -197,7 +201,20 @@ impl Gen7Reader {
197201
let can_blink = pnp::read::<u32>(npc + 0xe8) == 0;
198202

199203
if is_present && can_blink {
200-
npc_count += 1;
204+
let blink_type =
205+
NonZeroU32::new(pnp::read::<u32>(npc + self.addrs.npc_head_blinking_offset))
206+
.and_then(|struct_ptr| {
207+
NonZeroU32::new(pnp::read::<u32>(struct_ptr.get() + 0x114))
208+
})
209+
.and_then(|struct_ptr| {
210+
NonZeroU8::new(pnp::read::<u8>(struct_ptr.get() + 0xde))
211+
})
212+
.map(|blink_setting| blink_setting.get())
213+
.unwrap_or_default();
214+
let is_blinking = blink_type == 1 || blink_type == 2;
215+
if is_blinking {
216+
npc_count += 1;
217+
}
201218
}
202219
}
203220

0 commit comments

Comments
 (0)