Advertisement
Faschz

Majora's Mask - instruction_counter

Aug 7th, 2019
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. -- instruction_counter.lua
  2. --
  3. -- This script is designed to run on Majora's Mask (U), however can easily be
  4. -- changed to run on (J) by making changes to addresses/sizes.
  5. --
  6. -- This script is used to find what the values of the "instruction counter" gets
  7. -- overwritten to given specific indices. The instruction counter getting
  8. -- written allows for easily manipulatable text overflow options.
  9. --
  10. -- Author: @Faschz
  11. -- Created: May 5th, 2019
  12.  
  13. -- All specific to the current language/version of the game.
  14. STRING_BASE = 0x1D0714  -- Address to the start of the table for the strings.
  15. LENGTH_BASE = 0x1D07C4  -- Address to the start of the table for the lengths.
  16. ENTRANT_SIZE = 16       -- Size of each entrant of the string table.
  17.  
  18. -- The amount of bytes offset from the start of the written string in order to
  19. -- reach the specific addresses.
  20. INSTRUCTION_OFFSET = 191
  21. PAUSE_OFFSET = 1767
  22.  
  23. -- The calculated required length to overwrite the addresses from the text
  24. -- overflow glitch without the use of the instruction counter.
  25. REQUIRED_LENGTH = INSTRUCTION_OFFSET + 1 -- Address is a short, so add 1
  26.  
  27. file = io.open("instruction_counter.txt", "w")
  28.  
  29. -- The address for the index is a signed short, so the value range is as follows
  30. -- for RTA viable indices.
  31. for index=-300, 300 do
  32.     length = mainmemory.read_s16_be(LENGTH_BASE + 2*index)
  33.    
  34.     -- Check if the length is high enough to overwrite the "instruction counter"
  35.     -- while also being low enough as to not overwrite the menu type and debug
  36.     -- menu short
  37.     if (length >= REQUIRED_LENGTH and length < PAUSE_OFFSET) then
  38.         instruction = mainmemory.read_u16_be(STRING_BASE + ENTRANT_SIZE*index +
  39.                                                 INSTRUCTION_OFFSET)
  40.         file:write(index.." --- "..length.." --- "..instruction.."\n")
  41.     end
  42. end
  43.  
  44. file:close()
  45.  
  46. print("Finished instruction_counter.lua!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement