Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- outdated comments because this was my TCG2 lua, tweaked for imakuni routing
- Hotkeys:
- R: Toggle running the display
- D: Print your deck to the console
- S: Print their deck to the console if you really want??
- C: Cheat your deck to have Comp Search/PP/Sneak (good for having no basics in hand)
- B: Cheat your deck to have all Bulbasaurs (good for having basics in hand)
- (These are also toggles, press it again to get your old deck back)
- A: advance RNG once
- TAStudio open only:
- Q/W/E: Enter your file from the Press Start screen early, easy, or 1 frame late
- ]]
- local nome = {"Grass_Energy","Fire_Energy","Water_Energy",
- "Lightning_Energy","Fighting_Energy","Psychic_Energy","Double_Colorless_Energy",
- "Bulbasaur_LV13","Ivysaur_LV20","Venusaur_LV64(CP!_Promo)","Venusaur_LV67",
- "Caterpie_LV13","Metapod_LV21","Butterfree_LV28","Weedle_LV12","Kakuna_LV23",
- "Beedrill_LV32","Ekans_LV10","Arbok_LV27","Nidoran_Female_LV13","Nidorina_LV24",
- "Nidoqueen_LV43","Nidoran_Male_LV20","Nidorino_LV25","Nidoking_LV48","Zubat_LV10",
- "Golbat_LV29","Oddish_LV8","Gloom_LV22","Vileplume_LV35","Paras_LV8",
- "Parasect_LV28","Venonat_LV12","Venomoth_LV28","Bellsprout_LV11","Weepinbell_LV28",
- "Victreebell_LV42","Grimer_LV17","Muk_LV34","Exeggcute_LV14","Exeggutor_LV35",
- "Koffing_LV13","Weezing_LV27","Tangela_LV8_(GB)","Tangela_LV12","Scyther_LV25",
- "Pinsir_LV24","Charmander_LV10","CharmelEon_LV32","Charizard_LV76","Vulpix_LV11",
- "Ninetails_LV32","Ninetails_LV35_(GB)","Growlithe_LV18","Arcanine_LV34_(Promo)",
- "Arcanine_LV45","Ponyta_LV10","Rapidash_LV33","Magmar_LV24","Magmar_LV31_(Fossil)",
- "Flareon_LV22_(GB)","Flareon_LV28_(Jungle)","Moltres_LV35",
- "Legendary_Moltres_LV37","Squirtle_LV8","Wartortle_LV22","Blastoise_LV52",
- "Psyduck_LV15","Golduck_LV27","Poliwag_LV13","Poliwhirl_LV28","Poliwrath_LV48",
- "Tentacool_LV10","Tentacruel_LV21","Seel_LV12","Dewgong_LV42","Shellder_LV8",
- "Cloyster_LV25","Krabby_LV20","Kingler_LV27","Horsea_LV19","Seadra_LV23",
- "Goldeen_LV12","Seaking_LV28","Staryu_LV15","Starmie_LV28","Magikarp_LV8",
- "Gyarados_LV41","Lapras_LV31","Vaporeon_LV29_(GB)","Vaporeon_LV42_(Jungle)",
- "Omanyte_LV19","Omastar_LV32","Articuno_LV35","Legendary_Articuno_LV37",
- "Pikachu_LV12","Pikachu_LV14_(Jungle)","Pikachu_LV16_(promo)",
- "Pikachu_LV16_(promo2)","Flying_Pikachu_LV12","Surfing_Pikachu_LV13",
- "Surfing_Pikachu_LV13_(2)","Raichu_LV40","Raichu_LV45_(Fossil)","Magnemite_LV13",
- "Magnemite_LV15_(GB)","Magneton_LV28","Magneton_LV35_(Fossil)","Voltorb_LV10",
- "Electrode_LV35_(GB)","Electrode_LV42_(Jungle)","Electabuzz_LV20_(Promo)",
- "Electabuzz_LV35","Jolteon_LV24_(GB)","Jolteon_LV29","Zapdos_LV40",
- "Zapdos_LV64_(Fossil)","Legendary_Zapdos_LV68","Sandshrew_LV12","Sandslash_LV33",
- "Diglett_LV8","Dugtrio_LV36","Mankey_LV7","Primeape_LV35","Machop_LV20",
- "Machoke_LV40","Machamp_LV67","Geodude_LV16","Graveler_LV29","Golem_LV36",
- "Onix_LV12","Cubone_LV13","Marowak_LV26_(Jungle)","Marowak_LV32_(GB)",
- "Hitmonlee_LV30","Hitmonchan_LV33","Rhyhorn_LV18","Rhydon_LV48","Kabuto_LV9",
- "Kabutops_LV30","Aerodactlyl_LV28","Abra_LV10","Kadabra_LV38","Alakazam_LV42",
- "Slowpoke_LV9_(Promo)","Slowpoke_LV18_(Fossil)","Slowbro_LV26","Gastly_LV8",
- "Gastly_LV17_(Fossil)","Haunter_LV17_(Fossil)","Haunter_LV22","Gengar_LV38",
- "Drowzee_LV12","Hypno_LV36","Mr.Mime_LV28","Jynx_LV23","Mewtwo_LV53",
- "Mewtwo_LV60_(Promo)","Mewtwo_LV60_(Promo_2)","Mew_LV8_(Promo)",
- "Mew_LV15_(CP!_Promo)","Mew_LV23","Pidgey_LV8","Pidgeotto_LV36",
- "Pidgeot_LV38_(GB)","Pidgeot_LV40_(Jungle)","Rattata_LV9","Raticate_LV41",
- "Spearow_LV13","Fearow_LV27","Clefairy_LV14","Clefable_LV34",
- "Jigglypuff_LV12_(Promo)","Jigglypuff_LV13_(GB)","Jigglypuff_LV14_(Jungle)",
- "Wigglytuff_LV36","Meowth_LV14_(GB)","Meowth_LV15_(Jungle)","Persian_LV25",
- "Farfetch'd_LV20","Doduo_LV10","Dodrio_LV28","Lickitung_LV26","Chansey_LV55",
- "Kangaskhan_LV40","Tauros_LV32","Ditto_LV19","Eevee_LV12","Porygon_LV12",
- "Snorlax_LV20","Dratini_LV10","Dragonair_LV33","Legendary_Dragonite_LV41",
- "Dragonite_LV45","Professor_Oak","Imposter_Professor_Oak","Bill","Mr.Fuji",
- "Lass","Imakuni?","Pokemon_Trader","Pokemon_Breeder","Clefairy_Doll",
- "Mysterious_Fossil","Energy_Retrieval","Super_Energy_Retrieval","Energy_Search",
- "Energy_Removal","Super_Energy_Removal","Switch","Pokemon_Center","Pokeball",
- "Scoop_Up","Computer_Search","Pokedex","Pluspower","Defender","Item_Finder",
- "Gust_of_Wind","Devolution_Spray","Potion","Super_Potion","Full_Heal","Revive",
- "Maintenance","Pokemon_Flute","Gambler","Recycle","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","",}
- --163 Computer Search
- --167 PP
- --189, 1 for rocket's trap
- --C400 to C43B: IDs of deck
- memory.usememorydomain("System Bus")
- local DeckLocBegin=0xC300
- local MyDeckLocBegin=0xC200
- local DeckIDBegin=0xC480
- local MyDeckIDBegin=0xC400
- local ShuffledDeckBegin=0xC37E
- local MyShuffledDeckBegin=0xC27E
- local TopCard=0xC3BA
- local MyTopCard=0xC2BA
- --C23C: My prizes in order
- --C242: My hand in order
- --C33C: Their prizes (irrelevant)
- --C342: Their hand in order
- --C2C8: My pokemon's health
- local myDeckCards = {}
- local oppHand = {}
- local cheated = false
- local RNG1 = memory.readbyte(0xCACA)
- local RNG2 = memory.readbyte(0xCACB)
- local RNG3 = memory.readbyte(0xCACC)
- local initRNG1 = RNG1
- local initRNG2 = RNG2
- local initRNG3 = RNG3
- --Keyboard states last frame and this frame
- prevks = input.get()
- curks = input.get()
- --Should we display everything?
- rundisplay = true
- --Should we alternate A/B presses to auto-advance text?
- runtextskip = false
- lastInputWasA = true
- function cheat(bulba)
- if (cheated == false) then
- cheated = true
- for i=0,59 do
- myDeckCards[i] = memory.read_u8(MyDeckIDBegin+(i))
- end
- for i=0,59 do
- local loc = MyDeckIDBegin + (i)
- if (bulba) then
- --if (i > 5) then
- memory.writebyte(loc,2)
- --else
- --memory.writebyte(loc,1)
- --end
- --memory.writebyte(loc+1,0)
- else
- if (i > 40) then
- memory.writebyte(loc,187)
- elseif (i > 19) then
- memory.writebyte(loc,167)
- else
- memory.writebyte(loc,163)
- end
- --memory.writebyte(loc+1,1)
- end
- end
- else
- cheated = false
- for i=0,59 do
- local loc = MyDeckIDBegin + (i)
- memory.write_u8(loc,myDeckCards[i])
- end
- end
- end
- function advanceRNG()
- --Recreation of the code that advances RNG
- local temp = RNG2
- temp = bit.rol(temp,2)
- if (bit.check(temp,8)) then temp = bit.set(temp,0) end
- temp = bit.clear(temp,8)
- if (bit.check(temp,9)) then temp = bit.set(temp,1) end
- temp = bit.clear(temp,9)
- temp = bit.bxor(temp,RNG1)
- local carry = bit.check(temp,0)
- RNG2 = bit.bxor(RNG2,RNG1)
- temp = RNG3
- temp = bit.bxor(temp,RNG1)
- RNG1 = temp
- RNG1 = bit.rol(RNG1,1)
- if (carry) then RNG1 = bit.set(RNG1,0) end
- carry = bit.check(RNG1,8)
- RNG1 = bit.clear(RNG1,8)
- RNG2 = bit.rol(RNG2,1)
- if (carry) then RNG2 = bit.set(RNG2,0) end
- RNG2 = bit.clear(RNG2,8)
- RNG3 = RNG3 + 1
- if (RNG3 == 256) then RNG3 = 0 end
- return (bit.bxor(RNG2,RNG1))
- end
- function randomSlot(size)
- --Get a random deck slot 0-59
- --This is done by multiplying the RNG value by 60, and taking the left 8 bits
- local rng = advanceRNG()
- local temp = rng * size
- for i=0,7 do
- if (bit.check(temp,i+8)) then temp = bit.set(temp,i) else temp = bit.clear(temp,i) end
- temp = bit.clear(temp,i+8)
- end
- return temp
- end
- function shuffleOppHand(size)
- --Do 60 location swaps
- oppHand = {}
- for i=0,size-1 do
- oppHand[i] = memory.readbyte(0xC342+i)
- end
- for curLoc=0,size-1 do
- local newLoc = randomSlot(size)
- local temp = oppHand[curLoc]
- oppHand[curLoc] = oppHand[newLoc]
- oppHand[newLoc] = temp
- end
- end
- function startFile(delay)
- joypad.set({A=1})
- for i=0,31 do
- emu.frameadvance()
- end
- --print(delay)
- if (delay == 0) then
- for i=0,10 do
- emu.frameadvance()
- if (emu.islagged()) then
- tastudio.setplayback(emu.framecount()-2)
- joypad.set({A=1})
- break
- end
- end
- elseif (delay > 0) then
- for i=0,10 do
- emu.frameadvance()
- if (emu.islagged()) then
- for i=0,10 do
- emu.frameadvance()
- if (not emu.islagged()) then
- if (delay == 1) then tastudio.setplayback(emu.framecount()-1) end
- joypad.set({A=1})
- break
- end
- end
- break
- end
- end
- end
- end
- while true do
- RNG1 = memory.readbyte(0xCACA)
- RNG2 = memory.readbyte(0xCACB)
- RNG3 = memory.readbyte(0xCACC)
- initRNG1 = RNG1
- initRNG2 = RNG2
- initRNG3 = RNG3
- curks = input.get()
- --Write the [D]eck to a text file
- if (curks["D"] and not prevks["D"]) then
- file = io.open("deck.txt","w")
- local startSpot = MyDeckIDBegin
- for i=0,59 do
- print(tostring(i+1) .. ": " .. nome[memory.read_u8(startSpot+(i))])
- file:write(tostring(i+1) .. ": " .. nome[memory.read_u8(startSpot+(i))] .. "\r\n")
- end
- file:flush()
- file:close()
- end
- --[S]py on their deck? I dunno
- if (curks["S"] and not prevks["S"]) then
- file = io.open("deck.txt","w")
- local startSpot = DeckIDBegin
- for i=0,59 do
- print(tostring(i+1) .. ": " .. nome[memory.read_u8(startSpot+(i))])
- file:write(tostring(i+1) .. ": " .. nome[memory.read_u8(startSpot+(i))] .. "\r\n")
- end
- file:flush()
- file:close()
- end
- --[R]un
- if (curks["R"] and not prevks["R"]) then
- rundisplay = not rundisplay
- end
- --[A]dvance text
- --[[if (curks["A"] and not prevks["A"]) then
- runtextskip = not runtextskip
- end]]
- --Now [A]dvance RNG
- if (curks["A"] and not prevks["A"]) then
- advanceRNG()
- memory.writebyte(0xCACA, RNG1)
- memory.writebyte(0xCACB, RNG2)
- memory.writebyte(0xCACC, RNG3)
- end
- --[C]heat
- if (curks["C"] and not prevks["C"]) then
- cheat(false)
- end
- --[B]asics
- if (curks["B"] and not prevks["B"]) then
- cheat(true)
- end
- if (curks["Q"] and not prevks["Q"]) then
- startFile(0)
- end
- if (curks["W"] and not prevks["W"]) then
- startFile(1)
- end
- if (curks["E"] and not prevks["E"]) then
- startFile(2)
- end
- --Oak
- if (curks["O"] and not prevks["O"]) then
- myStartSpot = memory.readbyte(MyTopCard)
- for i=0,6 do
- local draws = memory.readbyte(MyShuffledDeckBegin + myStartSpot + i)
- if (nome[memory.read_u8(MyDeckIDBegin+(draws))] ~= nil) then
- print(tostring(draws+1) .. ": " .. nome[memory.read_u8(MyDeckIDBegin+(draws))])
- end
- end
- end
- local myHandEnd = 0
- local handEnd = 0
- local prize = 0
- --gui.text(1,1,nome[208])
- if (rundisplay) then
- local prizesPlaced = false
- for i=0,59 do
- --Display both hands
- if memory.readbyte(MyDeckLocBegin+i)==8 then prizesPlaced = true end
- if memory.readbyte(DeckLocBegin+i)==1 then
- if (nome[memory.read_u8(DeckIDBegin+(i))] ~= nil) then
- gui.text(241,1+12*handEnd,tostring(i+1) .. ": " .. nome[memory.read_u8(DeckIDBegin+(i))])
- end
- handEnd=handEnd+1
- end
- if memory.readbyte(MyDeckLocBegin+i)==1 then
- local position = 0
- for j=0,58 do
- if (memory.readbyte(0xC242+j)==i) then position = j+1 break end
- end
- if (nome[memory.read_u8(MyDeckIDBegin+(i))] ~= nil) then
- gui.text(1,21+12*myHandEnd,tostring(i+1) .. ": " .. nome[memory.read_u8(MyDeckIDBegin+(i))] .. "(" .. position .. ")")
- end
- myHandEnd=myHandEnd+1
- end
- end
- local startSpot = memory.readbyte(TopCard)
- local myStartSpot = memory.readbyte(MyTopCard)
- --if (!prizesPlaced) maxCards = 9
- if (prizesPlaced == false) then
- local numPrizes = memory.readbyte(0xCC00)
- startSpot = startSpot + numPrizes
- myStartSpot = myStartSpot + numPrizes
- for i=0,numPrizes-1 do
- end
- end
- for i=0,2 do
- --Display upcoming draws
- local draws = memory.readbyte(ShuffledDeckBegin + startSpot + i)
- if (myHandEnd > 0 and nome[memory.read_u8(DeckIDBegin+(draws))] ~= nil) then
- gui.text(261,6+12*handEnd,tostring(draws+1) .. ": " .. nome[memory.read_u8(DeckIDBegin+(draws))])
- handEnd=handEnd+1
- end
- local draws = memory.readbyte(MyShuffledDeckBegin + myStartSpot + i)
- if (myHandEnd > 0 and nome[memory.read_u8(MyDeckIDBegin+(draws))] ~= nil) then
- gui.text(21,26+12*myHandEnd,tostring(draws+1) .. ": " .. nome[memory.read_u8(MyDeckIDBegin+(draws))])
- myHandEnd=myHandEnd+1
- end
- end
- for i=0,59 do
- --Display our prizes
- --C23C: My prizes in order
- if memory.readbyte(MyDeckLocBegin+i)==8 then
- local position = 0
- for j=0,5 do
- if (memory.readbyte(0xC23C+j)==i) then position = j+1 break end
- end
- if (nome[memory.read_u8(MyDeckIDBegin+(i))] ~= nil) then
- gui.text(41,31+12*myHandEnd,tostring(i+1) .. ": " .. nome[memory.read_u8(MyDeckIDBegin+(i))] .. "(" .. position .. ")")
- end
- myHandEnd=myHandEnd+1
- end
- end
- local ShuffledDeckBegin=0xC37E
- local MyShuffledDeckBegin=0xC27E
- local TopCard=0xC3BA
- local MyTopCard=0xC2BA
- --Check upcoming flips, and Rocket's Trap results?
- gui.text(1,263,RNG1)
- gui.text(61,263,RNG2)
- gui.text(121,263,RNG3)
- gui.text(26,251,memory.read_u32_le(0xCACA))
- imakuniLocation = memory.readbyte(0xD3DD)
- local theClub = ""
- if (imakuniLocation % 16 == 0) then theClub = "Fighting"
- elseif (imakuniLocation % 16 == 4) then theClub = "Science"
- elseif (imakuniLocation % 16 == 8) then theClub = "Lightning"
- elseif (imakuniLocation % 16 == 12) then theClub = "Water" end
- gui.text(26,239,theClub)
- local checkRocket = false
- for i=0,2 do
- advanceRNG()
- --local flipRNG = bit.check(bit.bxor(RNG2,RNG1),7)
- local flipRNG = bit.bxor(RNG2,RNG1) % 2
- if (flipRNG == 1) then
- gui.text(1+i*60,275,"Tails")
- else
- gui.text(1+i*60,275,"Heads")
- if i == 0 then checkRocket = true end
- end
- end
- --[[ Tried to predict Rocket's Trap card grabs; This isn't how it works
- if (checkRocket) then
- RNG1 = initRNG1
- RNG2 = initRNG2
- RNG3 = initRNG3
- advanceRNG() --the heads coin
- local handSize = memory.readbyte(0xC3F4)
- shuffleOppHand(handSize)
- for i=handSize-1,handSize-3,-1 do
- if (i >= 0) then
- gui.text(200,275-(handSize-i-1)*12,((oppHand[i] + 1) .. ": " .. nome[memory.read_s16_le(DeckIDBegin+(oppHand[i]*2))]))
- end
- end
- --Hand shuffle
- --C3F4 = number of cards in opponent's hand
- end]]
- end
- if (runtextskip) then
- if (emu.islagged()) then
- lastInputWasA = not lastInputWasA
- end
- if (lastInputWasA) then
- joypad.set({B=1})
- lastInputWasA = false
- else
- joypad.set({A=1})
- lastInputWasA = true
- end
- end
- prevks = curks
- emu.frameadvance()
- end
Add Comment
Please, Sign In to add comment