Sign in Sign up
kretrod/lodestone Public
Branches
master
46 lines (41 loc) · 2.2 KB Raw
#!/bin/bash
# Rebuild, stop the client that is running, and load the new build.
#
# Each build goes in under a fresh name: the client never unmaps itself (that
# is what used to crash the game), so reusing a name would just load the old
# module again. Previous copies stay resident and inert.
#
# The unload marker is only read inside the render hook, so if the game happens
# to be between frames when we ask, the old copy has not unhooked by the time
# the new one tries — which surfaces as "already hooked" in the log. That is a
# race rather than a dead window, and the log has shown the old copy unhooking
# moments later, so we simply try again under a fresh name. If every attempt
# hits it, the game genuinely is not drawing and nothing can be injected until
# its window is back.
#
# Paths use forward slashes throughout — Windows accepts them, and it keeps
# backslashes from being eaten by two layers of shell quoting.
set -e
cd "$(dirname "$0")"
cargo build --release --target x86_64-pc-windows-gnu "$@" 2>&1 | grep -E "^error" -A10 || true
B=target/x86_64-pc-windows-gnu/release

# The loader travels with the client so the pair never drift apart.
scp -q "$B/lodestone-inject.exe" win:C:/lodestone/lodestone-inject-new.exe
ssh win 'Move-Item -Force C:/lodestone/lodestone-inject-new.exe C:/lodestone/lodestone-inject.exe -ErrorAction SilentlyContinue'

LOG=""
for attempt in 1 2 3; do
    NAME="lodestone-client-$(date +%H%M%S)-$attempt.dll"

    ssh win 'C:/lodestone/lodestone-inject.exe --eject' 2>&1 | tail -1
    scp -q "$B/lodestone_client.dll" "win:C:/lodestone/$NAME"
    ssh win "if (Test-Path C:/lodestone/lodestone.log) { Move-Item -Force C:/lodestone/lodestone.log C:/lodestone/lodestone.prev.log }; C:/lodestone/lodestone-inject.exe --no-wait C:/lodestone/$NAME" 2>&1 | tail -1
    sleep 4

    LOG=$(ssh win 'Get-Content C:/lodestone/lodestone.log -ErrorAction SilentlyContinue' 2>&1)
    if ! grep -q "already hooked" <<<"$LOG"; then
        tail -14 <<<"$LOG"
        exit 0
    fi
    echo "(the previous copy had not unhooked yet — trying again)"
done

tail -14 <<<"$LOG"
echo "still hooked by an older copy after 3 tries — the game is almost certainly not drawing frames"
exit 1