102 lines
3.2 KiB
C#
102 lines
3.2 KiB
C#
using BepInEx;
|
|
using BepInEx.Configuration;
|
|
using Comfort.Common;
|
|
using EFT;
|
|
using EFT.AssetsManager;
|
|
using System;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace SamSWAT.HelmetLights
|
|
{
|
|
[BepInPlugin("com.samswat.helmetlights", "SamSWAT.HelmetLights", "1.0.0")]
|
|
public class Plugin : BaseUnityPlugin
|
|
{
|
|
private static GameObject _flashlight;
|
|
private static GameObject[] _modes;
|
|
private static int _currentMode = 1;
|
|
internal static ConfigEntry<KeyboardShortcut> HeadlightToggleKey;
|
|
internal static ConfigEntry<KeyboardShortcut> HeadlightModeKey;
|
|
|
|
private void Awake()
|
|
{
|
|
HeadlightToggleKey = Config.Bind(
|
|
"Main Settings",
|
|
"Helmet Light Toggle",
|
|
new KeyboardShortcut(KeyCode.Y),
|
|
"Key for helmet light toggle");
|
|
|
|
HeadlightModeKey = Config.Bind(
|
|
"Main Settings",
|
|
"Helmet Light Mode",
|
|
new KeyboardShortcut(KeyCode.Y, KeyCode.LeftShift),
|
|
"Key for helemt light mode change");
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var gameWorld = Singleton<GameWorld>.Instance;
|
|
|
|
if (gameWorld == null || gameWorld.RegisteredPlayers == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_flashlight != null && _flashlight.GetComponent<WeaponModPoolObject>().IsInPool)
|
|
{
|
|
_flashlight = null;
|
|
_currentMode = 1;
|
|
}
|
|
|
|
if (HeadlightToggleKey.Value.IsUp() && PlayerHasFlashlight())
|
|
ToggleLight();
|
|
if (HeadlightModeKey.Value.IsUp() && PlayerHasFlashlight())
|
|
ChangeMode();
|
|
}
|
|
|
|
private void ToggleLight()
|
|
{
|
|
_modes[0].SetActive(!_modes[0].activeSelf);
|
|
_modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf);
|
|
}
|
|
|
|
private void ChangeMode()
|
|
{
|
|
if (_modes[0].activeSelf == false)
|
|
{
|
|
if (_currentMode < _modes.Length - 1)
|
|
{
|
|
_modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf);
|
|
_currentMode++;
|
|
_modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf);
|
|
}
|
|
else
|
|
{
|
|
_modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf);
|
|
_currentMode = 1;
|
|
_modes[_currentMode].SetActive(!_modes[_currentMode].activeSelf);
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool PlayerHasFlashlight()
|
|
{
|
|
if (_flashlight == null)
|
|
{
|
|
Player player = Singleton<GameWorld>.Instance.RegisteredPlayers.Find(p => p.IsYourPlayer);
|
|
_flashlight = player.GetComponentInChildren<TacticalComboVisualController>()?.gameObject;
|
|
|
|
if (_flashlight == null)
|
|
return false;
|
|
|
|
_modes = Array.ConvertAll(_flashlight.GetComponentsInChildren<Transform>(true), y => y.gameObject).Where(x => x.name.Contains("mode_")).ToArray();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|