The template
templates/overcooked-2-addon in the repository is a working Overcooked 2 addon. Copy it, rename it, then build and install it:
sh
cp -r templates/overcooked-2-addon ~/party-mode && cd ~/party-mode
mv MyKitchen.csproj PartyMode.csproj
# PartyMode.csproj: <AssemblyName>PartyMode</AssemblyName> and <RootNamespace>PartyMode</RootNamespace>
# swofty.json: "id": "yourname.party-mode", "name": "Party Mode", "assemblies": ["PartyMode.dll"]
dotnet build -c Release -p:SwoftyCoreDir=/path/to/SwoftyLauncher/cores/overcooked_2
swofty --game overcooked_2 addons install distThe template is MIT-licensed; your addon can use any licence. For level content (foods, stations, recipes, movement and animations for custom levels) start from templates/overcooked-2-content-addon instead; see Level content.
text
templates/overcooked-2-addon/
├── swofty.json id, name, version, compat.game overcooked_2 with the std range, the assembly to load
├── MyKitchen.csproj a net35 class library against Swofty Core; each build writes the addon folder to dist/
├── src/MyKitchenAddon.cs the addon
├── README.md build and install steps
└── LICENSE MITThe addon
csharp
using System;
using System.IO;
using System.Reflection;
using HarmonyLib;
using Swofty.Overcooked2;
namespace MyKitchen
{
public sealed class MyKitchenAddon : IAddon
{
private static AddonContext context;
private static int scenes;
public void Load(AddonContext ctx)
{
context = ctx;
ctx.Log.Info(ctx.Name + " " + ctx.Version + " on Overcooked 2 " + Game.Version + ", Swofty Core " + Runtime.CoreVersion);
MainMenu.AddButton(ctx.Id + ".about", "My Kitchen", ShowAbout);
MainMenu.Shown += () => ctx.Log.Info("the main menu has shown");
Game.SceneLoaded += scene =>
{
scenes++;
ctx.Log.Info("scene " + scene);
};
Type flow = AccessTools.TypeByName("T17FrontendFlow");
MethodInfo awake = flow == null ? null : AccessTools.Method(flow, "Awake");
if (awake == null)
{
ctx.Log.Warn("T17FrontendFlow.Awake is not in this build; the patch is off");
return;
}
ctx.Harmony.Patch(awake, postfix: new HarmonyMethod(typeof(MyKitchenAddon), nameof(AfterFrontendAwake)));
}
private static void AfterFrontendAwake()
{
context.Log.Info("the front end is up");
}
private static void ShowAbout()
{
string visits = Path.Combine(context.DataDirectory, "visits.txt");
int count = File.Exists(visits) ? int.Parse(File.ReadAllText(visits).Trim()) + 1 : 1;
File.WriteAllText(visits, count.ToString());
Dialogs.Message(context.Name, context.Name + " " + context.Version + "\n" + Plural(scenes, "scene") + " loaded this session, " + Plural(count, "visit") + " to this dialog.");
}
private static string Plural(int n, string word)
{
return n + " " + (n == 1 ? word : word + "s");
}
}
}Loadruns once, when the game loads its first scene: see Addons and IAddon.MainMenu.AddButtonadds MY KITCHEN to the MODS tab, with the idexample.my-kitchen.about: see MainMenu.Game.SceneLoadedcounts the scenes of the session: see Game.AccessTools.TypeByNamefinds the game'sT17FrontendFlowwith no reference to the game's assemblies, andctx.Harmony.Patchadds a postfix to itsAwake. Without that method, the addon logs a warning and loads without the patch: see Harmony patches.visits.txtis inctx.DataDirectory: see AddonContext and Log.Dialogs.Messageopens the dialog: see Dialogs.
The second time, MY KITCHEN opens:
text
My Kitchen
My Kitchen 0.1.0
4 scenes loaded this session, 2 visits to this dialog.swofty.json
json
{
"id": "example.my-kitchen",
"name": "My Kitchen",
"version": "0.1.0",
"author": "Your Name",
"description": "A starting point for an Overcooked 2 addon: a main menu button, a dialog, scene events, a data folder and a Harmony patch.",
"license": "MIT",
"compat": { "game": "overcooked_2", "std": ">=0.1.0" },
"assemblies": ["MyKitchen.dll"]
}Change id, name, author and description, and list your assembly in assemblies: see swofty.json.
The project
xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<AssemblyName>MyKitchen</AssemblyName>
<RootNamespace>MyKitchen</RootNamespace>
<Version>0.1.0</Version>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<DebugType>none</DebugType>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<SwoftyCoreDir Condition="'$(SwoftyCoreDir)' == ''">$(MSBuildThisFileDirectory)../../games/overcooked_2/dist</SwoftyCoreDir>
<OC2_DIR Condition="'$(OC2_DIR)' == '' And '$(OS)' == 'Windows_NT'">C:\Program Files (x86)\Steam\steamapps\common\Overcooked! 2</OC2_DIR>
<OC2_DIR Condition="'$(OC2_DIR)' == ''">$(HOME)/.local/share/Steam/steamapps/common/Overcooked! 2</OC2_DIR>
<OC2Managed>$(OC2_DIR)/Overcooked2_Data/Managed</OC2Managed>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net35" Version="1.0.3" PrivateAssets="all" />
<Reference Include="Swofty.Overcooked2" HintPath="$(SwoftyCoreDir)/core/Swofty.Overcooked2.dll" Private="false" />
<Reference Include="0Harmony" HintPath="$(SwoftyCoreDir)/core/0Harmony.dll" Private="false" />
</ItemGroup>
<ItemGroup Condition="Exists('$(OC2Managed)/Assembly-CSharp.dll')">
<Reference Include="$(OC2Managed)/Assembly-CSharp.dll" Private="false" />
<Reference Include="$(OC2Managed)/UnityEngine*.dll" Private="false" />
</ItemGroup>
<Target Name="SwoftyCheckCore" BeforeTargets="ResolveAssemblyReferences" Condition="!Exists('$(SwoftyCoreDir)/core/Swofty.Overcooked2.dll')">
<Error Text="Swofty Core not found in $(SwoftyCoreDir). Build it with games/overcooked_2/build.sh or pass -p:SwoftyCoreDir=<launcher>/cores/overcooked_2." />
</Target>
<Target Name="SwoftyAddonFolder" AfterTargets="Build">
<Copy SourceFiles="swofty.json;$(TargetPath)" DestinationFolder="dist" />
</Target>
</Project>SwoftyCoreDir: Swofty Core, withcore/Swofty.Overcooked2.dllandcore/0Harmony.dll. Passcores/overcooked_2in the launcher's install folder. In the repository, the default isgames/overcooked_2/dist, whichgames/overcooked_2/build.shbuilds. Without Swofty Core,SwoftyCheckCorestops the build withSwofty Core not found in <folder>.OC2_DIR: the game folder, by default the Steam library folder on Windows and Linux. WithAssembly-CSharp.dllthere, the project references it and the game'sUnityEngine*.dll. Without it, the template still builds.SwoftyAddonFoldercopiesswofty.jsonand the built dll todist/after each build. Install that folder, or a zip of it.