66ee383ac1c79

66ee383ac2712
1 Guest is here.
 

66ee383ac2d59Null1233

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

66ee383ac2fa9ZylonBane

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

66ee383ac3107Null1233

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

66ee383ac33b6sarge945

66ee383ac340e
What exactly are you trying to actually do?

66ee383ac365aZylonBane

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

66ee383ac382cNull1233

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

66ee383ac3a00ZylonBane

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

66ee383ac3b3bNull1233

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

66ee383ac3d5cNameless Voice

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

66ee383ac4117sarge945

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

66ee383ac42b1Nameless Voice

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

66ee383ac439dsarge945

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

66ee383ac44cbNameless Voice

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

66ee383ac466bsarge945

66ee383ac46ba
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:

Look at you, hacker: a pathetic creature of meat and ____!  (Fill in the missing word):
1 Guest is here.
Kirschblüten und Neonreklamen
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
66ee383ac558f