Decompiled source of DDSLoader v1.0.7

DDSLoader.dll

Decompiled a month ago
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 System.Security;
using System.Security.Permissions;
using AssetBundleLoader;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DDSLoader")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyDescription("Loads the DDS and strings CSV for other mods")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+273527c11e4a6c2eb13227ff012cbdb9e73aa003")]
[assembly: AssemblyProduct("DDSLoader")]
[assembly: AssemblyTitle("DDSLoader")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 DDSLoader
{
	public class DDSDebugHelper
	{
		public static void StartConversation(string ddsTreeId, string participantA, string participantB)
		{
			StartConversation(ddsTreeId, new string[2] { participantA, participantB });
		}

		public static void StartConversation(string ddsTreeId, string[] participants)
		{
			Human val = null;
			List<Human> val2 = new List<Human>();
			foreach (string text in participants)
			{
				if ((Object)(object)val == (Object)null)
				{
					val = GameObject.Find(text).GetComponent<Human>();
				}
				else
				{
					val2.Add(GameObject.Find(text).GetComponent<Human>());
				}
			}
			val.ExecuteConversationTree(Toolbox.Instance.allDDSTrees[ddsTreeId], val2);
		}
	}
	[HarmonyPatch(typeof(Human), "ExecuteConversationTree")]
	public class Human_ExecuteConversationTree
	{
		public static void Postfix(Human __instance, DDSTreeSave newTree, List<Human> otherParticipants)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (DDSLoaderPlugin.debugLogConversations.Value)
			{
				ManualLogSource pluginLogger = DDSLoaderPlugin.PluginLogger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(49, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Conversation started: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((DDSComponent)newTree).id);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" started by ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)__instance).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" and including ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(string.Join(", ", ((IEnumerable<Human>)otherParticipants.ToArray()).Select((Human other) => ((Object)other).name)));
				}
				pluginLogger.LogInfo(val);
			}
			if (DDSLoaderPlugin.debugPauseTreeGUID.Value == ((DDSComponent)newTree).id)
			{
				InterfaceController.Instance.ToggleNotebookButton();
			}
		}
	}
	internal class DDSLoaderHooks
	{
		[HarmonyPatch(typeof(Toolbox), "Start")]
		public class Toolbox_Start
		{
			[Serializable]
			private class CustomSerializableNewspaperArticle
			{
				public bool disabled;

				public int category;

				public string[] followupStories;

				public string[] possibleImages;

				public int context;
			}

			public static void Postfix()
			{
				//IL_013f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0146: Expected O, but got Unknown
				//IL_023c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0243: Expected O, but got Unknown
				//IL_034b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0352: Expected O, but got Unknown
				//IL_0448: Unknown result type (might be due to invalid IL or missing references)
				//IL_044f: Expected O, but got Unknown
				//IL_069d: Unknown result type (might be due to invalid IL or missing references)
				//IL_06a4: Expected O, but got Unknown
				//IL_07e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_07e8: Expected O, but got Unknown
				//IL_083c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0843: Expected O, but got Unknown
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Expected O, but got Unknown
				//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01da: Expected O, but got Unknown
				//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e9: Expected O, but got Unknown
				//IL_03df: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e6: Expected O, but got Unknown
				//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f3: Expected O, but got Unknown
				//IL_0730: Unknown result type (might be due to invalid IL or missing references)
				//IL_0737: Expected O, but got Unknown
				//IL_058f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0595: Invalid comparison between Unknown and I4
				//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_05b1: Expected O, but got Unknown
				//IL_062f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0636: Expected O, but got Unknown
				//IL_0b6a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0b71: Expected O, but got Unknown
				//IL_0af3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0afa: Expected O, but got Unknown
				if (DDSLoaderPlugin.debugClearNewspaperArticles.Value)
				{
					Toolbox.Instance.allArticleTrees.Clear();
				}
				bool flag = default(bool);
				string text11 = default(string);
				string text12 = default(string);
				string text13 = default(string);
				string text14 = default(string);
				int num3 = default(int);
				bool flag3 = default(bool);
				string text15 = default(string);
				foreach (DirectoryInfo item in DDSLoaderPlugin.modsToLoadFrom)
				{
					string path = Path.Combine(item.FullName, "DDS", "Trees");
					string path2 = Path.Combine(item.FullName, "DDS", "Messages");
					string path3 = Path.Combine(item.FullName, "DDS", "Blocks");
					if (Directory.Exists(path3))
					{
						string[] files = Directory.GetFiles(path3, "*.block");
						foreach (string text in files)
						{
							try
							{
								DDSBlockSave val = JsonUtility.FromJson<DDSBlockSave>(File.ReadAllText(text));
								if (val == null)
								{
									ManualLogSource pluginLogger = DDSLoaderPlugin.PluginLogger;
									BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
									if (flag)
									{
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load: ");
										((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (Empty)");
									}
									pluginLogger.LogWarning(val2);
								}
								else
								{
									Toolbox.Instance.allDDSBlocks.Add(((DDSComponent)val).id, val);
								}
							}
							catch (Exception ex)
							{
								ManualLogSource pluginLogger2 = DDSLoaderPlugin.PluginLogger;
								BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to load: ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text);
								}
								pluginLogger2.LogError(val3);
								DDSLoaderPlugin.PluginLogger.LogError((object)ex);
							}
						}
						string[] files2 = Directory.GetFiles(path3, "*.block_patch");
						foreach (string text2 in files2)
						{
							try
							{
								DDSBlockSave val4 = JsonUtility.FromJson<DDSBlockSave>(CreatePatchedJson(text2));
								if (val4 == null)
								{
									ManualLogSource pluginLogger3 = DDSLoaderPlugin.PluginLogger;
									BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
									if (flag)
									{
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load: ");
										((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text2);
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (Empty)");
									}
									pluginLogger3.LogWarning(val2);
								}
								else
								{
									Toolbox.Instance.allDDSBlocks[((DDSComponent)val4).id] = val4;
								}
							}
							catch (Exception ex2)
							{
								ManualLogSource pluginLogger4 = DDSLoaderPlugin.PluginLogger;
								BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to load: ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text2);
								}
								pluginLogger4.LogError(val3);
								DDSLoaderPlugin.PluginLogger.LogError((object)ex2);
							}
						}
					}
					if (Directory.Exists(path2))
					{
						string[] files3 = Directory.GetFiles(path2, "*.msg");
						foreach (string text3 in files3)
						{
							try
							{
								DDSMessageSave val5 = JsonUtility.FromJson<DDSMessageSave>(File.ReadAllText(text3));
								if (val5 == null)
								{
									ManualLogSource pluginLogger5 = DDSLoaderPlugin.PluginLogger;
									BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
									if (flag)
									{
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load: ");
										((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text3);
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (Empty)");
									}
									pluginLogger5.LogWarning(val2);
								}
								else
								{
									Toolbox.Instance.allDDSMessages.Add(((DDSComponent)val5).id, val5);
								}
							}
							catch (Exception ex3)
							{
								ManualLogSource pluginLogger6 = DDSLoaderPlugin.PluginLogger;
								BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to load: ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text3);
								}
								pluginLogger6.LogError(val3);
								DDSLoaderPlugin.PluginLogger.LogError((object)ex3);
							}
						}
						string[] files4 = Directory.GetFiles(path2, "*.msg_patch");
						foreach (string text4 in files4)
						{
							try
							{
								DDSMessageSave val6 = JsonUtility.FromJson<DDSMessageSave>(CreatePatchedJson(text4));
								if (val6 == null)
								{
									ManualLogSource pluginLogger7 = DDSLoaderPlugin.PluginLogger;
									BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
									if (flag)
									{
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load: ");
										((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text4);
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (Empty)");
									}
									pluginLogger7.LogWarning(val2);
								}
								else
								{
									Toolbox.Instance.allDDSMessages[((DDSComponent)val6).id] = val6;
								}
							}
							catch (Exception ex4)
							{
								ManualLogSource pluginLogger8 = DDSLoaderPlugin.PluginLogger;
								BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to load: ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text4);
								}
								pluginLogger8.LogError(val3);
								DDSLoaderPlugin.PluginLogger.LogError((object)ex4);
							}
						}
					}
					if (Directory.Exists(path))
					{
						string[] files5 = Directory.GetFiles(path, "*.tree");
						foreach (string text5 in files5)
						{
							try
							{
								DDSTreeSave val7 = JsonUtility.FromJson<DDSTreeSave>(File.ReadAllText(text5));
								if (val7 == null)
								{
									ManualLogSource pluginLogger9 = DDSLoaderPlugin.PluginLogger;
									BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(24, 1, ref flag);
									if (flag)
									{
										((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to load: ");
										((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text5);
										((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" (Empty)");
									}
									pluginLogger9.LogError(val3);
									continue;
								}
								val7.messageRef = new Dictionary<string, DDSMessageSettings>();
								Enumerator<DDSMessageSettings> enumerator2 = val7.messages.GetEnumerator();
								while (enumerator2.MoveNext())
								{
									DDSMessageSettings current2 = enumerator2.Current;
									val7.messageRef.Add(current2.instanceID, current2);
								}
								Toolbox.Instance.allDDSTrees.Add(((DDSComponent)val7).id, val7);
								if ((int)val7.treeType == 3)
								{
									ManualLogSource pluginLogger10 = DDSLoaderPlugin.PluginLogger;
									BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(66, 0, ref flag);
									if (flag)
									{
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Newspaper content is no longer supported - use the official editor");
									}
									pluginLogger10.LogWarning(val2);
								}
								bool flag2 = false;
								Enumerator<DDSMessageSettings> enumerator3 = val7.messages.GetEnumerator();
								while (enumerator3.MoveNext())
								{
									DDSMessageSettings current3 = enumerator3.Current;
									if (current3.instanceID == val7.startingMessage)
									{
										flag2 = true;
										break;
									}
								}
								if (!flag2)
								{
									ManualLogSource pluginLogger11 = DDSLoaderPlugin.PluginLogger;
									BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(144, 2, ref flag);
									if (flag)
									{
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("DDS Tree ");
										((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((DDSComponent)val7).name);
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (");
										((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((DDSComponent)val7).id);
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(") doesn't reference an existing message instanceID as it's starting message. This item may not work if it is a conversation or vmail!");
									}
									pluginLogger11.LogWarning(val2);
								}
							}
							catch (Exception ex5)
							{
								ManualLogSource pluginLogger12 = DDSLoaderPlugin.PluginLogger;
								BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to load: ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text5);
								}
								pluginLogger12.LogError(val3);
								DDSLoaderPlugin.PluginLogger.LogError((object)ex5);
							}
						}
						string[] files6 = Directory.GetFiles(path, "*.tree_patch");
						foreach (string text6 in files6)
						{
							try
							{
								DDSTreeSave val8 = JsonUtility.FromJson<DDSTreeSave>(CreatePatchedJson(text6));
								if (val8 == null)
								{
									ManualLogSource pluginLogger13 = DDSLoaderPlugin.PluginLogger;
									BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
									if (flag)
									{
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to load: ");
										((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text6);
										((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (Empty)");
									}
									pluginLogger13.LogWarning(val2);
								}
								else
								{
									val8.messageRef = new Dictionary<string, DDSMessageSettings>();
									Enumerator<DDSMessageSettings> enumerator4 = val8.messages.GetEnumerator();
									while (enumerator4.MoveNext())
									{
										DDSMessageSettings current4 = enumerator4.Current;
										val8.messageRef.Add(current4.instanceID, current4);
									}
									Toolbox.Instance.allDDSTrees[((DDSComponent)val8).id] = val8;
								}
							}
							catch (Exception ex6)
							{
								ManualLogSource pluginLogger14 = DDSLoaderPlugin.PluginLogger;
								BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(16, 1, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to load: ");
									((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text6);
								}
								pluginLogger14.LogError(val3);
								DDSLoaderPlugin.PluginLogger.LogError((object)ex6);
							}
						}
					}
					ManualLogSource pluginLogger15 = DDSLoaderPlugin.PluginLogger;
					BepInExInfoLogInterpolatedStringHandler val9 = new BepInExInfoLogInterpolatedStringHandler(36, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("Loaded DDS Content and Patches For: ");
						((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<string>(item.Parent.Name);
					}
					pluginLogger15.LogInfo(val9);
					string text7 = Path.Combine(item.FullName, "Strings", Game.Instance.language);
					string text8 = Path.Combine(item.FullName, "Strings", "English");
					MethodInfo method = Il2CppType.From(typeof(Strings)).GetMethod("LoadIntoDictionary", (BindingFlags)40);
					if (method == (MethodInfo)null)
					{
						DDSLoaderPlugin.PluginLogger.LogError((object)"Strings.LoadIntoDictionary not found!");
						continue;
					}
					string text9 = (Directory.Exists(text7) ? text7 : (Directory.Exists(text8) ? text8 : ""));
					if (!(text9 != ""))
					{
						continue;
					}
					string[] files7 = Directory.GetFiles(text9, "*.csv", SearchOption.AllDirectories);
					foreach (string path4 in files7)
					{
						string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path4);
						string[] array = File.ReadAllLines(path4);
						foreach (string text10 in array)
						{
							Strings.ParseLine(text10.Trim(), ref text11, ref text12, ref text13, ref text14, ref num3, ref flag3, ref text15, true);
							if (text13 == null || !(method != (MethodInfo)null))
							{
								continue;
							}
							if (Strings.stringTable[fileNameWithoutExtension].ContainsKey(text11))
							{
								if (Strings.randomEntryLists.ContainsKey(fileNameWithoutExtension))
								{
									for (int num4 = Strings.randomEntryLists[fileNameWithoutExtension].Count - 1; num4 >= 0; num4--)
									{
										if (Strings.randomEntryLists[fileNameWithoutExtension][num4].displayStr == Strings.stringTable[fileNameWithoutExtension][text11].displayStr)
										{
											Strings.randomEntryLists[fileNameWithoutExtension].RemoveAt(num4);
										}
									}
								}
								Strings.stringTable[fileNameWithoutExtension].Remove(text11);
							}
							((MethodBase)method).Invoke((Object)null, new Il2CppReferenceArray<Object>((Object[])(object)new Object[7]
							{
								Object.op_Implicit(fileNameWithoutExtension),
								Object.op_Implicit(Strings.stringTable[fileNameWithoutExtension].Count + 1),
								Object.op_Implicit(text11),
								Object.op_Implicit(text13.Replace("\\r\\n", "\r\n")),
								Object.op_Implicit(text14),
								Object.op_Implicit(num3),
								Object.op_Implicit(flag3)
							}));
							if (DDSLoaderPlugin.debugPrintLoadedStrings.Value)
							{
								ManualLogSource pluginLogger16 = DDSLoaderPlugin.PluginLogger;
								val9 = new BepInExInfoLogInterpolatedStringHandler(2, 2, ref flag);
								if (flag)
								{
									((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<string>(fileNameWithoutExtension);
									((BepInExLogInterpolatedStringHandler)val9).AppendLiteral(": ");
									((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<string>(text13.Replace("\\r\\n", "\r\n"));
								}
								pluginLogger16.LogInfo(val9);
							}
						}
					}
					ManualLogSource pluginLogger17 = DDSLoaderPlugin.PluginLogger;
					val9 = new BepInExInfoLogInterpolatedStringHandler(27, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("Loaded String Content For: ");
						((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<string>(item.Parent.Name);
					}
					pluginLogger17.LogInfo(val9);
				}
			}

			private static string CreatePatchedJson(string patchPath)
			{
				FileInfo fileInfo = new FileInfo(patchPath);
				DirectoryInfo directoryInfo = new DirectoryInfo(fileInfo.DirectoryName);
				return JSONPatch.ApplyPatch(File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "DDS", directoryInfo.Name, fileInfo.Name.Split('_')[0])), File.ReadAllText(patchPath)).ToString();
			}

			private static void LoadNewspaperArticle(DDSTreeSave tree, string messagesPath)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Invalid comparison between Unknown and I4
				if ((int)tree.treeType != 3)
				{
				}
			}
		}

		private static Dictionary<string, NewspaperArticle> ddsToArticle;
	}
	[BepInPlugin("DDSLoader", "DDSLoader", "1.0.2")]
	public class DDSLoaderPlugin : BasePlugin
	{
		public static ManualLogSource PluginLogger;

		public static List<DirectoryInfo> modsToLoadFrom = new List<DirectoryInfo>();

		public static ConfigEntry<bool> debugLogConversations;

		public static ConfigEntry<string> debugPauseTreeGUID;

		public static ConfigEntry<bool> debugClearNewspaperArticles;

		public static ConfigEntry<bool> debugPrintLoadedStrings;

		public override void Load()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			PluginLogger = ((BasePlugin)this).Log;
			ManualLogSource pluginLogger = PluginLogger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("DDSLoader");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			pluginLogger.LogInfo(val);
			Harmony val2 = new Harmony("DDSLoader");
			val2.PatchAll();
			ManualLogSource pluginLogger2 = PluginLogger;
			val = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("DDSLoader");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is patched!");
			}
			pluginLogger2.LogInfo(val);
			debugLogConversations = ((BasePlugin)this).Config.Bind<bool>("Debug", "Enable debugging of conversations", false, (ConfigDescription)null);
			debugPauseTreeGUID = ((BasePlugin)this).Config.Bind<string>("Debug", "Pause when this conversation tree GUID begins", "", (ConfigDescription)null);
			debugClearNewspaperArticles = ((BasePlugin)this).Config.Bind<bool>("Debug", "Clear existing newspaper articles", false, (ConfigDescription)null);
			debugPrintLoadedStrings = ((BasePlugin)this).Config.Bind<bool>("Debug", "Log loaded strings to the console", false, (ConfigDescription)null);
			modsToLoadFrom = (from dirPath in Directory.GetDirectories(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ".."), "DDSContent", SearchOption.AllDirectories)
				select new DirectoryInfo(dirPath) into dir
				where !File.Exists(Path.Combine(dir.Parent.FullName, "disabled.txt"))
				select dir).ToList();
		}
	}
	public class JSONPatch
	{
		public static dynamic ApplyPatch(string targetJSON, string patchJSON)
		{
			dynamic val = NewtonsoftExtensions.NewtonsoftJson.JToken_Parse(targetJSON);
			dynamic val2 = NewtonsoftExtensions.NewtonsoftJson.JToken_Parse(patchJSON);
			foreach (dynamic item in val2)
			{
				object obj = item["op"]?.ToString();
				dynamic val3 = item["path"]?.ToString();
				object obj2 = item["from"]?.ToString();
				dynamic val4 = item["value"];
				object obj3 = obj;
				object obj4 = obj3;
				switch (obj4 as string)
				{
				case "add":
					JSONPatch.SetValue(val, val3, val4, createIfMissing: true);
					break;
				case "replace":
					JSONPatch.SetValue(val, val3, val4, createIfMissing: false);
					break;
				case "remove":
					JSONPatch.RemoveValue(val, val3);
					break;
				default:
					throw new NotSupportedException($"Unsupported operation: {obj}");
				}
			}
			return val;
		}

		private static string[] SplitPath(string path)
		{
			return (from p in path.Trim('/').Split('/')
				select p.Replace("~1", "/").Replace("~0", "~")).ToArray();
		}

		private static void SetValue(dynamic root, string path, dynamic value, bool createIfMissing)
		{
			string[] array = SplitPath(path);
			dynamic val = root;
			int result = -1;
			for (int i = 0; i < array.Length - 1; i++)
			{
				string text = array[i];
				if (NewtonsoftExtensions.NewtonsoftJson.JToken_Type(val) == (e_JToken_Type)1)
				{
					if ((!val.ContainsKey(text)))
					{
						if (!createIfMissing)
						{
							throw new Exception("Path not found: " + path);
						}
						val[text] = NewtonsoftExtensions.NewtonsoftJson.JToken_Ctr();
					}
					val = val[text];
				}
				else
				{
					if (!((NewtonsoftExtensions.NewtonsoftJson.JToken_Type(val) == (e_JToken_Type)2 && int.TryParse(text, out result)) ? true : false))
					{
						throw new Exception("Invalid path segment: " + text);
					}
					val = val[result];
				}
			}
			string text2 = array.Last();
			if (NewtonsoftExtensions.NewtonsoftJson.JToken_Type(val) == (e_JToken_Type)1)
			{
				val[text2] = value;
				return;
			}
			if (NewtonsoftExtensions.NewtonsoftJson.JToken_Type(val) == (e_JToken_Type)2 && int.TryParse(text2, out result))
			{
				if (result >= 0 && result <= val.Count)
				{
					if (result == val.Count)
					{
						val.Add(value);
					}
					else
					{
						val[result] = value;
					}
					return;
				}
				throw new Exception("Invalid array index: " + text2);
			}
			throw new Exception("Cannot set value at path: " + path);
		}

		private static void RemoveValue(dynamic root, string path)
		{
			string[] array = SplitPath(path);
			dynamic val = root;
			for (int i = 0; i < array.Length - 1; i++)
			{
				string text = array[i];
				val = val[text] ?? throw new Exception("Path not found: " + path);
			}
			string text2 = array.Last();
			int result = -1;
			if (NewtonsoftExtensions.NewtonsoftJson.JToken_Type(val) == (e_JToken_Type)1)
			{
				val.Remove(text2);
				return;
			}
			if (!((NewtonsoftExtensions.NewtonsoftJson.JToken_Type(val) == (e_JToken_Type)2 && int.TryParse(text2, out result) && result < val.Count) ? true : false))
			{
				throw new Exception("Invalid remove path: " + path);
			}
			val.RemoveAt(result);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DDSLoader";

		public const string PLUGIN_NAME = "DDSLoader";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}