Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: alucard on March 01, 2021, 01:01:52 PM

Title: Launch Decorator plugin
Post by: alucard on March 01, 2021, 01:01:52 PM
Hi All,
I wrote a plugin to execute script before and/or after game execution.

LaunchDecorator has configurable ScriptRoot (and extensions) and follows convention
over configuration approach to find and run scripts

ScriptRoot
ʉӣ + emulator name
 â”ƒ â”— -- before.{script extension}
 â”ƒ â”— -- after.{script extension}
 â”ƒ â”— ...
 â”ƒ â”— -- before.{game name}.{script extension}
 â”ƒ â”— -- after.{game name}.{script extension}
 â”ƒ â”— ...
 â”ƒ
ʉӣ + another emulator name
ʉӣ +..

All ScriptRoot child elements are optional and script extensions can be mixed.

Plugin and instructions can be found here:
https://github.com/matteocedroni/am-launch-decorator-plugin (https://github.com/matteocedroni/am-launch-decorator-plugin)
Title: Re: Launch Decorator plugin
Post by: manzarek on March 02, 2021, 08:06:01 AM
Then I create a folder in AT with the name ScriptRoot
inside I create a folder with the name Mame and inside I put the file created bat to open a video, before.bat

Code: [Select]
@echo off
start "vlc" "H:\attract-v2.6.1\ScriptRoot\mame\logo_open.mp4"
exit

when I launch any mame game, the video opens, but then AT freezes, without the game being started after the video, what am I wrong?
Title: Re: Launch Decorator plugin
Post by: alucard on March 02, 2021, 10:14:11 AM
Interesting.

I can investigate but probably it's a windows focus problem.

This particular kind of script runs action that cause AttractMode lose focus. AttractMode can lose focus only after game is launched.

Your needs seems a sort of Fade To/From Game function. A function strictly performed by AttractMode while keeping focus.
FadeToGame plugin exists, but current version doesn't play video.
Title: Re: Launch Decorator plugin
Post by: ReBirFh on March 02, 2021, 11:29:16 AM
Sounds useful, can you give some practical examples/use cases?
Title: Re: Launch Decorator plugin
Post by: manzarek on March 02, 2021, 12:35:45 PM
Your needs seems a sort of Fade To/From Game function. A function strictly performed by AttractMode while keeping focus.
FadeToGame plugin exists, but current version doesn't play video.
Exactly I wanted to use it for this purpose, a kind of video loading of games.
Title: Re: Launch Decorator plugin
Post by: ReBirFh on March 02, 2021, 12:53:59 PM
Your needs seems a sort of Fade To/From Game function. A function strictly performed by AttractMode while keeping focus.
FadeToGame plugin exists, but current version doesn't play video.
Exactly I wanted to use it for this purpose, a kind of video loading of games.

This seems to be one of the most wanted thing in a Brazilian AM group I'm part of.  People hate to see comand line and/or the emulator loading when starting a game, they want a seamless transition from AM to game
Title: Re: Launch Decorator plugin
Post by: hermine.potter on March 03, 2021, 03:08:03 AM
nice idea and work.
Have tried do to something similar here (http://forum.attractmode.org/index.php?topic=555.msg25163#msg25163)

I'm trying to start JoyToKey with profile load before and close after with your plugin:

this batch content starts before:
Code: [Select]
@echo off
start "" "C:\attract\JoyToKey\JoyToKey.exe" "C:\attract\JoyToKey\ZSNES.cfg"
exit

but if i try this batch content after, AM stucks and crash:
Code: [Select]
@echo off
taskkill /F /IM "JoyToKey.exe"
exit

I think it crashes because of commandline popup, if taskkill starts.
do you have an idea to solve focus problem?
Title: Re: Launch Decorator plugin
Post by: alucard on March 03, 2021, 03:47:30 AM
Quote
I think it crashes because of commandline popup, if taskkill starts.
do you have an idea to solve focus problem?

Popups, windows and interactive actions outside Attract-Mode must be avoided before/after game.

So you can try to hide taskkill

Anyway, I'll try some possible fix to reduce lost focus occurrence
Title: Re: Launch Decorator plugin
Post by: hermine.potter on March 03, 2021, 01:20:46 PM
all already tried before posting (autoit, vbs, /min command).
even invisible compiled bat2exe ^-^

then I have used the plugins from here (http://forum.attractmode.org/index.php?topic=555.msg25163#msg25163) again (based on ResFix.nut Plugin).

was able to start before:
Code: [Select]
system( "start /MIN \"\" \"C:\\attract\\JoyToKey\\JoyToKey.exe\" \"C:\\attract\\JoyToKey\\ZSNES.cfg\"" );
or
system( "start /MIN \"\" \"C:\\attract\\JoyToKey\\JoyToKey.exe\" \"C:\\attract\\JoyToKey\\" + fe.game_info( Info.Emulator )+ ".cfg\"" );
or
system( "\"C:\\attract\\scripts\\" + fe.game_info( Info.Emulator )+ "\\before.bat\"" );

and after:
Code: [Select]
system( "taskkill /F /IM JoyToKey.exe" );
or
system( "\"C:\\attract\\scripts\\" + fe.game_info( Info.Emulator )+ "\\after.bat\"" );

it works with focus, popups, no AM crash.
so there is something in ResFix.nut Plugin, that handle the correct focus?!
squirrel language is not my favourite and I'm not a squirrel expert ^-^
Title: Re: Launch Decorator plugin
Post by: alucard on March 04, 2021, 01:15:01 AM
Ok,

so system function may be the solution  :D

I have attached a modified version of plugin.nut, using system function instead of fe_plugin_command.

Can you try if this fixes focus problem?

Thanks
Title: Re: Launch Decorator plugin
Post by: hermine.potter on March 05, 2021, 12:33:29 AM
thank you for programming. works perfect.
very good work.

often its necessary to start programs before and close them after.

the script/plugin now expand AM with an important feature ^-^
Title: Re: Launch Decorator plugin
Post by: manzarek on March 05, 2021, 10:55:43 AM
works perfect. :D
Anyone know what is the syntax to close the video? i tried this but it doesn't work

after:
Code: [Select]
@echo off
taskkill /F /IM "logo_open.mp4"
exit
Title: Re: Launch Decorator plugin
Post by: alucard on March 06, 2021, 02:14:54 AM
Quote
Anyone know what is the syntax to close the video? i tried this but it doesn't work

I don't think you can close the video killing it directly, but you can kill VLC

Code: [Select]
taskkill /F /IM "vlc.exe"
If you want to make VLC automatically quits itself after playing video, you can modify launch command to

Code: [Select]
start "vlc" "H:\attract-v2.6.1\ScriptRoot\mame\logo_open.mp4" "vlc://quit"
Title: Re: Launch Decorator plugin
Post by: manzarek on March 06, 2021, 02:24:30 AM
Thanks I'll try. :)