Raagentreg

TCG1 Lua that can advance RNG

Jul 8th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.63 KB | None | 0 0
  1. --[[
  2.  
  3. outdated comments because this was my TCG2 lua, tweaked for imakuni routing
  4.  
  5.  
  6. Hotkeys:
  7. R: Toggle running the display
  8. D: Print your deck to the console
  9. S: Print their deck to the console if you really want??
  10.  
  11. C: Cheat your deck to have Comp Search/PP/Sneak (good for having no basics in hand)
  12. B: Cheat your deck to have all Bulbasaurs (good for having basics in hand)
  13. (These are also toggles, press it again to get your old deck back)
  14.  
  15. A: advance RNG once
  16.  
  17. TAStudio open only:
  18. Q/W/E: Enter your file from the Press Start screen early, easy, or 1 frame late
  19.  
  20. ]]
  21.  
  22. local nome = {"Grass_Energy","Fire_Energy","Water_Energy",
  23. "Lightning_Energy","Fighting_Energy","Psychic_Energy","Double_Colorless_Energy",
  24. "Bulbasaur_LV13","Ivysaur_LV20","Venusaur_LV64(CP!_Promo)","Venusaur_LV67",
  25. "Caterpie_LV13","Metapod_LV21","Butterfree_LV28","Weedle_LV12","Kakuna_LV23",
  26. "Beedrill_LV32","Ekans_LV10","Arbok_LV27","Nidoran_Female_LV13","Nidorina_LV24",
  27. "Nidoqueen_LV43","Nidoran_Male_LV20","Nidorino_LV25","Nidoking_LV48","Zubat_LV10",
  28. "Golbat_LV29","Oddish_LV8","Gloom_LV22","Vileplume_LV35","Paras_LV8",
  29. "Parasect_LV28","Venonat_LV12","Venomoth_LV28","Bellsprout_LV11","Weepinbell_LV28",
  30. "Victreebell_LV42","Grimer_LV17","Muk_LV34","Exeggcute_LV14","Exeggutor_LV35",
  31. "Koffing_LV13","Weezing_LV27","Tangela_LV8_(GB)","Tangela_LV12","Scyther_LV25",
  32. "Pinsir_LV24","Charmander_LV10","CharmelEon_LV32","Charizard_LV76","Vulpix_LV11",
  33. "Ninetails_LV32","Ninetails_LV35_(GB)","Growlithe_LV18","Arcanine_LV34_(Promo)",
  34. "Arcanine_LV45","Ponyta_LV10","Rapidash_LV33","Magmar_LV24","Magmar_LV31_(Fossil)",
  35. "Flareon_LV22_(GB)","Flareon_LV28_(Jungle)","Moltres_LV35",
  36. "Legendary_Moltres_LV37","Squirtle_LV8","Wartortle_LV22","Blastoise_LV52",
  37. "Psyduck_LV15","Golduck_LV27","Poliwag_LV13","Poliwhirl_LV28","Poliwrath_LV48",
  38. "Tentacool_LV10","Tentacruel_LV21","Seel_LV12","Dewgong_LV42","Shellder_LV8",
  39. "Cloyster_LV25","Krabby_LV20","Kingler_LV27","Horsea_LV19","Seadra_LV23",
  40. "Goldeen_LV12","Seaking_LV28","Staryu_LV15","Starmie_LV28","Magikarp_LV8",
  41. "Gyarados_LV41","Lapras_LV31","Vaporeon_LV29_(GB)","Vaporeon_LV42_(Jungle)",
  42. "Omanyte_LV19","Omastar_LV32","Articuno_LV35","Legendary_Articuno_LV37",
  43. "Pikachu_LV12","Pikachu_LV14_(Jungle)","Pikachu_LV16_(promo)",
  44. "Pikachu_LV16_(promo2)","Flying_Pikachu_LV12","Surfing_Pikachu_LV13",
  45. "Surfing_Pikachu_LV13_(2)","Raichu_LV40","Raichu_LV45_(Fossil)","Magnemite_LV13",
  46. "Magnemite_LV15_(GB)","Magneton_LV28","Magneton_LV35_(Fossil)","Voltorb_LV10",
  47. "Electrode_LV35_(GB)","Electrode_LV42_(Jungle)","Electabuzz_LV20_(Promo)",
  48. "Electabuzz_LV35","Jolteon_LV24_(GB)","Jolteon_LV29","Zapdos_LV40",
  49. "Zapdos_LV64_(Fossil)","Legendary_Zapdos_LV68","Sandshrew_LV12","Sandslash_LV33",
  50. "Diglett_LV8","Dugtrio_LV36","Mankey_LV7","Primeape_LV35","Machop_LV20",
  51. "Machoke_LV40","Machamp_LV67","Geodude_LV16","Graveler_LV29","Golem_LV36",
  52. "Onix_LV12","Cubone_LV13","Marowak_LV26_(Jungle)","Marowak_LV32_(GB)",
  53. "Hitmonlee_LV30","Hitmonchan_LV33","Rhyhorn_LV18","Rhydon_LV48","Kabuto_LV9",
  54. "Kabutops_LV30","Aerodactlyl_LV28","Abra_LV10","Kadabra_LV38","Alakazam_LV42",
  55. "Slowpoke_LV9_(Promo)","Slowpoke_LV18_(Fossil)","Slowbro_LV26","Gastly_LV8",
  56. "Gastly_LV17_(Fossil)","Haunter_LV17_(Fossil)","Haunter_LV22","Gengar_LV38",
  57. "Drowzee_LV12","Hypno_LV36","Mr.Mime_LV28","Jynx_LV23","Mewtwo_LV53",
  58. "Mewtwo_LV60_(Promo)","Mewtwo_LV60_(Promo_2)","Mew_LV8_(Promo)",
  59. "Mew_LV15_(CP!_Promo)","Mew_LV23","Pidgey_LV8","Pidgeotto_LV36",
  60. "Pidgeot_LV38_(GB)","Pidgeot_LV40_(Jungle)","Rattata_LV9","Raticate_LV41",
  61. "Spearow_LV13","Fearow_LV27","Clefairy_LV14","Clefable_LV34",
  62. "Jigglypuff_LV12_(Promo)","Jigglypuff_LV13_(GB)","Jigglypuff_LV14_(Jungle)",
  63. "Wigglytuff_LV36","Meowth_LV14_(GB)","Meowth_LV15_(Jungle)","Persian_LV25",
  64. "Farfetch'd_LV20","Doduo_LV10","Dodrio_LV28","Lickitung_LV26","Chansey_LV55",
  65. "Kangaskhan_LV40","Tauros_LV32","Ditto_LV19","Eevee_LV12","Porygon_LV12",
  66. "Snorlax_LV20","Dratini_LV10","Dragonair_LV33","Legendary_Dragonite_LV41",
  67. "Dragonite_LV45","Professor_Oak","Imposter_Professor_Oak","Bill","Mr.Fuji",
  68. "Lass","Imakuni?","Pokemon_Trader","Pokemon_Breeder","Clefairy_Doll",
  69. "Mysterious_Fossil","Energy_Retrieval","Super_Energy_Retrieval","Energy_Search",
  70. "Energy_Removal","Super_Energy_Removal","Switch","Pokemon_Center","Pokeball",
  71. "Scoop_Up","Computer_Search","Pokedex","Pluspower","Defender","Item_Finder",
  72. "Gust_of_Wind","Devolution_Spray","Potion","Super_Potion","Full_Heal","Revive",
  73. "Maintenance","Pokemon_Flute","Gambler","Recycle","","","","","","","","","","",
  74. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  75. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  76. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  77. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  78. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  79. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  80. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  81. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  82. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  83. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  84. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  85. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  86. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  87. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  88. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  89. "","","","","","","","","","","","","","","","","",}
  90.  
  91. --163 Computer Search
  92. --167 PP
  93. --189, 1 for rocket's trap
  94.  
  95. --C400 to C43B: IDs of deck
  96.  
  97.  
  98.  
  99. memory.usememorydomain("System Bus")
  100.  
  101. local DeckLocBegin=0xC300
  102. local MyDeckLocBegin=0xC200
  103. local DeckIDBegin=0xC480
  104. local MyDeckIDBegin=0xC400
  105. local ShuffledDeckBegin=0xC37E
  106. local MyShuffledDeckBegin=0xC27E
  107. local TopCard=0xC3BA
  108. local MyTopCard=0xC2BA
  109. --C23C: My prizes in order
  110. --C242: My hand in order
  111. --C33C: Their prizes (irrelevant)
  112. --C342: Their hand in order
  113.  
  114. --C2C8: My pokemon's health
  115.  
  116. local myDeckCards = {}
  117. local oppHand = {}
  118. local cheated = false
  119. local RNG1 = memory.readbyte(0xCACA)
  120. local RNG2 = memory.readbyte(0xCACB)
  121. local RNG3 = memory.readbyte(0xCACC)
  122. local initRNG1 = RNG1
  123. local initRNG2 = RNG2
  124. local initRNG3 = RNG3
  125.  
  126. --Keyboard states last frame and this frame
  127. prevks = input.get()
  128. curks = input.get()
  129.  
  130. --Should we display everything?
  131. rundisplay = true
  132. --Should we alternate A/B presses to auto-advance text?
  133. runtextskip = false
  134. lastInputWasA = true
  135.  
  136. function cheat(bulba)
  137. if (cheated == false) then
  138. cheated = true
  139. for i=0,59 do
  140. myDeckCards[i] = memory.read_u8(MyDeckIDBegin+(i))
  141. end
  142. for i=0,59 do
  143. local loc = MyDeckIDBegin + (i)
  144. if (bulba) then
  145. --if (i > 5) then
  146. memory.writebyte(loc,2)
  147. --else
  148. --memory.writebyte(loc,1)
  149. --end
  150. --memory.writebyte(loc+1,0)
  151. else
  152. if (i > 40) then
  153. memory.writebyte(loc,187)
  154. elseif (i > 19) then
  155. memory.writebyte(loc,167)
  156. else
  157. memory.writebyte(loc,163)
  158. end
  159. --memory.writebyte(loc+1,1)
  160. end
  161. end
  162. else
  163. cheated = false
  164. for i=0,59 do
  165. local loc = MyDeckIDBegin + (i)
  166. memory.write_u8(loc,myDeckCards[i])
  167. end
  168. end
  169. end
  170.  
  171. function advanceRNG()
  172. --Recreation of the code that advances RNG
  173. local temp = RNG2
  174. temp = bit.rol(temp,2)
  175. if (bit.check(temp,8)) then temp = bit.set(temp,0) end
  176. temp = bit.clear(temp,8)
  177. if (bit.check(temp,9)) then temp = bit.set(temp,1) end
  178. temp = bit.clear(temp,9)
  179. temp = bit.bxor(temp,RNG1)
  180. local carry = bit.check(temp,0)
  181.  
  182. RNG2 = bit.bxor(RNG2,RNG1)
  183.  
  184. temp = RNG3
  185. temp = bit.bxor(temp,RNG1)
  186. RNG1 = temp
  187.  
  188. RNG1 = bit.rol(RNG1,1)
  189. if (carry) then RNG1 = bit.set(RNG1,0) end
  190. carry = bit.check(RNG1,8)
  191. RNG1 = bit.clear(RNG1,8)
  192.  
  193. RNG2 = bit.rol(RNG2,1)
  194. if (carry) then RNG2 = bit.set(RNG2,0) end
  195. RNG2 = bit.clear(RNG2,8)
  196.  
  197. RNG3 = RNG3 + 1
  198. if (RNG3 == 256) then RNG3 = 0 end
  199.  
  200. return (bit.bxor(RNG2,RNG1))
  201. end
  202.  
  203. function randomSlot(size)
  204. --Get a random deck slot 0-59
  205. --This is done by multiplying the RNG value by 60, and taking the left 8 bits
  206. local rng = advanceRNG()
  207. local temp = rng * size
  208. for i=0,7 do
  209. if (bit.check(temp,i+8)) then temp = bit.set(temp,i) else temp = bit.clear(temp,i) end
  210. temp = bit.clear(temp,i+8)
  211. end
  212. return temp
  213. end
  214.  
  215. function shuffleOppHand(size)
  216. --Do 60 location swaps
  217.  
  218. oppHand = {}
  219. for i=0,size-1 do
  220. oppHand[i] = memory.readbyte(0xC342+i)
  221. end
  222. for curLoc=0,size-1 do
  223. local newLoc = randomSlot(size)
  224. local temp = oppHand[curLoc]
  225. oppHand[curLoc] = oppHand[newLoc]
  226. oppHand[newLoc] = temp
  227. end
  228. end
  229.  
  230. function startFile(delay)
  231. joypad.set({A=1})
  232. for i=0,31 do
  233. emu.frameadvance()
  234. end
  235. --print(delay)
  236. if (delay == 0) then
  237. for i=0,10 do
  238. emu.frameadvance()
  239. if (emu.islagged()) then
  240. tastudio.setplayback(emu.framecount()-2)
  241. joypad.set({A=1})
  242. break
  243. end
  244. end
  245. elseif (delay > 0) then
  246. for i=0,10 do
  247. emu.frameadvance()
  248. if (emu.islagged()) then
  249. for i=0,10 do
  250. emu.frameadvance()
  251. if (not emu.islagged()) then
  252. if (delay == 1) then tastudio.setplayback(emu.framecount()-1) end
  253. joypad.set({A=1})
  254. break
  255. end
  256. end
  257. break
  258. end
  259. end
  260. end
  261. end
  262.  
  263. while true do
  264. RNG1 = memory.readbyte(0xCACA)
  265. RNG2 = memory.readbyte(0xCACB)
  266. RNG3 = memory.readbyte(0xCACC)
  267. initRNG1 = RNG1
  268. initRNG2 = RNG2
  269. initRNG3 = RNG3
  270.  
  271. curks = input.get()
  272. --Write the [D]eck to a text file
  273. if (curks["D"] and not prevks["D"]) then
  274. file = io.open("deck.txt","w")
  275. local startSpot = MyDeckIDBegin
  276. for i=0,59 do
  277. print(tostring(i+1) .. ": " .. nome[memory.read_u8(startSpot+(i))])
  278. file:write(tostring(i+1) .. ": " .. nome[memory.read_u8(startSpot+(i))] .. "\r\n")
  279. end
  280. file:flush()
  281. file:close()
  282. end
  283. --[S]py on their deck? I dunno
  284. if (curks["S"] and not prevks["S"]) then
  285. file = io.open("deck.txt","w")
  286. local startSpot = DeckIDBegin
  287. for i=0,59 do
  288. print(tostring(i+1) .. ": " .. nome[memory.read_u8(startSpot+(i))])
  289. file:write(tostring(i+1) .. ": " .. nome[memory.read_u8(startSpot+(i))] .. "\r\n")
  290. end
  291. file:flush()
  292. file:close()
  293. end
  294.  
  295.  
  296.  
  297. --[R]un
  298. if (curks["R"] and not prevks["R"]) then
  299. rundisplay = not rundisplay
  300. end
  301. --[A]dvance text
  302. --[[if (curks["A"] and not prevks["A"]) then
  303. runtextskip = not runtextskip
  304. end]]
  305. --Now [A]dvance RNG
  306. if (curks["A"] and not prevks["A"]) then
  307. advanceRNG()
  308. memory.writebyte(0xCACA, RNG1)
  309. memory.writebyte(0xCACB, RNG2)
  310. memory.writebyte(0xCACC, RNG3)
  311. end
  312. --[C]heat
  313. if (curks["C"] and not prevks["C"]) then
  314. cheat(false)
  315. end
  316. --[B]asics
  317. if (curks["B"] and not prevks["B"]) then
  318. cheat(true)
  319. end
  320.  
  321. if (curks["Q"] and not prevks["Q"]) then
  322. startFile(0)
  323. end
  324. if (curks["W"] and not prevks["W"]) then
  325. startFile(1)
  326. end
  327. if (curks["E"] and not prevks["E"]) then
  328. startFile(2)
  329. end
  330. --Oak
  331. if (curks["O"] and not prevks["O"]) then
  332. myStartSpot = memory.readbyte(MyTopCard)
  333. for i=0,6 do
  334. local draws = memory.readbyte(MyShuffledDeckBegin + myStartSpot + i)
  335. if (nome[memory.read_u8(MyDeckIDBegin+(draws))] ~= nil) then
  336. print(tostring(draws+1) .. ": " .. nome[memory.read_u8(MyDeckIDBegin+(draws))])
  337.  
  338. end
  339. end
  340.  
  341. end
  342.  
  343. local myHandEnd = 0
  344. local handEnd = 0
  345. local prize = 0
  346. --gui.text(1,1,nome[208])
  347. if (rundisplay) then
  348. local prizesPlaced = false
  349.  
  350. for i=0,59 do
  351. --Display both hands
  352. if memory.readbyte(MyDeckLocBegin+i)==8 then prizesPlaced = true end
  353. if memory.readbyte(DeckLocBegin+i)==1 then
  354. if (nome[memory.read_u8(DeckIDBegin+(i))] ~= nil) then
  355. gui.text(241,1+12*handEnd,tostring(i+1) .. ": " .. nome[memory.read_u8(DeckIDBegin+(i))])
  356. end
  357. handEnd=handEnd+1
  358. end
  359. if memory.readbyte(MyDeckLocBegin+i)==1 then
  360. local position = 0
  361. for j=0,58 do
  362. if (memory.readbyte(0xC242+j)==i) then position = j+1 break end
  363. end
  364. if (nome[memory.read_u8(MyDeckIDBegin+(i))] ~= nil) then
  365. gui.text(1,21+12*myHandEnd,tostring(i+1) .. ": " .. nome[memory.read_u8(MyDeckIDBegin+(i))] .. "(" .. position .. ")")
  366. end
  367. myHandEnd=myHandEnd+1
  368. end
  369.  
  370. end
  371. local startSpot = memory.readbyte(TopCard)
  372. local myStartSpot = memory.readbyte(MyTopCard)
  373. --if (!prizesPlaced) maxCards = 9
  374. if (prizesPlaced == false) then
  375. local numPrizes = memory.readbyte(0xCC00)
  376. startSpot = startSpot + numPrizes
  377. myStartSpot = myStartSpot + numPrizes
  378. for i=0,numPrizes-1 do
  379.  
  380. end
  381. end
  382. for i=0,2 do
  383. --Display upcoming draws
  384. local draws = memory.readbyte(ShuffledDeckBegin + startSpot + i)
  385. if (myHandEnd > 0 and nome[memory.read_u8(DeckIDBegin+(draws))] ~= nil) then
  386. gui.text(261,6+12*handEnd,tostring(draws+1) .. ": " .. nome[memory.read_u8(DeckIDBegin+(draws))])
  387. handEnd=handEnd+1
  388. end
  389.  
  390. local draws = memory.readbyte(MyShuffledDeckBegin + myStartSpot + i)
  391. if (myHandEnd > 0 and nome[memory.read_u8(MyDeckIDBegin+(draws))] ~= nil) then
  392. gui.text(21,26+12*myHandEnd,tostring(draws+1) .. ": " .. nome[memory.read_u8(MyDeckIDBegin+(draws))])
  393. myHandEnd=myHandEnd+1
  394. end
  395.  
  396.  
  397. end
  398. for i=0,59 do
  399. --Display our prizes
  400. --C23C: My prizes in order
  401. if memory.readbyte(MyDeckLocBegin+i)==8 then
  402. local position = 0
  403. for j=0,5 do
  404. if (memory.readbyte(0xC23C+j)==i) then position = j+1 break end
  405. end
  406. if (nome[memory.read_u8(MyDeckIDBegin+(i))] ~= nil) then
  407. gui.text(41,31+12*myHandEnd,tostring(i+1) .. ": " .. nome[memory.read_u8(MyDeckIDBegin+(i))] .. "(" .. position .. ")")
  408. end
  409. myHandEnd=myHandEnd+1
  410. end
  411. end
  412.  
  413.  
  414. local ShuffledDeckBegin=0xC37E
  415. local MyShuffledDeckBegin=0xC27E
  416. local TopCard=0xC3BA
  417. local MyTopCard=0xC2BA
  418.  
  419. --Check upcoming flips, and Rocket's Trap results?
  420. gui.text(1,263,RNG1)
  421. gui.text(61,263,RNG2)
  422. gui.text(121,263,RNG3)
  423. gui.text(26,251,memory.read_u32_le(0xCACA))
  424.  
  425. imakuniLocation = memory.readbyte(0xD3DD)
  426. local theClub = ""
  427. if (imakuniLocation % 16 == 0) then theClub = "Fighting"
  428. elseif (imakuniLocation % 16 == 4) then theClub = "Science"
  429. elseif (imakuniLocation % 16 == 8) then theClub = "Lightning"
  430. elseif (imakuniLocation % 16 == 12) then theClub = "Water" end
  431. gui.text(26,239,theClub)
  432.  
  433.  
  434. local checkRocket = false
  435. for i=0,2 do
  436. advanceRNG()
  437. --local flipRNG = bit.check(bit.bxor(RNG2,RNG1),7)
  438. local flipRNG = bit.bxor(RNG2,RNG1) % 2
  439. if (flipRNG == 1) then
  440. gui.text(1+i*60,275,"Tails")
  441. else
  442. gui.text(1+i*60,275,"Heads")
  443. if i == 0 then checkRocket = true end
  444. end
  445. end
  446. --[[ Tried to predict Rocket's Trap card grabs; This isn't how it works
  447. if (checkRocket) then
  448. RNG1 = initRNG1
  449. RNG2 = initRNG2
  450. RNG3 = initRNG3
  451. advanceRNG() --the heads coin
  452. local handSize = memory.readbyte(0xC3F4)
  453. shuffleOppHand(handSize)
  454. for i=handSize-1,handSize-3,-1 do
  455. if (i >= 0) then
  456. gui.text(200,275-(handSize-i-1)*12,((oppHand[i] + 1) .. ": " .. nome[memory.read_s16_le(DeckIDBegin+(oppHand[i]*2))]))
  457. end
  458. end
  459. --Hand shuffle
  460. --C3F4 = number of cards in opponent's hand
  461.  
  462. end]]
  463.  
  464. end
  465. if (runtextskip) then
  466. if (emu.islagged()) then
  467. lastInputWasA = not lastInputWasA
  468. end
  469. if (lastInputWasA) then
  470. joypad.set({B=1})
  471. lastInputWasA = false
  472. else
  473. joypad.set({A=1})
  474. lastInputWasA = true
  475. end
  476. end
  477. prevks = curks
  478. emu.frameadvance()
  479. end
Add Comment
Please, Sign In to add comment