apply.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. # Fix 2: make bakinplayer.exe pass a real plugin path to the native engine.
  3. #
  4. # Yukar.Player.Program calls SharpKmy.Entry.initialize("", null), so pluginpath
  5. # is NULL. The native scanPlugin then tries GetModuleFileNameW(NULL) to derive a
  6. # search dir, which under Wine does not resolve to the on-disk data dir where the
  7. # .dlp loaders live, so nothing is found. We rewrite the managed IL so the second
  8. # argument becomes AppDomain.CurrentDomain.BaseDirectory (the folder containing
  9. # bakinplayer.exe), which makes scanPlugin take its explicit-path branch.
  10. #
  11. # This is a pure IL rewrite done with Mono.Cecil (see Program.cs). It needs the
  12. # .NET SDK (`dotnet`) available on PATH to build the tiny patcher. Reversible via
  13. # the bakinplayer.exe.orig backup.
  14. set -euo pipefail
  15. GAME_ROOT="${1:?usage: apply.sh <game-root-dir>}"
  16. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  17. EXE="$GAME_ROOT/data/bakinplayer.exe"
  18. KNOWN_ORIG_MD5="dc76b6ee233efaa1270d845b47fd4e3d" # unpatched v1.1.0 (589,312 bytes)
  19. [ -f "$EXE" ] || { echo "!! not found: $EXE"; exit 1; }
  20. command -v dotnet >/dev/null || { echo "!! 'dotnet' (.NET SDK) not found on PATH, needed to build the IL patcher"; exit 2; }
  21. md5now=$(md5sum "$EXE" | cut -d' ' -f1)
  22. if [ "$md5now" != "$KNOWN_ORIG_MD5" ]; then
  23. echo " (note: bakinplayer.exe md5 $md5now != known-original $KNOWN_ORIG_MD5)"
  24. echo " If it was already patched by this tool, that is expected; continuing."
  25. fi
  26. echo "== Fix 2: building IL patcher (dotnet) ..."
  27. dotnet build -c Release -o "$HERE/bin" "$HERE/patcher.csproj" >/dev/null
  28. [ -f "$EXE.orig" ] || cp -n "$EXE" "$EXE.orig"
  29. TMP="$(mktemp --suffix=.exe)"
  30. if dotnet "$HERE/bin/patcher.dll" "$EXE.orig" "$TMP"; then
  31. cp "$TMP" "$EXE"; rm -f "$TMP"
  32. echo "== Fix 2: patched bakinplayer.exe (pluginpath=BaseDirectory), backup at bakinplayer.exe.orig"
  33. else
  34. rm -f "$TMP"
  35. echo "!! Fix 2: patcher found no patch site; bakinplayer.exe may be a different build"; exit 4
  36. fi