Code Monkey home page Code Monkey logo

dcs_code_injector's Introduction

PyPI - Version GitHub Workflow Status (with event) Discord

ko-fi

Supported by JetBrains' Open Source Development Project

JetBrains

📲 DCS Code Injector

Don't worry, I'll change the name to something cool later 🌴🥥

Questions or concerns? Find me under the name coconutcockpit on my Discord server here: Discord

Here's a video of an older version in action: https://youtu.be/m2tGLFgLp8Y

01

🙋‍What is it?

It's a small program that you can run alongside DCS to influence a mission while it's running. I use it a lot to quickly try out scripting ideas without having to reload the mission all the time. It's a REPL (Read-Eval-Print-Loop) that I kind of based on Autodesk Maya's script editor.

Some things other people have been using it for:

  • Something happened in a mission that didn't fire a trigger. Instead of calling it quits we got to activate the event that was supposed to happen
  • Adding extra functionality to paid campaigns, such as a splash damage script.
  • Spawning new enemies in a mission without having to set up a bunch of radio commands
  • ...

💾 How to download

You can grab a .zip file that contains an executable that should run on any Windows machine from the releases page here: https://github.com/nielsvaes/dcs_code_injector/releases

If you have Python installed on your computer, you can also find it on PyPi and pip install (and upgrade) it with the following command:

pip install --upgrade dcs-code-injector

It also makes an entry point to the application, so type dcs-code-injector to run it.

⚠️ False antivirus positives! All code is written in Python. To make it easier for people who don't have Python installed, I use a package called Nuitka to make it an executable that runs on Windows. A side effect of this is that sometimes it triggers antivirus software because they think it's a trojan. It is not. All the code for the program is available here on the github page. If you're running into troubles, it's easier to just use Python to run the program instead of the executable. Feel free to reach out to me if you need help getting it up and running with just Python.

🥇First time use

When you open the application for the first time, you need to tell it where your dcs.log file is saved. Browse to the file (it's in your Saved Games folder) and save the settings. You will then be presented with the main window and the log panel. The log gets updated automatically while DCS is running, so it's easy to see if you're getting any errors or warnings when running code.

🪝 Add the hook

A Lua hook needs to be loaded in order to tell DCS to connect to the application. The easiest way to do this is to go to Tools > Copy hook file. ⚠️ You need to have set the path to your dcs.log file for this to work, since it uses that log's location to figure out where the hook should go

image

In case this doesn't work (but it really should!) you can copy the file over manually: Find a file called dcs-code-injector-hook.lua in the Github repository or in the downloaded .zip archive. You need to copy this file into the Scripts/Hooks folder inside your Saved Games/DCS.openbeta or Saved Games/DCS folder. Remember where you put the SRS hook file? This one goes right next alongside it :)

✒️ Edit MissionScripting.lua

In the Scripts folder if your DCS install directory, there's a file called MissionScripting.lua. Comment out the lines that start with _G to make sure the hook can load everything it needs to:

MissionScripting.lua:

local function sanitizeModule(name)
	_G[name] = nil
	package.loaded[name] = nil
end

do
	sanitizeModule('os')
	sanitizeModule('io')
	sanitizeModule('lfs')
	--_G['require'] = nil
	--_G['loadlib'] = nil
	--_G['package'] = nil
end

❓How to use

Press Ctrl-N to make a new tab. This will add a new UNNAMED tab. UNNAMED tabs are not saved on shutdown, so it's best to rename the tab if you want to keep the code around for later use. Double-click on the tab name to rename it. Anything you write in a tab is saved automatically.

Select a block of code and press Ctrl-Enter or Ctrl-Return to execute it. The code block will appear in the log panel and will be run inside the mission. Any errors in the code will show up as red in the log. If nothing is selected, all the code in the currrent active code tab will be executed

You can save code you run often to Favorite buttons. I use this to reload MOOSE for example, when I've made changes to it. To save a button, select the lines of code you want to save and drag them to the blank strip beneath the code panel and above the connection icon. Pick a name and click save. To delete a Favorite button, right click on it and click Delete.

Press Ctrl-F to open a search box in the Log view. The Cc toggles between case sensitive and insensitive search.

Use Shift + Numpad+ and Shift + Numpad- to increase and decrease the log font size.

Use Ctrl + Numpad+ and Ctrl + Numpad- to increase and decrease the code font size.

🎨 Log highlighting colors

I've added some "default" highlighting colors for the log. These are the colors that I'm using, but they might not be to everyone's liking. You can add new highlighting rules in the settings, they can be individual words or phrases or regular expressions. Select a rule and press the delete key to delete it.

image

You need to restart the application for the new rules to be applied. If you want to get the defaults back, just delete all the rules and restart.

🎨 Code completion

The Code Injector supports some basic code completion for lightweight Lua, MOOSE and Mist code_completion

You can update code completion for MOOSE and Mist from the settings image

  • Lua keywords are completed
  • Variable names in the document are completed
  • Function definitions in the document are completed
  • It's a "dumb" completion model, it doesn't understand context, meaning:
my_group = GROUP:FindByName("goose_and_maverick") -- <=== GROUP:FindByName... will be auto completed
my_group:GetVec3() -- <== "my_group" will be autocompleted, but "GetVec3()" will not be, since it doesn't know that "my_group" is a MOOSE GROUP

🗺️Future plans

REPL

  • Better code highlighting

Other parts

The REPL is actually just a small part of larger project I had in mind. Future plans include:

  • Battlefield Commander Mode: This will show a map with all the units in the mission that you can manipulate in real time. In a limited testing mode I've used this to turn on SAM sites, spawn enemy fighters and things like that. I haven't really used LotATC, but I think it offers similar functionality.
  • Integration with Standalone Servers
  • Plugins
  • and more!

🤙Contributing

I am not a hardcore coder or programmer, so if you are and want to lend a helping hand, GREAT! Fork the project and create a PR with your changes. Other ways you can contribute is by reporting issues or posting feature requests on the Issues page of the GitHub repository. I started this project just to make my own life easier, but I would to hear what you might want to use it for!

📖License

Licensed under GNU GENERAL PUBLIC LICENSE v3

dcs_code_injector's People

Contributors

emcek avatar nielsvaes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dcs_code_injector's Issues

Code Injector crashes often and 1.4.9 doesn't appear to have working tabs and 1.4.10 doesn't open at all.

First of all. WOW! Great work on this!
There are a couple issues I have run into. For all I know they are limited to my system. When the application crashes I haven't found the log file it is writing to.
Here goes for the bugs:

  1. Code Injector crashes often usually when an error modal pops up and I click on DCS Code Injector before dismissing the modal.
  2. and 1.4.9 doesn't appear to have working tabs
  3. and 1.4.10 doesn't open at all.

Other than that I have been using it for a couple weeks now and it is amazing!

string.match doesn't work with patterns

In the DCS Code Injector the line trigger.action.outText(tostring(string.match("zone1", '%d+')),10) returns nil. The line directly in DCS over triggers returns 1. If I remove the pattern e.g. trigger.action.outText(tostring(string.match("zone1", '1')),10) it returns 1.

Reload MOOSE in the tool

          By the way, how do You reload whole Moose with the tool? I tried to copy-paste the Moose in the separate tab to drag it down to the buttons, but the tool have hung in paste action...

Originally posted by @Amarok73 in #8 (comment)

Better indentation handling

          And another thing that comes to my mind, if the indentation could behave more like in regular code editors, so the next line would be indented to the same level as the previous one, then pressing the backspace at the beginning of the line would cause jump left to the previous indentation level. That would significantly improve the comfort, especially when writing plenty of code.

That's almost all my wishes I've since started working with this unbelievably useful tool.

Originally posted by @Amarok73 in #10 (comment)

Optional activation for CodeInjector embedded LogViewer

As Mission Designer I am often using MOOSE debugging option to help understand the errors generated by my scripts. This is leading to big "dcs.log" file size which seems to impact the way that code within Injector is transmitted to DCS.
Would be good if we can enable/disable the internal LogViewer so that CodeInjector might have an improved behavior for this scenarios.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.