A simple tool to dynamically inject scripts into DCS missions
Because this tool requires the mission environment to be desantized (more on that later on), you open yourself up to some risks. When installing 3rd party injector modules or running 3rd party missions, please ensure that they only come from a trusted source and are free from any dangerous code. The modules that are sanitized by default, if desanitized, allow a nefarious actor among other things, to modify, delete and create files on your filesystem and execute shell commands at will.
- Get the latest release from the release section.
- Drop the file
injector.luainto your DCS saved games directory underC:\Users\<Your Name>\Saved Games\DCS(.openbeta)\Scripts\Hooks. - Desanitize the
Scripts\MissionScripting.luafile in the DCS installation directory.
By default the end of the file should look something like this:
do
sanitizeModule('os')
sanitizeModule('io')
sanitizeModule('lfs')
_G['require'] = nil
_G['loadlib'] = nil
_G['package'] = nil
endTo remove the sanitation, comment out or delete the entire do-end block:
-- do
-- sanitizeModule('os')
-- sanitizeModule('io')
-- sanitizeModule('lfs')
-- _G['require'] = nil
-- _G['loadlib'] = nil
-- _G['package'] = nil
-- endThe injectable scripts are located in the DCS saved games directory under Scripts\Inject. Here every subfolder is treated as an injector module. The name of the subfolder is also the name of the module. A module consists of two files, both of which are optional and are loaded and executed when a mission in DCS starts. So DCS does not have to be restarted for every change to a script file. A restart of the current mission is sufficient.
init.lua: executed in themissionenvironment. All mission scripting functions are available just like in aDO FILEtrigger action.hook.lua: executed in theguienvironment. This is a special environment where the hooks inScripts\Hooksare executed in. The DCS installation directory contains a file (API\DCS_ControlAPI.html) with an incomplete list of the available API. For example: By using thenet.dostring_infunction you can pass data to the mission environment.
You are not limited to only these two files. By using the require function additional files can be loaded. Even modules external to your injector module can be imported. Note, that the injected scripts are executed inside of a sandbox, so multiple injector modules cannot interfere with each other. They are completely independent of each other and can not depend on each other either.
Check out this project for an comprehensive example of how to use injector. Also a very simple example of an injector module can be found in this repository.