Skip to content

Commit ca7caed

Browse files
committed
zoom improvements + config changes
1 parent 5cc151f commit ca7caed

File tree

5 files changed

+46
-29
lines changed

5 files changed

+46
-29
lines changed

Patches/HUDManager_Patches.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ private static void Postfix(HUDManager __instance)
3030
string flashlightKey = InputControlPath.ToHumanReadableString(Plugin.Inputs.FlashlightKey.bindings[0].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
3131
string zoomOutKey = InputControlPath.ToHumanReadableString(Plugin.Inputs.ZoomOutKey.bindings[0].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
3232
string zoomInKey = InputControlPath.ToHumanReadableString(Plugin.Inputs.ZoomInKey.bindings[0].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
33-
// who needs to change the y position when u can just \n: sunglasses:
34-
if (SpectateEnemies.Instance.SpectatingEnemies)
35-
__instance.holdButtonToEndGameEarlyText.text += $"\n\n\n\n\nSpectate Players: [{swapKey}]\nFlashlight : [{flashlightKey}]\nZoom Out [{zoomOutKey}]\nZoom In [{zoomInKey}]\nConfig Menu : [{menuKey}]";
36-
else
37-
__instance.holdButtonToEndGameEarlyText.text += $"\n\n\n\n\nSpectate Enemies: [{swapKey}]\nFlashlight : [{flashlightKey}]\nConfig Menu : [{menuKey}]";
33+
if (!SpectateEnemies.Instance.HideControls.Value)
34+
{
35+
// who needs to change the y position when u can just \n: sunglasses:
36+
if (SpectateEnemies.Instance.SpectatingEnemies)
37+
__instance.holdButtonToEndGameEarlyText.text += $"\n\n\n\n\nSpectate Players: [{swapKey}]\nFlashlight : [{flashlightKey}]\nZoom Out : [{zoomOutKey}]\nZoom In : [{zoomInKey}]\nConfig Menu : [{menuKey}]";
38+
else
39+
__instance.holdButtonToEndGameEarlyText.text += $"\n\n\n\n\nSpectate Enemies: [{swapKey}]\nFlashlight : [{flashlightKey}]\nConfig Menu : [{menuKey}]";
40+
}
3841

3942
}
4043
}

Patches/QuickMenuManager_Patches.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SpectateEnemy.Patches
66
[HarmonyPatch(typeof(QuickMenuManager), "Start")]
77
internal class QuickMenuManager_Patches
88
{
9-
private static void Postfix(QuickMenuManager __instance)
9+
private static void Postfix()
1010
{
1111
if (SpectateEnemies.Instance == null)
1212
{

Plugin.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BepInEx;
2+
using BepInEx.Configuration;
23
using GameNetcodeStuff;
34
using HarmonyLib;
45
using System.Reflection;
@@ -13,11 +14,14 @@ internal class Plugin : BaseUnityPlugin
1314
public static MethodInfo displaySpectatorTip = null;
1415

1516
public static Inputs Inputs = new();
17+
public static ConfigFile Configuration;
1618

1719
private Harmony harmony;
1820

1921
private void Awake()
2022
{
23+
Configuration = Config;
24+
2125
harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
2226
harmony.PatchAll();
2327

SpectateEnemies.cs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BepInEx;
2+
using BepInEx.Configuration;
23
using GameNetcodeStuff;
34
using System;
45
using System.Collections.Generic;
@@ -14,15 +15,16 @@ internal class SpectateEnemies : MonoBehaviour
1415
{
1516
public static SpectateEnemies Instance;
1617

17-
private static readonly Dictionary<string, bool> settings = [];
18+
private static readonly Dictionary<string, ConfigEntry<bool>> settings = [];
1819

1920
private bool WindowOpen = false;
2021
private Rect window = new(10, 10, 500, 400);
2122

2223
public int SpectatedEnemyIndex = -1;
2324
public bool SpectatingEnemies = false;
2425
public Spectatable[] SpectatorList;
25-
public float zoomLevel = 1f;
26+
public float ZoomLevel = 1f;
27+
public ConfigEntry<bool> HideControls;
2628

2729
private void Awake()
2830
{
@@ -33,6 +35,8 @@ private void Awake()
3335
SetupKeybinds();
3436
Instance = this;
3537
DontDestroyOnLoad(gameObject);
38+
39+
HideControls = Plugin.Configuration.Bind("Config", "Hide Controls", false, "Hides the controls toolip on the right hand side.");
3640
}
3741

3842
private void SetupKeybinds()
@@ -92,18 +96,18 @@ private void OnZoomOutPressed(InputAction.CallbackContext context)
9296
{
9397
if (!context.performed) return;
9498
if (!SpectatingEnemies) return;
95-
zoomLevel += 0.1f;
96-
if (zoomLevel > 10f)
97-
zoomLevel = 10f;
99+
ZoomLevel += 0.1f;
100+
if (ZoomLevel > 10f)
101+
ZoomLevel = 10f;
98102
}
99103

100104
private void OnZoomInPressed(InputAction.CallbackContext context)
101105
{
102106
if (!context.performed) return;
103107
if (!SpectatingEnemies) return;
104-
zoomLevel -= 0.1f;
105-
if (zoomLevel < 1f)
106-
zoomLevel = 1f;
108+
ZoomLevel -= 0.1f;
109+
if (ZoomLevel < 1f)
110+
ZoomLevel = 1f;
107111
}
108112

109113
private void LateUpdate()
@@ -139,12 +143,15 @@ private void LateUpdate()
139143
{
140144
TryFixName(ref currentEnemy);
141145
}
142-
GameNetworkManager.Instance.localPlayerController.spectateCameraPivot.position = position.Value + Vector3.up * zoomLevel;
146+
147+
GameNetworkManager.Instance.localPlayerController.spectateCameraPivot.position = position.Value;
143148
if (currentEnemy.type == SpectatableType.Masked && currentEnemy.maskedName != string.Empty)
144-
HUDManager.Instance.spectatingPlayerText.text = string.Format("(Spectating: {0}) [{1:F1}x]", currentEnemy.maskedName, zoomLevel);
149+
HUDManager.Instance.spectatingPlayerText.text = string.Format("(Spectating: {0}) [{1:F1}x]", currentEnemy.maskedName, ZoomLevel);
145150
else
146-
HUDManager.Instance.spectatingPlayerText.text = string.Format("(Spectating: {0}) [{1:F1}x]", currentEnemy.enemyName, zoomLevel);
151+
HUDManager.Instance.spectatingPlayerText.text = string.Format("(Spectating: {0}) [{1:F1}x]", currentEnemy.enemyName, ZoomLevel);
147152
Plugin.raycastSpectate.Invoke(GameNetworkManager.Instance.localPlayerController, []);
153+
// Thanks HalfyRed!
154+
GameNetworkManager.Instance.localPlayerController.spectateCameraPivot.GetComponentInChildren<Camera>().transform.localPosition = Vector3.back * (ZoomLevel + 0.5f);
148155
}
149156
}
150157

@@ -209,7 +216,7 @@ public void ToggleSpectatingMode(PlayerControllerB __instance)
209216
SpectatingEnemies = !SpectatingEnemies;
210217
if (SpectatingEnemies)
211218
{
212-
SpectatorList = FindObjectsByType<Spectatable>(FindObjectsSortMode.None).Where(x => settings[x.enemyName]).ToArray();
219+
SpectatorList = FindObjectsByType<Spectatable>(FindObjectsSortMode.None).Where(x => GetSetting(x.enemyName)).ToArray();
213220
if (SpectatorList.Length == 0)
214221
{
215222
SpectatingEnemies = false;
@@ -254,12 +261,13 @@ public void PopulateSettings()
254261
{
255262
if (type.enemyName == "Red pill" || type.enemyName == "Lasso")
256263
continue;
257-
settings.TryAdd(type.enemyName, !type.isDaytimeEnemy);
264+
settings.TryAdd(type.enemyName, Plugin.Configuration.Bind("Enemies", type.enemyName, !type.isDaytimeEnemy, "Enables spectating " + type.enemyName));
258265
}
259266

260-
settings.TryAdd("Landmine", false);
261-
settings.TryAdd("Turret", false);
267+
settings.TryAdd("Landmine", Plugin.Configuration.Bind("Enemies", "Landmine", false, "Enables spectating Landmines"));
268+
settings.TryAdd("Turret", Plugin.Configuration.Bind("Enemies", "Turret", false, "Enables spectating Turrets"));
262269

270+
/*
263271
// TODO: this is terrible, improve
264272
try
265273
{
@@ -290,22 +298,24 @@ public void PopulateSettings()
290298
catch (Exception)
291299
{
292300
Debug.LogWarning("[SpectateEnemies]: Config failed to load, using default values!");
293-
}
301+
} */
294302

303+
Debug.LogWarning("[SpectateEnemies]: Config loaded");
295304
AssertSettings();
296305
}
297306

298307
private void OnApplicationQuit()
299308
{
300-
StringBuilder sb = new();
309+
/*StringBuilder sb = new();
301310
foreach (var s in settings)
302311
{
303312
sb.Append(s.Key);
304313
sb.Append(':');
305314
sb.Append(s.Value);
306315
sb.AppendLine();
307316
}
308-
File.WriteAllText(Paths.ConfigPath + "/SpectateEnemy.cfg", sb.ToString());
317+
File.WriteAllText(Paths.ConfigPath + "/SpectateEnemy.cfg", sb.ToString());*/
318+
Plugin.Configuration.Save();
309319
Debug.LogWarning("[SpectateEnemies]: Config saved");
310320
}
311321

@@ -322,7 +332,7 @@ public bool SpectateNextEnemy()
322332

323333
private void GetNextValidSpectatable()
324334
{
325-
SpectatorList = FindObjectsByType<Spectatable>(FindObjectsSortMode.None).Where(x => settings[x.enemyName]).ToArray();
335+
SpectatorList = FindObjectsByType<Spectatable>(FindObjectsSortMode.None).Where(x => GetSetting(x.enemyName)).ToArray();
326336
int enemiesChecked = 0;
327337
int current = SpectatedEnemyIndex;
328338
while (enemiesChecked < SpectatorList.Length)
@@ -366,7 +376,7 @@ private void AssertSettings()
366376
public bool GetSetting(string name)
367377
{
368378
if (settings.ContainsKey(name))
369-
return settings[name];
379+
return settings[name].Value;
370380
return false;
371381
}
372382

@@ -403,7 +413,7 @@ private void DrawGUI(int windowID)
403413
int y = 0;
404414
foreach (string k in settings.Keys.ToList())
405415
{
406-
settings[k] = GUI.Toggle(new Rect(10 + (150 * x), 60 + (30 * y), 150, 20), settings[k], k);
416+
settings[k].Value = GUI.Toggle(new Rect(10 + (150 * x), 60 + (30 * y), 150, 20), settings[k].Value, k);
407417
x++;
408418
if (x == 3)
409419
{

SpectateEnemy.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<AssemblyName>SpectateEnemy</AssemblyName>
66
<Description>My first plugin</Description>
7-
<Version>2.2.1</Version>
7+
<Version>2.3.0</Version>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<LangVersion>latest</LangVersion>
1010
<RestoreAdditionalProjectSources>
@@ -31,7 +31,7 @@
3131
<HintPath>F:\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Assembly-CSharp.dll</HintPath>
3232
</Reference>
3333
<Reference Include="LethalCompanyInputUtils">
34-
<HintPath>F:\SteamLibrary\steamapps\common\Lethal Company\BepInEx\plugins\Rune580-LethalCompany_InputUtils\LethalCompanyInputUtils.dll</HintPath>
34+
<HintPath>F:\SteamLibrary\steamapps\common\Lethal Company\BepInEx\plugins\Rune580-LethalCompany_InputUtils\LethalCompanyInputUtils\LethalCompanyInputUtils.dll</HintPath>
3535
</Reference>
3636
<Reference Include="Unity.InputSystem">
3737
<HintPath>F:\SteamLibrary\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.InputSystem.dll</HintPath>

0 commit comments

Comments
 (0)