Decompiled source of ReactiveCartel Il2Cpp v1.0.0

ReactiveCartel___IL2Cpp.dll

Decompiled 18 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppFishNet;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.Cartel;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.Persistence;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ReactiveCartel;
using ReactiveCartel.Patches;
using S1API.Leveling;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "ReactiveCartel", "1.1.0", "Lumahex", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ReactiveCartel___IL2Cpp")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReactiveCartel___IL2Cpp")]
[assembly: AssemblyTitle("ReactiveCartel___IL2Cpp")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ReactiveCartel
{
	public class Core : MelonMod
	{
		private bool _initialized = false;

		public override void OnInitializeMelon()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			((MelonBase)this).LoggerInstance.Msg("Reactive Cartel Initialized.");
			Harmony val = new Harmony("ReactiveCartel");
			val.PatchAll();
			MelonLogger.Msg("Harmony Patches Applied");
		}

		public override void OnUpdate()
		{
			if (!_initialized && ReactiveCartel.Patches.ReactiveCartel.TryToInitialize())
			{
				_initialized = true;
			}
		}
	}
}
namespace ReactiveCartel.Patches
{
	public static class ReactiveCartel
	{
		public static bool GameLoaded;

		public static bool TryToInitialize()
		{
			if ((Object)(object)Singleton<LoadManager>.Instance == (Object)null)
			{
				return false;
			}
			Singleton<LoadManager>.Instance.onLoadComplete.AddListener(UnityAction.op_Implicit((Action)OnLoadComplete));
			MelonLogger.Msg("Hooked LoadManager");
			return true;
		}

		private static void OnLoadComplete()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			GameLoaded = true;
			MelonLogger.Msg("Game fully loaded");
			if (!InstanceFinder.IsServer)
			{
				return;
			}
			Il2CppArrayBase<CartelRegionActivities> val = Object.FindObjectsOfType<CartelRegionActivities>();
			foreach (CartelRegionActivities item in val)
			{
				item.HoursUntilNextActivity = CartelRegionActivities.GetNewCooldown(item.Region);
				MelonLogger.Msg($"Recalculated {item.Region}: {item.HoursUntilNextActivity} hours");
			}
		}
	}
	[HarmonyPatch(typeof(CartelRegionActivities), "GetNewCooldown")]
	public static class RegionalCooldownPatch
	{
		private static bool Prefix(EMapRegion region, ref int __result)
		{
			//IL_002d: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			if (!ReactiveCartel.GameLoaded)
			{
				return true;
			}
			if (!LevelManager.Exists)
			{
				return true;
			}
			FullRank currentRank = LevelManager.CurrentRank;
			int rankIndex = ((FullRank)(ref currentRank)).GetRankIndex();
			float num = 40f;
			float num2 = Mathf.Clamp01((float)rankIndex + 1f / num);
			float num3 = Mathf.Lerp(24f, 6f, num2);
			float num4 = Mathf.Lerp(48f, 12f, num2);
			__result = Mathf.RoundToInt(Random.Range(num3, num4));
			MelonLogger.Msg($"[ReactiveCartel] Region: {region} | RankIndex: {rankIndex} | Progress: {num2:F2} | Cooldown: {__result}h");
			return false;
		}
	}
	[HarmonyPatch(typeof(CartelRegionActivities), "TryStartActivity")]
	public static class TryStartActivity_WeightedPatch
	{
		private static bool Prefix(CartelRegionActivities __instance)
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			FullRank currentRank = LevelManager.CurrentRank;
			int rankIndex = ((FullRank)(ref currentRank)).GetRankIndex();
			__instance.HoursUntilNextActivity = CartelRegionActivities.GetNewCooldown(__instance.Region);
			List<CartelActivity> activities = __instance.Activities;
			List<CartelActivity> list = new List<CartelActivity>();
			Enumerator<CartelActivity> enumerator = activities.GetEnumerator();
			while (enumerator.MoveNext())
			{
				CartelActivity current = enumerator.Current;
				if (current.IsRegionValidForActivity(__instance.Region))
				{
					list.Add(current);
				}
			}
			if (list.Count == 0)
			{
				return false;
			}
			List<float> list2 = new List<float>();
			foreach (CartelActivity item in list)
			{
				list2.Add(GetWeight(item, rankIndex));
			}
			CartelActivity val = WeightedPick(list, list2);
			int num = activities.IndexOf(val);
			AccessTools.Method(typeof(CartelRegionActivities), "StartActivity", (Type[])null, (Type[])null).Invoke(__instance, new object[2] { null, num });
			return false;
		}

		private static float GetWeight(CartelActivity activity, int playerRank)
		{
			bool flag = activity is Ambush || activity is RobDealer;
			float num = Mathf.Clamp01((float)(playerRank + 1) / 40f);
			if (flag)
			{
				return 1f + num * 5f;
			}
			return 1f;
		}

		private static CartelActivity WeightedPick(List<CartelActivity> options, List<float> weights)
		{
			float num = 0f;
			foreach (float weight in weights)
			{
				num += weight;
			}
			float num2 = Random.Range(0f, num);
			float num3 = 0f;
			for (int i = 0; i < options.Count; i++)
			{
				num3 += weights[i];
				if (num2 <= num3)
				{
					return options[i];
				}
			}
			return options[0];
		}
	}
}