TASLabz / dolphin-lua-core

do not use - obsolete
GNU General Public License v2.0
8 stars 2 forks source link

Calculate XZ/XYZ speed via Gecko code and store result in the EVA #31

Closed vabold closed 1 year ago

vabold commented 2 years ago

For every Wii game there is a region of memory where instructions for a variety of crash-recovery subroutines are located at. This region of memory is called the Exception Vector Area (or just EVA). The crash-recovery subroutines have unused spaces of memory in between each other. Those unused spaces are what you can safely use to store data at to later retrieve it. The EVA is universal (same location in memory) for every Wii game.

Due to most Gecko codes likely writing to the first part of unused space in the EVA, I propose we write to the last part of unused memory for any purpose we choose. This is a temporary solution to a much larger frame-delay problem. The free space in the last part of unused memory starts at 800017B0, and is 80 bytes long. We will be allocating 8 for this purpose.

XZ/XYZ speeds are the single most referenced value from info display in the MKW TAS community. As such, values delayed by a frame are unacceptable.

Currently, MKW_core.lua's speed calculations look like this:

local function getSpd()
  local PrevXpos = getPrevPos().X
  local PrevYpos = getPrevPos().Y
  local PrevZpos = getPrevPos().Z
  local Xpos = getPos().X
  local Ypos = getPos().Y
  local Zpos = getPos().Z
  return {X = (Xpos - PrevXpos), Y = (Ypos - PrevYpos), Z = (Zpos - PrevZpos), XZ = math.sqrt(((Xpos - PrevXpos)^2) + (Zpos - PrevZpos)^2), XYZ = math.sqrt(((Xpos - PrevXpos)^2) + ((Ypos - PrevYpos)^2) + (Zpos - PrevZpos)^2)}
end
core.getSpd = getSpd

This relies on using position differences to derive the final velocity vector's components and length. Instead, we can compute the length of the pre-existing vector in PlayerPhysics.

0x9C18F8 + 0x20 + 0x0 + 0x0 + 0x8 + 0x90 + 0x4 + 0xD4 will return the velocity vector's components. We can then use a Gecko code to calculate the XZ and XYZ speed via the sqrt function at 8022F80C, before storing the results at 800017B0 and 800017B4. We will then read those results in RMCP01.ini.

ximk commented 1 year ago

Thanks to Gaberboo's work, this is done and also is completely functional. It will be displayed with the detailed version of the ".ini" info display, as the team has decided that an external info display program is not necessary for MKW at the moment. Note that users should be advised to avoid @stblr's "Pretty Speedometer" gecko code, as this can cause crashes if these two + other codes are all activated (notably the 200cc code) on the Dolphin build currently being used.