Skip to content

Instantly share code, notes, and snippets.

@Swyter
Last active December 6, 2022 07:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swyter/971da5e0b5d9104e9f4e92e34de61d68 to your computer and use it in GitHub Desktop.
Save Swyter/971da5e0b5d9104e9f4e92e34de61d68 to your computer and use it in GitHub Desktop.
mab-warband-macos-binary-patches.txt
sh <<EOF && sh -c "# swy: zsh in catalina+ doesn't support inline comments: https://apple.stackexchange.com/a/405317"
# swy: needed for sed to stop complaining about the wholy unsupported hexadecimal literals
export LANG=C
export LC_ALL=C
# swy: go into the game's binary folder
cd ~/'Library/Application Support/Steam/steamapps/common/MountBlade Warband/Mount and Blade.app/Contents/MacOS'
# swy: turn their ../../.. hack into the harmless .//.//./ without changing the length of the string
sed -i '' 's|\.\./\.\./\.\.|\.//\.//\./|g' ./'Mount and Blade'
# swy: fix the game looking up the correct Data folder via Info.plist bundle manifest; go figure
sed -i '' -E 's|(</dict>)| \\
'$'\t''<!-- swy: tell SDL2 to read files out of the .app bundle; and do it properly --> \\
'$'\t''<key>SDL_FILESYSTEM_BASE_DIR_TYPE</key> \\
'$'\t''<string>parent</string> \\
\1|' ../Info.plist
# swy: turn GL_LINEAR_MIPMAP_NEAREST (0x2701) into GL_LINEAR_MIPMAP_LINEAR (0x2703) to avoid the harsh mip texture transitions
# 100903763 ba 01 27 00 00 MOV EDX,0x2701
# 1009037bd ba 01 27 00 00 MOV EDX,0x2701
# ---
# BA 01 27 00 00 -> BA 03 27 00 00
sed -i '' $'s|\xBA\x01\x27|\xBA\x03\x27|g' ./'Mount and Blade'
# swy: SDL_GL_DEPTH_SIZE; Improve the depth buffer resolution/quality from 24 to 32 bits
# BF 06 00 00 00 BE 18 00 00 00 -> BF 06 00 00 00 BE 20 00 00 00
# absolutely stupid sed workaround to avoid unsupported null bytes via capture group
sed -i '' -E 's|'$'\xbf\x06''(...)'$'\xbe\x18''|'$'\xbf\x06''\1'$'\xbe\x20''|g' ./'Mount and Blade'
# swy: Note: this old macOS sed adds a harmless carriage return byte (0A) at the end of the file; doesn't matter
echo "\n\033[42mDone, hopefully.\033[0m"
EOF
# swy: turn ../../.. into the harmless .//.//./ without changing the length of the string
sed -i'' s/..\/..\/../.\/\/.\/\/.\//g 'Mount and Blade'
sed -i '' 's|\.\./\.\./\.\.|\.//\.//\./|g' MaB_test
</array>
<key>SDL_FILESYSTEM_BASE_DIR_TYPE</key>
<string>parent</string>
</dict>
sed -i '' -E 's|(</dict>)| \
'$'\t''<!-- swy: tell SDL2 to read files out of the .app bundle; and do it properly --> \
'$'\t''<key>SDL_FILESYSTEM_BASE_DIR_TYPE</key> \
'$'\t''<string>parent</string> \
\1|' Info.plist
BF 15 00 00 00 BE 02 00 00 00 -> BF 15 00 00 00 BE 01 00 00 00 swy: SDL_GL_CONTEXT_PROFILE_MASK; turning SDL_GL_CONTEXT_PROFILE_COMPATIBILITY (0x2) -> SDL_GL_CONTEXT_PROFILE_CORE (0x1)
BF 11 00 00 00 BE 02 00 00 00 -> BF 11 00 00 00 BE 03 00 00 00 swy: SDL_GL_CONTEXT_MAJOR_VERSION; 2 to 3
BF 12 00 00 00 BE 01 00 00 00 -> BF 12 00 00 00 BE 03 00 00 00 swy: SDL_GL_CONTEXT_MINOR_VERSION; 1 to 3
BF 06 00 00 00 BE 18 00 00 00 -> BF 06 00 00 00 BE 20 00 00 00 swy: SDL_GL_DEPTH_SIZE; Improve the depth buffer resolution from 24 to 32 bits
sed -i '' -E 's|'$'\xbf\x06''(...)'$'\xbe\x18''|'$'\xbf\x06''\1'$'\xbe\x20''|g' MaB_test # swy: absolutely stupid workaround to avoid unsupported null bytes via capture group
sed -i '' '1i\
out vec4 swyFragColor;
' fs*.glsl
# swy: prepend the version tag to every GLSL shader
sed -i'' '1i\
#version 330
' *.glsl
sed -i '' s/attribute/in/g vs*.glsl
sed -i '' s/varying/out/g vs*.glsl
sed -i '' s/varying/in/g fs*.glsl
sed -i '' s/gl_FragColor/swyFragColor/g fs*.glsl
# swy: GL_LINEAR_MIPMAP_NEAREST (0x2701) into GL_LINEAR_MIPMAP_LINEAR (0x2703) to avoid the harsh texture transitions
# 100903763 ba 01 27 00 00 MOV EDX,0x2701
# 1009037bd ba 01 27 00 00 MOV EDX,0x2701
# ---
# BA 01 27 00 00 -> BA 03 27 00 00
sed -i '' s/\xBA\x10\x02\x00/\xBA\x03\x02\x00/g 'Mount and Blade'
export LANG=C
export LC_ALL=C
sed -i '' $'s|\xBA\x01\x27|\xBA\x03\x27|g' MaB_test
[i]This will show you how to install the Warband version of The Last Days of the Third Age on macOS. There are two ways of doing it; by taking advantage of the Steam Workshop automatic updates, or by installing the mod manually.
If you choose to install the mod *without* using the Steam Workshop, just make sure that the two latest .7z files from https://tldmod.github.io are already in your Downloads folder. Otherwise installing Warband on your Mac and clicking [url=https://steamcommunity.com/sharedfiles/filedetails/?id=299974223#profileBlock]Subscribe[/url] should be enough. Let's begin.[/i]
[quote][h1]Main way: Steam Workshop version[/h1]
After installing Warband on your Mac, clicking [url=https://steamcommunity.com/sharedfiles/filedetails/?id=299974223#profileBlock]Subscribe[/url], and waiting for the big download to finish, the mod should be technically installed, if the Warband engine worked as intended we shouldn't have to do any of the following steps:
[h2]a) FIXING WARBAND[/h2]
[olist]
[*] Open the «Go» menu in the Finder and select «Utilities», then click on the «Terminal» icon.
[list]
[*] We will go line by line, just copy-paste the various commands in the Terminal and press Enter. I will explain what it does first to avoid looking sketchy.
[/list]
[*] Fix the garbled font and the collision bodies so that you can actually hit baddies. Just paste this in the Terminal window and press Enter:
[code]cd ~/'Library/Application Support/Steam/steamapps/workshop' && ln -s 'content/48700/299974223/Data' Data[/code]
[*] Close the Terminal window.
[/olist]
That's it. Open Steam like your normally do and use Warband's [i]Configure[/i] utility to change the selected mod to «[i]The Last Days of the Third Age[/i]». If you followed this guide properly then the game should launch and reach to the main menu.
Automatic mod updates should work as normal, you only need to repeat these steps whenever the font breaks, so hopefully only when reinstalling the game.
Have fun in Middle-earth![/quote]
[quote][h1]Alternative way: Manual mod installation[/h1]
If you choose to install the mod *without* using the Steam Workshop, just make sure that the two latest .7z files from https://tldmod.github.io are already in your Downloads folder.
[h2]a) TEMPORARILY INSTALLING THE 7-ZIP EXTRACTOR[/h2]
[olist]
[*] Open the «Go» menu in the Finder and select «Utilities», then click on the «Terminal» icon.
[list]
[*] We will go line by line, just copy-paste the various commands in the Terminal and press Enter. I will explain what it does first to avoid looking sketchy.
[/list]
[*] This switches your [i]Terminal[/i] to your temporary directory (the one that gets flushed every time you reboot), then downloads the [i]7za[/i] command-line utility (right from the '[i]Homebrew[/i]' package manager but without installing anything) and extracts it in that very same folder:
[list]
[*] Don't worry, it's only a tiny, portable and self-contained program (called [i]7za[/i]) that will go away the next time you shutdown your Mac. They leave no trace behind.
[/list]
[code]cd /tmp && curl -L 'ghcr.io/v2/homebrew/core/p7zip/blobs/sha256:bea86999db7dee5f0cb78d3a72d875d822ec73ebb2a6e7d46cf27ae66243c645' -H 'Authorization: Bearer QQ==' -o p7zip.tar.gz && tar -xzvf p7zip.tar.gz 'p7zip/17.04/lib/p7zip/7za' && mv -f 'p7zip/17.04/lib/p7zip/7za' .[/code]
[/olist]
[h2]b) UNINSTALLING PREVIOUS TLD VERSIONS[/h2]
[olist]
[*] This opens Warband's «[i]Modules[/i]» folder in the Finder so that you can delete any previous versions of the «TLD» folder on your own by right-clicking it and using «[i]Move to Trash[/i]». If the folder isn't there let's just skip this step and proceed to the installation:
[code]open ~/'Library/Application Support/Steam/steamapps/common/MountBlade Warband/Modules/'[/code]
[/olist]
[h2]c) INSTALLING THE MOD[/h2]
Next up we are going to extract the mod under «[i]{game-root}/Modules/TLD/[/i]». Just ensure that the two latest .7z files (the standalone and the latest nightly patch) from https://tldmod.github.io are already conveniently stored in your Downloads folder and this will take care of the rest:
[olist]
[*]Let's switch to the [i]Downloads[/i] folder, where the compressed files are.
[code]cd ~/Downloads[/code]
[*] Extract the standalone TLD 3.6 release for Warband:
[code]/tmp/7za x -y -bb1 -o"$HOME/Library/Application Support/Steam/steamapps/common/MountBlade Warband/Modules" TLD_3.6_wb.7z[/code]
[*] Extract the latest Warband nightly patch (the one that comes with the latest updates) and, you guessed it, overwrite yet again:
[code]/tmp/7za x -y -bb1 -o"$HOME/Library/Application Support/Steam/steamapps/common/MountBlade Warband/Modules" `find . -name 'TLD_3.6_wb_*' | sort -r -u | head -n 1`[/code]
[/olist]
[h2]d) FIXING WARBAND[/h2]
The mod is now technically installed, if the Warband engine worked as intended we shouldn't have to do the following workaround:
[olist]
[*] Fix the garbled font and the collision bodies so that you can actually hit baddies. Just paste this in the Terminal window and press Enter:
[code]cd ~/'Library/Application Support/Steam/steamapps/common' && ln -s 'MountBlade Warband/Modules/TLD/Data' Data[/code]
[*] Close the Terminal window.
[/olist]
That's it. Open Steam like your normally do and use Warband's [i]Configure[/i] utility to change the selected mod to «[i]TLD[/i]». If you followed this guide properly then the game should launch and reach to the main menu.
Have fun in Middle-earth![/quote]
[quote][h1]How to roll these changes back if your game breaks / Uninstalling the mod[/h1]
If you have used previous versions of this guide (or something went wrong and your game no longer works correctly) you will need to verify the integrity of game files to get the original files back, as shown here: https://support.steampowered.com/kb_article.php?ref=2037-QEUH-3335
Also, delete the [i]Data[/i] folder we added under [i]SteamApps > Common[/i] to fix the garbled fonts in other mods by pasting these lines in your Terminal:
[code]rm ~/'Library/Application Support/Steam/steamapps/common/Data'
rm ~/'Library/Application Support/Steam/steamapps/workshop/Data'
[/code]
Keep in mind that by using this newer macOS install method you should be able to keep TLD installed without replacing any game files, meaning that you should also be able to play Native and other mods. ¯\_(ツ)_/¯[/quote]
@Swyter
Copy link
Author

Swyter commented Nov 22, 2022

This is undefined by the Apple GLSL compiler, we are only having trouble with textureGrad, which is 130+, not dFdx:

#ifdef __VERSION__ == "120"
#error asdfasdf VER
#endif

@Swyter
Copy link
Author

Swyter commented Nov 23, 2022

Absolutely insane litany of workarounds for the very limited and old sed from macOS:
sed -i '' -E 's|'$'\xbf\x06''(...)'$'\xbe\x18''|'$'\xbf\x06''\1'$'\xbe\x20''|g' MaB_test

@Swyter
Copy link
Author

Swyter commented Nov 23, 2022

Screenshot 2022-11-23 at 03 39 02
And it actually works. Screw that \1 not defined in the RE under OS X.

@Swyter
Copy link
Author

Swyter commented Nov 23, 2022

 sed -E 's|(</dict>)|\
	<key>SDL_FILESYSTEM_BASE_DIR_TYPE</key>\
	<string>parent</string>\
\1|' Info.plist```

@Swyter
Copy link
Author

Swyter commented Nov 23, 2022

modfolders=("$HOME/Library/Application Support/Steam/steamapps/common/MountBlade Warband/Modules/TLD/GLShadersOptimized" "$HOME/Library/Application Support/Steam/steamapps/workshop/content/48700/299974223/GLShadersOptimized")
for curfolder in "${modfolders[@]}"; do
  if [[ ! -d "$curfolder" ]]; then continue; fi # swy: skip if that folder is missing
  cd "$curfolder" && echo "{i} overwriting font shaders in $curfolder"
  curl -O https://raw.githubusercontent.com/tldmod/tldmod/no-custom-font/_wb/GLShaders/fs_font_outline.glsl
  curl -O https://raw.githubusercontent.com/tldmod/tldmod/no-custom-font/_wb/GLShaders/fs_font_outline_mtarini.glsl
done

@Swyter
Copy link
Author

Swyter commented Nov 23, 2022

Screenshot 2022-11-23 at 06 59 16

@Swyter
Copy link
Author

Swyter commented Dec 6, 2022

Escape the $ variables while doing the zsh workaround for Catalina and above.

sh <<EOF && sh -c "# swy: zsh in catalina+ doesn't support inline comments: https://apple.stackexchange.com/a/405317"
modfolders=("\$HOME/Library/Application Support/Steam/steamapps/common/MountBlade Warband/Modules/TLD/GLShadersOptimized" "\$HOME/Library/Application Support/Steam/steamapps/workshop/content/48700/299974223/GLShadersOptimized")
for curfolder in "\${modfolders[@]}"; do
  if [[ ! -d "\$curfolder" ]]; then continue; fi # swy: skip if that folder is missing
  cd "\$curfolder" && echo "{i} overwriting font shaders in \$curfolder"
  curl -O https://raw.githubusercontent.com/tldmod/tldmod/no-custom-font/_wb/GLShaders/fs_font_outline.glsl
  curl -O https://raw.githubusercontent.com/tldmod/tldmod/no-custom-font/_wb/GLShaders/fs_font_outline_mtarini.glsl
done
EOF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment