@echo off
rem ============================================================
rem  PLANTECH (Rumble) Registry Setup
rem  Place this bat in the game root folder (next to PLANTECH.exe)
rem  and run as Administrator.
rem
rem  PLANTECH.exe is a 32-bit application. On 64-bit Windows,
rem  its HKLM\SOFTWARE access is silently redirected to
rem  HKLM\SOFTWARE\WOW6432Node. This script writes to BOTH the
rem  64-bit and 32-bit views to be safe.
rem ============================================================

cd /d "%~dp0"

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$ErrorActionPreference='Stop';" ^
  "$g=(Get-Location).Path;" ^
  "if (-not $g.EndsWith('\')) { $g = $g + '\' };" ^
  "$sub='SOFTWARE\' + [char]0x30DA + [char]0x30F3 + [char]0x30AE + [char]0x30F3 + [char]0x30EF + [char]0x30FC + [char]0x30AF + [char]0x30B9 + '\' + [char]0xFF32 + [char]0xFF55 + [char]0xFF4D + [char]0xFF42 + [char]0xFF4C + [char]0xFF45 + '\1.0\PLANTECH APPLICATION';" ^
  "Write-Host ('Game path : ' + $g);" ^
  "Write-Host ('Subkey    : HKLM\' + $sub);" ^
  "Write-Host '';" ^
  "function Write-Reg($view, $label) {" ^
  "  $base=[Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine',$view);" ^
  "  $k=$base.CreateSubKey($sub);" ^
  "  if ($k -eq $null) { throw 'CreateSubKey failed - need admin' };" ^
  "  $k.SetValue('MainPath',  $g,             'String');" ^
  "  $k.SetValue('SinPath',   $g + 'SIN\',    'String');" ^
  "  $k.SetValue('MessPath',  $g + 'MESS\',   'String');" ^
  "  $k.SetValue('AnimPath',  $g + 'ANIM\',   'String');" ^
  "  $k.SetValue('MidiPath',  $g + 'MIDI\',   'String');" ^
  "  $k.SetValue('WavPath',   $g + 'WAV\',    'String');" ^
  "  $k.SetValue('VoicePath', $g + 'VOICE\',  'String');" ^
  "  $k.SetValue('PacPath',   $g + 'PAC\',    'String');" ^
  "  $k.SetValue('SetupType', '2',            'String');" ^
  "  $k.Close();" ^
  "  Write-Host ('[OK] wrote ' + $label) }" ^
  "Write-Reg 'Registry32' '32-bit view (WOW6432Node)';" ^
  "Write-Reg 'Registry64' '64-bit view';" ^
  "Write-Host '';" ^
  "Write-Host '--- Verify 32-bit view ---';" ^
  "$base=[Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine','Registry32');" ^
  "$k2=$base.OpenSubKey($sub);" ^
  "foreach ($n in 'MainPath','SinPath','MessPath','AnimPath','MidiPath','WavPath','VoicePath','PacPath','SetupType') {" ^
  "  $v=$k2.GetValue($n); Write-Host ('  ' + $n.PadRight(11) + '= ' + $v) }" ^
  "$k2.Close();" ^
  "Write-Host '';" ^
  "Write-Host '[OK] done. Try launching the game.'"

if %errorlevel% neq 0 (
    echo.
    echo [ERROR] Failed. Right-click this bat and "Run as administrator".
    echo.
    pause
    exit /b 1
)

echo.
pause