Decompiled source of AdditionalContentFramework v1.0.3

plugins/AdditionalContentFramework.dll

Decompiled 10 months ago
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("AdditionalContentFramework")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AdditionalContentFramework")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a49abfd9-fde7-4c8d-9798-d9cbe51418e3")]
[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 AdditionalContentFramework;

[Serializable]
public class AdditionalSuitDef
{
	public string suitID;

	public string suitName;

	public string suitTexture;
}
[Serializable]
public class AdditionalContentModule
{
	public string resourceFolder;

	public List<AdditionalSuitDef> suitDefList = new List<AdditionalSuitDef>();

	public AdditionalContentModule(string folder)
	{
		resourceFolder = folder;
	}
}
[BepInPlugin("ACS.AdditionalContentFramework", "AdditionalContentFramework", "1.0.3")]
public class AdditionalContentFrameworkBase : BaseUnityPlugin
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class acgAdditionalContentPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void acsAdditionalContentPatch(StartOfRound __instance)
		{
			try
			{
				if (IsContentLoaded)
				{
					return;
				}
				AddLog("finding suit prefab...");
				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)
					{
						PrefabUnlockableSuit = val;
						AddLog("found suit prefab!");
						break;
					}
				}
				if (PrefabUnlockableSuit == null)
				{
					AddLog("ERROR: suit prefab was not found!");
					return;
				}
				AddLog("loading content modules...");
				string directoryName = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
				string[] directories = Directory.GetDirectories(directoryName);
				string[] array = directories;
				foreach (string path in array)
				{
					string[] directories2 = Directory.GetDirectories(path);
					string[] array2 = directories2;
					foreach (string path2 in array2)
					{
						DirectoryInfo directoryInfo = new DirectoryInfo(path2);
						if (directoryInfo.Name.StartsWith("res"))
						{
							LoadContentModule(path2);
						}
					}
					DirectoryInfo directoryInfo2 = new DirectoryInfo(path);
					if (directoryInfo2.Name.StartsWith("res"))
					{
						LoadContentModule(path);
					}
				}
				AddLog("loaded content modules! (count=" + ContentModules.Count + ")");
				AddLog("applying content modules...");
				foreach (AdditionalContentModule contentModule in ContentModules)
				{
					ApplyContentModule(__instance, contentModule);
				}
				AddLog("applied content modules!");
				IsContentLoaded = true;
			}
			catch (Exception ex)
			{
				AddLog("failed to load suits into lobby!\nERROR: " + ex);
			}
		}
	}

	private static AdditionalContentFrameworkBase Instance;

	private const string modGUID = "ACS.AdditionalContentFramework";

	private const string modName = "AdditionalContentFramework";

	private const string modVersion = "1.0.3";

	private readonly Harmony harmony = new Harmony("ACS.AdditionalContentFramework");

	private static ManualLogSource mls;

	public static bool IsContentLoaded = false;

	public static UnlockableItem PrefabUnlockableSuit = null;

	public static List<AdditionalContentModule> ContentModules = new List<AdditionalContentModule>();

	public string ModGUID => "ACS.AdditionalContentFramework";

	public string ModName => "AdditionalContentFramework";

	public string ModVersion => "1.0.3";

	public static void AddLog(string log)
	{
		mls.LogInfo((object)("AdditionalContentFramework - " + log));
	}

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		mls = Logger.CreateLogSource("ACS.AdditionalContentFramework");
		AddLog("initializing...");
		harmony.PatchAll();
		AddLog("initialized!");
	}

	public static AdditionalSuitDef LoadContentPiece_Suit(string defStr)
	{
		try
		{
			return JsonUtility.FromJson<AdditionalSuitDef>(defStr);
		}
		catch (Exception ex)
		{
			AddLog("failed to load content module piece (suitDef='" + defStr + "')!\nERROR: " + ex);
			return null;
		}
	}

	public static void LoadContentModule(string path)
	{
		try
		{
			AddLog("attempting to load suits from path:" + path);
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path);
			string text2 = Path.Combine(text, "suit-defs.json");
			AddLog("attempting to parse json file: " + text2);
			string text3 = File.ReadAllText(text2);
			if (text3 == null)
			{
				AddLog("ERROR: json file was not found or invalid");
				return;
			}
			AdditionalContentModule additionalContentModule = new AdditionalContentModule(text);
			string[] array = text3.Split(new char[1] { '[' });
			array = array[1].Split(new char[1] { ']' });
			array = array[0].Split(new char[1] { '{' });
			for (int i = 1; i < array.Length; i++)
			{
				string text4 = "{" + array[i].Trim();
				if (i != array.Length - 1)
				{
					text4 = text4.Substring(0, text4.Length - 1);
				}
				try
				{
					AdditionalSuitDef additionalSuitDef = JsonUtility.FromJson<AdditionalSuitDef>(text4);
					if (additionalSuitDef != null)
					{
						additionalContentModule.suitDefList.Add(additionalSuitDef);
						AddLog("\tloaded suit def: " + additionalSuitDef.suitName);
					}
				}
				catch (Exception ex)
				{
					AddLog("failed to load content module piece (json='" + text4 + "')!\nERROR: " + ex);
				}
			}
			ContentModules.Add(additionalContentModule);
			AddLog("finished loading suits from path:" + path);
		}
		catch (Exception ex2)
		{
			AddLog("failed to load content module!\nERROR: " + ex2);
		}
	}

	public static void ApplyContentModule(StartOfRound __instance, AdditionalContentModule suitDefManifest)
	{
		AddLog("applying additional content module from: " + suitDefManifest.resourceFolder + "...");
		foreach (AdditionalSuitDef suitDef in suitDefManifest.suitDefList)
		{
			AddSuitToRack(__instance, suitDef, suitDefManifest.resourceFolder);
		}
		AddLog("applyed additional content module from: " + suitDefManifest.resourceFolder + "!");
	}

	public static void AddSuitToRack(StartOfRound __instance, AdditionalSuitDef suitDef, string resourcePath)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		AddLog("adding suit to rack {id=" + suitDef.suitID + ", name=" + suitDef.suitName + "}...");
		UnlockableItem val = JsonUtility.FromJson<UnlockableItem>(JsonUtility.ToJson((object)PrefabUnlockableSuit));
		Texture2D val2 = new Texture2D(2, 2);
		ImageConversion.LoadImage(val2, File.ReadAllBytes(Path.Combine(resourcePath, suitDef.suitTexture)));
		Material val3 = Object.Instantiate<Material>(val.suitMaterial);
		val3.mainTexture = (Texture)(object)val2;
		val.suitMaterial = val3;
		val.unlockableName = suitDef.suitName;
		__instance.unlockablesList.unlockables.Add(val);
		AddLog("added suit to rack {id=" + suitDef.suitID + ", name=" + suitDef.suitName + "}! (new unlockable count is " + __instance.unlockablesList.unlockables.Count + ")");
	}
}