Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.92 KB | None | 0 0
  1. -- User Input
  2. -- Please note the “Use GBA BIOS” option must be unselected for this script to work properly
  3. -- Or the Disable BIOS INTRO option must be enabled
  4. -- This program work for both Fire Red and Leaf Green without any modification
  5.  
  6. -- Start this script immediately after SRing
  7.  
  8. -- Please enter the seed from IVs to PID in the form 0x******** where the stars are the seed    
  9. targetSeed = 0x125E359C
  10.  
  11. -- Max amount of frames you are willing to wait
  12. maxFrame = 600000
  13.  
  14. -- Number of Savestates to restore before SRing - the larger the better but no more than 65536
  15. -- If you find that the script starts only returning "0000" then try lowering this to a number below the number of seeds it had previously tested!
  16. looptimes = 10000
  17.  
  18.  
  19. --Don’t edit anything below this unless you know what you are doing
  20.  
  21. local rshift = bit.rshift
  22. local lshift = bit.lshift
  23. local band = bit.band
  24. local mdword = memory.readdwordunsigned
  25.  
  26. print("Starting... Please Wait")
  27.  
  28. --Function that does the LCRNG math
  29. function LCRNG(s)
  30.     local a = 0x41C6 * band(s, 0xffff) + rshift(s, 16) * 0x4E6D
  31.     local b = 0x4E6D * band(s, 0xffff) + band(a, 0xffff) * 0x10000 + 0x6073
  32.     return b
  33. end
  34.  
  35. function round(num, numDecimalPlaces)
  36.   local mult = 10^(numDecimalPlaces or 0)
  37.   return math.floor(num * mult + 0.5) / mult
  38. end
  39.  
  40. initialState=savestate.create()
  41. targetHit = 0
  42.  
  43. while targetHit == 0 do
  44.   -- Advances frame to title screen
  45.     titleScreen = 0
  46.     while  titleScreen < 2000 do
  47.         emu.frameadvance()
  48.         titleScreen = titleScreen + 1
  49.     end
  50.  
  51.     savestate.save(initialState)
  52.    
  53.     -- Main loop for advancing frame and taking the base seed to test
  54.     cutSceneCounter = 0
  55.     while (cutSceneCounter < looptimes) and targetHit == 0 do
  56.         cutSceneCounter=cutSceneCounter+1
  57.         savestate.load(initialState)
  58.         emu.frameadvance()
  59.         savestate.save(initialState)
  60.        
  61.         frameCounter=1
  62.        
  63.         joypad.set(1,{A=true})
  64.         a = 0
  65.         while  a < 300 do
  66.             emu.frameadvance()
  67.             a=a+1
  68.         end
  69.         baseSeed=mdword(0x02020000)
  70.         print("Testing "..cutSceneCounter.."/"..looptimes.." "..round(((cutSceneCounter / looptimes) * 100), 5).."% (Init. "..string.format("%04X", baseSeed)..")")
  71.         PRNG=baseSeed
  72.            
  73.         currentFrame = 0
  74.         --Calls the LCRNG math and checks for a match
  75.         while (maxFrame > currentFrame) and targetHit == 0 and baseSeed ~= string.format("%04X", 0000) do
  76.             PRNG=LCRNG(PRNG)
  77.            
  78.             frameCounter=frameCounter + 1
  79.             --print(frameCounter.."/"..maxFrame)
  80.        
  81.             if targetSeed == PRNG then
  82.                 print("Finished. Your base seed is "..string.format("%04X", baseSeed).." And it happens on frame "..string.format("%04d", frameCounter)..".")
  83.                 print("Please stop the script before unpausing.")
  84.                 emu.pause()
  85.                 targetHit=1
  86.             end
  87.             currentFrame = currentFrame + 1  
  88.            
  89.         end
  90.     end
  91.     --Resets game after all frames have been tested for a given SR
  92.     if targetHit == 0 then
  93.         print("SRing...")
  94.         joypad.set(1,{A=true,B=true,select=true,start=true})
  95.         emu.frameadvance()
  96.         joypad.set(1,{A=true,B=true,select=true,start=true})
  97.         emu.frameadvance()
  98.         joypad.set(1,{A=true,B=true,select=true,start=true})
  99.         emu.frameadvance()
  100.         joypad.set(1,{A=true,B=true,select=true,start=true})
  101.         emu.frameadvance()
  102.         joypad.set(1,{A=true,B=true,select=true,start=true})
  103.         emu.frameadvance()
  104.         joypad.set(1,{A=true,B=true,select=true,start=true})
  105.         emu.frameadvance()
  106.         joypad.set(1,{A=true,B=true,select=true,start=true})
  107.         emu.frameadvance()
  108.         joypad.set(1,{A=true,B=true,select=true,start=true})
  109.         emu.frameadvance()
  110.         joypad.set(1,{A=true,B=true,select=true,start=true})
  111.         emu.frameadvance()
  112.         joypad.set(1,{A=true,B=true,select=true,start=true})
  113.         emu.frameadvance()
  114.         joypad.set(1,{A=true,B=true,select=true,start=true})
  115.         emu.frameadvance()
  116.         joypad.set(1,{A=true,B=true,select=true,start=true})
  117.         emu.frameadvance()
  118.         joypad.set(1,{A=true,B=true,select=true,start=true})
  119.         emu.frameadvance()
  120.         joypad.set(1,{A=true,B=true,select=true,start=true})
  121.         emu.frameadvance()
  122.     end
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement