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 BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using HarmonyLib;
using UnityEngine;
using xiaoye97;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ColliderPhotons")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColliderPhotons")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ee345284-cd8a-46a8-a561-7ae194a3cf34")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.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, StringProto> strings = new Dictionary<int, StringProto>();
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)
{
ItemProto val = (ItemProto)(object)((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.dataIndices.ContainsKey(i) || 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_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
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)(object)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)
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((ProtoType)4, (Proto)(object)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)
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((ProtoType)3, (Proto)(object)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_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)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: 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_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Expected O, but got Unknown
if (output.Length != 0)
{
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((ProtoType)6, (Proto)(object)val2);
recipes.Add(id, val2);
return val2;
}
throw new ArgumentException("Output array must not be empty");
}
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)
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((ProtoType)8, (Proto)(object)val2);
techs.Add(id, val2);
return val2;
}
public static void registerString(string key, string enTrans)
{
//IL_0013: 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_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
int num = findAvailableID<StringProto>(100, (ProtoSet<StringProto>)(object)LDB.strings, strings);
StringProto val = new StringProto
{
Name = key,
ENUS = enTrans,
ID = num
};
LDBTool.PreAddProto((ProtoType)7, (Proto)(object)val);
strings.Add(num, val);
}
}
[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(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(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_00d9: Unknown result type (might be due to invalid IL or missing references)
if (path.Contains(Registry.keyWord) && (Object)(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;
foreach (MeshRenderer val2 in array2)
{
Material[] array3 = (Material[])(object)new Material[((Renderer)val2).sharedMaterials.Length];
for (int j = 0; j < array3.Length; j++)
{
array3[j] = array[j];
}
((Renderer)val2).sharedMaterials = array3;
}
}
__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(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.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[CommonAPISubmoduleDependency(new string[] { "ProtoRegistry", "CustomDescSystem", "UtilSystem" })]
[CommonAPISubmoduleDependency(new string[] { "LocalizationModule", "CustomDescSystem", "UtilSystem" })]
[BepInProcess("DSPGAME.exe")]
public class ColliderPhotons : BaseUnityPlugin
{
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"ColliderPhotons initializing 1.0");
LDBTool.PreAddDataAction = (Action)Delegate.Combine(LDBTool.PreAddDataAction, new Action(addLang));
LDBTool.PreAddDataAction = (Action)Delegate.Combine(LDBTool.PreAddDataAction, new Action(GenRegistryPhotons));
}
private void addLang()
{
LocalizationModule.RegisterTranslation("colliderphotons", "Critical Photon");
LocalizationModule.RegisterTranslation("colliderphotonsdesc", "Critical Photons can be made in our Particle Colliders, it just takes a while.");
((BaseUnityPlugin)this).Logger.LogInfo((object)"ColliderPhotons preadd");
}
private void GenRegistryPhotons()
{
ProtoRegistry.RegisterRecipe(5000, (ERecipeType)5, 99, new int[1] { 1120 }, new int[1] { 2 }, new int[1] { 1208 }, new int[1] { 1 }, "colliderphotonsdesc", 1506, 1808);
}
}
}