Decompiled source of ColliderPhotons v1.0.1

ColliderPhotons.dll

Decompiled a month ago
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.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using kremnev8;
using xiaoye97;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ColliderPhotons")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ColliderPhotons")]
[assembly: AssemblyTitle("ColliderPhotons")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace kremnev8
{
	public class Registry
	{
		public static Dictionary<int, ItemProto> items = new Dictionary<int, ItemProto>();

		private static Dictionary<int, int> itemUpgradeList = new Dictionary<int, int>();

		public static Dictionary<int, RecipeProto> recipes = new Dictionary<int, RecipeProto>();

		public static Dictionary<int, TechProto> techs = new Dictionary<int, TechProto>();

		public static Dictionary<int, TechProto> techUpdateList = new Dictionary<int, TechProto>();

		public static Dictionary<int, ModelProto> models = new Dictionary<int, ModelProto>();

		public static Dictionary<string, Material[]> modelMats = new Dictionary<string, Material[]>();

		public static AssetBundle bundle;

		public static string vertaFolder = "";

		public static string keyWord = "";

		public static ManualLogSource LogSource;

		public static Action onLoadingFinished;

		private static int[] textureNames;

		public static void Init(string bundleName, string keyword, bool requireBundle, bool requireVerta)
		{
			LogSource = Logger.CreateLogSource("Registry-" + keyword);
			keyWord = keyword;
			string directoryName = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Registry)).Location);
			int num = Shader.PropertyToID("_MainTex");
			int num2 = Shader.PropertyToID("_NormalTex");
			int num3 = Shader.PropertyToID("_MS_Tex");
			int num4 = Shader.PropertyToID("_EmissionTex");
			textureNames = new int[4] { num, num2, num3, num4 };
			FileInfo fileInfo = new FileInfo(directoryName + "/Verta/");
			FileInfo fileInfo2 = new FileInfo(directoryName + "/plugins/");
			if (Directory.Exists(fileInfo.Directory?.FullName))
			{
				vertaFolder = directoryName;
			}
			else if (Directory.Exists(fileInfo2.Directory?.FullName))
			{
				vertaFolder = directoryName + "/plugins";
			}
			else if (requireVerta)
			{
				vertaFolder = "";
				LogSource.LogError((object)"Cannot find folder with verta files. Mod WILL not work!");
				return;
			}
			if (requireBundle)
			{
				bundle = AssetBundle.LoadFromFile(directoryName + "/" + bundleName);
			}
			LDBTool.PostAddDataAction = (Action)Delegate.Combine(LDBTool.PostAddDataAction, new Action(onPostAdd));
			LDBTool.EditDataAction = (Action<Proto>)Delegate.Combine(LDBTool.EditDataAction, new Action<Proto>(EditProto));
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}

		private static void onPostAdd()
		{
			foreach (KeyValuePair<int, ModelProto> model in models)
			{
				model.Value.Preload();
				PrefabDesc prefabDesc = model.Value.prefabDesc;
				Material[] materials = prefabDesc.materials;
				for (int i = 0; i < prefabDesc.lodCount; i++)
				{
					for (int j = 0; j < prefabDesc.lodMaterials[i].Length; j++)
					{
						prefabDesc.lodMaterials[i][j] = materials[j];
					}
				}
				LDB.models.modelArray[((Proto)model.Value).ID] = model.Value;
			}
			foreach (KeyValuePair<int, ItemProto> item in items)
			{
				item.Value.Preload(item.Value.index);
			}
			foreach (KeyValuePair<int, RecipeProto> recipe in recipes)
			{
				recipe.Value.Preload(recipe.Value.index);
			}
			foreach (KeyValuePair<int, TechProto> tech in techs)
			{
				tech.Value.Preload();
				tech.Value.Preload2();
			}
			foreach (KeyValuePair<int, TechProto> techUpdate in techUpdateList)
			{
				TechProto val = ((ProtoSet<TechProto>)(object)LDB.techs).Select(techUpdate.Key);
				val.postTechArray = CollectionExtensions.AddToArray<TechProto>(val.postTechArray, techUpdate.Value);
			}
			onLoadingFinished?.Invoke();
			LogSource.LogInfo((object)"Post loading is complete!");
		}

		private static void EditProto(Proto proto)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			ItemProto val = (ItemProto)((proto is ItemProto) ? proto : null);
			if (val == null)
			{
				return;
			}
			if (itemUpgradeList.ContainsKey(((Proto)val).ID))
			{
				val.Grade = itemUpgradeList[((Proto)val).ID];
				LogSource.LogDebug((object)("Changing grade of " + ((Proto)val).name));
			}
			if (val.Grade == 0 || items.ContainsKey(((Proto)val).ID))
			{
				return;
			}
			foreach (KeyValuePair<int, ItemProto> item in items)
			{
				if (item.Value.Grade != 0 && item.Value.Upgrades != null && val.Grade <= item.Value.Upgrades.Length && item.Value.Upgrades[val.Grade - 1] == ((Proto)val).ID)
				{
					val.Upgrades = item.Value.Upgrades;
					LogSource.LogDebug((object)("Updating upgrade list of " + ((Proto)val).name));
				}
			}
		}

		private static int findAvailableID<T>(int startIndex, ProtoSet<T> set, Dictionary<int, T> list) where T : Proto
		{
			int i;
			for (i = startIndex; set.Select(i) != null || list.ContainsKey(i); i++)
			{
				if (i > 12000)
				{
					LogSource.LogError((object)"Failed to find free index!");
					throw new ArgumentException("No free indices available!");
				}
			}
			return i;
		}

		public static Material CreateMaterial(string shaderName, string materialName, string color, string[] textures = null, string[] keywords = null)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			Color color2 = default(Color);
			ColorUtility.TryParseHtmlString(color, ref color2);
			Material val = new Material(Shader.Find(shaderName));
			val.shaderKeywords = keywords ?? new string[1] { "_ENABLE_VFINST" };
			val.color = color2;
			((Object)val).name = materialName;
			Material val2 = val;
			if (textures == null)
			{
				return val2;
			}
			for (int i = 0; i < textures.Length; i++)
			{
				if (i < textureNames.Length)
				{
					Texture2D val3 = Resources.Load<Texture2D>(textures[i]);
					val2.SetTexture(textureNames[i], (Texture)val3);
				}
			}
			return val2;
		}

		public static ModelProto registerModel(int id, ItemProto proto, string prefabPath, Material[] mats, int[] descFields, int buildIndex, int grade = 0, int[] upgradesIDs = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			ModelProto val = new ModelProto
			{
				Name = id.ToString(),
				PrefabPath = prefabPath,
				ID = id
			};
			proto.Type = (EItemType)6;
			proto.ModelIndex = id;
			proto.ModelCount = 1;
			proto.BuildIndex = buildIndex;
			proto.BuildMode = 1;
			proto.IsEntity = true;
			proto.CanBuild = true;
			proto.DescFields = descFields;
			if (grade != 0 && upgradesIDs != null)
			{
				proto.Grade = grade;
				for (int i = 0; i < upgradesIDs.Length; i++)
				{
					int num = upgradesIDs[i];
					if (num != 0)
					{
						itemUpgradeList.Add(num, i + 1);
					}
				}
				upgradesIDs[grade - 1] = ((Proto)proto).ID;
				proto.Upgrades = upgradesIDs;
			}
			LDBTool.PreAddProto((Proto)val);
			models.Add(((Proto)val).ID, val);
			modelMats.Add(prefabPath, mats);
			return val;
		}

		public static ItemProto registerItem(int id, string name, string description, string iconPath, int gridIndex, int stackSize = 50)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			ItemProto val = new ItemProto();
			val.Type = (EItemType)2;
			val.StackSize = stackSize;
			val.FuelType = 0;
			val.IconPath = iconPath;
			((Proto)val).Name = name;
			val.Description = description;
			val.GridIndex = gridIndex;
			val.DescFields = new int[1] { 1 };
			((Proto)val).ID = id;
			ItemProto val2 = val;
			LDBTool.PreAddProto((Proto)val2);
			items.Add(((Proto)val2).ID, val2);
			return val2;
		}

		public static RecipeProto registerRecipe(int id, ERecipeType type, int time, int[] input, int[] inCounts, int[] output, int[] outCounts, string description, int techID = 0)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			if (output.Length == 0)
			{
				throw new ArgumentException("Output array must not be empty");
			}
			ItemProto val = (items.ContainsKey(output[0]) ? items[output[0]] : ((ProtoSet<ItemProto>)(object)LDB.items).Select(output[0]));
			TechProto preTech = null;
			if (techID != 0 && ((ProtoSet<TechProto>)(object)LDB.techs).Exist(techID))
			{
				preTech = ((ProtoSet<TechProto>)(object)LDB.techs).Select(techID);
			}
			RecipeProto val2 = new RecipeProto
			{
				Type = type,
				Handcraft = true,
				TimeSpend = time,
				Items = input,
				ItemCounts = inCounts,
				Results = output,
				ResultCounts = outCounts,
				Description = description,
				GridIndex = val.GridIndex,
				IconPath = val.IconPath,
				Name = ((Proto)val).Name + "Recipe",
				preTech = preTech,
				ID = id
			};
			LDBTool.PreAddProto((Proto)val2);
			recipes.Add(id, val2);
			return val2;
		}

		public static TechProto registerTech(int id, string name, string description, string conclusion, string iconPath, int[] preTechs, int[] jellos, int[] jelloRate, long hashNeeded, int[] unlockRecipes, Vector2 position)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			bool isLabTech = jellos.Any((int itemId) => LabComponent.matrixIds.Contains(itemId));
			TechProto val = new TechProto();
			((Proto)val).ID = id;
			((Proto)val).Name = name;
			val.Desc = description;
			val.Published = true;
			val.Conclusion = conclusion;
			val.IconPath = iconPath;
			val.IsLabTech = isLabTech;
			val.PreTechs = preTechs;
			val.Items = jellos;
			val.ItemPoints = jelloRate;
			val.HashNeeded = hashNeeded;
			val.UnlockRecipes = unlockRecipes;
			val.AddItems = new int[0];
			val.AddItemCounts = new int[0];
			val.Position = position;
			val.PreTechsImplicit = new int[0];
			val.UnlockFunctions = new int[0];
			val.UnlockValues = new double[0];
			TechProto val2 = val;
			foreach (int key in preTechs)
			{
				techUpdateList.Add(key, val2);
			}
			LDBTool.PreAddProto((Proto)val2);
			techs.Add(id, val2);
			return val2;
		}

		public static void registerString(string key, string enTrans)
		{
		}
	}
	[HarmonyPatch(typeof(Resources), "Load", new Type[]
	{
		typeof(string),
		typeof(Type)
	})]
	internal static class ResourcesPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(ref string path, Type systemTypeInstance, ref Object __result)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if (path.Contains(Registry.keyWord) && (Object)Registry.bundle != (Object)null)
			{
				if (Registry.bundle.Contains(path + ".prefab") && systemTypeInstance == typeof(GameObject))
				{
					Material[] array = Registry.modelMats[path];
					Object val = Registry.bundle.LoadAsset(path + ".prefab");
					if (val != (Object)null)
					{
						Registry.LogSource.LogDebug((object)("Loading known asset " + path + " (" + ((val != (Object)null) ? "Success" : "Failure") + ")"));
						MeshRenderer[] componentsInChildren = ((GameObject)val).GetComponentsInChildren<MeshRenderer>();
						MeshRenderer[] array2 = componentsInChildren;
						MeshRenderer[] array3 = array2;
						foreach (MeshRenderer val2 in array3)
						{
							Material[] array4 = (Material[])(object)new Material[((Renderer)val2).sharedMaterials.Length];
							for (int j = 0; j < array4.Length; j++)
							{
								array4[j] = array[j];
							}
							((Renderer)val2).sharedMaterials = array4;
						}
					}
					__result = val;
					return false;
				}
				if (Registry.bundle.Contains(path + ".png"))
				{
					Object val3 = Registry.bundle.LoadAsset(path + ".png", systemTypeInstance);
					Registry.LogSource.LogDebug((object)("Loading known asset " + path + " (" + ((val3 != (Object)null) ? "Success" : "Failure") + ")"));
					__result = val3;
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(StorageComponent), "LoadStatic")]
	internal static class StorageComponentPatch
	{
		private static bool staticLoad;

		[HarmonyPostfix]
		public static void Postfix()
		{
			if (staticLoad)
			{
				return;
			}
			foreach (KeyValuePair<int, ItemProto> item in Registry.items)
			{
				StorageComponent.itemIsFuel[item.Key] = item.Value.HeatValue > 0;
				StorageComponent.itemStackCount[item.Key] = item.Value.StackSize;
			}
			staticLoad = true;
		}
	}
	[HarmonyPatch(typeof(UIBuildMenu), "StaticLoad")]
	internal static class UIBuildMenuPatch
	{
		[HarmonyPostfix]
		public static void Postfix(ItemProto[,] ___protos)
		{
			foreach (KeyValuePair<int, ItemProto> item in Registry.items)
			{
				int buildIndex = item.Value.BuildIndex;
				if (buildIndex > 0)
				{
					int num = buildIndex / 100;
					int num2 = buildIndex % 100;
					if (num <= 12 && num2 <= 12)
					{
						___protos[num, num2] = item.Value;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(VertaBuffer), "LoadFromFile")]
	internal static class VertaBufferPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(ref string filename)
		{
			if (filename.Contains(Registry.keyWord) && !Registry.vertaFolder.Equals(""))
			{
				string text = Registry.vertaFolder + "/" + filename;
				if (File.Exists(text))
				{
					filename = text;
					Registry.LogSource.LogDebug((object)("Loading known verta file " + filename));
				}
			}
			return true;
		}
	}
}
namespace ColliderPhotons
{
	[BepInPlugin("mod.jamesfire.ColliderPhotons", "ColliderPhotons Plug-In", "1.0.1.0")]
	[BepInProcess("DSPGAME.exe")]
	public class ColliderPhotons : BaseUnityPlugin
	{
		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ColliderPhotons initializing 1.0.1");
			Registry.Init("", "ColliderPhotons", requireBundle: false, requireVerta: false);
			LDBTool.PreAddDataAction = (Action)Delegate.Combine(LDBTool.PreAddDataAction, new Action(GenRegistryPhotons));
		}

		private void GenRegistryPhotons()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"GenRegistryPhotons 开始执行");
			int techID = 1312;
			int id = GetFreeId(6202);
			Registry.registerRecipe(id, (ERecipeType)4, 1, new int[1] { 1116 }, new int[1] { 1 }, new int[1] { 5201 }, new int[1] { 6 }, "硫酸→黑雾矩阵", techID);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("已注册黑雾矩阵配方 ID=" + id));
			int id2 = GetFreeId(6203);
			Registry.registerRecipe(id2, (ERecipeType)4, 1, new int[1] { 1014 }, new int[1] { 1 }, new int[1] { 5202 }, new int[1] { 3 }, "光栅石→硅基神经元", techID);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("已注册硅基神经元配方 ID=" + id2));
			int id3 = GetFreeId(6204);
			Registry.registerRecipe(id3, (ERecipeType)4, 1, new int[1] { 1013 }, new int[1] { 1 }, new int[1] { 5203 }, new int[1] { 3 }, "分形硅石→物质重组器", techID);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("已注册物质重组器配方 ID=" + id3));
			int id4 = GetFreeId(6205);
			Registry.registerRecipe(id4, (ERecipeType)4, 1, new int[1] { 1012 }, new int[1] { 1 }, new int[1] { 5204 }, new int[1] { 3 }, "金伯利矿石→负熵奇点", techID);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("已注册负熵奇点配方 ID=" + id4));
			int id5 = GetFreeId(6207);
			Registry.registerRecipe(id5, (ERecipeType)4, 1, new int[1] { 1015 }, new int[1] { 1 }, new int[1] { 5206 }, new int[1] { 6 }, "刺笋结晶→能量碎片", techID);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("已注册能量碎片配方 ID=" + id5));
			int id6 = GetFreeId(6206);
			ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(5205);
			int gridIndex = val.GridIndex;
			val.GridIndex = 1812;
			Registry.registerRecipe(id6, (ERecipeType)4, 1, new int[1] { 1016 }, new int[1] { 1 }, new int[1] { 5205 }, new int[1] { 1 }, "单极磁石→核心素", techID);
			val.GridIndex = gridIndex;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("已注册核心素配方 ID=" + id6));
			int id7 = GetFreeId(6201);
			ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(1208);
			int gridIndex2 = val2.GridIndex;
			val2.GridIndex = 1813;
			Registry.registerRecipe(id7, (ERecipeType)5, 10, new int[1] { 1120 }, new int[1] { 2 }, new int[1] { 1208 }, new int[1] { 1 }, "氢→临界光子", techID);
			val2.GridIndex = gridIndex2;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("已注册临界光子配方 ID=" + id7));
			static int GetFreeId(int startId)
			{
				int i;
				for (i = startId; ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(i) != null; i++)
				{
				}
				return i;
			}
		}
	}
}