using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Lethal_Injection.Patches;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Lethal_Injection")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Lethal_Injection")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c0becfb0-6b04-4495-8740-92435a88c284")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName = ".NET Framework 4.6.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Lethal_Injection
{
internal class Config
{
private static ConfigFile ConfigFile { get; set; }
static Config()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
ConfigFile = new ConfigFile(Paths.ConfigPath + "\\Lethal_Injection.cfg", true);
foreach (string cosmeticFolder in Plugin.CosmeticFolders)
{
int num = cosmeticFolder.IndexOf("plugins\\", StringComparison.Ordinal) + "plugins\\".Length;
int num2 = cosmeticFolder.IndexOf("\\Lethal_Injection", num, StringComparison.Ordinal);
string text = cosmeticFolder.Substring(num, num2 - num);
if (!ConfigFile.Bind<bool>(text, "Enabled", true, "Enable or disable " + text).Value)
{
Directory.Move(cosmeticFolder, cosmeticFolder + ".Disabled");
}
}
}
}
[BepInPlugin("Lethal_Injection", "Lethal_Injection", "1.2.3")]
public class Plugin : BaseUnityPlugin
{
private static string[] folderNames;
public static List<string>[] cosmeticFiles;
public static string DataPath;
public static List<string> CosmeticFolders = new List<string>();
public static Random Rand = new Random();
public static Plugin Instance;
public static bool SuitsAdded;
public static ConfigEntry<string> DisabledSuits;
private static TerminalNode cancelPurchase;
private static TerminalKeyword buyKeyword;
private void Awake()
{
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)(Paths.PluginPath + "\\cosmetic\\suits\\"));
cosmeticsAwake();
DisabledSuits = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Disabled Suit List", "UglySuit751.png,UglySuit752.png,UglySuit753.png", "Comma-separated list of suits that shouldn't be loaded");
Lethal_Injection.Patches.Patches.Init(((BaseUnityPlugin)this).Logger);
new Harmony("Lethal_Injection").PatchAll(typeof(Lethal_Injection.Patches.Patches));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Lethal_Injection (1.2.3) is loaded!");
((BaseUnityPlugin)this).Logger.LogInfo((object)("THE PLUGIN PATH IS: ----------------> " + Paths.PluginPath));
}
private void cosmeticsAwake()
{
folderNames = new string[4] { "posters", "tips", "clipboard", "terminal" };
cosmeticFiles = new List<string>[folderNames.Length];
DataPath = Paths.PluginPath + "\\Cosmos-Lethal_Injection";
CosmeticFolders = Directory.GetDirectories(DataPath, "cosmetic\\", SearchOption.TopDirectoryOnly).ToList();
((BaseUnityPlugin)this).Logger.LogInfo((object)(CosmeticFolders.Count + " !!!!!!!!!!!!!!"));
for (int i = 0; i < folderNames.Length; i++)
{
cosmeticFiles[i] = getFiles(CosmeticFolders[i]);
}
}
private List<string> getFiles(string path)
{
List<string> list = new List<string>();
int num = 0;
((BaseUnityPlugin)this).Logger.LogInfo((object)(Path.Combine(path, ((Object)this).name) + "--------------------------------------------------------------"));
string[] files = Directory.GetFiles(Path.Combine(path));
foreach (string text in files)
{
if (Path.GetExtension(text) != ".old")
{
list.Add(text);
num++;
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)(num + ((Object)this).name + " loaded"));
return list;
}
public static void AddToRotatingShop(UnlockableItem newSuit, int price, int unlockableID)
{
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Expected O, but got Unknown
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Expected O, but got Unknown
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
//IL_02a4: Expected O, but got Unknown
Terminal val = Object.FindObjectOfType<Terminal>();
for (int i = 0; i < val.terminalNodes.allKeywords.Length; i++)
{
if (((Object)val.terminalNodes.allKeywords[i]).name == "Buy")
{
buyKeyword = val.terminalNodes.allKeywords[i];
break;
}
}
newSuit.alreadyUnlocked = false;
newSuit.shopSelectionNode = ScriptableObject.CreateInstance<TerminalNode>();
((Object)newSuit.shopSelectionNode).name = newSuit.unlockableName + "SuitBuy1";
newSuit.shopSelectionNode.creatureName = newSuit.unlockableName + " suit";
newSuit.shopSelectionNode.displayText = "You have requested to order " + newSuit.unlockableName + " suits.\nTotal cost of item: [totalCost].\n\nPlease CONFIRM or DENY.\n\n";
newSuit.shopSelectionNode.clearPreviousText = true;
newSuit.shopSelectionNode.shipUnlockableID = unlockableID;
newSuit.shopSelectionNode.itemCost = price;
newSuit.shopSelectionNode.overrideOptions = true;
CompatibleNoun val2 = new CompatibleNoun();
val2.noun = ScriptableObject.CreateInstance<TerminalKeyword>();
val2.noun.word = "confirm";
val2.noun.isVerb = true;
val2.result = ScriptableObject.CreateInstance<TerminalNode>();
((Object)val2.result).name = newSuit.unlockableName + "SuitBuyConfirm";
val2.result.creatureName = "";
val2.result.displayText = "Ordered " + newSuit.unlockableName + " suits! Your new balance is [playerCredits].\n\n";
val2.result.clearPreviousText = true;
val2.result.shipUnlockableID = unlockableID;
val2.result.buyUnlockable = true;
val2.result.itemCost = price;
val2.result.terminalEvent = "";
CompatibleNoun val3 = new CompatibleNoun();
val3.noun = ScriptableObject.CreateInstance<TerminalKeyword>();
val3.noun.word = "deny";
val3.noun.isVerb = true;
if ((Object)(object)cancelPurchase == (Object)null)
{
cancelPurchase = ScriptableObject.CreateInstance<TerminalNode>();
}
val3.result = cancelPurchase;
((Object)val3.result).name = "MoreSuitsCancelPurchase";
val3.result.displayText = "Cancelled order.\n";
newSuit.shopSelectionNode.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2] { val2, val3 };
TerminalKeyword val4 = ScriptableObject.CreateInstance<TerminalKeyword>();
((Object)val4).name = newSuit.unlockableName + "Suit";
val4.word = newSuit.unlockableName.ToLower() + " suit";
val4.defaultVerb = buyKeyword;
CompatibleNoun val5 = new CompatibleNoun();
val5.noun = val4;
val5.result = newSuit.shopSelectionNode;
List<CompatibleNoun> list = buyKeyword.compatibleNouns.ToList();
list.Add(val5);
buyKeyword.compatibleNouns = list.ToArray();
List<TerminalKeyword> list2 = val.terminalNodes.allKeywords.ToList();
list2.Add(val4);
list2.Add(val2.noun);
list2.Add(val3.noun);
val.terminalNodes.allKeywords = list2.ToArray();
}
public static bool TryParseVector4(string input, out Vector4 vector)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: 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)
vector = Vector4.zero;
string[] array = input.Split(new char[1] { ',' });
if (array.Length == 4)
{
float result = 0f;
float result2 = 0f;
float result3 = 0f;
float result4 = 0f;
if (float.TryParse(array[0], out result) && float.TryParse(array[1], out result2) && float.TryParse(array[2], out result3) && float.TryParse(array[3], out result4))
{
vector = new Vector4(result, result2, result3, result4);
return true;
}
}
return false;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Lethal_Injection";
public const string PLUGIN_NAME = "Lethal_Injection";
public const string PLUGIN_VERSION = "1.2.3";
}
}
namespace Lethal_Injection.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
internal class Patches
{
private static Random rand = new Random();
private static ManualLogSource Logger { get; set; }
public static void Init(ManualLogSource logger)
{
Logger = logger;
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
private static void StartPatch(ref StartOfRound __instance)
{
Logger.LogInfo((object)"----------------------------------------------------------Patching Start in StartOfRound");
UpdateMaterials(0);
}
[HarmonyPatch(typeof(ItemDropship), "TryOpeningShip")]
[HarmonyPrefix]
private static void dropshipSuprise()
{
GameObject gameObject = ((Component)Object.FindObjectOfType<ItemDropship>()).gameObject;
RoundManager component = ((Component)Object.FindObjectOfType<RoundManager>()).gameObject.GetComponent<RoundManager>();
if (component.currentLevel.Enemies.Count > 1)
{
ItemDropship component2 = gameObject.GetComponent<ItemDropship>();
GameObject val = SpawnEnemy(component2.itemSpawnPositions, 1, component);
EnemyAI component3 = val.GetComponent<EnemyAI>();
EnemyType enemyType = component3.enemyType;
enemyType.numberSpawned++;
component3.enemyType.isOutsideEnemy = true;
component3.allAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode");
component3.SyncPositionToClients();
component.SpawnedEnemies.Add(component3);
}
else
{
Logger.LogError((object)"No enemies found to be spawned");
}
}
private static GameObject SpawnEnemy(Transform[] spawnPos, int count, RoundManager r2)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
GameObject enemyPrefab = r2.currentLevel.Enemies[rand.Next(1, r2.currentLevel.Enemies.Count)].enemyType.enemyPrefab;
GameObject val = Object.Instantiate<GameObject>(enemyPrefab, spawnPos[rand.Next(1, spawnPos.Length)].position, Quaternion.Euler(Vector3.zero));
val.gameObject.GetComponentInChildren<NetworkObject>().Spawn(true);
return val;
}
[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
[HarmonyPostfix]
private static void GenerateNewLevelClientRpcPatch(int randomSeed)
{
Logger.LogInfo((object)"Patching GenerateNewLevelClientRpc in RoundManager");
UpdateMaterials(randomSeed);
}
private static void UpdateMaterials(int seed)
{
Logger.LogInfo((object)string.Concat(Plugin.cosmeticFiles[0], " 1", Plugin.cosmeticFiles[1], "2", Plugin.cosmeticFiles[2], "3 ", Plugin.cosmeticFiles[3], " 4"));
Plugin.Rand = new Random(seed);
Material[] materials = ((Renderer)GameObject.Find("HangarShip/Plane.001").GetComponent<MeshRenderer>()).materials;
UpdateTexture(Plugin.cosmeticFiles[1], materials[0], randTrue: true);
UpdateTexture(Plugin.cosmeticFiles[3], materials[1], randTrue: true);
Logger.LogInfo((object)"Patching the textures for clipboard");
Material[] array = (Material[])(object)new Material[Plugin.cosmeticFiles[0].Count + 1];
array[0] = ((Renderer)GameObject.Find("HangarShip/ClipboardManual/Plane").GetComponent<SkinnedMeshRenderer>()).material;
array[1] = ((Renderer)GameObject.Find("HangarShip/ClipboardManual/Plane.001").GetComponent<SkinnedMeshRenderer>()).material;
array[2] = ((Renderer)GameObject.Find("HangarShip/ClipboardManual/Plane.002").GetComponent<SkinnedMeshRenderer>()).material;
array[3] = ((Renderer)GameObject.Find("HangarShip/ClipboardManual/Plane.003").GetComponent<SkinnedMeshRenderer>()).material;
UpdateTextures(Plugin.cosmeticFiles[0], array, randTrue: false);
Material material = ((Renderer)GameObject.Find("Environment/HangarShip/Terminal").GetComponent<MeshRenderer>()).material;
UpdateTexture(Plugin.cosmeticFiles[2], material, randTrue: false);
}
private static void UpdateTextures(IReadOnlyList<string> files, Material[] material, bool randTrue)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
int num = 0;
if (files.Count == 0)
{
return;
}
if (randTrue)
{
num = Plugin.Rand.Next(files.Count);
}
foreach (string file in files)
{
Texture2D val = new Texture2D(2, 2);
Logger.LogInfo((object)("Patching " + ((Object)material[num]).name + " with " + files[num]));
ImageConversion.LoadImage(val, File.ReadAllBytes(files[num]));
material[num].mainTexture = (Texture)(object)val;
num++;
}
}
private static void UpdateTexture(IReadOnlyList<string> files, Material material, bool randTrue)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
int index = 0;
if (files.Count != 0)
{
if (randTrue)
{
index = Plugin.Rand.Next(files.Count);
}
Texture2D val = new Texture2D(2, 2);
Logger.LogInfo((object)("Patching " + ((Object)material).name + " with " + files[index]));
ImageConversion.LoadImage(val, File.ReadAllBytes(files[index]));
material.mainTexture = (Texture)(object)val;
}
}
[HarmonyPatch("Start")]
[HarmonyPrefix]
private static void suitPatch(ref StartOfRound __instance)
{
//IL_0476: Unknown result type (might be due to invalid IL or missing references)
//IL_047d: Expected O, but got Unknown
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Expected O, but got Unknown
//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
try
{
if (Plugin.SuitsAdded)
{
return;
}
for (int i = 0; i < __instance.unlockablesList.unlockables.Count; i++)
{
UnlockableItem val = __instance.unlockablesList.unlockables[i];
if (!((Object)(object)val.suitMaterial != (Object)null) || !val.alreadyUnlocked)
{
continue;
}
List<string> list = Directory.GetDirectories(Paths.PluginPath + "\\Cosmos-Lethal_Injection\\", "suits", SearchOption.AllDirectories).ToList();
List<string> list2 = new List<string>();
List<string> list3 = Plugin.DisabledSuits.Value.ToLower().Replace(".png", "").Split(new char[1] { ',' })
.ToList();
List<string> list4 = new List<string>();
foreach (string item in list)
{
if (File.Exists(Path.Combine(item, "!less-suits.txt")))
{
string[] collection = new string[10] { "glow", "ted", "ruben", "xander", "htet htet", "seb", "skeleton", "slayer", "james", "black" };
list4.AddRange(collection);
break;
}
}
foreach (string item2 in list)
{
if (item2 != "")
{
string[] files = Directory.GetFiles(item2, "*.png");
list2.AddRange(files);
}
}
list2.Sort();
foreach (string item3 in list2)
{
if (list3.Contains(Path.GetFileNameWithoutExtension(item3).ToLower()))
{
continue;
}
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (list4.Contains(Path.GetFileNameWithoutExtension(item3).ToLower()) && item3.Contains(directoryName))
{
continue;
}
UnlockableItem val2;
Material val3;
if (Path.GetFileNameWithoutExtension(item3).ToLower() == "default")
{
val2 = val;
val3 = val2.suitMaterial;
}
else
{
string text = JsonUtility.ToJson((object)val);
val2 = JsonUtility.FromJson<UnlockableItem>(text);
val3 = Object.Instantiate<Material>(val2.suitMaterial);
}
byte[] array = File.ReadAllBytes(item3);
Texture2D val4 = new Texture2D(2, 2);
ImageConversion.LoadImage(val4, array);
val3.mainTexture = (Texture)(object)val4;
val2.unlockableName = Path.GetFileNameWithoutExtension(item3);
try
{
string path = Path.Combine(Path.GetDirectoryName(item3), "advanced", val2.unlockableName + ".json");
if (File.Exists(path))
{
string[] array2 = File.ReadAllLines(path);
string[] array3 = array2;
foreach (string text2 in array3)
{
string[] array4 = text2.Trim().Split(new char[1] { ':' });
if (array4.Length != 2)
{
continue;
}
string text3 = array4[0].Trim('"', ' ', ',');
string text4 = array4[1].Trim('"', ' ', ',');
int result = 0;
float result2;
Vector4 vector;
if (text3 == "PRICE" && int.TryParse(text4, out result))
{
try
{
Plugin.AddToRotatingShop(val2, result, __instance.unlockablesList.unlockables.Count);
}
catch (Exception ex)
{
string text5 = "Something went wrong with More Suits! Could not add a suit to the rotating shop. Error: ";
Debug.Log((object)(text5 + ex));
}
}
else if (text4 == "KEYWORD")
{
val3.EnableKeyword(text3);
}
else if (text4.Contains(".png"))
{
string path2 = Path.Combine(Path.GetDirectoryName(item3), "advanced", text4);
byte[] array5 = File.ReadAllBytes(path2);
Texture2D val5 = new Texture2D(2, 2);
ImageConversion.LoadImage(val5, array5);
val3.SetTexture(text3, (Texture)(object)val5);
}
else if (float.TryParse(text4, out result2))
{
val3.SetFloat(text3, result2);
}
else if (Plugin.TryParseVector4(text4, out vector))
{
val3.SetVector(text3, vector);
}
}
}
}
catch (Exception ex2)
{
string text6 = "Something went wrong with More Suits! Error: ";
Debug.Log((object)(text6 + ex2));
}
val2.suitMaterial = val3;
if (val2.unlockableName.ToLower() != "default")
{
__instance.unlockablesList.unlockables.Add(val2);
}
}
Plugin.SuitsAdded = true;
break;
}
}
catch (Exception ex3)
{
string text7 = "Something went wrong with More Suits! Error: ";
Debug.Log((object)(text7 + ex3));
}
}
[HarmonyPatch("PositionSuitsOnRack")]
[HarmonyPrefix]
private static bool PositionSuitsOnRackPatch(ref StartOfRound __instance)
{
//IL_0072: 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)
//IL_0088: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
List<UnlockableSuit> source = Object.FindObjectsOfType<UnlockableSuit>().ToList();
source = source.OrderBy((UnlockableSuit suit) => suit.syncedSuitID.Value).ToList();
int num = 0;
foreach (UnlockableSuit item in source)
{
AutoParentToShip component = ((Component)item).gameObject.GetComponent<AutoParentToShip>();
component.overrideOffset = true;
component.positionOffset = new Vector3(-2.45f, 2.75f, -8.41f) + __instance.rightmostSuitPosition.forward * 0.18f * (float)num;
component.rotationOffset = new Vector3(0f, 90f, 0f);
num++;
}
return false;
}
}
}