Modding Options

So for modding support, I’m running the options through my head.

1. Mono dynamic code generation
? Mono/.NET allows to compile code from within code, via the Code DOM compiler
? so the idea is to let modders create C# code and the game will compile those
? compilation results in either a compiled DLL file which will be loaded, or stored in memory. if you don’t save it as a DLL, you’d need to recompile the user’s C# file every time the game is run (not really a problem)
+ possible to let end-users create C# code, code that will run just as fast as the C# code in the game
– potentially allows end-users to cheat the single-player game by editing values or forcing commands on the game, similar to Game Genie
– potentially encourages end-users to share DLL files to each other, an avenue for a security breach on a user’s PC
– won’t work on web or mobile versions as they are sandboxed environments that do not allow compiling during runtime

2. KopiLuaInterface
? a Lua interpreter written purely in C#
? modders will make Lua scripts
+ a completely sandboxed environment, users will not be able to write malicious code
+ will work on web versions
+ will also work on mobile versions

– running a Lua script is slower than running a C# script. even slower since KopiLua is slower than the standard Lua1

3. LuaJIT + LuaInterface
? Unity (via Mono) can load a DLL of compiled C/C++ code (native code)
? modders will make Lua scripts
+ a completely sandboxed environment, users will not be able to write malicious code
+ runs faster than KopiLuaInterface, even faster than standard Lua with Just-In-Time compiling
+ can work on mobile versions with a little extra work
– will not work in web builds as they are sandboxed environments that do not allow loading of native DLLs
– works only on Unity Pro
– running a Lua script is slower than running a C# script1

LuaJIT is a no-go only because I have no Unity Pro.

Mono is the fastest for this situation, but it also has more potential to create malicious code. I’m only targeting Windows standalone so a web or mobile version is irrelevant for the moment. But if I ever decide later on to move some stuff into web/mobile, then mods made in C# won’t work, and that’s a loss.

So I’m going to use KopiLuaInterface for mod scripts.

When I get Pro, it’ll finally be possible for me to load native DLLs. It will likely be possible to convert what I have to use LuaJIT instead, at least, when making the standalone/mobile version of the game. If ever a web build is released, it would just fallback to using KopiLua. The nice thing is end-users’ Lua scripts will work regardless if the game is using LuaJIT or KopiLua.


1: The speed difference between Lua and C# should largely be trivial depending on what the Lua scripts do and what it is used for. Scripts shouldn’t be executed in tight loops, but for handling events, they’ll be fine.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s