This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
forked from bloodypenguin/Skylines-MetroOverhaulMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatchInitializePrefab.cs
54 lines (53 loc) · 2.11 KB
/
PatchInitializePrefab.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Harmony;
using MetroOverhaul.Extensions;
using MetroOverhaul.OptionsFramework;
using System;
using System.Linq;
using System.Reflection;
namespace MetroOverhaul
{
class PatchInitializePrefab
{
private static Initializer m_Container;
public static void Apply(HarmonyInstance harmony, ref Initializer initializer)
{
m_Container = initializer;
var postfix = typeof(PatchInitializePrefab).GetMethod("Postfix");
harmony.Patch(OriginalMethod, null, new HarmonyMethod(postfix), null);
}
public static void Revert(HarmonyInstance harmony)
{
//harmony.Unpatch(OriginalMethod, HarmonyPatchType.Prefix);
harmony.Unpatch(OriginalMethod, HarmonyPatchType.Postfix);
}
public static MethodInfo OriginalMethod => typeof(BuildingInfo)
.GetMethods().First(m => m.Name == "InitializePrefab" && !m.IsGenericMethod);
public static void Postfix(ref BuildingInfo __instance)
{
if (OptionsWrapper<Options>.Options.ingameTrainMetroConverter)
{
try
{
var ai = __instance.GetComponent<TransportStationAI>();
if (ai != null)
{
if (__instance.m_class.m_subService == ItemClass.SubService.PublicTransportTrain || __instance.m_class.m_subService == ItemClass.SubService.PublicTransportMetro)
{
if (__instance.name.IndexOf(ModTrackNames.ANALOG_PREFIX) == -1)
{
if (__instance.HasAbovegroundTrainStationTracks() || __instance.HasAbovegroundMetroStationTracks())
{
m_Container.InitializeBuildingInfoImpl(__instance);
}
}
}
}
}
catch (Exception e)
{
UnityEngine.Debug.LogError(e);
}
}
}
}
}