forked from bloodypenguin/Skylines-MetroOverhaulMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatchCreateBuilding.cs
61 lines (60 loc) · 3.04 KB
/
PatchCreateBuilding.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
55
56
57
58
59
60
61
using ColossalFramework;
using Harmony;
using MetroOverhaul.Extensions;
using MetroOverhaul.OptionsFramework;
using MetroOverhaul.UI;
using System;
using System.Linq;
using System.Reflection;
using static MetroOverhaul.StationTrackCustomizations;
namespace MetroOverhaul
{
class PatchCreateBuilding
{
private static MetroStationCustomizerUI m_Container2;
public static void Apply(HarmonyInstance harmony, ref MetroStationCustomizerUI ui)
{
m_Container2 = ui;
var postfix = typeof(PatchCreateBuilding).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(BuildingManager)
.GetMethods().First(m => m.Name == "UpdateBuilding" && !m.IsGenericMethod);
public static void Postfix(ushort building)
{
try
{
var buildingData = Singleton<BuildingManager>.instance.m_buildings.m_buffer[building];
if (buildingData.Info != null)
{
if (buildingData.Info.HasUndergroundMetroStationTracks())
{
if (m_Container2 != null)
{
Singleton<BuildingManager>.instance.m_buildings.m_buffer[building].m_happiness = StoreCustomization(MetroStationTrackAlterType.Length);
Singleton<BuildingManager>.instance.m_buildings.m_buffer[building].m_health = StoreCustomization(MetroStationTrackAlterType.Depth);
Singleton<BuildingManager>.instance.m_buildings.m_buffer[building].m_children = StoreCustomization(MetroStationTrackAlterType.Length);
Singleton<BuildingManager>.instance.m_buildings.m_buffer[building].m_childHealth = StoreCustomization(MetroStationTrackAlterType.Depth);
Singleton<BuildingManager>.instance.m_buildings.m_buffer[building].m_seniors = StoreCustomization(MetroStationTrackAlterType.Rotation);
Singleton<BuildingManager>.instance.m_buildings.m_buffer[building].m_seniorHealth = StoreCustomization(MetroStationTrackAlterType.Curve);
Singleton<BuildingManager>.instance.m_buildings.m_buffer[building].m_teens = (byte)m_Container2.m_TrackType;
}
}
}
}
catch (Exception e)
{
UnityEngine.Debug.LogError(e);
}
}
private static byte StoreCustomization(MetroStationTrackAlterType customizationType)
{
return (byte)((m_Container2.SetDict[customizationType] - m_Container2.SliderDataDict[customizationType].Min) / m_Container2.SliderDataDict[customizationType].Step);
}
}
}