-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadialPingsPlugin.cs
109 lines (90 loc) · 4.5 KB
/
RadialPingsPlugin.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
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
101
102
103
104
105
106
107
108
109
using BepInEx;
using R2API.Utils;
using UnityEngine;
using BepInEx.Configuration;
using R2API;
using System.Reflection;
using Path = System.IO.Path;
using RoR2;
using System.IO;
using UnityEngine.Networking;
using TILER2;
namespace ThinkInvisible.RadialPings {
[BepInDependency(R2API.R2API.PluginGUID, R2API.R2API.PluginVersion)]
[BepInDependency(TILER2Plugin.ModGuid, TILER2Plugin.ModVer)]
[BepInPlugin(ModGuid, ModName, ModVer)]
[R2APISubmoduleDependency(nameof(R2API.Networking.NetworkingAPI), nameof(LanguageAPI))]
public class RadialPingsPlugin:BaseUnityPlugin {
public const string ModVer = "2.1.0";
public const string ModName = "RadialPings";
public const string ModGuid = "com.ThinkInvisible.RadialPings";
internal static BepInEx.Logging.ManualLogSource logger;
internal static ConfigFile cfgFile;
internal static AssetBundle resources;
public ClientConfig clientConfig;
public class ClientConfig : AutoConfigContainer {
[AutoConfig("Time between ping keydown and opening of the radial menu. Faster keyups will cause a quick ping (vanilla behavior).",
AutoConfigFlags.None, 0f, float.MaxValue)]
[AutoConfigRoOSlider("{0:N1} seconds", 0f, 5f)]
public float mainMenuOpenDelay { get; internal set; } = 0.2f;
}
public void Awake() {
logger = Logger;
cfgFile = new ConfigFile(Path.Combine(Paths.ConfigPath, ModGuid + ".cfg"), true);
clientConfig = new ClientConfig();
clientConfig.BindAll(cfgFile, "RadialPings", "Client");
//todo: option to keep first ping preview as result
using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RadialPings.radialpings_assets")) {
resources = AssetBundle.LoadFromStream(stream);
}
using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RadialPings.lang_en.json"))
using(var reader = new StreamReader(stream)) {
LanguageAPI.Add(reader.ReadToEnd());
}
RadialMenu.Setup();
new MainPingMenuBindings();
new PlayersMenuBindings();
new DroneMenuBindings();
new RespondablesMenuBindings();
On.RoR2.PlayerCharacterMasterController.CheckPinging += On_PlayerCharacterMasterController_CheckPinging;
On.RoR2.Run.OnDestroy += On_Run_OnDestroy;
R2API.Networking.NetworkingAPI.RegisterMessageType<PingMenuHelper.MsgCustomPing>();
}
void Start() {
PingCatalog.Init();
}
private void On_Run_OnDestroy(On.RoR2.Run.orig_OnDestroy orig, Run self) {
orig(self);
RespondablesMenuBindings.UpdateRespondables();
}
private void On_PlayerCharacterMasterController_CheckPinging(On.RoR2.PlayerCharacterMasterController.orig_CheckPinging orig, PlayerCharacterMasterController self) {
if(!self.hasEffectiveAuthority || !self.body || !self.bodyInputs) return;
var menuTracker = self.gameObject.GetComponent<PingMenuInstanceTracker>();
if(!menuTracker) menuTracker = self.gameObject.AddComponent<PingMenuInstanceTracker>();
if(self.bodyInputs.ping.down)
menuTracker.btnHoldStopwatch += Time.unscaledDeltaTime;
else {
menuTracker.btnHoldStopwatch = 0f;
menuTracker.btnHoldActioned = false;
}
if(menuTracker.btnHoldStopwatch > clientConfig.mainMenuOpenDelay && !menuTracker.latestMenu && !menuTracker.btnHoldActioned) {
menuTracker.btnHoldActioned = true;
menuTracker.latestMenu = MainPingMenuBindings.instance.Instantiate(self);
} else if(self.bodyInputs.ping.justReleased) {
if(menuTracker.latestMenu) {
menuTracker.btnHoldActioned = false;
var cpt = menuTracker.latestMenu.GetComponent<ProceduralRadialMenu>();
if(cpt.inOutState != ProceduralRadialMenu.InOutState.Outro) {
cpt.Activate(false);
menuTracker.latestMenu = null;
return;
}
menuTracker.latestMenu = null;
}
if(!menuTracker.btnHoldActioned)
MiscUtil.DefaultPing(self);
menuTracker.btnHoldActioned = false;
}
}
}
}