-
Notifications
You must be signed in to change notification settings - Fork 18
Project Setup
Once you have an IDE setup, and SRML installed on an instance of Slime Rancher, 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.7.2 (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.7.2 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 <slime rancher game folder>/SlimeRancher_Data/Managed
as well as <slime rancher game folder>/SRML/Libs
and they include, Assembly-CSharp_old.dll (NOT Assembly-CSharp-firstpass.dll or Assembly-CSharp.dll), SRML.dll, 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 SRML 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": "veesus mikel heir",
"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 SRML
Your first mod is almost ready to run! But first you need to create an entry point for your mod to start execution at. SRML provides an abstract class for this called ModEntryPoint in the SRML namespace. SRML 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 SRML;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyFirstMod
{
public class Main : ModEntryPoint
{
// Called before GameContext.Awake
// You want to register new things and enum values here, as well as do all your harmony patching
public override void PreLoad()
{
HarmonyInstance.PatchAll();
}
// Called before GameContext.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()
{
}
}
}
You can use it as a template for your ModEntryPoints (completely replace the text in Class1 with this, and rename Clas1)
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 SRML/Mods
folder, and start the game.
If you click on Mods button in the main menu and see something similar to this:
Then congratulations! You just made your first mod for SRML! To make it do something, read the rest of this wiki.
Happy modding