A Valheim mod stub project using Jötunn including build tools for debugging your code in Visual Studio and a basic Unity project stub. There is no actual plugin content included, just a bare minimum plugin class.
These are quick setup steps with no context provided. Please see Jötunns Github Pages for a more in depth guide and documentation.
How to setup the development enviroment for this project.
<ValheimDir>\unstripped_corlib
and more additional stuff.JotunnModStub
. You can also use the template function of github to create a new, clean repo out of it and clone that.Environment.props
in the projects base path <JotunnModStub>
. Paste this snippet and change the path according to your local Valheim installation.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Needs to be your path to the base Valheim folder -->
<VALHEIM_INSTALL>F:\Steam\steamapps\common\Valheim</VALHEIM_INSTALL>
</PropertyGroup>
</Project>
DoPrebuild.props
in the project base path and change ExecutePrebuild
to true
if you want Jötunn to automatically generate publicized and MMHook versions of the game dlls for you.<JotunnModStub>\JotunnModStub.sln
. Right-click on the project or solution in the Solution Explorer and select Manage NuGet packages...
. It should prompt you a message at the top that some NuGet-Packages are missing. Click "Restore" and restart Visual Studio when finished.Included in this repo is a PowerShell script publish.ps1
. The script is referenced in the project file as a post-build event. Depending on the chosen configuration in Visual Studio the script executes the following actions.
<ValheimDir>\BepInEx\plugins
.<ValheimDir>\BepInEx\plugins
.<JotunnModStub>\libraries\Debug\mono-2.0-bdwgc.dll
is copied to <ValheimDir>\MonoBleedingEdge\EmbedRuntime
replacing the original file (a backup is created before).<JotunnModStub>\Packages
ready for upload to ThunderStore. Dont forget to include your information in the manifest.json and to change the project's readme file.New Assets can be created with Unity and imported into Valheim using the mod. A Unity project is included in this repository under <JotunnModStub>\JotunnModUnity
.
Individual Components
-> Visual Studio Tools for Unity
.Settings
-> Licence Management
.assembly_*.dll
from <ValheimDir>\valheim_Data\Managed
into <JotunnModStub>\JotunnModUnity\Assets\Assemblies
. Do this directly in the filesystem - don't open Unity first or import the dlls directly in Unity.AssetBundle Browser
package in the Unity Editor via Window
-> Package Manager
for easy bundle creation.Thanks to mono and unity-mono being open source, we patched and compiled our own mono runtime to enable actual live debugging of the game and the mod itself with dnSpy.
<ValheimDir>\unstripped_corlib
into dnSpy (just drag&drop the folder onto it).assembly_*
from <ValheimDir>\valheim_Data\Managed
into dnSpy (do not load the publicized ones, they will not be loaded into the process and therefore can not be debugged).JotunnModStub.dll
from <ValheimDir>\BepInEx\plugins
into dnSpy.<JotunnModStub>\libraries\Debug\mono-2.0-bdwgc.dll
into <ValheimDir>\MonoBleedingEdge\EmbedRuntime
and overwrite the existing file.Debug
-> Start Debugging
and select Unity debug engine. Select your valheim.exe as the executable and hit OK.Your own code can be debugged in source with Visual Studio itself. You cannot debug game disassemblies as with dnSpy, though.
Individual Components
-> Visual Studio Tools for Unity
)Debug
. The publish.ps1 PowerShell script from this repo...
Debug
-> Attach Unity debugger
Input IP
. It should fill in your local IP automatically. you just have to change the port to 55555
and the debugger should connect.When Valheim updates it is likely that parts of the assembly files change. If this is the case, the references to the assembly files must be renewed in Visual Studio and Unity.
assembly_*.dll
from <ValheimDir>\valheim_Data\Managed
into <JotunnModStub>\JotunnModUnity\Assets\Assemblies
. Ctrl+R
. This reloads all files from the filesystem and "re-imports" the copied dlls into the project.