-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoreOutsideInteractionThreading.cs
More file actions
100 lines (93 loc) · 4.43 KB
/
MoreOutsideInteractionThreading.cs
File metadata and controls
100 lines (93 loc) · 4.43 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using ColossalFramework;
using ColossalFramework.UI;
using HarmonyLib;
using ICities;
using MoreOutsideInteraction.CustomAI;
using MoreOutsideInteraction.Util;
namespace MoreOutsideInteraction
{
public class MoreOutsideInteractionThreading : ThreadingExtensionBase
{
public static bool isFirstTime = true;
public const int HarmonyPatchNum = 17;
public override void OnBeforeSimulationFrame()
{
base.OnBeforeSimulationFrame();
if (Loader.CurrentLoadMode == LoadMode.LoadGame || Loader.CurrentLoadMode == LoadMode.NewGame)
{
if (MoreOutsideInteraction.IsEnabled)
{
CheckDetour();
}
}
}
public void CheckDetour()
{
if (isFirstTime && Loader.DetourInited)
{
isFirstTime = false;
DebugLog.LogToFileOnly("ThreadingExtension.OnBeforeSimulationFrame: First frame detected. Checking detours.");
if (!Loader.HarmonyDetourInited)
{
string error = "MoreOutsideInteraction HarmonyDetourInit is failed, Send MoreOutsideInteraction.txt to Author.";
DebugLog.LogToFileOnly(error);
UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", error, true);
}
else
{
var harmony = new Harmony(HarmonyDetours.ID);
var methods = harmony.GetPatchedMethods();
int i = 0;
foreach (var method in methods)
{
var info = Harmony.GetPatchInfo(method);
if (info.Owners?.Contains(harmony.Id) == true)
{
DebugLog.LogToFileOnly($"Harmony patch method = {method.FullDescription()}");
if (info.Prefixes.Count != 0)
{
DebugLog.LogToFileOnly("Harmony patch method has PreFix");
}
if (info.Postfixes.Count != 0)
{
DebugLog.LogToFileOnly("Harmony patch method has PostFix");
}
i++;
}
}
if (i != HarmonyPatchNum)
{
string error = $"MoreOutsideInteraction HarmonyDetour Patch Num is {i}, Right Num is {HarmonyPatchNum} Send MoreOutsideInteraction.txt to Author.";
DebugLog.LogToFileOnly(error);
UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", error, true);
}
}
}
}
public override void OnAfterSimulationFrame()
{
base.OnAfterSimulationFrame();
if (Loader.CurrentLoadMode == LoadMode.LoadGame || Loader.CurrentLoadMode == LoadMode.NewGame)
{
if (MoreOutsideInteraction.IsEnabled)
{
uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
int num4 = (int)(currentFrameIndex & 255u);
if (num4 == 255)
{
CustomPlayerBuildingAI.haveCemetryBuilding = CustomPlayerBuildingAI.haveCemetryBuildingTemp;
CustomPlayerBuildingAI.haveFireBuilding = CustomPlayerBuildingAI.haveFireBuildingTemp;
CustomPlayerBuildingAI.havePoliceBuilding = CustomPlayerBuildingAI.havePoliceBuildingTemp;
CustomPlayerBuildingAI.haveHospitalBuilding = CustomPlayerBuildingAI.haveHospitalBuildingTemp;
CustomPlayerBuildingAI.haveGarbageBuilding = CustomPlayerBuildingAI.haveGarbageBuildingTemp;
CustomPlayerBuildingAI.haveCemetryBuildingTemp = false;
CustomPlayerBuildingAI.haveFireBuildingTemp = false;
CustomPlayerBuildingAI.havePoliceBuildingTemp = false;
CustomPlayerBuildingAI.haveHospitalBuildingTemp = false;
CustomPlayerBuildingAI.haveGarbageBuildingTemp = false;
}
}
}
}
}
}