Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. -- This is a sample script for Metroid Prime.
  2. -- It's simpler and less structured than the other game scripts
  3. -- (F-Zero GX, Super Mario Galaxy, etc.).
  4. -- It's meant to be easier to follow (or at least to imitate) for anyone new
  5. -- to these Lua scripts.
  6.  
  7.  
  8.  
  9. -- Imports.
  10.  
  11. -- package.loaded.<module> ensures that the module gets de-cached as needed.
  12. -- That way, if we change the code in those modules and then re-run the script,
  13. -- we won't need to restart Cheat Engine to see the code changes take effect.
  14. package.loaded.utils = nil
  15. local utils = require 'utils'
  16. local subclass = utils.subclass
  17.  
  18. package.loaded.dolphin = nil
  19. local dolphin = require 'dolphin'
  20.  
  21. package.loaded.valuetypes = nil
  22. local valuetypes = require "valuetypes"
  23. local V = valuetypes.V
  24. local MV = valuetypes.MV
  25. local MemoryValue = valuetypes.MemoryValue
  26. local FloatType = valuetypes.FloatTypeBE
  27. local Vector3Value = valuetypes.Vector3Value
  28.  
  29.  
  30.  
  31. local SH = subclass(dolphin.DolphinGame)
  32.  
  33. SH.supportedGameVersions = {
  34.   na = 'G9SE8P',
  35.   us = 'G9SE8P',
  36. }
  37.  
  38. -- Layouts specific to this game module can be found in metroidprime_layouts.lua.
  39. SH.layoutModuleNames = {'sonicheroes_layouts'}
  40. -- This game runs at 60 frames per second. A few layouts and functions need
  41. -- to know the framerate for their calculations.
  42. SH.framerate = 60
  43.  
  44. function SH:init(options)
  45.   dolphin.DolphinGame.init(self, options)
  46.  
  47.   self.addrs = {}
  48.   self.startAddress = self:getGameStartAddress()
  49. end
  50.  
  51.  
  52. -- If there are any addresses that can change during the game, calculate
  53. -- them in this function, which will be called on every frame.
  54. function SH:updateAddresses()
  55.   -- We don't have any dynamic addresses for this game yet,
  56.   -- so we'll just do nothing here.
  57. end
  58.  
  59.  
  60.  
  61. -- Values at static addresses (from the beginning of the game memory).
  62. SH.StaticValue = subclass(MemoryValue)
  63.  
  64. function SH.StaticValue:getAddress()
  65.   return self.startAddress + self.offset
  66. end
  67.  
  68. -- getActiveChar: checks the active character
  69. function SH:getActiveChar()
  70.     return self.startAddress + utils.readIntBE(self.startAddress + 0x9D986A) - 0x80000000
  71. end
  72.  
  73. local pointer = 0xAD090 + SH:getActiveChar() * 4
  74. -- Position.
  75. SH.blockValues.posX = MV("Pos X", pointer + 0x18, SH.StaticValue, FloatType)
  76. SH.blockValues.posY = MV("Pos Y", pointer + 0x1C, SH.StaticValue, FloatType)
  77. SH.blockValues.posZ = MV("Pos Z", pointer + 0x20, SH.StaticValue, FloatType)
  78.  
  79. local pointer1 = 0x2AD0D0 + getActiveChar() * 4
  80. local pointer2 = 0x2AD0B0 + getActiveChar() * 4
  81. local pointer3 = 0x2AD0D0 + getActiveChar() * 4
  82.  
  83. -- Velocity.
  84. SH.blockValues.velF = MV("Forward Vel", pointer1 + 0x60, SH.StaticValue, FloatType)
  85. SH.blockValues.velVt = MV("Vertical Vel", pointer1 + 0x64, SH.StaticValue, FloatType)
  86. SH.blockValues.velSd = MV("Sideways Vel", pointer1 + 0x68, SH.StaticValue, FloatType)
  87. SH.blockValues.velX = MV("Vel X", pointer2 + 0x0, SH.StaticValue, FloatType)
  88. SH.blockValues.velY = MV("Vel Y", pointer2 + 0x4, SH.StaticValue, FloatType)
  89. SH.blockValues.velZ = MV("Vel Z", pointer2 + 0x8, SH.StaticValue, FloatType)
  90.  
  91. -- We can also use a Vector3Value to group a set of coordinates together.
  92. SH.blockValues.pos = V(
  93.   subclass(Vector3Value),
  94.   SH.blockValues.posX,
  95.   SH.blockValues.posY,
  96.   SH.blockValues.posZ
  97. )
  98. SH.blockValues.pos.label = "Position"
  99.  
  100.  
  101. return SH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement