#!/bin/bash

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

if [ "${sum}" != "a85caddc4d1e5838f404956e99995d27" ]; 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 "mhyprot2.sys" init function. No need for "mhyprotect.sys".
dd if=<(echo -ne "\xc3")     of=UnityPlayer.dll bs=1 seek=$((0x014CDDB0)) conv=notrunc

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

echo "==> Patch applied!"
exit 0
