Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: coffeesoft on October 21, 2017, 06:45:04 am

Title: Execute EXE file on computer while playing
Post by: coffeesoft on October 21, 2017, 06:45:04 am

 Hi, i wanted to ask if someone knows if is possible to execute a EXE file stored on the computer while playing, for example when a enemy arrives or whatever.

Thanks.
Title: Re: Execute EXE file on computer while playing
Post by: The E on October 21, 2017, 07:48:31 am
Before I answer this, let me ask: What do you want to do?
Title: Re: Execute EXE file on computer while playing
Post by: coffeesoft on October 21, 2017, 08:32:26 am

 I want to use AutoHotKey and run some scripts to turn on lights, display messages... for example.

I learned to program this tool a little and wanted to do some testing if possible  :)
Title: Re: Execute EXE file on computer while playing
Post by: The E on October 21, 2017, 08:34:58 am
Ah. That seems much more reasonable than what I feared you wanted to do :)

The answer is simple. Just use
Code: [Select]
os.execute("Your command here")
Title: Re: Execute EXE file on computer while playing
Post by: coffeesoft on October 21, 2017, 10:51:22 am

 Thanks   :p

Questions.

- Where i put the EXE file, inside mod folder ?

- Wich OS command i must use to launch the file ?


Something like that would work ?

Code: [Select]
#Conditional Hooks
$Version: 3.7
$On Game Init:

Graphics.setColor(255, 255, 255)
Graphics.drawString("Running EXE !", 5, 10)

os.execute("Script1.exe")

]
+Override: YES
#End


Title: Re: Execute EXE file on computer while playing
Post by: m!m on October 21, 2017, 11:14:50 am
The answer is simple. Just use
Code: [Select]
os.execute("Your command here")
Unfortunately, that will not work. FSO disables that command for security reasons but I guess a command line option could be added to allow using those functions.
Title: Re: Execute EXE file on computer while playing
Post by: The E on October 21, 2017, 11:23:47 am
Right.
Title: Re: Execute EXE file on computer while playing
Post by: AdmiralRalwood on October 21, 2017, 11:59:59 am
Why can't you just have an autohotkey script running concurrently that detects something scripts can do?
Title: Re: Execute EXE file on computer while playing
Post by: coffeesoft on October 21, 2017, 04:28:55 pm
Quote
Unfortunately, that will not work. FSO disables that command for security reasons but I guess a command line option could be added to allow using those functions.

:(  out of curiosity, wich reasons ?, i mean, Can we format our HDs while playing ?  :D


Quote
Why can't you just have an autohotkey script running concurrently that detects something scripts can do?

I don´t know how to communicate both scripts, my knowledge about this is very limited....
Title: Re: Execute EXE file on computer while playing
Post by: jr2 on October 22, 2017, 12:26:48 am
Can't you pass messages to scripts somehow?  I mean, a quick Google turned up this (topic is Lua scripting and AHK):  https://autohotkey.com/board/topic/6894-running-another-program-then-retrieving-a-value/

At the worst, maybe you could alter the contents of the file, and have AHK poll that file?

But I think the other guys here will have much better ways of implementing whatever you're wanting to accomplish.
Title: Re: Execute EXE file on computer while playing
Post by: coffeesoft on October 22, 2017, 03:01:53 am

 I don't know if I understood correctly

 - Can FSO store some data of the mission in a custom txt file ?, for example, wing 1 arrives = true or false

So we could read those data with AHK
Title: Re: Execute EXE file on computer while playing
Post by: Phantom Hoover on October 22, 2017, 11:54:26 am
Quote
Unfortunately, that will not work. FSO disables that command for security reasons but I guess a command line option could be added to allow using those functions.

:(  out of curiosity, wich reasons ?, i mean, Can we format our HDs while playing ?  :D

If you can execute outside executables from within a game's code, you basically own the player's computer. It's that simple. It's a big security hole.
Title: Re: Execute EXE file on computer while playing
Post by: m!m on October 22, 2017, 12:29:41 pm
To be honest, FSO is not written with security in mind. I'm pretty sure that you could find a lot of possible attacks even without using scripts but a script is a very easy attack so we might as well try to reduce the attack surface by restricting what a script can do.
Title: Re: Execute EXE file on computer while playing
Post by: The E on October 22, 2017, 12:41:25 pm
Plus, the people who have used scripting to address other things external to FSO have used TCP/IP or other mechanisms to achieve their goals.
Title: Re: Execute EXE file on computer while playing
Post by: jr2 on October 23, 2017, 08:37:44 am

 I don't know if I understood correctly

 - Can FSO store some data of the mission in a custom txt file ?, for example, wing 1 arrives = true or false

So we could read those data with AHK

I don't know, someone else will have to answer that.
Title: Re: Execute EXE file on computer while playing
Post by: coffeesoft on October 23, 2017, 09:40:23 am
Quote
I don't know, someone else will have to answer that.

Would be great, i know how to read data of a txt file with AHK.
Title: Re: Execute EXE file on computer while playing
Post by: jr2 on October 23, 2017, 12:52:18 pm
Quote
I don't know, someone else will have to answer that.

Would be great, i know how to read data of a txt file with AHK.

If you can tell us what the purpose is, there might be a better way around it through scripting or something.  I'm assuming you're making a mod of some type?  Just tell us what exactly you're attempting to do, or PM a scripting guru (ask who to PM) if you want to keep it secret until launch.  Or you could ask on the HLP Discord server (https://is.gd/I73Mr9) (you don't have to install anything if you really don't want to, it will load in a browser just fine).
Title: Re: Execute EXE file on computer while playing
Post by: coffeesoft on October 24, 2017, 04:23:55 am

I have no problem to explain my purposes  :)

In a first time, I thought the content of the EXE was not relevant to the question.

I like to play with the script of PoDo, i mean using a secondary computer to visualize the data of the game, that allows you to remove almost everything from the main screen, plus playing with three displays, gives us a great space of vision and a nice feeling.

I'm interested in switch on-off real lights together with the PoDo script, but my knowledge of programming is really limited, Arduino is "easy" to program, a nice option, but i don´t know how to FSO and Arduino can talk.

Actually there is not much progress on that scripts, so I wanted to try other ways, and is the reason that i want to try with AutoHotKey, because i learned a bit how to program.

My idea was to do some tests, when  I get some data from FSO and launch an EXE.

I hope it is more or less well explained, sorry about my poor english  :p
Title: Re: Execute EXE file on computer while playing
Post by: mjn.mixael on October 26, 2017, 01:40:35 pm

 I don't know if I understood correctly

 - Can FSO store some data of the mission in a custom txt file ?, for example, wing 1 arrives = true or false

So we could read those data with AHK

I don't know, someone else will have to answer that.

Yes, FSO scripts can write text files. How do you think the checkpoint script works? :) I even used the ability to open/write text files to hide/unlock bonus missions in BtA.
Title: Re: Execute EXE file on computer while playing
Post by: coffeesoft on October 26, 2017, 03:40:13 pm
Quote
Unfortunately, that will not work. FSO disables that command for security reasons but I guess a command line option could be added to allow using those functions.

It would be great  :nod:

Quote
Yes, FSO scripts can write text files. How do you think the checkpoint script works? :) I even used the ability to open/write text files to hide/unlock bonus missions in BtA.

Can you point me in the right direction ?, some example ?