Skip to content

Commit 42da907

Browse files
committed
BepInEx Build
Changed code to be compatible with BepInEx
1 parent 5464188 commit 42da907

12 files changed

Lines changed: 193 additions & 224 deletions

File tree

Distance.OverheatMeter.sln

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.31515.178
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Distance.OverheatMeter.Content", "Distance.OverheatMeter.Content\Distance.OverheatMeter.Content.shproj", "{4E7D37C7-8AFE-4F79-BAF6-4CE82D05E091}"
7-
EndProject
86
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Distance.OverheatMeter", "Distance.OverheatMeter\Distance.OverheatMeter.csproj", "{7BCB2908-B003-45D9-BE68-50CBA5217603}"
97
EndProject
108
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{08A1C9FA-7DC2-4A60-B9A6-AC0EB7132893}"
@@ -16,9 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1614
EndProjectSection
1715
EndProject
1816
Global
19-
GlobalSection(SharedMSBuildProjectFiles) = preSolution
20-
Distance.OverheatMeter.Content\Distance.OverheatMeter.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13
21-
EndGlobalSection
2217
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2318
Debug|Any CPU = Debug|Any CPU
2419
Release|Any CPU = Release|Any CPU

Distance.OverheatMeter/ConfigurationLogic.cs

Lines changed: 0 additions & 75 deletions
This file was deleted.

Distance.OverheatMeter/Distance.OverheatMeter.csproj

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,73 +33,41 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<ItemGroup>
36-
<Reference Include="0Harmony, Version=2.5.1.0, Culture=neutral, processorArchitecture=MSIL">
37-
<HintPath>..\packages\HarmonyX.2.5.1\lib\net35\0Harmony.dll</HintPath>
36+
<Reference Include="0Harmony">
37+
<HintPath>..\..\..\AppData\Roaming\r2modmanPlus-local\Distance\profiles\Alt\BepInEx\core\0Harmony.dll</HintPath>
3838
</Reference>
39-
<Reference Include="Assembly-CSharp, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
40-
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\Assembly-CSharp.dll</HintPath>
39+
<Reference Include="Assembly-CSharp">
40+
<HintPath>..\..\publicized_assemblies\Assembly-CSharp.dll</HintPath>
4141
</Reference>
42-
<Reference Include="Centrifuge.Distance, Version=3.0.7868.41513, Culture=neutral, processorArchitecture=MSIL">
43-
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\Centrifuge.Distance.dll</HintPath>
44-
</Reference>
45-
<Reference Include="Mono.Cecil, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
46-
<HintPath>..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.dll</HintPath>
47-
</Reference>
48-
<Reference Include="Mono.Cecil.Mdb, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
49-
<HintPath>..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Mdb.dll</HintPath>
50-
</Reference>
51-
<Reference Include="Mono.Cecil.Pdb, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
52-
<HintPath>..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Pdb.dll</HintPath>
53-
</Reference>
54-
<Reference Include="Mono.Cecil.Rocks, Version=0.10.4.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
55-
<HintPath>..\packages\Mono.Cecil.0.10.4\lib\net35\Mono.Cecil.Rocks.dll</HintPath>
56-
</Reference>
57-
<Reference Include="MonoMod.RuntimeDetour, Version=21.7.8.3, Culture=neutral, processorArchitecture=MSIL">
58-
<HintPath>..\packages\MonoMod.RuntimeDetour.21.7.8.3\lib\net35\MonoMod.RuntimeDetour.dll</HintPath>
59-
</Reference>
60-
<Reference Include="MonoMod.Utils, Version=21.7.8.3, Culture=neutral, processorArchitecture=MSIL">
61-
<HintPath>..\packages\MonoMod.Utils.21.7.8.3\lib\net35\MonoMod.Utils.dll</HintPath>
62-
</Reference>
63-
<Reference Include="NAudio, Version=1.7.3.0, Culture=neutral, processorArchitecture=MSIL">
64-
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\NAudio.dll</HintPath>
65-
</Reference>
66-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
67-
<HintPath>..\packages\Json.Net.Unity3D.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
68-
</Reference>
69-
<Reference Include="Reactor.API, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
70-
<HintPath>..\packages\Centrifuge.Mod.SDK.3.2.0\lib\net35\Reactor.API.dll</HintPath>
42+
<Reference Include="BepInEx">
43+
<HintPath>..\..\..\AppData\Roaming\r2modmanPlus-local\Distance\profiles\Alt\BepInEx\core\BepInEx.dll</HintPath>
7144
</Reference>
7245
<Reference Include="System" />
7346
<Reference Include="System.Core" />
7447
<Reference Include="System.Xml.Linq" />
7548
<Reference Include="System.Data.DataSetExtensions" />
7649
<Reference Include="System.Data" />
7750
<Reference Include="System.Xml" />
78-
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
79-
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.dll</HintPath>
80-
</Reference>
81-
<Reference Include="UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
82-
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.Networking.dll</HintPath>
83-
</Reference>
84-
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
85-
<HintPath>..\packages\Centrifuge.GameSupport.Distance.3.0.7868.41513\lib\net35\UnityEngine.UI.dll</HintPath>
51+
<Reference Include="UnityEngine">
52+
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Distance\Distance_Data\Managed\UnityEngine.dll</HintPath>
8653
</Reference>
8754
</ItemGroup>
8855
<ItemGroup>
89-
<Compile Include="ConfigurationLogic.cs" />
9056
<Compile Include="Mod.cs" />
9157
<Compile Include="Enums\ActivationMode.cs" />
9258
<Compile Include="Enums\DisplayMode.cs" />
9359
<Compile Include="Enums\DisplayUnits.cs" />
9460
<Compile Include="Flags.cs" />
95-
<Compile Include="Harmony\Assembly-CSharp\SpeedrunTimerLogic\OnEnable.cs" />
96-
<Compile Include="Harmony\Assembly-CSharp\TrickyTextLogic\Update.cs" />
61+
<Compile Include="Options.cs" />
62+
<Compile Include="Patches\Assembly-CSharp\SpeedrunTimerLogic\OnEnable.cs" />
63+
<Compile Include="Patches\Assembly-CSharp\TrickyTextLogic\Update.cs" />
9764
<Compile Include="Properties\AssemblyInfo.cs" />
9865
<Compile Include="Scripts\HeatTextLogic.cs" />
66+
<Compile Include="Utilities.cs" />
67+
<Compile Include="Vehicle.cs" />
9968
</ItemGroup>
10069
<ItemGroup>
10170
<None Include="Distance.OverheatMeter.targets" />
102-
<None Include="packages.config" />
10371
</ItemGroup>
10472
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
10573
<PropertyGroup>

Distance.OverheatMeter/Flags.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Centrifuge.Distance.Game;
2-
using Distance.Overheatmeter.Enums;
1+
using Distance.Overheatmeter.Enums;
32
using Events.Game;
43
using Events.GameMode;
54
using Events.Level;

Distance.OverheatMeter/Mod.cs

Lines changed: 65 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,67 @@
1-
using Centrifuge.Distance.Game;
2-
using Centrifuge.Distance.GUI.Controls;
3-
using Centrifuge.Distance.GUI.Data;
1+
using BepInEx;
2+
using BepInEx.Configuration;
3+
using BepInEx.Logging;
44
using Distance.Overheatmeter.Enums;
5-
using Reactor.API.Attributes;
6-
using Reactor.API.Input;
7-
using Reactor.API.Interfaces.Systems;
8-
using Reactor.API.Logging;
9-
using Reactor.API.Runtime.Patching;
5+
using HarmonyLib;
106
using System;
117
using System.Collections.Generic;
128
using System.Text.RegularExpressions;
139
using UnityEngine;
1410

1511
namespace Distance.Overheatmeter
1612
{
17-
[ModEntryPoint("com.github.Seeker14491/Heat")]
18-
public class Mod : MonoBehaviour
13+
//"com.github.Seeker14491/Heat"
14+
//Authors: vddCore + Seekr + pigpenguin
15+
[BepInPlugin(modGUID, modName, modVersion)]
16+
public sealed class Mod : BaseUnityPlugin
1917
{
20-
public static Mod Instance;
18+
//Mod Details
19+
private const string modGUID = "Distance.OverheatMeter";
20+
private const string modName = "Overheat Meter";
21+
private const string modVersion = "1.0.0";
2122

22-
public IManager Manager { get; set; }
23+
//Config Entries
24+
public static ConfigEntry<KeyboardShortcut> ToggleHotkey { get; set; }
25+
public static ConfigEntry<ActivationMode> ActivationModeConfig { get; set; }
26+
public static ConfigEntry<DisplayMode> DisplayModeConfig { get; set; }
27+
public static ConfigEntry<float> WarningThreshold { get; set; }
2328

24-
public Log Logger { get; set; }
29+
//Public Variables
2530

26-
public ConfigurationLogic Config { get; private set; }
31+
//Private Variables
2732

28-
public void Initialize(IManager manager)
33+
//Other
34+
private static readonly Harmony harmony = new Harmony(modGUID);
35+
public static ManualLogSource Log = new ManualLogSource(modName);
36+
public static Mod Instance;
37+
38+
void Awake()
2939
{
3040
DontDestroyOnLoad(this);
31-
Instance = this;
32-
Manager = manager;
33-
3441
Flags.SubscribeEvents();
3542

36-
Logger = LogManager.GetForCurrentAssembly();
37-
Config = gameObject.AddComponent<ConfigurationLogic>();
43+
if (Instance == null)
44+
{
45+
Instance = this;
46+
}
3847

39-
Config.OnChanged += OnConfigChanged;
48+
Log = BepInEx.Logging.Logger.CreateLogSource(modGUID);
49+
Logger.LogInfo("Initializing Overheat Meter...");
4050

41-
OnConfigChanged(Config);
51+
//Config Setup
52+
ToggleHotkey = Config.Bind("General", "SET TOGGLE HOTKEY", new KeyboardShortcut(KeyCode.H, new KeyCode[] { KeyCode.LeftControl }),
53+
new ConfigDescription("Set the shortcut to toggle the Overheat Meter UI"));
4254

43-
CreateSettingsMenu();
55+
ActivationModeConfig = Config.Bind("General", "ACTIVATION MODE", ActivationMode.Always, new ConfigDescription("Control how the UI activates"));
4456

45-
RuntimePatcher.AutoPatch();
46-
}
57+
DisplayModeConfig = Config.Bind("General", "DISPLAY MODE", DisplayMode.Hud, new ConfigDescription("Control how the UI displays"));
4758

48-
private void CreateSettingsMenu()
49-
{
50-
var settingsMenu = new MenuTree("menu.mod.heat", "Heat Display Settings")
51-
{
52-
new InputPrompt(MenuDisplayMode.Both, "setting:toggle_hotkey", "SET TOGGLE HOTKEY")
53-
.WithTitle("SET TOGGLE HOTKEY")
54-
.WithDefaultValue(() => Config.ToggleHotkey)
55-
.WithSubmitAction(x => Config.ToggleHotkey = x),
56-
57-
new ListBox<DisplayMode>(MenuDisplayMode.Both, "setting:display_mode", "DISPLAY MODE")
58-
.WithEntries(MapEnumToListBox<DisplayMode>())
59-
.WithGetter(() => Config.DisplayMode)
60-
.WithSetter((x) => Config.DisplayMode = x),
61-
62-
new ListBox<ActivationMode>(MenuDisplayMode.Both, "setting:activation_mode", "ACTIVATION MODE")
63-
.WithEntries(MapEnumToListBox<ActivationMode>())
64-
.WithGetter(() => Config.ActivationMode)
65-
.WithSetter((x) => Config.ActivationMode = x),
66-
67-
new FloatSlider(MenuDisplayMode.Both, "setting:warning_threshold", "WARNING THRESHOLD")
68-
.LimitedByRange(0.0f, 1.0f)
69-
.WithGetter(() => Config.WarningTreshold)
70-
.WithSetter((x) => Config.WarningTreshold = x)
71-
};
72-
73-
Menus.AddNew(MenuDisplayMode.Both, settingsMenu, "HEAT DISPLAY", "Configure the Heat mod.");
59+
WarningThreshold = Config.Bind("General", "WARNING THRESHOLD", 0.8f, new ConfigDescription("Adjust the warning threshold", new AcceptableValueRange<float>(0.0f, 1.0f)));
60+
61+
//Apply Patches
62+
Logger.LogInfo("Loading...");
63+
harmony.PatchAll();
64+
Logger.LogInfo("Loaded!");
7465
}
7566

7667
#region Utilities
@@ -105,33 +96,40 @@ private string SplitCamelCase(string str)
10596
#endregion
10697

10798
#region Data
108-
public bool DisplayCondition => Config.ActivationMode == ActivationMode.Always ||
109-
(Config.ActivationMode == ActivationMode.Warning && Vehicle.HeatLevel >= Config.WarningTreshold) ||
110-
(Config.ActivationMode == ActivationMode.Toggle && Toggled);
99+
public bool DisplayCondition => ActivationModeConfig.Value == ActivationMode.Always ||
100+
(ActivationModeConfig.Value == ActivationMode.Warning && Vehicle.HeatLevel >= WarningThreshold.Value) ||
101+
(ActivationModeConfig.Value == ActivationMode.Toggle && Toggled);
111102

112103
public bool Toggled { get; set; }
113104

114105
public string Text => $"{GetHeatLevel()}\n{GetSpeed()}";
115106

116107
public string GetHeatLevel()
117108
{
118-
string percent = Mathf.RoundToInt(100 * Mathf.Clamp(Vehicle.HeatLevel, 0, 1)).ToString();
119-
while (percent.Length< 3)
109+
if (G.Sys.GameManager_.IsModeStarted_)
120110
{
121-
percent = $"0{percent}";
122-
}
111+
string percent = Mathf.RoundToInt(100 * Mathf.Clamp(Vehicle.HeatLevel, 0, 1)).ToString();
112+
while (percent.Length < 3)
113+
{
114+
percent = $"0{percent}";
115+
}
123116

124-
return $"{percent} %";
117+
return $"{percent} %";
118+
}
119+
else
120+
{
121+
return "0%";
122+
}
125123
}
126124

127125
private string GetSpeed()
128126
{
129127
if (G.Sys.GameManager_.IsModeStarted_)
130128
{
131-
switch (Centrifuge.Distance.Game.Options.General.Units)
129+
switch (Options.General.Units)
132130
{
133131
case Units.Metric:
134-
return $"{Mathf.RoundToInt(Vehicle.VelocityKPH)} KM/H";
132+
return $"{Mathf.RoundToInt( Vehicle.VelocityKPH)} KM/H";
135133
case Units.Imperial:
136134
return $"{Mathf.RoundToInt(Vehicle.VelocityMPH)} MPH";
137135
default:
@@ -146,9 +144,13 @@ private string GetSpeed()
146144
#endregion
147145

148146
#region Settings Changed
149-
public void OnConfigChanged(ConfigurationLogic config)
147+
public void OnConfigChanged(object sender, EventArgs e)
150148
{
151-
BindAction(ref _keybindToggle, config.ToggleHotkey, () =>
149+
SettingChangedEventArgs settingChangedEventArgs = e as SettingChangedEventArgs;
150+
151+
if (settingChangedEventArgs == null) return;
152+
153+
if (sender == ToggleHotkey)
152154
{
153155
Toggled = !Toggled;
154156

@@ -159,22 +161,7 @@ public void OnConfigChanged(ConfigurationLogic config)
159161
trickText.Clear();
160162
}
161163
}
162-
});
163-
}
164-
#endregion
165-
166-
#region Key Bindings
167-
168-
private Hotkey _keybindToggle = null;
169-
170-
public void BindAction(ref Hotkey unbind, string rebind, Action callback)
171-
{
172-
if (unbind != null)
173-
{
174-
Manager.Hotkeys.UnbindHotkey(unbind);
175164
}
176-
177-
unbind = Manager.Hotkeys.BindHotkey(rebind, callback, true);
178165
}
179166
#endregion
180167
}

0 commit comments

Comments
 (0)