using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
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("AdditionalSuits")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AdditionalSuits")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0c25b026-8574-4dd2-9af2-4265f618ef8a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AdditionalSuits;
[Serializable]
public class UnlockableSuitDef
{
public string suitID;
public string suitName;
public string suitTexture;
}
public class UnlockableSuitDefListing
{
public List<UnlockableSuitDef> unlockableSuits = new List<UnlockableSuitDef>();
}
[BepInPlugin("ACS.AdditionalSuits", "AdditionalSuits", "1.1.0")]
public class AdditionalSuitsBase : BaseUnityPlugin
{
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
private static void StartPatch(ref StartOfRound __instance)
{
//IL_0230: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Expected O, but got Unknown
try
{
if (SuitsLoaded)
{
return;
}
UnlockableItem val = null;
for (int i = 0; i < __instance.unlockablesList.unlockables.Count; i++)
{
UnlockableItem val2 = __instance.unlockablesList.unlockables[i];
if (!((Object)(object)val2.suitMaterial == (Object)null) && val2.alreadyUnlocked)
{
val = val2;
break;
}
}
string text = Path.Combine(ModResourceFolder, "suit-defs.json");
mls.LogInfo((object)("AdditionalSuits - attempting to parse json file: " + text));
string text2 = File.ReadAllText(text);
if (text2 == null)
{
mls.LogInfo((object)"AdditionalSuits - ERROR: json file was not found");
return;
}
mls.LogInfo((object)"AdditionalSuits - converting json file to manifest...");
string[] array = text2.Split(new char[1] { '[' });
array = array[1].Split(new char[1] { ']' });
array = array[0].Split(new char[1] { '{' });
SuitDefManifest = new UnlockableSuitDefListing();
for (int j = 1; j < array.Length; j++)
{
string text3 = "{" + array[j].Trim();
if (j != array.Length - 1)
{
text3 = text3.Substring(0, text3.Length - 1);
}
UnlockableSuitDef item = JsonUtility.FromJson<UnlockableSuitDef>(text3);
SuitDefManifest.unlockableSuits.Add(item);
}
mls.LogInfo((object)("AdditionalSuits - loading item defs from manifest, " + SuitDefManifest.unlockableSuits.Count + " items were found..."));
foreach (UnlockableSuitDef unlockableSuit in SuitDefManifest.unlockableSuits)
{
mls.LogInfo((object)("AdditionalSuits - processing custom suit {id=" + unlockableSuit.suitID + ", name=" + unlockableSuit.suitName + "}..."));
UnlockableItem val3 = JsonUtility.FromJson<UnlockableItem>(JsonUtility.ToJson((object)val));
Texture2D val4 = new Texture2D(2, 2);
ImageConversion.LoadImage(val4, File.ReadAllBytes(Path.Combine(ModResourceFolder, unlockableSuit.suitTexture)));
Material val5 = Object.Instantiate<Material>(val3.suitMaterial);
val5.mainTexture = (Texture)(object)val4;
val3.suitMaterial = val5;
val3.unlockableName = unlockableSuit.suitName;
__instance.unlockablesList.unlockables.Add(val3);
mls.LogInfo((object)("AdditionalSuits - added custom suit {id=" + unlockableSuit.suitID + ", name=" + unlockableSuit.suitName + "}!"));
}
mls.LogInfo((object)"AdditionalSuits - loaded item defs from json file!");
SuitsLoaded = true;
}
catch (Exception ex)
{
mls.LogInfo((object)("AdditionalSuits - initialization failed!\nERROR: " + ex));
}
}
}
private static AdditionalSuitsBase Instance;
private const string modGUID = "ACS.AdditionalSuits";
private const string modName = "AdditionalSuits";
private const string modVersion = "1.1.0";
private readonly Harmony harmony = new Harmony("ACS.AdditionalSuits");
public static ManualLogSource mls;
public static bool SuitsLoaded;
public static string ModResourceFolder;
public static UnlockableSuitDefListing SuitDefManifest;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("ACS.AdditionalSuits");
mls.LogInfo((object)"AdditionalSuits - initializing...");
ModResourceFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "resAdditionalSuits");
harmony.PatchAll();
mls.LogInfo((object)"AdditionalSuits - initialized!");
}
}