Advertisement
Guest User

Lua Mario Kart Wii

a guest
Sep 16th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.70 KB | None | 0 0
  1. -- Script made by Masterjun to display stuff on the screen of Dolphin.
  2. -- Modified for Mario Kart Wii
  3. -- Variables that need to be changed after the functions.
  4. -- Make sure that you checked "Graphics > Advanced > Show Statistics".
  5.  
  6. --------------------------------------------------------------------------------
  7. --------------------------------------------------------------------------------
  8.  
  9. --appends a string s to a table t as hex values
  10. local function appendstr(t,s)
  11.   for i=1,#s do table.insert(t,string.byte(string.sub(s,i,i))) end
  12.   table.insert(t,0x0A)
  13.   return t
  14. end
  15.  
  16. --converts a number into float
  17. local function tofloat(x)
  18.   if x==0 then return 0 end
  19.   local s = 1
  20.   if x>=0x80000000 then
  21.      s = -1
  22.      x=x-0x80000000
  23.   end
  24.   local e = math.floor(x/0x800000)-127
  25.   local m=(x%0x800000)/0x800000+1
  26.   return s*(2^e)*m
  27. end
  28.  
  29. --converts a table to a string
  30. local function tabletostr(x)
  31.   local s = ""
  32.   for k,v in pairs(x) do s=s..string.format("%02X",v) end
  33.   return s
  34. end
  35.  
  36. --takes two 4byte tables (the thing that returns when you getBytes(addr,4,true)
  37. --it turns the first one into a float string or gives the difference between the
  38. --first one and the second one
  39. --second argument is optional
  40. local function toflstr(x,y)
  41.   local minus = 0
  42.   local s
  43.   local sx = tabletostr(x)
  44.   local sy = ""
  45.   if y then
  46.      sy = tabletostr(y)
  47.      minus=tofloat(tonumber(sy,16))
  48.   end
  49.   s = tostring(tofloat(tonumber(sx,16))-minus)
  50.   return s
  51. end
  52.  
  53. local function getSecondaryPointer(x)
  54.     local sx = tabletostr(x)
  55.     local s = tonumber(sx,16)
  56.     return s
  57. end
  58.  
  59. local function tointstr(x)
  60.     local sx = tabletostr(x)
  61.     local s = tostring(tonumber(sx,16))
  62.     return s
  63. end
  64.  
  65. --scans for a string and returns the address of the first result
  66. --if there is no result it returns nil
  67. local function scanstr(str)
  68.   local startaddr=0
  69.   local stopaddr=0x7fffffffffffffff
  70.   local scan = createMemScan()
  71.   scan.OnlyOneResult=true
  72.   scan.firstScan(soExactValue,vtString,rtTruncated,str,"",startaddr,stopaddr,
  73.   "+W-C",fsmNotAligned,"",false,false,false,true)
  74.   scan.waitTillDone()
  75.   return scan.getOnlyResult()
  76. end
  77.  
  78. --------------------------------------------------------------------------------
  79. --------------------------------------------------------------------------------
  80. -- And again make sure that you checked "Graphics > Advanced > Show Statistics".
  81.  
  82. ----
  83. -- Enter here if you have 64bit Dolphin
  84. local DolphinIs64bit = false
  85. ----
  86.  
  87. -- Here are Addresses that need to be changed either once, once at Dolphin start
  88. -- or once at game start. Since Addresses are written in hex, make sure you have
  89. -- the "0x" before the actual number.
  90.  
  91. -----
  92. -- Follow this: http://tasvideos.org/forum/t/13462 tutorial to get a
  93. -- "pointerscan result". Doubleclick on the Address column and enter the address
  94. -- after the ' "Dolphin.exe"+ ' (don't forget the 0x).
  95. --
  96. -- Has to be adjusted: Once
  97. local GameRAMStartAddress = 0x045F806C
  98. -----
  99.  
  100. -----
  101. -- Choose "String" for Value Type and start a Scan searching "Textures created".
  102. -- There should be only one result, enter that address here.
  103. --
  104. -- Has to be adjusted: Once every game start
  105. local TexturesCreatedAddr = 0x0B3CF55C
  106. -----
  107.  
  108. -----
  109. -- Set the Value Type to "Array of byte" and uncheck "Writable" under Memory
  110. -- Scan Options. Make sure the "Hex" box is checked and search for
  111. --
  112. -- 48 63 D8 48 03 DF 48 83 7D C0 10
  113. -- if you have 64 bit Dolphin
  114. --
  115. -- 83 C4 0C 83 7C 24 1C 10 8D 3C 06
  116. -- if you have 32 bit Dolphin
  117. --
  118. -- There should be one result, rightclick that resuld and click "Disassemble
  119. -- this memory region". Enter the number after the "Dolphin.exe+" at the top.
  120. --
  121. -- Make sure to check "Writable" again, and really check it, because it has
  122. -- three states
  123. --
  124. -- Has to be adjusted: Once
  125. local ArrayOfBytesAddress = 0x3AFE9D
  126. -----
  127.  
  128. -----
  129. -- "local FrameCounterAddress = nil" if you don't want it.
  130. -- Not necessary but it adds a neat Frame- and Movecounter to the screen.
  131. -- When playing or recording a movie scan for the VI-Count+1 (on the top of the
  132. -- game window) and setting the Value Type to 4 Bytes. The first one should be a
  133. -- green address, enter it here.
  134. --
  135. -- Has to be adjusted: Once every Dolphin start
  136. local FrameCounterAddress = nil
  137. -----
  138.  
  139. --------------------------------------------------------------------------------
  140. --------------------------------------------------------------------------------
  141.  
  142. debug_removeBreakpoint(getAddress("Dolphin.exe")+ArrayOfBytesAddress)
  143. debug_setBreakpoint(getAddress("Dolphin.exe")+ArrayOfBytesAddress)
  144.  
  145. function debugger_onBreakpoint()
  146.   local mode=""
  147.   if FrameCounterAddress then
  148.     local curfc=readInteger(FrameCounterAddress)
  149.     local fc=readInteger(FrameCounterAddress+0x08)
  150.     local readonly=readBytes(FrameCounterAddress-((DolphinIs64bit and 0x30) or 0x28))
  151.     mode=curfc.." [recording]"
  152.     if readonly==2 then mode=curfc.."/"..fc.." [playback]"
  153.     elseif readonly==0 then mode=curfc.."/"..fc.." [inactve]" end
  154.   end
  155.  
  156.   local o=readInteger(getAddress("Dolphin.exe")+GameRAMStartAddress)
  157.   local second_pointer = readBytes(0x9C1956+o,2,true)
  158.   local oo = getSecondaryPointer(second_pointer)
  159.  
  160.   -- local variable_name = readBytes(addressoffset+o,4,true)
  161.   local xpos =readBytes(0x395BA4+o,4,true)
  162.   local ypos =readBytes(0x395B84+o,4,true)
  163.   local zpos =readBytes(0x395B94+o,4,true)
  164.   local speed=readBytes(0xE4A0E0+o+oo,4,true)
  165.   local speed2=readBytes(0xE48AD8+o+oo,4,true)
  166.   local tspeed=readBytes(0xE48AD0+o+oo,4,true)
  167.   local mtcharge = readBytes(0xE48BB6+o+oo, 2, true)
  168.   local mtrelease = readBytes(0xE48BC4+o+oo, 2, true)
  169.   local trickrelease = readBytes(0xE48BCC+o+oo, 2, true)
  170.   local boosttimer = readBytes(0xE48C00+o+oo, 2, true)
  171.   local airtime = readBytes(0xE48CD2+o+oo, 2, true)
  172.  
  173.  
  174.   local t = {0x0A,0x0A,0x0A,0x0A,0x0A}
  175.   --0x0A = new line
  176.  
  177.   t = appendstr(t,"xpos: "..toflstr(xpos))
  178.   t = appendstr(t,"ypos: "..toflstr(ypos))
  179.   t = appendstr(t,"zpos (height): "..toflstr(zpos))
  180.   t = appendstr(t,"")
  181.   t = appendstr(t,"speed: "..toflstr(speed))
  182.   t = appendstr(t,"speed (2): "..toflstr(speed2))
  183.   t = appendstr(t,"Max Terrain Speed: "..toflstr(tspeed))
  184.   t = appendstr(t,"")
  185.   t = appendstr(t,"MT charge: "..tointstr(mtcharge))
  186.   t = appendstr(t,"MT release: "..tointstr(mtrelease))
  187.   t = appendstr(t,"Trick release: "..tointstr(trickrelease))
  188.   t = appendstr(t,"Boost timer: "..tointstr(boosttimer))
  189.   t = appendstr(t,"Air time: "..tointstr(airtime))
  190.   t = appendstr(t,"")
  191.   t = appendstr(t,"")
  192.   t = appendstr(t,"")
  193.   t = appendstr(t,"")
  194.   t = appendstr(t,"")
  195.   t = appendstr(t,"")
  196.  
  197.  
  198.  
  199.   table.insert(t,0x00)
  200.   --0x00 = end of text
  201.   writeBytes(TexturesCreatedAddr,t)
  202.   return 1
  203. end
  204. --print(string.format("0x%08X",scanstr("Textures created") or 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement