66ee36b3093ee

66ee36b309d33
3 Guests are here.
 

66ee36b30c1f0Null1233

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

66ee36b30c43fZylonBane

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

66ee36b30c59eNull1233

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

66ee36b30c92asarge945

66ee36b30c982
What exactly are you trying to actually do?

66ee36b30ccacZylonBane

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

66ee36b30ce83Null1233

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

66ee36b30d057ZylonBane

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

66ee36b30d19dNull1233

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

66ee36b30d3f1Nameless Voice

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

66ee36b30d745sarge945

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

66ee36b30d8d4Nameless Voice

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

66ee36b30d9cbsarge945

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

66ee36b30daaeNameless Voice

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

66ee36b30dbc6sarge945

66ee36b30dc17
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 ____ of meat and bone!  (Fill in the missing word):
3 Guests are here.
“a cold, grim place”
Contact SMF 2.0.19 | SMF © 2016, Simple Machines | Terms and Policies
FEEP
66ee36b30ed34