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 CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using xiaoye97;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ProliferatorMk4;
[BepInPlugin("com.komonad.dsp.proliferatormk4", "Proliferator Mk.IV", "0.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[CommonAPISubmoduleDependency(new string[] { "LocalizationModule", "ProtoRegistry" })]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch]
private static class GameDataPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(GameData), "SetForNewGame")]
private static void SetForNewGamePostfix(GameData __instance)
{
EnsureMk4TechState(__instance?.history);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameData), "Import")]
private static void ImportPostfix(GameData __instance)
{
EnsureMk4TechState(__instance?.history);
}
}
[HarmonyPatch]
private static class SpraycoaterWindowPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(UISpraycoaterWindow), "RefreshSpraycoaterWindow")]
private static void RefreshSpraycoaterWindowPostfix(UISpraycoaterWindow __instance, SpraycoaterComponent spraycoater)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if (IsMk4Spraycoater(__instance.traffic, spraycoater))
{
RefreshMk4SpraycoaterTank(__instance, spraycoater);
}
}
}
[HarmonyPatch]
private static class SpraycoaterComponentPatch
{
[HarmonyPostfix]
[HarmonyPatch(typeof(SpraycoaterComponent), "InternalUpdate")]
private static void InternalUpdatePostfix(ref SpraycoaterComponent __instance, CargoTraffic _traffic, AnimData[] _animPool)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
RewriteMk4SpraycoaterVisualState(_traffic, _animPool, __instance);
}
}
[HarmonyPatch]
private static class FactoryModelPatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(FactoryModel), "LateUpdate")]
private static void LateUpdatePrefix(FactoryModel __instance)
{
ApplyPendingSpraycoaterVisualModelUpdates(__instance);
}
}
public const string ModGuid = "com.komonad.dsp.proliferatormk4";
public const string ModName = "Proliferator Mk.IV";
public const string Version = "0.1.1";
private const int DefaultItemProliferatorMk4 = 9441;
private const int DefaultRecipeProliferatorMk4 = 9441;
private const int DefaultTechProliferatorMk4 = 1998;
private const int DefaultSprayCoaterGridIndex = 2207;
private const int HiddenGridIndex = 0;
private const int MaxGridPage = 8;
private const int MaxGridRow = 7;
private const int MaxGridColumn = 14;
private const int ItemProliferatorMk3 = 1143;
private const int ItemStrangeMatter = 1127;
private const int ItemElectromagneticMatrix = 6001;
private const int ItemEnergyMatrix = 6002;
private const int ItemStructureMatrix = 6003;
private const int ItemInformationMatrix = 6004;
private const int ItemGravityMatrix = 6005;
private const int ItemUniverseMatrix = 6006;
private const int ItemSprayCoater = 2313;
private const int ModelSprayCoater = 120;
private const int DefaultModelSprayCoaterMk4IdleVisual = 720;
private const int DefaultModelSprayCoaterMk4ActiveVisual = 721;
private const int RecipeProliferatorMk3 = 108;
private const int RecipeSprayCoater = 109;
private const int TechProliferatorMk3 = 1153;
private const int TechSubmicroscopicQuantumEntanglement = 1305;
private const string TextProliferatorMk4Name = "ProliferatorMk4.Item.Name";
private const string TextProliferatorMk4Description = "ProliferatorMk4.Item.Description";
private const string TextProliferatorMk4RecipeDescription = "ProliferatorMk4.Recipe.Description";
private const string TextTechName = "ProliferatorMk4.Tech.HighDimensionalProliferation.Name";
private const string TextTechDescription = "ProliferatorMk4.Tech.Description";
private const string TextTechConclusion = "ProliferatorMk4.Tech.Conclusion";
private const string IconProliferatorMk4 = "Assets/texpack/proliferator-mk4";
private const string IconProliferatorMk4Tech = "Assets/texpack/proliferator-mk4-tech";
private const int Mk4SpraycoaterVisualAbility = 4;
private static readonly Color Mk4SprayTankColor = new Color(0.3f, 0.07f, 0.46f, 0.88f);
private static readonly Color Mk4SprayBgColor = new Color(0.08f, 0.03f, 0.14f, 0.76f);
private static readonly Color Mk4SprayBrightColor = new Color(0.52f, 0.18f, 0.74f, 1f);
private static readonly Color Mk4ModelBodyColor = new Color(0.36f, 0.08f, 0.52f, 1f);
private static readonly Color Mk4ModelWaterColor = new Color(0.42f, 0.1f, 0.6f, 0.86f);
private static readonly Color Mk4ModelGlowColor = new Color(0.72f, 0.24f, 0.95f, 1f);
private static readonly Color Mk4ModelGlowOffColor = new Color(0f, 0f, 0f, 0f);
private static readonly HashSet<long> Mk4SpraycoaterEntities = new HashSet<long>();
private static readonly object Mk4SpraycoaterEntitiesLock = new object();
private static readonly Dictionary<long, int> PendingSpraycoaterVisualModelUpdates = new Dictionary<long, int>();
private static readonly object PendingSpraycoaterVisualModelUpdatesLock = new object();
private static readonly HashSet<int> ReservedModelIds = new HashSet<int>();
private static readonly FieldInfo ModelProtoColliderPathField = AccessTools.Field(typeof(ModelProto), "_colliderPath");
private static readonly FieldInfo ModelProtoRuinPathField = AccessTools.Field(typeof(ModelProto), "<_ruinPath>k__BackingField");
private static readonly FieldInfo ModelProtoWreckagePathField = AccessTools.Field(typeof(ModelProto), "<_wreckagePath>k__BackingField");
private static readonly FieldInfo ModelProtoRuinOriginModelIndexField = AccessTools.Field(typeof(ModelProto), "<_ruinOriginModelIndex>k__BackingField");
private static readonly MethodInfo GameMainCreateGPUInstancingMethod = AccessTools.Method(typeof(GameMain), "CreateGPUInstancing", (Type[])null, (Type[])null);
private static readonly MethodInfo GameMainCreateBPGPUInstancingMethod = AccessTools.Method(typeof(GameMain), "CreateBPGPUInstancing", (Type[])null, (Type[])null);
private static readonly MethodInfo GameMainCreateStarmapGPUInstancingMethod = AccessTools.Method(typeof(GameMain), "CreateStarmapGPUInstancing", (Type[])null, (Type[])null);
private static int _itemProliferatorMk4 = 9441;
private static int _modelSprayCoaterMk4IdleVisual = 720;
private static int _modelSprayCoaterMk4ActiveVisual = 721;
private static int _techProliferatorMk3;
private static int _techProliferatorMk4 = 1998;
private static bool _visualModelSwitchDisabled;
private void Awake()
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"Proliferator Mk.IV loaded.");
RegisterLocalizations();
LDBTool.PreAddDataAction = (Action)Delegate.Combine(LDBTool.PreAddDataAction, new Action(RegisterProtos));
LDBTool.PostAddDataAction = (Action)Delegate.Combine(LDBTool.PostAddDataAction, new Action(PostAddData));
new Harmony("com.komonad.dsp.proliferatormk4").PatchAll();
}
private void OnDestroy()
{
LDBTool.PreAddDataAction = (Action)Delegate.Remove(LDBTool.PreAddDataAction, new Action(RegisterProtos));
LDBTool.PostAddDataAction = (Action)Delegate.Remove(LDBTool.PostAddDataAction, new Action(PostAddData));
}
private void RegisterProtos()
{
ReservedModelIds.Clear();
ItemProto val = CreateProliferatorMk4Item();
LDBTool.PreAddProto((Proto)(object)val);
_itemProliferatorMk4 = ((Proto)val).ID;
RegisterMk4BeltItemColor(((Proto)val).ID);
ModelProto val2 = CreateMk4SprayCoaterVisualModel(720, activeGlow: false);
if (val2 != null)
{
LDBTool.PreAddProto((Proto)(object)val2);
_modelSprayCoaterMk4IdleVisual = ((Proto)val2).ID;
}
else
{
_modelSprayCoaterMk4IdleVisual = 0;
}
ModelProto val3 = CreateMk4SprayCoaterVisualModel(721, activeGlow: true);
if (val3 != null)
{
LDBTool.PreAddProto((Proto)(object)val3);
_modelSprayCoaterMk4ActiveVisual = ((Proto)val3).ID;
}
else
{
_modelSprayCoaterMk4ActiveVisual = 0;
}
RecipeProto val4 = CreateProliferatorMk4Recipe(((Proto)val).ID);
LDBTool.PreAddProto((Proto)(object)val4);
if (val.GridIndex == 0 || val4.GridIndex == 0)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)$"Could not find a safe spray-coater-page grid slot for Proliferator Mk.IV. itemGrid={val.GridIndex}, recipeGrid={val4.GridIndex}");
}
TechProto val5 = CreateProliferatorMk4Tech(((Proto)val4).ID);
LDBTool.PreAddProto((Proto)(object)val5);
_techProliferatorMk4 = ((Proto)val5).ID;
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Registered Proliferator Mk.IV protos: item={0}, recipe={1}, tech={2}, itemGrid={3}, recipeGrid={4}, sprayCoaterIdleVisualModel={5}, sprayCoaterActiveVisualModel={6}, prereqs={7}, mk3Tech={8}", ((Proto)val).ID, ((Proto)val4).ID, ((Proto)val5).ID, val.GridIndex, val4.GridIndex, _modelSprayCoaterMk4IdleVisual, _modelSprayCoaterMk4ActiveVisual, string.Join(",", val5.PreTechs), _techProliferatorMk3));
}
private static void RegisterLocalizations()
{
LocalizationModule.RegisterTranslation("ProliferatorMk4.Item.Name", "Proliferator Mk.IV", "增产剂 Mk.IV", "");
LocalizationModule.RegisterTranslation("ProliferatorMk4.Item.Description", "Compared to Proliferator Mk.III, Proliferator Mk.IV uses the negative gravitational pressure of Strange Matter to constrain its active ingredients at a higher density. When cargo sprayed with Proliferator Mk.IV is used as raw materials to produce the next-level products, the extra products or production speedup effect can be further improved. However, power consumption will increase, and it requires a more sufficient supply of raw materials.", "在增产剂MK.III的基础上,利用奇异物质的引力负压特性对有效成分进行更高密度的约束。喷涂了增产剂MK.IV后的货物作为原材料生产下一级产物时,额外产出或者加速生产产物的效果能够进一步提升,同时整个生产过程的耗电量也会进一步提高,对原料供应提出了更高的要求。", "");
LocalizationModule.RegisterTranslation("ProliferatorMk4.Recipe.Description", "Uses Strange Matter's negative gravitational pressure to further compress the active ingredients of Proliferator Mk.III.", "利用奇异物质的引力负压,对增产剂MK.III的有效成分进行进一步压缩。", "");
LocalizationModule.RegisterTranslation("ProliferatorMk4.Tech.HighDimensionalProliferation.Name", "Proliferator Mk.IV", "增产剂 Mk.IV", "");
LocalizationModule.RegisterTranslation("ProliferatorMk4.Tech.Description", "Strange Matter carries negative gravitational pressure that can warp the space around it. By using this property to constrain the active ingredients of Proliferators at a higher density, Proliferator Mk.IV has been invented. It provides a more significant extra products or production speedup effect, though it also puts higher requirements on production line design.", "奇异物质本身具有的引力负压能够使周围空间发生翘曲。利用这一特性对增产剂的有效成分进行更高密度的约束后,增产剂MK.IV诞生了。它的增产效果更明显,当然对产线设计也提出了更高的要求。", "");
LocalizationModule.RegisterTranslation("ProliferatorMk4.Tech.Conclusion", "You've unlocked the \\zcj4-;. Using the Proliferator Mk.IV to coat cargo before using it as raw materials for next-level product manufacturing will further increase the yield of extra products or the production speedup effect. This also means that a more sufficient supply of raw materials and cargo overflow prevention are required.", "你解锁了\\zcj4-;,喷涂后的货物作为原材料生产下一级产物时,能够进一步增加产物的额外产出或者加速生产的效率,这也意味着需要保证更充足的原料供应以及防止货物堆叠。", "");
}
private void PostAddData()
{
RefreshProtoLinks();
RefreshPrefabDescCaches();
AddMk4ToSprayCoater();
}
private static ItemProto CreateProliferatorMk4Item()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
ItemProto val = new ItemProto();
((Proto)val).ID = 9441;
((Proto)val).Name = "ProliferatorMk4.Item.Name";
val.Description = "ProliferatorMk4.Item.Description";
val.IconPath = "Assets/texpack/proliferator-mk4";
val.IconTag = "zcj4";
val.GridIndex = ResolveFreeItemGridIndex(((ProtoSet<ItemProto>)(object)LDB.items)?.dataArray);
val.StackSize = 200;
val.Type = (EItemType)2;
val.DescFields = new int[6] { 29, 41, 42, 43, 1, 40 };
val.FuelType = 0;
val.HeatValue = 0L;
val.ReactorInc = 0f;
val.IsFluid = false;
val.Productive = true;
val.SubID = 0;
val.MiningFrom = string.Empty;
val.ProduceFrom = string.Empty;
val.Grade = 0;
val.Upgrades = Array.Empty<int>();
val.IsEntity = false;
val.CanBuild = false;
val.BuildInGas = false;
val.ModelIndex = 0;
val.ModelCount = 0;
val.HpMax = 120;
val.Ability = 8;
val.Potential = 0L;
val.BuildIndex = 0;
val.BuildMode = 0;
val.UnlockKey = 0;
val.MechaMaterialID = 0;
val.AmmoType = (EAmmoType)0;
val.BombType = (EBombType)0;
val.CraftType = 0;
val.DropRate = 0f;
val.EnemyDropLevel = 0;
val.EnemyDropRange = Vector2.zero;
val.EnemyDropCount = 0f;
val.EnemyDropMask = 0;
val.EnemyDropMaskRatio = 0f;
return val;
}
private static RecipeProto CreateProliferatorMk4Recipe(int itemProliferatorMk4)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
RecipeProto val = new RecipeProto();
((Proto)val).ID = 9441;
((Proto)val).Name = "ProliferatorMk4.Item.Name";
val.Description = "ProliferatorMk4.Recipe.Description";
val.IconPath = "Assets/texpack/proliferator-mk4";
val.IconTag = "zcj4";
val.Type = (ERecipeType)4;
val.GridIndex = ResolveFreeRecipeGridIndex(((ProtoSet<RecipeProto>)(object)LDB.recipes)?.dataArray);
val.TimeSpend = 240;
val.Items = new int[2] { 1143, 1127 };
val.ItemCounts = new int[2] { 2, 1 };
val.Results = new int[1] { itemProliferatorMk4 };
val.ResultCounts = new int[1] { 1 };
val.Explicit = false;
val.Handcraft = false;
val.NonProductive = false;
return val;
}
private static TechProto CreateProliferatorMk4Tech(int recipeProliferatorMk4)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
int num = (_techProliferatorMk3 = ResolveMk3ProliferatorTechId());
int[] preTechs = ((num <= 0 || num == 1305) ? new int[1] { 1305 } : new int[2] { 1305, num });
TechProto val = new TechProto();
((Proto)val).ID = 1998;
((Proto)val).Name = "ProliferatorMk4.Tech.HighDimensionalProliferation.Name";
val.Desc = "ProliferatorMk4.Tech.Description";
val.Conclusion = "ProliferatorMk4.Tech.Conclusion";
val.IconPath = "Assets/texpack/proliferator-mk4-tech";
val.IconTag = "zcj4";
val.IsHiddenTech = false;
val.PreItem = Array.Empty<int>();
val.Position = new Vector2(57f, -11f);
val.PreTechs = preTechs;
val.PreTechsImplicit = Array.Empty<int>();
val.Items = new int[5] { 6001, 6002, 6003, 6004, 6005 };
val.ItemPoints = new int[5] { 1, 1, 1, 1, 1 };
val.HashNeeded = 3600000L;
val.UnlockRecipes = new int[1] { recipeProliferatorMk4 };
val.UnlockFunctions = Array.Empty<int>();
val.UnlockValues = Array.Empty<double>();
val.Published = true;
val.Level = 0;
val.MaxLevel = 0;
val.LevelCoef1 = 0;
val.LevelCoef2 = 0;
val.IsLabTech = true;
val.PreTechsMax = false;
val.AddItems = Array.Empty<int>();
val.AddItemCounts = Array.Empty<int>();
val.PropertyOverrideItems = Array.Empty<int>();
val.PropertyItemCounts = Array.Empty<int>();
return val;
}
private static int ResolveMk3ProliferatorTechId()
{
RecipeProto val = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(108);
if (val?.preTech != null)
{
return ((Proto)val.preTech).ID;
}
return ((Proto)(((IEnumerable<TechProto>)((ProtoSet<TechProto>)(object)LDB.techs).dataArray).FirstOrDefault((Func<TechProto, bool>)((TechProto proto) => proto != null && proto.UnlockRecipes != null && proto.UnlockRecipes.Contains(108)))?)).ID ?? 1153;
}
private static int ResolveFreeItemGridIndex(ItemProto[] dataArray)
{
ItemProto[] source = dataArray?.Where((ItemProto proto) => proto != null).ToArray() ?? Array.Empty<ItemProto>();
return ResolveFreeGridIndexOnSamePage(anchorGridIndex: ((IEnumerable<ItemProto>)source).FirstOrDefault((Func<ItemProto, bool>)((ItemProto proto) => ((Proto)proto).ID == 2313))?.GridIndex ?? 2207, occupiedGridIndices: source.Select((ItemProto proto) => proto.GridIndex));
}
private static int ResolveFreeRecipeGridIndex(RecipeProto[] dataArray)
{
RecipeProto[] source = dataArray?.Where((RecipeProto proto) => proto != null).ToArray() ?? Array.Empty<RecipeProto>();
return ResolveFreeGridIndexOnSamePage(anchorGridIndex: ((IEnumerable<RecipeProto>)source).FirstOrDefault((Func<RecipeProto, bool>)((RecipeProto proto) => ((Proto)proto).ID == 109))?.GridIndex ?? 2207, occupiedGridIndices: source.Select((RecipeProto proto) => proto.GridIndex));
}
private static int ResolveFreeGridIndexOnSamePage(IEnumerable<int> occupiedGridIndices, int anchorGridIndex)
{
HashSet<int> hashSet = new HashSet<int>((occupiedGridIndices ?? Enumerable.Empty<int>()).Where(IsValidGridIndex));
List<int> list = new List<int>();
if (!TryDecodeGridIndex(anchorGridIndex, out var page, out var row, out var column) && !TryDecodeGridIndex(2207, out page, out row, out column))
{
return 0;
}
for (int i = column + 1; i <= 14; i++)
{
AddGridCandidate(list, ToGridIndex(page, row, i));
}
for (int num = column - 1; num >= 1; num--)
{
AddGridCandidate(list, ToGridIndex(page, row, num));
}
for (int j = row + 1; j <= 7; j++)
{
AddGridRowCandidates(list, page, j);
}
for (int num2 = row - 1; num2 >= 1; num2--)
{
AddGridRowCandidates(list, page, num2);
}
foreach (int item in list)
{
if (!hashSet.Contains(item))
{
return item;
}
}
return 0;
}
private static void AddGridRowCandidates(List<int> candidates, int page, int row)
{
for (int i = 1; i <= 14; i++)
{
AddGridCandidate(candidates, ToGridIndex(page, row, i));
}
}
private static void AddGridCandidate(List<int> candidates, int gridIndex)
{
if (IsValidGridIndex(gridIndex) && !candidates.Contains(gridIndex))
{
candidates.Add(gridIndex);
}
}
private static bool IsValidGridIndex(int gridIndex)
{
int page;
int row;
int column;
return TryDecodeGridIndex(gridIndex, out page, out row, out column);
}
private static bool TryDecodeGridIndex(int gridIndex, out int page, out int row, out int column)
{
page = gridIndex / 1000;
row = gridIndex % 1000 / 100;
column = gridIndex % 100;
if (page >= 1 && page <= 8 && row >= 1 && row <= 7 && column >= 1)
{
return column <= 14;
}
return false;
}
private static int ToGridIndex(int page, int row, int column)
{
return page * 1000 + row * 100 + column;
}
private static void RegisterMk4BeltItemColor(int itemId)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
Dictionary<int, IconDesc> obj = (Dictionary<int, IconDesc>)AccessTools.Field(typeof(ProtoRegistry), "itemIconDescs").GetValue(null);
IconDesc value = new IconDesc
{
faceColor = new Color(0.56f, 0.17f, 0.7f, 1f),
sideColor = new Color(0.23f, 0.055f, 0.34f, 1f),
faceEmission = new Color(0.18f, 0.035f, 0.25f, 1f),
sideEmission = new Color(0.055f, 0.005f, 0.095f, 1f),
iconEmission = Color.clear,
metallic = 0.92f,
smoothness = 0.62f,
solidAlpha = 1f,
iconAlpha = 0f
};
obj[itemId] = value;
}
private static ModelProto CreateMk4SprayCoaterVisualModel(int preferredModelId, bool activeGlow)
{
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected O, but got Unknown
ModelProto val = ((ProtoSet<ModelProto>)(object)LDB.models).Select(120);
if (val == null || val.prefabDesc == null)
{
return null;
}
int num = ResolveFreeModelId(preferredModelId);
if (num <= 0)
{
return null;
}
PrefabDesc prefabDesc = val.prefabDesc;
GameObject val2 = (((Object)(object)prefabDesc.prefab != (Object)null) ? prefabDesc.prefab : Resources.Load<GameObject>(val.PrefabPath));
GameObject val3 = (((Object)(object)prefabDesc.colliderPrefab != (Object)null) ? prefabDesc.colliderPrefab : Resources.Load<GameObject>(GetModelProtoColliderPath(val)));
if ((Object)(object)val2 == (Object)null)
{
return null;
}
ModelProto val4 = CopyModelProto(val);
((Proto)val4).ID = num;
((Proto)val4).Name = num.ToString();
((Proto)val4).SID = string.Empty;
((Proto)val4).sid = string.Empty;
val4.prefabDesc = (((Object)(object)val3 == (Object)null) ? new PrefabDesc(num, val2) : new PrefabDesc(num, val2, val3));
CopyPrefabDescPublicFields(prefabDesc, val4.prefabDesc);
val4.prefabDesc.modelIndex = num;
val4.prefabDesc.prefab = val2;
val4.prefabDesc.colliderPrefab = val3;
val4.prefabDesc.incItemId = prefabDesc.incItemId?.ToArray();
val4.prefabDesc.lodMaterials = CloneMaterialMatrix(prefabDesc.lodMaterials);
val4.prefabDesc.lodBlueprintMaterials = CloneMaterialMatrix(prefabDesc.lodBlueprintMaterials);
ApplyMk4SprayCoaterModelColors(val4.prefabDesc, activeGlow);
return val4;
}
private static int ResolveFreeModelId(int preferred)
{
ModelProto[] array = ((ProtoSet<ModelProto>)(object)LDB.models)?.dataArray;
if (array == null || array.Length == 0)
{
return preferred;
}
HashSet<int> hashSet = new HashSet<int>(from proto in array
where proto != null
select ((Proto)proto).ID);
hashSet.UnionWith(ReservedModelIds);
int num = array.Length + 64;
if (preferred > 0 && preferred <= num && !hashSet.Contains(preferred))
{
ReservedModelIds.Add(preferred);
return preferred;
}
for (int num2 = num; num2 > 0; num2--)
{
if (!hashSet.Contains(num2))
{
ReservedModelIds.Add(num2);
return num2;
}
}
return 0;
}
private static ModelProto CopyModelProto(ModelProto source)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: 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_0095: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Expected O, but got Unknown
ModelProto val = new ModelProto
{
ID = ((Proto)source).ID,
Name = ((Proto)source).Name,
SID = ((Proto)source).SID,
OverrideName = source.OverrideName,
Order = source.Order,
ObjectType = source.ObjectType,
RuinType = source.RuinType,
RendererType = source.RendererType,
RotSymmetry = source.RotSymmetry,
HpMax = source.HpMax,
HpUpgrade = source.HpUpgrade,
HpRecover = source.HpRecover,
RuinId = source.RuinId,
RuinCount = source.RuinCount,
RuinLifeTime = source.RuinLifeTime,
PrefabPath = source.PrefabPath,
meshBounds = source.meshBounds
};
SetModelProtoColliderPath(val, GetModelProtoColliderPath(source));
CopyModelProtoPrivateRuntimeFields(source, val);
return val;
}
private static string GetModelProtoColliderPath(ModelProto model)
{
if (model == null)
{
return string.Empty;
}
return model.ColliderPath ?? ((string)ModelProtoColliderPathField?.GetValue(model)) ?? string.Empty;
}
private static void SetModelProtoColliderPath(ModelProto model, string colliderPath)
{
if (model != null && ModelProtoColliderPathField != null)
{
ModelProtoColliderPathField.SetValue(model, colliderPath ?? string.Empty);
}
}
private static void CopyModelProtoPrivateRuntimeFields(ModelProto source, ModelProto target)
{
CopyFieldValue(ModelProtoRuinPathField, source, target);
CopyFieldValue(ModelProtoWreckagePathField, source, target);
CopyFieldValue(ModelProtoRuinOriginModelIndexField, source, target);
}
private static void CopyFieldValue(FieldInfo field, object source, object target)
{
if (field != null && source != null && target != null)
{
field.SetValue(target, field.GetValue(source));
}
}
private static void CopyPrefabDescPublicFields(PrefabDesc source, PrefabDesc target)
{
FieldInfo[] fields = typeof(PrefabDesc).GetFields(BindingFlags.Instance | BindingFlags.Public);
foreach (FieldInfo fieldInfo in fields)
{
fieldInfo.SetValue(target, fieldInfo.GetValue(source));
}
}
private static Material[][] CloneMaterialMatrix(Material[][] source)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
if (source == null)
{
return null;
}
Material[][] array = new Material[source.Length][];
for (int i = 0; i < source.Length; i++)
{
if (source[i] != null)
{
array[i] = (Material[])(object)new Material[source[i].Length];
for (int j = 0; j < source[i].Length; j++)
{
array[i][j] = (((Object)(object)source[i][j] == (Object)null) ? ((Material)null) : new Material(source[i][j]));
}
}
}
return array;
}
private static void ApplyMk4SprayCoaterModelColors(PrefabDesc prefabDesc, bool activeGlow)
{
ApplyMk4SprayCoaterMaterialColors(prefabDesc.lodMaterials, activeGlow);
ApplyMk4SprayCoaterMaterialColors(prefabDesc.lodBlueprintMaterials, activeGlow);
}
private static void ApplyMk4SprayCoaterMaterialColors(Material[][] lodMaterials, bool activeGlow)
{
if (lodMaterials == null)
{
return;
}
foreach (Material[] array in lodMaterials)
{
if (array != null)
{
Material[] array2 = array;
for (int j = 0; j < array2.Length; j++)
{
ApplyMk4SprayCoaterMaterialColors(array2[j], activeGlow);
}
}
}
}
private static void ApplyMk4SprayCoaterMaterialColors(Material material, bool activeGlow)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: 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)
if (!((Object)(object)material == (Object)null))
{
bool flag = ((((Object)material).name == null) ? string.Empty : ((Object)material).name.ToLowerInvariant()).Contains("effect");
Color val = (activeGlow ? Mk4ModelGlowColor : Mk4ModelGlowOffColor);
if (material.HasProperty("_Color4"))
{
material.SetColor("_Color4", flag ? val : Mk4ModelWaterColor);
}
if (material.HasProperty("_Color2"))
{
material.SetColor("_Color2", activeGlow ? Mk4ModelBodyColor : Mk4ModelGlowOffColor);
}
if (flag && material.HasProperty("_TintColor"))
{
material.SetColor("_TintColor", val);
}
}
}
private static void RefreshProtoLinks()
{
((ProtoSet<ModelProto>)(object)LDB.models).OnAfterDeserialize();
ModelProto.InitMaxModelIndex();
ModelProto.InitModelIndices();
ModelProto.InitModelOrders();
((ProtoSet<ItemProto>)(object)LDB.items).OnAfterDeserialize();
((ProtoSet<RecipeProto>)(object)LDB.recipes).OnAfterDeserialize();
((ProtoSet<TechProto>)(object)LDB.techs).OnAfterDeserialize();
TechProto[] dataArray = ((ProtoSet<TechProto>)(object)LDB.techs).dataArray;
foreach (TechProto val in dataArray)
{
if (val != null)
{
val.Preload();
}
}
for (int j = 0; j < ((ProtoSet<ItemProto>)(object)LDB.items).dataArray.Length; j++)
{
ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray[j];
if (val2 != null)
{
val2.recipes = null;
val2.rawMats = null;
val2.Preload(j);
}
}
for (int k = 0; k < ((ProtoSet<RecipeProto>)(object)LDB.recipes).dataArray.Length; k++)
{
RecipeProto val3 = ((ProtoSet<RecipeProto>)(object)LDB.recipes).dataArray[k];
if (val3 != null)
{
val3.Preload(k);
}
}
dataArray = ((ProtoSet<TechProto>)(object)LDB.techs).dataArray;
foreach (TechProto val4 in dataArray)
{
if (val4 != null)
{
val4.PreTechsImplicit = (val4.PreTechsImplicit ?? Array.Empty<int>()).Except(val4.PreTechs ?? Array.Empty<int>()).ToArray();
val4.UnlockRecipes = (val4.UnlockRecipes ?? Array.Empty<int>()).Distinct().ToArray();
val4.Preload2();
}
}
}
private static void RefreshPrefabDescCaches()
{
PlanetFactory.PrefabDescByModelIndex = null;
PlanetFactory.InitPrefabDescArray();
SpaceSector.PrefabDescByModelIndex = null;
SpaceSector.InitPrefabDescArray();
if (!((Object)(object)GameMain.instance == (Object)null))
{
InvokeGameMainMethod(GameMainCreateGPUInstancingMethod);
InvokeGameMainMethod(GameMainCreateBPGPUInstancingMethod);
InvokeGameMainMethod(GameMainCreateStarmapGPUInstancingMethod);
}
}
private static void InvokeGameMainMethod(MethodInfo method)
{
if (method != null)
{
method.Invoke(GameMain.instance, null);
}
}
private void AddMk4ToSprayCoater()
{
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(2313);
if (val == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find spray coater item proto.");
return;
}
bool flag = false;
flag |= AddIncItem(val.prefabDesc);
ModelProto val2 = ((ProtoSet<ModelProto>)(object)LDB.models).Select(val.ModelIndex);
if (val2 != null)
{
flag |= AddIncItem(val2.prefabDesc);
}
if (PlanetFactory.PrefabDescByModelIndex != null && val.ModelIndex >= 0 && val.ModelIndex < PlanetFactory.PrefabDescByModelIndex.Length)
{
flag |= AddIncItem(PlanetFactory.PrefabDescByModelIndex[val.ModelIndex]);
}
flag |= AddMk4ToSprayCoaterVisualModel(_modelSprayCoaterMk4IdleVisual);
flag |= AddMk4ToSprayCoaterVisualModel(_modelSprayCoaterMk4ActiveVisual);
((BaseUnityPlugin)this).Logger.LogInfo((object)(flag ? $"Spray coater now accepts item {_itemProliferatorMk4}." : $"Spray coater already accepted item {_itemProliferatorMk4}."));
}
private static bool AddMk4ToSprayCoaterVisualModel(int modelIndex)
{
if (modelIndex <= 0)
{
return false;
}
bool flag = false;
ModelProto val = ((ProtoSet<ModelProto>)(object)LDB.models).Select(modelIndex);
if (val != null)
{
flag |= AddIncItem(val.prefabDesc);
}
if (PlanetFactory.PrefabDescByModelIndex != null && modelIndex < PlanetFactory.PrefabDescByModelIndex.Length)
{
flag |= AddIncItem(PlanetFactory.PrefabDescByModelIndex[modelIndex]);
}
return flag;
}
private static bool AddIncItem(PrefabDesc prefabDesc)
{
if (prefabDesc == null || prefabDesc.incItemId == null)
{
return false;
}
if (prefabDesc.incItemId.Contains(_itemProliferatorMk4))
{
return false;
}
prefabDesc.incItemId = prefabDesc.incItemId.Concat(new int[1] { _itemProliferatorMk4 }).ToArray();
return true;
}
private static bool IsMk4Spraycoater(CargoTraffic traffic, SpraycoaterComponent spraycoater)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: 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_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
int num = Math.Max(0, spraycoater.incCount) + Math.Max(0, spraycoater.extraIncCount);
long spraycoaterKey = GetSpraycoaterKey(traffic?.factory, spraycoater.entityId);
lock (Mk4SpraycoaterEntitiesLock)
{
if (spraycoater.incItemId == _itemProliferatorMk4)
{
if (num > 0)
{
Mk4SpraycoaterEntities.Add(spraycoaterKey);
}
return true;
}
if (num <= 0 || spraycoater.incItemId != 0)
{
Mk4SpraycoaterEntities.Remove(spraycoaterKey);
return false;
}
return Mk4SpraycoaterEntities.Contains(spraycoaterKey);
}
}
private static long GetSpraycoaterKey(PlanetFactory factory, int entityId)
{
return ((long)((factory != null) ? factory.index : 0) << 32) | (uint)entityId;
}
private static void RewriteMk4SpraycoaterVisualState(CargoTraffic traffic, AnimData[] animPool, SpraycoaterComponent spraycoater)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
bool flag = IsMk4Spraycoater(traffic, spraycoater);
bool isSpraying = IsSpraycoaterVisualActive(animPool, spraycoater.entityId);
QueueSpraycoaterVisualModelUpdate(traffic?.factory, spraycoater.entityId, ResolveSpraycoaterVisualModelIndex(flag, isSpraying));
if (flag && animPool != null && spraycoater.entityId > 0 && spraycoater.entityId < animPool.Length)
{
uint state = animPool[spraycoater.entityId].state;
uint num = state % 1000;
uint num2 = state - num;
uint num3 = num % 10;
uint num4 = ((num >= 100) ? 100u : 0u);
animPool[spraycoater.entityId].state = num2 + num3 + num4 + 40;
}
}
private static bool IsSpraycoaterVisualActive(AnimData[] animPool, int entityId)
{
if (animPool == null || entityId <= 0 || entityId >= animPool.Length)
{
return false;
}
uint state = animPool[entityId].state;
if (state / 1000 == 0)
{
return state % 1000 >= 100;
}
return true;
}
private static int ResolveSpraycoaterVisualModelIndex(bool isMk4, bool isSpraying)
{
if (!isMk4)
{
return 120;
}
if (isSpraying && _modelSprayCoaterMk4ActiveVisual > 0)
{
return _modelSprayCoaterMk4ActiveVisual;
}
if (_modelSprayCoaterMk4IdleVisual <= 0)
{
return _modelSprayCoaterMk4ActiveVisual;
}
return _modelSprayCoaterMk4IdleVisual;
}
private static void QueueSpraycoaterVisualModelUpdate(PlanetFactory factory, int entityId, int targetModelIndex)
{
if (_visualModelSwitchDisabled || targetModelIndex <= 0 || factory == null || entityId <= 0)
{
return;
}
long spraycoaterKey = GetSpraycoaterKey(factory, entityId);
lock (PendingSpraycoaterVisualModelUpdatesLock)
{
PendingSpraycoaterVisualModelUpdates[spraycoaterKey] = targetModelIndex;
}
}
private static void ApplyPendingSpraycoaterVisualModelUpdates(FactoryModel factoryModel)
{
PlanetFactory val = factoryModel?.planet?.factory;
GPUInstancingManager val2 = factoryModel?.gpuiManager;
if (_visualModelSwitchDisabled || val?.entityPool == null || val2 == null)
{
return;
}
List<KeyValuePair<int, int>> list = null;
lock (PendingSpraycoaterVisualModelUpdatesLock)
{
KeyValuePair<long, int>[] array = PendingSpraycoaterVisualModelUpdates.ToArray();
for (int i = 0; i < array.Length; i++)
{
KeyValuePair<long, int> keyValuePair = array[i];
if ((int)(keyValuePair.Key >> 32) == val.index)
{
if (list == null)
{
list = new List<KeyValuePair<int, int>>();
}
list.Add(new KeyValuePair<int, int>((int)keyValuePair.Key, keyValuePair.Value));
PendingSpraycoaterVisualModelUpdates.Remove(keyValuePair.Key);
}
}
}
if (list == null)
{
return;
}
foreach (KeyValuePair<int, int> item in list)
{
ApplySpraycoaterVisualModel(val, val2, item.Key, item.Value);
}
}
private static void ApplySpraycoaterVisualModel(PlanetFactory factory, GPUInstancingManager gpuiManager, int entityId, int targetModelIndex)
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
if (factory?.entityPool == null || gpuiManager == null || targetModelIndex <= 0 || entityId <= 0 || entityId >= factory.entityPool.Length)
{
return;
}
ref EntityData reference = ref factory.entityPool[entityId];
if (reference.id != entityId)
{
return;
}
int modelIndex = reference.modelIndex;
if (modelIndex == targetModelIndex || !IsSpraycoaterVisualModelIndex(modelIndex) || !IsSpraycoaterVisualModelIndex(targetModelIndex))
{
return;
}
try
{
int num = gpuiManager.AddModel(targetModelIndex, reference.id, reference.pos, reference.rot, true);
if (num > 0)
{
if (reference.modelId > 0)
{
gpuiManager.RemoveModel(modelIndex, reference.modelId, true);
}
reference.modelIndex = (short)targetModelIndex;
reference.modelId = num;
}
}
catch (Exception arg)
{
_visualModelSwitchDisabled = true;
lock (PendingSpraycoaterVisualModelUpdatesLock)
{
PendingSpraycoaterVisualModelUpdates.Clear();
}
Debug.LogWarning((object)$"Proliferator Mk.IV disabled spray coater model switching after renderer error: {arg}");
}
}
private static bool IsSpraycoaterVisualModelIndex(int modelIndex)
{
if (modelIndex != 120 && modelIndex != _modelSprayCoaterMk4IdleVisual)
{
return modelIndex == _modelSprayCoaterMk4ActiveVisual;
}
return true;
}
private static void RefreshMk4SpraycoaterTank(UISpraycoaterWindow window, SpraycoaterComponent spraycoater)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
int num = Math.Max(0, spraycoater.incCount) + Math.Max(0, spraycoater.extraIncCount);
int num2 = Math.Max(1, spraycoater.incCapacity);
float num3 = Mathf.Clamp01((float)num / (float)num2);
float fillAmount = ((num3 > 0f && num3 < 0.01f) ? 0.01f : num3);
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(_itemProliferatorMk4);
if (val != null)
{
window.tankFillIconImage.sprite = val.iconSprite;
}
((Behaviour)window.tankFillIconImage).enabled = num > 0;
((Graphic)window.tankFillIconImage).color = Color.white;
((Graphic)window.tankFillBgImage).color = Mk4SprayBgColor;
window.tankFillOutlineImage.fillAmount = fillAmount;
((Graphic)window.tankFillOutlineImage).color = Mk4SprayBrightColor;
((Behaviour)window.tankFillMaskImage).enabled = num > 0;
((Graphic)window.tankFillMaskImage).color = Mk4SprayTankColor;
window.tankFillRectMask.anchoredPosition = new Vector2(0f, -158f + Mathf.Ceil(159f * num3));
window.tankCountText.text = Localization.Translate("增产剂储量提示") + num;
((Graphic)window.tankCountText).color = Mk4SprayBrightColor;
window.tankBtn.tips.itemId = ((num > 0) ? _itemProliferatorMk4 : 0);
SetEffectText(window.incInfoText1, "喷涂增产效果", Cargo.incTable, spraycoater.incAbility);
SetEffectText(window.incInfoText2, "喷涂加速效果", Cargo.accTable, spraycoater.incAbility);
SetEffectText(window.incInfoText3, "额外电力消耗", Cargo.powerTable, spraycoater.incAbility);
}
private static void SetEffectText(Text text, string labelKey, int[] table, int ability)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
int num = ((table != null && ability >= 0 && ability < table.Length) ? table[ability] : 0);
text.text = Localization.Translate(labelKey) + ": " + ((float)num * 0.1f).ToString("0.0") + "%";
((Graphic)text).color = Mk4SprayBrightColor;
}
private static void EnsureMk4TechState(GameHistoryData history)
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
if (history == null || history.techStates == null || history.techStates.ContainsKey(_techProliferatorMk4))
{
return;
}
TechProto val = ((ProtoSet<TechProto>)(object)LDB.techs).Select(_techProliferatorMk4);
if (val != null)
{
int num = 0;
if (val.Items != null && val.ItemPoints != null && val.Items.Length != 0 && val.ItemPoints.Length != 0 && val.Items[0] == 6006)
{
num = val.ItemPoints[0];
}
history.techStates.Add(_techProliferatorMk4, new TechState(false, val.Level, val.MaxLevel, 0L, val.GetHashNeeded(val.Level), num));
}
}
}
internal static class TextureHelper
{
private static readonly Assembly Assembly = typeof(TextureHelper).Assembly;
private static readonly Dictionary<string, Texture2D> Cache = new Dictionary<string, Texture2D>();
private static readonly Dictionary<string, Sprite> SpriteCache = new Dictionary<string, Sprite>();
internal static Texture2D GetTexture(string name)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
if (Cache.TryGetValue(name, out var value))
{
return value;
}
using Stream stream = Assembly.GetManifestResourceStream("ProliferatorMk4.assets.sprite." + name + ".png");
if (stream == null)
{
return null;
}
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
Texture2D val = new Texture2D(2, 2);
if (!ImageConversion.LoadImage(val, memoryStream.ToArray()))
{
return null;
}
((Object)val).name = name;
Cache[name] = val;
return val;
}
internal static Sprite GetSprite(string name)
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
if (SpriteCache.TryGetValue(name, out var value))
{
return value;
}
Texture2D texture = GetTexture(name);
if ((Object)(object)texture == (Object)null)
{
return null;
}
Sprite val = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0.5f, 0.5f));
SpriteCache[name] = val;
return val;
}
}
[HarmonyPatch(typeof(Resources), "Load", new Type[]
{
typeof(string),
typeof(Type)
})]
[HarmonyBefore(new string[] { "dsp.common-api.CommonAPI" })]
internal static class TextureResourcesPatch
{
private const string TexpackPrefix = "Assets/texpack/";
private static bool Prefix(ref string path, Type systemTypeInstance, ref Object __result)
{
if (!path.StartsWith("Assets/texpack/", StringComparison.Ordinal))
{
return true;
}
string name = path.Substring("Assets/texpack/".Length);
if (systemTypeInstance == typeof(Texture2D))
{
__result = (Object)(object)TextureHelper.GetTexture(name);
return __result == (Object)null;
}
if (systemTypeInstance == typeof(Sprite))
{
__result = (Object)(object)TextureHelper.GetSprite(name);
return __result == (Object)null;
}
return true;
}
}