Skip to content

Commit

Permalink
Simplifications to xi's commit
Browse files Browse the repository at this point in the history
  • Loading branch information
malleoz committed Sep 28, 2023
1 parent 32e1215 commit 7157f3d
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 207 deletions.
35 changes: 0 additions & 35 deletions scripts/Modules/infodisplay.ini

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/Modules/mkw_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass
# will be removed soon
from Modules import mkw_core as core
import math

# general structure / pointer reading
def chase_pointer(base_address, offsets, data_type):
Expand Down Expand Up @@ -40,6 +41,9 @@ class vec3:
y: float = 0.0
z: float = 0.0

def norm(self):
return math.sqrt(self.x**2 + self.y**2 + self.z**2)

def read_vec3(ptr):
x = memory.read_f32(ptr + 0x0)
y = memory.read_f32(ptr + 0x4)
Expand Down
52 changes: 17 additions & 35 deletions scripts/Modules/mkw_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,51 +90,33 @@ def get_speed(playerIdx=0):
return speed(x, y, z, xz, xyz)

# Next 3 functions are used for exact finish display
def getIGT(lap, player):
totalTime = [0, 0]
totalTime[0] = chase_pointer(
classes.getRaceInfoHolder(), [0xC, (player)*0x4, 0x3C, (lap-1)*0xC + 0x5], 'u8')
totalTime[1] = chase_pointer(
classes.getRaceInfoHolder(), [0xC, (player)*0x4, 0x3C, (lap-1)*0xC + 0x6], 'u8')

return totalTime


def updateExactFinish(lap, player):
finish = [0, 0]
def getIGT(lap, player): # lap is 1-indexed
offsets = [0xC, (player)*0x4, 0x3C, (lap-1)*0xC + 0x5]
value = chase_pointer(classes.getRaceInfoHolder(), offsets, 'u16')
return divmod(value, 0x100)

def updateExactFinish(lap, player): # lap is 1-indexed
if player == 0:
address = 0x800001B0
elif player == 1:
address = 0x800001F8

currMin, currSec = getIGT(lap, player)
currSec += memory.read_f32(address + (lap-1)*0x4) / 1000 % 1

currentMin = getIGT(lap, player)[0]
currentSec = getIGT(lap, player)[1] + \
memory.read_f32(address + (lap-1)*0x4) / 1000 % 1

pastMin = getIGT(lap-1, player)[0]
pastSec = getIGT(lap-1, player)[1] + \
memory.read_f32(address + (lap-2)*0x4) / 1000 % 1

splitMin = math.floor(
((currentMin * 60 + currentSec) - (pastMin * 60 + pastSec)) / 60)
splitSec = ((currentMin * 60 + currentSec) - (pastMin * 60 + pastSec)) % 60

finish[0] = splitMin
finish[1] = splitSec

return finish
pastMin, pastSec = getIGT(lap-1, player)
pastSec += memory.read_f32(address + (lap-2)*0x4) / 1000 % 1

splitMin, splitSec = divmod((currMin - pastMin)*60 + currSec - pastSec, 60)
return int(splitMin), splitSec

def getUnroundedTime(lap, player):
def getUnroundedTime(lap, player): # lap is 0-indexed
t = 0
totalTime = [0, 0]

for i in range(lap):
t += updateExactFinish(i + 1, player)[0] * \
60 + updateExactFinish(i + 1, player)[1]
min, sec = updateExactFinish(i + 1, player)
t += min*60 + sec

totalTime[0] = int(math.floor(t / 60))
totalTime[1] = t % 60
min, sec = divmod(t, 60)

return totalTime
return int(min), sec
Loading

0 comments on commit 7157f3d

Please sign in to comment.