diff --git a/Data/Sys/Scripts/MKW/MKW_Pointers.lua b/Data/Sys/Scripts/MKW/MKW_Pointers.lua index 56ecc3a..d800005 100644 --- a/Data/Sys/Scripts/MKW/MKW_Pointers.lua +++ b/Data/Sys/Scripts/MKW/MKW_Pointers.lua @@ -1,46 +1,38 @@ local Pointers = {} +function isViable() + local gameID = GetGameID() + if gameID == "RMCE01" or gameID == "RMCP01" or gameID == "RMCJ01" or gameID == "RMCK01" then return true end + return false +end + local function getKMPBasePointer() - local kmpBase - if GetGameID() == "RMCP01" then kmpBase = 0x9BD6E8 - elseif GetGameID() == "RMCE01"then kmpBase = 0x9B8F28 - elseif GetGameID() == "RMCJ01" then kmpBase = 0x9BC748 - elseif GetGameID() == "RMCK01" then kmpBase = 0x9ABD28 - end - return GetPointerNormal(kmpBase, 0x4, 0x0) + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9BD6E8, ["RMCE01"] = 0x9B8F28, ["RMCJ01"] = 0x9BC748, ["RMCK01"] = 0x9ABD28 } + local kmpBase = ptrTable[GetGameID()] + return GetPointerNormal(pointer, 0x4, 0x0) end Pointers.getKMPBasePointer = getKMPBasePointer local function getInputDataPointer() - local inputData - if GetGameID() == "RMCP01" then inputData = 0x9BD70C - elseif GetGameID() == "RMCE01"then inputData = 0x9B8F4C - elseif GetGameID() == "RMCJ01" then inputData = 0x9BC76C - elseif GetGameID() == "RMCK01" then inputData = 0x9ABD4C - end - return inputData + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9BD70C, ["RMCE01"] = 0x9B8F4C, ["RMCJ01"] = 0x9BC76C, ["RMCK01"] = 0x9ABD4C } + return ptrTable[GetGameID()] end Pointers.getInputDataPointer = getInputDataPointer local function getRaceDataPointer() - local raceData - if GetGameID() == "RMCP01" then raceData = 0x9BD728 - elseif GetGameID() == "RMCE01"then raceData = 0x9B8F68 - elseif GetGameID() == "RMCJ01" then raceData = 0x9BC788 - elseif GetGameID() == "RMCK01" then raceData = 0x9ABD68 - end - return raceData + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9BD728, ["RMCE01"] = 0x9B8F68, ["RMCJ01"] = 0x9BC788, ["RMCK01"] = 0x9ABD68 } + return ptrTable[GetGameID()] end Pointers.getRaceDataPointer = getRaceDataPointer local function getRaceInfoPointer(Offset) - local raceInfo - if GetGameID() == "RMCP01" then raceInfo = 0x9BD730 - elseif GetGameID() == "RMCE01"then raceInfo = 0x9B8F70 - elseif GetGameID() == "RMCJ01" then raceInfo = 0x9BC790 - elseif GetGameID() == "RMCK01" then raceInfo = 0x9ABD70 - end - return GetPointerNormal(raceInfo, 0xC, Offset) + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9BD730, ["RMCE01"] = 0x9B8F70, ["RMCJ01"] = 0x9BC790, ["RMCK01"] = 0x9ABD70 } + local pointer = ptrTable[GetGameID()] + return GetPointerNormal(pointer, 0xC, Offset) end Pointers.getRaceInfoPointer = getRaceInfoPointer @@ -50,57 +42,49 @@ end Pointers.getInputPointer = getInputPointer local function getRKSYSPointer() - local saveData - if GetGameID() == "RMCP01" then saveData = 0x9BD748 - elseif GetGameID() == "RMCE01"then saveData = 0x9B8F88 - elseif GetGameID() == "RMCJ01" then saveData = 0x9BC7A8 - elseif GetGameID() == "RMCK01" then saveData = 0x9ABD88 - end - return GetPointerNormal(saveData, 0x14, 0x0) + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9BD748, ["RMCE01"] = 0x9B8F88, ["RMCJ01"] = 0x9BC7A8, ["RMCK01"] = 0x9ABD88 } + local pointer = ptrTable[GetGameID()] + return GetPointerNormal(pointer, 0x14, 0x0) end Pointers.getRKSYSPointer = getRKSYSPointer -local function getPrevPositionPointer(Offset) - local pointer - if GetGameID() == "RMCP01" then pointer = 0x9C18F8 - elseif GetGameID() == "RMCE01"then pointer = 0x9BD110 - elseif GetGameID() == "RMCJ01" then pointer = 0x9C0958 - elseif GetGameID() == "RMCK01" then pointer = 0x9AFF38 - end +local function getPlayerPhysicsHolderPointer(Offset) + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9C18F8, ["RMCE01"] = 0x9BD110, ["RMCJ01"] = 0x9C0958, ["RMCK01"] = 0x9AFF38 } + local pointer = ptrTable[GetGameID()] return GetPointerNormal(pointer, 0xC, 0x10, Offset, 0x0, 0x8, 0x90) end -Pointers.getPrevPositionPointer = getPrevPositionPointer +Pointers.getPlayerPhysicsHolderPointer = getPlayerPhysicsHolderPointer -local function getPositionPointer(Offset) - local pointer - if GetGameID() == "RMCP01" then pointer = 0x9C18F8 - elseif GetGameID() == "RMCE01"then pointer = 0x9BD110 - elseif GetGameID() == "RMCJ01" then pointer = 0x9C0958 - elseif GetGameID() == "RMCK01" then pointer = 0x9AFF38 - end +local function getPlayerPhysicsPointer(Offset) + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9C18F8, ["RMCE01"] = 0x9BD110, ["RMCJ01"] = 0x9C0958, ["RMCK01"] = 0x9AFF38 } + local pointer = ptrTable[GetGameID()] return GetPointerNormal(pointer, 0xC, 0x10, Offset, 0x0, 0x8, 0x90, 0x4) end -Pointers.getPositionPointer = getPositionPointer +Pointers.getPlayerPhysicsPointer = getPlayerPhysicsPointer local function getPlayerBasePointer(Offset) - local pointer - if GetGameID() == "RMCP01" then pointer = 0x9C18F8 - elseif GetGameID() == "RMCE01"then pointer = 0x9BD110 - elseif GetGameID() == "RMCJ01" then pointer = 0x9C0958 - elseif GetGameID() == "RMCK01" then pointer = 0x9AFF38 - end + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9C18F8, ["RMCE01"] = 0x9BD110, ["RMCJ01"] = 0x9C0958, ["RMCK01"] = 0x9AFF38 } + local pointer = ptrTable[GetGameID()] return ReadValue32(pointer, 0xC, 0x10, Offset, 0x10, 0x10) end Pointers.getPlayerBasePointer = getPlayerBasePointer +local function getPlayerStatsPointer(Offset) + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9C18F8, ["RMCE01"] = 0x9BD110, ["RMCJ01"] = 0x9C0958, ["RMCK01"] = 0x9AFF38 } + local pointer = ptrTable[GetGameID()] + return ReadValue32(pointer, 0x20, 0x0, Offset, 0x0, 0x0, 0x14, 0x0) +end +Pointers.getPlayerStatsPointer = getPlayerStatsPointer + local function getFrameOfInputAddress() - local frameaddress - if GetGameID() == "RMCP01" then frameaddress = 0x9C38C0 - elseif GetGameID() == "RMCE01" then frameaddress = 0x9BF0B8 - elseif GetGameID() == "RMCJ01" then frameaddress = 0x9C2920 - elseif GetGameID() == "RMCK01" then frameaddress = 0x9B1F00 - end - return frameaddress + if not isViable() then return 0 end + ptrTable = { ["RMCP01"] = 0x9C38C0, ["RMCE01"] = 0x9BF0B8, ["RMCJ01"] = 0x9C2920, ["RMCK01"] = 0x9B1F00 } + return ptrTable[GetGameID()] end Pointers.getFrameOfInputAddress = getFrameOfInputAddress diff --git a/Data/Sys/Scripts/MKW/MKW_core.lua b/Data/Sys/Scripts/MKW/MKW_core.lua index f3dcc60..42bb299 100644 --- a/Data/Sys/Scripts/MKW/MKW_core.lua +++ b/Data/Sys/Scripts/MKW/MKW_core.lua @@ -135,7 +135,7 @@ end core.getVehicle = getVehicle local function getPos() - local address = Pointers.getPositionPointer(0x0) -- 0x0 first player in the array, to get the most accurate, read playerindex first + local address = Pointers.getPlayerPhysicsPointer(0x0) -- 0x0 first player in the array, to get the most accurate, read playerindex first if address == 0 then return {X = 0, Y = 0, Z = 0} end @@ -144,7 +144,7 @@ end core.getPos = getPos local function getPosGhost() - local address = Pointers.getPositionPointer(0x4) + local address = Pointers.getPlayerPhysicsPointer(0x4) if address == 0 then return {X = 0, Y = 0, Z = 0} end @@ -153,7 +153,7 @@ end core.getPosGhost = getPosGhost local function getPrevPos() - local address = Pointers.getPrevPositionPointer(0x0) + local address = Pointers.getPlayerPhysicsHolderPointer(0x0) if address == 0 then return {X = 0, Y = 0, Z = 0} end @@ -162,7 +162,7 @@ end core.getPrevPos = getPrevPos local function getPrevPosGhost() - local address = Pointers.getPrevPositionPointer(0x4) + local address = Pointers.getPlayerPhysicsHolderPointer(0x4) if address == 0 then return {X = 0, Y = 0, Z = 0} end @@ -193,7 +193,7 @@ end core.getSpdGhost = getSpdGhost local function getInput() - local address = Pointers.getInputPointer(0x0) -- change this to 0x4 for ghost + local address = Pointers.getInputPointer(0x0) local offset = 0x8 -- too lazy to adjust the values beneath... if address == 0 then return {ABLR = 0, X = 0, Y = 0, DPAD = 0} @@ -206,6 +206,20 @@ local function getInput() end core.getInput = getInput +local function getInputGhost() + local address = Pointers.getInputPointer(0x4) + local offset = 0x8 -- too lazy to adjust the values beneath... + + if address == 0 then return {ABLR = 0, X = 0, Y = 0, DPAD = 0} + else return { + ABLR = ReadValue8(address + offset + 0x1), + X = ReadValue8(address + offset + 0xC), + Y = ReadValue8(address + offset + 0xD), + DPAD = ReadValue8(address + offset + 0xF)} + end +end +core.getInputGhost = getInputGhost + local function floatHack(intVal) return string.unpack("f", string.pack("I4", intVal)) end @@ -260,7 +274,7 @@ core.math_atan2 = math_atan2 function getQuaternion() local offset2 = 0xF0 - local address2 = Pointers.getPositionPointer(0x0) + local address2 = Pointers.getPlayerPhysicsPointer(0x0) if(address2 == 0) then return {X = 0, Y = 0, Z = 0, W = 0} end @@ -302,7 +316,7 @@ end core.calculateEuler = calculateEuler local function isSinglePlayer() - local address = Pointers.getPositionPointer(0x4) + local address = Pointers.getPlayerPhysicsPointer(0x4) if address == 0 then return true else return false end @@ -465,7 +479,7 @@ end core.exactFinish = exactFinish local function NormalAccel(spd) - base = Pointers.getPlayerPointer() + base = Pointers.getPlayerBasePointer() local stats = GetPointerNormal(base, 0x14, 0x14, 0x0) local speed = ReadValueFloat(base, 0xC, 0x10, 0x0, 0x10, 0x10, 0x20) -- current vehicle speed -- from RMCE01.ini local p1 = ReadValueFloat(stats, 0x48) -- drift acceleration T1 @@ -490,7 +504,7 @@ end core.NormalAccel = NormalAccel local function DriftAccel(spd) - base = Pointers.getPlayerPointer() + base = Pointers.getPlayerBasePointer() local speed = ReadValueFloat(base, 0xC, 0x10, 0x0, 0x10, 0x10, 0x20) -- current vehicle speed -- from RMCE01.ini local p1 = ReadValueFloat(stats, 0x48) -- drift acceleration T1 local d0 = ReadValueFloat(stats, 0x40) -- drift acceleration A0 @@ -505,13 +519,13 @@ end core.DriftAccel = DriftAccel local function AccelText(spd) - base = Pointers.getPlayerPointer() + base = Pointers.getPlayerBasePointer() local speed = ReadValueFloat(base, 0xC, 0x10, 0x0, 0x10, 0x10, 0x20) -- current vehicle speed -- from RMCE01.ini end core.AccelText = AccelText local function detectAction() - base = Pointers.getPlayerPointer() + base = Pointers.getPlayerBasePointer() local stats = GetPointerNormal(base, 0x14, 0x14, 0x0) local bspeed = ReadValueFloat(stats, 0x18) -- base speed local maxspeed = ReadValueFloat(base, 0xC, 0x10, 0x0, 0x10, 0x10, 0x18) -- current max vehicle speed -- from RMCE01.ini @@ -574,7 +588,7 @@ end core.BoostAccel = BoostAccel local function AccelRates() - base = Pointers.getPlayerPointer() + base = Pointers.getPlayerBasePointer() local stats = GetPointerNormal(base, 0x14, 0x14, 0x0) local speed = ReadValueFloat(base, 0xC, 0x10, 0x0, 0x10, 0x10, 0x20) -- current vehicle speed -- from RMCE01.ini local maxspeed = ReadValueFloat(base, 0xC, 0x10, 0x0, 0x10, 0x10, 0x18) -- current max vehicle speed -- from RMCE01.ini @@ -709,4 +723,4 @@ local function translateKCL() end core.translateKCL = translateKCL -return core +return core \ No newline at end of file diff --git a/Data/Sys/Scripts/MKW/MKW_ghost_core.lua b/Data/Sys/Scripts/MKW/MKW_ghost_core.lua index 3986fbe..da9cab2 100644 --- a/Data/Sys/Scripts/MKW/MKW_ghost_core.lua +++ b/Data/Sys/Scripts/MKW/MKW_ghost_core.lua @@ -7,7 +7,7 @@ local Pointers = require("MKW_Pointers") local ghost_core = {} local function getGhostAddressBase() - local raceData = Pointers.getRaceData2Pointer(0x4) + local raceData = Pointers.getRaceInfoPointer(0x4) local address = ReadValue32(raceData, 0x48, 0x4) local offsetFaceButton = 0x94 @@ -49,7 +49,7 @@ end ghost_core.getGhostAddresses = getGhostAddresses local function getInputStorageAddresses() - local raceData = Pointers.getRaceData2Pointer(0x0) + local raceData = Pointers.getRaceInfoPointer(0x0) local addressF = GetPointerNormal(raceData, 0x48, 0xE8, 0x2C) local addressD = addressF + 0x276C