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.3")]
public class AdditionalSuitsBase : BaseUnityPlugin
{
[HarmonyPatch(typeof(StartOfRound))]
internal class acgAdditionalSuitsPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
private static void acsStartOfRoundPatch(StartOfRound __instance)
{
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: 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");
AddLog("attempting to parse json file: " + text);
string text2 = File.ReadAllText(text);
if (text2 == null)
{
AddLog("ERROR: json file was not found");
return;
}
AddLog("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);
}
AddLog("attempting to parse json file: items were found...");
foreach (UnlockableSuitDef unlockableSuit in SuitDefManifest.unlockableSuits)
{
AddLog("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.3";
private readonly Harmony harmony = new Harmony("ACS.AdditionalSuits");
private static ManualLogSource mls;
public static bool SuitsLoaded;
public static string ModResourceFolder;
public static UnlockableSuitDefListing SuitDefManifest;
public string ModGUID => "ACS.AdditionalSuits";
public string ModName => "AdditionalSuits";
public string ModVersion => "1.1.3";
public static void AddLog(string log)
{
mls.LogInfo((object)("AdditionalSuits - " + log));
}
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("ACS.AdditionalSuits");
AddLog("initializing...");
ModResourceFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "resAdditionalSuits");
harmony.PatchAll();
AddLog("initialized!");
}
}