Decompiled source of NewGamePlus v0.4.3

ScheduleOneNewGamePlus.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using FishNet.Object;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ScheduleOne.DevUtilities;
using ScheduleOne.Dialogue;
using ScheduleOne.Economy;
using ScheduleOne.GameTime;
using ScheduleOne.Growing;
using ScheduleOne.ItemFramework;
using ScheduleOne.Law;
using ScheduleOne.Levelling;
using ScheduleOne.Money;
using ScheduleOne.NPCs;
using ScheduleOne.NPCs.CharacterClasses;
using ScheduleOne.Persistence;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Product;
using ScheduleOne.Properties;
using ScheduleOne.Quests;
using ScheduleOne.UI.Phone.Messages;
using ScheduleOneNewGamePlus;
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), "ScheduleCustomDealer", "1.0.0", "Sean", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ScheduleOneNewGamePlus")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1f1851894414936c6f1c6268a9a7e81118427a30")]
[assembly: AssemblyProduct("ScheduleOneNewGamePlus")]
[assembly: AssemblyTitle("ScheduleOneNewGamePlus")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.0.0")]
[module: UnverifiableCode]
[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 ScheduleOneNewGamePlus
{
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(DialogueHandler), "InitializeDialogue", new Type[] { typeof(DialogueContainer) })]
		public static class DialogueHandler_InitializeDialogue_Patch
		{
			public static bool Prefix(DialogueHandler __instance, DialogueContainer container)
			{
				DialogueNodeData val = ((IEnumerable<DialogueNodeData>)container.DialogueNodeData).FirstOrDefault((Func<DialogueNodeData, bool>)((DialogueNodeData node) => node.Guid == "49a5e66d-5100-4193-9461-92f0e4a95330"));
				if (val != null)
				{
					MelonLogger.Msg("Found the drug dealer dialogue node!");
					val.DialogueText = "That's not funny.";
					val.DialogueNodeLabel = "";
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(DialogueController_Dan), "ModifyDialogueText")]
		public static class DialogueController_Dan_ModifyDialogueText_Patch
		{
			public static bool Prefix(DialogueController_Dan __instance, string dialogueLabel, string dialogueText)
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Expected O, but got Unknown
				MelonLogger.Msg("dumping info: " + dialogueLabel + " - " + dialogueText);
				if (dialogueText.Contains("not funny"))
				{
					((Component)__instance).GetComponent<DialogueHandler>().NPC.actions.SetCallPoliceBehaviourCrime((Crime)new AttemptingToSell());
					((Component)__instance).GetComponent<DialogueHandler>().NPC.actions.CallPolice_Networked(Player.Local);
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Plant), "Initialize")]
		public static class Plant_Initialize_Patch
		{
			public static bool Prefix(Plant __instance, NetworkObject pot, float growthProgress, float yieldLevel, float qualityLevel)
			{
				__instance.BaseQualityLevel = 0.3f;
				return true;
			}
		}

		[HarmonyPatch(typeof(PenaltyHandler), "ProcessCrimeList")]
		public static class PenaltyHandler_ProcessCrimeList_Patch
		{
			private static void Postfix(ref List<string> __result)
			{
				foreach (string item in __result)
				{
					MelonLogger.Msg("Penalty String: " + item);
				}
				List<string> obj = __result;
				string text = obj[obj.Count - 1];
				MelonLogger.Msg("last string: " + text);
				Match match = Regex.Match(text, "[-+]?\\d*\\.?\\d+");
				if (match.Success && float.TryParse(match.Value, out var result))
				{
					MelonLogger.Msg($"Parsed float: {result}");
					float num = result * 10f;
					string value = MoneyManager.FormatAmount(num, true, false) + " fine";
					List<string> obj2 = __result;
					obj2[obj2.Count - 1] = value;
					NetworkSingleton<MoneyManager>.Instance.ChangeCashBalance(0f - result * 9f, true, false);
				}
				else
				{
					MelonLogger.Msg("Failed to parse float.");
				}
			}
		}

		[HarmonyPatch(typeof(WeedInstance), "ApplyEffectsToPlayer")]
		public static class WeedInstance_ApplyEffectsToPlayer_Patch
		{
			private static void Postfix()
			{
				highOnWeed = true;
			}
		}

		[HarmonyPatch(typeof(WeedInstance), "ClearEffectsFromPlayer")]
		public static class WeedInstance_ClearEffectsFromPlayer_Patch
		{
			private static void Postfix()
			{
				highOnWeed = false;
			}
		}

		[HarmonyPatch(typeof(MethInstance), "ApplyEffectsToPlayer")]
		public static class MethInstance_ApplyEffectsToPlayer_Patch
		{
			private static void Postfix()
			{
				highOnMeth = true;
			}
		}

		[HarmonyPatch(typeof(MethInstance), "ClearEffectsFromPlayer")]
		public static class MethInstance_ClearEffectsFromPlayer_Patch
		{
			private static void Postfix()
			{
				highOnMeth = false;
			}
		}

		[HarmonyPatch(typeof(CocaineInstance), "ApplyEffectsToPlayer")]
		public static class CocaineInstance_ApplyEffectsToPlayer_Patch
		{
			private static void Postfix()
			{
				highOnCocaine = true;
			}
		}

		[HarmonyPatch(typeof(CocaineInstance), "ClearEffectsFromPlayer")]
		public static class CocaineInstance_ClearEffectsFromPlayer_Patch
		{
			private static void Postfix()
			{
				highOnCocaine = false;
			}
		}

		[HarmonyPatch(typeof(Contract), "GetProductListMatch")]
		public static class Contract_GetProductListMatch_Patch
		{
			private static void Postfix(ref float __result)
			{
				if (!highOnWeed && !highOnMeth && !highOnCocaine)
				{
					MelonLogger.Msg("30% contract penalty for not being high");
					__result *= 0.7f;
				}
			}
		}

		[HarmonyPatch(typeof(Customer), "GetProductEnjoyment")]
		public static class GetProductEnjoyment_Postfix
		{
			private static void Postfix(Customer __instance, ProductDefinition product, EQuality quality, ref float __result)
			{
				List<Property> properties = ((PropertyItemDefinition)product).Properties;
				if (__instance.CustomerData.PreferredProperties.Count == 0)
				{
					return;
				}
				bool flag = false;
				foreach (Property preferred in __instance.CustomerData.PreferredProperties)
				{
					if ((Object)(object)properties.Find((Property x) => (Object)(object)x == (Object)(object)preferred) != (Object)null)
					{
						flag = true;
					}
				}
				if (!flag)
				{
					MelonLogger.Msg("Couldn't find a single property the customer likes, failing the check");
					__result = -1000f;
				}
				else
				{
					MelonLogger.Msg("Found at least one property the customer likes, passing the check...");
				}
			}
		}

		private bool registered = false;

		private static bool highOnWeed;

		private static bool highOnMeth;

		private static bool highOnCocaine;

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			if (buildIndex == 1)
			{
				if ((Object)(object)Singleton<LoadManager>.Instance != (Object)null && !registered)
				{
					Singleton<LoadManager>.Instance.onLoadComplete.AddListener(new UnityAction(OnLoadCompleteCb));
				}
				return;
			}
			if ((Object)(object)Singleton<LoadManager>.Instance != (Object)null && registered)
			{
				Singleton<LoadManager>.Instance.onLoadComplete.RemoveListener(new UnityAction(OnLoadCompleteCb));
			}
			registered = false;
		}

		public void OnLoadCompleteCb()
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			if (registered)
			{
				return;
			}
			registered = true;
			LevelManager instance = NetworkSingleton<LevelManager>.Instance;
			TimeManager instance2 = NetworkSingleton<TimeManager>.Instance;
			if (instance2.ElapsedDays == 0)
			{
				foreach (NPC item in NPCManager.NPCRegistry)
				{
					if (item.Inventory.RandomCash)
					{
						int num = Random.Range(0, 50);
						if (num > 0)
						{
							CashInstance cashInstance = NetworkSingleton<MoneyManager>.Instance.GetCashInstance((float)num);
							item.Inventory.InsertItem((ItemInstance)(object)cashInstance, true);
						}
					}
				}
			}
			UncleNelson val = Object.FindObjectsOfType<UncleNelson>().FirstOrDefault();
			if ((Object)(object)val != (Object)null && instance.XP == 0)
			{
				val.SendInitialMessage();
				((NPC)val).MSGConversation.SetIsKnown(false);
				((NPC)val).MSGConversation.SendMessageChain(new MessageChain
				{
					Messages = new List<string> { "**Developer Note**", "Welcome to NewGamePlus mode! There are a few important differences to keep in mind.", "Customers will expect you to be high when you complete a deal.", "Customers only mess with drugs that have the affects they like.", "You start off at the Hoodlum rank. Good luck, have fun!" }
				}, 0f, true, true);
				((NPC)val).MSGConversation.SetRead(false);
			}
			if (instance.XP == 0)
			{
				instance.AddXP(1000);
			}
			Customer[] array = Object.FindObjectsOfType<Customer>();
			Customer[] array2 = array;
			foreach (Customer val2 in array2)
			{
				CustomerData customerData = val2.CustomerData;
				customerData.CallPoliceChance *= 2f;
				val2.CustomerData.GuaranteeFirstSampleSuccess = false;
			}
		}
	}
}