PDA

View Full Version : Exiting Visual Pinball problem



MiTKiNG
11-22-2010, 07:39 AM
Hi everyone!

I have a problem exiting visual pinball from hyperspin frontend. I use hyperlaunch and everything works fine but when I exit from the frontend the hiscores and credits dont save.

I have seen two diferent CloseProcess in the ahk file, CloseProcess and CloseProcess2. When I use CloseProcess which code is listed here:

CloseProcess:
Hotkey, %exitScriptKey%, Off
Process, Close, %Executable%
Process, WaitClose, %Executable%
Gui, Color, 000000
Gui -Caption +ToolWindow +AlwaysOnTop
Gui, Show, W%A_ScreenWidth% H%A_ScreenHeight%, BlackGui
return

All works perfect, load, clean exit. But hi scores dont save. And if I use CloseProcess2 which code is:

CloseProcess2:
Hotkey, %exitScriptKey%, Off
;Process, Close, %Executable%
Send, {ALTDOWN}{F4}{ALTUP}
Process, WaitClose, %Executable%
Gui, Color, 000000
Gui -Caption +ToolWindow +AlwaysOnTop
Gui, Show, W%A_ScreenWidth% H%A_ScreenHeight%, BlackGui
return

I have no clean exit, the window of visual pinball program stay on top of hyperspin frontend but when I close it with the X button, the records are saved.

All I need is a clean exit to frontEnd with hi scores saved.

Any advise on this? Every help would be appreciated.

Thanks in advance!

blur
11-22-2010, 03:05 PM
you have code for clean exit of fp and vp in hyperpin installation


for vp you don't use close process but close window - it's actually same as alt-f4, here is the code, if you don't have hp:

first part (look at closevp function);


else if (systemName = "Visual Pinball" && (executable = "VPinball.exe"))
{
Hotkey, $%exitEmulatorKey%, CloseVP
Run, "%emuPath%\%executable%" /play -"%tablePath%%tableName%.vpt",,hide UseErrorLevel
WinWaitActive, ahk_Class VPPlayer
Gui, destroy
Process, WaitClose, VPinball.exe

}


and second part:



CloseVP:
Hotkey, %exitScriptKey%, Off
;Visual Pinball must be closed this way instead of killing process or it wil not save your last game information.i.e score/credtis
DetectHiddenWindows, on ;Or next line will not work
WinHide, ahk_class VPinball ;This line fixes where the VP Window flashes real quick when closing the window for a cleaner exit
WinClose, ahk_class VPinball
return

MiTKiNG
11-25-2010, 07:34 AM
Thank you so much! That worked perfectly, like i want. I hope your reply help other users.

Cheers!

blur
11-25-2010, 02:16 PM
great:beer:

MiTKiNG
12-03-2010, 11:12 PM
Blur, now that I have it launching and exiting perfectly I have a doubt. Is there a way for not to see the vp program and vpinmame windows when launching a table?

Searching I have seen something about wrappers but I have tried one and it does not work.

Is there an ahk way?

Again, thank you!

blur
12-04-2010, 03:42 AM
again it is already done like that in hyperpin :)
visual pinball and future pinball launching screen is hidden by big black surface
but i think same code is in hyperspin also - you only have to set hide desktop and maybe hide taskbar to true

here is fplaunch code so you can check how is that done:


/**
* FPLaunch Version 1.00
* Autohotkey script by BadBoyBill badboybill@hyperspin-fe.com
* CursorHide by Lazlo
*
* If you are reading this and do not have autohotkey you can get it
* @ http://www.autohotkey.com/download/
* If you would like to modify this script and share it thats OK, but
* see if your modification is something that we would like to add
* to the official version.
*
* Refer to the autohotkey documentation for the keyoboard keylist
*
* If this script does not support your favorite emulator
* then please request support @ http://www.hyperspin-fe.com/forum
*
* Supports Future Pinball and Visual Pinball
*
*/

#SingleInstance force ;Prevent multiple instances
#InstallKeybdHook
SetTitleMatchMode 2

;------------------------------------------------------------------------------;
; MAIN SETTINGS ;
;------------------------------------------------------------------------------;

;[UNIVERSAL HOTKEYS] ;SEPERATE MULTIPLE KEYS WITH &(ampersand) up to 2 keys.
exitScriptKey = ~q & ~s ;Secret hotkey(s) to exit script if needed
;Not to be confused with exit emulator keys

exitEmulatorKey = Esc ;This key/key combo will close any emulators
;that do not have normal closing methods.

toggleCursorKey = t ;hotkey(s) to show or hide cursor if needed
;when hideCursor below is true

;[MOUSE CURSOR]
hideCursor = true ;Automatically hide cursor during script
;WARNING: Make sure ALL your emu's are running fine

;[WINDOWS]
hideDesktop = true ;Attempts to hide desktop with black screen, might help
;on some emu's for hiding launching windows.

hideTaskbar = true ;Hide the windows taskbar when running emu's.
;WARNING: Make sure ALL your emu's are running fine
; before setting this to true as a precaution.*



/*
*:If for some weird reason the script hangs follow these steps to get back to normal.
1. If an emulator hangs up or cant load your game then first try to exit the emu
by pressing your Emulator exit hotkey above.
2. If your emu exited but your mouse cursor is gone use your cursor toggle hotkey.
3. Next try to exit the script by pressing your Exit Script Hotkey above. This
will also bring back your cursor and taskbar is they are set to true.
*/







;************************************************* ******************************
;* EDIT BELOW THIS POINT AT YOUR OWN RISK *
;************************************************* ******************************

;------------------------------------------------------------------------------;
; GET PARAMATERS AND SET HOTKEYS ;
;------------------------------------------------------------------------------;

;CHECKING FOR 2 PARAMS, IF NOT THEN EXIT
if 0 < 2
{
MsgBox Usage: FPLaunch.ahk/exe "System Name" "Rom Name"
ExitApp
}

systemName = %1%
tableName = %2%

Hotkey, %exitScriptKey%, ExitScript

if (hideCursor = "true")
{
MouseMove %A_ScreenWidth%,%A_ScreenHeight%
Hotkey, %toggleCursorKey%, ToggleCursor
SystemCursor("Off")
}
if (hideTaskbar = "true")
{
WinHide ahk_class Shell_TrayWnd
WinHide Start ahk_class Button
}

if (hideDesktop = "true")
{
Gui, Color, 000000
Gui +AlwaysOnTop -Caption +ToolWindow
Gui, Show, x0 y0 W%A_ScreenWidth% H%A_ScreenHeight%, BlackScreen
}

WinClose, cmd.exe
;------------------------------------------------------------------------------;
; GET AND CHECK PATHS ;
;------------------------------------------------------------------------------;
GoSub, CheckINI
IniRead, iniEmuPath, %A_ScriptDir%\Settings\Settings.ini, %systemName%, Path
emuPath := GetFullName(iniEmuPath)
IniRead, iniTablePath, %A_ScriptDir%\Settings\Settings.ini, %systemName%, Table_Path
tablePath := GetFullName(iniTablePath)
IniRead, executable, %A_ScriptDir%\Settings\Settings.ini, %systemName%, Exe

romExtension =
GoSub, CheckPaths

;------------------------------------------------------------------------------;
; RUN SYSTEM ;
;------------------------------------------------------------------------------;


;**********************************FUTURE PINBALL***********************************
if (systemName = "Future Pinball" && (executable = "Future Pinball.exe"))
{
Hotkey, $%exitEmulatorKey%, CloseFP
; RunWait, "%emuPath%\%executable%" /open "%tablePath%\%tableName%.fpt" /play /exit /arcaderender,,hide UseErrorLevel
RunWait, "%emuPath%\%executable%" /open "%tablePath%\%tableName%.fpt" /play /arcaderender,,hide UseErrorLevel
Process, WaitClose, Future Pinball.exe
}

else if (systemName = "Visual Pinball" && (executable = "VPinball.exe"))
{
Hotkey, $%exitEmulatorKey%, CloseVP
Run, "%emuPath%\%executable%" /play -"%tablePath%%tableName%.vpt",,hide UseErrorLevel
WinWaitActive, ahk_Class VPPlayer
Gui, destroy
Process, WaitClose, VPinball.exe

}
else
{
MsgBox,48,Error,%systemName% is an invalid System Name or %executable% isnt supported yet,6
}

;------------------------------------------------------------------------------;
; WHEN EMULATOR FINISHES OR IF LAUNCH EXE FAILS ;
;------------------------------------------------------------------------------;
;************PROBABLY DO NOT NEED TO EDIT THIS AREA*************

if (ErrorLevel = "ERROR")
{
MsgBox,48,Error,Failed to run executable check your paths,6
}
Goto ExitScript ; Exits script and returns to frontend


;------------------------------------------------------------------------------;
; KILL COMMANDS ;
;------------------------------------------------------------------------------;
;************PROBABLY DO NOT NEED TO EDIT THIS AREA*************

CloseProcess:
Hotkey, %exitScriptKey%, Off
Process, Close, %executable%
Process, WaitClose, %Executable%
return

CloseFP:
;Future Pinball must be closed this way instead of killing process or it wil not save your last game information.i.e score/credtis
Send {Escape}
Sleep, 1000
Send ^{s}
Sleep, 1000
Send !{F4}
return


CloseVP:
Hotkey, %exitScriptKey%, Off
;Visual Pinball must be closed this way instead of killing process or it wil not save your last game information.i.e score/credtis
DetectHiddenWindows, on ;Or next line will not work
WinHide, ahk_class VPinball ;This line fixes where the VP Window flashes real quick when closing the window for a cleaner exit
WinClose, ahk_class VPinball
return

ExitScript:
Gui, destroy
Process, Exist, HyperPin.exe
if (hideTaskbar)
WinShow ahk_class Shell_TrayWnd
WinShow Start ahk_class Button

PID := errorLevel
if (PID)
{
WinActivate, ahk_pid %PID%
;WinWaitActive, ahk_pid %PID%
}
if (hideCursor)
SystemCursor("On")
ExitApp




OnExit, ExitScript
return


;------------------------------------------------------------------------------;
; REST OF SCRIPT ;
;------------------------------------------------------------------------------;
;************PROBABLY DO NOT NEED TO EDIT THIS AREA*************



SystemCursor(OnOff=1) ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
static AndMask, XorMask, $, h_cursor
,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
, b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 ; blank cursors
, h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13 ; handles of default cursors
if (OnOff = "Init" or OnOff = "I" or $ = "") ; init when requested or at first call
{
$ = h ; active default cursors
VarSetCapacity( h_cursor,4444, 1 )
VarSetCapacity( AndMask, 32*4, 0xFF )
VarSetCapacity( XorMask, 32*4, 0 )
system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32 645,32646,32648,32649,32650
StringSplit c, system_cursors, `,
Loop %c0%
{
h_cursor := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
h%A_Index% := DllCall( "CopyImage", "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
, "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
}
}
if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
$ = b ; use blank cursors
else
$ = h ; use the saved cursors

Loop %c0%
{
h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
}
}
ToggleCursor:
SystemCursor("Toggle")
return

IniRead(Filename, Section, Key, Default = "") {
FileRead, text, *t %Filename%
text = `n%text%`n
StringTrimLeft, text, text, InStr(text, "`n[" . Section . "]`n")
Loop, 8 {
sp := sp . " "
StringReplace, text, text, %Key%%sp%=, %Key%=
If ErrorLevel
Break
}
start := InStr(text, "`n" . Key . "=")
If !start
Return, Default
start += StrLen(Key) + 2
StringMid, Value, text, start, InStr(text, "`n", false, start) - start
Return, Value
}

;Get Full Path from Relative Path
GetFullName( fn ) {
static buf, i
if !i
i := VarSetCapacity(buf, 512)
DllCall("GetFullPathNameA", "str", fn, "uint", 512, "str", buf, "str*", 0)
return buf
}

CheckINI:
IfNotExist, %A_ScriptDir%\HyperPin.exe
{
MsgBox,48,Error, Must be in same directory as HyperPin.exe,6
Goto ExitScript
}
IfNotExist, %A_ScriptDir%\Settings\Settings.ini
{
MsgBox,48,Error,Cannot Find %A_ScriptDir%\Settings\Settings.ini,6
Goto ExitScript
}
return

CheckPaths:
romFound =
StringRight, emuPathBackSlash, EmuPath, 1
StringRight, tablePathBackSlash, TablePath, 1

If (emuPathBackSlash != "\" || tablePathBackSlash != "\")
{
MsgBox,48,Error, Make sure your paths contains a backslash on the end ,6
Goto ExitScript
}
If (executable = "")
{
MsgBox,48,Error, Missing executable in Settings.ini ,6
Goto ExitScript
}
If (tablePath = "")
{
MsgBox,48,Error, Missing rom path in Settings.ini ,6
Goto ExitScript
}
If (emuPath = "")
{
MsgBox,48,Error, Missing emulator path in Settings.ini ,6
Goto ExitScript
}
IfNotExist, %EmuPath%%Executable%
{
MsgBox,48,Error,Cannot Find %EmuPath%%Executable%,6
Goto ExitScript
}
return

MiTKiNG
12-13-2010, 11:03 AM
Many thanks again!! This is working very well. I donīt know where my ahk come from, but I didnt have all this stuff. Is there an official ahk to download? Which I have seen in download section is an unofficial one.

Or can you share yours? Im having problems with naomi too, following one thread instructions on the forum, the system doesnt start, nothing happens.

Thank you for your help blur, very appreciated!

BadBoyBill
12-13-2010, 07:29 PM
I will add modules for these systems tonight for HL 2.0 that have the better way of exiting, the downloads for the modules can by running HL 2.0 and clicking the download button.

MiTKiNG
12-16-2010, 03:23 AM
That sounds amazing, but... what is HL 2.0? HyperLaunch, HyperList... It is a link, a program? Sorry about my ignorance but I have looking around and havent seen what you said.

Thnks BadBoyBill!

MiTKiNG
08-15-2011, 12:27 AM
Hi,
I cannot seem to get this working:

I must be doing something wrong. (Yes, I compile.) Could you please let me see your ahk? Or at least the pinball part of it in it's entirety? Maybe I'm putting the code in the wrong place...

-Ed-

Hi SPeD66 this post is a few old. The doubt I had in the post is for my ahk code when I had a compiled ahk for all the systems in the root folder.

Now Im using HyperLaunch 2.0 with modules that are not necesary to be compiled. Have you tried HL2.0 I recomend it to you. Thats the way everyone up to date is runing games by now.

Here is my visual pinball module code (thanks to BBB) which is in the hyperlaunch 2.0 modules url (execute hyperlaunch 2.0 and click in the Download modules to go there):


;----------------------------------------------------------------------------
; Visual Pinball
;
;----------------------------------------------------------------------------

Hotkey, p, PauseVP
inPause = false
Run, "%emuPath%%executable%" -play -"%romPath%%romName%%romExtension%",,hide UseErrorLevel
WinWaitActive, ahk_Class VPPlayer
Gui, destroy
Process, WaitClose, %executable%

ExitApp

PauseVP:
if (inPause = "false") {
inPause = true
Send {Esc}
} else {
inPause = false
Send r
}
return

CloseProcess:
;Visual Pinball must be closed this way instead of killing process or it wil not save your last game information.i.e score/credtis
DetectHiddenWindows, on ;Or next line will not work
WinHide, ahk_class VPinball ;This line fixes where the VP Window flashes real quick when closing the window for a cleaner exit
WinClose, ahk_class VPinball
return

SPeD66
08-15-2011, 02:19 PM
Now Im using HyperLaunch 2.0 with modules that are not necesary to be compiled. Have you tried HL2.0 I recomend it to you. Thats the way everyone up to date is runing games by now.
I'm still using the old Hyperlaunch, so I guess that's why this code isn't working for me. Thank you for answering my pm. :)