RNG in MM4 is dictated by 4 bytes @ $E4-E7 that are changed with each frame. In addition, there are certain points (i.e., boss fights) in the game that internally modify the bytes to prevent timing attacks. Manipulation is not feasible outside of a TAS, so we must modify specific code segments to alter the use of RNG. 1. Dust man: Suck event has a 1/4 chance. 0xAD28 LDY #$03 BNE $AD34 DEC $0468,X BNE $AD4C JSR $B71E ; RNG LDA $AE42,Y ; 14 15 14 13 15 14 14 14 13 15 13 14 14 13 13 15 14 13 15 14 13 14 15 13 JSR $F446 ; 15 = suck, 6/24; 13 = dust shot, 14 = jump LDA $0558,X AND #$03 TAY LDA $AE5A,Y STA $0588,X LDA $AE5E,Y STA $05A0,X RTS ******************************************************************************************************************************** 2. Skull man: Skull shield can vary from 0.5 - 4.25s. 0xA8B2 LDA $E4 ADC $E6 STA $E6 ; update RNG byte 3 AND #$07 TAY ; Delay table for skull shield: LDA $AA5C,Y ; 40 FF A0 20 FF 70 30 5A STA $0468,X LDA #$E4 STA $0588,X LDA #$A8 STA $05A0,X RTS ******************************************************************************************************************************** 3. Drill man: Primary action table is 3 options, 2A/2F/30. Dive(2A) starts a timer of 210f (3.5s) once he disappears underground. Your x-coord is queried at 30f (0.5s) before he reappears. 0xB045 LDA #$B8 STA $EF LDY #$01 ; hardcoded initial dive BNE $B055 ; skip RNG DEC $0468,X BNE $B06D JSR $B71E ; RNG LDA $B28F,Y ; 2F 2A 2F 30 2A 2F 30 2F 30 2A 30 2F 30 2A 2A 30 2F 2A 2A 30 2F 2F 2A 2A JSR $F446 ; 2A = dive (9/24 chance), 2F = jump, 30 = bombs LDA $0558,X AND #$03 TAY LDA $B2A7,Y STA $0588,X LDA $B2AB,Y STA $05A0,X RTS ******************************************************************************************************************************** 4. Square machine: Odds of a 1-1 pass are 1/64. 0xBB94 LDA $E4 ADC $E6 STA $E6 ; update RNG byte 3 AND #$07 TAY ; Pass table: LDA $BD4F,Y ; 00 01 01 01 02 02 02 02 STA $0468,X ; 1 = 1/8, 2 = 3/8, 3 = 4/8 LDY $0468,X LDA $BD49,Y STA $03A8,X LDA $BD4C,Y STA $03C0,X RTS ******************************************************************************************************************************** 5. Met Man: Open/close duration 0xA127 LDA $E4 ADC $E5 ; update RNG byte 2 STA $E4 AND #$01 TAY ; Open duration LDA $A354,Y ; Look-up table: 3C 78 STA $0468,X ; Either 1 or 2s 0xA26F LDA $E4 ADC $E5 ; update RNG byte 2 STA $E4 AND #$01 TAY ; Close duration LDA $A352,Y ; Look-up table: B4 F0 STA $0468,X ; Either 3 or 4s ******************************************************************************************************************************** 6. Tako Trash: Fireball/bomb 0xA52B LDA $E4 ADC $E6 ; update RNG byte 3 STA $E6 ; 50/50 chance AND #$01 ; change #$01 to 00 for fireball, FF for bomb BNE $A559 ******************************************************************************************************************************** 7. Dr. Wily: Spawn location, hitbox duration, respawn delay Spawn location 0xB529 LDA $E4 ADC $E5 ; update RNG byte 2 STA $E4 AND #$0F TAY LDA $B8AA,Y ; Spawn location table: 01 00 01 07 02 06 03 05 04 03 05 02 06 01 07 ASL A TAY LDA $B890,Y ; Load YX coords based on above value: STA $0378,X ; YX pairs: 48 54 40 84 30 D4 70 44 88 7C 70 BC D0 34 C0 B4 LDA $B891,Y STA $0330,X Hitbox duration / Respawn delay 0xB5D8 LDA $E4 AND #$01 TAY LDA $B912,Y ; Hitbox duration table: 3C 5A STA $0468,X ; 1 or 1.5s LDA $E5 AND #$01 TAY LDA $B914,Y ; Respawn delay table: 3C 96 STA $0480,X ; 1 or 2.5s ******************************************************************************************************************************** v1: Initial release. v2: Added support for Met Man, Tako Trash, Dr. Wily. Added javascript randomizer for customization: https://jeboo.github.io/mm4_derng/