66ee374fdff05

66ee374fe0780
4 Guests are here.
 

66ee374fe0dfaNull1233

66ee374fe0e63
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?

66ee374fe1052ZylonBane

66ee374fe10ab
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.

66ee374fe1198Null1233

66ee374fe11e7
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?

66ee374fe146csarge945

66ee374fe14c2
What exactly are you trying to actually do?

66ee374fe176fZylonBane

66ee374fe17c4
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.

66ee374fe194fNull1233

66ee374fe19a4
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.

66ee374fe1b59ZylonBane

66ee374fe1baa
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.

66ee374fe1cbeNull1233

66ee374fe1d0d
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!

66ee374fe1f03Nameless Voice

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

66ee374fe21ecsarge945

66ee374fe2245
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?

66ee374fe23c8Nameless Voice

66ee374fe241b
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.

66ee374fe24cfsarge945

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

66ee374fe25bfNameless Voice

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

66ee374fe26d3sarge945

66ee374fe2724
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 challenge a ____, immortal machine? (Fill in the missing word):
4 Guests are here.
Once upon a lifetime, I died a pioneer, Now I sing within a spaceship's heart, Does anybody hear?
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
66ee374fe3717