Jump to content
samwyze

FPLaunch MOD: Pause and Loading screens...

Recommended Posts

Hello,

I can't locate "basic ahk" on the ahk website. There is a single download button and it directly downloads 'ahk L'. On install there are two options: ansi 32-bit and Uncode 32-bit. Both result in the compiled code failing for different reasons. Can somebody point out my obvious idiocy on not finding a 'basic ahk' download?

Thanks,

Matt

Looks like ahk decided to remove basic version from their site, maybe you can find it somewhere on internet, search for ahk basic or exact version from the manual 1...48 or something like that

Share this post


Link to post
Share on other sites

after a bit of searching, I found it on a German (or maybe Bavarian) site. Works fine. If anybody gets stuck and can't find it- pm me.

Share this post


Link to post
Share on other sites

Blur - Any chance of adding DWJukebox and LEDBlinky compatiblity to FPLaunch?

I already got a really good jump on it. If you didn't see my previous post (pg. 110) with the vid - please check it out.

Share this post


Link to post
Share on other sites

I am requesting you add 2 additional and important pieces of code the next version of fplaunch.

1)Use custom B2S settings per table in Hyperpin

http://www.vpforums.org/index.php?showtopic=20807&hl=%2Bb2s+%2Bfplaunch

2) I don’t have link for it but essentially it allows you to disable ledcontol.ini so people with forcefeedback on their cabs can turn it on and off through the HS menus.

I will get permission from Kodiac and Deegor.

Edited by bent98

Share this post


Link to post
Share on other sites

FYI: If you are having trouble finding the basic ahk compiler, google this: AutoHotkey104805_Install

-Matt

Edited by mattdavis

Share this post


Link to post
Share on other sites

I have a problem with ESC and P (both opens the same window but the result is different):

If I press the ESC key the same menu appears as with "P" - this is clear. But when I press "P" I can continue playing after selecting "Back", when I press the "ESC" key the same menu appears but I can not continue playing as the Visual Pinball menu (with the three choices) appears and I can not select anything (should be able to press "R"esume). In this case I have to press ALT+Tab to change to the Visual Pinball Player, then it works. But I can only do that with the PC keyboard. How can this problem be solved?

Moreover I see the PinMAME splash screen appearing right under the "loading table"-animation. How can this be hidden?

Thanx for any info!

Edit: Is there a reason why AutoHotKey 1.0.48.05 should be used and not the latest version 1.1.09.02???

Edited by Clark Kent

Share this post


Link to post
Share on other sites

that's normal for esc - you have to use e instead of esc (or p)

to avoid pinmame splash screen you have to use cabinet pinmame

latest ahk version is not compatible with the fplaunch script

Share this post


Link to post
Share on other sites

But I have the cabinet version of pinmame installed!

Can I use "e" (or "p") for both VP and FP to exit/show the exit menu?

Interesting that the latest ahk version is not fully compatible - I did not notice any problem with the script itself. Is ahk 104805 compatible with Win7 x64?

Share this post


Link to post
Share on other sites

do i see a tone here?

i tried new ahk_L for few weeks, i wanted to use it cause it makes com objects and drawing swf easier - but all the time i was getting some small window on exit one by two cm out of nowhere that had to be closed manually with mouse - i posted finds in this thread, never found what it is - i was testing on win7

so for me it is incompatible, there is also a backslash problem which every one bumps into if they try to compile with new ahk

same keys are used for both vp and fp

check fplaunch manual on first page of this thread - fp has to be configured specially

Share this post


Link to post
Share on other sites

OK, I'm using "e" instead of "ESC" now. It really seems to work much better! No more weird problems when pressing the exit button! I also noticed that somehow my pinmame.dll was overwritten with the non-cabinet version - I replaced the .dll file with the cabinet-version of it and now I do not see the splash screen anymore. So all is working well now! :)

I still have two problems when using FuturePinball-tables:

1) It happens that when starting a FP-table, the editor window of FP could be seen in the background (between HyperPin frontend and the "please wait" display). Can this be hidden in some way?

2) The graphics right under the exit menu (when I press "e" for menu/pause) is black instead of the graphics of the table in the background. Is there a way to fix this glitch?

I still do not understand the thing with AHK: When I'm using the compiled exe of FPLaunch only I do not need to install AHK 1.048.05, right?

Using Win7 x64 here!

Edit: Enclosed two pictures of the two problems I have with FuturePinball.

Edit2: After some trial and error I noticed that FP freezes HyperPin now and then after pressing the exit button (in my case "e") short and exit via menu or long with the countdown. After the freeze I can only use the taskmanager to kill all tasks. This is not good for a cabinet...

post-12536-142870583228_thumb.jpg

post-12536-14287058323_thumb.jpg

Edited by Clark Kent

Share this post


Link to post
Share on other sites

never had that problem with FP

it is started minimized on my rig and menu is drawn over full table image.

try to set startup mode to minimized to fp exe (or link to fp exe) - when you click fp it should open minimized

from latest fplanch fp is started minimized so should be invisible on screen

for menus - menus are drawn over printscreen image - try to do print screen of fp and check if image is ok, maybe print screen doesn't work good with fp

Share this post


Link to post
Share on other sites

Thank you for your help! :)

I wonder how to set the startup-mode to minimized!? I thought is is only possible when using a link (but this link won't be started by your script)? Please explain - I think this should solve my problems with FP! Or do you think that something other could be wrong with my installed FP? Are there any hidden settings?

How could printscreen be broken? And the better question would be how to repair it if it is broken!? Do you think this has something to do with the window handling of Windows 7? Maybe the windows are not drawn on the right layer and the screenshot is made from the wrong layer? But how can I change that behavior?

I read at another forum thread (do not remember where at the moment) that a change in your script how to handle the windows could repair some strange behavior. I think it even was a post from you, but I do not find it anymore. Can you bring some light into my darkness here? ;)

And as written in my last post, exiting from FP sometimes result in a freeze of HyperPin. FP exits and HyperPin appears as always but it's frozen - no video playback, no reaction to key input. I can only use Ctrl+Alt+Del to enter the Taskmanager and force quit all running apps (or pressing the power button on my cabinet so that Windows is shutting down). This does not happen in VP but only in FP. These freezes occure at a friends cabinet with the same hardware configuration, too! So this is no single case...

Thanks and keep on doing your great stuff!

Edited by Clark Kent

Share this post


Link to post
Share on other sites

Yes run minimized is possible to do only on links. But since from the ahk script I'm running fp minimized and it doesn't work i want to see how it works on a link.

Bad printscreen is an old problem of FP, when you do printsceen in windows fp screen is saved as black screen - you can see image from last printscreen in your HP directory - it is named screen.bmp

If print screen doesn't work - you have to find better (newer/older) driver. You can find here and on vpf which drivers are good and which have known bugs in vp and fp.

There are also a two numbers in settings.ini for playfield and backglass screen:

pfScreenNum = 1

bgScreenNum = 2

You have to set them according to your setup or you will get wrong image on screen (backglass instead of playfield)

As for freeze - you have to set all exe's to native mode if you are on win 7 (speccialy hyperpin, fplaunch, ultravp and hglass)

In compatibility mode hyperpin has memory leak (every comp. mode) and it kills comp after some time.

Some people get better results with vp and fp in xp sp3 comp. mod so you can try that also

Share this post


Link to post
Share on other sites

I was just playing around with a link of Future Pinball.exe. First I tried simply to select the minimize option in the properties - which was not working first time I tried. The window was "normal" and not "minimized" as selected when I started it. Then I tried to deselect the WinXP SP3 compatibility mode and the run as admin option - only one time it worked. After starting Future Pinball the second time, the window was not minimized anymore. I was only playing around with these options and suddenly it worked! I must admit that I did not open the Future Pinball regular editor window again as I think as soon as I do that the minimize on startup would not work anymore. So let's see how long this will work! :) Why this very very strange behavior of Windows 7????

The screen.bmp is really black! Interesting. This is a driver thing only? I'm using one of the latest driver versions as I had some graphic glitches in Future Pinball with other/older drivers which were totally gone with 306.97! Can you tell me the page where this is discussed? Nevertheless I have a good starting point to investigate! Thank you for the great info!

As for the freezes: All exe's are in native mode (hyperpin, fplaunch, ultravp, hglass), except FuturePinball.exe and VPinball.exe. Only these two use the XP compatibility mode and the run as admin option (I think visual designs are also disabled). It's interesting that if I do not use these options, even more distortions than only the editor window appear while starting Future Pinball! Is it ok to have these two exe's (FP and VP) with compatibility mode or are these two settings also killing HyperPin after some time?

Share this post


Link to post
Share on other sites

Prior to today I was running wip8, exit set to escape, pc has xp, and a nvidia 285 with very old drivers. Everything worked PERFECTLY. Today my new nvidia 660ti came in so I removed the 285 and installed the 660ti. I updated drivers to 306.23. Vpinball direct from emulator works fine. However in hyperpin as I exit a table it is still running in the background now. This never happened before. It is causing different backglasses/dmds/playfields to show and then will eventually crash. I searched for others having the same issue and saw recommendations to try wip9 so I did. This did not fix the issue. Then I saw to remap escape key to E key so I did that, also did not correct the issue. Is there anything else I can try short of getting rid of a brand new video card and going back to a 4 year old card and ancient drivers?

Share this post


Link to post
Share on other sites

Here is a new version of fplaunch 1.295 wip 9 with hiscores and table name.

Tnx goes to dnadisturber, bleasby and horseyhorsey for pinemhi and fplaunch scripts.

To use this script just copy this code to fplaunch.ahk and recompile (i used basic ahk and ahk_L ANSI version and they both work, i did not test unicode version) and download pinemhi.exe and pinemhi.ini from http://www.pinemhi.com/ and put them in hyperpin dir.

Report back bugs if you find some.

;  FPLaunch MOD by bbb, samwyze and blur
Version := "FPLaunch 1.295 WIP 9 with hiscores and title"
/*
Check FPLaunch Manual at
	http://www.hyperspin-fe.com/forum/showthread.php?t=10935


Based on original FPLaunch 1.2 by [email protected]
Modified by dumpster.monkey (samwyze) & blur 
CursorHide by Lazlo
Thanks to tic (Tariq Porter) for his GDI+ Library
	http://www.autohotkey.com/forum/viewtopic.php?t=32238
Includes modified pause code from ManofWars Nuevo FPLaunch 1.2
Includes exit png's based on jpg's from BBB's 'exit feature' thread
Includes exit menus by samwyze
Includes support for Pause in FP by blur and loafer
For pause to work in FP you have to define right mouse button as pause in FP
Includes support for saving FP table position (scrolllock) on exit by blur
VP nag screen removal by blur
B2S backglass exe support by rosve
different exe, sound level and hdrender flag support by bigboss
	http://www.vpforums.org/index.php?showtopic=12906
slamit bigscore pinball support by bigboss
	http://www.hyperspin-fe.com/forum/showthread.php?t=12198
ledwiz support by darkfall:
	http://www.vpforums.org/index.php?showtopic=16186&hl=

All images should be placed in %HyperPinDir%\Media\HyperPin\Images 
All settings are added to %HyperPinDir%\Settings\Settings.ini


NOTE: This is a wip and is by no means complete or optimized
Feel free to disect, mod, clean, optimize, distribute or delete!
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.   


CODE MAP
This is short list of all sections and functions in this script 
so that you can find and customize them quickly
GET PARAMATERS AND SET HOTKEYS 
	reads input parameters from command line
GET AND CHECK PATHS 
	gets settings from ini files
	calculates window coordinates
	hides taskbar, cursor and desktop
RUN SYSTEM
	FUTURE PINBALL, VISUAL PINBALL
		commands for launching vp and fp
WHEN EMULATOR FINISHES OR IF LAUNCH EXE FAILS
	error msg
	key remaps for Slamit pinball
KILL COMMANDS
	this is where all our procedures are!
Procedures:
	CloseProcess - kills process - not used
	QuickLaunch - launching gui
	Loading screen
		CreateLoadScreen - loading screen loop with slider, closes nag messages
		CheckPlayer - check if player is active
		CheckVP - checks 3 times
		CheckFP - checks 3 times
		WaitPlayer - wait for  player to be active
		WaitVP - waits 3 times
		WaitFP - waits 3 times
		CloseProgress - closes loading screen with slider
		MoveProgress - moves rotating hyperpin ball
	Exit screen
		ExitScreen - call exit menu or exit countdown
		CreateExitScreen - create exiting in 321 screens
		CreatePauseScreen - show blue PAUSED image
		CreateBlackScreen - do printscreen of fp table and show it on the screen
	PrintScreen - save playfield screenshot to media folder
	PrintBG - save bg creenshot to media folder
	PauseFP - call pause screen or exit menu
	PauseVP - call pause screen or exit menu
	PauseGame - call vp of fp pause
	ShowFP - close player and show editor on edit key
	ShowVP - close player and show editor on edit key
	ShowGame - show vp or fp
	SetSaveFPNeeded - set flag to save fp table on exit
	CloseFP - closes fp
	CloseVP - closes vp
	CloseGame - close vp or fp
	Exit menu
		ExitMenu - draw or close exit menu
		closeMenus - closes menus
		MenuSwap - change active menu item
		selectItem - select active menu item
	Flyer
		Flyer - show flyer
		MoveUp, MoveUp - going up and down in menus
		flyerSwap - swap flyer
	Instructions
		Instructions - show Instructions
		instrSwap - swap instructions
	DrawImageBTB - functions for drawing images - used in menus, flyers, instr.
	External functions (from other people)
		rosve - support for B2S active backglasses
		rosveClose - kills B2S backglass
		bigboss - support for different exe, sound levels and hdrender off
		bigbossClose - returns sound and hdrender settings
		SlamitBigScore - support for slamit bigscore from bigboss
		CloseSlam - close slamit pinball
		PINemHiScore - hiscores from dna disturber, tnx to blesby and horseyhorsey
		ExitScript - kills all gui's, activates hyperpin
REST OF SCRIPT
	- scripts for enabling/disabling cursor and reading ini files
	toLog - logging to screen and log file
	Gdip_BitmapReplaceColor - replace color - used for swf instructions
	CaptureScreen - scripts for screen capture - removed, not needed

HISTORY
 1.295 wip 2
 + add sleep after printscreen
 + add sleep during winactivate of vpinball, dmd and backglass
 + put winactivate outside of loading screen
 + enable other exe names
 + read logical and phyisical key state
 + win activate of secondary fp window (backglass) - doesn't help
 + put version in usage - double click on fplaunch.exe to get version
 + bigboss additions (more exe files, sound mods ...)
 + support for slamit pinball


 1.295 wip 3
 + winactivates removed (you have to set exe to nt4sp5 comp mode)
 + fix runtime error on close (you have to set exe to comp mode)
 + fix dmd not visible behind playfield (set exe to comp mode)
 + fps drop - same drop comes from loose of focus so it's not script related
 + shorter time for esc screens
 + win activate on nag screens brings them to focus and closes them


 1.295 wip 4
 + fix dmd not visible behind playfield
 + put all rosve and bigboss code to functions
 + write a code map
 + winactivate of fp after pause and printscreen
 + fix winactivate on z screen buffer message (msg stays in back)
 + fgi keys mapped to enter for slamit bigscore pinball
   if you don't use slamit you can remove them


 1.295 wip 5
 + save printscreen-a under name taken from description
 + quick launch gui from HL 2.0
 + options do not get overwritten
 + menus from sam
 + show instructions and flyer on pause
 + fix slow down after close (when vp is still closing) - fixed - 
   you have to wait a little till windows free memory

 1.295 wip 6
 + pauseVPinball key changed to pauseKey since it is not just for VP
 + pauseKey acts exactly the same as exitEmulatorKey (long press also)
   so now you can have two keys for opening and exiting menus (Esc and p)
   and two keys for menu items activation (1 and enter)
   or you can use some gamepad keys Joy1, 2Joy3, ...
 + instructions are much, much bigger
 + flyer is bigger, and if works with different dimensions images for same table
 + loading menu is merged from sam's version
 + some parts of the code are optimized (draw image by the book), some are not
 + lots of work and testing so that you can always use exit, enter, flyer and instr keys
   for example you can press flyer to open flyer directly or go through menus with enter
   same with instructions
   you can also switch from flyer to instructions
   you can close flyer with exit, enter or flyer key, same for instructions
   all of this will work in vp and fp
 + ... what else, uhmmmmm let me think -  yes loading menu - something was hiding
   loading slider (probably vp) and unhiding taskbar - this is both fixed
   so taskbar is hidden every few secs and slider is unhiden
 + focus problem with loading screen - while slider is on the screen
   every few seconds we try to activate vp (avoiding dmd hack)
   also after aprox. 25 secs. we just close loading screen unconditionally
   also on exit key (or pause key) we close loading screen unconditionally
   and after close of loading screen there is a one sec sleep and 
   winactivate in a loop so now you should get perfect focus on every vp game
 + debug mode - lot's of things was written to log file, I also added tool tip
   on top of the screen - but nothing is written anywhere by default
   only if you enable it with this option in settings.ini

 1.295 wip 7
 + fixed memory leak
 + swf draws in same resolution, not double, faster, better image
 + support for many instructions cards swf, bmp, png, jpg, gif format


 1.295 wip 8
 + fixed b2s close bug
 + ledwiz support added, for more info check:
   http://www.vpforums.org/index.php?showtopic=16186&hl=
 + support for different names for hyperpin.exe

 1.295 wip 9
 + fixed vp doesnt close bug (detect hidden windows on)
 + capture screen code removed (not used any more)
 + printscreen for backglass added (o saves pf, u saves bg)
 + code map updated
 + reorg - all procedures moved up and down a bit
 + #winactivateforce added (didn't help much -
   actually made some wierd problems and freezes - removed)
 + fix focus on table close in win7 with triple checks
 + lots of triple checks added (ifactive, waitactive, ...)
 + taskbar shown on exit if there is no hyperpin process
 + cursor shown on exit
 + show vp/fp editor on error and close loading slider
 + activate commands moved to functions
 + file and screen debug modes added
 + toggle taskbar on t key (it was always shown, now it is hiden also)
 + fix blackscreen gui (no need for black screen if useloadscreen is true)
 + remove all detect hidden windows off
 + remove double exitscreen - it is executed on exit, no need to call it 
 + find why hyperpin freezes sometimes ??? (activate force maybe)
 - add toLog to every function
 - test fp activate and errors, change fp run code to use functions
 - fp sometimes doesn't show loading slider - test it


 1.295 wip 10
 - add toLog to every function
 - error handling should be removed - wait from reply from user
 - test fp activate and errors, change fp run code to use functions
 - fp sometimes doesn't show loading slider - test it




TO DO:
 - read keys from hyperpin (keyboard and joystick)
 - dodati highscores od leasby-ija - ima ahk u hyperpin diru, ime roma staviti u xml
 ili naći neku metodu za otkrit koji mame se vrti trenutno???
 - dodati opciju triplecheck on exit - ili ubaciti više sleepova da se ne freeza stalno
 - dodati opciju disable service menu
 - make loading screen resolution independent?
 - read settings.ini into memory
 - change key names to exitkey exitkey1 and startkey startkey1 for simplicity
 - remove usepause useexitasapuse useexitmenu options for simplicitiy
 - use prerotated menu images for simplicity
 - always use draw image by the book function for simplicity
 - put every repeating code to subroutines for simplicity
 - change instruction card menu item to instructions
 - enable png instructions
 - compile a set of png instructions and replay score cards
   and helps for setting replay levels, and tactics help, and ...
   (hopefully somebody will do this eventually)
 - test service menu
 - fix late printscreen in fp
 - fp auto positioning
*/




#SingleInstance force      ;Prevent multiple instances
#InstallKeybdHook
SetTitleMatchMode 2        ;Use relaxed title matching
;#InstallMouseHook
;#UseHook ; this one breaks long press functionality for gamepad button mapped to Esc!!!
;#KeyHistory 500
#MaxThreadsPerHotkey 1
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
DetectHiddenWindows on
#WinActivateForce


OnExit onExitScript
SoundPlay menu.wav


GlobalListLines("Off")


#Include, Gdip.ahk
#Include, Com.ahk


;------------------------------------------------------------------------------;
; Start gdi+
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus Error!, Gdiplus failed to start. Please ensure you have Gdip.ahk In Hyperpin dir
ExitApp
}
toLog("GDI+ Initialised")


; start com
COM_Init()
COM_CoInitialize()
COM_AtlAxWinInit()
toLog("COM Standard Library Initialised")




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

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


hyperini = %A_ScriptDir%\Settings\Settings.ini
picDir = %A_ScriptDir%\Media\HyperPin\Images\


GoSub, CheckINI


IniRead, lastSystem, %hyperini%, LastLoad, system
IniRead, lastTable, %hyperini%, LastLoad, table


iniKeys = 
( 
[FPLaunch]
; default settings, if you don't have them they will be added to your settings.ini file
; ***** don't change them here - edit your settings.ini file!!! *****
exitScriptKey    = q & s    ; kill script key
exitEmulatorKey  = Esc      ; main exit key, can be joy key also (Joy1)
toggleCursorKey  = t
hideCursor       = true
hideDesktop      = true
hideTaskbar      = true
; new settings
useExitScreen    = true     ; show exit321 countdown on long press
usePauseKey      = true     ; if used pause key works same as exit key
useLoadScreen    = true     ; show loading slider
useExitAsPause   = true     ; open pause window on exit key or exit directly
useExitMenu      = true     ; use exit menu instead of pause window
pauseKey         = p        ; former pauseVPinball key, works same as exit key
fadespeed        = 25
exitEmulatorKey2 = 1        ; key for entering into menus
exitEmulatorKey3 = Enter    ; and another one
pauseFPKey       = RButton  ; pause in FP
saveFPTables     = true     ; save fp table position on exit
editTableKey     = !F4      ; close table and go to vp/fp editor
printScreenKey   = o        ; save playfield
printBGKey       = u        ; save backglass
pfScreenNum      = 1        ; playfield Screen Number (used for print screen)
bgScreenNum      = 2        ; backglass Screen Number (used for print screen)
upKey            = LShift   ; left flipper goes up in menus
downKey          = RShift   ; right flipper goes down in menus
instructionsKey  = i
flyerKey         = f
hyperScale       = 0.75
debugMode        = false
ledwiz           = false
hyperpinexe      = hyperpin.exe
)
Loop, parse, iniKeys, `n,`r`t" "
{
StringSplit, iniKey, A_LoopField, =;, %A_Space%%A_Tab%
if (iniKey0 > 1 And iniKey1 != "") {
	IniRead, %iniKey1%, %hyperini%, FPLaunch, %iniKey1%
	If (%iniKey1% = "ERROR" Or %iniKey1% = "") {
		%iniKey1% = %iniKey2%
		IniWrite, %iniKey2%, %hyperini%, FPLaunch, %iniKey1%
	}
}
}
toLog("Ini files parsed")


GlobalListLines("On")


;CHECKING FOR 2 PARAMS, IF NOT THEN OPEN QuickLaunch dialog box
if 0 < 2
{
GoSub QuickLaunch
} Else {
systemName = %1%
tableName = %2%
}


If (systemName != lastSystem OR tableName != lastTable) {
IniWrite, %systemName%, %hyperini%, LastLoad, system
IniWrite, %tableName%, %hyperini%, LastLoad, table
}


databaseFile = %A_Scriptdir%\Databases\%systemName%\%systemName%.xml


;------------------------------------------------------------------------------;
;                              GET AND CHECK PATHS                             ;
;------------------------------------------------------------------------------;
IniRead, iniEmuPath, %hyperini%, %systemName%, Path
emuPath := GetFullName(iniEmuPath)
IniRead, iniTablePath, %hyperini%, %systemName%, Table_Path
tablePath := GetFullName(iniTablePath)
IniRead, executable, %hyperini%, %systemName%, Exe
IniRead, iniTableImagePath, %hyperini%, %systemName%, Table_Image_Path
tableImagePath := GetFullName(iniTableImagePath)
IniRead, iniBackglassImagePath, %hyperini%, %systemName%, Backglass_Image_Path
backglassImagePath := GetFullName(iniBackglassImagePath)
if (systemName = "Future Pinball")
romExtension = fpt
else
romExtension = vpt
GoSub, CheckPaths


Hotkey, %exitScriptKey%, ExitScript


Playfield_Rotation := 270


StrX( H,  BS="",BO=0,BT=1,   ES="",EO=0,ET=1,  ByRef N="" ) { ;    | by Skan | 19-Nov-2009
Return SubStr(H,P:=(((Z:=StrLen(ES))+(X:=StrLen(H))+StrLen(BS)-Z-X)?((T:=InStr(H,BS,0,((BO
<0)?(1):(BO))))?(T+BT):(X+1)):(1)),(N:=P+((Z)?((T:=InStr(H,ES,0,((EO)?(P+1):(0))))?(T-P+Z
+(0-ET)):(X+P)):(X)))-P) ; v1.0-196c 21-Nov-2009 www.autohotkey.com/forum/topic51354.html
}


q = "
FileRead, XML, %databaseFile% ;load database xml for parsing
temptableDescription := StrX( XML, q . tableName . q ,1,0,"</description>",1,14)
tableDescription := StrX( temptableDescription, "<description>" ,1,13,"",1,1)
shortDescription := StrX( tableDescription, "" ,1,1,"(",1,0)


pfName = %tableImagePath%%tableDescription%.png
bgName = %backglassImagePath%%tableDescription%.png
loadspeed := fadespeed * 10


if (ledwiz = "true")
Run, "%A_ScriptDir%\ledclear.bat",,hide


; loading screen
gui, 99:add,picture,hwndloadpic, %picDir%loading.png
controlgetpos,,,hLoad,wLoad,,ahk_id %loadpic%
gui, 99:destroy	
wLoad := Round(wLoad*A_ScreenWidth/1920)
xLoad := Round(A_ScreenWidth/2-(wLoad/2))
hLoad := Round(hLoad*A_ScreenHeight/1080)
yLoad := Round(A_ScreenHeight/2-(hLoad/2))
wLoadProgress := Round(20*A_ScreenWidth/1920)
xLoadProgress := Round(145*A_ScreenWidth/1920)
hLoadProgress := Round(194*A_ScreenHeight/1080)
yLoadProgress := Round(288*A_ScreenHeight/1080)


; old flags
ProgBar = 0
Paused = 0
Exiting = 0


; new flags
menuOn = 0
menuItem = 1
serviceMenuOn = 0
instructionsOn = 0
flyerOn = 0
loading = 1


; flyer images
flyerpages = 0
Loop, %A_ScriptDir%\Media\HyperPin\Flyer Images\%shortDescription%*, ,1
{
  flyerpages++
  flyerPic%A_Index% := A_LoopFileFullPath
}
If (flyerpages > 1) {
  flyerPic := flyerPic2
  flyer = 2
} Else If (flyerpages = 1) {
  flyerPic := flyerPic1
  flyer = 1
} Else {
  flyerPic1 := picDir . "FlyerMissing.png"
  flyerPic := flyerPic1
  flyer = 1
  flyerpages = 1
}
toLog("Flyer Pages Parsed")


; instructions images
instrpages = 0
Loop, %A_ScriptDir%\Media\HyperPin\Instruction Cards\%shortDescription%*, ,1
{
  instrpages++
  instrPic%A_Index% := A_LoopFileFullPath
}
If (instrpages > 0) {
  instrPic := instrPic . instrpages
  instr := instrpages
} Else {
  instrPic1 := picDir . "instructMissing.png"
  instrPic := instrPic1
  instr = 1
  instrpages = 1
}
toLog("Instruction Pages Parsed")


if (hideCursor = "true") {
 ;MouseMove 960, 540
 MouseMove %A_ScreenWidth%/2, %A_ScreenHeight%/2
 Hotkey, %toggleCursorKey%, ToggleCursor
 SystemCursor("Off")
}


taskbar = 1
if (hideTaskbar = "true") {
WinHide, ahk_class Shell_TrayWnd
WinHide, Start ahk_class Button
taskbar = 0
}


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


; WinClose, cmd.exe ; what is this?
; if somebody needs it uncomment it




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






;**********************************FUTURE PINBALL***********************************
if (systemName = "Future Pinball") {
 if(tableName = "BigScore") { ; bigboss slamit bigscore support
GoSub SlamitBigScore
 } else {
   if (useExitScreen = "true")
	exitmeth = ExitScreen
   else if (useExitAsPause = "true")
	exitmeth = PauseFP
else
	exitmeth = CloseFP
; fp needs $ or it will not get the key
; * enables any modifier (shift, ctrl, alt)
; * breaks long press functionality - removed
Hotkey $%exitEmulatorKey%, %exitmeth%
if  (usePauseKey = "true")
	Hotkey, $%pauseKey%, %exitmeth%
Hotkey, $%editTableKey%, ShowFP
Hotkey, $%printScreenKey%, printScreen
Hotkey, $%printBGKey%, printBG
Hotkey, $%instructionsKey%, Instructions
Hotkey, $%flyerKey%, Flyer
if (saveFPTables = "true") {
	Hotkey, $ScrollLock, SetSaveFPNeeded
	Run, "%emuPath%\%executable%" /open "%tablePath%\%tableName%.fpt" /play /arcaderender,,Min UseErrorLevel
} else
	Run, "%emuPath%\%executable%" /open "%tablePath%\%tableName%.fpt" /play /Exit /arcaderender,,Min UseErrorLevel


If (useLoadScreen   = "true") ;Draw the loading Gui with wrapped Progress bar
	Gosub CreateLoadScreen
   Else {
	WinWait, ahk_class FuturePinball
	WinHide, ahk_class FuturePinball
}
loading = 0	; ************ use acrtivate functions *****************
WinWait, ahk_class FuturePinballOpenGL
WinActivate, ahk_class FuturePinballOpenGL
WinWaitActive, ahk_class FuturePinballOpenGL
   Gui, destroy
WinWait, ahk_class FuturePinballOpenGLSecondary,,1
WinActivate, ahk_class FuturePinballOpenGLSecondary
WinWaitActive, ahk_class FuturePinballOpenGLSecondary,,1
WinActivate, ahk_class FuturePinballOpenGL


; pinemhiscore
FileDelete hiscore.txt
FileAppend %tablename%`n, hiscore.txt
RunWait, %comspec% /c PINemHi %tablename%.fpram>>hiscore.txt,,hide

   Process, WaitClose, %executable%
 }
}
;**********************************VISUAL PINBALL***********************************
else if (systemName = "Visual Pinball")
 {
GoSub bigboss ; bigboss support for different exe, sound levels and hdrender off
GoSub rosve ; rosve support for B2S active backglasses


   Run, "%emuPath%\%executable%" /play -"%tablePath%%tableName%.vpt",, Min UseErrorLevel
   ;Run, "%emuPath%\%executable%" /play -"%tablePath%%tableName%.vpt",, Min UseErrorLevel
;Run Minimized was the best way I could hide the vp editor and 
;play loading screens as WinHide didn't seem to find them sometimes


If  (useExitScreen = "true") ; * breaks long press functionality
	exitmeth = ExitScreen
Else If (useExitAsPause = "true")
	exitmeth = PauseVP
Else
	exitmeth = CloseVP
Hotkey, $%exitEmulatorKey%, %exitmeth%
If  (usePauseKey = "true")
	Hotkey, $*%pauseKey%, %exitmeth%
Hotkey, $%editTableKey%, ShowVP
Hotkey, $%printScreenKey%, printScreen
Hotkey, $%printBGKey%, printBG
Hotkey, $%instructionsKey%, Instructions
Hotkey, $%flyerKey%, Flyer
If (useLoadScreen   = "true") ; draw the loading Gui with Progress bar
	Gosub CreateLoadScreen
   Else {
	WinWait, ahk_class VPinball
	; winhide doesn't work sometimes
	WinHide, ahk_class VPinball
}
;dj loop
loading = 1
Loop {
	WinActivate, ahk_class VPPlayer,,DMD
	Sleep 100
	Gosub CheckVP
	if (loading = 0)
		Break
}
Gosub WaitVP
;bring cursor to center
DllCall("SetCursorPos", int, A_ScreenWidth//2, int, A_ScreenHeight//2)
;bring dmd to front
;don't click on dmd if it is hidden (uvp table)
DetectHiddenWindows off
WinActivate, ahk_class MAME
WinWaitActive, ahk_class MAME,,0
Sleep 100
;dj click on dmd
SetControlDelay -1
ControlClick,, ahk_class MAME
WinWaitActive, ahk_class MAME,,0
Sleep 100
DetectHiddenWindows on
;dj loop again
loading = 1
Loop {
	WinActivate, ahk_class VPPlayer,,DMD
	Sleep 100
	Gosub CheckVP
	if (loading = 0)
		Break
}
Gosub WaitVP
Gui, destroy


; pinemhiscore
FileDelete hiscore.txt
FileAppend %tablename%`n, hiscore.txt
; get rom title
WinGetTitle, romnice, ahk_class MAME
if (romnice != "") {
	; get romname
	IniRead, romname, pinemhi.ini, romfind, %romnice%
	if (romname = "ERROR" or romname = "") {
		FileAppend ROM title %romnice% not found in pinemhi.ini`n, hiscore.txt
	} else {
		; get the hiscore from nvram and put it in hiscore.txt
		RunWait, %comspec% /c PINemHi %romname%>>hiscore.txt,,hide
	}
}

Process, WaitClose, %executable%
}
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


; You should never come here


; bigboss Slamit support remaps
; - this has to be here, not in procedures, not in normal code
; - ahk stops on first #ifwinactive command
; Remap  keys:
; enter to down arrow for plunger
; 1 to s for start, 5 to 1 for insert coin
; magnasave, flyer, genre or instructions to enter for menus
; change it to what you have on your cab and recompile
; or remove it if you don't use slamit pinball
#IfWinActive ahk_class SlamIt Pinball - Big Score
RControl::Enter
LControl::Enter
f::Enter
g::Enter
i::Enter
Enter::down
5::1
1::s
#IfWinActive




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


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




;------------------- QuickLaunch gui -------------------
QuickLaunch:
ListLines Off
Gui, Add, ComboBox, x12 y100 w266 gsetSystem vsystemName, Visual Pinball|Future Pinball
Gui, Add, ComboBox, x12 y150 w266 h20 r10 vtableName
Gosub getSystem
Gui, Add, Text, x12 y10 w430 h20 , Usage: FPLaunch.ahk/exe "System Name" "Rom Name"
Gui, Add, Text, x12 y40 w350 h30 , Select system name and table name and click the Run button.
Gui, Add, Text, x12 y80 w80 h20 , System Name:
Gui, Add, Text, x12 y130 w220 h20 , Table Name (file name without extension):
Gui, Add, Button, x290 y100 w60 h70 gtestdone vrun, Run
Gui, Show, Center h185 w365, %Version%
GuiControl, Focus, run
While (Test != "done")
{
	sleep 500
}
 ListLines %gListLines%
Return


GuiClose:
Gosub exitScript
Return


testdone:
Gui, Submit
Test = done
Return


getSystem:
 GuiControl, ChooseString, systemName, %lastSystem%
 Gui, Submit, NoHide
 Gosub getTables
Return


setSystem:
 Gui, Submit, NoHide
 Gosub getTables
Return

getTables:
Tables = 
ArrayCount = 1

 systemsFile := A_ScriptDir . "\Databases\" . systemName . "\" . systemName . ".xml"
 Loop, Read, %systemsFile%
 {   
   Pos := RegExMatch(A_LoopReadLine,"name=""(.*)""", SubPat)
   If(Pos > 1){
     Tables%ArrayCount% := SubPat1
     ArrayCount += 1
   }
 }
 ArrayCount -= 1
 elements := "|"
 Loop %ArrayCount%
   {
     elements .= Tables%A_Index% . "|"
   }  
 GuiControl,, tableName, %elements%
 If (systemName = lastSystem And lastTable != "")
GuiControl, ChooseString, tableName, %lastTable%
 Else
GuiControl, Choose, tableName, 1
 GuiControl, Focus, run
 Gui, Submit, NoHide
Return
;------------------- End of QuickLaunch gui -------------------




;------------------- Loading screen -------------------
CreateLoadScreen:
GlobalListLines("Off")
SetTitleMatchMode 2 ;Use relaxed title matching
Gui, Destroy ; kill Gui blackScreen
toLog("CreateLoadScreen Called")
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show,, Loading
hwLoad := WinExist()
loadPic = %picDir%loading.png
pBitmap := Gdip_CreateBitmapFromFile(loadPic)
pWidth := Gdip_GetImageWidth(pBitmap)
pHeight := Gdip_GetImageHeight(pBitmap)
  scale := ((A_ScreenHeight*hyperScale)/pWidth)
sWidth := Round(pWidth*scale), sHeight := Round(pHeight*scale)
Gdip_GetRotatedDimensions(sWidth, sHeight, Playfield_Rotation, rWidth, rHeight)
Gdip_GetRotatedTranslation(sWidth, sHeight, Playfield_Rotation, xTranslation, yTranslation)
xLoad := Round((A_ScreenWidth-rWidth)/2), yLoad := Round((A_ScreenHeight-rHeight)/2)	
hbm := CreateDIBSection(rWidth, rHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 7)
Gdip_TranslateWorldTransform(G, xTranslation, yTranslation)
Gdip_RotateWorldTransform(G, Playfield_Rotation)
Gdip_DrawImage(G, pBitmap, 0, 0, sWidth, sHeight, 0, 0, pWidth, pHeight)
Gdip_DisposeImage(pBitmap)
Gdip_ResetWorldTransform(G)
UpdateLayeredWindow(hwLoad, hdc, xLoad, yLoad, rWidth, rHeight)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G)


Gui, 2: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 2: Show, NA, Loading
hwLoadprog := WinExist()
progPic = %picDir%loadProgress.png 
pBitmap := Gdip_CreateBitmapFromFile(progPic)
pLWidth := Gdip_GetImageWidth(pBitmap), pLHeight := Gdip_GetImageHeight(pBitmap)
sLWidth := Round(pLWidth*scale), sLHeight := Round(pLHeight*scale)
Gdip_GetRotatedDimensions(sLWidth, sLHeight, Playfield_Rotation, rLWidth, rLHeight)
Gdip_GetRotatedTranslation(sLWidth, sLHeight, Playfield_Rotation, xTranslation, yTranslation)
xLoadProgress := Round(rWidth/6*5+xLoad-rLWidth),yLoadProgress := Round(rHeight/3*2+yLoad-rLHeight)
pinend := Round(rHeight/3*2+yLoad-rLHeight),pinstart := Round(rHeight/3+yLoad)
hbm := CreateDIBSection(rLWidth, rLHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 7)
dir = 2
pinrot := Playfield_Rotation
DetectHiddenWindows off ; why is this here? - to avoid detecting hidden error windows
;;;Gui, 99:Destroy ??? no need for this?
SetTimer, MoveProgress, %fadespeed%


Loop {
Sleep %loadspeed%
; nag screens removal
toLog("Loading Loop "A_Index)
ifWinExist, Please
{ ; first time run nag screen
	WinActivate, Please
	IfWinActive, Please
	{ ; dj
		SetControlDelay -1
		ControlClick, Button2, Please answer AHK_class #32770 ; Click Yes I am
		ControlSend, Button1, {Enter}, Please answer AHK_class #32770 ; Click the OK button
	}
} else ifWinExist, Game Info
{
	WinActivate, Game Info
	IfWinActive, Game Info
	{
		Send {Enter}
		Send {Enter}
	}
} else ifWinExist, Notice
{ ; sound warnings (antar)
	WinActivate, Notice
	IfWinActive, Notice
	{
		Send {Enter}
		Send {Enter}
	}
} else ifWinExist, VBScript
{ ; errors in vb script
	WinActivate, VBScript
	IfWinActive, VBScript
	{
		Send {Enter}
	}
} else ifWinExist, Error
{	; open editor on serious errors
	; (z buffer, script error, rosve bg - line 0, ...)
	; old error treatment was to show msg and close vp
	; hm on some errors vp crashes, we will test for that in waitplayer
	toLog("LoadScreen Closed - Error")
	Gosub CloseProgress
	if (systemName = "Visual Pinball") {
		WinRestore, ahk_class VPinball
		WinActivate, ahk_class VPinball
		WinWaitActive, ahk_class VPinball
	} else {
		WinRestore, ahk_class FuturePinball
		WinActivate, ahk_class FuturePinball
		WinWaitActive, ahk_class FuturePinball
	}
	SystemCursor("On")
	WinShow ahk_class Shell_TrayWnd
	WinShow Start ahk_class Button
	taskbar = 1
	Suspend, On
	WinActivate, Error
	WinWaitActive, Error
	Gosub WaitPlayer
	Suspend, Off
	SystemCursor("Off")
	WinHide, ahk_class Shell_TrayWnd
	WinHide, Start ahk_class Button
	taskbar = 0
	;WinMinimize, ahk_class VPinball
	Continue
}
; check if player is active
Gosub CheckPlayer
; try to get focus every ~five seconds
if (Mod(A_Index, 20) = 0) {
	WinActivate, ahk_class VPPlayer,,DMD
	WinActivate, ahk_class FuturePinballOpenGL
}
; after ~25 seconds close unconditionally
if (Mod(A_Index, 100) = 0) {
	toLog("LoadScreen Closed - 25 sec")
	Break
}
; close loading slider unconditionally on exit key
if (loading = 0) {
	toLog("LoadScreen Closed - Esc?")
	Break
}
; hide taskbar again (vp unhides taskbar
; only if auto hide taskbar is set windows
; so disable auto hide taskbar in windows!!!)
;if (hideTaskbar = "true") {
;	WinHide, ahk_class Shell_TrayWnd
;	WinHide, Start ahk_class Button
;}
}
Gosub CloseProgress
DetectHiddenWindows on
GlobalListLines("On")
Return


CheckPlayer: 	; check if player is active
; toLog("CheckPlayer Called")
if (systemName = "Visual Pinball")
	Gosub CheckVP
else
	Gosub CheckFP
Return


CheckVP:
; check three times cause player can be
; active for a sec and then throw an error
;toLog("CheckVP Called")
IfWinActive, Visual Pinball Player,,DMD
{
	Sleep 100
	IfWinActive, Visual Pinball Player,,DMD
	{
		Sleep 100
		IfWinActive, Visual Pinball Player,,DMD
		{
			toLog("CheckVP - VP is active")
			loading = 0
		}
	}
}
Return


CheckFP:
;toLog("CheckFP Called")
IfWinActive, ahk_class FuturePinballOpenGL
{
	Sleep 100
	IfWinActive, ahk_class FuturePinballOpenGL
	{
		Sleep 100
		IfWinActive, ahk_class FuturePinballOpenGL
		{
			toLog("CheckFP - FP is active")
			loading = 0
		}
	}
}
Return


WaitPlayer:	; wait for  player to be really active!!!
toLog("WaitPlayer Called")
if (systemName = "Visual Pinball")
	Gosub WaitVP
else
	Gosub WaitFP
Return


WaitVP:
; sometimes player is active just for a sec
; then it throws an error, this loop fixes that!!!
; it will not go on untill player is active three times in a row
toLog("WaitVP Called")
waitagainvp:
; if vp doesn't exist (crashed or closed) - exit
IfWinNotExist ahk_class VPinball
	ExitApp
MouseMove 88,130
WinWaitActive ahk_class VPPlayer,,1,DMD
Sleep 100
IfWinNotActive ahk_class VPPlayer,,DMD
	Goto waitagainvp
WinWaitActive ahk_class VPPlayer,,1,DMD
Sleep 100
IfWinNotActive ahk_class VPPlayer,,DMD
	Goto waitagainvp
WinWaitActive ahk_class VPPlayer,,1,DMD
Sleep 100
IfWinNotActive ahk_class VPPlayer,,DMD
	Goto waitagainvp
Return


WaitFP:
toLog("WaitFP Called")
waitagainfp:
MouseMove 88,130
WinWaitActive, ahk_class FuturePinballOpenGL
Sleep 100
IfWinNotActive, ahk_class FuturePinballOpenGL
	Goto waitagainfp
WinWaitActive, ahk_class FuturePinballOpenGL
Sleep 100
IfWinNotActive, ahk_class FuturePinballOpenGL
	Goto waitagainfp
WinWaitActive, ahk_class FuturePinballOpenGL
Sleep 100
IfWinNotActive, ahk_class FuturePinballOpenGL
	Goto waitagainfp
Return


CloseProgress:	; closes loading screen with slider
toLog("CloseProgress Called")
SetTimer, MoveProgress, Off
SelectObject(hdc, obm)
DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
Gdip_DisposeImage(pBitmap)
Gui, 2:Destroy
Gui, 1:Destroy
Return


MoveProgress:	; moves rotating hyperpin ball
ListLines Off
yLoadProgress := (yLoadProgress - dir)
If (yLoadProgress > pinend) Or (yLoadProgress < pinstart)
	dir := -(dir)
Gdip_TranslateWorldTransform(G, xTranslation, yTranslation)
Gdip_RotateWorldTransform(G, pinrot)
Gdip_DrawImage(G, pBitmap, 0, 0, sLWidth, sLHeight, 0, 0, pLWidth, pLHeight)
Gdip_DisposeImage(pBitmap)
Gdip_ResetWorldTransform(G)
dif := (rLHeight-sLHeight)/2
dif := -dif
movedyLoadProgress := Round(yLoadProgress+dif)
movedxLoadProgress := Round(xLoadProgress+dif)
UpdateLayeredWindow(hwLoadProg, hdc, movedxLoadProgress+1, movedyLoadProgress, rLWidth, rLHeight)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G)
pinrot := pinrot + dir*5
Gdip_GetRotatedTranslation(sLWidth, sLHeight, pinrot, xTranslation, yTranslation)
Gdip_GetRotatedDimensions(sLWidth, sLHeight, pinrot, rLWidth, rLHeight)
pBitmap := Gdip_CreateBitmapFromFile(progPic)
hbm := CreateDIBSection(rLWidth, rLHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 7)
; this had to be added cause vp would hide loading slider during load
; remember we are waiting for vp to take focus so slider must not take focus
Gui, 2: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 2: Show, NA, Loading
Return
;------------------- End of Loading screen -------------------


;------------------- Exit screen -------------------
ExitScreen:		; call exit menu or exit countdown
toLog("ExitScreen called")
if (loading = 1) ; just close loading slider
loading = 0
else if (Exiting = 0) { ; check for long press
Exiting = 1
LoopVal = 0
Loop {
	;Sleep, 10 ; check if we need this - nope
	state = 0
	; check for logical and physical state of the exit key
	GetKeyState, statel, %exitEmulatorKey%
	if statel = D
		state = 1
	GetKeyState, statep, %exitEmulatorKey%, P
	if statep = D
		state = 1
	; also check for state of the pause key
	GetKeyState, statel, %pauseKey%
	if statel = D
		state = 1
	GetKeyState, statep, %pauseKey%, P
	if statep = D
		state = 1
	if (state) {
           if (loopVal = 10) {
			if (Paused = 1) { ; close pause window before going to countdown
				Gosub PauseGame
			}
			Gosub CreateExitScreen
			if (systemName = "Future Pinball")
				GoSub CreateBlackScreen
	        Gui, 3:Show
		} else if loopVal = 25
		    Gui, 2:Show
		else if loopVal = 40
		    Gui, 1:Show
           Sleep,  %fadespeed%
		if (loopVal = 60) {
			Gosub CloseGame
			break
           }
	} else {
		Exiting = 0
		if (LoopVal < 10 && useExitAsPause = "true") { ; short press
	        Gosub PauseGame
		} else { ; long press but not long enough
			Loop, 6
				Gui, %A_Index%: Destroy
			WinActivate, Visual Pinball Player,, DMD
			WinActivate, ahk_class FuturePinballOpenGL
		}
        	Transvalue = 0
		LoopVal = 0
 		break
       }
    LoopVal += 1
   }
}
Return


CreateExitScreen:		; create exit321 screens
toLog("CreateExitScreen Called")
	Gui, Destroy
Loop, 4
  {
    ExitPic = Exit_%A_Index%.png
    Gui %A_Index%: Destroy
    Gui %A_Index%: Color, EEAA99
       Gui %A_Index%: Margin, 0, 0
       Gui %A_Index%: Add, Picture, w%wLoad% h%hLoad%, %picDir%%ExitPic%
       Gui %A_Index%: +AlwaysOnTop -Caption +Lastfound
       Gui %A_Index%: Show, AutoSize Center Hide
	WinSet, TransColor, EEAA99
  }
Return


CreatePauseScreen:		; show blue PAUSED image
toLog("CreatePauseScreen Called")
Gui, Destroy
Gui, Color, EEAA99
Gui, Margin, 0, 0
Gui, Add, Picture, w%wLoad% h%hLoad% vPausePic, %picDir%pause.png
Gui +AlwaysOnTop -Caption +Lastfound
Gui, Show, AutoSize Center, pauseScreen
WinSet, TransColor, EEAA99
;Gui, Show
Return


CreateBlackScreen:		; do printscreen of fp table and show it on the screen
toLog("CreateBlackScreen Called")
pBitmap := Gdip_BitmapFromScreen(pfScreenNum)
Gdip_SaveBitmapToFile(pBitmap, "screen.bmp")
WinActivate, ahk_class FuturePinballOpenGL
WinWaitActive, ahk_class FuturePinballOpenGL,,2
Gui 9: Destroy
Gui 9: Color, 000000
Gui 9: Margin, 0, 0
Gui 9: Add, Picture, W%A_ScreenWidth% H%A_ScreenHeight% vScreenPic, screen.bmp
Gui 9: +AlwaysOnTop -Caption ;+ToolWindow
Gui 9: Show, x0 y0 W%A_ScreenWidth% H%A_ScreenHeight%, BlackScreen
Return


PrintScreen:		; save playfield screenshot to media folder
toLog("PrintScreen Called")
pBitmap := Gdip_BitmapFromScreen(pfScreenNum)
Gdip_ImageRotateFlip(pBitmap, 2) ;rotate 180, flip 0
Gdip_SaveBitmapToFile(pBitmap, pfName)
Gdip_DisposeImage(pBitmap)
return


PrintBG:			; save bg creenshot to media folder
toLog("PrintBG Called")
pBitmap := Gdip_BitmapFromScreen(bgScreenNum)
Gdip_SaveBitmapToFile(pBitmap, bgName)
Gdip_DisposeImage(pBitmap)
return


PauseFP:			; call pause screen or exit menu
toLog("PauseFP Called")
if (Paused = 0) { ; we are enetering pause menu
Paused = 1
WinActivate, ahk_class FuturePinballOpenGL
WinWaitActive, ahk_class FuturePinballOpenGL
Send {%pauseFPKey%}
WinWaitActive, ahk_class FuturePinballOpenGL
Gosub CreateBlackScreen ; we draw printscreen first
if (useExitMenu = "true") {
	Gosub ExitMenu ; draw menus - nothing else!
	Hotkey, %UpKey%, MoveUp, On
	Hotkey, %DownKey%, MoveDown, On
	Hotkey, %exitEmulatorKey2%, selectItem, On
	Hotkey, %exitEmulatorKey3%, selectItem, On
} else {
	Gosub CreatePauseScreen
	Hotkey, $%exitEmulatorKey2%, CloseFP, On
	Hotkey, $%exitEmulatorKey3%, CloseFP, On
}
} else { ; we are exiting pause menu
Paused = 0
if (useExitMenu = "true") {
	Gosub ExitMenu ; close menus or flyer or instr.
	Hotkey, %UpKey%, Off
	Hotkey, %DownKey%, Off
	Hotkey, %exitEmulatorKey2%, Off
	Hotkey, %exitEmulatorKey3%, Off
} else {
	Gui 1: Destroy
	Gui 9: Destroy
	Hotkey, $%exitEmulatorKey2%, Off
	Hotkey, $%exitEmulatorKey3%, Off
	WinActivate, ahk_class FuturePinballOpenGL
	WinWaitActive, ahk_class FuturePinballOpenGL
	Send {%pauseFPKey%}
}
}
return


PauseVP:			; call pause screen or exit menu
toLog("PauseVP Called")
If (Paused = 0) { ; entering pause menu
Paused = 1
if (useExitMenu = "true") {
	Gosub ExitMenu ; draw menus
	Hotkey, %UpKey%, MoveUp, On
	Hotkey, %DownKey%, MoveDown, On
	Hotkey, %exitEmulatorKey2%, selectItem, On
	Hotkey, %exitEmulatorKey3%, selectItem, On
} else {
	Gosub CreatePauseScreen
	Hotkey, $%exitEmulatorKey2%, CloseVP, On
	Hotkey, $%exitEmulatorKey3%, CloseVP, On
}
} Else { ; exiting pause menu
Paused = 0
if (useExitMenu = "true") {
	Gosub ExitMenu ; close menus
	Hotkey, %UpKey%, Off
	Hotkey, %DownKey%, Off
	Hotkey, %exitEmulatorKey2%, Off
	Hotkey, %exitEmulatorKey3%, Off
} else {
	Gui, Destroy
	Hotkey, $%exitEmulatorKey2%, Off
	Hotkey, $%exitEmulatorKey3%, Off
}
WinActivate, ahk_class VPPlayer,,DMD
}
return


PauseGame:		; call vp of fp pause
toLog("PauseGame Called")
if (systemName = "Visual Pinball")
GoSub, PauseVP
else if (systemName = "Future Pinball")
GoSub, PauseFP
Return




ShowFP:		; close player and show editor on edit key
toLog("ShowFP Called")
if (Paused = 1)
	Gosub PauseFP
WinActivate, ahk_class FuturePinballOpenGL
WinWaitActive, ahk_class FuturePinballOpenGL
Send {Esc}
WinWaitClose, ahk_class FuturePinballOpenGL
WinShow, ahk_class FuturePinball
WinRestore, ahk_class FuturePinball
WinActivate, ahk_class FuturePinball
WinWaitActive, ahk_class FuturePinball
SystemCursor("On")
WinShow, ahk_class Shell_TrayWnd
WinShow, Start ahk_class Button
taskbar = 1
Suspend, On
MouseMove 200,200
WinWait, ahk_class FuturePinballOpenGL
Suspend, Off
SystemCursor("Off")
WinHide, ahk_class Shell_TrayWnd
WinHide, Start ahk_class Button
taskbar = 0
WinHide, ahk_class FuturePinball
WinMinimize, ahk_class FuturePinball
WinActivate, ahk_class FuturePinballOpenGL
WinWaitActive, ahk_class FuturePinballOpenGL
return


ShowVP:		; close player and show editor on edit key
toLog("ShowVP Called")
if (Paused = 1)
	Gosub PauseVP
WinActivate, ahk_class VPPlayer,,DMD
WinWaitActive, ahk_class VPPlayer
WinClose, ahk_class VPPlayer
WinWaitClose, ahk_class VPPlayer
WinShow, ahk_class VPinball
WinRestore, ahk_class VPinball
WinActivate, ahk_class VPinball
WinWaitActive, ahk_class VPinball
SystemCursor("On")
WinShow ahk_class Shell_TrayWnd
WinShow Start ahk_class Button
taskbar = 1
Suspend, On
MouseMove 200,200
WinWait, ahk_class VPPlayer
Suspend, Off
SystemCursor("Off")
WinHide, ahk_class Shell_TrayWnd
WinHide, Start ahk_class Button
taskbar = 0
;WinHide, ahk_class VPinball
WinMinimize, ahk_class VPinball
WinWaitActive, ahk_class VPPlayer
;WinActivate, ahk_class TBackglass
;WinActivate, ahk_class MAME
;WinActivate, ahk_class VPPlayer
return


ShowGame:	; show vp or fp
toLog("ShowGame Called")
if (systemName = "Visual Pinball")
	GoSub, ShowVP
else if (systemName = "Future Pinball")
	GoSub, ShowFP
Return


SetSaveFPNeeded:	; set flag to save fp table on exit
toLog("SetSaveFPNeeded Called")
saveFPNeeded = true
Send {ScrollLock}
return


CloseFP:
toLog("CloseFP Called")
;close all gui's except black screen (gui 9)
Loop, 3
	Gui, %A_Index%: Destroy
;hide and minimize fp editor
WinHide, ahk_class FuturePinball
WinMinimize, ahk_class FuturePinball
;Future Pinball must be closed this way instead of killing process
;or it wil not save your last game information.i.e score/credtis
WinActivate, ahk_class FuturePinballOpenGL
WinWaitActive, ahk_class FuturePinballOpenGL
Send {Esc}
WinWaitClose, ahk_class FuturePinballOpenGL
;saving fp table position, black screen hides fp window
if (saveFPTables = "true") and (saveFPNeeded = "true") {
	;WinRestore, ahk_class FuturePinball
	WinActivate, ahk_class FuturePinball
	WinWaitActive, ahk_class FuturePinball
	WinMenuSelectItem, ahk_class FuturePinball,,File,Save
	Sleep, 1000
}
WinClose, ahk_class FuturePinball
WinWaitClose, ahk_class FuturePinball
GoSub, ExitScript
return


CloseVP:
toLog("CloseVP Called")
Hotkey, %exitScriptKey%, Off
GoSub rosveClose
;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
Loop, 4
Gui, %A_Index%: Destroy
;This line fixes where the VP Window flashes real quick
;when closing the window for a cleaner exit
; win hide removed cause vp should be minimized, not hidden
;WinHide, ahk_class VPinball
;WinShow, ahk_class VPinball
WinMinimize, ahk_class VPinball
WinClose, ahk_class VPinball
WinWaitClose ahk_class VPinball
GoSub bigbossClose
GoSub, ExitScript
return


CloseGame:
toLog("CloseGame Called")
if (systemName = "Visual Pinball")
	GoSub, CloseVP
else if (systemName = "Future Pinball")
	GoSub, CloseFP
Return


;----------------------------------Exit Menu-----------------------------------;
ExitMenu:
toLog("ExitMenu Called")
If (instructionsOn = 1)		; close instruction card
 Gosub Instructions
Else If (flyerOn = 1)		; close flyer
 Gosub Flyer
Else If (Paused = 1) {		; show menus
SoundPlay menu.wav
menuOn = 1
menuItem = 1
serviceMenuOn = 0
DMDon = 0
Gui, 2: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 2: Show, Hide
hwExitInfo := WinExist()
Gui, 2: +Lastfound
WinActivate
   exitInfoPic = %picDir%exitMenu1b.png
iBitmap := Gdip_CreateBitmapFromFile(exitInfoPic)
iWidth := Gdip_GetImageWidth(iBitmap), iHeight := Gdip_GetImageHeight(iBitmap)
;If (Playfield_Rotation = 90) Or (Playfield_Rotation = 270) {
	iscale := A_ScreenHeight/iWidth
	sWidth := A_ScreenHeight+1, sHeight := iHeight*iscale
	yExitInfo := -1
;}
Gdip_GetRotatedDimensions(sWidth, sHeight, Playfield_Rotation, brWidth, brHeight)
   Gdip_GetRotatedTranslation(sWidth, sHeight, Playfield_Rotation, xTranslation, yTranslation)
  xExitInfo := A_ScreenWidth-brWidth+1
ihbm := CreateDIBSection(brWidth, brHeight)
ihdc := CreateCompatibleDC()
iobm := SelectObject(ihdc, ihbm)
iG := Gdip_GraphicsFromHDC(ihdc)
Gdip_TranslateWorldTransform(iG, xTranslation, yTranslation)
   Gdip_RotateWorldTransform(iG, Playfield_Rotation)
Gdip_SetCompositingMode(iG, 1)
Gdip_SetInterpolationMode(iG, 7)
Gdip_DrawImage(iG, iBitmap, -1, -1, sWidth+2, sHeight+2, 0, 0, iWidth, iHeight)
   Gdip_DisposeImage(iBitmap)
UpdateLayeredWindow(hwExitInfo, ihdc, xExitInfo, yExitInfo, brWidth, brHeight)

Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, Hide, ExitMenu
hwExit := WinExist()
Gui, 1: +Lastfound
Winactivate
exitmenuPic = %picDir%exitMenu1.png
pBitmap := Gdip_CreateBitmapFromFile(exitMenuPic)
pWidth := Gdip_GetImageWidth(pBitmap), pHeight := Gdip_GetImageHeight(pBitmap)
  pscale := ((A_ScreenHeight*hyperScale)/pWidth)
dWidth := pWidth*pscale, dHeight := pHeight*pscale
Gdip_GetRotatedDimensions(dWidth, dHeight, Playfield_Rotation, rWidth, rHeight)
   Gdip_GetRotatedTranslation(dWidth, dHeight, Playfield_Rotation, xMTranslation, yMTranslation)
  xExitM := (A_ScreenWidth-rWidth)/2, yExitM := (A_ScreenHeight-rHeight)/2
hbm := CreateDIBSection(rWidth, rHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_TranslateWorldTransform(G, xMTranslation, yMTranslation)
   Gdip_RotateWorldTransform(G, Playfield_Rotation)
Gdip_SetCompositingMode(G, 1)
Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, pBitmap, 0, 0, dWidth, dHeight, 0, 0, pWidth, pHeight)
   Gdip_DisposeImage(pBitmap)
UpdateLayeredWindow(hwExit, hdc, xExitM, yExitM, rWidth, rHeight)
Gosub PinEmHiScore
Gui, 1:Show
Gui, 2:Show	
} Else { ; close menus
SoundPlay menu.wav
menuOn = 0
serviceMenuOn = 0
DMDon = 0
GoSub closeMenus
if (systemName = "Future Pinball") {
	Gui, 9: Destroy
	WinActivate, ahk_class FuturePinballOpenGL
	WinWaitActive, ahk_class FuturePinballOpenGL
	Send {%pauseFPKey%}
}
}
Return


closeMenus:
toLog("closeMenus Called")
Gdip_SetCompositingMode(G, 0)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_DisposeImage(pBitmap)
Gdip_SetCompositingMode(iG, 0)
SelectObject(ihdc, iobm)
DeleteObject(ihbm)
DeleteDC(ihdc)
Gdip_DeleteGraphics(iG)
Gdip_DisposeImage(iBitmap)
Gui 6:Destroy
Gui 5:Destroy
Gui 4:Destroy
Gui 3:Destroy
Gui 2:Destroy
Gui 1:Destroy
return




MenuSwap:
toLog("MenuSwap Called")
;SoundPlay menu.wav
If menuItem = 0 
	menuItem = 5
If menuItem = 6
	menuItem = 1
If (serviceMenuOn = 0) { ; main menu
	exitmenuPic = %picDir%exitMenu%menuItem%.png
	exitInfoPic = %picDir%exitMenu%menuItem%b.png
	toLog("Exit Menu Swapped - Item " . menuItem)
} Else If (serviceMenuOn = 1) { ; service menu
	exitmenuPic = %picDir%serviceMenu%menuItem%.png
	exitInfoPic = %picDir%serviceMenu%menuItem%b.png
	toLog("service Menu Swapped - Item " . menuItem)
}
pBitmap := Gdip_CreateBitmapFromFile(exitMenuPic)
iBitmap := Gdip_CreateBitmapFromFile(exitInfoPic)
Gdip_DrawImage(G, pBitmap, 0, 0, dWidth, dHeight, 0, 0, pWidth, pHeight)
Gdip_DrawImage(iG, iBitmap, 0, 0, sWidth, sHeight, 0, 0, iWidth, iHeight)
Gdip_DisposeImage(pBitmap)
Gdip_DisposeImage(iBitmap)
UpdateLayeredWindow(hwExit, hdc, xExitM, yExitM, rWidth, rHeight)
UpdateLayeredWindow(hwExitInfo, ihdc, xExitInfo, yExitInfo, brWidth, brHeight)
clear("exitmenuPic,exitInfoPic")
Return


selectItem:
toLog("selectItem Called")
If (serviceMenuOn = 0) { ; main menu
If (menuItem = 1) { ; close menu
	Gosub %exitmeth%
} Else  If (menuItem = 2) { ; instructions
	;Gosub %exitmeth%
	toLog("Exit Menu Closed - Instructions")
	Gosub Instructions
} Else  If (menuItem = 3) { ; flyer
	;Gosub %exitmeth%
	toLog("Exit Menu Closed - Flyer")
	Gosub Flyer
} Else  If (menuItem = 4) { ; service menu
	SoundPlay menu.wav
	serviceMenuOn = 1
	menuItem = 1
	toLog("Exit Menu Swapped - Service")
	Gosub MenuSwap
} Else  If (menuItem = 5) { ; exit
	Gosub %exitmeth%
	toLog("Exit Menu Closed - CloseGame")
	Goto CloseGame
} 
} Else If (serviceMenuOn = 1) { ; service menu
If (menuItem = 1) { ; back
	serviceMenuOn = 0
	toLog("Service Menu Swapped - Exit")
	Gosub MenuSwap
} Else  If (menuItem = 2) { ; reset vp - send f3
	Gosub %exitmeth%
	toLog("Service Menu Closed - F3")
	toLog("Attempting to reset Visual Pinball")
	If (systemName = "Visual Pinball") { 
		Send {F3 down}
		Sleep 100
		Send {F3 up}
	}
} Else  If (menuItem = 3) { ; resize fp - send scroll lock in case you don't have one 
	Gosub %exitmeth%
	toLog("Service Menu Closed - Size FP")
	If (systemName = "Future Pinball") {
		Send {ScrollLock down}
		Sleep 100
		Send {ScrollLock up}
	}
} Else  If (menuItem = 4) {
; focus - not tested!!! wip wip wip wip - should be a function
; should be executed on every exit from menu - not just here
; (if it is needed - if it is not it can be removed from menu)
	Gosub %exitmeth%
	toLog("Service Menu Closed - Focus Windows")
	If (systemName = "Visual Pinball") {
		toLog("Attempting to Focus Visual Pinball")
		DetectHiddenWindows off 	
		IfWinExist, Ahk_Class  MAME 
		{
			WinActivate, Ahk_Class  MAME
			WinWaitActive, Ahk_Class MAME,,2
			ControlClick,, Ahk_Class MAME
			toLog("Attempting to Focus Visual Pinball DMD")
		}
		DetectHiddenWindows on
		WinSet, Bottom, ,Form1
		WinSet, Bottom, ,HGlass1
		WinActivate, Ahk_Class VPPlayer,,DMD
		WinWaitActive, Ahk_Class VPPlayer,,2
		ControlClick, X5 Y5, Ahk_Class VPPlayer,,,,,DMD
	} Else If (systemName = "Future Pinball") {
		toLog("Attempting to Focus Future Pinball")
		WinActivate, Ahk_Class FuturePinballOpenGLSecondary
		WinWaitActive, Ahk_Class FuturePinballOpenGLSecondary,,2
		toLog("Attempting to Focus Future Pinball DMD")
		WinActivate, Ahk_Class FuturePinballOpenGL
		WinWaitActive, Ahk_Class FuturePinballOpenGL,,2
	}
} Else  If (menuItem = 5) { ; go to editor
	Gosub %exitmeth%
	toLog("Service Menu Closed - Drop to Editor")
	If (systemName = "Visual Pinball")
		Gosub ShowVP
	Else If (systemName = "Future Pinball")
		Gosub ShowFP
}
}
Return
;------------------------------End of exitmenu -------------------------------;




;----------------------------------Flyer---------------------------------------;
Flyer:
SoundPlay menu.wav
toLog("Flyer Called")
If (flyerOn = 0) { ; show flyer
If (menuOn = 0) And (instructionsOn = 0) And (systemName = "Future Pinball") {
	WinActivate, ahk_class FuturePinballOpenGL
	WinWaitActive, ahk_class FuturePinballOpenGL
	Send {%pauseFPKey%}
	WinWaitActive, ahk_class FuturePinballOpenGL
	Gosub CreateBlackScreen ; we draw printscreen first
}
If (menuOn = 1)
	Gosub closeMenus
flyerOn = 1
paused = 1
instructionsOn = 0
toLog("Flyer Create")
; put hotkeys in a sub !!!
Hotkey, %UpKey%, MoveUp, On
Hotkey, %DownKey%, MoveDown, On
; start and plunger will close flyer
Hotkey, %exitEmulatorKey2%, %exitmeth%, On
Hotkey, %exitEmulatorKey3%, %exitmeth%, On
; show footer first, then flyer
; show footer image in gui 2
flyerInfoPic = %picDir%flyerb.png
iBitmap := Gdip_CreateBitmapFromFile(flyerInfoPic)
Gdip_ImageRotateFlip(iBitmap,3) ; rotate image for 270°
iWidth := Gdip_GetImageWidth(iBitmap)
iHeight := Gdip_GetImageHeight(iBitmap)
iScale := A_ScreenHeight/iHeight
tWidth := iWidth*iScale
tHeight := A_ScreenHeight
Gui, 2: Show,, Footer
DrawImageBTB(2, iBitmap, iWidth, iHeight, tWidth, tHeight, A_ScreenWidth-tWidth+1, 0, 1)
; show flyer in gui 1
Gosub flyerSwap
;msgbox
} Else { ; kill flyer
flyerOn = 0
menuOn = 0
serviceMenuOn = 0
paused = 0
toLog("Flyer Close")
Hotkey, %UpKey%, Off
Hotkey, %DownKey%, Off
Hotkey, %exitEmulatorKey2%, Off
Hotkey, %exitEmulatorKey3%, Off
Gui, 2: Destroy
Gui, 1: Destroy
; wip wip wip wip !!!!! one unique focus function!!!
IfWinExist, Visual Pinball Player,, DMD 
{
	WinActivate
	ControlClick,, Ahk_Class VPPlayer
	;WinSet, Bottom, ,Form1 ;send to back b2s backglass so mame dmd is on top ;ahk_class is impossibly long!
	;WinSet, Bottom, ,HGlass1 ;then backglass image from hyperpin as above ;ahk_class ThunderRT6FormDC clashes with HyperPin
} Else IfWinExist, Ahk_Class FuturePinballOpenGL 
{
	If (systemName = "Future Pinball") {
		Gui, 9: Destroy
		WinActivate, Ahk_Class FuturePinballOpenGL
		WinWaitActive, ahk_class FuturePinballOpenGL
		Send {%pauseFPKey%}
	}
}
toLog("Flyer Closed")
}
Return


MoveUp:		; used for exitmenu as well, probably will be used for instr. also
SoundPlay menu.wav
toLog("MoveUp Called")
If (flyerOn = 1) {
flyer--
Gosub flyerSwap
;Gui, 1: Show
} Else If (instructionsOn = 1) {
instr--
Gosub instrSwap
} Else If (menuOn = 1) {
menuItem--
Gosub MenuSwap
}
Return


MoveDown:		; used for exitmenu as well, probably will be used for instr. also
SoundPlay menu.wav
toLog("MoveDown Called")
If (flyerOn = 1) {
flyer++
Gosub flyerSwap
;Gui, 1: Show
} Else If (instructionsOn = 1) {
sleep 1
instr++
Gosub instrSwap
} Else If (menuOn = 1) {
menuItem++
Gosub MenuSwap
}
Return


flyerSwap:
toLog("flyerSwap Called")
If (flyer = 0) {
 flyer := flyerpages
 if (flyerpages = 1)
return
}
If (flyer > flyerpages) {
 flyer = 1
 if (flyerpages = 1)
   return
}
flyerPic := flyerPic%flyer%  
pBitmap := Gdip_CreateBitmapFromFile(flyerPic)
Gdip_ImageRotateFlip(pBitmap,3) ; rotate image for 270°
OriginalWidth := Gdip_GetImageWidth(pBitmap)
OriginalHeight := Gdip_GetImageHeight(pBitmap)
Ratio := OriginalWidth/OriginalHeight
; we want flyer to be as big as possible
if (OriginalWidth/(A_ScreenWidth*0.8) >= OriginalHeight/(A_ScreenHeight*0.96)) {
Width := A_ScreenWidth*0.8
Height := Width*(1/Ratio)
} else {
Height := A_ScreenHeight*0.96
Width := Height*Ratio
}
xCoo := (A_ScreenWidth*0.85-Width)//2
yCoo := (A_ScreenHeight-Height)//2
Gui, 1: Show,, Flyer
DrawImageBTB(1, pBitmap, OriginalWidth, OriginalHeight, Width, Height, xCoo, yCoo, 0)
;Gui, 2: Show
;Gui, 1: Show
toLog("Flyer Page Turned")
Return
;--------------------------------End of flyer----------------------------------;




;-----------------------------Instruction Cards--------------------------------;
Instructions:
SoundPlay menu.wav
toLog("Instructions Called")
If (instructionsOn = 0) { ; show instructions
If (menuOn = 0) And (flyerOn = 0) And (systemName = "Future Pinball") {
	; no menus, print screen and send pause
	; put this in sub !!!
	WinActivate, ahk_class FuturePinballOpenGL
	WinWaitActive, ahk_class FuturePinballOpenGL
	Send {%pauseFPKey%}
	WinWaitActive, ahk_class FuturePinballOpenGL
	Gosub CreateBlackScreen ; we draw printscreen first
}
If (menuOn = 1)
	Gosub closeMenus
instructionsOn = 1
paused = 1
flyerOn = 0
toLog("Instruction Card Create")
;Gui, 2: Destroy
Hotkey, %UpKey%, MoveUp, On
Hotkey, %DownKey%, MoveDown, On
; start and plunger will close instructions
Hotkey, %exitEmulatorKey2%, %exitmeth%, On
Hotkey, %exitEmulatorKey3%, %exitmeth%, On
; show footer first, then instructions
; show footer image in gui 2
flyerInfoPic = %picDir%instructb.png
iBitmap := Gdip_CreateBitmapFromFile(flyerInfoPic)
Gdip_ImageRotateFlip(iBitmap,3) ; rotate image for 270°
iWidth := Gdip_GetImageWidth(iBitmap)
iHeight := Gdip_GetImageHeight(iBitmap)
iScale := A_ScreenHeight/iHeight
tWidth := iWidth*iScale
tHeight := A_ScreenHeight
Gui, 2: Show,, Footer
DrawImageBTB(2, iBitmap, iWidth, iHeight, tWidth, tHeight, A_ScreenWidth-tWidth+1, 0, 1)
; show instr in gui 1
Gosub instrSwap
} Else  { ; hide instructions
instructionsOn = 0
menuOn = 0
serviceMenuOn = 0
paused = 0
toLog("Instruction Card Close")
; up and down not needed for now (it will be after we extend instructions)
Hotkey, %UpKey%, Off
Hotkey, %DownKey%, Off
Hotkey, %exitEmulatorKey2%, Off
Hotkey, %exitEmulatorKey3%, Off
Gui, 2: Destroy
Gui, 1: Destroy
; wip wip wip wip wip focus code should be subroutine !!!
IfWinExist, Visual Pinball Player,, DMD
{
    WinActivate ; winactivate what???
	WinWaitActive, Ahk_Class VPPlayer,,2
	ControlClick, X5 Y5, Ahk_Class VPPlayer,,,,,DMD
} Else IfWinExist, Ahk_Class FuturePinballOpenGL 
{
	If (systemName = "Future Pinball") {
		Gui, 9: Destroy
		WinActivate, Ahk_Class FuturePinballOpenGL
		WinWaitActive, ahk_class FuturePinballOpenGL
		Send {%pauseFPKey%}
	}
    WinActivate, Ahk_Class FuturePinballOpenGL
}
	toLog("Instruction Card Closed")
}
Return


instrSwap:
toLog("instrSwap Called")
If (instr = 0) {
 instr := instrpages
 if (instrpages = 1)
return
}
If (instr > instrpages) {
 instr = 1
 if (instrpages = 1)
   return
}
instrPic := instrPic%instr%  
StringRight, ending, instrPic, 3
if (ending = "swf") { ; we have swf image
Width := A_ScreenHeight*0.95
Height := A_ScreenHeight*0.95


SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79


;Gui, 1: Destroy
Gui, 1: +LastFound -Caption +AlwaysOnTop -SysMenu  +E0x80000
Gui, 1: Show, w%Width% h%Height%  x%VirtualWidth% y%VirtualHeight%, Instruction Card 
;Gui, 1: Margin, 0 ,0
;Gui, 1: Color, EEAA99
;Gui, 1: Add, ActiveX, w%Width% h%Height% vpwb, ShockwaveFlash.ShockwaveFlash
Gui, 1: +LastFound 
WinActivate
getInstructFromDisk = %instrPic%
;pwb.wmode := "direct" ;window/opaque/direct/transparent/gpu
;pwb.scale := "Default" ;noborder/default/exactfit/noscale
;pwb.bgcolor := "#EEAA99"
;pwb.Movie := "file:///" . getInstructFromDisk
SwfWnd := WinExist()	   
hCtrl := COM_AtlAxCreateContainer(SwfWnd, 0, 0, Width, Height) 
COM_AtlAxAttachControl(psf := COM_ActiveXObject("{D27CDB6E-AE6D-11cf-96B8-444553540000}"), hCtrl) 
COM_Invoke(psf, "Menu=", "0") 
COM_Invoke(psf, "Movie=", "file:///" . getInstructFromDisk) 
COM_Invoke(psf, "bgcolor=", "#EEAA99")
pBitmap := Gdip_BitmapFromHWND(SwfWnd)
;Gdip_GetRotatedDimensions(Width, Height, Playfield_Rotation, rWidth, rHeight)
Gdip_GetRotatedTranslation(Width, Height, Playfield_Rotation, xTranslation, yTranslation)
hbm := CreateDIBSection(Width,Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc), Gdip_SetInterpolationMode(G, 7)
Gdip_TranslateWorldTransform(G, xTranslation, yTranslation)
Gdip_RotateWorldTransform(G, Playfield_Rotation)
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, Width, Height)
pBitmapOut := Gdip_CreateBitmap(Width, Height)
E := Gdip_BitmapReplaceColor(pBitmap, pBitmapOut, 0xFFEEAA99, 0x00000000, 1)
Gdip_GraphicsClear(G) ;make note of this - prob needs to be added to Menu And countdown
Gdip_DrawImage(G, pBitmapOut)
Gdip_DisposeImage(pBitmap)
Gdip_ResetWorldTransform(G)
Gdip_DisposeImage(pBitmapOut)
UpdateLayeredWindow(SwfWnd, hdc, (A_ScreenWidth-Width)//2, (A_ScreenHeight-Height)//2, Width, Height)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
COM_Release(psf)
} Else { ; show instructions not found or some other image
; new flyer code
pBitmap := Gdip_CreateBitmapFromFile(instrPic)
Gdip_ImageRotateFlip(pBitmap,3) ; rotate image for 270°
OriginalWidth := Gdip_GetImageWidth(pBitmap)
OriginalHeight := Gdip_GetImageHeight(pBitmap)
Ratio := OriginalWidth/OriginalHeight
; we want instr to be as big as possible
if (OriginalWidth/(A_ScreenWidth*0.8) >= OriginalHeight/(A_ScreenHeight*0.96)) {
	Width := A_ScreenWidth*0.8
	Height := Width*(1/Ratio)
} else {
	Height := A_ScreenHeight*0.96
	Width := Height*Ratio
}
xCoo := (A_ScreenWidth*0.85-Width)//2
yCoo := (A_ScreenHeight-Height)//2
Gui, 1: Show,, instr
DrawImageBTB(1, pBitmap, OriginalWidth, OriginalHeight, Width, Height, xCoo, yCoo, 0)
;Gui, 2: Show
;Gui, 1: Show
}
toLog("instr Page Turned")
Return
;---------------------------End of instruction card----------------------------;




; draw image by the book - destroys bitmap also
DrawImageBTB(guiNum, pBitmap, origWidth, origHeight, tgtWidth, tgtHeight, xCoo=0, yCoo=0, CompMode=0) {
toLog("DrawImageBTB Called")
;Gui, %guiNum%: Show, Hide, Flyer
Gui, %guiNum%: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, %guiNum%: Show
hwnd1 := WinExist()
; why is this ???
   ;Gui, 1: +LastFound 
;WinActivate
; no need for bitmap since we have it already
; if we need to rotate bitmap calling script can to it also
;pBitmap := Gdip_CreateBitmapFromFile("background.png")
;Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
hbm := CreateDIBSection(tgtWidth, tgtHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetCompositingMode(G, CompMode)
Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, pBitmap, 0, 0, tgtWidth, tgtHeight, 0, 0, origWidth, origHeight)
UpdateLayeredWindow(hwnd1, hdc, xCoo, yCoo, tgtWidth, tgtHeight)
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_DisposeImage(pBitmap)
}


;------------------- "External" functions -------------------


; rosve support for B2S active backglasses
rosve:
toLog("rosve Called")
;--------------------------------------------------------------
;------     check if an active backglass shall be started -----
;--------------------------------------------------------------
StringRight, ending, tableName, 3
if (ending = "B2S")
{
Run, %tablePath%%tableName%.exe, %tablePath%
sleep 200
}
return


rosveClose:
toLog("rosveClose Called")
; rosve
; --------------------------------------------------------------
; --- Close the animated backglass -----------------------
; --------------------------------------------------------------
; b2s close bug fix
StringRight, ending, tableName, 3
if (ending = "B2S")
{
WinKill, Form1
}
return


; bigboss support for different exe, sound levels and hdrender off
bigboss:
toLog("bigboss Called")
; bigboss
; Array examples: http://www.autohotkey.com/docs/misc/Arrays.htm
; Read config file for vp9.08 tables
vp908count = 0
; This loop retrieves each line from the file, one at a time.
Loop, Read, %A_ScriptDir%\Settings\vp908tables.txt
{
	vp908count += 1  ; Keep track of how many items are in the array.
	vp908array%vp908count% := A_LoopReadLine  ; Store this line in the next array element.
}


; Check if table is in the vp908tables array.
Loop %vp908count%
{
	; The following line uses the := operator to retrieve an array element:
	element := vp908array%A_Index%  ; A_Index is a built-in variable.
	if(tableName = element)
	{
		TableIndex = %A_Index%
		vpExeIndex = %TableIndex%
		vpExeIndex += 1		
		executable := vp908array%vpExeIndex%
		break
	}
}


; Read config file for disable HD rendering tables since this is a global setting now.
HDRenderOffCount = 0
HDRenderOffChanged = 0
; This loop retrieves each line from the file, 1 at a time.
Loop, Read, %A_ScriptDir%\Settings\hdrenderofftables.txt
{
	HDRenderOffCount += 1  ; Keep track of how many items are in the array.
	HDRenderOffArray%HDRenderOffCount% := A_LoopReadLine  ; Store this line in the next array element.
}


; Check if table is in the no hdrender array and write the VP hardwarerender key to off.
Loop %HDRenderOffCount%
{
	; The following line uses the := operator to retrieve an array element:
	element := HDRenderOffArray%A_Index%  ; A_Index is a built-in variable.
	if(tableName = element)
	{
		HDRenderOffChanged = 1
		RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Visual Pinball\Player, HardwareRender, 0
		break
	}
}

; Read config for sound volume hard codes
SoundModCount = 0
SoundChangeAmount = 0
Loop, Read, %A_ScriptDir%\Settings\soundmodtables.txt
{
	SoundModCount += 1
	SoundModCountArray%SoundModCount% := A_LoopReadLine
}


; Check if table is in the vp908tables array.
Loop %SoundModCount%
{
	; The following line uses the := operator to retrieve an array element:
	TableIndex = %A_Index%
	SoundIndex = %TableIndex%
	SoundIndex += 1		
	TheTable := SoundModCountArray%TableIndex%
	TheSoundAmount := SoundModCountArray%SoundIndex%

	if(tableName = TheTable)
	{
		; Set the new sound change amount. Should be a + or - number otherwise it needs a , SoundSet, absoluteamt
		; SoundSet: http://www.autohotkey.com/docs/commands/SoundSet.htm
		; SoundGet: http://www.autohotkey.com/docs/commands/SoundGet.htm
		;SoundSet, %TheSoundAmount%
		Send {Volume_Down %TheSoundAmount%}
		break
	}
}
return


bigbossClose:
toLog("bigbossClose Called")
; bigboss
; Restore hdrender original value
if (HDRenderOffChanged)
RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Visual Pinball\Player, HardwareRender, 1
; Restore master volume original value
if (TheSoundAmount)
Send {Volume_Up %TheSoundAmount%}
return




; big boss slamit bigscore support
SlamitBigScore:
toLog("SlamitBigScore Called")
Hotkey, $%exitEmulatorKey%, CloseSlam
;setworkingdir, "..\SlamIt\BigScore.exe"
Run, "..\slamit\go.bat", "..\SlamIt"
WinWait, ahk_class SlamIt Pinball - Big Score
Gui, destroy
Process, WaitClose, BigScore.exe
goto ExitScript
return


CloseSlam:
toLog("CloseSlam Called")
WinClose, ahk_class SlamIt Pinball - Big Score
goto ExitScript
return


PinEmHiScore:
; show hiscores on screen
Fileread, contents,hiscore.txt
;msgbox %tablename%
;pToken := Gdip_Startup()
;Gui, Destroy
;vertical distance of Hiscore window
HiScoreTopDistance := 10
;Gui 4 - hidden horizontal Gui
Gui, 4: Color, 0b40e4
Gui, 4: Font, s15, Quartz
Gui, 4: Add, Text, Cffffff Center, %contents%
Gui, 4: +AlwaysOnTop -Caption +Lastfound
hwnd := WinExist()
Gui, 4: Show, NA, hiscoreshidden
WinGetPos,scorex,scorey, scorew, scoreh, ahk_id %hwnd%
pBitmap := Gdip_BitmapFromScreen("hwnd:" hwnd)
Gui, 4: Show, Hide
;Gui 5 - hiscore background image
imageW := scoreh+20, imageH := scorew+40
Gui, 5: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 5: Show, NA, hiscoresback
hwnd1 := WinExist()
shbm := CreateDIBSection(imageW, imageH)
shdc := CreateCompatibleDC()
sobm := SelectObject(shdc, shbm)
sG := Gdip_GraphicsFromHDC(shdc)
Gdip_SetSmoothingMode(sG, 4)
pBrush1 := Gdip_BrushCreateSolid(0xff0ffffff)
pBrush2 := Gdip_BrushCreateSolid(0xff00C32A5)
pBrush3 := Gdip_BrushCreateSolid(0xff0b40e4)
Gdip_FillRoundedRectangle(sG, pBrush1, 0, 0, imageW, imageH, 20)
Gdip_FillRoundedRectangle(sG, pBrush2, 5, 5, imageW-10, imageH-10, 15)
Gdip_FillRoundedRectangle(sG, pBrush3, 10, 10, imageW-20, imageH-20, 10)
Gdip_DeleteBrush(pBrush1)
Gdip_DeleteBrush(pBrush2)
Gdip_DeleteBrush(pBrush3)
UpdateLayeredWindow(hwnd1, shdc, HiScoreTopDistance, (A_ScreenHeight-imageH)//2, imageW, imageH)
SelectObject(shdc, sobm)
DeleteObject(shbm)
DeleteDC(shdc)
Gdip_DeleteGraphics(sG)
;Gui 6 - rotated vertical Gui
Gui, 6: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 6: Show, NA, hiscores
hwnd2 := WinExist()
bitmapW := scoreh, bitmapH := scoreW
shbm := CreateDIBSection(bitmapW, bitmapH)
shdc := CreateCompatibleDC()
sobm := SelectObject(shdc, shbm)
sG := Gdip_GraphicsFromHDC(shdc)
UpdateLayeredWindow(hwnd2, shdc, HiScoreTopDistance+10, (A_ScreenHeight-bitmapH)//2, bitmapW, bitmapH)
Gdip_ImageRotateFlip(pBitmap, 3)
Gdip_DrawImage(sG, pBitmap)
UpdateLayeredWindow(hwnd2, shdc)
Gdip_DisposeImage(pBitmap)
SelectObject(shdc, sobm)
DeleteObject(shbm)
DeleteDC(shdc)
Gdip_DeleteGraphics(sG)


Return

;------------------- End of External functions -------------------


ExitScript:
toLog("ExitScript Called")
ExitApp
return


onExitScript:
toLog("onExitScript Called")
if (ledwiz = "true")
Run, "%A_ScriptDir%\ledset.bat",,hide
Gdip_Shutdown(pToken)
toLog("GDI+ Unloaded")
COM_AtlAxWinTerm() 
COM_CoUninitialize() 
COM_Term() 
toLog("COM Unloaded")


Loop, 5
Gui, %A_Index%: Destroy


if (hideCursor = "true")
SystemCursor("On")
Process, Exist, %hyperpinexe%
PID := errorLevel
if (PID) {
; activate hyperpin
;WinActivate, ahk_pid %PID%
;ExitApp
loading = 1
waithp:
toLog("waithp 1")
if (loading = 0) break
Sleep 400
WinActivate, ahk_pid %PID%
;MouseMove %A_ScreenWidth%/2, %A_ScreenHeight%/2
;ControlClick,, ahk_pid %PID%
Sleep 400
IfWinNotActive, ahk_pid %PID%
	Goto waithp
toLog("waithp 2")
Sleep 400
IfWinNotActive, ahk_pid %PID%
	Goto waithp
toLog("waithp 3")
Sleep 400
IfWinNotActive, ahk_pid %PID%
	Goto waithp
} else if (hideTaskbar = "true") {
; show taskbar if there is no hyperpin
WinShow ahk_class Shell_TrayWnd
WinShow Start ahk_class Button
taskbar = 1
}
; show cursor
SystemCursor("On")


;to debug script uncomment the pause
;Pause
; final exit
toLog("Exiting...")
;Run, "cscript %A_ScriptDir%\FPClose.vbs",,hide
ExitApp
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
{
ListLines Off
   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,32645,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% )
   }
if (gListLines)
	ListLines %gListLines%
}


ToggleCursor:
SystemCursor("Toggle")
Gosub ToggleTaskbar
return


ToggleTaskbar:
if (hideTaskbar = "true") {
if (taskbar) {	; taskbar is shown
	WinHide ahk_class Shell_TrayWnd
	WinHide Start ahk_class Button
	taskbar = 0
} else {
	WinShow ahk_class Shell_TrayWnd
	WinShow Start ahk_class Button
	taskbar = 1
}
}
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 
}


ini_getValue(ByRef _Content, _Section, _Key, _PreserveSpace = False)
{
   If (_Section = "")
       _Section = (?:\[.*])?
   Else
   {
        _Section = \[\s*?\Q%_Section%\E\s*?]
   }
   ; Note: The RegEx of this Function was rewritten by Mystiq.
   RegEx = `aiU)(?:\R|^)\s*%_Section%\s*(?:\R\s*|\R\s*.+\s*=\s*.*?\s*(?=\R)|\R\s*[;#].*?(?=\R))*\R\s*\Q%_Key%\E\s*=(.*)(?=\R|$)
   If RegExMatch(_Content, RegEx, Value)
   {
       If Not _PreserveSpace
       {
           Value1 = %Value1% ; Trim spaces.
           FirstChar := SubStr(Value1, 1, 1)
           If (FirstChar = """" And SubStr(Value1, 0, 1)= """"
               Or FirstChar = "'" And SubStr(Value1, 0, 1)= "'")
           {
               StringTrimLeft, Value1, Value1, 1
               StringTrimRight, Value1, Value1, 1
           }
       }
       ErrorLevel = 0
   }
   Else
   {
       ErrorLevel = 1
       Value1 =
   }
   Return Value1
}


;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, %hyperini%
 {
   MsgBox,48,Error,Cannot Find %hyperini%,6
hyperpinexe = hyperpin.exe
   Goto ExitScript 
 }
 ; check images
 ;for i in %picini% ...
 ; check com and gdi libs
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, %A_ScriptDir%\%hyperpinexe%
 {
   MsgBox,48,Error, Must be in same directory as %hyperpinexe%,6
   Goto ExitScript 
 }
 IfNotExist, %EmuPath%%Executable%
 {
   MsgBox,48,Error, Cannot Find %EmuPath%%Executable%,6
   Goto ExitScript 
 }
 IfNotExist, %tablePath%%tableName%.%romExtension%
 {
   MsgBox,48,Error, Cannot Find %tablePath%%tablename%.%romExtension%,6
   Goto ExitScript 
 }
return


toLog(data, filename="log.txt", dtype="string") 
{
ListLines Off
Global debugMode, paused, menuon, flyeron, instructionson, gListLines
if (debugMode = "true" OR debugmode = "file") {
	FormatTime, timenow ,, hh:mm:ss tt | 
	FileAppend, %timenow% %data% p%paused% m%menuon% f%flyeron% i%instructionson%`n, %filename% 
}
if (debugMode = "true" OR debugmode = "screen") {
	CoordMode ToolTip
	ToolTip %data%, 10, 40, 3
}
;msgbox %gListLines%
ListLines %gListLines%
}


Clear($)       ; Clear("VarName1,  VarName2,...")
{             
  Loop Parse, $, `,, %A_Space%%A_Tab%
     %A_LoopField% := ""
}


Gdip_BitmapReplaceColor(pBitmap, ByRef pBitmapOut, Color, ReplaceColor, Variation)
{
global G
global Width
global Height
global SwfWnd
global hdc
  static BitmapReplaceColor
  If !BitmapReplaceColor
  {
     MCode_BitmapReplaceColor := "83EC248B4424388B4C243C995683E2038BF103C28B542438C1FE10C1F90881E6FF00000081E1FF000000C1F8028"
     . "9742408894C244085D20F8E0A010000538B5C2430558B6C245033C903C0578B7C243C03C0894C241C89442430897C241889542420837C2440000F8"
     . "EB90000008D43018BD32BD083C202895424282BF5894C244403C88BD32BD08B442440897424248954242C89442410EB0B8DA424000000008B74242"
     . "48B5424280FB6140A0FB6013BD67E0A8B74241403F53BD67C268B74244C2BF53BC67E248B5C244C03DD3BC38B5C24387C0E3BC67E128B74244C03F"
     . "53BC67D088B4424508907EB228B7424440FB6741E03C1E6080BF28B54242CC1E6080BF00FB6040AC1E6080BF08937834424440483C10483C704FF4"
     . "C241075828B4C241C8B7424148B7C2418037C2430034C2448FF4C2420897C2418894C241C0F851EFFFFFF5F5D5BB8010000005E83C424C3"


     VarSetCapacity(BitmapReplaceColor, StrLen(MCode_BitmapReplaceColor)//2)
     Loop % StrLen(MCode_BitmapReplaceColor)//2      ;%
        NumPut("0x" SubStr(MCode_BitmapReplaceColor, (2*A_Index)-1, 2), BitmapReplaceColor, A_Index-1, "char")
  }


  If (Variation > 255 || Variation < 0)
     Return -2


  E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  If (E1 || E2)
     Return -3


  E := DllCall(&BitmapReplaceColor, "uint", Scan01, "uint", Scan02, "int", Width, "int", Height, "int", Stride1, "int", Color, "int", ReplaceColor, "int", Variation)
  Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
  Return 0
}


GlobalListLines(OnOffLines) ; sets ListLines On/Off and updates global variable gListLines
{
global gListLines := OnOffLines
ListLines %OnOffLines%
}


Share this post


Link to post
Share on other sites

Here is new version of fplaunch 1.295 wip 9 with hiscores and table name in exit menu http://vpuniverse.com/forums/index.php/topic/135-hyperpin-hi-scores/?p=1142

Try it and report back.

For hiscores to work you have to download pinemhi from www.pinemhi.com and put pinemhi.exe and pinemhi.ini in hyperpin dir

Edited by blur

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...