#!/bin/sh
cat /etc/losetup.key | losetup -e aes -k 256 -p 0 /dev/loop/12 /mnt/usb/vf5r.dat
mount /dev/loop/12 /home
cat /etc/losetup.key | losetup -e aes -k 256 -p 0 /dev/loop/13 /mnt/usb/vf5r_rom.dat
mount /dev/loop/13 /home/disk0/rom

if [ ! -f /home/disk0/libalpb.so ]; then
echo "game has been modified, NOT ALLOWED!"
umount /home/disk0/rom
losetup -d /dev/loop/13
umount /home
losetup -d /dev/loop/12
exit 0
fi

if [ ! -f /home/disk0/rom/pkey00000.pub ]; then
echo "game has been modified, NOT ALLOWED!"
umount /home/disk0/rom
losetup -d /dev/loop/13
umount /home
losetup -d /dev/loop/12
exit 0
fi

pushd /games/saves/ > /dev/null
/games/saves/backup.sh load vf5r
popd > /dev/null
/home/run.sh -t -wxga
/usr/segaboot.sh
/home/run.sh -wxga
umount /home/disk0/rom
losetup -d /dev/loop/13
umount /home
losetup -d /dev/loop/12
pushd /games/saves/ > /dev/null
/games/saves/backup.sh save vf5r
popd > /dev/null
