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 HarmonyLib;
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("GamersSuit")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GamersSuit")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2a6f062c-6cbd-40eb-ba5f-a5904bb66676")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GamersSuit;
[BepInPlugin("Cerzix.GamersSuitMod", "Gamers Suit Mod", "0.0.1")]
public class GamersSuitModBase : BaseUnityPlugin
{
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
private static void StartPatch(ref StartOfRound __instance)
{
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Expected O, but got Unknown
//IL_0314: Unknown result type (might be due to invalid IL or missing references)
//IL_031b: Expected O, but got Unknown
//IL_0367: Unknown result type (might be due to invalid IL or missing references)
try
{
if (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, "gamerssuit", SearchOption.AllDirectories).ToList();
List<string> list2 = new List<string>();
List<string> list3 = new List<string>();
foreach (string item in list)
{
if (item != "")
{
string[] files = Directory.GetFiles(item, "*.png");
Debug.Log((object)("Found file " + item));
list2.AddRange(files);
}
}
list2.Sort();
foreach (string item2 in list2)
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
UnlockableItem val2;
Material val3;
if (Path.GetFileNameWithoutExtension(item2).ToLower() == "default")
{
val2 = val;
val3 = val2.suitMaterial;
}
else
{
Debug.Log((object)"Making new suit");
string text = JsonUtility.ToJson((object)val);
val2 = JsonUtility.FromJson<UnlockableItem>(text);
val3 = Object.Instantiate<Material>(val2.suitMaterial);
}
byte[] array = File.ReadAllBytes(item2);
Texture2D val4 = new Texture2D(2, 2);
ImageConversion.LoadImage(val4, array);
val3.mainTexture = (Texture)(object)val4;
val2.unlockableName = Path.GetFileNameWithoutExtension(item2);
try
{
string path = Path.Combine(Path.GetDirectoryName(item2), "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('"', ' ', ',');
float result2;
Vector4 vector;
if (text3 == "PRICE" && int.TryParse(text4, out var result))
{
try
{
AddToRotatingShop(val2, result, __instance.unlockablesList.unlockables.Count);
}
catch (Exception ex)
{
Debug.Log((object)("Something went wrong with More Suits! Could not add a suit to the rotating shop. Error: " + ex));
}
}
else if (text4 == "KEYWORD")
{
val3.EnableKeyword(text3);
}
else if (text4.Contains(".png"))
{
string path2 = Path.Combine(Path.GetDirectoryName(item2), "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 (TryParseVector4(text4, out vector))
{
val3.SetVector(text3, vector);
}
}
}
}
catch (Exception ex2)
{
Debug.Log((object)("Something went wrong with More Suits! Error: " + ex2));
}
val2.suitMaterial = val3;
if (val2.unlockableName.ToLower() != "default")
{
__instance.unlockablesList.unlockables.Add(val2);
}
}
SuitsAdded = true;
break;
}
}
catch (Exception ex3)
{
Debug.Log((object)("Something went wrong with More Suits! Error: " + 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;
}
}
private const string modGuid = "Cerzix.GamersSuitMod";
private const string modName = "Gamers Suit Mod";
private const string modVersion = "0.0.1";
private readonly Harmony harmony = new Harmony("Cerzix.GamersSuitMod");
public static bool SuitsAdded;
private static GamersSuitModBase Instance;
private static TerminalNode cancelPurchase;
private static TerminalKeyword buyKeyword;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Gamers Suit Mod is loaded!");
}
private static void AddToRotatingShop(UnlockableItem newSuit, int price, int unlockableID)
{
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Expected O, but got Unknown
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Expected O, but got Unknown
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: 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_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: 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.TryParse(array[0], out var result) && float.TryParse(array[1], out var result2) && float.TryParse(array[2], out var result3) && float.TryParse(array[3], out var result4))
{
vector = new Vector4(result, result2, result3, result4);
return true;
}
return false;
}
}