using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyMetadata("Notice", "Copyright (c) casualexpie. All rights reserved. Do NOT decompile, disassemble, or reverse-engineer this assembly. Report bug symptoms on the Nexus Bugs page; do not post decompiled or reconstructed source. Reverse-engineering this DLL is not authorized.")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace IRegretNothing;
[BepInPlugin("iregretnothing", "I Regret Nothing", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
public const string Version = "1.0.2";
internal static ManualLogSource Log;
internal static ConfigEntry<float> Fuse;
internal static ConfigEntry<float> Radius;
internal static ConfigEntry<bool> PauseButton;
internal static ConfigEntry<bool> AskTwice;
internal static ConfigEntry<string> LastWords;
internal static ConfigEntry<string> LastWordsMilky;
internal static ConfigEntry<string> LastWordsDune;
private void Awake()
{
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
Fuse = ((BaseUnityPlugin)this).Config.Bind<float>("Grenade", "FuseSeconds", 3f, "Seconds between pulling the pin and the explosion.");
Radius = ((BaseUnityPlugin)this).Config.Bind<float>("Grenade", "BlastRadius", 6f, "Blast radius of the grenade. Landmines are 12, dynamite is 18.");
PauseButton = ((BaseUnityPlugin)this).Config.Bind<bool>("End Yourself", "PauseMenuButton", true, "Show the red skull 'End Yourself?' button in the pause menu.");
AskTwice = ((BaseUnityPlugin)this).Config.Bind<bool>("End Yourself", "AskTwice", true, "The skull button needs two clicks, so a stray click doesn't end your run.");
LastWords = ((BaseUnityPlugin)this).Config.Bind<string>("End Yourself", "LastWords", "I regret nothing.", "What Expie says before pulling the pin.");
LastWordsMilky = ((BaseUnityPlugin)this).Config.Bind<string>("End Yourself", "LastWordsMilky", "I have no remorse for my actions", "What Milky says before pulling the pin.");
LastWordsDune = ((BaseUnityPlugin)this).Config.Bind<string>("End Yourself", "LastWordsDune", "Du-ne not re-gret any-thing...", "What Dune says before pulling the pin.");
Reskin.Bind(((BaseUnityPlugin)this).Config, 3f, 0f, 0f, 0f, 1f, 0f, "the grenade in the mouth");
GrenadeResources.Install();
new Harmony("iregretnothing").PatchAll(typeof(Plugin).Assembly);
if (Item.GlobalItems != null && !Item.GlobalItems.ContainsKey("fraggrenade"))
{
SetupPatch.Register();
}
Runner.Start();
Log.LogInfo((object)"I Regret Nothing 1.0.2 loaded.");
}
internal static string Words(int charType)
{
ConfigEntry<string> val = (ConfigEntry<string>)(charType switch
{
2 => LastWordsDune,
1 => LastWordsMilky,
_ => LastWords,
});
if (!string.IsNullOrEmpty(val.Value))
{
return val.Value;
}
return LastWords.Value;
}
}
internal static class Grenade
{
public const string Id = "fraggrenade";
public const string Name = "Frag Grenade";
public const string Desc = "A hand grenade. Throwing it pulls the pin for you. Using it pulls the pin and lets you hold on to it, if you're brave.";
private static GameObject template;
private static GameObject holder;
private static Sprite full;
private static Sprite pulled;
public static Sprite Full
{
get
{
if ((Object)(object)full == (Object)null)
{
full = Draw(pin: true);
}
return full;
}
}
public static Sprite Pulled
{
get
{
if ((Object)(object)pulled == (Object)null)
{
pulled = Draw(pin: false);
}
return pulled;
}
}
public static bool IsOurs(string id)
{
if (id != null)
{
return string.Equals(id, "fraggrenade", StringComparison.OrdinalIgnoreCase);
}
return false;
}
public static bool IsOurs(Item it)
{
if ((Object)(object)it != (Object)null)
{
return IsOurs(it.id);
}
return false;
}
public static ItemInfo NewInfo()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
ItemInfo val = new ItemInfo();
val.category = "utility";
val.slotRotation = 0f;
val.usable = true;
val.usableOnLimb = false;
val.decayMinutes = 300f;
val.weight = 0.4f;
val.destroyAtZeroCondition = true;
val.fullName = "Frag Grenade";
val.description = "A hand grenade. Throwing it pulls the pin for you. Using it pulls the pin and lets you hold on to it, if you're brave.";
val.useAction = (Use)delegate(Body body, Item item)
{
Runner.Arm(item, Plugin.Fuse.Value, mouth: false);
};
val.value = 20;
val.rec = new Recognition(8);
return val;
}
public static Object Template()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)template != (Object)null)
{
return (Object)(object)template;
}
GameObject val = Resources.Load<GameObject>("dynamite");
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogError((object)"Couldn't find the dynamite to base the grenade on.");
return null;
}
if ((Object)(object)holder == (Object)null)
{
holder = new GameObject("FragGrenadeTemplate");
holder.SetActive(false);
((Object)holder).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)holder);
}
GameObject val2 = Object.Instantiate<GameObject>(val, holder.transform);
((Object)val2).name = "fraggrenade";
Item component = val2.GetComponent<Item>();
component.id = "fraggrenade";
SpriteRenderer component2 = val2.GetComponent<SpriteRenderer>();
if ((Object)(object)component2 != (Object)null)
{
component2.sprite = Full;
}
AudioSource component3 = val2.GetComponent<AudioSource>();
if ((Object)(object)component3 != (Object)null)
{
component3.playOnAwake = false;
}
BoxCollider2D component4 = val2.GetComponent<BoxCollider2D>();
if ((Object)(object)component4 != (Object)null)
{
component4.size = new Vector2(0.9f, 1.25f);
((Collider2D)component4).offset = Vector2.zero;
}
template = val2;
return (Object)(object)val2;
}
private static Sprite Draw(bool pin)
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
string[] array = new string[11]
{
"...RR...", "..R..R..", "...RRLL.", "..TTTTL.", ".GGGGGGL", "GGgGGgGG", "GGGGGGGG", "GGgGGgGG", "GGGGGGGG", ".GgGGgG.",
"..GGGG.."
};
int num = 8;
int num2 = array.Length;
Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false);
((Texture)val).filterMode = (FilterMode)0;
((Texture)val).wrapMode = (TextureWrapMode)1;
Color32[] array2 = (Color32[])(object)new Color32[num * num2];
Color32 val2 = default(Color32);
for (int i = 0; i < num2; i++)
{
string text = array[num2 - 1 - i];
for (int j = 0; j < num; j++)
{
char c = text[j];
((Color32)(ref val2))..ctor((byte)0, (byte)0, (byte)0, (byte)0);
switch (c)
{
case 'G':
((Color32)(ref val2))..ctor((byte)86, (byte)99, (byte)48, byte.MaxValue);
break;
case 'g':
((Color32)(ref val2))..ctor((byte)51, (byte)61, (byte)28, byte.MaxValue);
break;
case 'T':
((Color32)(ref val2))..ctor((byte)58, (byte)58, (byte)58, byte.MaxValue);
break;
case 'L':
((Color32)(ref val2))..ctor((byte)154, (byte)154, (byte)154, byte.MaxValue);
break;
case 'R':
if (pin)
{
((Color32)(ref val2))..ctor((byte)208, (byte)208, (byte)208, byte.MaxValue);
}
break;
}
array2[i * num + j] = val2;
}
}
val.SetPixels32(array2);
val.Apply();
((Object)val).hideFlags = (HideFlags)61;
Sprite val3 = Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num2), new Vector2(0.5f, 0.5f), 8f);
((Object)val3).name = (pin ? "fraggrenade" : "fraggrenadepulled");
((Object)val3).hideFlags = (HideFlags)61;
return val3;
}
}
internal class Runner : MonoBehaviour
{
private class Armed
{
public Item Item;
public float At;
public bool Mouth;
public Body Body;
}
private static Runner inst;
private static readonly List<Armed> armed = new List<Armed>();
private float nextCheck;
internal static bool Busy;
internal static Item MouthItem;
internal static float RaiseStart = -1f;
internal static Vector3 RaiseFrom;
private static Body poseBody;
private static Limb upArm;
private static Limb downArm;
private static Limb hand;
private static float lower = -1f;
private static Body mouthBody;
private static Transform mouthHead;
public static void Start()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
GameObject val = new GameObject("IRegretNothingRunner");
((Object)val).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)val);
inst = val.AddComponent<Runner>();
}
public static bool IsArmed(Item it)
{
for (int i = 0; i < armed.Count; i++)
{
if ((Object)(object)armed[i].Item == (Object)(object)it)
{
return true;
}
}
return false;
}
public static void Arm(Item it, float fuse, bool mouth)
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)it == (Object)null) && !IsArmed(it))
{
Armed armed = new Armed();
armed.Item = it;
armed.At = Time.time + Mathf.Max(0.2f, fuse);
armed.Mouth = mouth;
armed.Body = (((Object)(object)PlayerCamera.main != (Object)null) ? PlayerCamera.main.body : null);
Runner.armed.Add(armed);
SpriteRenderer component = ((Component)it).GetComponent<SpriteRenderer>();
if ((Object)(object)component != (Object)null)
{
component.sprite = Grenade.Pulled;
}
Sound.Play("mine", Vector2.op_Implicit(((Component)it).transform.position), false, true, (Transform)null, 1f, 1f, false, false);
}
}
private void Update()
{
if (Time.unscaledTime >= nextCheck)
{
nextCheck = Time.unscaledTime + 3f;
try
{
GrenadeResources.Check();
}
catch (Exception)
{
}
}
for (int num = Runner.armed.Count - 1; num >= 0; num--)
{
Armed armed = Runner.armed[num];
if ((Object)(object)armed.Item == (Object)null)
{
Runner.armed.RemoveAt(num);
}
else if (!(Time.time < armed.At))
{
Runner.armed.RemoveAt(num);
try
{
Boom(armed);
}
catch (Exception ex2)
{
Plugin.Log.LogError((object)("The grenade failed to go off: " + ex2));
}
}
}
}
private static void Boom(Armed a)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: 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_008d: Expected O, but got Unknown
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
Vector2 position = Vector2.op_Implicit(((Component)a.Item).transform.position);
Body body = a.Body;
if (a.Mouth && (Object)(object)body != (Object)null && body.limbs != null && body.limbs.Length > 0 && (Object)(object)body.limbs[0] != (Object)null)
{
position = Vector2.op_Implicit(((Component)body.limbs[0]).transform.position);
}
Object.Destroy((Object)(object)((Component)a.Item).gameObject);
if (!((Object)(object)WorldGeneration.world == (Object)null))
{
ExplosionParams val = new ExplosionParams();
val.position = position;
val.range = Mathf.Clamp(Plugin.Radius.Value, 1f, 30f);
val.structuralDamage = 350f;
val.dismemberChance = (Body.censorPain ? 0f : (a.Mouth ? 0.35f : 0.15f));
WorldGeneration.CreateExplosion(val);
if (a.Mouth && (Object)(object)body != (Object)null)
{
body.brainHealth = 0f;
body.consciousness = 0f;
}
if ((Object)(object)a.Item == (Object)(object)MouthItem)
{
MouthItem = null;
Busy = false;
RaiseStart = -1f;
}
}
}
private static void FindArm(Body b)
{
poseBody = b;
upArm = (downArm = (hand = null));
InventorySlot val = ((b.slots != null && b.handSlot >= 0 && b.handSlot < b.slots.Length) ? b.slots[b.handSlot] : null);
string text = (((Object)(object)val != (Object)null && (Object)(object)val.limb != (Object)null && ((Object)val.limb).name.EndsWith("B")) ? "B" : "F");
hand = b.LimbByName("Hand" + text);
downArm = b.LimbByName("DownArm" + text);
upArm = b.LimbByName("UpArm" + text);
}
private static Vector3 Joint(Limb l)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)l.joint != (Object)null))
{
return ((Component)l).transform.position;
}
return ((Component)l).transform.TransformPoint(Vector2.op_Implicit(((AnchoredJoint2D)l.joint).anchor));
}
private void LateUpdate()
{
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
try
{
HoldInMouth();
}
catch (Exception)
{
}
if (RaiseStart < 0f && lower < 0f)
{
return;
}
Body val = (((Object)(object)PlayerCamera.main != (Object)null) ? PlayerCamera.main.body : null);
if ((Object)(object)val == (Object)null || !val.standing || val.limbs == null || val.limbs.Length == 0)
{
return;
}
if ((Object)(object)val != (Object)(object)poseBody || (Object)(object)upArm == (Object)null)
{
FindArm(val);
}
if ((Object)(object)upArm == (Object)null || (Object)(object)downArm == (Object)null || (Object)(object)hand == (Object)null)
{
return;
}
float num2;
if (RaiseStart >= 0f)
{
float num = Mathf.Clamp01((Time.time - RaiseStart) / 0.9f);
num2 = num * num * (3f - 2f * num);
}
else
{
lower = Mathf.MoveTowards(lower, 0f, Time.deltaTime * 4f);
num2 = lower;
if (lower <= 0f)
{
lower = -1f;
}
}
if (num2 <= 0f)
{
return;
}
try
{
Pose(val, MouthPos(val), num2);
}
catch (Exception)
{
}
}
private static void Pose(Body b, Vector3 target, float w)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = Joint(upArm);
Vector3 val2 = Joint(downArm);
Vector3 position = ((Component)hand).transform.position;
float num = Vector2.Distance(Vector2.op_Implicit(val), Vector2.op_Implicit(val2));
float num2 = Vector2.Distance(Vector2.op_Implicit(val2), Vector2.op_Implicit(position));
if (!(num < 0.01f) && !(num2 < 0.01f))
{
Vector2 val3 = Vector2.op_Implicit(target - val);
float num3 = Mathf.Clamp(((Vector2)(ref val3)).magnitude, Mathf.Abs(num - num2) + 0.01f, num + num2 - 0.01f);
float num4 = Mathf.Acos(Mathf.Clamp((num * num + num3 * num3 - num2 * num2) / (2f * num * num3), -1f, 1f)) * 57.29578f;
float num5 = Mathf.Atan2(val3.y, val3.x) * 57.29578f;
float num6 = (b.isRight ? 1f : (-1f));
float num7 = 0f - num6;
float num8 = (num5 + num7 * num4) * ((float)Math.PI / 180f);
Vector3 val4 = val + new Vector3(Mathf.Cos(num8), Mathf.Sin(num8), 0f) * num;
float num9 = Vector2.SignedAngle(Vector2.op_Implicit(val2 - val), Vector2.op_Implicit(val4 - val)) * w;
((Component)upArm).transform.RotateAround(val, Vector3.forward, num9);
((Component)downArm).transform.RotateAround(val, Vector3.forward, num9);
((Component)hand).transform.RotateAround(val, Vector3.forward, num9);
Vector3 val5 = Joint(downArm);
Vector3 position2 = ((Component)hand).transform.position;
Vector3 val6 = Vector3.Lerp(position2, target, w);
float num10 = Vector2.SignedAngle(Vector2.op_Implicit(position2 - val5), Vector2.op_Implicit(val6 - val5));
((Component)downArm).transform.RotateAround(val5, Vector3.forward, num10);
((Component)hand).transform.RotateAround(val5, Vector3.forward, num10);
}
}
private static void PutInMouth(Body b, Item it)
{
//IL_0035: 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)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
Limb val = b.limbs[0];
int num = 0;
SpriteRenderer component = ((Component)val).GetComponent<SpriteRenderer>();
if ((Object)(object)component != (Object)null)
{
num = ((Renderer)component).sortingOrder;
}
((Component)it).transform.SetParent((Transform)null, true);
((Component)it).transform.localScale = Vector3.one;
SpriteRenderer component2 = ((Component)it).GetComponent<SpriteRenderer>();
if ((Object)(object)component2 != (Object)null)
{
((Renderer)component2).sortingOrder = num + 2;
}
mouthBody = b;
mouthHead = ((Component)val).transform;
HoldInMouth();
Sound.Play("switch", Vector2.op_Implicit(((Component)it).transform.position), false, true, (Transform)null, 1f, 1f, false, false);
}
private static void HoldInMouth()
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
Item mouthItem = MouthItem;
if (!((Object)(object)mouthItem == (Object)null) && !((Object)(object)mouthBody == (Object)null) && !((Object)(object)mouthHead == (Object)null) && !((Object)(object)((Component)mouthItem).transform.parent != (Object)null))
{
float num = (mouthBody.isRight ? 1f : (-1f));
float z = mouthHead.eulerAngles.z;
Vector2 val = Reskin.Pixels(mouthBody.charType);
((Component)mouthItem).transform.position = mouthHead.position + Quaternion.Euler(0f, 0f, z) * new Vector3(num * (1f + val.x / 8f), -0.35f + val.y / 8f, 0f);
((Component)mouthItem).transform.rotation = Quaternion.Euler(0f, 0f, z - 90f * num);
((Component)mouthItem).transform.localScale = Vector3.one;
if ((Object)(object)mouthItem.rb != (Object)null && mouthItem.rb.simulated)
{
mouthItem.rb.simulated = false;
}
}
}
public static void EndYourself()
{
if (!Busy && !((Object)(object)inst == (Object)null))
{
PlayerCamera main = PlayerCamera.main;
if (!((Object)(object)main == (Object)null) && !((Object)(object)main.body == (Object)null) && main.body.alive)
{
((MonoBehaviour)inst).StartCoroutine(Sequence(main.body));
}
}
}
private static IEnumerator Sequence(Body body)
{
Busy = true;
if (PauseHandler.paused)
{
PauseHandler.TogglePause();
}
float wait = 0f;
while (PauseHandler.paused && wait < 2f)
{
wait += Time.unscaledDeltaTime;
yield return null;
}
yield return (object)new WaitForSecondsRealtime(0.35f);
Item it = null;
try
{
int handSlot = body.handSlot;
if (body.HoldingItem(handSlot))
{
body.DropItem(handSlot);
}
GameObject val = Utils.Create("fraggrenade", Vector2.op_Implicit(((Component)body.limbs[0]).transform.position), 0f);
it = (((Object)(object)val != (Object)null) ? val.GetComponent<Item>() : null);
if ((Object)(object)it != (Object)null)
{
body.PickUpItem(it, handSlot, true);
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("Couldn't put the grenade in your hand: " + ex));
}
if ((Object)(object)it == (Object)null)
{
Busy = false;
yield break;
}
MouthItem = it;
RaiseFrom = body.targetLookPos;
RaiseStart = Time.time;
yield return (object)new WaitForSeconds(1f);
if ((Object)(object)it == (Object)null || !body.alive)
{
Busy = false;
RaiseStart = -1f;
MouthItem = null;
yield break;
}
try
{
int handSlot2 = body.handSlot;
if ((Object)(object)body.GetItem(handSlot2) == (Object)(object)it)
{
body.DropItem(handSlot2);
}
if ((Object)(object)it.rb != (Object)null)
{
it.rb.simulated = false;
it.rb.velocity = Vector2.zero;
}
PutInMouth(body, it);
}
catch (Exception ex2)
{
Plugin.Log.LogWarning((object)("Couldn't put the grenade in the mouth: " + ex2.Message));
}
yield return (object)new WaitForSeconds(0.45f);
if ((Object)(object)it == (Object)null)
{
Busy = false;
RaiseStart = -1f;
MouthItem = null;
yield break;
}
body.talker.Talk(Plugin.Words(body.charType), (Limb)null, true, true);
yield return (object)new WaitForSeconds(0.9f);
if ((Object)(object)it == (Object)null)
{
Busy = false;
RaiseStart = -1f;
MouthItem = null;
yield break;
}
Arm(it, 1.3f, mouth: true);
yield return (object)new WaitForSeconds(0.25f);
if (RaiseStart >= 0f)
{
RaiseStart = -1f;
lower = 1f;
}
float guard = 0f;
while ((Object)(object)MouthItem != (Object)null && guard < 6f)
{
guard += Time.deltaTime;
yield return null;
}
Busy = false;
RaiseStart = -1f;
MouthItem = null;
}
public static Vector3 MouthPos(Body body)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
Transform transform = ((Component)body.limbs[0]).transform;
float num = (body.isRight ? 1f : (-1f));
Vector2 val = Reskin.Pixels(body.charType);
return transform.position + new Vector3(num * (0.55f + val.x / 8f), -0.35f + val.y / 8f, 0f);
}
}
[HarmonyPatch(typeof(PlayerCamera), "HandleInput")]
internal static class AimPatch
{
private static void Postfix(PlayerCamera __instance)
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
if (!(Runner.RaiseStart < 0f) && !((Object)(object)Runner.MouthItem == (Object)null) && !((Object)(object)__instance.body == (Object)null))
{
Body body = __instance.body;
float num = Mathf.Clamp01((Time.time - Runner.RaiseStart) / 0.9f);
num = 1f - Mathf.Pow(1f - num, 3f);
body.targetLookPos = Vector3.Lerp(Runner.RaiseFrom, Runner.MouthPos(body) + new Vector3(body.isRight ? 5f : (-5f), 0f, 0f), num);
}
}
}
[HarmonyPatch(typeof(Body), "ThrowItem")]
internal static class ThrowPatch
{
private static bool Prefix(Body __instance)
{
Item item = __instance.GetItem(__instance.handSlot);
if (!Grenade.IsOurs(item))
{
return true;
}
if ((Object)(object)item == (Object)(object)Runner.MouthItem)
{
return false;
}
if (!Runner.IsArmed(item))
{
Runner.Arm(item, Plugin.Fuse.Value, mouth: false);
}
return true;
}
}
[HarmonyPatch(typeof(PauseHandler), "Update")]
internal static class PauseSkull
{
private static PauseHandler builtFor;
private static GameObject button;
private static Image img;
private static UITooltip tip;
private static int clicks;
private static readonly FieldInfo PosField = AccessTools.Field(typeof(PauseHandler), "buttonPos");
private static readonly Color Red = new Color(0.9f, 0.08f, 0.08f, 1f);
private static void Postfix(PauseHandler __instance)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Invalid comparison between Unknown and I4
try
{
if (!__instance.isPaused && clicks > 0)
{
Reset();
}
if (!((Object)(object)builtFor == (Object)(object)__instance) && __instance.isPaused && Plugin.PauseButton.Value && !((Object)(object)WorldGeneration.world == (Object)null) && (int)WorldGeneration.world.biomeOverride != 1)
{
builtFor = __instance;
Build(__instance);
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Couldn't add the End Yourself button: " + ex.Message));
}
}
private static void Reset()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
clicks = 0;
if ((Object)(object)img != (Object)null)
{
((Graphic)img).color = Red;
}
if ((Object)(object)tip != (Object)null)
{
tip.tipName = "End Yourself?";
tip.tipDesc = (Plugin.AskTwice.Value ? "Click twice. No regrets." : "No regrets.");
}
}
private static void Click()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
if (Runner.Busy)
{
return;
}
PlayerCamera.PlayUISound("selfharmtap", 1f);
clicks++;
if (Plugin.AskTwice.Value && clicks < 2)
{
if ((Object)(object)img != (Object)null)
{
((Graphic)img).color = new Color(0.45f, 0f, 0f, 1f);
}
if ((Object)(object)tip != (Object)null)
{
tip.tipName = "Really?";
tip.tipDesc = "Click again to pull the pin.";
}
}
else
{
Reset();
Runner.EndYourself();
}
}
private static Vector2 Factor(int index)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
float num = 1f + (float)index * 0.1f;
return new Vector2(0.5f + Utils.OutCubic(num) * 0.5f, 0.5f + Utils.InOutCubic(num) * 0.5f);
}
private static void Build(PauseHandler ph)
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Expected O, but got Unknown
//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
//IL_02f6: Expected O, but got Unknown
//IL_0308: Unknown result type (might be due to invalid IL or missing references)
//IL_0312: Unknown result type (might be due to invalid IL or missing references)
//IL_031e: Unknown result type (might be due to invalid IL or missing references)
//IL_0336: Unknown result type (might be due to invalid IL or missing references)
//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: Expected O, but got Unknown
//IL_02de: Unknown result type (might be due to invalid IL or missing references)
//IL_02e8: Expected O, but got Unknown
List<Vector2> list = ((PosField == null) ? null : (PosField.GetValue(ph) as List<Vector2>));
if (ph.buttons == null || ph.buttons.Count == 0 || list == null || list.Count != ph.buttons.Count || (Object)(object)ph.quitButton == (Object)null)
{
return;
}
List<float> list2 = new List<float>();
float num = 0f;
Vector2 val2 = default(Vector2);
for (int i = 0; i < list.Count; i++)
{
Vector2 val = Factor(i);
((Vector2)(ref val2))..ctor(list[i].x * val.x, list[i].y * val.y);
if (!(((Vector2)(ref val2)).magnitude < 1f))
{
num += ((Vector2)(ref val2)).magnitude;
list2.Add(Mathf.Repeat(Mathf.Atan2(val2.y, val2.x) * 57.29578f, 360f));
}
}
if (list2.Count == 0)
{
return;
}
num /= (float)list2.Count;
list2.Sort();
float num2 = -1f;
float num3 = 270f;
for (int j = 0; j < list2.Count; j++)
{
float num4 = list2[j];
float num5 = ((j + 1 < list2.Count) ? list2[j + 1] : (list2[0] + 360f));
if (num5 - num4 > num2)
{
num2 = num5 - num4;
num3 = num4 + (num5 - num4) / 2f;
}
}
float num6 = num3 * ((float)Math.PI / 180f);
Vector2 val3 = default(Vector2);
((Vector2)(ref val3))..ctor(Mathf.Cos(num6) * num, Mathf.Sin(num6) * num);
Vector2 val4 = Factor(list.Count);
Vector2 item = default(Vector2);
((Vector2)(ref item))..ctor(Mathf.Approximately(val4.x, 0f) ? val3.x : (val3.x / val4.x), Mathf.Approximately(val4.y, 0f) ? val3.y : (val3.y / val4.y));
RectTransform val5 = (RectTransform)((Component)ph.quitButton).transform;
GameObject val6 = Object.Instantiate<GameObject>(((Component)val5).gameObject, ((Transform)val5).parent, false);
((Object)val6).name = "IRegretNothingEndYourself";
img = val6.GetComponent<Image>();
if ((Object)(object)img != (Object)null)
{
img.sprite = ph.quitButton.sprite;
}
tip = val6.GetComponent<UITooltip>();
if ((Object)(object)tip != (Object)null)
{
tip.skipLocale = true;
tip.localeName = "";
tip.localeDesc = "";
}
Button component = val6.GetComponent<Button>();
if ((Object)(object)component != (Object)null)
{
component.onClick = new ButtonClickedEvent();
((UnityEvent)component.onClick).AddListener(new UnityAction(Click));
}
RectTransform val7 = (RectTransform)val6.transform;
((Transform)val7).localPosition = new Vector3(item.x, item.y, ((Transform)val5).localPosition.z);
((Transform)val7).localScale = Vector3.one;
ph.buttons.Add(val7);
list.Add(item);
button = val6;
Reset();
}
}
internal class GrenadeResources : ResourcesAPI
{
private static ResourcesAPI previous;
private static GrenadeResources instance;
private static int depth;
private static readonly MethodInfo LoadMethod = AccessTools.Method(typeof(ResourcesAPI), "Load", new Type[2]
{
typeof(string),
typeof(Type)
}, (Type[])null);
public static void Install()
{
ResourcesAPI overrideAPI = ResourcesAPI.overrideAPI;
if (overrideAPI == null || (object)overrideAPI != instance)
{
previous = overrideAPI;
if (instance == null)
{
instance = new GrenadeResources();
}
ResourcesAPI.overrideAPI = (ResourcesAPI)(object)instance;
}
}
public static void Check()
{
ResourcesAPI overrideAPI = ResourcesAPI.overrideAPI;
if (overrideAPI == null || (object)overrideAPI != instance)
{
bool flag = false;
try
{
flag = Resources.Load("fraggrenade") != (Object)null;
}
catch (Exception)
{
}
if (!flag)
{
Plugin.Log.LogWarning((object)"Another mod replaced the game's item loader without passing items along. Putting the grenade back.");
Install();
}
}
}
protected override Object Load(string path, Type systemTypeInstance)
{
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Expected O, but got Unknown
if (Grenade.IsOurs(path) && (systemTypeInstance == null || systemTypeInstance.IsAssignableFrom(typeof(GameObject))))
{
try
{
Object val = Grenade.Template();
if (val != (Object)null)
{
return val;
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("Couldn't create the grenade: " + ex));
}
}
if (depth > 0 || previous == null || LoadMethod == null)
{
return ((ResourcesAPI)this).Load(path, systemTypeInstance);
}
depth++;
try
{
return (Object)LoadMethod.Invoke(previous, new object[2] { path, systemTypeInstance });
}
catch (Exception)
{
return ((ResourcesAPI)this).Load(path, systemTypeInstance);
}
finally
{
depth--;
}
}
}
[HarmonyPatch(typeof(Utils), "Create", new Type[]
{
typeof(string),
typeof(Vector2),
typeof(float)
})]
internal static class CreateAtPatch
{
private static bool Prefix(string id, Vector2 pos, float rot, ref GameObject __result)
{
//IL_001d: 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_002e: Unknown result type (might be due to invalid IL or missing references)
if (!Grenade.IsOurs(id))
{
return true;
}
Object val = Grenade.Template();
if (val == (Object)null)
{
return true;
}
Object obj = Object.Instantiate(val, Vector2.op_Implicit(pos), Quaternion.Euler(0f, 0f, rot));
__result = (GameObject)(object)((obj is GameObject) ? obj : null);
return false;
}
}
[HarmonyPatch(typeof(Utils), "Create", new Type[]
{
typeof(string),
typeof(Transform)
})]
internal static class CreateInPatch
{
private static bool Prefix(string id, Transform trans, ref GameObject __result)
{
if (!Grenade.IsOurs(id))
{
return true;
}
Object val = Grenade.Template();
if (val == (Object)null)
{
return true;
}
Object obj = Object.Instantiate(val, trans);
__result = (GameObject)(object)((obj is GameObject) ? obj : null);
return false;
}
}
[HarmonyPatch(typeof(Item), "SetupItems")]
internal static class SetupPatch
{
private static void Postfix()
{
Register();
}
internal static void Register()
{
try
{
Item.GlobalItems["fraggrenade"] = Grenade.NewInfo();
if (ItemLootPool.pool != null && ItemLootPool.pool.TryGetValue("utility", out var value) && !value.Contains("fraggrenade"))
{
value.Add("fraggrenade");
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("Couldn't add the grenade: " + ex));
}
}
}
[HarmonyPatch(typeof(Locale), "GetItem")]
internal static class NamePatch
{
private static bool Prefix(string str, ref string __result)
{
if (str == null || !str.StartsWith("fraggrenade", StringComparison.OrdinalIgnoreCase))
{
return true;
}
if (str.Length == "fraggrenade".Length)
{
__result = "Frag Grenade";
return false;
}
if (string.Equals(str, "fraggrenadedsc", StringComparison.OrdinalIgnoreCase))
{
__result = "A hand grenade. Throwing it pulls the pin for you. Using it pulls the pin and lets you hold on to it, if you're brave.";
return false;
}
return true;
}
}
[HarmonyPatch(typeof(ConsoleScript), "RegisterSpawnEntities")]
internal static class ConsoleListPatch
{
private static void Postfix(ConsoleScript __instance)
{
try
{
MethodInfo methodInfo = AccessTools.Method(typeof(ConsoleScript), "SearchExact", (Type[])null, (Type[])null);
object obj = ((methodInfo != null) ? methodInfo.Invoke(methodInfo.IsStatic ? null : __instance, new object[1] { "spawn" }) : null);
if (obj != null)
{
FieldInfo fieldInfo = AccessTools.Field(obj.GetType(), "argAutofill");
IDictionary dictionary = ((fieldInfo != null) ? (fieldInfo.GetValue(obj) as IDictionary) : null);
if (dictionary != null && dictionary.Contains(0) && dictionary[0] is List<string> list && !list.Contains("fraggrenade"))
{
list.Add("fraggrenade");
}
}
}
catch (Exception)
{
}
}
}
internal static class Reskin
{
internal static ConfigEntry<float> ExpieX;
internal static ConfigEntry<float> ExpieY;
internal static ConfigEntry<float> MilkyX;
internal static ConfigEntry<float> MilkyY;
internal static ConfigEntry<float> DuneX;
internal static ConfigEntry<float> DuneY;
internal static ConfigEntry<bool> Fit;
private static BaseUnityPlugin plugin;
private static bool looked;
private static bool hasDune;
public static void Bind(ConfigFile c, float ex, float ey, float mx, float my, float dx, float dy, string what)
{
DuneX = c.Bind<float>("Interpretation", "DuneX", dx, "With the Interpretation reskin (v1.2.0 or newer): move " + what + " on Dune forward (+) or back (-), in pixels.");
DuneY = c.Bind<float>("Interpretation", "DuneY", dy, "With the Interpretation reskin (v1.2.0 or newer): move " + what + " on Dune up (+) or down (-), in pixels.");
Fit = c.Bind<bool>("Interpretation", "FitToReskin", true, "Fit " + what + " to the Interpretation reskin. Only does something when the Interpretation mod is installed. Also on the pause screen.");
ExpieX = c.Bind<float>("Interpretation", "ExpieX", ex, "With the Interpretation reskin: move " + what + " on Expie forward (+) or back (-), in pixels.");
ExpieY = c.Bind<float>("Interpretation", "ExpieY", ey, "With the Interpretation reskin: move " + what + " on Expie up (+) or down (-), in pixels.");
MilkyX = c.Bind<float>("Interpretation", "MilkyX", mx, "With the Interpretation reskin: move " + what + " on Milky forward (+) or back (-), in pixels.");
MilkyY = c.Bind<float>("Interpretation", "MilkyY", my, "With the Interpretation reskin: move " + what + " on Milky up (+) or down (-), in pixels.");
}
public static bool On(int chr)
{
if (chr < 0 || chr > 2)
{
return false;
}
if (!looked)
{
looked = true;
if (Chainloader.PluginInfos.TryGetValue("interpretation", out var value) && value != null)
{
plugin = value.Instance;
hasDune = value.Metadata != null && value.Metadata.Version >= new Version(1, 2, 0);
}
}
if ((Object)(object)plugin == (Object)null || (chr == 2 && !hasDune))
{
return false;
}
if (Flag("General", "Enabled"))
{
return Flag("Characters", chr switch
{
1 => "Milky",
0 => "Expie",
_ => "Dune",
});
}
return false;
}
private static bool Flag(string section, string key)
{
ConfigEntry<bool> val = default(ConfigEntry<bool>);
if (plugin.Config.TryGetEntry<bool>(section, key, ref val))
{
return val.Value;
}
return true;
}
public static Vector2 Pixels(int chr)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: 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_0035: Unknown result type (might be due to invalid IL or missing references)
if (!Fit.Value || !On(chr))
{
return Vector2.zero;
}
return (Vector2)(chr switch
{
1 => new Vector2(MilkyX.Value, MilkyY.Value),
0 => new Vector2(ExpieX.Value, ExpieY.Value),
_ => new Vector2(DuneX.Value, DuneY.Value),
});
}
}