using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("BounceIndicatorPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BounceIndicatorPlus")]
[assembly: AssemblyTitle("BounceIndicatorPlus")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
internal static class AllBounceIndicators
{
internal static Dictionary<Gun, List<LineRenderer>> BounceLines = new Dictionary<Gun, List<LineRenderer>>();
internal static Dictionary<Gun, int> CachedBounces = new Dictionary<Gun, int>();
internal static LineRenderer BounceLinePrefab;
private static Color GetSelectedColor()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
switch (SparrohPlugin.bounceIndicatorColor.Value)
{
case BounceIndicatorColor.Orange:
return new Color(1f, 0.5f, 0f);
case BounceIndicatorColor.White:
return new Color(1f, 1f, 1f);
case BounceIndicatorColor.Green:
return new Color(0f, 1f, 0f);
case BounceIndicatorColor.Blue:
return new Color(0f, 0f, 1f);
case BounceIndicatorColor.Red:
return new Color(1f, 0f, 0f);
case BounceIndicatorColor.Yellow:
return new Color(1f, 1f, 0f);
case BounceIndicatorColor.Purple:
return new Color(1f, 0f, 1f);
case BounceIndicatorColor.Cyan:
return new Color(0f, 1f, 1f);
case BounceIndicatorColor.Custom:
{
string text = SparrohPlugin.bounceIndicatorCustomColor.Value;
if (!text.StartsWith("#"))
{
text = "#" + text;
}
Color result = default(Color);
if (ColorUtility.TryParseHtmlString(text, ref result))
{
return result;
}
return new Color(1f, 0f, 0f);
}
default:
return new Color(1f, 0f, 0f);
}
}
public static LineRenderer CreateBounceLinePrefab()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("BounceIndicatorPrefab");
LineRenderer obj = val.AddComponent<LineRenderer>();
Color selectedColor = GetSelectedColor();
Material val2 = new Material(Shader.Find("Sprites/Default"));
val2.color = selectedColor;
Color val3 = selectedColor * 0.5f;
val3.a = 1f;
val2.SetColor("_EmissionColor", val3);
((Renderer)obj).material = val2;
obj.startWidth = 0.01f;
obj.endWidth = 0.01f;
obj.startColor = selectedColor;
obj.endColor = selectedColor;
obj.positionCount = 2;
obj.useWorldSpace = true;
val.SetActive(false);
Object.DontDestroyOnLoad((Object)(object)val);
return obj;
}
}
[HarmonyPatch]
public static class GunBouncePatches
{
private static readonly PropertyInfo IsOwnerProperty = typeof(NetworkBehaviour).GetProperty("IsOwner");
private static readonly PropertyInfo ActiveProperty = typeof(Gun).GetProperty("Active");
private static int GetBounces(Gun gun)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
_ = ((object)gun).GetType().Name;
try
{
Type type = ((object)gun.GunData).GetType();
FieldInfo field = type.GetField("bounces", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
return (int)field.GetValue(gun.GunData);
}
PropertyInfo property = type.GetProperty("bounces", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (property != null)
{
return (int)property.GetValue(gun.GunData);
}
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.Name.ToLower().Contains("bounce") || fieldInfo.Name.ToLower().Contains("ricochet"))
{
object value = fieldInfo.GetValue(gun.GunData);
if (value is int result)
{
return result;
}
if (value is float num)
{
return (int)num;
}
}
}
UpgradeStatChanges val = new UpgradeStatChanges();
IEnumerator<StatInfo> enumerator = ((IGear)gun).EnumerateSecondaryStats(val);
int num2 = 0;
while (enumerator.MoveNext())
{
float result2;
if (enumerator.Current.name.ToLower().Contains("bounce"))
{
return (int)(float.TryParse(enumerator.Current.value, out result2) ? result2 : 0f);
}
num2++;
}
IEnumerator<StatInfo> enumerator2 = ((IGear)gun).EnumeratePrimaryStats(val);
num2 = 0;
while (enumerator2.MoveNext())
{
float result3;
if (enumerator2.Current.name.ToLower().Contains("bounce"))
{
return (int)(float.TryParse(enumerator2.Current.value, out result3) ? result3 : 0f);
}
num2++;
}
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogInfo((object)(" ERROR: GetBounces exception: " + ex.Message));
}
return 0;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Gun), "Enable")]
public static void Enable_Postfix(Gun __instance)
{
int bounces = GetBounces(__instance);
AllBounceIndicators.CachedBounces[__instance] = bounces;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Gun), "Update")]
public static void Update_Postfix(Gun __instance)
{
try
{
if ((bool)IsOwnerProperty.GetValue(__instance) && (bool)ActiveProperty.GetValue(__instance))
{
HandleBounceIndicators(__instance);
}
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogInfo((object)("ERROR: Update postfix failed: " + ex.Message));
}
}
private static void HandleBounceIndicators(Gun gun)
{
if (!AllBounceIndicators.CachedBounces.TryGetValue(gun, out var value))
{
value = 0;
}
bool value2 = SparrohPlugin.enableAllBounceIndicators.Value;
_ = ((object)gun).GetType().Name;
if (!value2 || value < 1)
{
return;
}
if (!AllBounceIndicators.BounceLines.ContainsKey(gun))
{
AllBounceIndicators.BounceLines[gun] = new List<LineRenderer>();
}
List<LineRenderer> list = AllBounceIndicators.BounceLines[gun];
if ((Object)(object)AllBounceIndicators.BounceLinePrefab == (Object)null)
{
AllBounceIndicators.BounceLinePrefab = AllBounceIndicators.CreateBounceLinePrefab();
}
int num = gun.GunData.bulletsPerShot * value;
while (list.Count < num)
{
LineRenderer item = Object.Instantiate<LineRenderer>(AllBounceIndicators.BounceLinePrefab);
list.Add(item);
}
Traverse obj = Traverse.Create((object)gun);
obj.Method("PrepareFireData", Array.Empty<object>()).GetValue();
object value3 = obj.Field("player").GetValue();
bool num2 = (bool)value3?.GetType().GetProperty("IsSprinting")?.GetValue(value3);
bool flag = (bool)value3?.GetType().GetProperty("IsFireLocked")?.GetValue(value3);
if (num2 || flag)
{
for (int i = 0; i < list.Count; i++)
{
if (((Component)list[i]).gameObject.activeSelf)
{
((Component)list[i]).gameObject.SetActive(false);
}
}
}
else
{
UpdateBounceLines(gun);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Gun), "Disable")]
public static void Disable_Postfix(Gun __instance)
{
if (AllBounceIndicators.BounceLines.TryGetValue(__instance, out var value))
{
for (int i = 0; i < value.Count; i++)
{
((Component)value[i]).gameObject.SetActive(false);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Gun), "OnDestroy")]
public static void OnDestroy_Postfix(Gun __instance)
{
if (AllBounceIndicators.BounceLines.TryGetValue(__instance, out var value))
{
for (int i = 0; i < value.Count; i++)
{
if ((Object)(object)value[i] != (Object)null)
{
Object.Destroy((Object)(object)((Component)value[i]).gameObject);
}
}
AllBounceIndicators.BounceLines.Remove(__instance);
}
AllBounceIndicators.CachedBounces.Remove(__instance);
}
private static Vector3 CalculateSpreadDirection(Vector3 baseDirection, int bulletIndex, int totalBullets, Gun gun)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0403: Unknown result type (might be due to invalid IL or missing references)
//IL_0408: Unknown result type (might be due to invalid IL or missing references)
//IL_040a: Unknown result type (might be due to invalid IL or missing references)
//IL_040b: Unknown result type (might be due to invalid IL or missing references)
//IL_0410: Unknown result type (might be due to invalid IL or missing references)
//IL_0412: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Unknown result type (might be due to invalid IL or missing references)
//IL_0314: Unknown result type (might be due to invalid IL or missing references)
//IL_0318: Unknown result type (might be due to invalid IL or missing references)
//IL_031d: Unknown result type (might be due to invalid IL or missing references)
//IL_031f: Unknown result type (might be due to invalid IL or missing references)
//IL_0320: Unknown result type (might be due to invalid IL or missing references)
//IL_0325: Unknown result type (might be due to invalid IL or missing references)
//IL_0327: Unknown result type (might be due to invalid IL or missing references)
//IL_032c: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0359: Unknown result type (might be due to invalid IL or missing references)
//IL_0418: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_0388: Unknown result type (might be due to invalid IL or missing references)
//IL_038d: Unknown result type (might be due to invalid IL or missing references)
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_0396: Unknown result type (might be due to invalid IL or missing references)
if (totalBullets <= 1)
{
return baseDirection;
}
Vector3 val2;
try
{
GunData gunData = gun.GunData;
object obj = ((object)gunData).GetType().GetField("spreadData")?.GetValue(gunData);
if (obj != null)
{
Type type = obj.GetType();
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
List<string> list = new List<string>();
MethodInfo[] array = methods;
foreach (MethodInfo methodInfo in array)
{
list.Add(methodInfo.Name);
}
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
List<string> list2 = new List<string>();
FieldInfo[] array2 = fields;
foreach (FieldInfo fieldInfo in array2)
{
list2.Add(fieldInfo.Name);
}
List<MethodInfo> list3 = new List<MethodInfo>();
array = methods;
foreach (MethodInfo methodInfo2 in array)
{
if (methodInfo2.Name.Contains("Spread"))
{
list3.Add(methodInfo2);
}
}
foreach (MethodInfo item in list3)
{
try
{
ParameterInfo[] parameters = item.GetParameters();
object[] array3 = null;
if (parameters.Length == 2 && parameters[0].ParameterType == typeof(int) && parameters[1].ParameterType == typeof(int))
{
array3 = new object[2] { bulletIndex, totalBullets };
}
else if (parameters.Length == 3 && parameters[0].ParameterType == typeof(Vector3) && parameters[1].ParameterType == typeof(int) && parameters[2].ParameterType == typeof(int))
{
array3 = new object[3] { baseDirection, bulletIndex, totalBullets };
}
if (array3 != null && item.Invoke(obj, array3) is Vector3 val)
{
return ((Vector3)(ref val)).normalized;
}
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogInfo((object)("Method " + item.Name + " failed: " + ex.Message));
}
}
PropertyInfo property = type.GetProperty("spreadAngle");
FieldInfo field = type.GetField("spreadAngle");
float num = 0f;
if (property != null)
{
num = (float)property.GetValue(obj);
}
else if (field != null)
{
num = (float)field.GetValue(obj);
}
if (num > 0f)
{
float num2 = num * ((float)Math.PI / 180f);
float num3 = (float)bulletIndex * ((float)Math.PI * 2f) / (float)totalBullets;
float num4 = (float)bulletIndex * num2 / (float)totalBullets;
float num5 = num4 * Mathf.Sin(num3);
val2 = new Vector3(num4 * Mathf.Cos(num3), num5, 1f);
Vector3 normalized = ((Vector3)(ref val2)).normalized;
return Quaternion.LookRotation(baseDirection) * normalized;
}
MethodInfo method = type.GetMethod("CalculateSpread", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method != null && method.Invoke(obj, new object[4] { baseDirection, bulletIndex, totalBullets, gun }) is Vector3 val3)
{
return ((Vector3)(ref val3)).normalized;
}
}
}
catch (Exception ex2)
{
SparrohPlugin.Logger.LogInfo((object)("Error examining spread data: " + ex2.Message));
}
float num6 = 15f * ((float)Math.PI / 180f);
float num7 = (float)bulletIndex * ((float)Math.PI * 2f) / (float)totalBullets;
float num8 = (float)(bulletIndex + 1) * num6 / (float)totalBullets;
float num9 = Mathf.Sin(num8);
float num10 = Mathf.Cos(num8);
val2 = new Vector3(num9 * Mathf.Cos(num7), num9 * Mathf.Sin(num7), num10);
Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
return Quaternion.LookRotation(baseDirection) * normalized2;
}
private static void UpdateBounceLines(Gun gun)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
if (!AllBounceIndicators.BounceLines.TryGetValue(gun, out var value))
{
return;
}
try
{
object value2 = Traverse.Create((object)gun).Field("fireData").GetValue();
Vector3 val = (Vector3)value2.GetType().GetField("firePosition").GetValue(value2);
Quaternion val2 = (Quaternion)value2.GetType().GetField("bulletRotation").GetValue(value2);
int bulletsPerShot = gun.GunData.bulletsPerShot;
int num = 0;
if (AllBounceIndicators.CachedBounces.TryGetValue(gun, out var value3))
{
num = value3;
}
int i = 0;
RaycastHit val6 = default(RaycastHit);
RaycastHit val7 = default(RaycastHit);
for (int j = 0; j < bulletsPerShot; j++)
{
if (i >= value.Count)
{
break;
}
Vector3 val3 = val;
Vector3 val4 = CalculateSpreadDirection(val2 * Vector3.forward, j, bulletsPerShot, gun);
Vector3 val5 = val;
if (!Physics.Raycast(val3, val4, ref val6, 50f, LayerMask.GetMask(new string[3] { "Default", "Terrain", "Environment" })))
{
continue;
}
val3 = ((RaycastHit)(ref val6)).point;
val4 = Vector3.Reflect(val4, ((RaycastHit)(ref val6)).normal);
for (int k = 0; k < num; k++)
{
if (i >= value.Count)
{
break;
}
val5 = val3;
if (Physics.Raycast(val3, val4, ref val7, 50f, LayerMask.GetMask(new string[3] { "Default", "Terrain", "Environment" })))
{
Vector3 point = ((RaycastHit)(ref val7)).point;
Vector3[] positions = (Vector3[])(object)new Vector3[2] { val5, point };
value[i].SetPositions(positions);
((Component)value[i]).gameObject.SetActive(true);
val3 = point;
val4 = Vector3.Reflect(val4, ((RaycastHit)(ref val7)).normal);
i++;
continue;
}
Vector3 val8 = val3 + val4 * 15f;
Vector3[] positions2 = (Vector3[])(object)new Vector3[2] { val5, val8 };
value[i].SetPositions(positions2);
((Component)value[i]).gameObject.SetActive(true);
i++;
break;
}
}
for (; i < value.Count; i++)
{
((Component)value[i]).gameObject.SetActive(false);
}
}
catch (Exception ex)
{
SparrohPlugin.Logger.LogInfo((object)("ERROR: UpdateBounceLines failed: " + ex.Message));
}
}
}
public enum BounceIndicatorColor
{
[Description("Standard orange color (highest priority, default)")]
Orange,
[Description("Clean white color")]
White,
[Description("Bright green color")]
Green,
[Description("Deep blue color")]
Blue,
[Description("Vibrant red color")]
Red,
[Description("Sunny yellow color")]
Yellow,
[Description("Royal purple color")]
Purple,
[Description("Aqua cyan color")]
Cyan,
[Description("Use a custom color specified by hex code")]
Custom
}
[BepInPlugin("sparroh.bounceindicatorplus", "BounceIndicatorPlus", "1.0.1")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class SparrohPlugin : BaseUnityPlugin
{
public const string PluginGUID = "sparroh.bounceindicatorplus";
public const string PluginName = "BounceIndicatorPlus";
public const string PluginVersion = "1.0.1";
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> enableAllBounceIndicators;
internal static ConfigEntry<BounceIndicatorColor> bounceIndicatorColor;
internal static ConfigEntry<string> bounceIndicatorCustomColor;
private FileSystemWatcher _configWatcher;
private float _configReloadTimer = -1f;
private const float ConfigReloadDebounceSeconds = 0.25f;
internal static SparrohPlugin Instance { get; set; }
private void Awake()
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
enableAllBounceIndicators = ((BaseUnityPlugin)this).Config.Bind<bool>("Bounce Indicators", "All Bounce Indicators", true, "Show bounce/ricochet prediction lines for all weapons with bounces >= 1.");
bounceIndicatorColor = ((BaseUnityPlugin)this).Config.Bind<BounceIndicatorColor>("Bounce Indicators", "Bounce Indicator Color", BounceIndicatorColor.Orange, "Select the color for bounce/ricochet prediction lines");
bounceIndicatorCustomColor = ((BaseUnityPlugin)this).Config.Bind<string>("Bounce Indicators", "Bounce Indicator Custom Color", "#FF8000", "Hex color code when 'Custom' is selected (format: #RRGGBB or RRGGBB)");
enableAllBounceIndicators.SettingChanged += OnEnableAllBounceIndicatorsChanged;
bounceIndicatorColor.SettingChanged += OnBounceIndicatorColorChanged;
bounceIndicatorCustomColor.SettingChanged += OnBounceIndicatorCustomColorChanged;
SetupConfigWatcher();
try
{
new Harmony("sparroh.bounceindicatorplus").PatchAll(typeof(GunBouncePatches));
}
catch (Exception ex)
{
Logger.LogError((object)("Error applying patches: " + ex.Message));
}
Logger.LogInfo((object)"BounceIndicatorPlus loaded successfully.");
}
private void Update()
{
if (_configReloadTimer < 0f)
{
return;
}
_configReloadTimer -= Time.unscaledDeltaTime;
if (_configReloadTimer > 0f)
{
return;
}
_configReloadTimer = -1f;
try
{
((BaseUnityPlugin)this).Config.Reload();
Logger.LogInfo((object)"Config reloaded from disk.");
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to reload config: " + ex.Message));
}
}
private void OnDestroy()
{
if (_configWatcher != null)
{
_configWatcher.EnableRaisingEvents = false;
_configWatcher.Changed -= OnConfigFileChanged;
_configWatcher.Created -= OnConfigFileChanged;
_configWatcher.Renamed -= OnConfigFileRenamed;
_configWatcher.Dispose();
_configWatcher = null;
}
enableAllBounceIndicators.SettingChanged -= OnEnableAllBounceIndicatorsChanged;
bounceIndicatorColor.SettingChanged -= OnBounceIndicatorColorChanged;
bounceIndicatorCustomColor.SettingChanged -= OnBounceIndicatorCustomColorChanged;
}
private void SetupConfigWatcher()
{
try
{
string configFilePath = ((BaseUnityPlugin)this).Config.ConfigFilePath;
string directoryName = Path.GetDirectoryName(configFilePath);
string fileName = Path.GetFileName(configFilePath);
if (string.IsNullOrEmpty(directoryName) || string.IsNullOrEmpty(fileName))
{
Logger.LogWarning((object)"Could not set up config file watcher: invalid config path.");
return;
}
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
_configWatcher = new FileSystemWatcher(directoryName, fileName)
{
NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite),
IncludeSubdirectories = false
};
_configWatcher.Changed += OnConfigFileChanged;
_configWatcher.Created += OnConfigFileChanged;
_configWatcher.Renamed += OnConfigFileRenamed;
_configWatcher.EnableRaisingEvents = true;
Logger.LogInfo((object)("Watching config file for changes: " + configFilePath));
}
catch (Exception ex)
{
Logger.LogError((object)("Failed to set up config file watcher: " + ex.Message));
}
}
private void OnConfigFileChanged(object sender, FileSystemEventArgs e)
{
_configReloadTimer = 0.25f;
}
private void OnConfigFileRenamed(object sender, RenamedEventArgs e)
{
if (string.Equals(e.Name, Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath), StringComparison.OrdinalIgnoreCase) || string.Equals(e.OldName, Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath), StringComparison.OrdinalIgnoreCase))
{
_configReloadTimer = 0.25f;
}
}
private void OnEnableAllBounceIndicatorsChanged(object sender, EventArgs e)
{
if (!enableAllBounceIndicators.Value)
{
HideAllBounceLines();
}
}
private void OnBounceIndicatorColorChanged(object sender, EventArgs e)
{
UpdateBounceIndicatorColors();
}
private void OnBounceIndicatorCustomColorChanged(object sender, EventArgs e)
{
if (bounceIndicatorColor.Value == BounceIndicatorColor.Custom)
{
UpdateBounceIndicatorColors();
}
}
private static void HideAllBounceLines()
{
if (AllBounceIndicators.BounceLines == null)
{
return;
}
foreach (KeyValuePair<Gun, List<LineRenderer>> bounceLine in AllBounceIndicators.BounceLines)
{
List<LineRenderer> value = bounceLine.Value;
for (int i = 0; i < value.Count; i++)
{
if ((Object)(object)value[i] != (Object)null && (Object)(object)((Component)value[i]).gameObject != (Object)null && ((Component)value[i]).gameObject.activeSelf)
{
((Component)value[i]).gameObject.SetActive(false);
}
}
}
}
private Color GetSelectedColor()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
switch (bounceIndicatorColor.Value)
{
case BounceIndicatorColor.Orange:
return new Color(1f, 0.5f, 0f);
case BounceIndicatorColor.White:
return new Color(1f, 1f, 1f);
case BounceIndicatorColor.Green:
return new Color(0f, 1f, 0f);
case BounceIndicatorColor.Blue:
return new Color(0f, 0f, 1f);
case BounceIndicatorColor.Red:
return new Color(1f, 0f, 0f);
case BounceIndicatorColor.Yellow:
return new Color(1f, 1f, 0f);
case BounceIndicatorColor.Purple:
return new Color(1f, 0f, 1f);
case BounceIndicatorColor.Cyan:
return new Color(0f, 1f, 1f);
case BounceIndicatorColor.Custom:
{
string text = bounceIndicatorCustomColor.Value;
if (!text.StartsWith("#"))
{
text = "#" + text;
}
Color result = default(Color);
if (ColorUtility.TryParseHtmlString(text, ref result))
{
return result;
}
return new Color(1f, 0f, 0f);
}
default:
return new Color(1f, 0f, 0f);
}
}
private void UpdateBounceIndicatorColors()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
Color selectedColor = GetSelectedColor();
if (AllBounceIndicators.BounceLines != null)
{
foreach (KeyValuePair<Gun, List<LineRenderer>> bounceLine in AllBounceIndicators.BounceLines)
{
List<LineRenderer> value = bounceLine.Value;
for (int i = 0; i < value.Count; i++)
{
if ((Object)(object)value[i] != (Object)null && (Object)(object)((Renderer)value[i]).material != (Object)null)
{
((Renderer)value[i]).material.color = selectedColor;
Color val = selectedColor * 0.5f;
val.a = 1f;
((Renderer)value[i]).material.SetColor("_EmissionColor", val);
value[i].startColor = selectedColor;
value[i].endColor = selectedColor;
}
}
}
}
AllBounceIndicators.BounceLinePrefab = null;
}
}
namespace BounceIndicatorPlus
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "BounceIndicatorPlus";
public const string PLUGIN_NAME = "BounceIndicatorPlus";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}