Duck Game Guide

Creating high-quality mods for Duck Game

Creating high-quality mods

Overview

This guide is intented to show some sides of how DG mod development should be done.

What tools do we need?

  • Visual Studio 2019 with tools for creating .net framework windows C# libraries
  • Sublime Text 3/NotePad++/VS Code
  • DotPeek

This guide assumes you are familiar with VS, DotPeek, C# 7 and MonoGame

What do we expect from mod?

Properly built mod should never distribute sources (even if they are open) neither extra libraries as separate files (I’ve people to distribute DuckGame.exe alongside their dll).
Also we want as little as possible troubles publicly.

OK, how to create some cool guns now, eh? (no)

There’s no way to starts with guns.
First of all, let’s create a project. We assume you’ve already installed all necessary tools.

Creating project

File->New->Project (or Ctrl+Shift+N)

Now select template (or type): Class Library (.NET Framework)

Project name: any
Location: any, but NOT in %userprofile%DocumentsDuckGameMods (even though others suggest this, you must not do this)
Solution name: same as project
Framework: .NET Framework 4.5.2 (matching DG’s one)

Create!

References

Here the pain fun starts
Add reference to DuckGame.exe which is under steamappscommon…
Then right click it->properties->copy local
set it (copy local) to be False

For now, we won’t create references for steam and other (useful?) things

Platform configuration

right click solution->Properties->Configuration->Configuration Manager
Active solution platform->New->x86
Active solution platform->Edit
select Any CPU
remove it

Important files/folders

remove Class1.cs, we don’t need it
in the root of the project (alongside bin, obj, Properties and *.csproj), create following folders and files:

  • src/
  • content/
  • mod.conf

leave folders as is by now
in mod.conf write the following:

<Mod> <NoCompilation>true</NoCompilation> </Mod>

this option makes makes DG not compile sources, because it uses old C#
Now, project folder should look like:

Build configuration

right click project->Properties->Build Events->Post-build event command line

SET modpath=%userprofile%DocumentsDuckGameMods$(TargetName) ECHO %modpath% IF NOT EXIST %modpath% ( MKDIR %modpath% ) COPY $(TargetPath) %modpath%$(TargetFileName) COPY $(ProjectDir)mod.conf %modpath% RMDIR /S /Q %modpath%content XCOPY $(ProjectDir)content %modpath%content /E /Y /Q

After build, mod folder should look like:

Debug configuration

project properties->Debug
Configuration: All Configurations
Start action: Start external program->path to DG
Start options: Command line argumets:

-moddebug -nointro

Classes

Mod

Mod class inheritor (e.g. class ExampleMod) must have name equal to Project’s one
create this in src/ folder. From this point, mod should work after build (only appear in mod list)

using DuckGame; namespace ExampleMod { public class ExampleMod: Mod { } }
Thing

That’s the main class you’ll work with

Important methods, fields, etc.
Update

That’s the method of any IAutoUpdate class (including Thing)
It’s called by DG (roughly) 60 times a second

Initialize

Some things must be placed here instead of constructor

StateBinding

public field of this type handles Net synchronization
Example[gist.github.com]
Details[gist.github.com]

Important subclasses
MaterialThing

Thing meant to interact with others

PhysicsObject

gravity, friction, etc.

Holdable
  • OnPressAction
Gun
  • Fire
  • Reload

AssemblyInfo.cs

project->Properties (folder)-> -//-
AssemblyTitle: title, shown in DG
AssemblyDescription: description, shown in DG
AssemblyConfiguration: omit for now
AssemblyCompany: author, shown in DG
AssemblyProduct: omit for now
AssemblyCopyright: omit for now (or set if you want)
AssemblyTrademark: omit for now (or set if you want)
AssemblyCulture: omit
ComVisible: leave as is
Guid: leave as is
AssemblyVersion: version, shown in DG
AssemblyFileVersion: remove

Some level issues

Why don’t my maps work online?
  • level is marked as having local mods
  • workshop id of objects on level is incorrect (hard to achieve, actually)

How to fix it? Subscribe on mod, resave with editor’s “save as” feature as another file and replace

Why do I have old version of my map online?

DG somehow caches levels and stores them by GUID
How to fix it?

  • Resave
  • Or change it by script or by hand

Environments

Did you know you can change workshop ID in mod.conf?
Main purpose of this is to have more than one environment.
At least, you should have PROD and DEV.
PROD is public.
DEV is private, you usually update it way more often than PROD. Main Only usage is to test online. You cannot just test online with local mod because of level issues.

What’s next?

The main advice is to use DotPeek to access public parts of DuckGame (it can’t pick some internal things like Dart, but it’s not fatal) or discover open source mods (Example[github.com]).
From this point usual development process begins.
Another advice is not to develop alone. It’s almost impossible to test online otherwise. Find someone to (at least) test with.

Post scriptum

This is only the initial form of the guide. However, I tried to cover some aspects not shown in the official guide.
Also, I’m not really sure if I wrote correct names of VS features as I only have non-English version. Please, correct me where I’m wrong.
Guide’s still incomplete. Any proper suggestion is respected.

Some question and answers

Q: In Things I use GetPath(), but how do I use it without Thing, e.g. in AmmoType?
A: Use Mod.GetPath<YourMod>() . YourMod is a class, inheritor of DuckGame.Mod .

Q: I changed smth in my mod and things on levels disappeared. What did I do?
A: You changed namespace or classname of things.

Q: I want to include lib in my mod, e.g. OgtDgLib or MathNet.Numerics, but DuckGame refuses to load mod at all. Why so?
A: DuckGame only loads DLL with the same name as its folder. So you have to include DLLs inside mod DLL with MSBuild.ILMerge.Task .

Q: What happens if both workshop and local mods are enabled?
A: Previously, it meant that only workshop one would load. Now, both mods show up ingame. Easiest solution is to remove dll from local folder.

SteamSolo.com