Several mods for the game Valheim, by me.
Mods can be found on Valheim ThunderStore
How to setup the development enviroment for this project:
- Install Visual Studio 2022 and add the C# workload.
- Update
Environment.props
in the projects base path, and update the propertyVALHEIM_INSTALL
to point to the path of your installed copy of Valheim. - Install the required dependencies by running the script
./scripts/Download-Dependencies.ps1
in Powershell - Open
ValheimMods.sln
with Visual Studio, andbuild
the project at least once. - Close Visual Studio, and reopen
ValheimMods.sln
. For whatever reason Visual Studio will not detect the publicized assemblies unless this is done.
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.
- Build the project with target
Debug
. The publish.ps1 PowerShell script from this repo...- The compiled dll file for this project is copied to
<ValheimDir>\BepInEx\plugins
. - A .mdb file is generated for the compiled project dll and copied to
<ValheimDir>\BepInEx\plugins
. - automatically generates a
.dll.mdb
file, which is needed for Unity/mono debugging. It should be in <ValheimDir>\BepInEx\plugins, too. <JotunnModStub>\libraries\Debug\mono-2.0-bdwgc.dll
is copied to<ValheimDir>\MonoBleedingEdge\EmbedRuntime
replacing the original file (a backup is created before).
- The compiled dll file for this project is copied to
- A compressed file with the binaries is created in
<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.
- Download UnityHub directly from Unity or install it with the Visual Studio Installer via
Individual Components
->Visual Studio Tools for Unity
. - You will need an Unity account to register your PC and get a free licence. Create the account, login with it in Unity Hub and get your licence via
Settings
->Licence Management
. - Install Unity Editor version v2020.3.44f1.
- Copy all
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. - Warning: These assembly files are copyrighted material and you can theoretically get into trouble when you distribute them in your github repository. To avoid that there is a .gitignore file in the Unity project folder. Keep that when you clone or copy this repository.
You can enable remote debugging of your mod code at runtime via dnSpy or Visual Studio. Before being able to attach a remote debugger you will have to prepare your game install and turn it into a "Development Build" once:
- Locate your Unity Editor installation from the previous step and navigate to
<UnityInstall>\Editor\Data\PlaybackEngines\windowsstandalonesupport\Variations\win64_development_mono
- Copy
UnityPlayer.dll
andWinPixEventRuntime.dll
from that folder into your game installation folder. Overwrite existing files. - Open the
<Valheim>\valheim_Data\boot.config
with a text editor (Notepad++ for example) and add a new lineplayer-connection-debug=1
to it. - When starting up Valheim you should see a
Development Build
text at the lower-right corner of the screen.
Your own code can be debugged in source with Visual Studio itself. You cannot debug game disassemblies as with dnSpy, though.
- Install Visual Studio Tools for Unity (can be done in Visual Studio installer via
Individual Components
->Visual Studio Tools for Unity
) - Build the project with target
Debug
. - Start Valheim (either directly from Steam or hit F5 in Visual Studio when Steam is running)
- Go to
Debug
->Attach Unity debugger
- Since the patched mono dll does not open the same port as Unity Dev builds, you have to click on
Input IP
. It should fill in your local IP automatically. you just have to change the port to55555
and the debugger should connect.
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.
- Download dnSpy-net-win64 and extract the exe.
- Load all assemblies from
<ValheimDir>\unstripped_corlib
into dnSpy (just drag&drop the folder onto it). - Load all
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). - Load
JotunnModStub.dll
from<ValheimDir>\BepInEx\plugins
into dnSpy. - Copy
<JotunnModStub>\libraries\Debug\mono-2.0-bdwgc.dll
into<ValheimDir>\MonoBleedingEdge\EmbedRuntime
and overwrite the existing file. - Now go to
Debug
->Start Debugging
and select Unity debug engine. Select your valheim.exe as the executable and hit OK. - If you did set some breakpoints, the game will halt when it hits the breakpoint in memory and dnSpy will show you the objects in memory and much more useful stuff.
Description | Link |
---|---|
Template used to create this project | https://github.com/Valheim-Modding/JotunnModStub |
Jötunn's in depth setup guide | https://valheim-modding.github.io/Jotunn/guides/overview.html |
Jötunn Mod Library Tutorials | https://valheim-modding.github.io/Jotunn/tutorials/overview.html |
Logging with BepinEx | https://docs.bepinex.dev/v5.4.11/articles/dev_guide/plugin_tutorial/4_logging.html |
Helpful development mod, launches game automatically and picks world | https://valheim.thunderstore.io/package/abearcodes/Simple_Auto_Game_Start/ |