generated from Captain-Of-Coit/cities-skylines-2-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c91cc8c
Showing
13 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: mycoolmod-ci | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
tags: [ "v*" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
bepinex-version: [5, 6] | ||
steps: | ||
- name: Checkout source | ||
uses: actions/checkout@v3 | ||
- name: Checkout libcs2 | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: Captain-Of-Coit/libcs2 | ||
token: ${{ secrets.GH_PAT }} | ||
path: libcs2/ | ||
- name: Install .NET Core | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 6.0.x | ||
- name: Build (BepInEx ${{ matrix.bepinex-version }}) | ||
run: make package-unix BEPINEX_VERSION=${{ matrix.bepinex-version }} | ||
- name: Upload Artifact (BepInEx ${{ matrix.bepinex-version }}) | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: built-code-${{ matrix.bepinex-version }} | ||
path: dist/*.dll | ||
publish: | ||
needs: build | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout source | ||
uses: actions/checkout@v3 | ||
- name: Download built artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: built-code-5 | ||
path: dist/ | ||
- name: Debug | ||
run: ls && ls dist/ | ||
- name: Download tcli | ||
run: | | ||
curl -L https://github.com/thunderstore-io/thunderstore-cli/releases/download/0.2.1/tcli-0.2.1-linux-x64.tar.gz -o tcli.tar.gz | ||
tar -xzf tcli.tar.gz | ||
- name: Publish with tcli | ||
run: ./tcli-0.2.1-linux-x64/tcli publish --token=${{ secrets.TS_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist/ | ||
bin/ | ||
obj/ | ||
ts-build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 0.1.0 | ||
|
||
Initial Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
MyCoolMod - Copyright <Year> <Author> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
Cities: Skylines 2 Mod Template - Copyright 2023 Captain-Of-Coit | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
all: build | ||
BEPINEX_VERSION = 6 | ||
|
||
clean: | ||
@dotnet clean | ||
|
||
restore: | ||
@dotnet restore | ||
|
||
build: clean restore | ||
@dotnet build /p:BepInExVersion=$(BEPINEX_VERSION) | ||
|
||
package-win: | ||
@-mkdir dist | ||
@cmd /c copy /y "bin\Debug\netstandard2.1\0Harmony.dll" "dist\" | ||
@cmd /c copy /y "bin\Debug\netstandard2.1\MyCoolMod.dll" "dist\" | ||
@echo Packaged to dist/ | ||
|
||
package-unix: build | ||
@-mkdir dist | ||
@cp bin/Debug/netstandard2.1/0Harmony.dll dist | ||
@cp bin/Debug/netstandard2.1/MyCoolMod.dll dist | ||
@echo Packaged to dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<!-- | ||
Base csproj setup. Change the AssemblyName, RootNamespace and Description to | ||
accurately describe your mod. | ||
Increment the Version property when you release a new version. | ||
--> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<AssemblyName>MyCoolMod</AssemblyName> | ||
<RootNamespace>MyCoolMod</RootNamespace> | ||
<Description>A mod that I made for Cities: Skylines 2</Description> | ||
<Version>0.1.0</Version> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<LangVersion>latest</LangVersion> | ||
<RestoreAdditionalProjectSources> | ||
https://api.nuget.org/v3/index.json; | ||
https://nuget.bepinex.dev/v3/index.json; | ||
https://nuget.samboy.dev/v3/index.json | ||
</RestoreAdditionalProjectSources> | ||
<!-- Copies references we make to 3rd party library for distributions --> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
<!-- Suppress the version conflict warnings for System.Net.Http and System.IO.Compression --> | ||
<NoWarn>MSB3277</NoWarn> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
Uncomment this PropertyGroup to let the C# project read DLLs directory from your game directory, | ||
and also allow the build to move the mod DLLs into the plugins directory for you | ||
--> | ||
<PropertyGroup> | ||
<Cities2_Location>C:\Program Files (x86)\Steam\steamapps\common\Cities Skylines II</Cities2_Location> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
This is all the references to the DLLs directly from your game directory. The Cities2_Location property | ||
above needs to be uncommented for this to work | ||
--> | ||
<ItemGroup> | ||
<Reference Include="$(Cities2_Location)\Cities2_Data\Managed\Colossal.*.dll" Private="False"/> | ||
<Reference Include="$(Cities2_Location)\Cities2_Data\Managed\Game.dll" Private="False"/> | ||
<Reference Include="$(Cities2_Location)\Cities2_Data\Managed\Unity.*.dll" Private="False"/> | ||
</ItemGroup> | ||
|
||
<!-- | ||
If you want to embed things directly into your mod, instead of shipping multiple files | ||
<ItemGroup> | ||
<EmbeddedResource Include="./resources/my_pretty_embedded_image.jpg" /> | ||
</ItemGroup> | ||
--> | ||
|
||
<!-- | ||
This ItemGroup is used in CI for the game DLLs. | ||
Make sure you have a private `libcs2` repository with the appropriate DLLs for this to work. | ||
DO NOT make the proprietary DLLs for the game public, as the files are owned by PDX/CO. | ||
--> | ||
<ItemGroup> | ||
<Reference Include="libcs2/Colossal.*.dll" Private="False"/> | ||
<Reference Include="libcs2/Game.dll" Private="False"/> | ||
<Reference Include="libcs2/Unity.*.dll" Private="False"/> | ||
</ItemGroup> | ||
|
||
<!-- | ||
Everything related to BepInEx and Harmony | ||
--> | ||
<ItemGroup> | ||
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.0.0" /> | ||
<PackageReference Include="HarmonyX" Version="2.10.2"></PackageReference> | ||
<PackageReference Include="UnityEngine.Modules" Version="2022.3.7" IncludeAssets="compile" /> | ||
</ItemGroup> | ||
|
||
<!-- Set the default value for BepInExVersion --> | ||
<PropertyGroup> | ||
<BepInExVersion Condition="'$(BepInExVersion)' == ''">5</BepInExVersion> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
These ItemGroups and PropertyGroups gives you compatibility with both BepInEx 5 and 6. | ||
Mainly for the purposes of being able to distribute your mods on Thunderstore, and | ||
making it easy to upgrade in the future to proper versions. | ||
--> | ||
<ItemGroup Condition="'$(BepInExVersion)' == '6'"> | ||
<PackageReference Include="BepInEx.Unity.Mono" Version="6.0.0-be.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(BepInExVersion)' == '5'"> | ||
<PackageReference Include="BepInEx.Core" Version="5.4.21" IncludeAssets="compile"/> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition="'$(BepInExVersion)' == '6'"> | ||
<DefineConstants>$(DefineConstants);BEPINEX_V6</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'"> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" | ||
PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<!-- | ||
This will try to copy the resulting DLLs from builds directly into your game directory, | ||
as long as we're not in CI | ||
--> | ||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(CI)' != 'true'"> | ||
<Exec | ||
Command="if not exist "$(Cities2_Location)\BepInEx\plugins\$(ProjectName)" mkdir "$(Cities2_Location)\BepInEx\plugins\$(ProjectName)"
copy /Y "$(TargetDir)0Harmony.dll" "$(Cities2_Location)\BepInEx\plugins\$(ProjectName)\0Harmony.dll"
copy /Y "$(TargetDir)$(ProjectName).dll" "$(Cities2_Location)\BepInEx\plugins\$(ProjectName)\$(ProjectName).dll"" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Colossal.UI; | ||
using Game.SceneFlow; | ||
using Game.Audio; | ||
using Game.UI.Menu; | ||
using HarmonyLib; | ||
using System.Reflection.Emit; | ||
using Game; | ||
using MyCoolMod.Systems; | ||
|
||
namespace MyCoolMod.Patches { | ||
|
||
// This example patch adds the loading of a custom ECS System after the AudioManager has | ||
// its "OnGameLoadingComplete" method called. We're just using it as a entrypoint, and | ||
// it won't affect anything related to audio. | ||
[HarmonyPatch(typeof(AudioManager), "OnGameLoadingComplete")] | ||
class AudioManager_OnGameLoadingComplete | ||
{ | ||
static void Postfix(AudioManager __instance, Colossal.Serialization.Entities.Purpose purpose, GameMode mode) | ||
{ | ||
if (!mode.IsGameOrEditor()) | ||
return; | ||
|
||
// Here we add our custom ECS System to the game's ECS World, so it's "online" at runtime | ||
__instance.World.GetOrCreateSystem<MyCoolModSystem>(); | ||
} | ||
} | ||
|
||
// This example patch enables the editor in the main menu | ||
[HarmonyPatch(typeof(MenuUISystem), "IsEditorEnabled")] | ||
class MenuUISystem_IsEditorEnabledPatch | ||
{ | ||
static bool Prefix(ref bool __result) | ||
{ | ||
__result = true; | ||
|
||
return false; // Ignore original function | ||
} | ||
} | ||
// Thanks to @89pleasure for the MenuUISystem_IsEditorEnabledPatch snippet above | ||
// https://github.com/89pleasure/cities2-mod-collection/blob/71385c000779c23b85e5cc023fd36022a06e9916/EditorEnabled/Patches/MenuUISystemPatches.cs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.IO.Compression; | ||
using System.IO; | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using BepInEx; | ||
using HarmonyLib; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
#if BEPINEX_V6 | ||
using BepInEx.Unity.Mono; | ||
#endif | ||
|
||
namespace MyCoolMod | ||
{ | ||
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] | ||
public class Plugin : BaseUnityPlugin | ||
{ | ||
private void Awake() | ||
{ | ||
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!"); | ||
|
||
var harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), MyPluginInfo.PLUGIN_GUID + "_Cities2Harmony"); | ||
var patchedMethods = harmony.GetPatchedMethods().ToArray(); | ||
|
||
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} made patches! Patched methods: " + patchedMethods.Length); | ||
|
||
foreach (var patchedMethod in patchedMethods) { | ||
Logger.LogInfo($"Patched method: {patchedMethod.Module.Name}:{patchedMethod.Name}"); | ||
} | ||
} | ||
|
||
// Keep in mind, Unity UI is immediate mode, so OnGUI is called multiple times per frame | ||
// https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnGUI.html | ||
private void OnGUI() { | ||
GUI.Label(new Rect(10, 10, 300, 20), $"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Cities: Skylines 2 - C# Mod template | ||
|
||
This repository template allows you to get started with Cities: Skylines 2 modding easily, all the way to building your mod on commit with GitHub Actions and publishing your mod automatically on Thunderstore. | ||
|
||
- [Requirements](#requirements) | ||
- [Usage](#usage) | ||
- [Renaming your project](#renaming-your-project) | ||
- [Set license details](#set-license-details) | ||
- [Incrementing version number](#incrementing-version-number) | ||
- [CI / GitHub Actions - Setup](#ci-github-actions-setup) | ||
- [Regarding BepInEx version 5 (Stable) VS 6 (Alpha/Unstable/Nightly)](#regarding-bepinex-version-5-stable-vs-6-alphaunstablenightly) | ||
- [Credits](#credits) | ||
- [Community](#community) | ||
|
||
# Requirements | ||
|
||
- [Cities: Skylines 2](https://store.steampowered.com/app/949230/Cities_Skylines_II/) (duh) | ||
- [BepInEx 5.4.22](https://github.com/BepInEx/BepInEx/releases) or later | ||
- (Optional) [dotnet-script](https://github.com/dotnet-script/dotnet-script) (for `rename.csx` helper script) | ||
- Installation `dotnet tool install -g dotnet-script` | ||
|
||
# Usage | ||
|
||
- Create a new repository based on this one | ||
- Clone your new repository to your computer | ||
- Uncomment and update the `Cities2_Location` variable in `MyCoolMod.csproj` | ||
- Run `make build` | ||
|
||
After running the last command, the mod should be automatically copied to your game directory, | ||
so launching the game should include running the mod you just started :) | ||
|
||
# Renaming your project | ||
|
||
You can leverage the helper script in `scripts/rename.csx` in order to replace "MyCoolMod" with whatever you want to name your project. Usage: | ||
|
||
``` | ||
$ dotnet script scripts\rename.csx "MyCoolMod" "AnotherModIMade" | ||
``` | ||
|
||
# Set license details | ||
|
||
You'll need to update `LICENSE` with the correct details for `<Year>` and `<Author>`, and change "MyCoolMod" to your mod name if you haven't already. | ||
|
||
# Incrementing version number | ||
|
||
- Update `.csproj` file with new version number | ||
- Update `thunderstore.toml` file with new version number | ||
- Update `CHANGELOG` to describe the changes you've made between this and previous version | ||
- Commit version bump | ||
- Do a git tag with the new version number | ||
- `git tag -a v0.2.0 -m v0.2.0` | ||
- Push your changes + tags | ||
- `git push origin master --tags` | ||
|
||
# CI / GitHub Actions - Setup | ||
|
||
In order to get the CI/GitHub Actions workflow to work, you have to do a couple of things. | ||
|
||
- Create a new private repository with all the game DLLs that you require for building your mod | ||
- Create a new GitHub Personal Access Token ("PAT") that has only READ access to the created private repository | ||
- Create a new secret variable in GitHub Actions called `GH_PAT` that has your PAT with read access to the private repository | ||
|
||
Now the CI job should work as expected :) | ||
|
||
# Regarding BepInEx version 5 (Stable) VS 6 (Alpha/Unstable/Nightly) | ||
|
||
Currently, this mod template defaults to building against BepInEx version 6 (unstable pre-release). If you'd like to instead use Stable BepInEx version 5, you can run the build like this: | ||
|
||
``` | ||
$ make build BEPINEX_VERSION=5 | ||
``` | ||
|
||
In order to run code only for one BepInEx version, you can do something like this: | ||
|
||
``` | ||
#if BEPINEX_V6 | ||
using BepInEx.Unity.Mono; | ||
#endif | ||
``` | ||
|
||
That would only run `using BepInEx.Unity.Mono` when you're building the project for BepInEx 6. Add in a `else` if you want to do something different when it's version 5. | ||
|
||
# Credits | ||
|
||
- Thanks to Cities Skylines 2 Unofficial Modding Discord | ||
- Particular thanks to [@StudioLE](https://github.com/StudioLE) who helped with feedback and improving .csproj setup | ||
|
||
# Community | ||
|
||
Looking to discuss Cities: Skylines 2 Unofficial modding together with other modders? You're welcome to join our "Cities 2 Modding" Discord, which you can find here: https://discord.gg/vd7HXnpPJf |
Oops, something went wrong.