-
-
Notifications
You must be signed in to change notification settings - Fork 1
Project Setup
Once you have an IDE setup, and SALT installed on an instance of Smol Ame, you're ready to create your first mod!
If you already have a project you can skip to the section Setting up the project
The first step in creating a mod is creating a .NET Framework Class Library for C# Project
Next, give your project a name and set it to target .NET Framework 4.8 (if this option is not present, make sure you selected .NET Framework Class Library for C# when creating your library, and not .NET Core or .NET Standard, and not for Visual Basic)
Once you have your class library project targeting .NET 4.8 you can start setting it up for modding.
The first step is importing all the DLLs that are required for mod development In the solution explorer on the right side of the screen, you'll find an option called References
Right click on this option and click Add Reference...
Once you get to this menu select the Browse... option in the bottom right corner
The DLLs you will need are located in /SlimeRancher_Data/Managed as well as /SALT/Libs and they include, Assembly-CSharp_old.dll (NOT Assembly-CSharp-firstpass.dll or Assembly-CSharp.dll), SALT.dll (Don't mind the old photos, SAL was the old name for the loader), 0Harmony.dll and any UnityEngine DLLs you'll need for your mod (We'll start with UnityEngine.CoreModule.dll for now)
Now that you have the correct DLLs imported it's time to make the file that allows SALT to recognize your mod as a mod. This file is known as the modinfo.json
To create a modinfo.json, right click on your project in the solution explorer and select Add->New Item...
Next, it'll ask you for the name and type of your new item. Make sure you select Text File and set the name to modinfo.json (make sure the extension is .json and not .txt)
As evidenced by it's name, the modinfo.json uses the JSON File Format which means you need to use JSON syntax when filling it out Here's a sample modinfo.json:
If you'd like to copy and paste it as a template, it can be found right here (NOTE: DO NOT PUT COMMENTS IN YOUR FINAL MODINFO.JSON (comments are the // prefixed strings after each entry)):
{
"id": "myfirstmod",
"name": "My First Mod",
"author": "MegaPiggy",
"description": "This is the first mod I have ever made!",
"version": "1.0"
}
After you've filled out your modinfo.json to your liking, save it, and select it in your solution explorer. At the bottom of the solution explorer, you'll find a bunch of information about the file, as well as an option that reads, Build Action, click on it and select Embedded Resource. This will make the C# compiler include your modinfo.json in your mods final .dll, and allow it to be recognized by SALT
Creating the ModEntryPoint Your first mod is almost ready to run! But first you need to create an entry point for your mod to start execution at. SALT provides an abstract class for this called ModEntryPoint in the SALT namespace. SALT will auto-detect a class extending ModEntryPoint and run the code found in certain methods inside it, PreLoad, Load, and PostLoad
The sample mods ModEntryPoint code can be found here:
using SALT;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace MyFirstMod
{
public class Main : ModEntryPoint
{
// THE EXECUTING ASSEMBLY
public static Assembly execAssembly;
// Called before MainScript.Awake
// You want to register new things and enum values here, as well as do all your harmony patching
public override void PreLoad()
{
// Gets the Assembly being executed
execAssembly = Assembly.GetExecutingAssembly();
HarmonyInstance.PatchAll(execAssembly);
}
// Called before MainScript.Start
// Used for registering things that require a loaded gamecontext
public override void Load()
{
}
// Called after all mods Load's have been called
// Used for editing existing assets in the game, not a registry step
public override void PostLoad()
{
}
// Called when the reload command/button is used
// Configs are reloaded right before this.
public override void ReLoad()
{
}
// Called when the game is exited
public override void UnLoad()
{
}
// Called every frame, if ModLoader.CurrentLoadingStep equals LoadingStep.FINISHED
public override void Update()
{
}
// Called every fixed frame-rate frame, if ModLoader.CurrentLoadingStep equals LoadingStep.FINISHED
public override void FixedUpdate()
{
}
// Called every frame after all mods' Update functions have been called, if ModLoader.CurrentLoadingStep equals LoadingStep.FINISHED
public override void LateUpdate()
{
}
}
}
You can use it as a template for your ModEntryPoints (completely replace the text in Class1 with this, and rename Class1.cs to Main.cs)
Once you have your modinfo.json and your ModEntryPoint, it's time to build and test your mod! To build a project in visual studio you can click on the Build tab at the top of the screen and select Build Solution
If you did everything correctly, you should see Build Succeeded at the bottom of your screen
To access the results of your build, right click on the project, select Open Folder in File Explorer
and navigate to bin/Debug
In there, you should see your compiled mods DLL, in this case called MyFirstMod.dll as by default the output DLL has the same name as the name of your mod project.
Now, to test your mod, simply drag and drop the dll into your SALT/Mods
folder, and start the game.
Then congratulations! You just made your first mod for SALT! To make it do something, read the rest of this wiki.
Happy modding