using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace FishGodMode;
[BepInPlugin("com.fish.godmode", "FishGodMode", "2.4.0")]
public class Plugin : BaseUnityPlugin
{
private const int DMG = 500000;
internal static ManualLogSource Log;
internal static bool GodMode = false;
internal static bool InfAmmo = false;
internal static bool OneShot = false;
internal static bool AlwaysRare = false;
internal static bool BulletPierce = false;
internal static bool InfBait = false;
private bool prevAny = false;
private float timer = 0f;
private PropertyInfo gmProp = null;
private bool gmSearched = false;
private PropertyInfo cheatProp = null;
private FieldInfo cheatField = null;
private PropertyInfo devProp = null;
private FieldInfo devField = null;
private bool cheatSearched = false;
private Type weaponType = null;
private FieldInfo ammoField = null;
private FieldInfo weaponInfoField = null;
private FieldInfo projDmgField = null;
private Type attachmentsType = null;
private FieldInfo bulletUpgradesField = null;
private FieldInfo sharpUpgradesField = null;
private FieldInfo attachmentsField = null;
private Type bulletUpgradeType = null;
private FieldInfo bulletDmgField = null;
private Type sharpUpgradeType = null;
private FieldInfo sharpDmgField = null;
private Type punchType = null;
private FieldInfo punchDmgField = null;
private Type creatureMgrType = null;
private FieldInfo shinyChanceField = null;
private int origShinyChance = 1;
private Type baitInfoType = null;
private FieldInfo lostChanceField = null;
private Dictionary<int, float> baitSnap = new Dictionary<int, float>();
private PropertyInfo allBaitsProp = null;
private bool gameInfoSearched = false;
private Dictionary<int, int> ammoSnap = new Dictionary<int, int>();
private Dictionary<int, int> punchSnap = new Dictionary<int, int>();
private Dictionary<int, int> projDmgSnap = new Dictionary<int, int>();
private Dictionary<int, int> bulletDmgSnap = new Dictionary<int, int>();
private Dictionary<int, int> sharpDmgSnap = new Dictionary<int, int>();
private List<Object> weapons = new List<Object>();
private List<Object> punchers = new List<Object>();
private List<Object> creatureMgrs = new List<Object>();
private float lastRefresh = -100f;
private GUIStyle sMain = null;
private GUIStyle sShadow = null;
public void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Harmony harmony = new Harmony("com.fish.godmode");
PatchAll(harmony);
CacheTypes();
Log.LogInfo((object)"FishGodMode v2.4 loaded. Num1=God Num2=Ammo Num3=OneShot Num4=Rare Num5=Pierce Num6=Bait");
}
private void PatchAll(Harmony harmony)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Expected O, but got Unknown
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Expected O, but got Unknown
HarmonyMethod val = new HarmonyMethod(typeof(Patches), "DamageSkipPrefix", (Type[])null);
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
int num = 0;
Type type = AccessTools.TypeByName("PlayerVitals");
if (type != null)
{
MethodInfo[] methods = type.GetMethods(bindingAttr);
foreach (MethodInfo methodInfo in methods)
{
string text = methodInfo.Name.ToLower();
if (text.Contains("damage") || text.Contains("hurt") || text.Contains("kill") || text.Contains("takedamage"))
{
try
{
harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
num++;
}
catch (Exception ex)
{
Log.LogInfo((object)("Patch fail " + methodInfo.Name + ": " + ex.Message));
}
}
}
}
Log.LogInfo((object)("Patched " + num + " player damage methods"));
Type type2 = AccessTools.TypeByName("ProjectileManager");
if (type2 != null)
{
MethodInfo methodInfo2 = AccessTools.Method(type2, "Hit", new Type[3]
{
AccessTools.TypeByName("Projectile"),
AccessTools.TypeByName("ProjectileType"),
typeof(RaycastHit)
}, (Type[])null);
if (methodInfo2 != null)
{
harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Patches), "HitPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Log.LogInfo((object)"Patched ProjectileManager.Hit for penetration");
}
}
Type type3 = AccessTools.TypeByName("Weapon");
if (type3 != null)
{
MethodInfo methodInfo3 = AccessTools.Method(type3, "GunClippingRay", (Type[])null, (Type[])null);
if (methodInfo3 != null)
{
harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "GunClippingRayPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Log.LogInfo((object)"Patched Weapon.GunClippingRay for penetration");
}
}
}
private void CacheTypes()
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
weaponType = AccessTools.TypeByName("Weapon");
if (weaponType != null)
{
ammoField = weaponType.GetField("<Ammo>k__BackingField", bindingAttr);
weaponInfoField = weaponType.GetField("_weaponInfo", bindingAttr);
attachmentsField = weaponType.GetField("_attachments", bindingAttr);
}
Type type = AccessTools.TypeByName("WeaponInfo");
if (type != null)
{
projDmgField = type.GetField("<ProjectileDamage>k__BackingField", bindingAttr);
}
attachmentsType = AccessTools.TypeByName("Attachments");
if (attachmentsType != null)
{
bulletUpgradesField = attachmentsType.GetField("_bulletUpgrades", bindingAttr);
if (bulletUpgradesField == null)
{
bulletUpgradesField = attachmentsType.GetField("bulletUpgrades", bindingAttr);
}
sharpUpgradesField = attachmentsType.GetField("_sharpnessUpgrades", bindingAttr);
if (sharpUpgradesField == null)
{
sharpUpgradesField = attachmentsType.GetField("sharpnessUpgrades", bindingAttr);
}
}
bulletUpgradeType = AccessTools.TypeByName("BulletUpgrade");
if (bulletUpgradeType != null)
{
bulletDmgField = bulletUpgradeType.GetField("_damage", bindingAttr);
}
sharpUpgradeType = AccessTools.TypeByName("SharpnessUpgrade");
if (sharpUpgradeType != null)
{
sharpDmgField = sharpUpgradeType.GetField("_damage", bindingAttr);
}
punchType = AccessTools.TypeByName("PlayerPunching");
if (punchType != null)
{
punchDmgField = punchType.GetField("_damage", bindingAttr);
}
creatureMgrType = AccessTools.TypeByName("CreatureManager");
if (creatureMgrType != null)
{
shinyChanceField = creatureMgrType.GetField("_shinyCreatureChance", bindingAttr);
if (shinyChanceField == null)
{
shinyChanceField = creatureMgrType.GetField("shinyCreatureChance", bindingAttr);
}
}
baitInfoType = AccessTools.TypeByName("BaitInfo");
if (baitInfoType != null)
{
lostChanceField = baitInfoType.GetField("_lostOnBaitChance", bindingAttr);
if (lostChanceField == null)
{
lostChanceField = baitInfoType.GetField("lostOnBaitChance", bindingAttr);
}
}
Log.LogInfo((object)("Weapon:" + (weaponType != null) + " ammo:" + (ammoField != null) + " punch:" + (punchType != null) + " CMgr:" + (creatureMgrType != null) + " shiny:" + (shinyChanceField != null) + " BaitInfo:" + (baitInfoType != null) + " lostChance:" + (lostChanceField != null)));
}
public void Update()
{
if (Input.GetKeyDown((KeyCode)257))
{
GodMode = !GodMode;
if (!GodMode)
{
SetGodMode(val: false);
}
Log.LogInfo((object)("GodMode: " + (GodMode ? "ON" : "OFF")));
}
if (Input.GetKeyDown((KeyCode)258))
{
InfAmmo = !InfAmmo;
if (!InfAmmo)
{
RestoreAmmo();
}
Log.LogInfo((object)("InfAmmo: " + (InfAmmo ? "ON" : "OFF")));
}
if (Input.GetKeyDown((KeyCode)259))
{
OneShot = !OneShot;
if (!OneShot)
{
RestoreOneShot();
}
Log.LogInfo((object)("OneShot: " + (OneShot ? "ON" : "OFF")));
}
if (Input.GetKeyDown((KeyCode)260))
{
AlwaysRare = !AlwaysRare;
if (!AlwaysRare)
{
RestoreRare();
}
Log.LogInfo((object)("AlwaysRare: " + (AlwaysRare ? "ON" : "OFF")));
}
if (Input.GetKeyDown((KeyCode)261))
{
BulletPierce = !BulletPierce;
Log.LogInfo((object)("BulletPierce: " + (BulletPierce ? "ON" : "OFF")));
}
if (Input.GetKeyDown((KeyCode)262))
{
InfBait = !InfBait;
if (!InfBait)
{
RestoreBait();
}
Log.LogInfo((object)("InfBait: " + (InfBait ? "ON" : "OFF")));
}
bool flag = GodMode || InfAmmo || OneShot || AlwaysRare || BulletPierce || InfBait;
if (flag != prevAny)
{
if (flag)
{
SetCheats(val: true);
}
else
{
SetCheats(val: false);
}
prevAny = flag;
}
if (!flag)
{
return;
}
timer += Time.deltaTime;
if (!(timer >= 1f))
{
return;
}
timer = 0f;
if (GodMode)
{
SetGodMode(val: true);
}
if (InfAmmo || OneShot || AlwaysRare)
{
RefreshInstances(force: false);
if (InfAmmo)
{
DoInfAmmo();
}
if (OneShot)
{
DoOneShot();
}
if (AlwaysRare)
{
DoAlwaysRare();
}
}
if (InfBait)
{
DoInfBait();
}
}
private void RefreshInstances(bool force)
{
if (!force && Time.time - lastRefresh < 5f)
{
return;
}
lastRefresh = Time.time;
weapons.Clear();
punchers.Clear();
creatureMgrs.Clear();
if (weaponType != null)
{
Object[] array = Object.FindObjectsOfType(weaponType);
if (array != null)
{
weapons.AddRange(array);
}
}
if (punchType != null)
{
Object[] array = Object.FindObjectsOfType(punchType);
if (array != null)
{
punchers.AddRange(array);
}
}
if (creatureMgrType != null)
{
Object[] array = Object.FindObjectsOfType(creatureMgrType);
if (array != null)
{
creatureMgrs.AddRange(array);
}
}
}
private void DoInfAmmo()
{
if (ammoField == null)
{
return;
}
foreach (Object weapon in weapons)
{
if (weapon == (Object)null)
{
continue;
}
int instanceID = weapon.GetInstanceID();
if (!ammoSnap.ContainsKey(instanceID))
{
try
{
ammoSnap[instanceID] = (int)ammoField.GetValue(weapon);
}
catch
{
continue;
}
}
try
{
ammoField.SetValue(weapon, 9999);
}
catch
{
}
}
}
private void DoOneShot()
{
foreach (Object weapon in weapons)
{
if (weapon == (Object)null)
{
continue;
}
if (weaponInfoField != null && projDmgField != null)
{
try
{
object value = weaponInfoField.GetValue(weapon);
if (value != null)
{
int hashCode = value.GetHashCode();
if (!projDmgSnap.ContainsKey(hashCode))
{
projDmgSnap[hashCode] = (int)projDmgField.GetValue(value);
}
projDmgField.SetValue(value, 500000);
}
}
catch
{
}
}
if (attachmentsField != null && bulletUpgradesField != null && bulletDmgField != null)
{
try
{
object value2 = attachmentsField.GetValue(weapon);
if (value2 != null)
{
object value3 = bulletUpgradesField.GetValue(value2);
if (value3 is Array array)
{
foreach (object item in array)
{
if (item != null)
{
int hashCode = item.GetHashCode();
if (!bulletDmgSnap.ContainsKey(hashCode))
{
bulletDmgSnap[hashCode] = (int)bulletDmgField.GetValue(item);
}
bulletDmgField.SetValue(item, 500000);
}
}
}
else if (value3 is IList list)
{
foreach (object item2 in list)
{
if (item2 != null)
{
int hashCode = item2.GetHashCode();
if (!bulletDmgSnap.ContainsKey(hashCode))
{
bulletDmgSnap[hashCode] = (int)bulletDmgField.GetValue(item2);
}
bulletDmgField.SetValue(item2, 500000);
}
}
}
}
}
catch
{
}
}
if (!(attachmentsField != null) || !(sharpUpgradesField != null) || !(sharpDmgField != null))
{
continue;
}
try
{
object value2 = attachmentsField.GetValue(weapon);
if (value2 == null)
{
continue;
}
object value4 = sharpUpgradesField.GetValue(value2);
if (value4 is Array array2)
{
foreach (object item3 in array2)
{
if (item3 != null)
{
int hashCode = item3.GetHashCode();
if (!sharpDmgSnap.ContainsKey(hashCode))
{
sharpDmgSnap[hashCode] = (int)sharpDmgField.GetValue(item3);
}
sharpDmgField.SetValue(item3, 500000);
}
}
}
else
{
if (!(value4 is IList list2))
{
continue;
}
foreach (object item4 in list2)
{
if (item4 != null)
{
int hashCode = item4.GetHashCode();
if (!sharpDmgSnap.ContainsKey(hashCode))
{
sharpDmgSnap[hashCode] = (int)sharpDmgField.GetValue(item4);
}
sharpDmgField.SetValue(item4, 500000);
}
}
continue;
}
}
catch
{
}
}
if (!(punchDmgField != null))
{
return;
}
foreach (Object puncher in punchers)
{
if (puncher == (Object)null)
{
continue;
}
int hashCode = puncher.GetInstanceID();
if (!punchSnap.ContainsKey(hashCode))
{
try
{
punchSnap[hashCode] = (int)punchDmgField.GetValue(puncher);
}
catch
{
continue;
}
}
try
{
punchDmgField.SetValue(puncher, 500000);
}
catch
{
}
}
}
private void DoAlwaysRare()
{
if (shinyChanceField == null)
{
return;
}
foreach (Object creatureMgr in creatureMgrs)
{
if (creatureMgr == (Object)null)
{
continue;
}
try
{
int num = (int)shinyChanceField.GetValue(creatureMgr);
if (origShinyChance == 1 && num != 100)
{
origShinyChance = num;
}
shinyChanceField.SetValue(creatureMgr, 100);
}
catch
{
}
}
}
private void DoInfBait()
{
if (lostChanceField == null)
{
return;
}
if (!gameInfoSearched)
{
gameInfoSearched = true;
Type type = AccessTools.TypeByName("GameInfo");
if (type != null)
{
BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
allBaitsProp = type.GetProperty("AllBaits", bindingAttr);
}
}
if (allBaitsProp != null)
{
try
{
if (allBaitsProp.GetValue(null, null) is IList list)
{
foreach (object item in list)
{
if (item == null)
{
continue;
}
int hashCode = item.GetHashCode();
if (!baitSnap.ContainsKey(hashCode))
{
try
{
baitSnap[hashCode] = (float)lostChanceField.GetValue(item);
}
catch
{
continue;
}
}
try
{
lostChanceField.SetValue(item, 0f);
}
catch
{
}
}
}
}
catch
{
}
}
if (!(baitInfoType != null))
{
return;
}
try
{
Object[] array = Resources.FindObjectsOfTypeAll(baitInfoType);
if (array == null)
{
return;
}
Object[] array2 = array;
foreach (Object val in array2)
{
if (val == (Object)null)
{
continue;
}
int hashCode = val.GetInstanceID();
if (!baitSnap.ContainsKey(hashCode))
{
try
{
baitSnap[hashCode] = (float)lostChanceField.GetValue(val);
}
catch
{
continue;
}
}
try
{
lostChanceField.SetValue(val, 0f);
}
catch
{
}
}
}
catch
{
}
}
private void RestoreAmmo()
{
if (ammoField == null)
{
return;
}
RefreshInstances(force: true);
int num = 0;
foreach (Object weapon in weapons)
{
if (weapon == (Object)null)
{
continue;
}
int instanceID = weapon.GetInstanceID();
if (ammoSnap.ContainsKey(instanceID))
{
try
{
ammoField.SetValue(weapon, ammoSnap[instanceID]);
num++;
}
catch
{
}
}
}
ammoSnap.Clear();
Log.LogInfo((object)("Ammo restored " + num));
}
private void RestoreOneShot()
{
RefreshInstances(force: true);
int num = 0;
foreach (Object weapon in weapons)
{
if (weapon == (Object)null)
{
continue;
}
if (weaponInfoField != null && projDmgField != null)
{
try
{
object value = weaponInfoField.GetValue(weapon);
if (value != null)
{
int hashCode = value.GetHashCode();
if (projDmgSnap.ContainsKey(hashCode))
{
projDmgField.SetValue(value, projDmgSnap[hashCode]);
num++;
}
}
}
catch
{
}
}
if (attachmentsField != null && bulletUpgradesField != null && bulletDmgField != null)
{
try
{
object value2 = attachmentsField.GetValue(weapon);
if (value2 == null)
{
continue;
}
object value3 = bulletUpgradesField.GetValue(value2);
if (value3 is Array array)
{
foreach (object item in array)
{
if (item != null)
{
int hashCode = item.GetHashCode();
if (bulletDmgSnap.ContainsKey(hashCode))
{
bulletDmgField.SetValue(item, bulletDmgSnap[hashCode]);
num++;
}
}
}
}
else if (value3 is IList list)
{
foreach (object item2 in list)
{
if (item2 != null)
{
int hashCode = item2.GetHashCode();
if (bulletDmgSnap.ContainsKey(hashCode))
{
bulletDmgField.SetValue(item2, bulletDmgSnap[hashCode]);
num++;
}
}
}
}
goto IL_02a1;
}
catch
{
goto IL_02a1;
}
}
goto IL_02a1;
IL_02a1:
if (!(attachmentsField != null) || !(sharpUpgradesField != null) || !(sharpDmgField != null))
{
continue;
}
try
{
object value2 = attachmentsField.GetValue(weapon);
if (value2 == null)
{
continue;
}
object value4 = sharpUpgradesField.GetValue(value2);
if (value4 is Array array2)
{
foreach (object item3 in array2)
{
if (item3 != null)
{
int hashCode = item3.GetHashCode();
if (sharpDmgSnap.ContainsKey(hashCode))
{
sharpDmgField.SetValue(item3, sharpDmgSnap[hashCode]);
num++;
}
}
}
}
else
{
if (!(value4 is IList list2))
{
continue;
}
foreach (object item4 in list2)
{
if (item4 != null)
{
int hashCode = item4.GetHashCode();
if (sharpDmgSnap.ContainsKey(hashCode))
{
sharpDmgField.SetValue(item4, sharpDmgSnap[hashCode]);
num++;
}
}
}
continue;
}
}
catch
{
}
}
if (punchDmgField != null)
{
foreach (Object puncher in punchers)
{
if (puncher == (Object)null)
{
continue;
}
int hashCode = puncher.GetInstanceID();
if (punchSnap.ContainsKey(hashCode))
{
try
{
punchDmgField.SetValue(puncher, punchSnap[hashCode]);
num++;
}
catch
{
}
}
}
}
projDmgSnap.Clear();
bulletDmgSnap.Clear();
sharpDmgSnap.Clear();
punchSnap.Clear();
Log.LogInfo((object)("OneShot restored " + num + " fields"));
}
private void RestoreRare()
{
if (shinyChanceField == null)
{
return;
}
RefreshInstances(force: true);
int num = 0;
foreach (Object creatureMgr in creatureMgrs)
{
if (!(creatureMgr == (Object)null))
{
try
{
shinyChanceField.SetValue(creatureMgr, origShinyChance);
num++;
}
catch
{
}
}
}
Log.LogInfo((object)("Rare restored " + num + " (chance=" + origShinyChance + ")"));
}
private void RestoreBait()
{
if (lostChanceField == null)
{
return;
}
int num = 0;
if (allBaitsProp != null)
{
try
{
if (allBaitsProp.GetValue(null, null) is IList list)
{
foreach (object item in list)
{
if (item == null)
{
continue;
}
int hashCode = item.GetHashCode();
if (baitSnap.ContainsKey(hashCode))
{
try
{
lostChanceField.SetValue(item, baitSnap[hashCode]);
num++;
}
catch
{
}
}
}
}
}
catch
{
}
}
if (baitInfoType != null)
{
try
{
Object[] array = Resources.FindObjectsOfTypeAll(baitInfoType);
if (array != null)
{
Object[] array2 = array;
foreach (Object val in array2)
{
if (val == (Object)null)
{
continue;
}
int hashCode = val.GetInstanceID();
if (baitSnap.ContainsKey(hashCode))
{
try
{
lostChanceField.SetValue(val, baitSnap[hashCode]);
num++;
}
catch
{
}
}
}
}
}
catch
{
}
}
baitSnap.Clear();
Log.LogInfo((object)("Bait restored " + num));
}
public void OnGUI()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
if (sMain == null)
{
sMain = new GUIStyle(GUI.skin.label);
sMain.fontSize = 18;
sMain.fontStyle = (FontStyle)1;
sShadow = new GUIStyle(sMain);
sShadow.normal.textColor = Color.black;
}
int y = 10;
DrawLine("锁血: " + (GodMode ? "ON" : "OFF") + " (Num1)", ref y, GodMode);
DrawLine("无需换弹: " + (InfAmmo ? "ON" : "OFF") + " (Num2)", ref y, InfAmmo);
DrawLine("一击必杀: " + (OneShot ? "ON" : "OFF") + " (Num3)", ref y, OneShot);
DrawLine("极品钓鱼: " + (AlwaysRare ? "ON" : "OFF") + " (Num4)", ref y, AlwaysRare);
DrawLine("子弹穿透: " + (BulletPierce ? "ON" : "OFF") + " (Num5)", ref y, BulletPierce);
DrawLine("鱼饵不减: " + (InfBait ? "ON" : "OFF") + " (Num6)", ref y, InfBait);
}
private void DrawLine(string text, ref int y, bool on)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: 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)
sMain.normal.textColor = (on ? new Color(0.2f, 1f, 0.2f) : new Color(1f, 0.3f, 0.3f));
sShadow.normal.textColor = Color.black;
GUI.Label(new Rect(11f, (float)(y + 1), 250f, 25f), text, sShadow);
GUI.Label(new Rect(10f, (float)y, 250f, 25f), text, sMain);
y += 24;
}
private void SetGodMode(bool val)
{
if (!gmSearched)
{
gmSearched = true;
Type type = AccessTools.TypeByName("PlayerManager");
if (type != null)
{
BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
gmProp = type.GetProperty("InGodMode", bindingAttr);
}
}
try
{
if (gmProp != null && gmProp.CanWrite)
{
gmProp.SetValue(null, val, null);
}
}
catch
{
}
}
private void SetCheats(bool val)
{
if (!cheatSearched)
{
cheatSearched = true;
BindingFlags bindingAttr = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
Type type = AccessTools.TypeByName("ClientSettings");
if (type != null)
{
cheatProp = type.GetProperty("CheatsEnabled", bindingAttr);
if (cheatProp == null)
{
cheatField = type.GetField("<CheatsEnabled>k__BackingField", bindingAttr);
}
if (cheatField == null)
{
cheatField = type.GetField("CheatsEnabled", bindingAttr);
}
}
Type type2 = AccessTools.TypeByName("SteamManager");
if (type2 != null)
{
devProp = type2.GetProperty("IsDev", bindingAttr);
if (devProp == null)
{
devField = type2.GetField("<IsDev>k__BackingField", bindingAttr);
}
if (devField == null)
{
devField = type2.GetField("IsDev", bindingAttr);
}
}
}
try
{
if (cheatProp != null && cheatProp.CanWrite)
{
cheatProp.SetValue(null, val, null);
}
else if (cheatField != null)
{
cheatField.SetValue(null, val);
}
if (devProp != null && devProp.CanWrite)
{
devProp.SetValue(null, val, null);
}
else if (devField != null)
{
devField.SetValue(null, val);
}
}
catch
{
}
}
}
public static class Patches
{
public static bool DamageSkipPrefix()
{
return !Plugin.GodMode;
}
public static bool HitPrefix(RaycastHit hit)
{
if (Plugin.BulletPierce && (Object)(object)((RaycastHit)(ref hit)).transform != (Object)null && ((Component)((RaycastHit)(ref hit)).transform).CompareTag("Level"))
{
return false;
}
return true;
}
public static void GunClippingRayPostfix(ref RaycastHit __result)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.BulletPierce && (Object)(object)((RaycastHit)(ref __result)).transform != (Object)null && ((Component)((RaycastHit)(ref __result)).transform).CompareTag("Level"))
{
__result = default(RaycastHit);
}
}
}