67311fd85aeff

67311fd85c905
1 Guest is here.
 

67311fd85cedeNull1233

67311fd85cf56
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?

67311fd85d14fZylonBane

67311fd85d19e
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.

67311fd85d292Null1233

67311fd85d2e0
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?

67311fd85d502sarge945

67311fd85d559
What exactly are you trying to actually do?

67311fd85d7acZylonBane

67311fd85d80c
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.

67311fd85d9d5Null1233

67311fd85da31
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.

67311fd85dbf2ZylonBane

67311fd85dc47
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.

67311fd85dd84Null1233

67311fd85dde6
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!

67311fd85e034Nameless Voice

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

67311fd85e323sarge945

67311fd85e38c
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?

67311fd85e4f0Nameless Voice

67311fd85e550
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.

67311fd85e621sarge945

67311fd85e67c
now if only I could figure out memory injection...

67311fd85e73bNameless Voice

67311fd85e7d6
That was really more of a "you theoretically could" rather than "you should".

67311fd85e8afsarge945

67311fd85e903
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):
1 Guest is here.
What should we do, Santa? C'mon, rack your fat brain!
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
67311fd85f4bf