1- use crate :: utils;
1+ use crate :: { pnp , utils} ;
22use chrono:: NaiveDateTime ;
33static mut MAIN_RNG_SEED_TICKS : u32 = 0 ;
44static mut MAIN_RNG_DATE_TIME : NaiveDateTime = NaiveDateTime :: MIN ;
5+ static mut MAIN_RNG_TIME_OFFSET_MS : u64 = 0 ;
56static mut SOS_SEED : u32 = 0 ;
67
78pub fn sos_seed ( ) -> u32 {
@@ -16,33 +17,34 @@ fn init_sfmt_hook(regs: &[u32], _stack_pointer: *mut u32) {
1617
1718pub struct RngSeedContext {
1819 pub init_datetime : NaiveDateTime ,
20+ pub time_offset_ms : u64 ,
1921 pub ticks : u32 ,
2022}
2123
2224pub fn main_rng_seed_context ( ) -> RngSeedContext {
2325 unsafe {
2426 RngSeedContext {
2527 init_datetime : MAIN_RNG_DATE_TIME ,
28+ time_offset_ms : MAIN_RNG_TIME_OFFSET_MS ,
2629 ticks : MAIN_RNG_SEED_TICKS ,
2730 }
2831 }
2932}
3033
31- const THIRTY_YEARS_MS : u64 = 946684800000 ;
32-
3334fn init_main_rng_hook ( _regs : & [ u32 ] , stack_pointer : * mut u32 ) {
3435 let ticks = unsafe { stack_pointer. add ( 4 ) . read ( ) } ;
3536 let console_ms_epoch_low = unsafe { stack_pointer. add ( 12 ) . read ( ) } ;
3637 let console_ms_epoch_high = unsafe { stack_pointer. add ( 13 ) . read ( ) } ;
3738 let console_ms_epoch = ( ( console_ms_epoch_high as u64 ) << 32 ) | ( console_ms_epoch_low as u64 ) ;
38- let standard_ms_epoch = console_ms_epoch. saturating_add ( THIRTY_YEARS_MS ) ;
39- let ms_epoch: i64 = standard_ms_epoch. try_into ( ) . unwrap_or_default ( ) ;
39+ let current_time = pnp:: datetime_from_console_ms ( console_ms_epoch) ;
40+ // Assume we didn't start with any milliseconds and any extra milliseconds was spent loading
41+ let start_ms = ( pnp:: game_start_ms ( ) / 1000 ) * 1000 ;
42+ let time_offset_ms = console_ms_epoch. saturating_sub ( start_ms) ;
4043
4144 unsafe {
4245 MAIN_RNG_SEED_TICKS = ticks;
43- if let Some ( date_time) = NaiveDateTime :: from_timestamp_millis ( ms_epoch) {
44- MAIN_RNG_DATE_TIME = date_time;
45- }
46+ MAIN_RNG_DATE_TIME = current_time;
47+ MAIN_RNG_TIME_OFFSET_MS = time_offset_ms;
4648 }
4749}
4850
0 commit comments