jupyter: jupytext: textrepresentation: extension: .md formatname: markdown formatversion: '1.3' jupytextversion: 1.15.2 kernelspec: display_name: Bash language: bash

name: bash

Using LE-CODE to load custom tracks in Mario Kart Wii

tl;dr on how to run this: python3 -m venv jupyter_bash && mkdir -p jupyter_bash/home/mkwii_tutorial && cd jupyter_bash/home/mkwii_tutorial && ../../bin/pip install jupytext bash_kernel jupyterlab && ../../bin/python -m bash_kernel.install && ../../bin/jupytext instadistr.md --to ipynb && ../../bin/jupyter lab

This translates https://wiki.tockdom.com/wiki/LE-CODE/Distribution_Tutorial into a notebook.

Ingredients

Variable setup

```bash REGION='PAL'

GAMEISO='RMCP01.iso' DESTDIR='destdir' TEMPDIR='extractfiles'

WBZDIR='tracks' SZSDIR='tracks_extracted' ```

Getting Wiimm's Tools

You can get Wiimm's tools through your distrubtion. Wiimm also provides prebuilt binaries from his website. We'll download them and add them to the path here:

Downloading

```bash URLSZS='https://szs.wiimm.de/download/szs-v2.39a-r8904-x8664.tar.gz' URLWIT='https://wit.wiimm.de/download/wit-v3.05a-r8638-x8664.tar.gz'

wget -O szs-tools.tar.gz "$URLSZS" wget -O wit.tar.gz "$URLWIT" ```

Extracting

bash tar xvf szs-tools.tar.gz tar xvf wit.tar.gz

Adding to path

bash SZS_TOOLS_DIR="$(readlink -f szs-*/bin)" WIT_DIR="$(readlink -f wit-*/bin)" PATH="$SZS_TOOLS_DIR:$WIT_DIR:$PATH"

Patching the main DOL

bash wit extract -o -F '+/sys/main.dol' "$GAME_ISO" "$TEMP_DIR" wstrt patch -D "$DEST_DIR/sys/main.dol" --add-lecode -o "$TEMP_DIR/DATA/sys/main.dol"

Converting WBZs to SZSs

Note: distr can convert and move SZSes in one go, but I'll show it as a separate step in case you have some SZSes already you also want to use

Creating the auto-add library

bash wit extract -o -F '+/files/Race/Course' "$GAME_ISO" "$TEMP_DIR" wszst autoadd "$TEMP_DIR/DATA/files/Race/Course"

Converting the files

```bash

mkdir "$SZS_DIR"

wszst copy --szs $WBZDIR/*.wbz -D "$SZSDIR/%N.szs" ```

Creating a CT-DEF file

CT-DEF has been replaced by LE-DEF, but wctct bmg needs it.

See this article for special per-slot features: https://wiki.tockdom.com/wiki/Slot

```bash cat > ctdef.txt <

CT-CODE

[RACING-TRACK-LIST]

Define the maximum number of strings of track definition:

%N-STRINGS = 4

Enable support for LE-CODE flags (0=no, 1=yes):

%LE-FLAGS = 0

Auto insert a Wiimm cup with 4 special random slots (0=no, 1=yes):

%WIIMM-CUP = 0

EOF

IFS=$'\n' for file in $(ls "$SZS_DIR"); do # wlect dis .szs le-def=- can parse the [r33] in filenames # can we use that somehow? # Use the slot specified in the brackets, otherwise use Mario Circuit as a fallback slot="$(echo "$file" | sed 's/.[r([0-9]+)./\1/; /^[0-9]$/!cMC')" music="$slot" name="$(basename -s ".szs" "$file")" label="$(echo "$name" | sed 's/ [.*]$//')"

echo "T $music; $slot; \"$name\"; \"$label\"" | tee -a ctdef.txt

done unset IFS ```

Converting CT-DEF to LE-DEF

We don't really need a LE-DEF in this notebook, but it helps illustrate how the powerful wlect distribution command works.

bash wlect dis ctdef.txt ledef=ledef.txt

At the beginning of the distribution (shortened to dis) command, you specify files to be scanned by naming them. These can definition files, SZSes, parameter files, etc. On the right-hand side, you specify outputs to be generated based on what was scanned beforehand. In this case, we're generating a ledef file from the information that was gathered by reading ctdef.txt.

For a more expansive explanation of the command, run it without any parameters:

bash wlect dis

Adding LE-CODE

Using LE-CODE from a zip

bash URL_LECODE='https://download.wiimm.de/lecode/distribution-support/lecode-bin/2023-08-05.build-38.zip' wget -O lecode.zip "$URL_LECODE" unzip -o lecode.zip

bash wlect patch --le-define ctdef.txt *.build-*/lecode-$REGION.bin -o -D "$DEST_DIR/rel/lecode-$REGION.bin"

Using LE-CODE built-in to WLECT

bash wlect distribution -o ctdef.txt "$REGION=$DEST_DIR/rel/lecode-$REGION.bin"

Setting up the UI

Creating cup icons

bash wlect distribution -o ctdef.txt cup-icons=swapped,5,space=icons.tpl

Creating BMG files

BMG files contain the text you see on screen in the game's menus.

bash wctct bmg --le-code ctdef.txt > bmg.txt

Adding them to the game

bash wit extract -o -F '+/files/Scene/UI/*.szs' "$GAME_ISO" "$TEMP_DIR" mkdir -p "$DEST_DIR/Scene/UI" wszst patch --cup-icons icons.tpl --patch-bmg 'OVERWRITE=bmg.txt' --le-menu --9laps $TEMP_DIR/DATA/files/Scene/UI/*.szs -od "$DEST_DIR/Scene/UI"

Placing the SZS files

bash mkdir -p "$DEST_DIR/Race/Course" wlect dis --track-dir="$DEST_DIR/Race/Course" --copy-tracks="$SZS_DIR" ctdef.txt tracks=log

Adding empty preview videos

bash wget -O video.zip https://download.wiimm.de/lecode/distribution-support/video.zip unzip -o video.zip mkdir -p "$DEST_DIR/thp/course" tee < video.thp > /dev/null "$DEST_DIR/thp/course/banana.thp" "$DEST_DIR/thp/course/cup_select.thp" "$DEST_DIR/thp/course/flower.thp" "$DEST_DIR/thp/course/kinoko.thp" "$DEST_DIR/thp/course/konoha.thp" "$DEST_DIR/thp/course/koura.thp" "$DEST_DIR/thp/course/special.thp" "$DEST_DIR/thp/course/star.thp" "$DEST_DIR/thp/course/thunder.thp"

Creating a Riivolution XML file

bash sed 's/ /\t/g' > mydistr.xml <<EOF <wiidisc version="1"> <options> <section name="example section"> <option name="example patch"> <choice name="Enabled"> <patch id="example"/> </choice> </option> </section> </options> <patch id="example"> <folder external="/destdir" disc="/" recursive="true" create="true"/> <folder external="/destdir/sys" recursive="false" /> </patch> </wiidisc> EOF