Is there a way to call the serialization/deserialization from C++ to string?
In api_usage_example/Source.cpp it looks like it is looking up the handles to the function calls provided to the Papyrus interface. I am not seeing a way to directly call the serialization functions.
I would like to use this plugin to serialize JSON data to be sent over a network connection. So I need byte access to the resulting JSON data. Right now the API reads and writes to file. Is there currently a way to get serialize to a string in the API? I cannot find one.
@Demolishun Hi there! Sounds like an interesting project you have. Well, I can add such a method
@SilverIce Hello! I wrote this plugin for OBSE a while back: https://github.com/Demolishun/NetworkPipeOBSE It basically gave the ability to pass JSON to and from the scripting environment to an external program. The plugin itself was threaded and provided a port for external apps to connect to. I am finally getting around to modding skyrim and wanted to recreate the plugin. I would love to have mods that allow you to journal in game and have it post on a webpage, or store data in a database for some interaction. Maybe even a chat interface between people.
Anyway, I would want 2 methods: one method would serialize the json from your data structure and return a byte array containing the data, the other method would take a byte array and populate your json scripting object. I am writing the plugin in c++ so I am not sure what form the functions should take. To keep from reinventing the wheel I would like to attach to your plugin through my plugin like your example shows.
What do you need from me? Also, what encoding is the serialized data in? UTF8?
Yeah, the data is encoded into utf-8 string. I can add something like JValue.toJSONString and JValue.fromJSONString.
PS Would love to have some integration between Skyrim and my kettle :D
"Skyrim and my kettle" That would be an awesome example project to include in the plugin! Definitely a must do.
You can try this one - JContainers.3.3.0.zip.
There are JValue.objectFromPrototype (it's been there for years and it parses a string) and JValue.toJSONString.
I am writing the plugin in c++ so I am not sure what form the functions should take.
The definitions should look like:
// context is a domain pointer. Pass NULL since more likely you'll use the default one.
BSFixedString(*JValue_toString)(void* context, SInt32 jc_object_handle, SInt32 json_format_indent) = nullptr;
SInt32(*JValue_objectFromPrototype)(void* context, BSFixedString input_string) = nullptr;
I'm a bit concerned, as Skyrim string may have length limit - and my C API returns methods adapted to Skyrim
In regards of kettles - https://github.com/NARKOZ/hacker-scripts/blob/master/README.md
@Demolishun any news?
@SilverIce I modified my plugin to use your JValue_toString and JValue_objectFromPrototype. I get an assert when it checks the function for JValue_toString. If I comment it out it just keeps skyrim from starting. I included jc_interface.h into the project. Do I need more than that in the project? I noticed when adding jc_interface.cpp it wanted to include a lot more things. I also noticed jc_interface.cpp fleshes out the stuff in jc_interface.h. I was going to test with your plugin example next to try and see what I am doing wrong. Also, does the plugin need to be compiled in release mode?
I get an assert when it checks the function for JValue_toString
What assert? I haven't tested as I don't have Skyrim installed ATM
I included jc_interface.h into the project. Do I need more than that in the project? I noticed when adding jc_interface.cpp it wanted to include a lot more things.
No, you need to have jc_interface.h only.
Also, does the plugin need to be compiled in release mode?
Well, it shouldn't matter
@Demolishun That was a mistake. I absolutely forgot that you HAVE to get a pointer to the default JC domain/context (like in the example) and pass it as a first argument of JValue_toString, JValue_objectFromPrototype. It can't be null
void* default_domain = root->query_interface<jc::domain_interface>()->get_default_domain();
I am having trouble getting the example plugin to work. I built it using VS 2013 VC++. I copied the example plugin into the plugins directory of SKSE. When I run skyrim without any mods that use the plugin, it won't ever load skyrim. It spins up the exe, but it sits there and never brings up the main menu. I have to kill the process. Then if I start without the plugin it starts up and loads to the main menu. This is using the example plugin from the JContainers repo. I have not made changes to it yet.
I am loading JContainers (the version you linked above) using Mod Organizer. The example plugin is copied directly to the skyrim/skse/plugins directory. I tried both release and debug versions.
@Demolishun , there were several issues. It wasn't OK to publish C API (and use C++ thread-related functions) from DllMain. Also folder structure in the prev. archive weren't proper
TLDR
Here is the fixed and working version (the new function renamed to JValue.toString):
JContainers.3.3.0.zip
I did test the plugin and it seems to be getting the pointers now. I will let you know what my testing shows for string size. If its big enough I will just document the size and live with it. I will do some sort of test that exercises this to make it easy to see what is going on. I am working on the plugin structure and deciding what functions to include. I also need to get my head around the threading part of papyrus to decide if I need to create my own thread or not.
@Demolishun that's good news! I heard (not proven) that Skyrim string length may have a limit like 4kb
@Demolishun, the functions, you'll register in Papyrus can be called in undefined way (i.e. amount of Papyrus threads is unknown, call order is unknown and so on). These methods had to be thread-safe
@Demolishun , also you may with to focus on Skyrim SE (since SE modding scene can be more active than Oldrim), and maybe talk to @ryobg
@SilverIce The mods I want to run are in oldrim.
I have tested creating a thread for a udp server this weekend. It did a loop back test. The next test will be something responding in the scripting. During that test I will be testing string sizes and exercising your functions. I have not done any skyrim scripting so it will take a bit to get my head around it all.
@Demolishun , I may even imagine functionality in user mods like downloading mod's JSON data from a server in order to update the mod, or retrieving dX dY dZ data from miBand to turn camera with a gesture, or syncing real weather with Skyrim..
Feel free to ask about scripting
@SilverIce I really like these ideas. I am thinking I need to make it so the scripts can create multiple services. I am going to stick with UDP, but allow multiple independent ports to be opened. That way each mod can create their own protocol to talk to an external process.
I have not thought of allowing skyrim to act as a client. I mainly have wanted it to act as a server on a local port, then have external processes do whatever they want. In the OBSE version I have mechanisms for launching external apps/scripts to make it all self contained in a mod. Python is my goto for scripts so examples will be using that. I don't think it is unreasonable for end users to download python. I mean some mods require java to do their config.
The mods I want to run are in oldrim.
@Demolishun, Are you going to modify some existing mods?
@SilverIce probably not. I do want a journal mod though. One I can enter a journal and it will get pushed to a file/website. Maybe a local git account that gets pushed periodically. Mostly I want the challenge and the fun. If someone wants it on SE I will help make that too. I just don't run SE.