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 1ea1482
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 213 deletions.
35 changes: 0 additions & 35 deletions scripts/Modules/infodisplay.ini

This file was deleted.

35 changes: 35 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,40 @@ 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)

@dataclass
class timer:
min: int
sec: int
mil: float

def __add__(self, rhs):
ret = timer(self.min, self.sec, self.mil)
ret.min += rhs.min
ret.sec += rhs.sec
ret.mil += rhs.mil
carry, ret.mil = divmod(ret.mil, 1000)
ret.sec += carry
carry, ret.sec = divmod(ret.sec, 60)
ret.min += int(carry)
return ret

def __sub__(self, rhs):
ret = timer(self.min, self.sec, self.mil)
ret.min -= rhs.min
ret.sec -= rhs.sec
ret.mil -= rhs.mil
carry, ret.mil = divmod(ret.mil, 1000)
ret.sec += carry
carry, ret.sec = divmod(ret.sec, 60)
ret.min += int(carry)
return ret

def __str__(self):
return "{:02d}:{:012.9f}".format(self.min, self.sec + self.mil / 1000)

def read_vec3(ptr):
x = memory.read_f32(ptr + 0x0)
y = memory.read_f32(ptr + 0x4)
Expand Down
56 changes: 17 additions & 39 deletions scripts/Modules/mkw_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,51 +90,29 @@ 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)
currMil = memory.read_f32(address + (lap-1)*0x4) / 1000 % 1
currentLapTime = classes.timer(currMin, currSec, currMil)

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
pastMin, pastSec = getIGT(lap-1, player)
pastMil = memory.read_f32(address + (lap-2)*0x4) / 1000 % 1
pastLapTime = classes.timer(pastMin, pastSec, pastMil)

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

return finish


def getUnroundedTime(lap, player):
t = 0
totalTime = [0, 0]
return currentLapTime - pastLapTime

def getUnroundedTime(lap, player): # lap is 0-indexed
t = classes.timer(0, 0, 0)
for i in range(lap):
t += updateExactFinish(i + 1, player)[0] * \
60 + updateExactFinish(i + 1, player)[1]

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

return totalTime
t += updateExactFinish(i + 1, player)
return t
Loading

0 comments on commit 1ea1482

Please sign in to comment.