Skip to content

Commit

Permalink
Merge pull request #1 from CitiesSkylinesMods/v1.1
Browse files Browse the repository at this point in the history
Compatibility improvements with Harmony mod
  • Loading branch information
krzychu124 authored Jan 31, 2021
2 parents 0212296 + 7ecd37e commit 5393c81
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 36 deletions.
37 changes: 37 additions & 0 deletions TrolleybusTrailerMod/Patcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Reflection;
using ColossalFramework.UI;
using HarmonyLib;
using UnityEngine;

namespace TrolleybusTrailerMod {
public static class Patcher {
private const string HarmonyId = "krzychu124.trolleybus.trailer.ai";
private static bool patched;
public static void PatchAll() {
try {
Harmony harmony = new Harmony(HarmonyId);
harmony.PatchAll(Assembly.GetExecutingAssembly());
Debug.Log("[Trolleybus Trailer AI] Patches applied correctly");
patched = true;
} catch (Exception e) {
Debug.LogError("[Trolleybus Trailer AI] Exception while patching game:\n" + e);
UIView.library
.ShowModal<ExceptionPanel>(
"ExceptionPanel")
.SetMessage(
"Trolleybus Trailer AI ",
"Something went wrong while patching. :(\nMod will not work correctly. Contact author for support.",
true);
}
}

public static void UnPatchAll() {
if (!patched) return;
Harmony harmony = new Harmony(HarmonyId);
harmony.UnpatchAll(HarmonyId );
patched = false;
Debug.Log("[Trolleybus Trailer AI] UnPatched successfully");
}
}
}
2 changes: 1 addition & 1 deletion TrolleybusTrailerMod/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.1.*")]
37 changes: 8 additions & 29 deletions TrolleybusTrailerMod/TrolleybusTrailerMod.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
using System;
using System.Reflection;
using ColossalFramework.UI;
using HarmonyLib;
using CitiesHarmony.API;
using ICities;
using UnityEngine;

namespace TrolleybusTrailerMod {
public class TrolleybusTrailerMod: IUserMod {
public class TrolleybusTrailerMod : IUserMod {
public string Name { get; } = "Trolleybus Trailer AI";
public string Description { get; } = "Support Trolleybus trailers with poles at any trailer";

public readonly string HARMONY_ID = "krzychu124.trolleybus.trailer.ai";
private Harmony _harmony;

public void OnEnabled() {
if (CitiesHarmony.API.HarmonyHelper.IsHarmonyInstalled) {
CitiesHarmony.API.HarmonyHelper.DoOnHarmonyReady(() => {
Debug.Log("[Trolleybus Trailer AI] Applying patches...");
_harmony = new Harmony(HARMONY_ID);
try {
_harmony.PatchAll(Assembly.GetExecutingAssembly());
Debug.Log("[Trolleybus Trailer AI] Patches applied correctly");
} catch (Exception e) {
Debug.LogError("[Trolleybus Trailer AI] Exception while patching game:\n" + e);
UIView.library
.ShowModal<ExceptionPanel>(
"ExceptionPanel")
.SetMessage(
"Trolleybus Trailer AI ",
"Something went wrong while patching. :(\nMod will not work correctly. Contact author for support.",
true);
}
HarmonyHelper.DoOnHarmonyReady(() => {
Debug.Log("[Trolleybus Trailer AI] Try Patch...");
Patcher.PatchAll();
});
}
}

public void OnDisabled() {
if (_harmony != null) {
Debug.Log("[Trolleybus Trailer AI] UnPatching...");
_harmony.UnpatchAll(HARMONY_ID);
if (HarmonyHelper.IsHarmonyInstalled) {
Debug.Log("[Trolleybus Trailer AI] Try UnPatch...");
Patcher.UnPatchAll();
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions TrolleybusTrailerMod/TrolleybusTrailerMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Lib.Harmony.2.0.1\lib\net35\0Harmony.dll</HintPath>
<Reference Include="0Harmony, Version=2.0.4.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Lib.Harmony.2.0.4\lib\net35\0Harmony.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\dependencies\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="CitiesHarmony.API, Version=1.0.5.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\CitiesHarmony.API.1.0.5\lib\net35\CitiesHarmony.API.dll</HintPath>
<Reference Include="CitiesHarmony.API, Version=1.0.6.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\CitiesHarmony.API.1.0.6\lib\net35\CitiesHarmony.API.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ColossalManaged, Version=0.3.0.0, Culture=neutral, PublicKeyToken=null">
Expand All @@ -65,6 +65,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AI\TrolleybusTrailerAI.cs" />
<Compile Include="Patcher.cs" />
<Compile Include="Patch\EditorImportTrolleyPolePatch.cs" />
<Compile Include="Patch\EditorMaskDropdownPatch.cs" />
<Compile Include="Patch\TrolleybusPatch.cs" />
Expand Down
4 changes: 2 additions & 2 deletions TrolleybusTrailerMod/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CitiesHarmony.API" version="1.0.5" targetFramework="net35" />
<package id="Lib.Harmony" version="2.0.1" targetFramework="net35" />
<package id="CitiesHarmony.API" version="1.0.6" targetFramework="net35" />
<package id="Lib.Harmony" version="2.0.4" targetFramework="net35" />
</packages>

0 comments on commit 5393c81

Please sign in to comment.