Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
69f600f
Rotation
Blounard Dec 11, 2023
4617d83
Rotation + Rotation speed
Blounard Dec 12, 2023
6ee3cce
Bugfix
Blounard Dec 12, 2023
379a4e4
info_display timediff
Blounard Dec 16, 2023
5059268
TimeDiff Update + AGC + Bruteforcer
Blounard Dec 23, 2023
d13686a
Added doc and removed personal files
Blounard Dec 24, 2023
dcc7f4c
Remove compiled code from PR.
ximk Dec 26, 2023
3215e26
Appease linter
ximk Dec 26, 2023
5eea673
Update scripts/RMC/Adv. Ghost Comp/Load_data.py
ximk Dec 26, 2023
d7ddb70
Appease linter
ximk Dec 26, 2023
2620cf6
github is being silly
ximk Dec 26, 2023
70086c4
Final touches
ximk Dec 26, 2023
ffbfb20
Implemented the 7 column version of TTK
Blounard Apr 7, 2024
dc1cd2c
Merge branch 'main' of https://github.com/Blounard/mkw-scripts
Blounard Apr 7, 2024
f04d1e2
remade agc
Blounard Feb 23, 2025
e57711b
agc other functions
Blounard Feb 23, 2025
2f4090b
rkg lib
Blounard Feb 25, 2025
a401694
Remove pycache files
Epik95mkw Feb 26, 2025
c76be6c
Add dolphin function stubs
Epik95mkw Feb 26, 2025
bb5c180
Add glitchy corner accessor
Epik95mkw Feb 26, 2025
cc499ec
Personal infodisplay
Epik95mkw Feb 26, 2025
78864c9
External scripts and memory sharing utils
Epik95mkw Feb 26, 2025
05aaf18
WIP superhopping macro
Epik95mkw Feb 26, 2025
8bdbae6
Superslide (and neutral glide) macro
Epik95mkw Feb 26, 2025
5d370d8
Auto MT release macro
Epik95mkw Feb 26, 2025
d2df7ec
WIP teleport offset script
Epik95mkw Feb 26, 2025
7c6d12f
Merge pull request #1 from Epik95mkw/main
Blounard Feb 26, 2025
36a3676
RKG Loader, TTK RKG to Player, TTK Player to CSV
Blounard Feb 27, 2025
3873271
mkds minimap + other small utils
Blounard Mar 1, 2025
333cd26
auto teleport + various bugfix
Blounard Mar 2, 2025
86f570d
Update .gitignore
Blounard Mar 2, 2025
f374bf7
auto tp componed component
Blounard Mar 3, 2025
b729957
Soft drift assist macro
Epik95mkw Mar 3, 2025
6fb5ba1
Merge remote-tracking branch 'upstream/main'
Epik95mkw Mar 3, 2025
2cdf1d6
Reorganize stuff
Epik95mkw Mar 3, 2025
c871000
update mkds minimap
Blounard Mar 5, 2025
2c463f5
Merge remote-tracking branch 'upstream/main'
Epik95mkw Mar 6, 2025
8a04771
Big script commit
Blounard Mar 16, 2025
7b30c17
Update TAS_Input.py
Blounard Mar 16, 2025
605001b
Simple TTK GUI
Epik95mkw Mar 16, 2025
03d1161
Merge remote-tracking branch 'upstream/main'
Epik95mkw Mar 16, 2025
436ec85
TTK GUI improvements
Epik95mkw Mar 20, 2025
03c11df
Small fix
Epik95mkw Mar 20, 2025
f314de9
Remove all on state load events
Blounard Mar 21, 2025
8c2e6af
gitignore modif to include default mii
Blounard Mar 21, 2025
49bf2ee
Merge commit '5e237f4c04f522274cf6109cd6dc53a2f2bab2b4'
Blounard Mar 21, 2025
fea79bc
Fix staticmethod for outside_drift_last_dir (#56)
malleoz Dec 26, 2023
b72a0d7
Merge remote-tracking branch 'upstream/main'
Epik95mkw Mar 21, 2025
c160db8
Update alt infodisplay with docs
Epik95mkw Mar 21, 2025
1f23c3e
TTK GUI listener thread for button commands
Epik95mkw Mar 22, 2025
19383a2
Fix TTK GUI crashing on exit
Epik95mkw Mar 22, 2025
c00fbfa
Use window.mainloop for gui window
Epik95mkw Mar 22, 2025
875172f
Fix freeze(s) caused by TTK GUI buttons
Epik95mkw Mar 23, 2025
7ebc822
Add more comments
Epik95mkw Mar 23, 2025
85a10fc
Update macros and add usage instructions
Epik95mkw Mar 23, 2025
282c363
Update wheelie turn macro
Epik95mkw Mar 24, 2025
744d89e
Update startslide scripts and inputs
Epik95mkw Mar 24, 2025
b5ceb10
Merge pull request #2 from Epik95mkw/main
Blounard Mar 24, 2025
3f9a32b
Delete scripts/Settings/Infodisplay.ini
Blounard Apr 7, 2025
8cbb96a
Delete scripts/Settings/AGC.ini
Blounard Apr 7, 2025
be1cc29
Delete scripts/AGC_Data/ghost_data.agc
Blounard Apr 7, 2025
4095e70
Delete scripts/MKW_Inputs/Startslides directory
Blounard Apr 7, 2025
2bf2286
Delete scripts/Ghost/Default directory
Blounard Apr 7, 2025
4c09cc7
Removed unwanted file from the repo
Blounard Apr 7, 2025
f0e66de
Merge branch 'main' of https://github.com/Blounard/mkw-scripts
Blounard Apr 7, 2025
8e0b6c7
TTK Save scripts auto cancel
Blounard Apr 7, 2025
7c7ee2f
Improved TTK Activate scripts
Blounard Apr 7, 2025
bf8d3ab
infodisplay update
Blounard Apr 7, 2025
6591109
Update TAS_input_window.py
Blounard Apr 7, 2025
41101d9
Update .gitignore
Blounard Apr 7, 2025
8b1194b
Delete scripts/RMC/hop test.py
Blounard Apr 7, 2025
1528535
Delete scripts/RMC/test.py
Blounard Apr 7, 2025
ce51715
Delete scripts/RMC/set_position_test.py
Blounard Apr 7, 2025
20669dd
TTK Settings and Backup
Blounard Apr 8, 2025
ee0d94e
Update AGC_Save_Ghost.py
Blounard Apr 8, 2025
870d6b4
Update draw_input_display.py
Blounard Apr 8, 2025
33fb5be
Update TAS_Input.py
Blounard Apr 8, 2025
acd8dee
draw_infodisplay more often on screen
Blounard Apr 8, 2025
3ad7430
TTK GUI edit
Blounard Apr 8, 2025
a4fab8e
Update startslide_utils.py
Blounard Apr 8, 2025
20fd079
2 bugfixes
Blounard Apr 8, 2025
17b8281
Update external_utils.py
Blounard Apr 9, 2025
afd4332
TTK GUI bugfix + new buttons
Blounard Apr 10, 2025
0ff9d82
Added module for Yaz1 management
Blounard Apr 12, 2025
ac23d11
Update _draw_info_display.py
Blounard Apr 12, 2025
a7aec65
bugfix compressed ghost
Blounard Apr 12, 2025
5ed69fe
Create update_scripts.py
Blounard Apr 13, 2025
c84d7fa
update python stub
Blounard Apr 13, 2025
0e23fdf
Various fixes and updates
Epik95mkw Apr 13, 2025
4ead035
Merge remote-tracking branch 'upstream/main'
Epik95mkw Apr 13, 2025
ddfe33c
Restore input display changes
Epik95mkw Apr 13, 2025
191982b
Merge pull request #3 from Epik95mkw/main
Blounard Apr 13, 2025
36d841f
auto input optimizer v1
Blounard Apr 14, 2025
a16ba05
bugfix infodisplay
Blounard Apr 14, 2025
c9a0b64
Delete ttk_lib -backup.py
Blounard Apr 14, 2025
9f57c75
Update _TTK_Backup.py
Blounard Apr 14, 2025
4347066
added requests to python packages installer
Blounard Apr 14, 2025
b69caea
crash fix attempt
Blounard Apr 14, 2025
e10c307
more infodisplay options
Blounard Apr 15, 2025
11056c7
Update infodisplay_utils.py
Blounard Apr 15, 2025
db5a76f
infodisplay rkg buffer + erase rkg buffer
Blounard Apr 17, 2025
dfd199b
Update infodisplay_utils.py
Blounard Apr 17, 2025
63a0e91
AGC setting update
Blounard Apr 20, 2025
57e6ae4
agc fix aniamtion
Blounard Apr 21, 2025
fd1293a
228 memory check event
Blounard Apr 25, 2025
6539c7b
agc save at exit crashfix
Blounard Apr 25, 2025
a300400
bug fix in settings
Blounard Apr 25, 2025
b5cce6f
python stubs update 230
Blounard Apr 25, 2025
f6e92a1
Exact finish time
Blounard Apr 28, 2025
9f434bf
AGC load player
Blounard Apr 28, 2025
8ec043e
Improved freefly
Blounard May 5, 2025
5bf9235
auto input opti
Blounard May 5, 2025
0bacfe9
small bugfix
Blounard May 5, 2025
acac792
Delete special.py
Blounard May 5, 2025
179dcaa
ttk gui update
Blounard May 6, 2025
1f6c7f6
Update Auto_Input_Optimizer.py
Blounard May 6, 2025
bef2906
Flag for no UI delay
Epik95mkw May 9, 2025
03b9a27
Upgraded superslide macro
Epik95mkw May 9, 2025
80851db
Updated startslide
Blounard May 15, 2025
77aaa14
Merge remote-tracking branch 'upstream/main'
Epik95mkw May 17, 2025
589b175
Boost panel timer
Epik95mkw May 17, 2025
a60ab32
framedump extended
Blounard May 18, 2025
6970bd5
with the packages it's better
Blounard May 18, 2025
a1cacbb
update wiggle slide, and some small fix
Blounard May 20, 2025
4b42f01
framedump script update
Blounard May 25, 2025
940ae8a
bugfix
Blounard May 26, 2025
2c4779f
debug script
Blounard May 26, 2025
42af695
QOL stuff
Epik95mkw May 27, 2025
aff9a88
Update macros after new EV discoveries
Epik95mkw May 27, 2025
ab5a0e4
Merge remote-tracking branch 'upstream/main'
Epik95mkw May 27, 2025
5fe572e
Merge pull request #4 from Epik95mkw/main
Blounard May 27, 2025
35a8080
attempt to fix linux import
Blounard May 27, 2025
ce1aa79
Reverse previous commit
Blounard May 27, 2025
3a36e2f
Attempt to fix import syntax for Linux
Epik95mkw May 28, 2025
7d2465a
bugfix
Blounard May 31, 2025
70cab37
updater update
Blounard May 31, 2025
139fd6a
tiny bugfix
Blounard May 31, 2025
d0a82f9
math geometry function
Blounard May 31, 2025
56d3a09
geometry function
Blounard May 31, 2025
8928445
framedump osd extradisplay
Blounard Jun 1, 2025
4f458ad
Merge remote-tracking branch 'upstream/main'
Epik95mkw Jun 2, 2025
e5326ae
Merge pull request #5 from Epik95mkw/main
Blounard Jun 2, 2025
f58df12
mbp library
Blounard Jun 8, 2025
358ae0c
added input display images
xAntares17 Jun 18, 2025
07ce060
implements width and color options, config_util changed accordingly
xAntares17 Jun 18, 2025
0482f3a
changed spelling: frame to frames
xAntares17 Jun 18, 2025
6c8498e
formatting
xAntares17 Jun 18, 2025
1bfd681
default color fixed
xAntares17 Jun 18, 2025
18efa3d
Merge pull request #6 from xAntares17/width-color-options
Blounard Jun 18, 2025
ba481b2
does the recoloring once in main for better performance
xAntares17 Jun 19, 2025
ddb5169
restructuring
xAntares17 Jun 19, 2025
00ea3fa
necessary name changes
xAntares17 Jun 19, 2025
782f8b9
Merge pull request #7 from xAntares17/width-color-options
Blounard Jun 19, 2025
d1ac30a
AGC copy input 1f delay fix
Blounard Jun 20, 2025
7c5547f
Merge branch 'main' of https://github.com/Blounard/mkw-scripts
Blounard Jun 20, 2025
e9f2867
added comments
Blounard Jun 20, 2025
d8364a8
OSD update for the present event
Blounard Jun 20, 2025
da11212
input display fix when not in race
Blounard Jun 20, 2025
0ce3599
creates additional fonts in the sizes specified in custom_text_scaling
xAntares17 Jun 22, 2025
6e8b2c8
implements custom text function, author display encoding changed to u…
xAntares17 Jun 22, 2025
ab9f138
added slash
xAntares17 Jun 22, 2025
900724a
Merge pull request #8 from xAntares17/custom-text
Blounard Jun 22, 2025
c3e1fb9
performance improvements
xAntares17 Jun 22, 2025
a76eb48
further optimization by selecting the analog stick parts depending on…
xAntares17 Jun 23, 2025
8b55d19
Merge pull request #9 from xAntares17/custom-text
Blounard Jun 23, 2025
fabf855
made dpad edges less rough, added tutorial folder
xAntares17 Jun 25, 2025
ebce1c9
fly in animation
xAntares17 Jun 25, 2025
8b8e678
reanchoring stick text depends on scale
xAntares17 Jun 26, 2025
3e41310
Update input_display_util.py
xAntares17 Jun 26, 2025
2dda662
Add inactive outline colour to config
kierio04 Jun 26, 2025
8b04b5a
Merge pull request #11 from kierio04/main
Blounard Jun 27, 2025
6f79eee
Merge pull request #10 from xAntares17/custom-text
Blounard Jun 27, 2025
3956b0c
pretty speedometer option added as gecko code doesnt use entry anim. …
xAntares17 Jul 1, 2025
44c5659
adds pretty speedometer scaled font
xAntares17 Jul 1, 2025
a2d5217
Merge pull request #12 from xAntares17/custom-text
Blounard Jul 1, 2025
5f1fbc2
improved framdump script
Blounard Jul 15, 2025
eeb66ba
Update mbp_utils.py
Blounard Jul 15, 2025
8f17f66
Update _draw_info_display.py
Blounard Jul 15, 2025
0dc8799
Update framesequence.py
Blounard Jul 18, 2025
28d5272
framedump script update
Blounard Jul 19, 2025
df386fb
Update config_util.py
Blounard Jul 19, 2025
4a108b7
Update config_util.py
Blounard Jul 19, 2025
b32aeb9
Update encoder.py
Blounard Jul 19, 2025
1539a48
fix fly out anim + other small changes
xAntares17 Jul 20, 2025
49ec92c
number quality improvement; letters mostly unchanged except saturatio…
xAntares17 Jul 20, 2025
e7c0aed
Merge pull request #13 from xAntares17/fixes-overhauls
Blounard Jul 20, 2025
3e18867
Update input_display_util.py
Blounard Jul 21, 2025
ed0ab80
framedump script custom timings
Blounard Jul 24, 2025
7a327eb
Update TTK_GUI.py
Blounard Jul 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/scripts/MKW_Inputs/*.csv
scripts/AGC_Data/ghost.data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency.

Suggested change
scripts/AGC_Data/ghost.data
/scripts/AGC_Data/ghost.data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the purpose of this is to have a placeholder file to keep the folder, .gitkeep is the preferred name. Otherwise, messages or notes are best done in .txt or .md file bodies.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only purpose of that text file, delete it if it's not needed

Empty file.
58 changes: 58 additions & 0 deletions scripts/Modules/TimeDifference information.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid spaces in filenames. TimeDifferenceInfo.txt would be my pick.

Optionally, this can be improved via markdown.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
This file contain some information about the TimeDifference scripts in infodisplay.

In infodisplay.ini, you can chose to display or not each time difference calculation.

In infodisplay.ini, "timediff setting" is a setting with 4 possible value :
"player" which will use the TimeDifference (Player -> Ghost)
"ghost" which will use the TimeDifference (Ghost -> Player)
"ahead" which will use the TimeDifference (the one ahead -> the one behind)
"behind" which will use the TimeDifference (the one behind -> the one ahead)
any other value will default to "player".

In infodisplay.ini "history size" is a setting used for the TimeDifference RaceComp.
history size = 200 means the TimeDiff RaceComp can at best detect a timedifference of 200 frames or less.
It uses memory, so don't use an unecessary large number.

Some TimeDifference calculations are not symmetrical. It means this calculation gives different result
for the time difference between the ghost and the player, and between the player and the ghost.
Here's an example : For the TimeDifference Absolute (Player1 -> Player2) :
We take Player1's speed, we take the distance between both players.
And we simply define the TimeDiff as the distance divided by the speed.
Player1 and Player2 have asymmetrical roles in the calculation.
Therefore : we talk about the timedifference from Player1 to Player2 (and not the timedifference between Player1 and Player2)

This is how each one is calculated :

-TimeDifference Absolute (P1 -> P2) (Not very relevant imo)
Take S1 the speed of P1
Take D the distance between P1 and P2
Return D / S1

-TimeDifference Relative (P1 -> P2) (A bit more relevant maybe)
Take S1 the speed of P1 directed "toward" P2. (mathematically, it's a dot product)
Take D the distance between P1 and P2
Return D / S1

-TimeDifference Projected (P1 -> P2) (A good one for short distances)
Take S1 the speed of P1
Take D the distance represented here : https://blounard.s-ul.eu/iMDYhZDI.png
Return D / S1

-TimeDifference CrossPath (P1 -> P2) (Another good one for short distances)
this one is symmetrical
With the notation here : https://blounard.s-ul.eu/WYbotlks.png
Calculate t1 = TimeDifference (P1 -> C) (in this case, all 3 above timedifference formula will give the same result)
Calculate t2 = TimeDifference (P2 -> C) (--------------------------------------------------------------------------)
Return t1-t2

-TimeDifference ToFinish (P1 -> P2) (Perfectly precise when both player are going straight to the finish line at constant speed. Useless otherwise)
this one is symmetrical
Calculate t1, the time needed for P1 to cross the finish line if P1 keep going at a constant speed.
Calculate t2, the time needed for P2 to cross the finish line if P2 keep going at a constant speed.
Return t1-t2

-TimeDifference RaceComp (P1 -> P2) (Useful even for long distances. Based on RaceCompletion data. Has several flaws)
this one is symmetrical
Store in memory the racecompletion data for both players for the last few frames.
Make the player ahead go "back in time" until it's behind the other player.
How much frame you had to go "back in time" is how much frame the player was ahead.
320 changes: 320 additions & 0 deletions scripts/Modules/agc_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
from dolphin import gui, memory
from .mkw_classes import vec3
from .mkw_classes import VehiclePhysics, KartMove, RaceConfig, RaceManagerPlayer
import math


class FrameData:
"""Class to represent a set of value accessible each frame in the memory"""

def __init__(self, addrlist=None, string=None, usedefault=False):
self.values = [] # List of bytearray
if string is not None:
self.read_from_string(string)

elif addrlist is not None:
if not usedefault:
for addr, size in addrlist:
self.values.append(memory.read_bytes(addr, size))
else:
for addr, size in addrlist:
self.values.append(bytearray(size))

def __str__(self):
text = ''
for array in self.values:
for byte in array:
text += str(byte)+','
if len(array) > 0:
text = text[:-1]
text += ';'
if len(self.values) > 0:
text = text[:-1]
return text+'\n'

def read_from_string(self, string):
values = string.split(';')
for value in values:
self.values.append(bytearray([int(s) for s in value.split(',')]))

def interpolate(self, other, selfi, otheri):
# Call only if self.value[0] represent a vec3
v1 = vec3.from_bytes(self.values[0])
v2 = vec3.from_bytes(other.values[0])
v = (v1*selfi)+(v2*otheri)
self.values[0] = v.to_bytes()

def write(self, addrlist):
for index in range(len(self.values)):
addr = addrlist[index][0]
val = self.values[index]
memory.write_bytes(addr, val)


def float_to_str(f):
ms = round((f % 1)*1000)
s = math.floor(f) % 60
m = math.floor(f)//60
return f"{m},{s},{ms}"


def floats_to_str(fs):
return f"{float_to_str(fs[0])};{float_to_str(fs[1])};{float_to_str(fs[2])}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old functions that i forgot to remove when I changed the implementation of TimerData. You can delete



class Split:
"""Class for a lap split. Contain just a float, representing the split in s"""

def __init__(self, f):
self.val = f

def __str__(self):
return f"{self.val:.3f}"

def __add__(self, other):
return Split(max(0, self.val+other.val))

@staticmethod
def from_string(string):
return Split(float(string))

@staticmethod
def from_time_format(m, s, ms):
return Split(m*60+s+ms/1000)

@staticmethod
def from_bytes(b):
data_int = b[0]*256*256+b[1]*256+b[2]
ms = data_int % 1024
data_int = data_int//1024
s = data_int % 128
data_int = data_int//128
m = data_int % 128
return Split(m*60+s+ms/1000)

def time_format(self):
# return m,s,ms corresponding
f = self.val
ms = round((f % 1)*1000)
s = math.floor(f) % 60
m = math.floor(f)//60
return m, s, ms

def bytes_format(self):
# return a bytearray of size 3 for rkg format
m, s, ms = self.time_format()
data_int = ms+s*1024+m*1024*128
b3 = data_int % 256
data_int = data_int//256
b2 = data_int % 256
data_int = data_int//256
b1 = data_int % 256
return bytearray((b1, b2, b3))


class TimerData:
"""Class for the laps splits, both in RKG and Timer format
Cumulative convention (lap2 split is stored as lap1+lap2)"""

def __init__(self, string=None, readid=0, splits=None):
# Call with a string OR when the race is finished
if string is None:
if splits is None:
self.splits = [] # List of Split (size 3)
timerlist = [RaceManagerPlayer.lap_finish_time(
readid, lap) for lap in range(3)]
for timer in timerlist:
self.splits.append(Split.from_time_format(
timer.minutes(), timer.seconds(), timer.milliseconds()))
else:
self.splits = splits
else:
self.splits = []
laps = string.split(';')
for lap in laps:
self.splits.append(Split.from_string(lap))

@staticmethod
def from_sliced_rkg(rkg_metadata):
sliced_bytes = rkg_metadata.values[3]
l1 = Split.from_bytes(sliced_bytes[1:4])
l2 = Split.from_bytes(sliced_bytes[4:7])+l1
l3 = Split.from_bytes(sliced_bytes[7:10])+l2
return TimerData(splits=[l1, l2, l3])

def __str__(self):
text = 't'
for split in self.splits:
text += str(split)+";"
text = text[:-1]
return text+'\n'

def add_delay(self, delay):
s = -delay/59.94
for i in range(len(self.splits)):
self.splits[i] = Split(max(self.splits[i].val+s, 0))

def to_bytes(self):
# A lap split is 3 bytes, so there is 9 bytes total
# Non cumulative format, ready to be written in a rkg
r = bytearray()
prev = 0
for split in self.splits:
r = r + Split(split.val - prev).bytes_format()
prev = split.val
return r

def write_rkg(self):
r = rkg_addr()
memory.write_bytes(r+0x11, self.to_bytes())


def metadata_to_file(filename, read_id):
# Should be called before the countdown
metadata = FrameData(get_metadata_addr(read_id))
file = open(filename, 'w')
if file is None:
gui.add_osd_message("Error : could not create the data file")
else:
file.write(str(metadata))
file.close()
gui.add_osd_message(f"{filename} successfully opened")


def get_metadata(read_id):
return FrameData(get_metadata_addr(read_id))


def get_rkg_metadata():
return FrameData(get_rkg_metadata_addr())


def rkg_metadata_to_file(filename):
rkg_metadata = get_rkg_metadata()
file = open(filename, 'w')
if file is None:
gui.add_osd_message("Error : could not create the data file")
else:
file.write("r"+str(rkg_metadata))
file.close()
gui.add_osd_message(f"{filename} successfully opened")


def frame_to_file(filename, read_id):
frame = FrameData(get_addr(read_id))
file = open(filename, 'a')
if file is None:
gui.add_osd_message("Error : could not create the data file")
else:
file.write(str(frame))
file.close()


def get_framedata(read_id):
return FrameData(get_addr(read_id))


def timerdata_to_file(filename, read_id):
timerdata = TimerData(read_id)
file = open(filename, 'a')
if file is None:
gui.add_osd_message("Error : could not create the data file")
else:
file.write(str(timerdata))
file.close()


def get_timerdata(read_id):
return TimerData(read_id)


def file_to_framedatalist(filename):
datalist = []
file = open(filename, 'r')
if file is None:
gui.add_osd_message("Error : could not load the data file")
else:
timerdata = None
metadata = None
rkg_metadata = None
listlines = file.readlines()
if listlines[0][0] == 'r':
rkg_metadata = FrameData(string=listlines[0][1:])
timerdata = TimerData.from_sliced_rkg(rkg_metadata)
else:
metadata = FrameData(string=listlines[0])
if listlines[-1][0] == 't':
timerdata = TimerData(string=listlines.pop()[1:])
for i in range(1, len(listlines)):
datalist.append(FrameData(string=listlines[i]))
file.close()
gui.add_osd_message(f"Data successfully loaded from {filename}")
return metadata, datalist, timerdata, rkg_metadata


def framedatalist_to_file(filename, datalist, read_id):
metadata = get_metadata(read_id)
timerdata = get_timerdata(read_id)
file = open(filename, 'w')
if file is None:
gui.add_osd_message("Error : could not create the data file")
else:
file.write(str(metadata))
for frame in range(max(datalist.keys())+1):
if frame in datalist.keys():
file.write(str(datalist[frame]))
else:
file.write(str(FrameData(get_addr(read_id), usedefault=True)))
file.write(str(timerdata))
file.close()


def framedatalist_to_file_rkg(filename, datalist):
metadata = get_rkg_metadata()
file = open(filename, 'w')
if file is None:
gui.add_osd_message("Error : could not create the data file")
else:
file.write('r'+str(metadata))
for frame in range(max(datalist.keys())+1):
if frame in datalist.keys():
file.write(str(datalist[frame]))
else:
file.write(str(FrameData(get_addr(1), usedefault=True)))
file.close()


def get_addr(player_id):
a = VehiclePhysics.chain(player_id)
b = KartMove.chain(player_id)
return [(a+0x68, 12), # Position
(a+0xF0, 16), # Rotation
(a+0x74, 12), # EV
(a+0x14C, 12), # IV
(b+0x18, 4), # MaxEngineSpd
(b+0x20, 4), # EngineSpd
(b+0x9C, 4), # OutsideDriftAngle
(b+0x5C, 12)] # Dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that these are blindly referenced (e.g. addr[0], addr[1], etc). There are two alternatives to solve this:

  • Return a dict with key-value pairs, where the keys are these comments
  • Create a dataclass with a static read method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about static read method was a thing when i wrote that, that's why some init functions are a mess.
This class will probably be rewritten and merged with mkw_utils.FrameData at some point



def get_metadata_addr(player_id):
a = RaceConfig.chain() + player_id*0xF0
return [(a+0x30, 8)] # CharacterID and VehicleID


def rkg_addr():
return memory.read_u32(RaceConfig.chain() + 0xC0C)


def get_rkg_metadata_addr():
r = rkg_addr()
return [(r+0x4, 3), # Skipping track ID
(r+0x8, 4), # Skipping Compression flag
(r+0xD, 1), # Skipping Input Data Length
(r+0x10, 0x78)]


def is_rkg():
s = bytearray('RKGD', 'ASCII')
r = rkg_addr()
return s == memory.read_bytes(r, 4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, it may as well be beneficial to create an RKG wrapper class.

4 changes: 2 additions & 2 deletions scripts/Modules/mkw_classes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# noqa: F401

from .common import RegionError
from .common import vec2, vec3, mat34, quatf
from .common import vec2, vec3, mat34, quatf, eulerAngle
from .common import ExactTimer
from .common import CupId, CourseId, VehicleId, CharacterId, WheelCount, VehicleType
from .common import SpecialFloor, TrickType, SurfaceProperties, RaceConfigPlayerType
Expand Down Expand Up @@ -56,4 +56,4 @@
from .race_manager import RaceManager, RaceState
from .time_manager import TimerManager
from .timer import Timer
from .race_manager_player import RaceManagerPlayer
from .race_manager_player import RaceManagerPlayer
Loading