-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMoreEffectiveTransferThreading.cs
More file actions
92 lines (89 loc) · 4.45 KB
/
MoreEffectiveTransferThreading.cs
File metadata and controls
92 lines (89 loc) · 4.45 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
using ColossalFramework;
using ColossalFramework.UI;
using HarmonyLib;
using ICities;
using MoreEffectiveTransfer.Patch;
using MoreEffectiveTransfer.UI;
using MoreEffectiveTransfer.Util;
namespace MoreEffectiveTransfer
{
public class MoreEffectiveTransferThreading : ThreadingExtensionBase
{
public static bool isFirstTime = true;
public const int HarmonyPatchNum = 8;
public static float shipStationDistanceRandom = 1f;
public static float trainStationDistanceRandom = 1f;
public static float planeStationDistanceRandom = 1f;
public override void OnBeforeSimulationFrame()
{
base.OnBeforeSimulationFrame();
if (Loader.CurrentLoadMode == LoadMode.LoadGame || Loader.CurrentLoadMode == LoadMode.NewGame)
{
if (MoreEffectiveTransfer.IsEnabled)
{
uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
int num4 = (int)(currentFrameIndex & 255u);
if (num4 == 255)
{
BuildingUI.refeshOnce = true;
PlayerBuildingUI.refeshOnce = true;
UniqueFactoryUI.refeshOnce = true;
WareHouseUI.refeshOnce = true;
HelicopterDepotAISimulationStepPatch.haveFireHelicopterDepotFinal = HelicopterDepotAISimulationStepPatch.haveFireHelicopterDepot;
HelicopterDepotAISimulationStepPatch.haveFireHelicopterDepot = false;
shipStationDistanceRandom = (float)Singleton<SimulationManager>.instance.m_randomizer.Int32(100, 200) * 0.005f;
trainStationDistanceRandom = (float)Singleton<SimulationManager>.instance.m_randomizer.Int32(100, 200) * 0.005f;
planeStationDistanceRandom = (float)Singleton<SimulationManager>.instance.m_randomizer.Int32(100, 200) * 0.005f;
}
CheckDetour();
}
}
}
public void CheckDetour()
{
if (isFirstTime && Loader.DetourInited && Loader.HarmonyDetourInited)
{
isFirstTime = false;
if (Loader.DetourInited)
{
DebugLog.LogToFileOnly("ThreadingExtension.OnBeforeSimulationFrame: First frame detected. Checking detours.");
if (Loader.HarmonyDetourFailed)
{
string error = "MoreEffectiveTransfer HarmonyDetourInit is failed, Send MoreEffectiveTransfer.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 = $"MoreEffectiveTransfer HarmonyDetour Patch Num is {i}, Right Num is {HarmonyPatchNum} Send MoreEffectiveTransfer.txt to Author.";
DebugLog.LogToFileOnly(error);
UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", error, true);
}
}
}
}
}
}
}