using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("LongSyringes")]
[assembly: AssemblyConfiguration("realese")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LongSyringes")]
[assembly: AssemblyTitle("LongSyringes")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LongSyringes;
[BepInPlugin("local.longsyringes", "Long Syringes", "0.4.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private static ConfigEntry<float> Mult;
private static ConfigEntry<bool> ScaleDecay;
private static readonly ConditionalWeakTable<object, object> seen = new ConditionalWeakTable<object, object>();
private const BindingFlags All = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
private void Awake()
{
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Expected O, but got Unknown
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Mult = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DurationMultiplier", 5f, "Во сколько раз дольше действуют шприцы");
ScaleDecay = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SlowDecay", true, "Также во столько же раз замедлять угасание эффекта (loseRate)");
Type type = AppDomain.CurrentDomain.GetAssemblies().SelectMany(delegate(Assembly a)
{
try
{
return a.GetTypes();
}
catch
{
return new Type[0];
}
}).FirstOrDefault((Type t) => t.Name == "HandItem_Buff");
if (type == null)
{
Log.LogError((object)"HandItem_Buff не найден (игра обновилась?)");
return;
}
Harmony val = new Harmony("local.longsyringes");
int num = 0;
MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
if (!methodInfo.IsSpecialName && !methodInfo.IsAbstract && !(methodInfo.Name == "Update"))
{
try
{
val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
num++;
}
catch (Exception ex)
{
Log.LogWarning((object)("skip " + methodInfo.Name + ": " + ex.Message));
}
}
}
Log.LogInfo((object)$"LongSyringes 0.4.0: пропатчено методов: {num}, множитель x{Mult.Value}");
}
private static void Prefix(object __instance, MethodBase __originalMethod)
{
try
{
if (__instance != null && !seen.TryGetValue(__instance, out var _))
{
seen.Add(__instance, __instance);
Type type = __instance.GetType();
Scale(type.GetField("buff", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(__instance), "buff", __originalMethod.Name);
Scale(type.GetField("secondaryBuffs", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(__instance), "secondary", __originalMethod.Name);
}
}
catch (Exception ex)
{
Log.LogWarning((object)("Prefix: " + ex));
}
}
private static void Scale(object c, string label, string via)
{
if (c == null)
{
return;
}
if (c.GetType().Name != "BuffContainer" && c is IEnumerable enumerable)
{
{
foreach (object item in enumerable)
{
Scale(item, label, via);
}
return;
}
}
if (!seen.TryGetValue(c, out var _))
{
seen.Add(c, c);
Type type = c.GetType();
FieldInfo field = type.GetField("buffTime", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo field2 = type.GetField("loseRate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
float num = ((field != null) ? ((float)field.GetValue(c)) : 0f);
float num2 = ((field2 != null) ? ((float)field2.GetValue(c)) : 0f);
if (field != null)
{
field.SetValue(c, num * Mult.Value);
}
if (field2 != null && ScaleDecay.Value && Mult.Value > 0f)
{
field2.SetValue(c, num2 / Mult.Value);
}
Log.LogInfo((object)$"[{label}] buffTime {num} -> {num * Mult.Value}; loseRate {num2} -> {(ScaleDecay.Value ? (num2 / Mult.Value) : num2)} (via {via})");
}
}
}