using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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("TickBeGone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+67caabd039fc650a4bb285700a4f9e3d540ae17c")]
[assembly: AssemblyProduct("TickBeGone")]
[assembly: AssemblyTitle("TickBeGone")]
[assembly: AssemblyVersion("2.0.0.0")]
public enum Shape
{
Sphere,
Cube,
Cylinder,
Cat,
Unchanged
}
namespace TickBeGone
{
internal class BetterBillboard : MonoBehaviour
{
private void LateUpdate()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
((Component)this).transform.forward = ((Component)Camera.main).transform.forward;
}
}
internal class BugUtilities
{
public static bool TryCensorBug(Transform parent, Vector3 position, Vector3 scale, Material material)
{
//IL_0028: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
//IL_0069: 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)
if (Configuration.UseShapeOverride && TryGetReplacementBug(out var bug))
{
bug.transform.parent = parent;
bug.transform.localPosition = position;
bug.transform.localScale = scale;
if (Configuration.ShapeOverride != Shape.Cat)
{
MeshRenderer component = bug.GetComponent<MeshRenderer>();
((Renderer)component).material = material;
MaterialPropertyBlock val = new MaterialPropertyBlock();
((Renderer)component).GetPropertyBlock(val);
if (Configuration.UseColorOverride)
{
val.SetColor("_BaseColor", Configuration.ColorOverride);
val.SetColor("_Color1", Configuration.ColorOverride);
}
if (!Configuration.UseOriginalTexture)
{
val.SetTexture("_Texture1", (Texture)(object)Texture2D.whiteTexture);
}
((Renderer)component).SetPropertyBlock(val);
}
else
{
Transform transform = bug.transform;
transform.localScale *= 1.5f;
}
Collider val2 = default(Collider);
if (bug.TryGetComponent<Collider>(ref val2))
{
Object.Destroy((Object)(object)val2);
}
return true;
}
return false;
}
public static void CensorOldBug(Renderer bugRenderer)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
MaterialPropertyBlock val = new MaterialPropertyBlock();
bugRenderer.GetPropertyBlock(val);
if (Configuration.UseColorOverride)
{
val.SetColor("_BaseColor", Configuration.ColorOverride);
val.SetColor("_Color1", Configuration.ColorOverride);
}
if (!Configuration.UseOriginalTexture)
{
val.SetTexture("_Texture1", (Texture)(object)Texture2D.whiteTexture);
}
bugRenderer.SetPropertyBlock(val);
}
internal static bool TryGetReplacementBug(out GameObject bug)
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
bug = null;
if (!Configuration.Enabled)
{
return false;
}
switch (Configuration.ShapeOverride)
{
case Shape.Sphere:
bug = GameObject.CreatePrimitive((PrimitiveType)0);
return true;
case Shape.Cube:
bug = GameObject.CreatePrimitive((PrimitiveType)3);
return true;
case Shape.Cylinder:
bug = GameObject.CreatePrimitive((PrimitiveType)2);
return true;
case Shape.Cat:
{
bug = GameObject.CreatePrimitive((PrimitiveType)5);
Renderer component = bug.GetComponent<Renderer>();
component.sharedMaterial.shader = Shader.Find("GD/Face Cards");
MaterialPropertyBlock val = new MaterialPropertyBlock();
component.GetPropertyBlock(val);
val.SetTexture("_MainTex", (Texture)(object)TickPlugin.GetRandomCat());
component.SetPropertyBlock(val);
bug.AddComponent<BetterBillboard>();
Object.DestroyImmediate((Object)(object)bug.GetComponent<Collider>());
return true;
}
default:
return false;
}
}
}
internal static class Configuration
{
private static ConfigFile config;
private static ConfigEntry<bool> enabled;
private static ConfigEntry<bool> useColorOverride;
private static ConfigEntry<Color> colorOverride;
private static ConfigEntry<bool> useOriginalTexture;
private static ConfigEntry<bool> useShapeOverride;
private static ConfigEntry<Shape> shapeOverride;
private static ConfigEntry<bool> useNameOverride;
private static ConfigEntry<string> nameOverride;
private static ConfigEntry<bool> useIconOverride;
public static bool Enabled => enabled.Value;
public static bool UseColorOverride => useColorOverride.Value;
public static Color ColorOverride => colorOverride.Value;
public static bool UseOriginalTexture => useOriginalTexture.Value;
public static bool UseShapeOverride => useShapeOverride.Value;
public static Shape ShapeOverride => shapeOverride.Value;
public static bool UseNameOverride => useNameOverride.Value;
public static string NameOverride => nameOverride.Value;
public static bool UseIconOverride => useIconOverride.Value;
public static void Init()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
config = new ConfigFile(Path.Combine(Paths.ConfigPath, "Tick-Be-Gone.cfg"), true);
enabled = config.Bind<bool>("General", "Enabled", true, "Enable or disable the mod.");
useColorOverride = config.Bind<bool>("Color", "UseColorOverride", true, "Enable color override for the bug.");
colorOverride = config.Bind<Color>("Color", "ColorOverride", Color.magenta, "Color to override the bug's appearance with.");
useOriginalTexture = config.Bind<bool>("Color", "UseOriginalTexture", false, "Use the original texture for the bug.");
useShapeOverride = config.Bind<bool>("Shape", "UseShapeOverride", true, "Enable shape override for the bug.");
shapeOverride = config.Bind<Shape>("Shape", "ShapeOverride", Shape.Sphere, "Shape to override the bug's appearance with.");
useNameOverride = config.Bind<bool>("Name", "UseNameOverride", true, "Enable name override for the bug.");
nameOverride = config.Bind<string>("Name", "NameOverride", "[Redacted]", "Name to override the bug's name with.");
useIconOverride = config.Bind<bool>("Icon", "UseIconOverride", true, "Replace the bug icon with a kitty.");
}
}
[BepInPlugin("com.steven.peak.tickbegone", "Tick-Be-Gone", "2.0.0")]
public class TickPlugin : BaseUnityPlugin
{
private static Texture2D catTexture = new Texture2D(2, 2);
private void Awake()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
Configuration.Init();
new Harmony("com.steven.peak.tickbegone").PatchAll();
LoadCat();
}
private void LoadCat()
{
//IL_0054: 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_0060: Expected O, but got Unknown
//IL_0066: Expected O, but got Unknown
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
int num = Random.Range(0, manifestResourceNames.Length);
Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(manifestResourceNames[num]);
if (manifestResourceStream == null)
{
Debug.LogError((object)("Failed to load resource: " + manifestResourceNames[num]));
return;
}
byte[] array = new byte[manifestResourceStream.Length];
manifestResourceStream.Read(array, 0, (int)manifestResourceStream.Length);
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, array);
catTexture = val;
}
public static Texture2D GetRandomCat(bool useLastIndex = false)
{
return catTexture;
}
}
}
namespace TickBeGone.Patches
{
[HarmonyPatch(typeof(Bugfix), "AttachBug")]
internal class Bugfix_AttachBug
{
}
[HarmonyPatch(typeof(Bugfix), "Start")]
internal class Bugfix_Start
{
private static void Postfix(Bugfix __instance)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
SphereCollider component = ((Component)__instance).GetComponent<SphereCollider>();
MeshRenderer componentInChildren = ((Component)__instance).GetComponentInChildren<MeshRenderer>();
if (BugUtilities.TryCensorBug(((Component)__instance).transform, component.center, Vector3.one * component.radius * 2f, ((Renderer)componentInChildren).sharedMaterial))
{
((Component)componentInChildren).gameObject.SetActive(false);
}
else
{
BugUtilities.CensorOldBug((Renderer)(object)componentInChildren);
}
if (Configuration.UseIconOverride)
{
__instance.bugItem.UIData.icon = TickPlugin.GetRandomCat(useLastIndex: true);
}
}
}
[HarmonyPatch(typeof(Item), "Awake")]
internal class Item_Awake
{
private static void Prefix(Item __instance)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (__instance.itemID == 95)
{
MeshRenderer component = ((Component)((Component)__instance).transform.Find("Bugfix")).gameObject.GetComponent<MeshRenderer>();
Material sharedMaterial = ((Renderer)component).sharedMaterial;
if (BugUtilities.TryCensorBug(((Component)__instance).transform, new Vector3(0f, 0.047f, -0.074f), Vector3.one * 0.21511f, sharedMaterial))
{
((Renderer)component).enabled = false;
}
else
{
BugUtilities.CensorOldBug((Renderer)(object)component);
}
if (Configuration.UseIconOverride)
{
__instance.UIData.icon = TickPlugin.GetRandomCat(useLastIndex: true);
}
}
}
}
[HarmonyPatch(typeof(LocalizedText), "GetText", new Type[]
{
typeof(string),
typeof(bool)
})]
internal class LocalizedText_ReplaceCustomValues
{
private static Regex regex = new Regex("\\btick\\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static bool Prepare()
{
return Configuration.UseNameOverride;
}
private static void Postfix(ref string __result)
{
if (!string.IsNullOrEmpty(__result))
{
__result = regex.Replace(__result, Configuration.NameOverride);
}
}
}
}