#!/bin/bash

FILE="UnityPlayer.dll"
sum=($(md5sum $FILE))

if [ "${sum}" != "76c77812286e04474b3644b5e1cc26ed" ]; then
	echo "Wrong file version or patch is already applied"
	echo "md5sum: ${sum}"
	exit 1
fi

# Include timestamps et all
cp --preserve=all UnityPlayer.dll UnityPlayer.dll.bak

# Skip both service init functions (mhyprotect.sys is redundant)
dd if=<(echo -ne "\xc3")     of=UnityPlayer.dll bs=1 seek=$((0x0148BDD0)) conv=notrunc
dd if=<(echo -ne "\xc3")     of=UnityPlayer.dll bs=1 seek=$((0x0148C420)) conv=notrunc

# Prevent access to uninitialized data (~ segfault)
dd if=<(echo -ne "\x31\xed") of=UnityPlayer.dll bs=1 seek=$((0x01B30933)) conv=notrunc

echo "==> Patch applied!"
exit 0
