Setting up a work environment for creating Cement mods - HueSamai/CementSource GitHub Wiki
This page covers a good workflow for creating mods for Gang Beasts, using Cement. This isn't the only workflow you can use, but I think it makes your life the easiest.
To briefly explain, we are going to create a solution to house all of our Mod C# projects, and also make all of our Mods be stored in the same GitHub repo.
We are going to be using a program called Visual Studio to program in and to manage our mod files.
To download Visual Studio, go here.
The programming language we are going to be using is C#, because it is the language Gang Beasts is written in, and for it to work we need to install the .NET framework. You can install that here.
Open Visual Studio, and select the 'Create a new project' option on the right.
Then you want to select the 'Class Library' option, and click 'Next', in the bottom right corner.
Then fill out on the following page, your project name (the name of your Mod), your solution name (your solution houses all of your Mods, so it can be called something like MyCementMods, ModProjects, or anything else you find fitting), and then you can select a location, where your projects will be stored. Click 'Next'.
On the next page, you will see a drop down of which .NET framework you want to use. Select '.NET standard 2.0'.
Then click 'Create'. It will take a bit to create your project, just wait.
Once it's done you should see a screen like this:
And boom! You've created a project!
Our project still needs to be setup, however, so check the below section 'Managing mod projects' so that you can setup your project correctly, to start developing mods.
Right click on your project.
Your project is the item in the solution explorer which has the C# in the box next to the name:
NOTE:: if you can't find the solution explorer, click on 'View' right at the top of the Visual Studio window, next to 'Edit' and 'Git', and then click on 'Solution Explorer'.
Then click 'Add', and then on 'New Folder...'.
And call it: "build". Make sure it is spelled EXACTLY the same.
Now double click on your project on the left in the solution explorer, and paste the following lines of code before the </Project>
but after the </ItemGroup>
:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="COPY "$(TargetPath)" build" />
</Target>
It should look like this:
This will just make it so that our '.DLL' (Dynamic Linked Library), the file that contains all the code of our mod, is in an easier to access location, so that it makes setting up our Cement file a bit easier.
You are going to need to add dependencies, so that your project can access the code from other projects, especially from Cement and Gang Beasts. Adding a dependency just tells Visual Studio you want to use the code from a source, and also when Cement loads in your mod, it knows which other sources of code it must add.
I'm going to go through the process of adding the required Gang Beasts '.dll's, and the 'Cement.dll', which contains the source code of Cement, but the process for adding another dependency is the same.
Start by finding the project you want to add a dependency to in the solution explorer, and going to 'Dependencies'.
Then right click on it and select, 'Add project reference'.
On the menu that popped up, select 'Browse'.
Locate your Gang Beasts folder, go into the 'Gang Beasts_Data', and then the 'Managed' folder, and select the 'Assembly-CSharp.dll' file.
You also want to scroll down, hold in control (to select multiple files), and select the 'UnityEngine.CoreModule.dll', as well as the 'UnityEngine.dll' file.
Then you can click 'Add', in the bottom right.
NOTE: If you ever get an error saying you are missing a dependency, you will most probably find the '.dll' file in the 'Managed' folder. All of the Unity modules, for Physics, UI, Audio, etc. are found in this folder, and if you want to work with those things, you will need to add those dependencies.
Then to add the 'Cement.dll', click 'Browse' again, and go back to your Gang Beasts' folder, but this time, go into your 'BepInEx' folder, then 'plugins', then 'Cement', and then select the 'Cement.dll' file, and click 'Add' in the bottom right.
We're also going to have to add the 'BepInEx.dll' file, so similar to the other times, click 'Browse' then go to your Gang Beasts' folder and go to the 'BepInEx' folder again, but then into 'core', and then select the 'BepInEx.dll' file and click 'Add'.
You should have five '.dll' files added as dependencies now. If you don't go, back and read again to make sure you added all of them.
Now you can click 'Ok', and then wait a bit for the menu to disappear and the '.dll' files to be added as dependencies.
We need to add helper files for our Cement mod, which will be hosted somewhere online, so that Cement can access information of our mods, such as the Latest version of our mods, to know if it should install a later version, the message to display when our mod is loaded, and the latest version of the Cement file for our mod, so that if we ever add new dependencies or parameters, the cement file gets updated automatically.
You should go here to read more about Cement files, and how they are read by Cement, so that you know what you need for your mod to work.
To Add any file, right click on the Project you want to add the file to, then click on 'Add', and then 'New Item...'.
A menu will pop up with a list of options to pick from. Pick the 'Text File' one.
If you can't find the 'Text File' option, you can always search for it in the top right.
At the bottom there will be a field to enter a name for your text file, as well as an extension. Any extension will work here, except for no extension. If no extension is provided it will default to '.txt'.
When you've given your file the name and extension, you can click 'Add', in the bottom right.
Now let's create all the files we need. You don't have to do them in any specific order.
- You need to create a file to store the Latest Version of your mod. This can be called anything but I usually call mine 'version.txt'
- You need to create a file to store the message that your mod displays. I usually call this 'message.txt'.
NOTE: You don't actually need to a file for the message of your mod, but it is better practice to have one, in case you want to change it. Otherwise you can just have a static message in the Cement file. Also if your message file is modified, you don't need to publish a new version of the mod, because Cement fetches the message every time it loads the game, so it will automatically update, without you issuing a new version. Don't worry if you don't know how to publish a new version, it will be discussed later on.
- You need to create a cement file. This file MUST have the '.cmt' extension, so when adding a file, make sure you delete the '.txt' extension and give it a '.cmt' one. The name of this file can be anything, but obviously it would be the best practice to call it the name of your mod.
Now we're all done with adding all the files we need! We still need to fill out their contents, but in order to do that you need to read the section on 'Hosting files on GitHub' first, and then return here. If you've already setup a GitHub repo for your project, then you don't need to do it again.
The version and message files are easy to fill out.
The message file can contain anything you'd like, but best practice is to include a description of what the mod does and instructions if they are needed.
The version file should just contain the latest version of the mod. This is so that Cement knows when it should be updated. If you read the Cement file wiki page you will know there is a CurrentVersion parameter that Cement uses to keep track of the version installed of the mod. Cement fetches the latest version from the file given in the Cement file and checks to see if it matches the current version of the mod installed. If they don't match, the mod is installed again to update it, and then the CurrentVersion parameter is updated by copying over the new contents of the version file into the CurrentVersion parameter. So if you want to update your mod, and make sure that everybody gets the new update, you just need to change the contents of the version file.
You can use any version scheme, as long as a version name never repeats. I use semantic versioning, where there are three parts to the current version, for example: "1.0.0" or "0.2.0", where the digits encode for Major.Minor.Patch. So if a major change is made, the major part will increment, if the minor change is made the minor part will be incremented, and so on. But you can also just use plain old numbers: the version starts at "1", then the next update will be "2", and so on. Anything works here. Just make sure old version names don't repeat, because it will lead to cases where somebody with an older version might not have their mod updated.
Now for filling out the Cement file. I'm not going to go over all the parameters, just the major ones. Make sure you read the Cement file wiki page before continuing.
The fields I'm going to go over are: 'LatestVersion', 'Message', 'CementFile', and 'Links'
In order to fill out these fields you need to have your file hosted somewhere. In this tutorial we will be covering how to fill out these fields if your files are hosted on GitHub.
We need to supply links to the files we are using. If we are hosting on GitHub all our links will look like this:
https://github.com/{your github username}/{the name of your repo}/raw/{the name of the branch you are using}/
{the name of your mod}/{the path to the file you want}
If you look at the link, you will see there is a "raw" hidden in there. This tells GitHub to just send the raw data of the file and not all the website's contents, which is exactly what we want.
The first part of the link will stay the same for all your links for your Cement file, except the last little bit of the path to the file. So let's fill out the whole first part of the link. For me it will look like this:
https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/
This is everything except the last path to the file I want. You might not know what to fill in for the branch name, if you followed this tutorial on making a GitHub repo, you should use 'master', like I did. We will discuss branches later, because we will need to create another branch of our project to test our mod, once we've already published it. For now, all you need to know are branches are just different "versions" of your project.
Now once we have our base link we can just add the paths to our different files. All the paths are just the paths relative to our mod's directory. So for the version, since my file is just called 'version.txt' and is in the root folder, I'm just going to add 'version.txt' to the end of my base link. So it becomes:
https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/version.txt
As you can see in the photo, my 'version.txt' file is in the root mod folder.
The same is true for my 'message.txt' file, so I can just add 'message.txt' to my base link:
https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/message.txt
But now if we want to create a link for our '.DLL' we can't just add the name of our file to the end, because it is in the build directory/folder. So we must add: build/{name of your mod}.dll
NOTE: if you don't have a .DLL file it's because you haven't built your mod yet. Don't worry, just use the same name as your project name, and then just add '.dll' to it, or right click on your project in the solution explorer and click on "Build" and if that doesn't work, "Rebuild".
Mine becomes:
https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/build/TutorialMod.dll
The 'TutorialMod.dll' file is not in the root directory, but under the build directory.
With the same process I can figure out the link to my Cement file is:
https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/TutorialMod.cmt
Hopefully you can now make links of your own without the need of my help, but you can always return this guide if you are struggling. We can now use these links to add values to our Cement file.
This is now the contents of my Cement file after filling out all the info:
Name=Tutorial Mod
Author=dotpy
Links=https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/build/TutorialMod.dll
CementFile=https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/TutorialMod.cmt
Message=https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/message.txt
LatestVersion=https://github.com/HueSamai/TutorialModsSolution/raw/master/TutorialMod/version.txt
Yours should look similar.
Okay but before going, we still need to push our changes to GitHub, because if we created these files on our machine it doesn't automatically create them on GitHub, so remember to push your changes to GitHub. Look in the below section to see how to do that, if you don't know or can't remember.
To create a new mod project in your solution, right click on your solution in the Solution Explorer on the left, or click on File in the menu at the top, on the left.
Then select 'Add', and 'New Project'. The menus will be similar to the above 'Creating a solution and project' section.
You must select a 'Class Library' project, like before, then click 'Next'. There won't be a solution name field, so just fill out the project name, which is the name of your mod, and DON'T change the location, then click 'Next', and then 'Create', on the next page.
Now repeat all the previously discussed steps to setup your mod project. Yes you're going to have to add all the dependencies again, and create a build folder, but you won't have to setup a GitHub repo.
In order for our Cement files to work, we need a site to host them on. GitHub is a very good choice, and also has version control, as well as allowing multiple creators to collaborate. If you don't know how Cement files work, click here to go to the wiki page on them. You only need to setup a GitHub repo once, for your whole solution, so only when you create your first mod. After that, it will be setup for all your other mods you create in that solution.
Firstly you need to go to GitHub, the site you are currently on, and create an account. Then go here to download git, which allows you to publish changes to GitHub.
Then in Visual Studio, click on 'Git', at the top, and then 'Create Git Repository...'. This will create a new repository, to which we can upload our mod files to, for ALL our mods. Therefore, we can have all our mods in on place instead of having a new repo, for every single mod we make.
Make sure on the left you select 'GitHub' as the remote location.
IMPORTANT! Make sure 'Private repository' is UNCHECKED. You NEED your repo to be public, otherwise Cement won't be able to access them and therefore won't be able to download them.
Under account, if you don't have any account selected, click on the button next to 'Account' and then click on 'Add a new account', it will ask to open your browser, and then might want you to log in to GitHub, and also click on an Allow button, to allow Visual Studio to access some parts of your account. This is just so that Visual Studio can push files to GitHub for you.
Then click on 'Create and Push' in the bottom right of the menu.
We need a way to actually upload the files to GitHub. It will automatically upload all the files in their current state when we first create the repo, but not constantly update them automatically. To update them we need to go to the 'Git' menu.
To do this, click on 'Git' at the top of the Visual Studio window, next to 'View' and 'Project', and then select 'Commit or Stash...'.
A new menu will pop up on the side, which will allow you to stage changes, which basically means select the changes you want to be committed and then pushed up to GitHub, and then commit and push those changes to GitHub.
You can stage a specific change to a file by hovering over that file then clicking the '+' button next to it.
If you want to stage all the changes you made, then just click the '+' button next to the 'Changes' heading.
If you want to change the branch you are committing to, you can click on the drop down box which has the name of the current branch right at the top of the menu, and then select a different branch, if there is one, or create a new branch by clicking on the 'New Branch' button. This allows you to either make changes to the development branch or the main branch, once you want to publish an update.
If you are creating a new branch just fill out the name of the branch in the popup that appears, and then click 'Create'.
NOTE: if you don't know exactly what are branches and are a bit confused just leave the branch as it was. Only change it if you know what they are used for.
Then you can type in a message for what changes you made in the message field, and when you are ready click the 'Commit Staged' button.
If it was successful the message and changes should disappear and a message in a yellow box should appear that says: 'Commit created locally'
Committing will only create a new version of your project on your side (that's why it says Commit created locally) but it won't update on GitHub yet. To do that, we must click on the up arrow next to 'master', which is labelled 'Push', when we hover over it.
After clicking it, it will take a while to upload all the changes before a new message in a yellow box will appear to say the push was a success.
You can now click on the 'x' at the top right of the menu, to close it and return to the solution explorer.