Unreal.js icon indicating copy to clipboard operation
Unreal.js copied to clipboard

[Question] Use this as ingame scripting?

Open Uniphix opened this issue 2 years ago • 9 comments

Could this be used as ingame scripting? Is there a way to restrict and expose certain things that can only be done say on a ingame computer?

Basically I want to be able to design an ingame computer that can run multiple applications but limited to game functionality as I would be concerned for security as this would be used in a MP world. Don't want unwanted functions that could hurt the players actual computer as the entire UE Api is excused from my understanding?

Uniphix avatar Apr 19 '23 14:04 Uniphix

You can runtime reload a JavaScript file allowing you to write scripts and execute them at game time even in a packaged game (see https://github.com/ncsoft/Unreal.js/issues/46#issuecomment-196876459).

Regarding safety, by default the whole UE api gets exposed, but if you go lower in the API you can control what gets exposed. In a fork of this plugin I made a new js component type using the lower api that can control this exposure (https://github.com/getnamo/Unrealjs#javascriptinstance and see https://github.com/ncsoft/Unreal.js/issues/259#issuecomment-776288832 for api notes).

getnamo avatar Apr 20 '23 05:04 getnamo

Thanks for the reply! So basically I would just use something like what you suggested and only expose what I want?

Uniphix avatar Apr 20 '23 06:04 Uniphix

It hasn't been tested heavily for robustness of safety for partial expose (e.g. root JavaScript component only), but in theory that's how it should work. Also if you expose no unreal objects, it will just be a vanilla script with no access to anything outside its scope.

Edit: this appears to be the c++ code that handles the common expose api: https://github.com/getnamo/UnrealJs/blob/master/Source/V8/Private/JavascriptInstanceComponent.cpp#L86

Looks like 'Context' or 'JsOwner' is likely the one you want to try first. This should only expose e.g. the functions on the owning actor which you can control.

getnamo avatar Apr 20 '23 07:04 getnamo

Perfect thanks! Yeah I don't want to expose any of the UE stuff and if I do it'll be a wrapper to expose only what needed...

Uniphix avatar Apr 20 '23 07:04 Uniphix

Do you have a version that works for 4.27.2? For some reason I have spent over 5 hours trying to get the plugin built and keep getting failures.

Uniphix avatar Apr 20 '23 10:04 Uniphix

I tried to use the build the plugin steps but it just doesn't want to do it's work everytime I try to build from the modules it fails, and manual compiling works but still prompt to ask. Am I missing something? Do I need to add anything else?

Uniphix avatar Apr 20 '23 16:04 Uniphix

If you cloned from git you need the V8 third party dependencies, or just download a release which should have them.

getnamo avatar Apr 20 '23 17:04 getnamo

Yeah but so far I am finding anything that works with 4.27

Uniphix avatar Apr 20 '23 17:04 Uniphix

@getnamo thanks for the guidance, I was able to do several things, I basically took your copy of your branch, and then basically went through all the changes by comparing against a specific branch of UnrealJS-core that was closest to 4.27 (4.26 is what I used) and then found what changed between UE4.26 to 4.27 and what changed between 4.27 to 5.1 and thus got it all compiled!

For those who may run into situations, if it doesn't build the modules, it's probably because there are compiling errors when using a specific version, in my case I was using 5.1 and was trying to build it against 4.27 (IT DID NOT LIKE THAT LOL). There was quite a bit of changes such as FEditorStyle was changed to FAppStyle in 5.1.

Uniphix avatar Apr 21 '23 16:04 Uniphix