VPM Hi-Scores to PNGs for Popper Media

(requires Pinup 1.4 or later):

Summary: after exiting a VP/FP table, a script is called to parse either the VPM nvram file or the PostIT-style high score text file, as well as Future Pinball fpram files, and generates a PNG file with the high score information for that particular rom (example: https://ibb.co/mJJquq ). The PNG file is saved, in this example, as GAMEFILE-06.png and stored in \POPMedia\Visual Pinball X\Gameinfo (Note: the “-06” suffix fits well into my personal setup, and the \Visual Pinball X\ folder is where I store all media for VP, independently of version). Users can choose to save in Topper or DMD folders if they fit their setup better.

Components:
1) PINemiHi 1.3.1 (from vpforums)


Takes romname.nv as parameter, and outs the high-score information via stdout
Note: romname is CASE-SENSITIVE
Note: PINemHi has an ini file that only requires pointers to VPinMAME\nvram\ and Future Pinball\fpram
Note: PINemHi supports Future Pinball but I did not spend any time on that

2) MagiImageMagick-7.0.8-14-portable-Q16-x86 (https://imagemagick.org/script/download.php)


Note: Takes a txt file and merges it with a background picture.
Note: Tested with the portable 32-bit version
Note: lots of customization here, so you can experiment with font size, colors, background image, etc.

3) JPG for background (use www.google.com). I use a chalkboard in my setup (examples at https://tinyurl.com/yadrvdr2 )


Note: I'm currently using a 736×920 background image

4) windows batch script hiscore.bat that takes [ROMNAME|HSFilename] and “[GAMEFILE]” “[?GAMETYPE?]” as parameters

@echo off
SETLOCAL EnableDelayedExpansion

REM START OF VARIABLES DECLARATION

    REM Set the following variables based on your setup
    REM Path to PINemHI
    SET "PINemHiPath=c:\Pinball\PINemHi"

    REM Path to ImageMagick
    SET "ImageMagick=c:\Tools\ImageMagick-7.0.8-14-portable-Q16-x86"

    REM Path to TXT files with HiScores
    SET "PINemHiHS=c:\Pinball\PINemHi\Text"
    If NOT EXIST "%PINemHiHS%" (mkdir "%PINemHiHS%")

    REM Path for temporary PNGs and background image
    SET "PINemHiPNG=c:\Pinball\PINemHi\PNGs"

    REM Filename of background image to be used
    SET "Background=chalkboard.jpg"

    REM Path to VPinMAME nvram files
    SET "NVRamPath=c:\Pinball\Visual Pinball\VPinMAME\nvram"

    REM Path to FP nvram files
    SET "FPNVRamPath=c:\Pinball\Future Pinball\fpRAM"

    REM Path to VP User files
    SET "UserPath=c:\Pinball\Visual Pinball\User"

    REM Path to 7z
    SET "Zexepath=c:\Tools"

    REM Folder where you want the VP high score PNGs with high scores placed (GameInfo, Topper, DMD, etc.)
    SET "POPVPMedia=c:\Pinball\PinupSystem\POPMedia\Visual Pinball X\GameInfo"

    REM Folder where you want the FP high score PNGs with high scores placed (GameInfo, Topper, DMD, etc.)
    SET "POPFPMedia=c:\Pinball\PinupSystem\POPMedia\Future Pinball\GameInfo"

    REM This suffix will be added to the second parameter passed (tablename) when saving high score PNGs
    SET "Suffix=-06"

REM END OF VARIABLES DECLARATION

REM Need to change to the PINemHi folder in order for the exe to read its INI
cd "%PINemHiPath%"
REM Uncomment the next line to regenerate PINemHi supported roms DB
REM "%PINemHiPath%\pinemhi.exe" -lr>"%PINemHiPath%\supported.txt"

REM We will select the right parsing routine
SET ISTEXT=%3
if "%ISTEXT%" == "BAM" GOTO FUTURE
SET ISTEXT=%3
if "%ISTEXT%" == "UltraDMD" GOTO ULTRADMD
SET ISTEXT=%1
SET ISTEXT=%ISTEXT:~-5%
set ISTEXT=%ISTEXT:"=%
if "%ISTEXT%" == ".txt" GOTO POSTIT

GOTO NVRAM

:FUTURE
REM Start of fpram processing
SET TEMPTXT=%~2
SET OUTPUT=%POPFPMedia%
REM if there is no FP nvram file, exit
IF NOT EXIST "%FPNVRamPath%\%~2.fpram" exit
REM call PINemHi pipped to a txt file
"%PINemHiPath%\pinemhi.exe" %~2.fpram>"%PINemHiHS%\%~2.txt"
REM delete TXT files with size 0 as they are empty
for /f %%I in ("%PINemHiHS%\%~2.txt") do if %%~zI==0 del "%PINemHiHS%\%TEMPTXT%.txt"
GOTO PNG

:ULTRADMD
REM Start of ULTRADMD processing
SET TEMPTXT=%~1
SET OUTPUT=%POPVPMedia%
REM extract hiscore files from iStor
@echo High Scores>"%PINemHiHS%\%TEMPTXT%.txt"
%Zexepath%\7z.exe x -o"%PINemHiHS%" "%UserPath%\VPReg.stg" %1
REM Then parse and build TXT file similar to POSTIT
FOR /L %%G IN (1,1,4) DO (
    more "%PINemHiHS%\%1\HighScore%%GName">>"%PINemHiHS%\%TEMPTXT%.txt"
    more "%PINemHiHS%\%1\HighScore%%G">>"%PINemHiHS%\%TEMPTXT%.txt"
    echo.>>"%PINemHiHS%\%TEMPTXT%.txt"
)
REM we now clean temp files
rmdir "%PINemHiHS%\%1" /s/q
REM delete TXT files with size 0 as they are empty
for /f %%I in ("%PINemHiHS%\%TEMPTXT%.txt") do if %%~zI==0 del "%PINemHiHS%\%TEMPTXT%.txt"
GOTO PNG

:POSTIT
REM Start POSIT is file processing
SET TEMPTXT=%~1
SET TEMPTXT=%TEMPTXT:"=%
SET OUTPUT=%POPVPMedia%
REM if there is no PostIT file, exit
IF NOT EXIST "%UserPath%\%TEMPTXT%" exit
REM We read the PostIT file into an Array
set var[0]=0
set /a idx=0
for /f "usebackq delims=" %%I in ("%UserPath%\%TEMPTXT%") do (
    set "var[!idx!]=%%I"
    set /a idx += 1
    )
REM We generate a text file with the high scores table
@echo High scores:>"%PINemHiHS%\%TEMPTXT%.txt"
set /a "HSN=idx-5"
set /a "HS=idx-10"
:While
    IF %HSN% EQU %idx% GOTO EndWhile
        call echo %%var[!HSN!]%% %%var[!HS!]%%>>"%PINemHiHS%\%TEMPTXT%.txt"
        set /a HSN += 1
        set /a HS += 1
        GOTO While
:EndWhile
GOTO PNG

:NVRAM
REM Start of NVRAM processing
SET TEMPTXT=%~1
SET OUTPUT=%POPVPMedia%

REM if there is no nvram file, exit
IF NOT EXIST "%NVRamPath%\%TEMPTXT%.nv" exit
REM we will only process the nvram file if the rom is supported by PINemHi
for /F "usebackq delims=" %%A in ("%PINemHiPath%\supported.txt") do (
    if %%A==%TEMPTXT% (
        REM call PINemHi pipped to a txt file
        "%PINemHiPath%\pinemhi.exe" %TEMPTXT%.nv>"%PINemHiHS%\%TEMPTXT%.txt"
        )
    )
REM delete TXT files with size 0 as they are empty
for /f %%I in ("%PINemHiHS%\%TEMPTXT%.txt") do if %%~zI==0 del "%PINemHiHS%\%TEMPTXT%.txt"
GOTO PNG

:PNG
REM Call ImageMagick convert to create a PNG from the hiscore TXT file (note color, font and other options available)
REM Choose to size the resulting image based on the background file you use
REM if you'd like a monospaced output, add -font Courier
IF EXIST "%PINemHiHS%\%TEMPTXT%.txt" (
    type "%PINemHiHS%\%TEMPTXT%.txt" | "%ImageMagick%\convert.exe" -background none -fill yellow -pointsize 26 pango:@- -resize 570x730 "%PINemHiPNG%\%TEMPTXT%.png"
    )

REM Call ImageMagick composite to merge previous PNG with the background image, and center it
IF EXIST "%PINemHiPNG%\%TEMPTXT%.png" (
    "%ImageMagick%\composite.exe" "%PINemHiPNG%\%TEMPTXT%.png" "%PINemHiPNG%\%Background%" -gravity center "%OUTPUT%\%~2%Suffix%.png"
    REM Cleanup temp PNGs
    del "%PINemHiPNG%\%TEMPTXT%.png"
    )

REM done
exit /B

Note: the script is self-documented and could be modified as needed
Note: this script assumes Media for all VP versions are on the same folder. If this is not the case you can either modify the script or create different copies of the script for each system you have
Note: you NEED to define a few variables at the top of the script to fit your setup

5) On Popper, add this to the bottom of the VPX/9/PM5/FP close Script/s (make sure it runs after VP, and VPinMAME are closed):

REM Generate HiScore media file
"c:\Pinball\PinemHi\hiscore.bat" [?ROM?] "[GAMENAME]" "[?GAMETYPE?]"

Note: notice the use of double-quotes for [GAMENAME] and [?GAMETYPE?]

You then need to populate the following fields for each table using Game Manager:

- For VPinMAME tables: romname in lowercase (eg. “xenon” no quotes) in the ROM field
- For UltraDMD tables: “UltraDMD” (no quotes) in Game Type. Also CGNAME in the ROM field (list of CGNAME mappings below)
- For PostIT method used by EM and some VP Originals: high score filename (eg. “Prospector_77VPX.txt” no quotes). You can find the filename within the table script: look for :“Const HSFileName=“Prospector_77VPX.txt”). Some examples provided below
- For Future Pinball tables, just enter “BAM” (no quotes) in Game Type

Note: that there are a few different formats of the PostIT Notes high-score files. This script supports the latest format as of Nov-2018 (mostly VPX tables), and will not work as-is with older versions. The file contents look similar to this:

———————-
0
0
5
1
2
1
7500
7000
6000
5500
5000
AAA
ZZZ
XXX
ABC
BBB


Note: The script will add a suffix, if desired, to GAMENAME for the resulting PNG. Make sure you configure the MediaSearch field for your tables accordingly (example: GAMENAME* )

Useful SQL statements:

Set GameType value for all FP tables
UPDATE Games SET GameType= "BAM" where emuid=4

Optional:
If you want to batch create all the PNGs in one shot, you can create a batch file with the following format:

start hiscore.bat abv106 "Airborne (Capcom 1996)" SS
Timeout 0 /NOBREAK
start hiscore.bat acd_168h "ACDC nude (Stern 2012) Luci" DMD
Timeout 0 /NOBREAK
start hiscore.bat acd_168h "ACDC LE (Stern 2012) BiB" DMD
Timeout 0 /NOBREAK
start hiscore.bat acd_168h "FSS ACDC LE (Stern 2012) BiB" DMD
Timeout 0 /NOBREAK
start hiscore.bat acd_168h "ACDC LE (Stern 2012) LiBR" DMD
Timeout 0 /NOBREAK
start hiscore.bat acd_168h "ACDC LE (Stern 2012) Luci" DMD
Timeout 0 /NOBREAK
start hiscore.bat QuickDraw_75VPX.txt "Quick Draw (Gottlieb 1975)" EM
Timeout 0 /NOBREAK
start hiscore.bat RoadRace_69VPX.txt "Road Race (Gottlieb 1969)" EM
Timeout 0 /NOBREAK

Note: you can export the popper DB as a CSV file, import in excel and create this batch file in a minute
Note: you should still call the script when tables close to update the PNGs after each play session
Note: a batch process script like the above processed 832 tables in 2 minutes, generating 669 High-score PNGs on my setup

UltraDMD cgname mappings:

America's Most Haunted –
Champions League Argentina (Original 2018) – uefa_cl18
Champions League S17 (Original 2017) – uefa_cl17
Champions League S18 (Original 2018) – uefa_cl18
Copa libertadores (Original 2018) – uefa_cl
Diablo Pinball (Original 2017) – diablo
Ghostbusters JP (Original 2015) Slimer – slimer
Giana Sisters (Original 2018) –
Gradius (Original 2015) –
Halloween Michael Myers Pinball Adventures (Orignal 2018) – HalloweenMichaelMyers
Jaws FP (Original 2018) – JAWSHighScore
Kiss Premium (Stern 2015) – kiss_original_2016
Kratos God of War (Orignal 2018) –
Legend of Zelda (Original 2015) – ZELDA
Mad Scientist (Original 2017) – madscientist
Masters of the Universe (Original 2018) – MOTUHighScore
Metal Slug (Original 2015) – Metal Slug
Minions (Original 2014) – minions
Mortal Kombat (Original 2015) –
Mortal Kombat II (Original 2015) – Mortal Kombat II
Need for Speed (Original 2018) – Need4Speed
Pokemon Pinball JP (Original 2015) – Pokemon_Pinball
PUP Champions League S18 (Original 2018) – uefa_cl18
PUP Clue (Original 2018) – Clue
PUP Masters of the Universe (Original 2018) – MOTUHighScore
Ready player one (Original) – Ready player one
Serious Sam Pinball (Original 2017) – SeriousSam
Space Cadet (Original 2018) –
Stranger Things (Original 2017) – StrangerThings
Streets of Rage (Original 2018) – STLE
Terminator Salvation (Original 2018) – TerminatorSalvation
The Last of Us (Original 2018) –
The Web (Original 2015) – TheWeb
Three Angels (Orignal 2018) –
Twilight (Original 1993) – TwilightTWILIGHT
Ufo Robot Goldorak (Original 2017) – Goldorak
Ufo Robot Grendizer (Original 2017) – Goldorak
Wizard of Oz (JJP 2013) – WoZ
Young Frankenstein (Original 2015) –
Post-IT filenames:

2001 (Gottlieb 1971) – 2001_71VPX.txt
300 (Gottlieb 1975) – 300_75VPX.txt
Airport (Gottlieb 1969) – Airport_69VPX.txt
Aquarius (Gottlieb 1970) – Aquarius_70VPX.txt
Atlantis (Gottlieb 1975) – Atlantis_75VPX.txt
Bank Shot (Gottlieb 1976) – BankShot_76VPX.txt
Beat Time (Williams 1967) – BeatTime_67VPX.txt
Beat Time (Williams 1967) (Beatles MOD) – BeatTimeBeatles_67VPX.txt
Big Brave (Gottlieb 1974) – BigBrave_74VPX.txt
Big Casino (Gottlieb 1961) – BigCasino_61VPX.txt
Big Shot (Gottlieb 1973) – BigShot_74VPX.txt
Blue Note (Gottlieb 1979) – BlueNote_79VPX.txt
Bristol Hills (Gottlieb 1971) – BristolHills_70VPX.txt
Bronco (Gottlieb 1977) – Bronco_77VPX.txt
Buckaroo (Gottlieb 1965) – Buckaroo_65VPX.txt
Canada Dry (Gottlieb 1976) – CanadaDry_76VPX.txt
Capt. Card (Gottlieb 1974) – CaptCard_73_2VPX.txt
Card Trix (Gottlieb 1970) – CardTrix_70VPX.txt
Circus (Zaccaria 1977) – CircusZaccaria_77VPX.txt
College Queens (Gottlieb 1969) – CollegeQueens_69VPX.txt
Cow Poke (Gottlieb 1965) – CowPoke_65VPX.txt
Crescendo (Gottlieb 1970) – Crescendo_70VPX.txt
Dimension (Gottlieb 1971) – Dimension_71VPX.txt
Domino (Gottlieb 1968) – Domino_68VPX.txt
Drop-A-Card (Gottlieb 1971) – DropACard_71VPX.txt
Duotron (Gottlieb 1974) – Duotron_74VPX.txt
El Dorado (Gottlieb 1975) – El_Dorado_75VPX.txt
Far Out (Gottlieb 1974) – FarOut_74VPX.txt
Fast Draw (Gottlieb 1975) – FastDraw_75VPX.txt
Firecracker (Bally 1971) – Firecracker_71VPX.txt
Flip a Card (Gottlieb 1970) – FlipACard_70VPX.txt
Free Fall (Gottlieb 1974) – FreeFall_74VPX.txt
FSS Fast Draw (Gottlieb 1975) – FastDraw_75VPX.txt
Fun Land (Gottlieb 1968) – FunLand_68VPX.txt
Fun Park (Gottlieb 1968) – FunPark_68VPX.txt
Gigi (Gottlieb 1963) – Gigi_63VPX.txt
Gold Strike (Gottlieb 1975) – GoldStrike_75VPX.txt
Groovy (Gottlieb 1970) – Groovy_70VPX.txt
Hearts And Spades (Gottlieb 1969) – HeartsAndSpades_69VPX.txt
High Hand (Gottlieb 1973) – HighHand_73_2VPX.txt
Jack In The Box (Gottlieb 1973) – JackInTheBox_73_2VPX.txt
Jet Spin (Gottlieb 1977) – JetSpin_77VPX.txt
Jumping Jack (Gottlieb 1973) – JumpingJack_73_2VPX.txt
Jungle (Gottlieb 1972) – Jungle_72VPX.txt
King Kool (Gottlieb 1972) – KingKool_72VPX.txt
King Pin (Gottlieb 1973) – KingPin_73VPX.txt
King Rock (Gottlieb 1972) – KingRock_72VPX.txt
Kings and Queens (Gottlieb 1965) – KingsAndQueens_65VPX.txt
Lariat (Gottlieb 1969) – Lariat_69.txt
Lawman (Gottlieb 1971) – Lawman_71VPX.txt
Magnotron (Gottlieb 1974) – Magnotron_74VPX.txt
Melody (Gottlieb 1967) – Melody_67VPX.txt
Mibs (Gottlieb 1969) – MIBS_69VPX.txt
Mini Cycle (Gottlieb 1970) – MiniCycle_70VPX.txt
Mustang (Gottlieb 1977) – Mustang_77VPX.txt
Neptune (Gottlieb 1978) – Neptune_78VPX.txt
New York (Gottlieb 1976) – NewYork_76VPX.txt
NOTLD-68 (Original 2018) – NOTLD68VPX.txt
NOTLD-68 Grunge (Original 2018) – NOTLD68VPX.txt
Old Chicago (Bally 1975) – OldChicago_75VPX.txt
Orbit (Gottlieb 1971) – Orbit_71VPX.txt
Out Of Sight (Gottlieb 1974) – OutOfSight_74VPX.txt
Outer Space (Gottlieb 1972) – OuterSpace_72VPX.txt
Palace Guard (Gottlieb 1968) – PalaceGuard_70VPX.txt
Pin-Up (Gottlieb 1975) – PinUp_73VPX.txt
Pioneer (Gottlieb 1976) – Pioneer_76VPX.txt
PlayMates (Gottlieb 1968) – Playmates_68VPX.txt
Pop-A-Card (Gottlieb 1972) – PopACard_71VPX.txt
Pro Football (Gottlieb 1973) – ProFootball_73VPX.txt
Prospector (Sonic 1977) – Prospector_77VPX.txt
Quick Draw (Gottlieb 1975) – QuickDraw_75VPX.txt
Road Race (Gottlieb 1969) – RoadRace_69VPX.txt
Rock Star (Gottlieb 1978) – RockStar_79VPX.txt
Rocket III (Bally 1967) – RocketIII_67VPX.txt
Roller Coaster (Gottlieb 1971) – RollerCoaster_71VPX.txt
Royal Guard (Gottlieb 1968) – RoyalGuard_70VPX.txt
Sing Along (Gottlieb 1967) – SingAlong_67VPX.txt
Sky Jump (Gottlieb 1974) – SkyJump_74VPX.txt
Slick Chick (Gottlieb 1963) – SlickChick_63VPX.txt
Snow Derby (Gottlieb 1970) – SnowDerby_70VPX.txt
Snow Queen (Gottlieb 1970) – SnowQueen_70VPX.txt
Soccer (Gottlieb 1975) – Soccer_75VPX.txt
Solids N Stripes (Williams 1971) – SolidsNStripes_71VPX.txt
Spin Out (Gottlieb 1975) – SpinOut_75VPX.txt
Spin-A-Card (Gottlieb 1969) – SpinACard_69VPX.txt
Spirit of 76 (Gottlieb 1975) – SpiritOf76_75VPX.txt
Strange World (Gottlieb 1978) – StrangeWorld_78VPX.txt
Super Spin (Gottlieb 1977) – SuperSpin_77VPX.txt
Sure Shot (Gottlieb 1976) – SureShot_76VPX.txt
Surf Champ (Gottlieb 1976) – SurfChamp_76VPX.txt
Surfer (Gottlieb 1976) – Surfer_76VPX.txt
Target Alpha (Gottlieb 1976) – Target_Alpha_76VPX.txt
Top Card (Gottlieb 1974) – TopCard_74VPX.txt
Top Score (Gottlieb 1975) – TopScore_75VPX.txt
Volley (Gottlieb 1976) – Volley_76VPX.txt
Wild Life (Gottlieb 1972) – WildLife_72VPX.txt
Wild Wild West (Gottlieb 1969) – WildWildWest_69.txt
Zip-A-Doo (Bally 1970) – ZipADoo_70VPX.txt
Wrap:
This solution is provided AS-IS without support beyond this instructions page. Please put your mind into it and don't expect everything to work with a straight copy&paste. For further support, visit: ====

http://www.pinemhi.com/ for PINemHI
https://imagemagick.org/ for ImageMagick
https://stackoverflow.com/ for Windows scripting
http://www.nailbuster.com/wikipinup/doku.php?id=support| for Pinup PopperPopper
http://www.google.com for everything else

Still to do:
- HS for FX2/FX3 (high score files are encoded)
- HS for PROC (stored in \Games\gamename\config\game_user_data.yaml)
WIP - HS for UltraDMDtables
- Hiscores Stored in VPReg.stg. iStor file that could be read, but each game stores scores adn initials on files with no naming convention (nightmare)

Create info page for VP tables from IPDB

If you populate the IPDB number within Game Manager, the following code would create an info PNG file for each table based on IPDB's information (the file will be stored in the GameInfo folder). The file should be created only once, so you can run this as part of the launch or close scripts for the VP emulators. Make sure you modify the paths based on your setup

Requires curl ( https://curl.haxx.se/windows/ ) and wkhtmltopdf ( https://wkhtmltopdf.org/ ) to be installed.

REM Update IPDB and Hiscore info page info
IF NOT EXIST "[MEDIADIR]GameInfo\[GAMENAME]-07.png" (
     C:\Tools\curl\bin\curl https://www.ipdb.org/machine.cgi?id=[?IPDBNum?]>"[MEDIADIR]GameInfo\[GAMENAME].html"
     C:\Tools\wkhtmltox\bin\wkhtmltoimage --crop-h 2068 "[MEDIADIR]GameInfo\[GAMENAME].html" "[MEDIADIR]GameInfo\[GAMENAME]-07.png"
     del "[MEDIADIR]GameInfo\[GAMENAME].html"
 )