using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComputerysModdingUtilities;
using FishNet.Object;
using HarmonyLib;
using ModMenu.Api;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("NoGore")]
[assembly: AssemblyDescription("Hides ragdolls, body pieces and hats that fall off players, and removes blood.")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: StraftatMod(true)]
[assembly: AssemblyVersion("1.3.5.0")]
namespace NoGore;
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("dorsth.straftat.nogore", "NoGore", "1.3.5")]
public sealed class NoGorePlugin : BaseUnityPlugin
{
public const string Guid = "dorsth.straftat.nogore";
public const string Name = "NoGore";
public const string Version = "1.3.5";
internal static ManualLogSource Log;
internal static ConfigEntry<bool> HideBodies;
internal static ConfigEntry<bool> HideRagdolls;
internal static ConfigEntry<bool> HideHats;
internal static ConfigEntry<bool> NoBlood;
internal static ConfigEntry<bool> NoHitBlood;
internal static ConfigEntry<bool> NoDeathBlood;
internal static ConfigEntry<bool> NoBloodStains;
private static bool _errorLogged;
internal static bool Ragdolls
{
get
{
if (!HideBodies.Value)
{
return HideRagdolls.Value;
}
return true;
}
}
internal static bool Hats
{
get
{
if (!HideBodies.Value)
{
return HideHats.Value;
}
return true;
}
}
internal static bool HitBlood
{
get
{
if (!NoBlood.Value)
{
return NoHitBlood.Value;
}
return true;
}
}
internal static bool DeathBlood
{
get
{
if (!NoBlood.Value)
{
return NoDeathBlood.Value;
}
return true;
}
}
internal static bool Stains
{
get
{
if (!NoBlood.Value)
{
return NoBloodStains.Value;
}
return true;
}
}
private static void FromOldName(ConfigFile c, ConfigDefinition old, ConfigEntry<bool> now)
{
try
{
if (AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(c, null) is Dictionary<ConfigDefinition, string> dictionary && dictionary.TryGetValue(old, out var value))
{
if (bool.TryParse(value, out var result))
{
now.Value = result;
}
dictionary.Remove(old);
c.Save();
}
}
catch
{
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void ModMenuDescription()
{
ModMenuCustomisation.SetPluginDescription("Hides blood, bodies, ragdolls and hats that come off players. Only on your screen.");
}
private void Awake()
{
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Expected O, but got Unknown
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"NoGore 1.3.5 loaded. Dorsth was here.");
if (Chainloader.PluginInfos.ContainsKey("kestrel.straftat.modmenu"))
{
try
{
ModMenuDescription();
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Mod Menu description: " + ex.Message));
}
}
HideBodies = ((BaseUnityPlugin)this).Config.Bind<bool>("Bodies", "Hide Bodies", true, "No ragdolls, body pieces or dropped hats. Turn off to pick which.");
HideRagdolls = ((BaseUnityPlugin)this).Config.Bind<bool>("Bodies", "Hide Ragdolls", false, "Dead bodies (yours too) and the pieces from an explosive death.");
HideHats = ((BaseUnityPlugin)this).Config.Bind<bool>("Bodies", "Hide Dropped Hats", false, "Hats that come off players.");
FromOldName(((BaseUnityPlugin)this).Config, new ConfigDefinition("Bodies", "Hide Hats"), HideHats);
NoBlood = ((BaseUnityPlugin)this).Config.Bind<bool>("Blood", "No Blood", true, "No blood at all. Turn off to pick which.");
NoHitBlood = ((BaseUnityPlugin)this).Config.Bind<bool>("Blood", "No Hit Blood", false, "Blood from hits.");
NoDeathBlood = ((BaseUnityPlugin)this).Config.Bind<bool>("Blood", "No Death Blood", false, "The blood that comes out of a body when it dies. It shows without the body too.");
NoBloodStains = ((BaseUnityPlugin)this).Config.Bind<bool>("Blood", "No Blood Stains", false, "Blood left on floors and walls.");
try
{
CarryOld();
}
catch (Exception ex2)
{
Log.LogWarning((object)("The old settings could not be carried over. (" + ex2.Message + ")"));
}
Harmony harmony = new Harmony("dorsth.straftat.nogore");
Install("deaths", delegate
{
Deaths.Install(harmony);
});
Install("blood", delegate
{
Blood.Install(harmony);
});
Install("mod menu links", delegate
{
MenuLinks.Install(harmony);
});
}
private void CarryOld()
{
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Expected O, but got Unknown
Dictionary<ConfigDefinition, string> left = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries")?.GetValue(((BaseUnityPlugin)this).Config, null) as Dictionary<ConfigDefinition, string>;
if (left == null || left.Count == 0)
{
return;
}
string value2;
Func<string, bool?> obj = (string section) => (!left.TryGetValue(new ConfigDefinition(section, "Enabled"), out value2) || value2 == null) ? ((bool?)null) : new bool?(string.Equals(value2.Trim(), "true", StringComparison.OrdinalIgnoreCase));
bool? flag = obj("NoRagdoll");
bool? flag2 = obj("NoBlood");
bool? flag3 = obj("NoBloodParticles");
bool? flag4 = obj("NoBloodTextures");
if (flag == false)
{
HideBodies.Value = false;
}
if (flag3.HasValue || flag4.HasValue)
{
bool flag5 = flag3 ?? true;
bool flag6 = flag4 ?? true;
NoBlood.Value = flag5 && flag6;
if (!NoBlood.Value)
{
NoHitBlood.Value = flag5;
NoDeathBlood.Value = flag5;
NoBloodStains.Value = flag6;
}
}
else if (flag2 == false)
{
NoBlood.Value = false;
}
if (left.TryGetValue(new ConfigDefinition("Blood", "No Blood Spray"), out var value) && value != null && string.Equals(value.Trim(), "true", StringComparison.OrdinalIgnoreCase))
{
NoHitBlood.Value = true;
NoDeathBlood.Value = true;
}
left.Clear();
((BaseUnityPlugin)this).Config.Save();
}
private static void Install(string feature, Action install)
{
try
{
install();
}
catch (Exception ex)
{
Log.LogWarning((object)("The " + feature + " hooks don't fit this game version, so they're off. (" + ex.Message + ")"));
}
}
internal static void LogErrorOnce(Exception e)
{
if (!_errorLogged)
{
_errorLogged = true;
Log.LogError((object)("Error (further errors are not logged): " + e));
}
}
internal static MethodInfo Method(Type type, string name)
{
MethodInfo methodInfo = AccessTools.Method(type, name, (Type[])null, (Type[])null);
if (methodInfo == null)
{
throw new MissingMethodException(type.Name, name);
}
return methodInfo;
}
internal static MethodInfo Rpc(Type type, string name)
{
foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(type))
{
if (declaredMethod.Name.StartsWith("RpcLogic___" + name + "_", StringComparison.Ordinal))
{
return declaredMethod;
}
}
throw new MissingMethodException(type.Name, "RpcLogic___" + name);
}
internal static HarmonyMethod Patch(Type type, string name)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
return new HarmonyMethod(Method(type, name));
}
}
internal static class Deaths
{
private struct Loose
{
public Transform Hips;
public GameObject Blood;
}
internal struct State
{
public bool Active;
public GameObject[] Parts;
public GameObject BloodFX;
public KillCam Cam;
public Transform CamRagdoll;
public Vector3 CamFirstPosition;
public bool CamTrigger;
}
private static readonly GameObject[] NoParts = (GameObject[])(object)new GameObject[0];
private static FieldRef<PlayerHealth, bool> _spawnedRagdoll;
private static FieldRef<PlayerHealth, GameObject[]> _bodyParts;
private static FieldRef<PlayerHealth, GameObject> _bloodFX;
private static FieldRef<PlayerHealth, KillCam> _killCam;
private static bool _ownSpawn;
private static readonly List<Loose> LooseBlood = new List<Loose>(32);
internal static void Install(Harmony harmony)
{
_spawnedRagdoll = AccessTools.FieldRefAccess<PlayerHealth, bool>("spawnedRagdoll");
_bodyParts = AccessTools.FieldRefAccess<PlayerHealth, GameObject[]>("bodyParts");
_bloodFX = AccessTools.FieldRefAccess<PlayerHealth, GameObject>("bloodFX");
_killCam = AccessTools.FieldRefAccess<PlayerHealth, KillCam>("killCamScript");
MethodInfo methodInfo = NoGorePlugin.Rpc(typeof(PlayerHealth), "ExplodeForAll");
harmony.Patch((MethodBase)methodInfo, NoGorePlugin.Patch(typeof(Deaths), "DeathPrefix"), NoGorePlugin.Patch(typeof(Deaths), "DeathPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
try
{
harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, NoGorePlugin.Patch(typeof(Deaths), "DeathTranspiler"), (HarmonyMethod)null, (HarmonyMethod)null);
}
catch (Exception ex)
{
_ownSpawn = false;
NoGorePlugin.Log.LogWarning((object)("Death blood is handled the old way in this game version. (" + ex.Message + ")"));
}
harmony.Patch((MethodBase)NoGorePlugin.Method(typeof(PlayerHealth), "Hat"), (HarmonyMethod)null, NoGorePlugin.Patch(typeof(Deaths), "HatPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)NoGorePlugin.Method(typeof(Weapon), "TriggerEnvironment"), (HarmonyMethod)null, NoGorePlugin.Patch(typeof(Deaths), "ShotHatPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private static IEnumerable<CodeInstruction> DeathTranspiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
MethodInfo methodInfo = AccessTools.Method(typeof(Deaths), "SpawnDeathBlood", (Type[])null, (Type[])null);
int index = -1;
int num = 0;
for (int i = 0; i < list.Count; i++)
{
MethodInfo methodInfo2 = list[i].operand as MethodInfo;
if (!(methodInfo2 == null) && !(list[i].opcode != OpCodes.Call) && !(methodInfo2.Name != "Instantiate") && !(methodInfo2.DeclaringType != typeof(Object)))
{
ParameterInfo[] parameters = methodInfo2.GetParameters();
if (parameters.Length == 4 && !(parameters[1].ParameterType != typeof(Vector3)) && !(parameters[2].ParameterType != typeof(Quaternion)) && !(parameters[3].ParameterType != typeof(Transform)) && (!(parameters[0].ParameterType != typeof(GameObject)) || !(parameters[0].ParameterType != typeof(Object))))
{
index = i;
num++;
}
}
}
_ownSpawn = methodInfo != null && num == 1;
if (_ownSpawn)
{
list[index].operand = methodInfo;
}
else
{
NoGorePlugin.Log.LogWarning((object)("Death blood is handled the old way in this game version (its spawn was found " + num + " times)."));
}
return list;
}
private static GameObject SpawnDeathBlood(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent)
{
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
try
{
for (int num = LooseBlood.Count - 1; num >= 0; num--)
{
if (!((Object)(object)LooseBlood[num].Hips != (Object)null))
{
if ((Object)(object)LooseBlood[num].Blood != (Object)null)
{
Object.Destroy((Object)(object)LooseBlood[num].Blood);
}
LooseBlood.RemoveAt(num);
}
}
if (NoGorePlugin.DeathBlood)
{
return null;
}
if (!NoGorePlugin.Ragdolls)
{
return Object.Instantiate<GameObject>(prefab, position, rotation, parent);
}
GameObject val = Object.Instantiate<GameObject>(prefab, position, rotation);
if (LooseBlood.Count < 256)
{
LooseBlood.Add(new Loose
{
Hips = parent,
Blood = val
});
}
return val;
}
catch (Exception e)
{
NoGorePlugin.LogErrorOnce(e);
return Object.Instantiate<GameObject>(prefab, position, rotation, parent);
}
}
private static void DeathPrefix(PlayerHealth __instance, bool explode, out State __state)
{
//IL_00c2: 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)
__state = default(State);
try
{
if (_spawnedRagdoll.Invoke(__instance))
{
return;
}
__state.Active = true;
if (!_ownSpawn && NoGorePlugin.DeathBlood)
{
__state.BloodFX = _bloodFX.Invoke(__instance);
_bloodFX.Invoke(__instance) = Blood.Placeholder();
}
if (explode)
{
if (NoGorePlugin.Ragdolls)
{
__state.Parts = _bodyParts.Invoke(__instance);
_bodyParts.Invoke(__instance) = NoParts;
}
}
else if (NoGorePlugin.Ragdolls && !((NetworkBehaviour)__instance).IsOwner)
{
KillCam val = _killCam.Invoke(__instance);
if (!((Object)(object)val == (Object)null))
{
__state.Cam = val;
__state.CamRagdoll = val.ragdoll;
__state.CamFirstPosition = val.firstPosition;
__state.CamTrigger = val.triggerLookAtBody;
}
}
}
catch (Exception e)
{
NoGorePlugin.LogErrorOnce(e);
}
}
private static void DeathPostfix(PlayerHealth __instance, bool explode, State __state)
{
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
if (!__state.Active)
{
return;
}
try
{
if ((Object)(object)__state.BloodFX != (Object)null)
{
_bloodFX.Invoke(__instance) = __state.BloodFX;
}
if (__state.Parts != null)
{
_bodyParts.Invoke(__instance) = __state.Parts;
}
if (!explode && NoGorePlugin.Ragdolls)
{
KillCam val = _killCam.Invoke(__instance);
if ((Object)(object)val != (Object)null && (Object)(object)val.ragdoll != (Object)null)
{
Hide(((Component)val.ragdoll).gameObject);
}
if (!((Object)(object)__state.Cam == (Object)null))
{
__state.Cam.ragdoll = __state.CamRagdoll;
__state.Cam.firstPosition = __state.CamFirstPosition;
__state.Cam.triggerLookAtBody = __state.CamTrigger;
}
}
}
catch (Exception e)
{
NoGorePlugin.LogErrorOnce(e);
}
}
private static void HatPostfix(GameObject obj)
{
try
{
if (NoGorePlugin.Hats && (Object)(object)obj != (Object)null)
{
Hide(obj);
}
}
catch (Exception e)
{
NoGorePlugin.LogErrorOnce(e);
}
}
private static void ShotHatPostfix(GameObject obj)
{
try
{
if (NoGorePlugin.Hats && (Object)(object)obj != (Object)null && (Object)(object)obj.transform.parent == (Object)null && obj.CompareTag("Hat"))
{
Hide(obj);
}
}
catch (Exception e)
{
NoGorePlugin.LogErrorOnce(e);
}
}
private static void Hide(GameObject go)
{
Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
componentsInChildren[i].enabled = false;
}
Collider[] componentsInChildren2 = go.GetComponentsInChildren<Collider>(true);
for (int i = 0; i < componentsInChildren2.Length; i++)
{
componentsInChildren2[i].enabled = false;
}
Rigidbody[] componentsInChildren3 = go.GetComponentsInChildren<Rigidbody>(true);
for (int i = 0; i < componentsInChildren3.Length; i++)
{
componentsInChildren3[i].isKinematic = true;
}
go.SetActive(false);
}
}
internal static class Blood
{
internal struct Saved
{
public Weapon Weapon;
public GameObject Head;
public GameObject Body;
public GameObject Generic;
public GameObject Splatter;
}
private sealed class EmptyEffect : MonoBehaviour
{
private void Awake()
{
if ((Object)(object)((Component)this).gameObject != (Object)(object)_placeholder)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
}
}
}
private static GameObject _placeholder;
private static FieldRef<MeleeChildCollision, MeleeWeapon> _meleeWeapon;
private static readonly Dictionary<MethodBase, FieldRef<object, GameObject>[]> SpawnFields = new Dictionary<MethodBase, FieldRef<object, GameObject>[]>();
private static readonly Dictionary<MethodBase, bool[]> SpawnStains = new Dictionary<MethodBase, bool[]>();
internal static void Install(Harmony harmony)
{
_meleeWeapon = AccessTools.FieldRefAccess<MeleeChildCollision, MeleeWeapon>("weaponScript");
HarmonyMethod arg = NoGorePlugin.Patch(typeof(Blood), "WeaponPrefix");
HarmonyMethod postfix = NoGorePlugin.Patch(typeof(Blood), "WeaponPostfix");
List<string> missing = new List<string>();
Action<Func<MethodInfo>, HarmonyMethod> action = delegate(Func<MethodInfo> find, HarmonyMethod pre)
{
try
{
harmony.Patch((MethodBase)find(), pre, postfix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
catch (Exception ex)
{
missing.Add(ex.Message);
}
};
Type[] array = new Type[6]
{
typeof(Gun),
typeof(BeamGun),
typeof(ChargeGun),
typeof(Minigun),
typeof(Shotgun),
typeof(LargeRaycastGun)
};
foreach (Type gun in array)
{
action(() => NoGorePlugin.Method(gun, "ShootServer"), arg);
action(() => NoGorePlugin.Rpc(gun, "ObserversFX"), arg);
action(() => NoGorePlugin.Rpc(gun, "SpawnVFX"), arg);
}
action(() => NoGorePlugin.Method(typeof(LargeRaycastGun), "ShootServerBox"), arg);
action(() => NoGorePlugin.Method(typeof(MeleeWeapon), "HitServer"), arg);
action(() => NoGorePlugin.Rpc(typeof(MeleeWeapon), "SpawnVFX"), arg);
action(() => NoGorePlugin.Rpc(typeof(Taser), "SpawnVFX"), arg);
action(() => NoGorePlugin.Rpc(typeof(RepulsiveGun), "SpawnVFX"), arg);
action(() => NoGorePlugin.Method(typeof(Weapon), "TriggerEnvironment"), arg);
action(() => NoGorePlugin.Method(typeof(MeleeChildCollision), "OnCollisionEnter"), NoGorePlugin.Patch(typeof(Blood), "MeleePrefix"));
Action<Func<MethodInfo>, Type, string[]> action2 = delegate(Func<MethodInfo> find, Type type, string[] fields)
{
try
{
SwapOnSpawn(harmony, find(), type, fields);
}
catch (Exception ex)
{
missing.Add(ex.Message);
}
};
action2(() => NoGorePlugin.Method(typeof(PredictedProjectile), "Awake"), typeof(PredictedProjectile), new string[3] { "bloodVfx", "headBloodVfx", "bloodSplatter" });
action2(() => NoGorePlugin.Method(typeof(ShrapnelBallistic), "Awake"), typeof(ShrapnelBallistic), new string[1] { "bloodSplatter" });
action2(() => NoGorePlugin.Rpc(typeof(PhysicsGrenade), "HandleExplosion"), typeof(PhysicsGrenade), new string[1] { "bloodSplatter" });
action2(() => NoGorePlugin.Method(typeof(PhysicsProp), "Start"), typeof(PhysicsProp), new string[1] { "bloodImpact" });
if (missing.Count > 0)
{
NoGorePlugin.Log.LogWarning((object)("NoBlood skipped what's not in this game version: " + string.Join("; ", missing.ToArray())));
}
}
private static void SwapOnSpawn(Harmony harmony, MethodInfo method, Type type, string[] fields)
{
FieldRef<object, GameObject>[] array = new FieldRef<object, GameObject>[fields.Length];
bool[] array2 = new bool[fields.Length];
for (int i = 0; i < fields.Length; i++)
{
FieldInfo fieldInfo = AccessTools.Field(type, fields[i]);
if (fieldInfo == null)
{
throw new MissingFieldException(type.Name, fields[i]);
}
array[i] = AccessTools.FieldRefAccess<object, GameObject>(fieldInfo);
array2[i] = fields[i] == "bloodSplatter";
}
SpawnFields[method] = array;
SpawnStains[method] = array2;
harmony.Patch((MethodBase)method, NoGorePlugin.Patch(typeof(Blood), "SpawnPrefix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private static void WeaponPrefix(Weapon __instance, out Saved __state)
{
__state = default(Saved);
if (NoGorePlugin.HitBlood || NoGorePlugin.Stains)
{
Swap(__instance, ref __state);
}
}
private static void MeleePrefix(MeleeChildCollision __instance, out Saved __state)
{
__state = default(Saved);
if (NoGorePlugin.HitBlood || NoGorePlugin.Stains)
{
Swap((Weapon)(object)_meleeWeapon.Invoke(__instance), ref __state);
}
}
private static void Swap(Weapon w, ref Saved s)
{
if (!((Object)(object)w == (Object)null))
{
GameObject val = Placeholder();
s.Weapon = w;
s.Head = w.headImpact;
s.Body = w.bodyImpact;
s.Generic = w.genericBodyImpact;
s.Splatter = w.bloodSplatter;
if (NoGorePlugin.HitBlood)
{
w.headImpact = (w.bodyImpact = (w.genericBodyImpact = val));
}
if (NoGorePlugin.Stains)
{
w.bloodSplatter = val;
}
}
}
private static void WeaponPostfix(Saved __state)
{
Weapon weapon = __state.Weapon;
if (weapon != null)
{
weapon.headImpact = __state.Head;
weapon.bodyImpact = __state.Body;
weapon.genericBodyImpact = __state.Generic;
weapon.bloodSplatter = __state.Splatter;
}
}
private static void SpawnPrefix(object __instance, MethodBase __originalMethod)
{
try
{
bool hitBlood = NoGorePlugin.HitBlood;
bool stains = NoGorePlugin.Stains;
if (!hitBlood && !stains)
{
return;
}
GameObject val = Placeholder();
FieldRef<object, GameObject>[] array = SpawnFields[__originalMethod];
bool[] array2 = SpawnStains[__originalMethod];
for (int i = 0; i < array.Length; i++)
{
if (array2[i] ? stains : hitBlood)
{
array[i].Invoke(__instance) = val;
}
}
}
catch (Exception e)
{
NoGorePlugin.LogErrorOnce(e);
}
}
internal static GameObject Placeholder()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
if ((Object)(object)_placeholder == (Object)null)
{
_placeholder = new GameObject("NoGore_EmptyBlood")
{
hideFlags = (HideFlags)61
};
_placeholder.AddComponent<EmptyEffect>();
}
return _placeholder;
}
}
internal static class MenuLinks
{
private static Type _panel;
private static Type _boxed;
private static FieldInfo _cache;
private static FieldInfo _current;
private static FieldInfo _source;
private static FieldInfo _search;
private static PropertyInfo _entry;
private static readonly Dictionary<int, ConfigEntryBase> RowEntry = new Dictionary<int, ConfigEntryBase>();
internal static void Install(Harmony harmony)
{
_panel = null;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
_panel = assemblies[i].GetType("ModMenu.Behaviours.OptionList.OptionListPanel", throwOnError: false);
if (_panel != null)
{
break;
}
}
if (_panel == null)
{
return;
}
_boxed = AccessTools.TypeByName("ModMenu.Behaviours.OptionList.ValueControllers.BoxedValueController");
Type type = AccessTools.TypeByName("ModMenu.Options.Option");
_cache = AccessTools.Field(_panel, "m_optionCache");
_current = AccessTools.Field(_panel, "m_currentEnabledGuid");
_search = AccessTools.Field(_panel, "searchBar");
_source = ((_boxed != null) ? AccessTools.Field(_boxed, "sourceOption") : null);
_entry = ((type != null) ? AccessTools.Property(type, "BaseEntry") : null);
if (_boxed == null || _cache == null || _current == null || _source == null || _entry == null)
{
return;
}
ConfigEntryBase[] array = (ConfigEntryBase[])(object)new ConfigEntryBase[2]
{
(ConfigEntryBase)NoGorePlugin.HideBodies,
(ConfigEntryBase)NoGorePlugin.NoBlood
};
foreach (ConfigEntryBase val in array)
{
ConfigEntryBase group = val;
group.ConfigFile.SettingChanged += delegate(object sender, SettingChangedEventArgs args)
{
if (args.ChangedSetting == group)
{
Refresh();
}
};
}
HarmonyMethod val2 = NoGorePlugin.Patch(typeof(MenuLinks), "ShownPostfix");
harmony.Patch((MethodBase)NoGorePlugin.Method(_panel, "ShowListFor"), (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)NoGorePlugin.Method(_panel, "FilterOptionList"), (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private static bool Hidden(ConfigEntryBase e)
{
if ((object)e == NoGorePlugin.HideRagdolls || (object)e == NoGorePlugin.HideHats)
{
return NoGorePlugin.HideBodies.Value;
}
if ((object)e == NoGorePlugin.NoHitBlood || (object)e == NoGorePlugin.NoDeathBlood || (object)e == NoGorePlugin.NoBloodStains)
{
return NoGorePlugin.NoBlood.Value;
}
return false;
}
private static void ShownPostfix(object __instance)
{
try
{
if (!(_current.GetValue(__instance) as string == "dorsth.straftat.nogore") || !(_cache.GetValue(__instance) is Dictionary<string, GameObject[]> dictionary) || !dictionary.TryGetValue("dorsth.straftat.nogore", out var value))
{
return;
}
GameObject[] array = value;
foreach (GameObject val in array)
{
if (!((Object)(object)val == (Object)null) && val.activeSelf)
{
int instanceID = ((Object)val).GetInstanceID();
if (!RowEntry.TryGetValue(instanceID, out var value2))
{
Component component = val.GetComponent(_boxed);
object obj = (((Object)(object)component != (Object)null) ? _source.GetValue(component) : null);
value2 = (RowEntry[instanceID] = (ConfigEntryBase)((obj != null) ? /*isinst with value type is only supported in some contexts*/: null));
}
if (value2 != null && Hidden(value2))
{
val.SetActive(false);
}
}
}
}
catch (Exception e)
{
NoGorePlugin.LogErrorOnce(e);
}
}
private static void Refresh()
{
try
{
Object[] array = Object.FindObjectsOfType(_panel);
foreach (Object obj in array)
{
if (_current.GetValue(obj) as string == "dorsth.straftat.nogore")
{
string text = "";
TMP_InputField val = (TMP_InputField)((_search != null) ? /*isinst with value type is only supported in some contexts*/: null);
if ((Object)(object)val != (Object)null)
{
text = val.text ?? "";
}
NoGorePlugin.Method(_panel, "FilterOptionList").Invoke(obj, new object[1] { text });
}
}
}
catch (Exception e)
{
NoGorePlugin.LogErrorOnce(e);
}
}
}