-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRealConstructionThreading.cs
More file actions
100 lines (94 loc) · 3.94 KB
/
RealConstructionThreading.cs
File metadata and controls
100 lines (94 loc) · 3.94 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 ICities;
using System;
using System.Reflection;
using RealConstruction.Util;
using RealConstruction.UI;
using RealConstruction.CustomManager;
using ColossalFramework.UI;
using HarmonyLib;
namespace RealConstruction
{
public class RealConstructionThreading : ThreadingExtensionBase
{
public static bool isFirstTime = true;
public const int HarmonyPatchNum = 9;
public override void OnBeforeSimulationFrame()
{
base.OnBeforeSimulationFrame();
if (Loader.CurrentLoadMode == LoadMode.LoadGame || Loader.CurrentLoadMode == LoadMode.NewGame)
{
if (RealConstruction.IsEnabled)
{
CheckDetour();
}
}
}
public override void OnAfterSimulationFrame()
{
base.OnAfterSimulationFrame();
if (Loader.CurrentLoadMode == LoadMode.LoadGame || Loader.CurrentLoadMode == LoadMode.NewGame)
{
uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
int num4 = (int)(currentFrameIndex & 255u);
if (RealConstruction.IsEnabled)
{
BuildingManager instance = Singleton<BuildingManager>.instance;
if (num4 == 255)
{
PlayerBuildingUI.refeshOnce = true;
UniqueFactoryUI.refeshOnce = true;
UniqueFactoryButton.refeshOnce = true;
WarehouseButton.refeshOnce = true;
WareHouseUI.refeshOnce = true;
PlayerBuildingButton.refeshOnce = true;
}
//CustomSimulationStepImpl for 124 125 TransferReason
CustomTransferManager.CustomSimulationStepImpl();
}
}
}
public void CheckDetour()
{
if (isFirstTime && Loader.HarmonyDetourInited)
{
isFirstTime = false;
if (Loader.HarmonyDetourFailed)
{
string error = "RealConstruction HarmonyDetourInit is failed, Send RealConstruction.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 = $"RealConstruction HarmonyDetour Patch Num is {i}, Right Num is {HarmonyPatchNum} Send RealConstruction.txt to Author.";
DebugLog.LogToFileOnly(error);
UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", error, true);
}
}
}
}
}
}