daily pastebin goal
14%
SHARE
TWEET

MKDS Watch Lua Script

a guest Mar 30th, 2015 212 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----- SCRIPT OPTIONS -----
  2. local verUSA = true -- set to false if using a EUR ROM
  3. local exactSine = false -- set to true to read sine/cosine as int (no rounding means no rounding errors)
  4. local playerID = 0 -- set to 1 to watch your ghost's values
  5. --------------------------
  6.  
  7. local pntCheckNum -- Checkpoint number
  8. local pntPlayerData -- X, Y, Z, speed
  9. local pntCheckData -- Checkpoint data
  10.  
  11. local lap_f = 0
  12.  
  13. local checkpoint, keycheckpoint, checkpointghost, keycheckpointghost = 0,0,0,0,0
  14. local xPos, zPos, yPos, speed, boostall, boostmt, mttime = 0,0,0,0,0,0,0
  15.  
  16. local realspeed, xPosPrev, zPosPrev = 0.0,0,0
  17. local maxspeed = 0
  18.  
  19. local angle, yAngle, driftAngle = 0,0,0
  20. local pAng, pDAng = 0,0
  21. local turnLoss = 0
  22. local grip = 0
  23. local air = "Ground"
  24. local spawnpoint = 0
  25.  
  26. local tSine, tCosi = 0,0
  27. local targSine, targCosi = 0,0
  28.  
  29. function time(secs)
  30.         t_sec = math.floor(secs) % 60
  31.         if (t_sec < 10) then t_secaux = "0" else t_secaux = "" end
  32.         t_min = math.floor(secs / 60)
  33.         t_mili = math.floor(secs * 1000) % 1000
  34.         if (t_mili < 10) then t_miliaux = "00" elseif (t_mili < 100) then t_miliaux = "0" else t_miliaux = "" end
  35.         return (t_min .. ":" .. t_secaux .. t_sec .. ":" .. t_miliaux .. t_mili)
  36. end
  37. function padLeft(str,pad,len)
  38.         for i = #str, len - 1, 1 do
  39.         str = pad .. str end
  40.         return str
  41. end
  42. function prettyFloat(value, neg)
  43.         value = math.floor(value * 10000) / 10000
  44.         local ret
  45.         if (not (value == 1 or value == -1)) then
  46.                 if (value >= 0) then
  47.                         value = " " .. value end
  48.                 ret = string.sub(value .. "000000", 0, 6)
  49.         else
  50.                 if (value == 1) then
  51.                         ret = " 1    "
  52.                 else
  53.                         ret = "-1    "
  54.                 end
  55.         end
  56.         if (not neg) then
  57.                 ret = string.sub(ret, 2, 6)
  58.         end
  59.        
  60.         return ret
  61. end
  62.  
  63. function fn()
  64.         -- Read pointer values
  65.         pntCheckNum = memory.readdword(0x021661B0)
  66.         pntCheckData = memory.readdword(0x02175600)
  67.         if (verUSA) then
  68.                 pntPlayerData = memory.readdword(0x217ACF8)
  69.         else
  70.                 pntPlayerData = memory.readdword(0x217D028)
  71.         end
  72.         pntPlayerData = playerID * 0x5A8 + pntPlayerData
  73.  
  74.         -- Read checkpoint values
  75.         checkpoint = memory.readbytesigned(pntCheckNum + 0xDAE)
  76.         keycheckpoint = memory.readbytesigned(pntCheckNum + 0xDB0)
  77.         checkpointghost = memory.readbytesigned(pntCheckNum + 0xE3A)
  78.         keycheckpointghost = memory.readbytesigned(pntCheckNum + 0xE3C)
  79.        
  80.         -- Lap time
  81.         lap_f = memory.readdword(pntCheckNum + 0xD80) * 1.0 / 60 - 0.05
  82.         if (lap_f < 0) then lap_f = 0 end
  83.  
  84.         -- Read positions and speed
  85.         xPosPrev = xPos
  86.         zPosPrev = zPos
  87.         xPos = memory.readdwordsigned(pntPlayerData + 0x80)
  88.         yPos = memory.readdwordsigned(pntPlayerData + 0x80 + 4)
  89.         zPos = memory.readdwordsigned(pntPlayerData + 0x80 + 8)
  90.         speed = memory.readdwordsigned(pntPlayerData + 0x2A8)
  91.         boostall = memory.readbytesigned(pntPlayerData + 0x238)
  92.         boostmt = memory.readbytesigned(pntPlayerData + 0x23C)
  93.         mttime = memory.readdwordsigned(pntPlayerData + 0x30C)
  94.         maxspeed = memory.readdwordsigned(pntPlayerData + 0xD0)
  95.         -- Real speed
  96.         realspeed = math.sqrt(math.abs(zPosPrev - zPos) * math.abs(zPosPrev - zPos) + math.abs(xPosPrev - xPos) * math.abs(xPosPrev - xPos))
  97.         realspeed = math.floor(realspeed * 10) / 10
  98.        
  99.         -- Read angles, more stuff
  100.         pAng = angle
  101.         pDAng = driftAngle
  102.         angle = memory.readwordsigned(pntPlayerData + 0x236)
  103.         yAngle = memory.readwordsigned(pntPlayerData + 0x234)
  104.         driftAngle = memory.readwordsigned(pntPlayerData + 0x388)
  105.         turnLoss = memory.readdwordsigned(pntPlayerData + 0x2D4)
  106.         grip = memory.readdwordsigned(pntPlayerData + 0x240)
  107.         if (memory.readbyte(pntPlayerData + 0x3DD) == 0) then
  108.                 air = "Ground"
  109.         else
  110.                 air = "Air"
  111.         end
  112.         spawnpoint = memory.readdwordsigned(pntPlayerData + 0x3C4)
  113.        
  114.         -- Travel info, oh no!
  115.         tSine = memory.readdwordsigned(pntPlayerData + 0x68)
  116.         tCosi = memory.readdwordsigned(pntPlayerData + 0x70)
  117.         targSine = memory.readdwordsigned(pntPlayerData + 0x50)
  118.         targCosi = memory.readdwordsigned(pntPlayerData + 0x58)
  119. end
  120.  
  121. function fm()
  122.         -- Display lap time
  123.         gui.text(160,22,"Lap = " .. time(lap_f))
  124.         -- Display speed
  125.         gui.text(1, 10, "Speed      = " .. speed)
  126.         gui.text(1, 20, "Max Speed  = " .. maxspeed)
  127.         -- Display position
  128.         gui.text(1, 37, "X, Z, Y = " .. xPos .. ", " .. zPos .. ", " .. yPos)
  129.         gui.text(1, 47, "Real speed = " .. realspeed)
  130.         -- Display boost time
  131.         gui.text(1, 63, "Boost Timer = " .. boostall .. " (" .. boostmt .. ")")
  132.         gui.text(150, 63, "MT Time = " .. mttime)
  133.         -- Display angles
  134.         local sAng = padLeft("" .. angle," ",6);
  135.         local sDAng = padLeft("" .. driftAngle," ",6);
  136.         local sTAng = padLeft("" .. (angle + driftAngle)," ",6);
  137.         gui.text(1,80,"Angle = " .. sAng .. " + " .. sDAng .. " = " .. sTAng)
  138.         local dAng = padLeft("" .. (angle - pAng)," ",6);
  139.         local dDAng = padLeft("" .. (driftAngle - pDAng)," ",6);
  140.         local dTAng = padLeft("" .. (angle + driftAngle - pAng - pDAng)," ",6);
  141.         gui.text(1,90,"Diff. = " .. dAng .. " + " .. dDAng .. " = " .. dTAng)
  142.         gui.text(1,100,"yAngle = " .. yAngle)
  143.         gui.text(96, 100, air)
  144.         -- More stuff
  145.         gui.text(1,115,"turnLoss = " .. turnLoss)
  146.         local displayGrip = grip
  147.         if (not exactSine) then
  148.                 displayGrip = prettyFloat(grip / 4096, false)
  149.         end
  150.         gui.text(1,130,"grip = " .. displayGrip)
  151.         -- Travel info
  152.         local displayDir = tSine
  153.         local displayTarg = targSine
  154.         if (not exactSine) then
  155.                 displayDir = prettyFloat(tSine / 4096, true)
  156.                 displayTarg = prettyFloat(targSine / 4096, true)
  157.         end
  158.         gui.text(1,145,"Sine = " .. displayDir .. " (" .. displayTarg .. ")")
  159.         displayDir = tCosi
  160.         displayTarg = targCosi
  161.         if (not exactSine) then
  162.                 displayDir = prettyFloat(tCosi / 4096, true)
  163.                 displayTarg = prettyFloat(targCosi / 4096, true)
  164.         end
  165.         gui.text(1,155,"Cosi = " .. displayDir .. " (" .. displayTarg .. ")")
  166.         displayDir = math.sqrt((tSine / 4096) ^ 2 + (tCosi / 4096) ^ 2)
  167.         displayTarg = math.sqrt((targSine / 4096) ^ 2 + (targCosi / 4096) ^ 2)
  168.                 -- These numbers aren't in the game's memory, thus rounding will always happen.
  169.                 displayDir = prettyFloat(displayDir, false)
  170.                 displayTarg = prettyFloat(displayTarg, false)
  171.         gui.text(140, 145, "Total: " .. displayDir)
  172.         gui.text(176, 155, "(" .. displayTarg .. ")")
  173.  
  174.         -- Display checkpoints
  175.         if (spawnpoint > -1) then gui.text(1, 170, "Spawn Point: " .. spawnpoint) end
  176.         gui.text(1, 180, "Checkpoint number (player) = " .. checkpoint .. " (" .. keycheckpoint .. ")")
  177. end
  178.  
  179. emu.registerafter(fn)
  180. gui.register(fm)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top