66ee323c2cd14

66ee323c2d666
1 Guest is here.
 

66ee323c2dcbcNull1233

66ee323c2dd33
I am trying to open ss2 with a python script and then have that python script communicate to a squirrel script.  I don't know how possible this is, but to even test it I need squirrel to have access to stdin and stdout.  According to online http://squirrel-lang.org/squirreldoc/stdlib/stdiolib.html these should be file objects I can use to read and write from the streams.  If I try to reference them I get a "the index 'stdin' does not exist" error.  Anyone know how to get access to the stdin and stdout streams or if it is just straight impossible?

66ee323c2df0aZylonBane

66ee323c2df5c
Squirrel is implemented in Dark as a script module, and as such its interaction with the host exe is constrained to the scripting API. This API does not include retrieving any strings hurled at Dark's process, of course. Why on earth would it?

This code will verify that none of the standard streams are implemented in Dark Squirrel:
Code: [Select]
print("stdin" in getroottable());
print("stdout" in getroottable());
print("stderr" in getroottable());
This will output false, false, and false. The print() and error() functions appear to have been internally rewired to output to the mono window instead of stdout and stderr.

Your best bet for passing external data to Dark would probably be via a file. See the section "Accessing files from script modules (OSMs)" in script_notes.txt.

Note that it appears to be impossible to create/write files via Squirrel. This is likely intentional, since it could be used for all sorts of mischief by malicious mod authors.

66ee323c2e045Null1233

66ee323c2e092
Yeah that makes sense, thanks for confirming that stdin/out just won't work.

I tried to write to files earlier and just thought I was doing something wrong, good to know it just can't.  So I can read data into squirrel through files.  But then what are my routes, if any, for squirrel to send data out in a way that my Python script can receive it?

66ee323c2e2b6sarge945

66ee323c2e309
What exactly are you trying to actually do?

66ee323c2e555ZylonBane

66ee323c2e5a9
But then what are my routes, if any, for squirrel to send data out in a way that my Python script can receive it?
None. I think it's safe to say that inter-process communication was not a consideration in NewDark's Squirrel implementation.

66ee323c2e737Null1233

66ee323c2e789
I am trying to add SS2 to the multi-game randomizer archipelago and this is the last thing I have to learn, test, and get working before I can get started building this thing. https://archipelago.gg/

Since files work for getting information in, all I need is to get ss2 to send out ints.  So if Squirrel can't do that, is there some other way I could, even if incredibly hacky?  I am going to replace most pick uppable objects with the same object that destroys itself when picked up, each one has a unique location id that needs to get to the python script in some way when that object is picked up.

66ee323c2e918ZylonBane

66ee323c2e966
Well, there's the Debug.Log() command, which can add any arbitrary string to ss2.log. Though it seems to be slightly unpredictable how often the output buffer is flushed.

If you look in new_commands.txt, there are a few console commands that generate files. Pretty much all of them dump info to a hard-coded filename, or the info itself isn't customizable. Performance stats, internal data structures, that sort of thing.

However, the command dump_cmds for some reason accepts a filename. It's normally intended to be run from within DromEd, but scripts can execute it too. Squirrel does it like so:
Code: [Select]
Debug.Command("dump_cmds", "filename.txt");The generated file ends up in the install root. The filename can be any valid Windows filename, so one could encode a decent amount of information in the filename itself. Then you just set up Python to watch the root folder for new files being created, then scan for files that start with a unique prefix ("pydat" or whatever). Parse the data from the filename then delete the file.

Windows has a maximum path + filename length of 256 characters, so the amount of data that can be safely packed into a filename is somewhat limited.

66ee323c2ea79Null1233

66ee323c2eac9
That is perfect!  Tested in editor and in game and it is doing exactly what I need it to.  Thank you so much, within everything I have been testing I have been coming back to this issue repeatedly and being worried about it so this is a lot of stress gone.

Also if you come back to this thread sarge945 I wanted to mention I appreciate all of your mods, they have been my greatest learning resource for ways to implement all the features I want and how to avoid and fix the pitfalls associated with those features.  And my playthrough of your randomizer mod was quite fun!

66ee323c2ecb6Nameless Voice

66ee323c2ed03
You could also write a C++ script module to do what you want.
They're basically DLLs and can do pretty much anything.

66ee323c2ef5fsarge945

66ee323c2efc0
You could also write a C++ script module to do what you want.
They're basically DLLs and can do pretty much anything.

Pretty much anything?

Is there much in the way of documentation for this? I had a look around for OSM documentation and couldn't find a whole lot in the ss2 folder.

I have been wanting to make a restricted saving mod for years now, and it's impossible with Squirrel because saving is deeply hardcoded into the engine. Would a custom C++ script module be able to accomplish that?

66ee323c2f0eeNameless Voice

66ee323c2f13c
They're primarily object scripts, they only have access to the parts of the engine that the script services expose, plus the console commands.

But they're also C++ code, so if you really really want to, you could do memory injection or similar to hack the game as it's running.
Reading and writing to disks, sockets, or pipes would also be no problem.

Telliamed's public scripts are open source, as is NVScript - you can study those to see how to make your own script modules.

66ee323c2f1c8sarge945

66ee323c2f213
now if only I could figure out memory injection...

66ee323c2f2a1Nameless Voice

66ee323c2f2ee
That was really more of a "you theoretically could" rather than "you should".

66ee323c2f3b3sarge945

66ee323c2f402
I've been meaning to learn about memory injection anyway. Got a few other projects I want to do.

But I agree, memory injection kinda sucks. At least SS2 is pretty stable as a game (in terms of updates) so the chances of having stuff break through modified executables is minimal.

Your name:
This box must be left blank:

How can you ____ a perfect, immortal machine? (Fill in the missing word):
1 Guest is here.
“Is this a crime?”
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
66ee323c329c7