Decompiled source of Fabricators v1.0.5

FabricatorStandalone.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using EntityStates;
using MonoMod.RuntimeDetour;
using On.RoR2;
using On.RoR2.Projectile;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.Audio;
using RoR2.ContentManagement;
using RoR2.Projectile;
using RoR2BepInExPack.GameAssetPathsBetter;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FabricatorStandalone")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FabricatorStandalone")]
[assembly: AssemblyTitle("FabricatorStandalone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
namespace FabricatorStandalone;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.RiskOfBrainrot.Fabricators", "Fabricators", "1.0.2")]
public class FabricatorPlugin : BaseUnityPlugin
{
	public const string guid = "com.RiskOfBrainrot.Fabricators";

	public const string teamName = "RiskOfBrainrot";

	public const string modName = "Fabricators";

	public const string version = "1.0.2";

	public static BasicPickupDropTable doubleChestDropTable;

	public static float fabricatorEjectVelocity = 1f;

	public static int fabricatorCommonFirstCost = 30;

	public static int fabricatorUncommonFirstCost = 60;

	public static int fabricatorSecondCost = 30;

	public static int doubleChestWeight = 16;

	public static float doubleChestItemDisplayTime = 5f;

	public static DirectorCard fabricatorCommonDirectorCard;

	public static InteractableSpawnCard fabricatorCommonSpawnCard;

	public static GameObject fabricatorCommonPrefab;

	public static DirectorCard fabricatorUncommonDirectorCard => fabricatorCommonDirectorCard;

	public static InteractableSpawnCard fabricatorUncommonSpawnCard => fabricatorCommonSpawnCard;

	public static GameObject fabricatorUncommonPrefab => fabricatorCommonPrefab;

	public void Awake()
	{
		//IL_0060: 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)
		LanguageAPI.Add("CASINOCHEST_NAME", "Fabricator Chest");
		LanguageAPI.Add("CASINOCHEST_CONTEXT", "Use Fabricator Chest");
		LanguageAPI.Add("CASINOCHEST_DESCRIPTION", "Costs gold to activate and will show a single item. Pay twice to get two copies of the shown item, or once to get two Scrap.");
		FabricatorPlugin.LoadAsync<GameObject>(RoR2_Base_CasinoChest.CasinoChest_prefab, (Action<GameObject>)delegate(GameObject casinoChest)
		{
			fabricatorCommonPrefab = casinoChest;
			TinkerableObjectAttributes val = casinoChest.AddComponent<TinkerableObjectAttributes>();
			val.maxTinkers = 2;
			PurchaseInteraction val2 = default(PurchaseInteraction);
			if (casinoChest.TryGetComponent<PurchaseInteraction>(ref val2))
			{
				val2.cost = fabricatorCommonFirstCost;
				val2.saleStarCompatible = false;
			}
			RouletteChestController val3 = default(RouletteChestController);
			if (casinoChest.TryGetComponent<RouletteChestController>(ref val3))
			{
				val3.dropCount = 2;
				val.indicatorOffset = val3.ejectionTransform;
			}
		});
		fabricatorCommonSpawnCard = Addressables.LoadAssetAsync<InteractableSpawnCard>((object)RoR2_Base_CasinoChest.iscCasinoChest_asset).WaitForCompletion();
		fabricatorCommonDirectorCard = DirectorCards.BuildDirectorCard(fabricatorCommonSpawnCard, doubleChestWeight, 0);
		FabricatorPlugin.LoadAsync<BasicPickupDropTable>(RoR2_Base_CasinoChest.dtCasinoChest_asset, (Action<BasicPickupDropTable>)delegate(BasicPickupDropTable dropTable)
		{
			doubleChestDropTable = dropTable;
			doubleChestDropTable.tier1Weight = 1f;
			doubleChestDropTable.tier2Weight = 0f;
			doubleChestDropTable.tier3Weight = 0f;
			doubleChestDropTable.equipmentWeight = 0f;
		});
		AddDoubleChestToStage1();
		Hooks.Init();
	}

	public static AssetReferenceT<T> LoadAsync<T>(string guid, Action<T> callback) where T : Object
	{
		//IL_0018: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		AssetReferenceT<T> val = new AssetReferenceT<T>(guid);
		AsyncOperationHandle<T> handle = AssetAsyncReferenceManager<T>.LoadAsset(val, (AsyncReferenceHandleUnloadType)2);
		if (callback == null)
		{
			return val;
		}
		if (handle.IsDone)
		{
			onCompleted(handle);
			return val;
		}
		handle.Completed += onCompleted;
		return val;
		void onCompleted(AsyncOperationHandle<T> val2)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			if (val2.Result == null || (int)val2.Status != 1)
			{
				Debug.LogError((object)$"Failed to load asset [{val2.DebugName}] : {val2.OperationException}");
			}
			else
			{
				callback(val2.Result);
			}
		}
	}

	public static void AddDoubleChestToStage1()
	{
		Helpers.AddNewInteractableToStage(fabricatorCommonDirectorCard, (InteractableCategory)2, (Stage)2, "");
		Helpers.AddNewInteractableToStage(fabricatorCommonDirectorCard, (InteractableCategory)2, (Stage)4, "");
		Helpers.AddNewInteractableToStage(fabricatorCommonDirectorCard, (InteractableCategory)2, (Stage)67108864, "");
	}
}
public static class Hooks
{
	public delegate bool orig_IsTinkerable(TinkerableObjectAttributes self);

	public static void Init()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		Hook val = new Hook((MethodBase)typeof(TinkerableObjectAttributes).GetMethod("get_IsTinkerable", (BindingFlags)(-1)), typeof(Hooks).GetMethod("DoubleChestTinkerTarget", (BindingFlags)(-1)));
		TinkerProjectile.TransmuteTargetObject += new hook_TransmuteTargetObject(DoubleChestTinker);
		Cycling.OnEnter += new hook_OnEnter(DoubleChestOnInteract);
		RouletteChestController.GetPickupForTime += new hook_GetPickupForTime(DoubleChestScrap);
		RouletteChestController.EjectPickupServer += new hook_EjectPickupServer(DoubleChestDoubleLoot);
		DirectorAPI.InteractableActions += ScrapperOccurrenceHook;
	}

	public static bool DoubleChestTinkerTarget(orig_IsTinkerable orig, TinkerableObjectAttributes self)
	{
		if (!orig(self))
		{
			return false;
		}
		RouletteChestController val = default(RouletteChestController);
		return !((Component)self).TryGetComponent<RouletteChestController>(ref val) || val.isCycling;
	}

	private static void DoubleChestTinker(orig_TransmuteTargetObject orig, TinkerProjectile self, GameObject targetObject)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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_009e: Expected O, but got Unknown
		//IL_00ae: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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)
		TinkerableObjectAttributes val = default(TinkerableObjectAttributes);
		RouletteChestController val2 = default(RouletteChestController);
		if (targetObject.TryGetComponent<TinkerableObjectAttributes>(ref val) && targetObject.TryGetComponent<RouletteChestController>(ref val2))
		{
			if (self.tinkeredObjects.Contains(targetObject))
			{
				return;
			}
			self.tinkeredObjects.Add(targetObject);
			if (val.IsTinkerable)
			{
				PointSoundManager.EmitSoundServer(self.soundEvent.index, targetObject.transform.position);
				TinkerableObjectAttributes val3 = val;
				val3.Networktinkers = val3.tinkers + 1;
				EffectData val4 = new EffectData
				{
					origin = targetObject.transform.position
				};
				EffectManager.SpawnEffect(self.effectPrefab, val4, true);
				UniquePickup pickupForTime = val2.GetPickupForTime(FixedTimeStamp.now);
				UniquePickup val5 = val2.dropTable.GeneratePickup(val2.rng);
				if (val5 == pickupForTime)
				{
					val5 = val2.dropTable.GeneratePickup(val2.rng);
				}
				val2.entries[0].pickup = val5;
				((NetworkBehaviour)val2).SetDirtyBit(RouletteChestController.entriesDirtyBit);
				val2.pickupDisplay.SetPickup(ref val5, false);
			}
		}
		else
		{
			orig.Invoke(self, targetObject);
		}
	}

	private static void ScrapperOccurrenceHook(DccsPool pool, StageInfo stageInfo)
	{
		ChangeInteractableWeightForPool(pool, InteractableNames.AdaptiveChest.ToLowerInvariant(), FabricatorPlugin.doubleChestWeight, -1);
		static void ChangeInteractableWeightForPool(DccsPool val, string interactableNameLowered, int newWeight, int maxPerStage)
		{
			if (Object.op_Implicit((Object)(object)val))
			{
				Helpers.ForEachPoolEntryInDccsPool(val, (Action<PoolEntry>)delegate(PoolEntry poolEntry)
				{
					//IL_0089: Unknown result type (might be due to invalid IL or missing references)
					for (int i = 0; i < poolEntry.dccs.categories.Length; i++)
					{
						List<DirectorCard> list = poolEntry.dccs.categories[i].cards.ToList();
						foreach (DirectorCard item in list)
						{
							SpawnCard spawnCard = item.spawnCard;
							if (((Object)spawnCard).name.ToLowerInvariant() == interactableNameLowered)
							{
								item.selectionWeight = newWeight;
								if (maxPerStage >= 0 && spawnCard is InteractableSpawnCard)
								{
									((InteractableSpawnCard)spawnCard).maxSpawnsPerStage = maxPerStage;
								}
							}
						}
						poolEntry.dccs.categories[i].cards = list.ToArray();
					}
				});
			}
		}
	}

	public static void DoubleChestDoubleLoot(orig_EjectPickupServer orig, RouletteChestController self, UniquePickup pickup)
	{
		//IL_0003: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: 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_0099: 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_00a5: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
		if (!((UniquePickup)(ref pickup)).Equals(UniquePickup.none))
		{
			Vector3 val = self.ejectionTransform.rotation * self.localEjectionVelocity;
			float num = 60f;
			float num2 = num * 2f / (float)(self.dropCount + 1);
			for (int i = 0; i < self.dropCount; i++)
			{
				float num3 = ((self.dropCount == 1) ? 0f : (num2 * (float)(i + 1) - num));
				Vector3 val2 = ((self.dropCount == 1) ? val : Util.ApplySpread(val, 0f, 0f, 1f, 1f, num3, 0f));
				PickupDropletController.CreatePickupDroplet(pickup, self.ejectionTransform.position, val2 + new Vector3(FabricatorPlugin.fabricatorEjectVelocity, 0f, 0f), false, false);
			}
		}
	}

	public static UniquePickup DoubleChestScrap(orig_GetPickupForTime orig, RouletteChestController self, FixedTimeStamp time)
	{
		//IL_005c: 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_0066: 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_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		float doubleChestItemDisplayTime = FabricatorPlugin.doubleChestItemDisplayTime;
		if (!(doubleChestItemDisplayTime > self.bonusTime))
		{
			TinkerableObjectAttributes val = default(TinkerableObjectAttributes);
			if (((Component)self).TryGetComponent<TinkerableObjectAttributes>(ref val))
			{
				val.Networktinkers = 2;
			}
			return new UniquePickup(PickupCatalog.FindPickupIndex(Items.ScrapWhite.itemIndex));
		}
		self.bonusTime += 0.01f;
		return orig.Invoke(self, time);
	}

	public static void DoubleChestOnInteract(orig_OnEnter orig, Cycling self)
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		RouletteChestController component = ((EntityState)self).gameObject.GetComponent<RouletteChestController>();
		component.maxEntries = 2;
		component.bonusTime = 3f;
		orig.Invoke(self);
		if ((Object)(object)component == (Object)null)
		{
			Debug.Log((object)"auuuuuh fuck :3");
			return;
		}
		PurchaseInteraction purchaseInteraction = component.purchaseInteraction;
		if ((Object)(object)purchaseInteraction == (Object)null)
		{
			Debug.Log((object)"purchase interaction null 3:");
			return;
		}
		purchaseInteraction.costType = (CostTypeIndex)1;
		purchaseInteraction.cost = Run.instance.GetDifficultyScaledCost(FabricatorPlugin.fabricatorSecondCost, Stage.instance.entryDifficultyCoefficient);
		purchaseInteraction.saleStarCompatible = false;
	}
}
public static class Spawnlists
{
	public static void Init()
	{
		SpawnCards.Init();
	}

	public static void AddMonsterCardToSpawnlist(DirectorCardCategorySelection categorySelection, DirectorCard directorCard, MonsterCategory monsterCategory)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected I4, but got Unknown
		categorySelection.AddCard((int)monsterCategory, directorCard);
	}
}
public static class SpawnCards
{
	public static bool initialized;

	public static void Init()
	{
		if (!initialized)
		{
			initialized = true;
			DirectorCards.Init();
		}
	}
}
public static class DirectorCards
{
	public static bool initialized;

	public static bool logCardInfo;

	public static void Init()
	{
		if (!initialized)
		{
			initialized = true;
		}
	}

	public static DirectorCard BuildDirectorCard(CharacterSpawnCard spawnCard)
	{
		return BuildDirectorCard(spawnCard, 1, 0, (MonsterSpawnDistance)0);
	}

	public static DirectorCard BuildDirectorCard(CharacterSpawnCard spawnCard, int weight, int minStages, MonsterSpawnDistance spawnDistance)
	{
		//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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: 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_002a: Expected O, but got Unknown
		return new DirectorCard
		{
			spawnCard = (SpawnCard)(object)spawnCard,
			selectionWeight = weight,
			preventOverhead = false,
			minimumStageCompletions = minStages,
			spawnDistance = spawnDistance
		};
	}

	public static DirectorCard BuildDirectorCard(InteractableSpawnCard spawnCard, int weight, int minStages)
	{
		//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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_0023: Expected O, but got Unknown
		return new DirectorCard
		{
			spawnCard = (SpawnCard)(object)spawnCard,
			selectionWeight = weight,
			preventOverhead = false,
			minimumStageCompletions = minStages
		};
	}
}