using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CyberShred;
using HarmonyLib;
using Healthbars;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.UI.Extensions.ColorPicker;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CyberShred")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CyberShred")]
[assembly: AssemblyTitle("CyberShred")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
public class CyberShredToggle : MonoBehaviour
{
public TextMeshProUGUI label;
private Button button;
private void Start()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
button = ((Component)this).GetComponent<Button>();
((UnityEvent)button.onClick).AddListener(new UnityAction(Clicked));
if (!Plugin.ENABLE_CYBERSHRED)
{
((TMP_Text)label).text = "<color=#f00>OFF";
}
else
{
((TMP_Text)label).text = "<color=#0f0>ON";
}
}
private void Clicked()
{
if (Plugin.ENABLE_CYBERSHRED)
{
Plugin.ENABLE_CYBERSHRED = false;
((TMP_Text)label).text = "<color=#f00>OFF";
}
else
{
Plugin.ENABLE_CYBERSHRED = true;
((TMP_Text)label).text = "<color=#0f0>ON";
}
}
private void Update()
{
}
}
public class Timer : MonoBehaviour
{
public static Timer _instance;
public EnemyIdentifier identifier;
public BossHealthBar bar;
public RectTransform rect;
public TextMeshProUGUI timerText;
public TextMeshProUGUI scoreText;
public TextMeshProUGUI barCountText;
private TextMeshProUGUI barCountTextClone;
public float timeLeft = 180f;
public float timeUntilSetInactive = 5f;
public double score = 0.0;
public bool gameOver = false;
public static Timer Instance => _instance;
private void Awake()
{
_instance = this;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
}
private void Start()
{
((Component)this).gameObject.SetActive(false);
}
private int CountBarsLeft(BossHealthBar bar)
{
float health = bar.source.Health;
float num = 0f;
for (int i = 0; i < bar.healthLayers.Length; i++)
{
HealthLayer val = bar.healthLayers[i];
if (health < num)
{
return i;
}
num += val.health;
}
return bar.healthLayers.Length;
}
private void Update()
{
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: 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)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)identifier == (Object)null)
{
identifier = null;
timeUntilSetInactive -= Time.deltaTime;
if (timeUntilSetInactive < 0f)
{
((Component)this).gameObject.SetActive(false);
}
return;
}
if ((Object)(object)((TMP_Text)barCountTextClone).transform.parent == (Object)(object)((Component)this).transform)
{
Dictionary<int, BossHealthBarTemplate> privateField = MonoSingleton<BossBarManager>.Instance.GetPrivateField<Dictionary<int, BossHealthBarTemplate>>("bossBars");
if (privateField.ContainsKey(bar.bossBarId))
{
((TMP_Text)barCountTextClone).transform.parent = privateField[bar.bossBarId].sliderTemplate.filler.transform;
((TMP_Text)barCountTextClone).transform.localScale = Vector3.one;
((TMP_Text)barCountTextClone).rectTransform.sizeDelta = Vector2.op_Implicit(new Vector3(-200f, -4f));
((Transform)((TMP_Text)barCountTextClone).rectTransform).localPosition = Vector3.zero;
((TMP_Text)barCountTextClone).fontSize = 30f;
}
}
if (MonoSingleton<NewMovement>.Instance.dead || identifier.health < 0f)
{
gameOver = true;
}
if (!gameOver && identifier.health > 0f)
{
timeLeft -= Time.deltaTime;
}
if (!gameOver)
{
score = (double)(50000f - identifier.Health) * 100.0;
}
if (timeLeft < 0f && !gameOver && !MonoSingleton<NewMovement>.Instance.dead)
{
gameOver = true;
MonoSingleton<NewMovement>.Instance.GetHurt(999, false, 1f, false, true, 0.35f, true);
}
((TMP_Text)barCountTextClone).text = $"x{CountBarsLeft(bar)}";
int num = (int)(timeLeft / 60f);
int num2 = (int)(timeLeft % 60f);
((TMP_Text)timerText).text = string.Format("<size=50%><color=#fff>Time Left<space=0.1em></color></size>\n{0}:{1}", num, num2.ToString("D2"));
((TMP_Text)scoreText).text = "<size=50%><color=#fff>Score</color></size>\n" + ((int)score).ToString("N0", CultureInfo.InvariantCulture);
}
public void StartTimer(EnemyIdentifier boss)
{
((Component)this).gameObject.SetActive(true);
timeLeft = 180f;
timeUntilSetInactive = 5f;
gameOver = false;
identifier = boss;
bar = ((Component)boss).GetComponent<BossHealthBar>();
barCountTextClone = Object.Instantiate<GameObject>(((Component)barCountText).gameObject).GetComponent<TextMeshProUGUI>();
((Component)barCountTextClone).gameObject.SetActive(true);
((TMP_Text)barCountTextClone).transform.parent = ((Component)this).transform;
}
}
namespace Healthbars
{
internal static class ReflectionUtils
{
public static T GetPrivateField<T>(this object obj, string field)
{
Type type = obj.GetType();
if (type.GetField(field, BindingFlags.Instance | BindingFlags.NonPublic) == null)
{
throw new ArgumentException("The field " + field + " does not exist in target class " + type.Name + "!");
}
return (T)type.GetField(field, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj);
}
public static void SetPrivateField<T>(this object obj, string field, T value)
{
Type type = obj.GetType();
if (type.GetField(field, BindingFlags.Instance | BindingFlags.NonPublic) == null)
{
throw new ArgumentException("The field " + field + " does not exist in target class " + type.Name + "!");
}
type.GetField(field, BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, value);
}
}
}
namespace CyberShred
{
[HarmonyPatch(typeof(EnemyIdentifier))]
public static class EnemyBossPatch
{
public static void SetHealth(this EnemyIdentifier enemyIdentifier, float health)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Invalid comparison between Unknown and I4
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Invalid comparison between Unknown and I4
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: 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_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected I4, but got Unknown
if (((int)enemyIdentifier.enemyType == 1 || (int)enemyIdentifier.enemyType == 9) && Object.op_Implicit((Object)(object)enemyIdentifier.drone))
{
enemyIdentifier.health = health;
enemyIdentifier.drone.health = health;
return;
}
if ((int)enemyIdentifier.enemyType == 4 && Object.op_Implicit((Object)(object)enemyIdentifier.spider))
{
enemyIdentifier.health = health;
enemyIdentifier.spider.health = health;
return;
}
EnemyClass enemyClass = enemyIdentifier.enemyClass;
EnemyClass val = enemyClass;
switch ((int)val)
{
case 0:
if (Object.op_Implicit((Object)(object)enemyIdentifier.zombie))
{
enemyIdentifier.health = health;
enemyIdentifier.zombie.health = health;
}
break;
case 1:
if (Object.op_Implicit((Object)(object)enemyIdentifier.machine))
{
enemyIdentifier.health = health;
enemyIdentifier.machine.health = health;
}
break;
case 2:
if (Object.op_Implicit((Object)(object)enemyIdentifier.statue))
{
enemyIdentifier.statue.health = health;
enemyIdentifier.health = health;
}
break;
default:
throw new Exception("enemy type unsupported!");
}
}
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void EnemySpawned(EnemyIdentifier __instance)
{
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Expected O, but got Unknown
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Expected O, but got Unknown
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: 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_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.ENABLE_CYBERSHRED)
{
return;
}
BossHealthBar component = ((Component)__instance).GetComponent<BossHealthBar>();
if (!((Object)(object)component != (Object)null))
{
return;
}
SliderLayer[] privateField = MonoSingleton<BossBarManager>.Instance.GetPrivateField<SliderLayer[]>("layers");
List<SliderLayer> list = new List<SliderLayer>();
list.Capacity = 50;
list.AddRange(privateField);
for (int i = 4; i < 50; i++)
{
bool flag = i % 2 == 1;
float num = 360f - 45f * (float)(i / 2);
if (i % 16 >= 8)
{
num -= 45f;
}
if (i % 16 >= 12)
{
num = 60f;
}
if (i % 16 >= 14)
{
num = 30f;
}
Color color = HSVUtil.ConvertHsvToRgb((double)num, 1.0, (double)(flag ? 0.12f : 1f), 1f);
SliderLayer val = new SliderLayer();
val.color = color;
if (i % 16 < 4)
{
val.color = privateField[i % 16].color;
}
val.afterImageColor = privateField[0].afterImageColor;
list.Add(val);
}
MonoSingleton<BossBarManager>.Instance.SetPrivateField("layers", list.ToArray());
HealthLayer[] array = (HealthLayer[])(object)new HealthLayer[50];
for (int j = 0; j < array.Length; j++)
{
array[array.Length - 1 - j] = new HealthLayer();
float health = 50f;
if (j >= 49)
{
health = 5000f;
}
else if (j >= 39)
{
health = 2500f;
}
else if (j >= 25)
{
health = 1000f;
}
else if (j >= 17)
{
health = 500f;
}
else if (j >= 11)
{
health = 200f;
}
else if (j >= 6)
{
health = 100f;
}
array[array.Length - 1 - j].health = health;
}
float num2 = 0f;
for (int k = 0; k < array.Length; k++)
{
num2 += array[k].health;
}
if (num2 != 50000f)
{
Debug.LogError((object)$"{num2} != {50000f}!!!!!");
}
component.healthLayers = array;
__instance.SetHealth(50000f);
Timer.Instance.StartTimer(__instance);
}
}
[HarmonyPatch(typeof(MenuEsc))]
public class MenuEscPatch
{
private static GameObject cyberShredToggle;
[HarmonyPostfix]
[HarmonyPatch("OnEnable")]
private static void MenuOpened(MenuEsc __instance)
{
Plugin.Log.LogInfo((object)((Object)((Component)__instance).gameObject).name);
if (((Object)((Component)__instance).gameObject).name == "Chapter Select" && (Object)(object)cyberShredToggle == (Object)null)
{
cyberShredToggle = Object.Instantiate<GameObject>(Plugin.toggle, ((Component)__instance).transform);
}
}
}
[BepInPlugin("CyberShred", "CyberShred", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const float BOSS_HEALTH = 50000f;
public const bool ENABLE_STAMINA_BAR = false;
public const bool PER_PHASE_SEGMENTING = false;
public static Plugin instance;
public static GameObject ob;
public static GameObject healthbar;
public static Canvas canvas;
public static GameObject toggle;
public static bool ENABLE_CYBERSHRED;
internal static ManualLogSource Log;
private void Awake()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Harmony val = new Harmony("me.eladnlg.cybershred");
val.PatchAll();
ob = ((Component)this).gameObject;
instance = this;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CyberShred is loaded!");
AssetBundle val2 = AssetUtils.LoadAssetBundleFromResources("cybershred", Assembly.GetExecutingAssembly());
healthbar = val2.LoadAsset<GameObject>("Timer");
toggle = val2.LoadAsset<GameObject>("CyberShred Toggle");
if ((Object)(object)healthbar == (Object)null)
{
throw new NullReferenceException("Healthbar asset is null!");
}
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Plugin {0} is loade2d! {1}", "CyberShred", (Object)(object)toggle == (Object)null));
canvas = Object.Instantiate<GameObject>(healthbar).GetComponent<Canvas>();
SceneManager.activeSceneChanged += ActiveSceneChanged;
Log = ((BaseUnityPlugin)this).Logger;
}
private void ActiveSceneChanged(Scene prev, Scene next)
{
if ((Object)(object)canvas != (Object)null)
{
Object.Destroy((Object)(object)((Component)canvas).gameObject);
}
canvas = Object.Instantiate<GameObject>(healthbar).GetComponent<Canvas>();
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "CyberShred";
public const string PLUGIN_NAME = "CyberShred";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace Jotunn.Utils
{
public static class AssetUtils
{
public const char AssetBundlePathSeparator = '$';
public static Texture2D LoadTexture(string texturePath, bool relativePath = true)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
string text = texturePath;
if (relativePath)
{
text = Path.Combine(Paths.PluginPath, texturePath);
}
if (!File.Exists(text))
{
return null;
}
if (!text.EndsWith(".png") && !text.EndsWith(".jpg"))
{
throw new Exception("LoadTexture can only load png or jpg textures");
}
byte[] array = File.ReadAllBytes(text);
Texture2D val = new Texture2D(2, 2);
val.LoadRawTextureData(array);
return val;
}
public static Sprite LoadSpriteFromFile(string spritePath)
{
//IL_002e: 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)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = LoadTexture(spritePath);
if ((Object)(object)val != (Object)null)
{
return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), default(Vector2), 100f);
}
return null;
}
public static AssetBundle LoadAssetBundle(string bundlePath)
{
string text = Path.Combine(Paths.PluginPath, bundlePath);
if (!File.Exists(text))
{
return null;
}
return AssetBundle.LoadFromFile(text);
}
public static AssetBundle LoadAssetBundleFromResources(string bundleName, Assembly resourceAssembly)
{
if (resourceAssembly == null)
{
throw new ArgumentNullException("Parameter resourceAssembly can not be null.");
}
string text = null;
try
{
text = resourceAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(bundleName));
}
catch (Exception)
{
}
if (text == null)
{
Debug.LogError((object)("AssetBundle " + bundleName + " not found in assembly manifest"));
return null;
}
AssetBundle result;
using (Stream stream = resourceAssembly.GetManifestResourceStream(text))
{
result = AssetBundle.LoadFromStream(stream);
}
return result;
}
public static string LoadText(string path)
{
string text = Path.Combine(Paths.PluginPath, path);
if (!File.Exists(text))
{
Debug.LogError((object)("Error, failed to load contents from non-existant path: $" + text));
return null;
}
return File.ReadAllText(text);
}
public static Sprite LoadSprite(string assetPath)
{
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
string text = Path.Combine(Paths.PluginPath, assetPath);
if (!File.Exists(text))
{
return null;
}
if (text.Contains('$'.ToString()))
{
string[] array = text.Split('$');
string text2 = array[0];
string text3 = array[1];
AssetBundle val = AssetBundle.LoadFromFile(text2);
Sprite result = val.LoadAsset<Sprite>(text3);
val.Unload(false);
return result;
}
Texture2D val2 = LoadTexture(text, relativePath: false);
if (!Object.op_Implicit((Object)(object)val2))
{
return null;
}
return Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), Vector2.zero);
}
}
}