Advertisement
Masterjun

Lua in Cheat Engine for Dolphin

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