Guest User

RNG Brute Force Testing Script - Crits

a guest
Feb 11th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. -- RNG Brute Force Script
  2. -- Author: Omnigamer
  3. -- Instructions:
  4. --
  5. -- Fill in the information below according to what you want to test.
  6. -- At the very minimum, you need an address for the RNG and a condition that you want to check.
  7. -- In an emulator, start the script 2 frames before the RNG is checked and the condition you're watching changes.
  8. -- Adapt the condition and tracking according to what you are trying to find out.
  9. -- You will also potentially need to change the RNG function to suit the target game.
  10.  
  11. -- Addresses
  12. RNG_ADDR = 0x00052C;
  13. COND_ADDR = 0x000A18;
  14.  
  15. -- Control values; number of frames to advance and how many times to test
  16. NUM_FRAMES = 1;
  17. NUM_ITER = 1000;
  18.  
  19. -- Sets the RNG to val; assumes a 16-bit RNG
  20. function set_RNG(val)
  21.     mainmemory.write_u16_le(RNG_ADDR,val);
  22. end
  23.  
  24. -- Function that checks whether the condition and reports whatever information
  25. -- you are trying to track from it.
  26. function check_cond()
  27.  
  28.     cond = mainmemory.read_u16_le(COND_ADDR);
  29.    
  30.     -- Adds a point when the condition happens
  31.     if(cond ~= 0x0000) then
  32.         mycount = mycount+1;
  33.     end;
  34.    
  35. end
  36.  
  37. -- Advances the set number of frames. May need to be done when the RNG value is used
  38. -- but the testable action is some number of frames away. Defaults to 1.
  39. function advance_frames(val)
  40.     for i=0,val,1 do
  41.         emu.frameadvance();
  42.     end
  43. end
  44.  
  45. -- Sets up the save states
  46. savestate.save("test_state2");
  47. savestate.load("test_state2");
  48.  
  49. emu.limitframerate(false);
  50.    
  51. -- Initialize some variables
  52. mycount = 0;
  53.    
  54. -- Main testing loop
  55. for i=0,NUM_ITER,1 do
  56.     -- Grab a random value to set the RNG to; adjust size as necessary
  57.     myrand = math.random(0,0xFFFF);
  58.     set_RNG(myrand);
  59.    
  60.     -- Report various things that you're looking for on-screen
  61.     gui.drawText(30,30,string.format("ITER:    %d",i));
  62.     gui.drawText(30,45,string.format("COUNT:   %d",mycount));
  63.     gui.drawText(30,60,string.format("RATE:    %.2f%%",(mycount/i)*100));
  64.    
  65.    
  66.     advance_frames(1);
  67.     check_cond();
  68.     savestate.load("test_state2");
  69.     final = i;
  70. end
  71.    
  72. emu.limitframerate(true);
  73.    
  74. -- After the processing is done, just leave the information on-screen
  75. while true do
  76.     gui.drawText(30,30,string.format("ITER:     %d",final));
  77.     gui.drawText(30,45,string.format("COUNT:    %d",mycount));
  78.     gui.drawText(30,60,string.format("RATE:     %.2f%%",(mycount/final)*100));
  79.     emu.frameadvance();
  80. end
Advertisement
Add Comment
Please, Sign In to add comment