Skip to content

Commit

Permalink
Renamed project to DCS-Input-Command-Injector, Saved Game folder chan…
Browse files Browse the repository at this point in the history
…ged to "InputCommands/"
  • Loading branch information
Quaggles committed Apr 1, 2021
1 parent 581363d commit e815de8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ end
into the "loadDeviceProfileFromFile" function below the line:
status, result = pcall(f)
]]--
local quagglesLogName = 'Quaggles.KeybindInjector'
local quagglesLogName = 'Quaggles.InputCommandInjector'
local quagglesLoggingEnabled = false
local function QuagglesKeybindInjector(filename, folder, env, result)
local function QuagglesInputCommandInjector(filename, folder, env, result)
-- Returns true if string starts with supplied string
local function StartsWith(String,Start)
return string.sub(String,1,string.len(Start))==Start
Expand All @@ -95,7 +95,7 @@ local function QuagglesKeybindInjector(filename, folder, env, result)
local targetPrefix = "./Mods/aircraft/"
if StartsWith(filename, targetPrefix) and StartsWith(folder, targetPrefix) then
-- Transform path to user folder
local newFileName = filename:gsub(targetPrefix, lfs.writedir():gsub('\\','/').."QuagglesKeybindInjector/")
local newFileName = filename:gsub(targetPrefix, lfs.writedir():gsub('\\','/').."InputCommands/")
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '--Translated path: '..newFileName) end

-- If the user has put a file there continue
Expand Down
1 change: 1 addition & 0 deletions DCS-Input-Command-Injector-Quaggles/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modifies the DCS control scripts to allow merging of user configured input commands from "Saved Games/DCS/" without modifying the original source files: https://github.com/Quaggles/dcs-input-command-injector/
1 change: 1 addition & 0 deletions DCS-Input-Command-Injector-Quaggles/VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.2
1 change: 0 additions & 1 deletion DCS-Keybind-Injector-Quaggles/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion DCS-Keybind-Injector-Quaggles/VERSION.txt

This file was deleted.

33 changes: 19 additions & 14 deletions Inject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
into the "loadDeviceProfileFromFile" function below the line:
status, result = pcall(f)
]]--
local quagglesLogName = 'Quaggles.KeybindInjector'
local quagglesLogName = 'Quaggles.InputCommandInjector'
local quagglesLoggingEnabled = false
local function QuagglesKeybindInjector(filename, folder, env, result)
local function QuagglesInputCommandInjector(filename, folder, env, result)
-- Returns true if string starts with supplied string
local function StartsWith(String,Start)
return string.sub(String,1,string.len(Start))==Start
Expand All @@ -18,25 +18,30 @@ local function QuagglesKeybindInjector(filename, folder, env, result)
local targetPrefix = "./Mods/aircraft/"
if StartsWith(filename, targetPrefix) and StartsWith(folder, targetPrefix) then
-- Transform path to user folder
local newFileName = filename:gsub(targetPrefix, lfs.writedir():gsub('\\','/').."QuagglesKeybindInjector/")
local newFileName = filename:gsub(targetPrefix, lfs.writedir():gsub('\\','/').."InputCommands/")
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '--Translated path: '..newFileName) end

-- If the user has put a file there continue
if lfs.attributes(newFileName) then
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '----Found merge at: '..newFileName) end
--Configure file to run in same environment as the default command entry file
local f = loadfile(newFileName)
setfenv(f, env)
local statusInj, resultInj
statusInj, resultInj = pcall(f)

-- Merge resulting tables
if statusInj then
if resultInj.keyCommands then env.join(result.keyCommands, resultInj.keyCommands) end
if resultInj.axisCommands then env.join(result.axisCommands, resultInj.axisCommands) end
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '------Merge successful') end
local f, err = loadfile(newFileName)
if err ~= nil then
log.write(quagglesLogName, log.ERROR, '------Failure loading: '..tostring(newFileName).." Error: "..tostring(err))
return
else
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '------Merge failed: '..tostring(statusInj)) end
setfenv(f, env)
local statusInj, resultInj
statusInj, resultInj = pcall(f)

-- Merge resulting tables
if statusInj then
if resultInj.keyCommands then env.join(result.keyCommands, resultInj.keyCommands) end
if resultInj.axisCommands then env.join(result.axisCommands, resultInj.axisCommands) end
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '------Merge successful') end
else
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '------Merge failed: '..tostring(statusInj)) end
end
end
end
end
Expand Down
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# DCS Keybind Injector by Quaggles
# DCS Input Command Injector by Quaggles

![image](https://user-images.githubusercontent.com/8382945/113183515-75dbfb00-9297-11eb-965a-492fd9789c26.png)

## Summary

A mod that allows you to configure custom keybind entries inside your `Saved Games/DCS/` folder instead of inside your game folder, when DCS is run these entries are merged in with the default aircraft entries. This method avoids having to manually merge your control changes into each aircrafts default controls when DCS updates.
A mod that allows you to configure custom input commands inside your `Saved Games/DCS/` folder instead of inside your game folder, when DCS is run these commands are merged in with the default aircraft commands. This method avoids having to manually merge your command changes into each aircrafts default commands when DCS updates.

## The goal of this mod

Commonly in DCS users with unique input systems will need to create custom keybinds to allow them to use certain aircraft functions with their HOTAS. Some examples are:
Commonly in DCS users with unique input systems will need to create custom input command to allow them to use certain aircraft functions with their HOTAS. Some examples are:

* Configuring 3 way switches on a Thrustmaster Warthog HOTAS to control switches the module developer never intended to be controlled by a 3 way switch
* Configuring actions that only trigger a cockpit switch while a button is held, for example using the trigger safety on a VKB Gunfighter Pro to turn on Master Arm while it's flipped down and then turn off Master Arm when flipped up
* Adding keybinds that the developer forgot, for example the Ka-50 has no individual "Gear Up" and Gear Down" binds, only a gear toggle
* Adding control entries that the developer forgot, for example the Ka-50 has no individual "Gear Up" and Gear Down" commands, only a gear toggle

In my case, on my Saitek X-55 Throttle there is an airbrake slider switch that when engaged registers as a single button being held down, when the slider is disengaged the button is released. In DCS by default few aircraft support this type of input so a custom input is needed, in my case for the F/A-18C:
In my case, on my Saitek X-55 Throttle there is an airbrake slider switch that when engaged registers as a single button being held down, when the slider is disengaged the button is released. In DCS by default few aircraft support this type of input so a custom input command is needed, in my case for the F/A-18C:

```lua
{down = hotas_commands.THROTTLE_SPEED_BRAKE, up = hotas_commands.THROTTLE_SPEED_BRAKE, cockpit_device_id = devices.HOTAS, value_down = -1.0, value_up = 1.0, name = 'Speed Brake Hold', category = {'Quaggles Custom'}},
```

Until now the solution was to find the control definition file `DCSWorld\Mods\aircraft\FA-18C\Input\FA-18C\joystick\default.lua` and insert your command somewhere inside of it, if you weren't using a mod manager then every time the game was updated your change would be erased and you'd need reinsert your commands into the files for every aircraft you changed.
Until now the solution was to find the control definition file `DCSWorld\Mods\aircraft\FA-18C\Input\FA-18C\joystick\default.lua` and insert your custom command somewhere inside of it, if you weren't using a mod manager then every time the game was updated your change would be erased and you'd need reinsert your commands into the files for every aircraft you changed.

If you were using a mod manager such as OVGME if you reapplied your mod after an update and the developers had changed the control binds things could break as things could conflict.
If you were using a mod manager such as OVGME if you reapplied your mod after an update and the developers had changed the input commands things could break and conflict.

With this mod you should just need to re-enable it after every update with OVGME and your custom control binds are safe with no need no change anything.
With this mod you should just need to re-enable it after every update with OVGME and your custom commands are safe with no need no change anything.

## Installation

1. Go to the [latest release](https://github.com/Quaggles/dcs-keybind-injector/releases/latest)
2. Download `DCS-Keybind-Injector-Quaggles.zip`
1. Go to the [latest release](https://github.com/Quaggles/dcs-input-command-injector/releases/latest)
2. Download `DCS-Input-Command-Injector-Quaggles.zip`

### [OVGME (Recommended)](https://wiki.hoggitworld.com/view/OVGME)
3. Drop the zip file in your mod directory
Expand All @@ -38,22 +38,22 @@ With this mod you should just need to re-enable it after every update with OVGME

### Manual
3. Extract the zip
4. Find the `DCS-Keybind-Injector-Quaggles/Scripts` folder
4. Find the `DCS-Input-Command-Injector-Quaggles/Scripts` folder
5. Move it into your `DCSWorld/` folder
6. Windows Explorer will ask you if you want to replace `Data.lua`, say yes
7. Repeat this process every DCS update, if you use OVGME you can just reenable the mod and it handles this for you

## Configuration

New commands are configured in the `Saved Games\DCS\QuagglesKeybindInjector` directory, lets go through how to configure a hold action for the speedbrake on the F/A-18C Hornet.
New commands are configured in the `Saved Games\DCS\InputCommands` directory, lets go through how to configure a hold command for the speedbrake on the F/A-18C Hornet.

### Setting the folder structure

For the F/A-18C the default input files are located in `DCSWorld\Mods\aircraft\FA-18C\Input\FA-18C`, inside this directory are folders with the generic names of your input devices, these can include `joystick`, `keyboard`, `mouse`, `trackir` and `headtracker`. Each generic input folder contains `default.lua` which is the default set of keybinds the developer has configured, this is an important reference when making your own commands. It also contains many lua files for automatic binding of common hardware like the Thrustmaster Warthog HOTAS but these can be ignored.
For the F/A-18C the default input files are located in `DCSWorld\Mods\aircraft\FA-18C\Input\FA-18C`, inside this directory are folders with the generic names of your input devices, these can include `joystick`, `keyboard`, `mouse`, `trackir` and `headtracker`. Each generic input folder contains `default.lua` which is the default set of commands the developer has configured, this is an important reference when making your own commands. It also contains many lua files for automatic binding of common hardware like the Thrustmaster Warthog HOTAS but these can be ignored (`*.diff.lua`).

The DCS input folder structure needs be duplicated so that the folders relative to `DCSWorld\Mods\aircraft` are placed in `Saved Games\DCS\QuagglesKeybindInjector`. The folder structure needs to match <b>EXACTLY</b> for each generic input device you want to add commands to. In my F/A-18C Speedbrake Hold example that means I will create the structure `Saved Games\DCS\QuagglesKeybindInjector\FA-18C\Input\FA-18C\joystick\`, for an F-14B in the RIO seat I would create `Saved Games\DCS\QuagglesKeybindInjector\F14\Input\F-14B-RIO\joystick`.
The DCS input folder structure needs be duplicated so that the folders relative to `DCSWorld\Mods\aircraft` are placed in `Saved Games\DCS\InputCommands`. The folder structure needs to match <b>EXACTLY</b> for each generic input device you want to add commands to. In my F/A-18C Speedbrake Hold example that means I will create the structure `Saved Games\DCS\InputCommands\FA-18C\Input\FA-18C\joystick\`, for an F-14B in the RIO seat I would create `Saved Games\DCS\InputCommands\F14\Input\F-14B-RIO\joystick`.

<b>IMPORTANT:</b> For some aircraft the 1st and 3rd folders have different names, for example `F14\Input\F-14B-Pilot` make sure this structure is followed correctly or your inputs won't be found
<b>IMPORTANT:</b> For some aircraft the 1st and 3rd folders have different names, for example `F14\Input\F-14B-Pilot` make sure this structure is followed correctly or your inputs won't be found.

An example of the folder structure for some aircraft I have configured:

Expand All @@ -63,7 +63,7 @@ An example of the folder structure for some aircraft I have configured:

![image](https://user-images.githubusercontent.com/8382945/113173913-37414300-928d-11eb-91ad-6e09b6f64a8b.png)

Inside the generic input folder `Saved Games\DCS\QuagglesKeybindInjector\FA-18C\Input\FA-18C\joystick\` etc we will create a lua script called `default.lua`, paste in the following text, it contains the Speedbrake Hold example and some commented out templates for the general structure of commands
Inside the generic input folder `Saved Games\DCS\InputCommands\FA-18C\Input\FA-18C\joystick\` we will create a lua script called `default.lua`, paste in the following text, it contains the Speedbrake Hold example and some commented out templates for the general structure of commands

```lua
return {
Expand All @@ -80,19 +80,19 @@ return {
}
```

To work out what to put in these templates reference the developer provided default keybinds file, for the F/A-18C that is in `DCSWorld\Mods\aircraft\FA-18C\Input\FA-18C\joystick\default.lua`
To work out what to put in these templates reference the developer provided default input command file, for the F/A-18C that is in `DCSWorld\Mods\aircraft\FA-18C\Input\FA-18C\joystick\default.lua`

I'd recommend setting a unique category name for your custom commands so that they are easy to find in the menu.

## Extras
### Hardlinking
If you want to have a set of commands bindable to both your HOTAS and your keyboard consider [hardlinking](https://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html) your `default.lua` from your `joystick` folder to your `keyboard` folder.
If you want to have a set of custom commands for both your HOTAS and your keyboard consider [hardlinking](https://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html) your `default.lua` from your `joystick` folder to your `keyboard` folder.

By hardlinking both files look like they are in different directories to Windows and DCS but they actually refer to the same file on the disk meaning if you modify one you automatically modify the other
By hardlinking both files look like they are in different directories to Windows and DCS but they actually refer to the same file on the disk meaning if you modify one you automatically modify the other.

## Examples

### Request AWACS Nearest Bandit
Allows binding request bogey dope to your HOTAS, not every aircraft has this by default in DCS

```lua
{down = iCommandAWACSBanditBearing, name='Request AWACS Nearest Bandit', category = 'Quaggles Custom'},
```
Expand Down Expand Up @@ -120,13 +120,13 @@ Note: May get broken by Heatblur at any time and could be considered unscrupulou
```

# FAQ
## My new control bindings aren't showing up ingame
## My new input commands aren't showing up ingame
First look at `Saved Games\DCS\Logs\dcs.log` at the bottom is likely an error telling you what went wrong in your code, for finding syntax errors in lua I would recommend Visual Studio Code with the vscode-lua extension, it should highlight them all in red for you making it easy to find that missing comma 😄

If you have no errors open the mod version of `Scripts\Input\Data.lua` and find the line `local quagglesLoggingEnabled = false` and set it to `true` you will get outputs in the `Saved Games\DCS\Logs\dcs.log` file as the script tries to handle every lua control file, it will tell you the path to the file it is trying to find in your Saved Games folder so you can ensure your folder structure is correct. Remember `../` in a path means get the parent directory.
If you have no errors open the mod version of `Scripts\Input\Data.lua` and find the line `local quagglesLoggingEnabled = false` and set it to `true` you will get outputs in the `Saved Games\DCS\Logs\dcs.log` file as the script tries to handle every lua control file, it will tell you the path to the files it is trying to find in your Saved Games folder so you can ensure your folder structure is correct. Remember `../` in a path means get the parent directory.

## HELP MY CONTROLS MENU IS BLANK/MISSING
Don't worry, this doesn't mean you've lost all your keybinds, it means there was an error somewhere in the code loading the keybinds, usually my injector catches any errors in the `default.lua` and reports them `Saved Games\DCS\Logs\dcs.log`. If you see nothing there it could mean that DCS has been updated and changed the format of the `Scripts/Input/Data.lua` file the mod changes, simple uninstall the mod and the game should work as normal, then wait for an updated version of the mod.
Don't worry, this doesn't mean you've lost all your binds, it means there was an error somewhere in the code loading the commands, usually my injector catches any errors in the `default.lua` and reports them `Saved Games\DCS\Logs\dcs.log`. If you see nothing there it could mean that DCS has been updated and changed the format of the `Scripts/Input/Data.lua` file the mod changes, simple uninstall the mod and the game should work as normal, then wait for an updated version of the mod.

## Disclaimer
I am not responsible for any corrupted keybinds when you use this mod, I've personally never had an issue with this method but I recommend <b>always</b> keeping backups of your keybinds (`Saved Games\DCS\Config\Input`) if you value them.
I am not responsible for any corrupted binds when you use this mod, I've personally never had an issue with this method but I recommend <b>always</b> keeping backups of your binds (`Saved Games\DCS\Config\Input`) if you value them.

0 comments on commit e815de8

Please sign in to comment.