Decompiled source of AchievementHelper v0.1.1

AchievementHelper.dll

Decompiled 4 months 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 AIGraph;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using Enemies;
using GameData;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AchievementHelper")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AchievementHelper")]
[assembly: AssemblyTitle("AchievementHelper")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace AchievementHelper
{
	internal static class CompleteMarkingEveryEnemy_Patches
	{
		private static bool notified_MarkingEveryEnemy_failure;

		[HarmonyPatch(typeof(AchievementManager), "OnLevelGenDone")]
		[HarmonyPostfix]
		private static void ResetForNewLevel()
		{
			notified_MarkingEveryEnemy_failure = false;
		}

		[HarmonyPatch(typeof(Achievement_CompleteMarkingEveryEnemy), "OnEnemyKilledMaster")]
		[HarmonyPostfix]
		private static void Host_CheckAchievementStatus(Achievement_CompleteMarkingEveryEnemy __instance, EnemyDamageInfo __0)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			string text = ((Object)__0.Source).name.Split(" : ").Last();
			EnemyAgent damagedAgent = __0.DamagedAgent;
			uint gearCategoryId = __0.gearCategoryId;
			if (!AchievementManager.GetSyncedAchievementState<Achievement_CompleteMarkingEveryEnemy>().IsActive && !damagedAgent.WasTagged && !notified_MarkingEveryEnemy_failure)
			{
				Utils.SendLocalMessage("Biotracker achievement failed!");
				notified_MarkingEveryEnemy_failure = true;
				string text2 = text + " killed unmarked " + ((GameDataBlockBase<EnemyDataBlock>)(object)damagedAgent.EnemyData).name;
				if (gearCategoryId != 0)
				{
					text2 = ((gearCategoryId == GearCategory.MeleeBat) ? (text2 + " with Bat") : ((gearCategoryId == GearCategory.MeleeKnife) ? (text2 + " with Knife") : ((gearCategoryId == GearCategory.MeleeSledgehammer) ? (text2 + " with Sledgehammer") : ((gearCategoryId == GearCategory.MeleeSpear) ? (text2 + " with Spear") : ((gearCategoryId != GearCategory.TripMine) ? (text2 + $" with gearCategoryId {gearCategoryId}") : (text2 + " with Tripmine"))))));
				}
				Utils.SendLocalMessage(text2);
			}
		}

		public static void Anyone_CheckAchievementStatus()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if ((int)GameStateManager.CurrentStateName == 10 && !AchievementManager.GetSyncedAchievementState<Achievement_CompleteMarkingEveryEnemy>().IsActive && !notified_MarkingEveryEnemy_failure)
			{
				Utils.SendLocalMessage("Biotracker achievement failed!");
				notified_MarkingEveryEnemy_failure = true;
			}
		}

		[HarmonyPatch(typeof(PlayerChatManager), "PostMessage")]
		[HarmonyPrefix]
		private static void OnCommand(PlayerChatManager __instance)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.m_currentValue.StartsWith("/biotracker"))
			{
				return;
			}
			__instance.m_currentValue = "";
			if ((int)GameStateManager.CurrentStateName != 10)
			{
				Utils.SendLocalMessage("You are not in a level");
				return;
			}
			if (!AchievementManager.GetSyncedAchievementState<Achievement_CompleteMarkingEveryEnemy>().IsActive)
			{
				Utils.SendLocalMessage("An unmarked enemy was killed. Biotracker achievement is void");
				return;
			}
			Utils.SendLocalMessage("No unmarked enemies have been killed");
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			Enumerator<AIG_CourseNode> enumerator = ((SteppedUpdateGroup<AIG_CourseNode>)(object)EnemyUpdateManager.Current.m_nodeUpdates).m_members.GetEnumerator();
			while (enumerator.MoveNext())
			{
				AIG_CourseNode current = enumerator.Current;
				string key = $"Zone {current.m_zone.m_navInfo.Number} Area {current.m_area.m_navInfo.Suffix}";
				int count = current.m_enemiesInNode.Count;
				if (count > 0)
				{
					if (dictionary.ContainsKey(key))
					{
						dictionary[key] += count;
					}
					else
					{
						dictionary[key] = count;
					}
				}
			}
			int num = dictionary.Sum((KeyValuePair<string, int> pair) => pair.Value);
			Utils.SendLocalMessage($"{num} {((num == 1) ? "enemy" : "enemies")} remaining");
			if (dictionary.Count > 5)
			{
				return;
			}
			foreach (KeyValuePair<string, int> item in dictionary)
			{
				Utils.SendLocalMessage($"- {item.Key} contains {item.Value} {((item.Value == 1) ? "enemy" : "enemies")}");
			}
		}
	}
	internal static class ElevatorTravel_Patches
	{
		[HarmonyPatch(typeof(GameStateManager), "ChangeState")]
		[HarmonyPostfix]
		private static void Notify()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)GameStateManager.CurrentStateName == 5)
			{
				float num = AchievementManager.Current.GetFloatValue("STAT_FLOAT_1");
				if (num > 99.9f && num < 100f)
				{
					num = 99.9f;
				}
				Utils.SendLocalMessage($"The Inner: {num:F1}/100.0 km");
			}
		}
	}
	internal static class ListenToVoiceOfMrTruth_Patches
	{
		[HarmonyPatch(typeof(Achievement_ReadAllLogs), "CheckCompletion")]
		[HarmonyPostfix]
		private static void CheckCompletion(Achievement_ReadAllLogs __instance)
		{
			uint num = 2644574539u;
			if (__instance.m_readLogsOnStart.Contains(num))
			{
				AchievementManager.CompleteAchievementLocalFromKey("ACH_53");
			}
		}
	}
	internal static class ReadCharacterLogs_Patches
	{
		[HarmonyPatch(typeof(Achievement_ReadAllLogs), "CheckCompletion")]
		[HarmonyPostfix]
		private static void CheckCompletion(Achievement_ReadAllLogs __instance)
		{
			List<uint> obj = new List<uint>
			{
				3340509967u, 3213710012u, 1098021268u, 1276363701u, 2618453398u, 649711753u, 4258872482u, 3124381907u, 3820350058u, 3200929578u,
				2899831782u, 294658885u
			};
			bool flag = false;
			foreach (uint item in obj)
			{
				if (!__instance.m_readLogsOnStart.Contains(item))
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				AchievementManager.CompleteAchievementLocalFromKey("ACH_60");
			}
		}
	}
	internal static class Utils
	{
		private static ManualLogSource logger = Logger.CreateLogSource("AchievementHelper");

		public static void LogInfo(string text)
		{
			logger.LogInfo((object)text);
		}

		public static void LogError(string text)
		{
			logger.LogError((object)text);
		}

		public static void SendChatMessage(string text)
		{
			LogInfo("SendChatMessage: " + text);
			string text2 = "<color=yellow>";
			int num = 50 - text2.Length;
			while (text.Length > num)
			{
				PlayerChatManager.WantToSentTextMessage(PlayerManager.GetLocalPlayerAgent(), text2 + text.Substring(0, num).Trim(), (PlayerAgent)null);
				text = text.Substring(num).Trim();
			}
			PlayerChatManager.WantToSentTextMessage(PlayerManager.GetLocalPlayerAgent(), text2 + text, (PlayerAgent)null);
		}

		public static void SendLocalMessage(string text)
		{
			LogInfo("SendLocalMessage: " + text);
			GuiManager.PlayerLayer.m_gameEventLog.AddLogItem("<color=yellow>" + text, (eGameEventChatLogType)2);
			CM_PageLoadout.Current.m_gameEventLog.AddLogItem("<color=yellow>" + text, (eGameEventChatLogType)2);
		}
	}
	[BepInPlugin("AchievementHelper", "AchievementHelper", "0.1.1")]
	internal class Plugin : BasePlugin
	{
		private class UnityPlugin : MonoBehaviour
		{
			private void Update()
			{
				if (ConfigManager.enable_CompleteMarkingEveryEnemy_Patches)
				{
					CompleteMarkingEveryEnemy_Patches.Anyone_CheckAchievementStatus();
				}
			}
		}

		public static class ConfigManager
		{
			private static ConfigEntry<bool> _enable_CompleteMarkingEveryEnemy_Patches;

			private static ConfigEntry<bool> _enable_CompleteElevatorTravel_Patches;

			private static ConfigEntry<bool> _enable_ListenToVoiceOfMrTruth_Patches;

			private static ConfigEntry<bool> _enable_ReadCharacterLogs_Patches;

			public static bool enable_CompleteMarkingEveryEnemy_Patches => _enable_CompleteMarkingEveryEnemy_Patches.Value;

			public static bool enable_CompleteElevatorTravel_Patches => _enable_CompleteElevatorTravel_Patches.Value;

			public static bool enable_ListenToVoiceOfMrTruth_Patches => _enable_ListenToVoiceOfMrTruth_Patches.Value;

			public static bool enable_ReadCharacterLogs_Patches => _enable_ReadCharacterLogs_Patches.Value;

			static ConfigManager()
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: 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)
				ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "AchievementHelper.cfg"), true);
				_enable_CompleteMarkingEveryEnemy_Patches = val.Bind<bool>("Biotracker", "Enable", true, "Display a notice when an unmarked enemy is killed, and enable /biotracker command.");
				_enable_CompleteElevatorTravel_Patches = val.Bind<bool>("The Inner", "Enable", true, "Display progress before and after every game.");
				_enable_ListenToVoiceOfMrTruth_Patches = val.Bind<bool>("The Voice of Truth", "Enable", true, "Fix a very rare bug that makes this achievement unobtainable. Works retroactively.");
				_enable_ReadCharacterLogs_Patches = val.Bind<bool>("Unmasked", "Enable", true, "Fix a very rare bug that makes this achievement unobtainable. Works retroactively.");
			}
		}

		public override void Load()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			Utils.LogInfo("AchievementHelper is loading...");
			Harmony val = new Harmony("AchievementHelper");
			if (ConfigManager.enable_CompleteMarkingEveryEnemy_Patches)
			{
				val.PatchAll(typeof(CompleteMarkingEveryEnemy_Patches));
			}
			if (ConfigManager.enable_CompleteElevatorTravel_Patches)
			{
				val.PatchAll(typeof(ElevatorTravel_Patches));
			}
			if (ConfigManager.enable_ListenToVoiceOfMrTruth_Patches)
			{
				val.PatchAll(typeof(ListenToVoiceOfMrTruth_Patches));
			}
			if (ConfigManager.enable_ReadCharacterLogs_Patches)
			{
				val.PatchAll(typeof(ReadCharacterLogs_Patches));
			}
			((BasePlugin)this).AddComponent<UnityPlugin>();
			Utils.LogInfo("AchievementHelper is loaded");
		}
	}
}