Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of TaKiLethalTweaks v1.3.1
TaKiLethalTweaks.dll
Decompiled 2 weeks agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TaKiLethalTweaks")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.3.1.0")] [assembly: AssemblyInformationalVersion("1.3.1")] [assembly: AssemblyProduct("TaKiLethalTweaks")] [assembly: AssemblyTitle("TaKiLethalTweaks")] [assembly: AssemblyVersion("1.3.1.0")] [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; } } } namespace TaKi.LethalTweaks { [BepInPlugin("taki.lethaltweaks", "TaKi LethalTweaks", "1.3.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private static class ErrorGuards { private static readonly Dictionary<string, int> counts = new Dictionary<string, int>(); private static readonly Dictionary<string, DateTime> lastLog = new Dictionary<string, DateTime>(); private static FieldInfo fTurretTarget; private static void Note(string what, Exception e) { counts.TryGetValue(what, out var value); value = (counts[what] = value + 1); if (!lastLog.TryGetValue(what, out var value2) || (DateTime.Now - value2).TotalSeconds > 60.0) { lastLog[what] = DateTime.Now; Log.LogWarning((object)$"{what}: error evitado ({value} en total). {e.GetType().Name}"); } } private static void Guard(Harmony h, string typeName, string method, string finalizer) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown try { Type type = AccessTools.TypeByName(typeName); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, method, (Type[])null, (Type[])null) : null); if (methodInfo == null) { Log.LogWarning((object)("No encontre " + typeName + "." + method + ", salteo esa proteccion.")); } else { h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ErrorGuards), finalizer, (Type[])null), (HarmonyMethod)null); } } catch (Exception ex) { Log.LogWarning((object)("No pude proteger " + typeName + "." + method + ": " + ex.Message)); } } internal static void Apply(Harmony h) { Type type = AccessTools.TypeByName("Turret"); if (type != null) { fTurretTarget = AccessTools.Field(type, "targetPlayerWithRotation"); } Guard(h, "Turret", "TurnTowardsTargetIfHasLOS", "TurretFinalizer"); Guard(h, "GameNetcodeStuff.PlayerControllerB", "DestroyItemInSlot", "DestroyFinalizer"); Guard(h, "GameNetcodeStuff.PlayerControllerB", "NearOtherPlayers", "NearFinalizer"); Log.LogInfo((object)"Protecciones contra errores repetidos activas - By: TaKi"); } private static Exception TurretFinalizer(Exception __exception, object __instance) { if (!(__exception is NullReferenceException)) { return __exception; } try { fTurretTarget?.SetValue(__instance, null); } catch { } Note("Torreta sin objetivo", __exception); return null; } private static Exception DestroyFinalizer(Exception __exception) { if (!(__exception is NullReferenceException)) { return __exception; } Note("Item ya borrado del inventario", __exception); return null; } private static Exception NearFinalizer(Exception __exception) { if (!(__exception is NullReferenceException)) { return __exception; } Note("Jugador cercano al cerrar la partida", __exception); return null; } } private static class HoarderFix { private static FieldInfo fTarget; private static FieldInfo fHeld; private static FieldInfo fItemObj; private static FieldInfo fMapList; private static FieldInfo fBugItems; private static DateTime lastLog = DateTime.MinValue; private static int swallowed; internal static void Apply(Harmony h) { //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Expected O, but got Unknown //IL_00cc: Expected O, but got Unknown try { Type type = AccessTools.TypeByName("HoarderBugAI"); Type type2 = AccessTools.TypeByName("HoarderBugItem"); if (type == null) { Log.LogError((object)"No encontre HoarderBugAI."); return; } fTarget = AccessTools.Field(type, "targetItem"); fHeld = AccessTools.Field(type, "heldItem"); fMapList = AccessTools.Field(type, "grabbableObjectsInMap"); fBugItems = AccessTools.Field(type, "HoarderBugItems"); if (type2 != null) { fItemObj = AccessTools.Field(type2, "itemGrabbableObject"); } h.Patch((MethodBase)AccessTools.Method(type, "DoAIInterval", (Type[])null, (Type[])null), new HarmonyMethod(typeof(HoarderFix), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(HoarderFix), "Finalizer", (Type[])null), (HarmonyMethod)null); Log.LogInfo((object)$"Arreglo Hoarding bug activo (target:{fTarget != null} held:{fHeld != null} mapa:{fMapList != null} nido:{fBugItems != null})"); } catch (Exception ex) { Log.LogError((object)("Arreglo Hoarding bug fallo: " + ex)); } } private static bool Dead(object o) { if (o == null) { return true; } Object val = (Object)((o is Object) ? o : null); if (val != null) { return val == (Object)null; } return false; } private static void PurgeList(FieldInfo f, FieldInfo inner) { if (f == null || !(f.GetValue(null) is IList list)) { return; } for (int num = list.Count - 1; num >= 0; num--) { object obj = list[num]; bool num2; if (!(inner == null)) { if (obj == null) { goto IL_0052; } num2 = Dead(inner.GetValue(obj)); } else { num2 = Dead(obj); } if (!num2) { continue; } goto IL_0052; IL_0052: list.RemoveAt(num); } } private static void Clean(object bug, bool afterError) { if (fTarget != null) { object value = fTarget.GetValue(bug); if (value != null && (afterError || Dead(value))) { if (afterError && !Dead(value) && fMapList != null) { Component val = (Component)((value is Component) ? value : null); if (val != null) { try { (fMapList.GetValue(null) as IList)?.Remove(val.gameObject); } catch { } } } fTarget.SetValue(bug, null); } } if (fHeld != null && fItemObj != null) { object value2 = fHeld.GetValue(bug); if (value2 != null && Dead(fItemObj.GetValue(value2))) { fHeld.SetValue(bug, null); } } PurgeList(fMapList, null); PurgeList(fBugItems, fItemObj); } private static void Prefix(object __instance) { try { Clean(__instance, afterError: false); } catch { } } private static Exception Finalizer(Exception __exception, object __instance) { if (__exception == null) { return null; } try { Clean(__instance, afterError: true); } catch { } swallowed++; if ((DateTime.Now - lastLog).TotalSeconds > 30.0) { lastLog = DateTime.Now; Log.LogWarning((object)$"Hoarding bug destrabado ({swallowed} errores evitados). {__exception.GetType().Name}: {__exception.Message}"); } return null; } } private static class MoonPrices { private static PropertyInfo pLevels; private static PropertyInfo pPrice; private static PropertyInfo pName; private static PropertyInfo pSel; private static FieldInfo fRisk; private static readonly Regex moonLine = new Regex("^(\\s*\\*\\s+)(.+?)(\\s*(\\(.*)?)$"); private static readonly ConditionalWeakTable<object, int[]> state = new ConditionalWeakTable<object, int[]>(); internal static void Apply(Harmony h) { //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Expected O, but got Unknown //IL_011c: 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_0130: Expected O, but got Unknown try { Type type = AccessTools.TypeByName("LethalLevelLoader.PatchedContent"); Type type2 = AccessTools.TypeByName("LethalLevelLoader.ExtendedLevel"); Type type3 = AccessTools.TypeByName("Terminal"); if (type == null || type2 == null || type3 == null) { Log.LogError((object)"No encontre LethalLevelLoader, no cambio precios."); return; } pLevels = AccessTools.Property(type, "ExtendedLevels"); pPrice = AccessTools.Property(type2, "RoutePrice"); pName = AccessTools.Property(type2, "NumberlessPlanetName"); pSel = AccessTools.Property(type2, "SelectableLevel"); Type type4 = AccessTools.TypeByName("SelectableLevel"); if (type4 != null) { fRisk = AccessTools.Field(type4, "riskLevel"); } if (pLevels == null || pPrice == null) { Log.LogError((object)"Version de LethalLevelLoader no compatible para precios."); return; } MethodInfo methodInfo = AccessTools.Method(type3, "TextPostProcess", (Type[])null, (Type[])null); if (methodInfo != null && pName != null) { h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(MoonPrices), "ShowPrices", (Type[])null) { priority = 0 }, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } HarmonyMethod val = new HarmonyMethod(typeof(MoonPrices), "Refresh", (Type[])null); string[] array = new string[2] { "Start", "BeginUsingTerminal" }; foreach (string text in array) { MethodInfo methodInfo2 = AccessTools.Method(type3, text, (Type[])null, (Type[])null); if (methodInfo2 != null) { h.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } Log.LogInfo((object)$"Precio de lunas x{cfgPrice.Value} activo - By: TaKi"); } catch (Exception ex) { Log.LogError((object)("Cambio de precios fallo: " + ex)); } } private static void ShowPrices(ref string __result) { try { if (string.IsNullOrEmpty(__result) || __result.IndexOf('*') < 0) { return; } Refresh(); if (!(pLevels.GetValue(null) is IList list)) { return; } Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); foreach (object item in list) { if (item == null) { continue; } string text = pName.GetValue(item) as string; if (string.IsNullOrEmpty(text)) { continue; } string text2 = "($" + (int)pPrice.GetValue(item) + ")"; try { object obj = pSel?.GetValue(item); string text3 = ((obj != null && fRisk != null) ? (fRisk.GetValue(obj) as string) : null); if (!string.IsNullOrEmpty(text3)) { text2 = text2 + " [" + text3.Trim() + "]"; } } catch { } dictionary[text.Trim()] = text2; } string[] array = __result.Split('\n'); int num = 0; for (int i = 0; i < array.Length; i++) { string text4 = array[i].TrimEnd('\r'); if (!text4.Contains("$")) { Match match = moonLine.Match(text4); if (match.Success && dictionary.TryGetValue(match.Groups[2].Value.Trim(), out var value)) { string text5 = (array[i].EndsWith("\r") ? "\r" : ""); array[i] = match.Groups[1].Value + match.Groups[2].Value + " " + value + ((match.Groups[4].Success && match.Groups[4].Value.Length > 0) ? (" " + match.Groups[4].Value) : "") + text5; num++; } } } if (num >= 2) { __result = string.Join("\n", array); } } catch (Exception ex) { Log.LogWarning((object)("No pude mostrar precios: " + ex.Message)); } } private static void Refresh() { try { if (!(pLevels.GetValue(null) is IList list)) { return; } float value = cfgPrice.Value; foreach (object item in list) { if (item != null) { int current2 = (int)pPrice.GetValue(item); int[] value2 = state.GetValue(item, (object _) => new int[2] { current2, -1 }); if (current2 != value2[1]) { value2[0] = current2; } int num = (int)Math.Round((float)value2[0] * value, MidpointRounding.AwayFromZero); if (num < 0) { num = 0; } if (current2 != num) { pPrice.SetValue(item, num); } value2[1] = num; } } } catch (Exception ex) { Log.LogWarning((object)("No pude actualizar precios: " + ex.Message)); } } } private static class HerobrineSkins { private static FieldInfo fOverride; private static FieldInfo fRagdoll; private static PropertyInfo pSteamValid; private static PropertyInfo pSteamName; private const string BuiltInPlayers = "Taki=Gonzas_, elmaridodetumama=SexoFernandez, MateriaGris=Scambless, FraNn=FranN42_, Bataebata=Subduction_, Nano956=Nano956, NANOMG=Nano956, Sexymbol=Sexymbol"; private const string BuiltInGroup = "SexoFernandez, Scambless, Gonzas_, FranN42_, Subduction_, Nano956, Sexymbol"; private static FieldInfo fUsable; private static FieldInfo fSkinTex; private static PropertyInfo pPlayerSkin; internal static void Apply(Harmony h) { //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown try { Type type = AccessTools.TypeByName("Kittenji.HerobrineMod.Plugin"); if (type == null) { Log.LogInfo((object)"Herobrine no esta instalado, salteo skins."); return; } fOverride = AccessTools.Field(type, "MinecraftUsernameOverride"); fRagdoll = AccessTools.Field(type, "RagdollSkinTexture"); Type type2 = AccessTools.TypeByName("Steamworks.SteamClient"); if (type2 != null) { pSteamValid = AccessTools.Property(type2, "IsValid"); pSteamName = AccessTools.Property(type2, "Name"); } MethodInfo methodInfo = AccessTools.Method(type, "ProcessMinecraftUsernames", (Type[])null, (Type[])null); if (fOverride == null || methodInfo == null || pSteamName == null) { Log.LogWarning((object)"Version de Herobrine no compatible para skins."); return; } h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(HerobrineSkins), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); ApplyDisguise(h); Log.LogInfo((object)"Skins del grupo para Herobrine activas - By: TaKi"); } catch (Exception ex) { Log.LogError((object)("Skins de Herobrine fallo: " + ex)); } } private static string Norm(string s) { return (s ?? "").Trim().ToLowerInvariant(); } private static string LookupForLocal() { if (pSteamValid != null && !(bool)pSteamValid.GetValue(null)) { return null; } string text = pSteamName.GetValue(null) as string; if (string.IsNullOrWhiteSpace(text)) { return null; } string[] array = (cfgSkins?.Value + ",Taki=Gonzas_, elmaridodetumama=SexoFernandez, MateriaGris=Scambless, FraNn=FranN42_, Bataebata=Subduction_, Nano956=Nano956, NANOMG=Nano956, Sexymbol=Sexymbol").Split(','); foreach (string text2 in array) { int num = text2.IndexOf('='); if (num > 0) { string s = text2.Substring(0, num); string text3 = text2.Substring(num + 1).Trim(); if (text3.Length > 0 && Norm(s) == Norm(text)) { return text3; } } } Log.LogInfo((object)("No hay skin configurada para el jugador de Steam '" + text + "'.")); return null; } private static bool Prefix() { try { if (!(fOverride.GetValue(null) is ConfigEntry<string> val)) { return true; } string text = LookupForLocal(); try { if (fRagdoll?.GetValue(null) is ConfigEntry<bool> val2 && val2.Value != (text != null)) { val2.Value = text != null; } } catch { } List<string> list = new List<string>(); string[] array = (cfgGroup?.Value + ",SexoFernandez, Scambless, Gonzas_, FranN42_, Subduction_, Nano956, Sexymbol").Split(','); foreach (string text2 in array) { string n = text2.Trim(); if (n.Length != 0 && (text == null || !(Norm(n) == Norm(text))) && !list.Exists((string x) => Norm(x) == Norm(n))) { list.Add(n); } } if (text != null) { list.Add(text); } if (list.Count == 0) { return true; } string text3 = string.Join(",", list); if (string.Equals(val.Value, text3, StringComparison.Ordinal)) { return true; } Log.LogInfo((object)("Skins del grupo para Herobrine: " + text3 + " (tuya: " + (text ?? "desconocida") + ")")); val.Value = text3; return false; } catch (Exception ex) { Log.LogWarning((object)("No pude asignar las skins: " + ex.Message)); return true; } } private static void SkinPrefix(out object __state) { __state = null; try { if (fUsable == null || pPlayerSkin == null || fSkinTex == null || !(fUsable.GetValue(null) is IList { Count: not 0 } list)) { return; } object value = pPlayerSkin.GetValue(null); object obj = ((value != null) ? fSkinTex.GetValue(value) : null); if (obj == null) { return; } List<KeyValuePair<int, object>> list2 = new List<KeyValuePair<int, object>>(); for (int num = list.Count - 1; num >= 0; num--) { object obj2 = list[num]; if (obj2?.GetType().GetProperty("Key")?.GetValue(obj2) == obj) { list2.Add(new KeyValuePair<int, object>(num, obj2)); list.RemoveAt(num); } } if (list2.Count > 0) { __state = list2; } } catch { } } private static Exception SkinFinalizer(Exception __exception, object __state) { try { if (__state is List<KeyValuePair<int, object>> list && fUsable.GetValue(null) is IList list2) { for (int num = list.Count - 1; num >= 0; num--) { int index = Math.Min(list[num].Key, list2.Count); list2.Insert(index, list[num].Value); } } } catch { } return __exception; } internal static void ApplyDisguise(Harmony h) { //IL_00d2: 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_00f4: Expected O, but got Unknown //IL_00f4: Expected O, but got Unknown try { Type type = AccessTools.TypeByName("Kittenji.HerobrineMod.Skins.MCSkinAPI"); Type type2 = AccessTools.TypeByName("Kittenji.HerobrineMod.Skins.MinecraftSkin"); Type type3 = AccessTools.TypeByName("Kittenji.HerobrineMod.HerobrineAI"); if (!(type == null) && !(type2 == null) && !(type3 == null)) { fUsable = AccessTools.Field(type, "UsableSkins"); pPlayerSkin = AccessTools.Property(type, "PlayerSkin"); fSkinTex = AccessTools.Field(type2, "texture"); MethodInfo methodInfo = AccessTools.Method(type3, "SetPlayerSkin", (Type[])null, (Type[])null); if (methodInfo == null || fUsable == null || pPlayerSkin == null || fSkinTex == null) { Log.LogWarning((object)"No pude enganchar el disfraz de Herobrine."); } else { h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(HerobrineSkins), "SkinPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(HerobrineSkins), "SkinFinalizer", (Type[])null), (HarmonyMethod)null); } } } catch (Exception ex) { Log.LogError((object)("Disfraz de Herobrine fallo: " + ex)); } } } internal static ManualLogSource Log; private static ConfigEntry<bool> cfgHoarder; private static ConfigEntry<float> cfgPrice; private static ConfigEntry<string> cfgSkins; private static ConfigEntry<string> cfgGroup; private void Awake() { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; cfgHoarder = ((BaseUnityPlugin)this).Config.Bind<bool>("Hoarding bug", "Arreglo activado", true, "Destraba al Hoarding bug cuando el item que busca o tiene fue destruido."); cfgPrice = ((BaseUnityPlugin)this).Config.Bind<float>("Lunas", "Multiplicador de precio", 0.5f, new ConfigDescription("Precio de las lunas. 1 = normal, 0.5 = mitad, 0.25 = un cuarto, 0 = gratis.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); Harmony h = new Harmony("taki.lethaltweaks"); if (cfgHoarder.Value) { HoarderFix.Apply(h); } MoonPrices.Apply(h); try { cfgSkins = ((BaseUnityPlugin)this).Config.Bind<string>("Herobrine", "Jugadores Steam a Minecraft", "", "Lista separada por comas de NombreDeSteam=NickDeMinecraft. Sirve para saber cual es TU skin (la de tu cuerpo al morir) y para que Herobrine nunca se disfrace de vos."); cfgGroup = ((BaseUnityPlugin)this).Config.Bind<string>("Herobrine", "Nicks del grupo", "", "Nicks de Minecraft del grupo. Cuando Herobrine se disfraza, usa la skin de alguno de ellos (nunca la del jugador al que persigue)."); HerobrineSkins.Apply(h); } catch (Exception ex) { Log.LogError((object)("Skins de Herobrine desactivadas: " + ex.Message)); } try { ErrorGuards.Apply(h); } catch (Exception ex2) { Log.LogError((object)("Protecciones de errores desactivadas: " + ex2.Message)); } } } }