using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EnhancedRadarBooster;
using GameNetcodeStuff;
using HarmonyLib;
using ImmersiveCompany.Patches;
using Microsoft.CodeAnalysis;
using OpenBodyCams;
using OpenBodyCams.API;
using TMPro;
using TwoRadarMaps.Compatibility;
using TwoRadarMaps.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TwoRadarMaps")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TwoRadarMaps")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("58be1122-f068-4465-95ee-b1f09dcd559f")]
[assembly: AssemblyFileVersion("2.0.6")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.6.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 TwoRadarMaps
{
[BepInPlugin("Zaggy1024.TwoRadarMaps", "TwoRadarMaps", "1.4.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
private const string MOD_NAME = "TwoRadarMaps";
private const string MOD_UNIQUE_NAME = "Zaggy1024.TwoRadarMaps";
private const string MOD_VERSION = "1.4.2";
internal static readonly Harmony Harmony = new Harmony("Zaggy1024.TwoRadarMaps");
public static ConfigEntry<FilterMode> TextureFiltering;
public static ConfigEntry<int> BodyCamHorizontalResolution;
public static ConfigEntry<bool> EnableZoom;
public static ConfigEntry<string> ZoomLevels;
public static ConfigEntry<int> DefaultZoomLevel;
public static ConfigEntry<bool> EnableTeleportCommand;
public static ConfigEntry<bool> EnableTeleportCommandShorthand;
private const string DEFAULT_ZOOM_LEVELS = "19.7, 29.55, 39.4";
internal static Terminal Terminal;
internal static ShipTeleporter Teleporter;
public static ManualCameraRenderer TerminalMapRenderer;
public static TextMeshProUGUI TerminalMapScreenPlayerName;
public static Canvas TerminalMapScreenUICanvas;
public static float[] TerminalMapZoomLevelOptions;
public static int TerminalMapZoomLevel;
public static Plugin Instance { get; private set; }
public ManualLogSource Logger => ((BaseUnityPlugin)this).Logger;
public void Awake()
{
Instance = this;
TextureFiltering = ((BaseUnityPlugin)this).Config.Bind<FilterMode>("Rendering", "TextureFiltering", (FilterMode)0, "The filtering mode to apply to the map (and the body cam if present).\n\nPoint will result in sharp edges on pixels.\nBilinear and Trilinear will result in smooth transitions between pixels.");
TextureFiltering.SettingChanged += delegate
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
((Texture)TerminalMapRenderer.cam.targetTexture).filterMode = TextureFiltering.Value;
OpenBodyCamsCompatibility.UpdateBodyCamTexture();
};
BodyCamHorizontalResolution = ((BaseUnityPlugin)this).Config.Bind<int>("Compatibility", "BodyCamHorizontalResolution", 170, "The horizontal resolution to use for the picture-in-picture body cam when it is enabled in OpenBodyCams 2.1.0+.\n\nThe vertical resolution will be calculated based on a 4:3 aspect ratio.");
EnableZoom = ((BaseUnityPlugin)this).Config.Bind<bool>("Zoom", "Enabled", false, "Enable 'zoom in' and 'zoom out' commands in the terminal to zoom in and out of the terminal radar map.");
EnableZoom.SettingChanged += delegate
{
TerminalCommands.Initialize();
};
ZoomLevels = ((BaseUnityPlugin)this).Config.Bind<string>("Zoom", "Sizes", "19.7, 29.55, 39.4", "The orthographic sizes to use for each zoom level.\nA list of comma-separated numbers.\nLower values indicate a smaller field of view.\n100% zoom is 19.7.");
ZoomLevels.SettingChanged += delegate
{
UpdateZoomFactors();
};
DefaultZoomLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Zoom", "DefaultLevel", 0, "The zoom factor to select by default. The first zoom level is 0.");
EnableTeleportCommand = ((BaseUnityPlugin)this).Config.Bind<bool>("TeleportCommand", "Enabled", false, "Enable an 'activate teleport' command in the terminal. A player can be specified to teleport them instead of the target of the terminal's map.");
EnableTeleportCommand.SettingChanged += delegate
{
TerminalCommands.Initialize();
};
EnableTeleportCommandShorthand = ((BaseUnityPlugin)this).Config.Bind<bool>("TeleportCommand", "ShorthandEnabled", true, "Enable a 'tp' shorthand for the 'activate teleport' command. Will only function if the longhand command is enabled.");
EnableTeleportCommandShorthand.SettingChanged += delegate
{
TerminalCommands.Initialize();
};
Harmony.PatchAll(typeof(PatchTerminal));
Harmony.PatchAll(typeof(PatchVanillaBugs));
Harmony.PatchAll(typeof(PatchManualCameraRenderer));
Harmony.PatchAll(typeof(PatchShipTeleporter));
RenderPipelineManager.beginCameraRendering += BeforeCameraRendering;
OpenBodyCamsCompatibility.Initialize();
EnhancedRadarBoosterCompatibility.Initialize(Harmony);
}
public static void BeforeCameraRendering(ScriptableRenderContext context, Camera camera)
{
ManualCameraRenderer val = StartOfRound.Instance?.mapScreen;
if ((Object)(object)val == (Object)null)
{
return;
}
ManualCameraRenderer val2 = null;
((Behaviour)val.mapCameraLight).enabled = false;
if ((Object)(object)camera == (Object)(object)val.cam)
{
val2 = val;
}
if ((Object)(object)TerminalMapRenderer != (Object)null)
{
((Behaviour)TerminalMapRenderer.mapCameraLight).enabled = false;
if ((Object)(object)camera == (Object)(object)TerminalMapRenderer.cam)
{
val2 = TerminalMapRenderer;
}
}
if (!((Object)(object)val2 == (Object)null))
{
((Behaviour)val2.mapCameraLight).enabled = true;
}
}
private static bool TargetIsValid(Transform targetTransform)
{
if ((Object)(object)targetTransform == (Object)null)
{
return false;
}
PlayerControllerB component = ((Component)((Component)targetTransform).transform).GetComponent<PlayerControllerB>();
if ((Object)(object)component == (Object)null)
{
return true;
}
if (!component.isPlayerControlled && !component.isPlayerDead)
{
return (Object)(object)component.redirectToEnemy != (Object)null;
}
return true;
}
internal static void SetTargetIndex(ManualCameraRenderer mapRenderer, int targetIndex)
{
if (targetIndex < mapRenderer.radarTargets.Count)
{
mapRenderer.targetTransformIndex = targetIndex;
mapRenderer.targetedPlayer = ((Component)mapRenderer.radarTargets[targetIndex].transform).GetComponent<PlayerControllerB>();
}
}
internal static int GetNextValidTarget(List<TransformAndName> targets, int initialIndex)
{
int count = targets.Count;
for (int i = 0; i < count; i++)
{
int num = (initialIndex + i) % count;
if (TargetIsValid(targets[num]?.transform))
{
return num;
}
}
return -1;
}
internal static void StartTargetTransition(ManualCameraRenderer mapRenderer, int targetIndex)
{
if (mapRenderer.updateMapCameraCoroutine != null)
{
((MonoBehaviour)mapRenderer).StopCoroutine(mapRenderer.updateMapCameraCoroutine);
}
mapRenderer.updateMapCameraCoroutine = ((MonoBehaviour)mapRenderer).StartCoroutine(mapRenderer.updateMapTarget(targetIndex, true));
}
internal static void EnsureMapRendererHasValidTarget(ManualCameraRenderer mapRenderer)
{
int nextValidTarget = GetNextValidTarget(mapRenderer.radarTargets, mapRenderer.targetTransformIndex);
if (nextValidTarget != -1)
{
StartTargetTransition(mapRenderer, nextValidTarget);
}
}
public static void EnsureAllMapRenderersHaveValidTargets()
{
EnsureMapRendererHasValidTarget(StartOfRound.Instance.mapScreen);
EnsureMapRendererHasValidTarget(TerminalMapRenderer);
}
public static void UpdateZoomFactors(string factors)
{
try
{
TerminalMapZoomLevelOptions = (from s in factors.Split(new char[2] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
select float.Parse(s.Trim(), CultureInfo.InvariantCulture)).ToArray();
}
catch (Exception arg)
{
Instance.Logger.LogError((object)$"Failed to parse terminal map radar zoom levels: {arg}");
UpdateZoomFactors("19.7, 29.55, 39.4");
}
SetZoomLevel(DefaultZoomLevel.Value);
}
public static void UpdateZoomFactors()
{
UpdateZoomFactors(ZoomLevels.Value);
}
public static float GetZoomOrthographicSize()
{
return TerminalMapZoomLevelOptions[TerminalMapZoomLevel];
}
public static void SetZoomLevel(int level)
{
if (!((Object)(object)TerminalMapRenderer == (Object)null))
{
TerminalMapRenderer.mapCameraAnimator.SetTrigger("Transition");
TerminalMapZoomLevel = Math.Max(0, Math.Min(level, TerminalMapZoomLevelOptions.Length - 1));
TerminalMapRenderer.cam.orthographicSize = GetZoomOrthographicSize();
}
}
public static void CycleTerminalMapZoom()
{
SetZoomLevel((TerminalMapZoomLevel + 1) % TerminalMapZoomLevelOptions.Length);
}
public static void ZoomTerminalMapIn()
{
SetZoomLevel(TerminalMapZoomLevel - 1);
}
public static void ZoomTerminalMapOut()
{
SetZoomLevel(TerminalMapZoomLevel + 1);
}
public static void TeleportTarget(int targetIndex)
{
ManualCameraRenderer mapScreen = StartOfRound.Instance.mapScreen;
if (mapScreen.targetTransformIndex >= mapScreen.radarTargets.Count)
{
Instance.Logger.LogError((object)$"Attempted to teleport target #{targetIndex} which is out of bounds of the {mapScreen.radarTargets.Count} targets available.");
return;
}
if ((Object)(object)Teleporter == (Object)null)
{
Instance.Logger.LogError((object)$"Attempted to teleport target #{targetIndex} ({mapScreen.radarTargets[targetIndex].name}) with no teleporter.");
return;
}
int targetTransformIndex = mapScreen.targetTransformIndex;
SetTargetIndex(mapScreen, targetIndex);
Teleporter.PressTeleportButtonOnLocalClient();
SetTargetIndex(mapScreen, targetTransformIndex);
}
}
public static class TerminalCommands
{
public static TerminalNode CycleZoomNode = null;
public static TerminalNode ZoomInNode = null;
public static TerminalNode ZoomOutNode = null;
public static TerminalNode ResetZoomNode = null;
public static TerminalNode TeleportNode = null;
private static readonly List<TerminalKeyword> newTerminalKeywords = new List<TerminalKeyword>();
private static readonly List<TerminalKeyword> modifiedTerminalKeywords = new List<TerminalKeyword>();
private static readonly List<(TerminalNode, string)> appendedDescriptions = new List<(TerminalNode, string)>();
public static void Initialize()
{
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Expected O, but got Unknown
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Expected O, but got Unknown
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Expected O, but got Unknown
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Expected O, but got Unknown
if ((Object)(object)Plugin.Terminal == (Object)null)
{
return;
}
RemoveAddedKeywords();
Plugin.UpdateZoomFactors();
CycleZoomNode = null;
ZoomInNode = null;
ZoomOutNode = null;
ResetZoomNode = null;
if (Plugin.EnableZoom.Value)
{
CycleZoomNode = ScriptableObject.CreateInstance<TerminalNode>();
((Object)CycleZoomNode).name = "CycleZoomNode";
CycleZoomNode.displayText = "";
CycleZoomNode.clearPreviousText = true;
ZoomInNode = ScriptableObject.CreateInstance<TerminalNode>();
((Object)ZoomInNode).name = "ZoomIn";
ZoomInNode.displayText = "";
ZoomInNode.clearPreviousText = true;
ZoomOutNode = ScriptableObject.CreateInstance<TerminalNode>();
((Object)ZoomOutNode).name = "ZoomOut";
ZoomOutNode.displayText = "";
ZoomOutNode.clearPreviousText = true;
ResetZoomNode = ScriptableObject.CreateInstance<TerminalNode>();
((Object)ResetZoomNode).name = "ResetZoom";
ResetZoomNode.displayText = "";
ResetZoomNode.clearPreviousText = true;
TerminalKeyword noun = FindOrCreateKeyword("In", "in", verb: false);
TerminalKeyword noun2 = FindOrCreateKeyword("Out", "out", verb: false);
FindOrCreateKeyword("Zoom", "zoom", verb: true, (CompatibleNoun[])(object)new CompatibleNoun[2]
{
new CompatibleNoun
{
noun = noun,
result = ZoomInNode
},
new CompatibleNoun
{
noun = noun2,
result = ZoomOutNode
}
}).specialKeywordResult = CycleZoomNode;
TerminalKeyword noun3 = FindOrCreateKeyword("Zoom", "zoom", verb: false);
FindOrCreateKeyword("Reset", "reset", verb: true, (CompatibleNoun[])(object)new CompatibleNoun[1]
{
new CompatibleNoun
{
noun = noun3,
result = ResetZoomNode
}
});
AddCommandDescription("other", "ZOOM", "Cycle through zoom levels on the map. Specify direction with 'IN' and 'OUT'.\nThe 'RESET ZOOM' command will set the zoom back to the default level.");
}
TeleportNode = null;
if (Plugin.EnableTeleportCommand.Value)
{
TeleportNode = ScriptableObject.CreateInstance<TerminalNode>();
((Object)TeleportNode).name = "TeleportNode";
TeleportNode.clearPreviousText = true;
TerminalKeyword noun4 = FindOrCreateKeyword("Teleporter", "teleporter", verb: false);
FindOrCreateKeyword("Activate", "activate", verb: true, (CompatibleNoun[])(object)new CompatibleNoun[1]
{
new CompatibleNoun
{
noun = noun4,
result = TeleportNode
}
});
string text = "";
if (Plugin.EnableTeleportCommandShorthand.Value)
{
FindOrCreateKeyword("TeleportShorthand", "tp", verb: true).specialKeywordResult = TeleportNode;
text = "/TP";
}
AddCommandDescription("other", "ACTIVATE TELEPORTER" + text, "Activate the teleporter to beam the player monitored on the map into the ship.");
}
AddNewlyCreatedCommands();
}
public static bool ProcessNode(TerminalNode node)
{
if ((Object)(object)node == (Object)(object)CycleZoomNode)
{
Plugin.CycleTerminalMapZoom();
return false;
}
if ((Object)(object)node == (Object)(object)ZoomInNode)
{
Plugin.ZoomTerminalMapIn();
return false;
}
if ((Object)(object)node == (Object)(object)ZoomOutNode)
{
Plugin.ZoomTerminalMapOut();
return false;
}
if ((Object)(object)node == (Object)(object)ResetZoomNode)
{
Plugin.SetZoomLevel(Plugin.DefaultZoomLevel.Value);
return false;
}
if ((Object)(object)node == (Object)(object)TeleportNode)
{
if ((Object)(object)Plugin.Teleporter == (Object)null)
{
TeleportNode.displayText = "Teleporter is not installed.\n\n";
return true;
}
TeleportNode.displayText = "Teleporting " + StartOfRound.Instance.mapScreen.radarTargets[Plugin.TerminalMapRenderer.targetTransformIndex]?.name + "...\n\n";
Plugin.TeleportTarget(Plugin.TerminalMapRenderer.targetTransformIndex);
return false;
}
return true;
}
private static TerminalKeyword FindKeyword(string word, bool verb)
{
return ((IEnumerable<TerminalKeyword>)Plugin.Terminal.terminalNodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword keyword) => keyword.word == word && keyword.isVerb == verb));
}
private static CompatibleNoun FindCompatibleNoun(this TerminalKeyword keyword, string noun)
{
return ((IEnumerable<CompatibleNoun>)keyword.compatibleNouns).FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun compatible) => compatible.noun.word == noun));
}
private static TerminalKeyword FindOrCreateKeyword(string name, string word, bool verb, CompatibleNoun[] compatibleNouns = null)
{
Plugin.Instance.Logger.LogInfo((object)("Creating terminal " + (verb ? "verb" : "noun") + " '" + word + "' (" + name + ")."));
TerminalKeyword val = FindKeyword(word, verb);
if ((Object)(object)val == (Object)null)
{
val = ScriptableObject.CreateInstance<TerminalKeyword>();
((Object)val).name = name;
val.isVerb = verb;
val.word = word;
val.compatibleNouns = compatibleNouns;
newTerminalKeywords.Add(val);
Plugin.Instance.Logger.LogInfo((object)" Keyword was not found, created a new one.");
}
else
{
TerminalKeyword obj = val;
CompatibleNoun[] array = val.compatibleNouns ?? Array.Empty<CompatibleNoun>();
CompatibleNoun[] array2 = compatibleNouns ?? Array.Empty<CompatibleNoun>();
int num = 0;
CompatibleNoun[] array3 = (CompatibleNoun[])(object)new CompatibleNoun[array.Length + array2.Length];
ReadOnlySpan<CompatibleNoun> readOnlySpan = new ReadOnlySpan<CompatibleNoun>(array);
readOnlySpan.CopyTo(new Span<CompatibleNoun>(array3).Slice(num, readOnlySpan.Length));
num += readOnlySpan.Length;
ReadOnlySpan<CompatibleNoun> readOnlySpan2 = new ReadOnlySpan<CompatibleNoun>(array2);
readOnlySpan2.CopyTo(new Span<CompatibleNoun>(array3).Slice(num, readOnlySpan2.Length));
num += readOnlySpan2.Length;
obj.compatibleNouns = array3;
Plugin.Instance.Logger.LogInfo((object)" Keyword existed, appended nouns.");
}
modifiedTerminalKeywords.Add(val);
return val;
}
private static void AddNewlyCreatedCommands()
{
TerminalNodesList terminalNodes;
TerminalKeyword[] allKeywords = (terminalNodes = Plugin.Terminal.terminalNodes).allKeywords;
List<TerminalKeyword> list = newTerminalKeywords;
int num = 0;
TerminalKeyword[] array = (TerminalKeyword[])(object)new TerminalKeyword[allKeywords.Length + list.Count];
ReadOnlySpan<TerminalKeyword> readOnlySpan = new ReadOnlySpan<TerminalKeyword>(allKeywords);
readOnlySpan.CopyTo(new Span<TerminalKeyword>(array).Slice(num, readOnlySpan.Length));
num += readOnlySpan.Length;
foreach (TerminalKeyword item in list)
{
array[num] = item;
num++;
}
terminalNodes.allKeywords = array;
}
private static void AddCommandDescription(string category, string word, string description)
{
TerminalNode specialKeywordResult = FindKeyword(category, verb: false).specialKeywordResult;
string text = new StringBuilder(word.Length + description.Length + 5).Append(">").Append(word).Append("\n")
.Append(description)
.Append("\n\n")
.ToString();
appendedDescriptions.Add((specialKeywordResult, text));
if (specialKeywordResult.displayText.EndsWith("\n\n\n"))
{
specialKeywordResult.displayText = specialKeywordResult.displayText.Insert(specialKeywordResult.displayText.Length - 1, text);
}
else
{
specialKeywordResult.displayText += text;
}
}
private static void RemoveCommandDescription(TerminalNode category, string text)
{
}
private static void RemoveAddedKeywords()
{
foreach (TerminalKeyword modifiedTerminalKeyword in modifiedTerminalKeywords)
{
if (modifiedTerminalKeyword.compatibleNouns != null)
{
List<CompatibleNoun> list = new List<CompatibleNoun>();
list.AddRange(modifiedTerminalKeyword.compatibleNouns.Where((CompatibleNoun compatible) => !newTerminalKeywords.Contains(compatible.noun)));
modifiedTerminalKeyword.compatibleNouns = list.ToArray();
}
}
modifiedTerminalKeywords.Clear();
foreach (TerminalKeyword newTerminalKeyword in newTerminalKeywords)
{
Object.Destroy((Object)(object)newTerminalKeyword);
}
TerminalNodesList terminalNodes = Plugin.Terminal.terminalNodes;
List<TerminalKeyword> list2 = new List<TerminalKeyword>();
list2.AddRange(terminalNodes.allKeywords.Where((TerminalKeyword keyword) => !newTerminalKeywords.Contains(keyword)));
terminalNodes.allKeywords = list2.ToArray();
newTerminalKeywords.Clear();
foreach (var appendedDescription in appendedDescriptions)
{
TerminalNode item = appendedDescription.Item1;
string item2 = appendedDescription.Item2;
int num = item.displayText.IndexOf(item2);
if (num == -1)
{
Plugin.Instance.Logger.LogError((object)("Could not find command description text in " + ((Object)item).name + " to remove it:"));
Plugin.Instance.Logger.LogError((object)item2);
}
else
{
item.displayText = item.displayText.Remove(num, item2.Length);
}
}
appendedDescriptions.Clear();
}
}
internal class TerminalVisibilityTracker : MonoBehaviour
{
private void OnEnable()
{
((Behaviour)Plugin.TerminalMapRenderer).enabled = true;
}
private void OnDisable()
{
((Behaviour)Plugin.TerminalMapRenderer).enabled = false;
if ((Object)(object)Plugin.TerminalMapRenderer.cam != (Object)null)
{
((Behaviour)Plugin.TerminalMapRenderer.cam).enabled = false;
}
}
}
}
namespace TwoRadarMaps.Patches
{
public class SequenceMatch
{
public int Start;
public int End;
public int Size => End - Start;
public SequenceMatch(int start, int end)
{
Start = start;
End = end;
base..ctor();
}
}
public static class Common
{
public static void ReplaceMainMapWithTerminalMap(this List<CodeInstruction> instructions)
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
int num = 0;
while (true)
{
num = instructions.FindIndex(num, (CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, Reflection.f_StartOfRound_mapScreen, false));
if (num != -1)
{
SequenceMatch sequenceMatch = instructions.InstructionRangeForStackItems(num, 0, 0);
List<Label> labels = instructions[sequenceMatch.Start].labels;
instructions.RemoveAt(num);
instructions.RemoveAbsoluteRange(sequenceMatch.Start, sequenceMatch.End);
instructions.Insert(sequenceMatch.Start, CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldsfld, (object)Reflection.f_Plugin_terminalMapRenderer), (IEnumerable<Label>)labels));
continue;
}
break;
}
}
internal static void InsertTerminalField(this List<CodeInstruction> instructions, ILGenerator generator, CodeInstruction loadRenderer, FieldInfo vanillaStartOfRoundField, FieldInfo pluginField)
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Expected O, but got Unknown
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Expected O, but got Unknown
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Expected O, but got Unknown
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Expected O, but got Unknown
int startIndex = 0;
while (true)
{
SequenceMatch sequenceMatch = instructions.FindIndexOfSequence(startIndex, new <>z__ReadOnlyArray<Predicate<CodeInstruction>>(new Predicate<CodeInstruction>[2]
{
(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_StartOfRound_Instance),
(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, vanillaStartOfRoundField, false)
}));
if (sequenceMatch != null)
{
Label label = generator.DefineLabel();
instructions[sequenceMatch.End].labels.Add(label);
Label label2 = generator.DefineLabel();
CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[3]
{
new CodeInstruction(loadRenderer),
new CodeInstruction(OpCodes.Ldsfld, (object)Reflection.f_Plugin_terminalMapRenderer),
new CodeInstruction(OpCodes.Beq_S, (object)label2)
};
instructions.InsertRange(sequenceMatch.Start, array);
CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Br_S, (object)label),
CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldsfld, (object)pluginField), new Label[1] { label2 })
};
instructions.InsertRange(sequenceMatch.End + array.Length, array2);
startIndex = sequenceMatch.End + array.Length + array2.Length;
continue;
}
break;
}
}
public static void RemoveAbsoluteRange<T>(this List<T> list, int start, int end)
{
list.RemoveRange(start, end - start);
}
public static void RemoveRange<T>(this List<T> list, SequenceMatch range)
{
list.RemoveAbsoluteRange(range.Start, range.End);
}
public static IEnumerable<T> GetAbsoluteRangeView<T>(this List<T> list, int start, int end)
{
for (int i = start; i < end; i++)
{
yield return list[i];
}
}
public static IEnumerable<T> GetRangeView<T>(this List<T> list, SequenceMatch range)
{
return list.GetAbsoluteRangeView(range.Start, range.End);
}
public static SequenceMatch FindIndexOfSequence<T>(this List<T> list, int startIndex, IEnumerable<Predicate<T>> predicates)
{
int num;
for (num = startIndex; num < list.Count(); num++)
{
IEnumerator<Predicate<T>> enumerator = predicates.GetEnumerator();
if (!enumerator.MoveNext())
{
return null;
}
num = list.FindIndex(num, enumerator.Current);
if (num < 0)
{
break;
}
bool flag = true;
int num2 = 1;
while (enumerator.MoveNext())
{
if (num2 >= list.Count() - num || !enumerator.Current(list[num + num2]))
{
flag = false;
break;
}
num2++;
}
if (flag)
{
return new SequenceMatch(num, num + predicates.Count());
}
}
return null;
}
public static SequenceMatch FindIndexOfSequence<T>(this List<T> list, IEnumerable<Predicate<T>> predicates)
{
return list.FindIndexOfSequence(0, predicates);
}
public static int PopCount(this CodeInstruction instruction)
{
if (instruction.opcode == OpCodes.Call || instruction.opcode == OpCodes.Callvirt)
{
MethodInfo obj = (MethodInfo)instruction.operand;
int num = obj.GetParameters().Length;
if (!obj.IsStatic)
{
num++;
}
return num;
}
if (instruction.opcode == OpCodes.Ret)
{
return 1;
}
return instruction.opcode.StackBehaviourPop switch
{
StackBehaviour.Pop0 => 0,
StackBehaviour.Pop1 => 1,
StackBehaviour.Pop1_pop1 => 2,
StackBehaviour.Popi => 1,
StackBehaviour.Popi_pop1 => 2,
StackBehaviour.Popi_popi => 2,
StackBehaviour.Popi_popi8 => 2,
StackBehaviour.Popi_popi_popi => 3,
StackBehaviour.Popi_popr4 => 2,
StackBehaviour.Popi_popr8 => 2,
StackBehaviour.Popref => 1,
StackBehaviour.Popref_pop1 => 2,
StackBehaviour.Popref_popi => 2,
StackBehaviour.Popref_popi_popi => 3,
StackBehaviour.Popref_popi_popi8 => 3,
StackBehaviour.Popref_popi_popr4 => 3,
StackBehaviour.Popref_popi_popr8 => 3,
StackBehaviour.Popref_popi_popref => 3,
StackBehaviour.Varpop => throw new NotImplementedException("Variable pop on non-call instruction"),
StackBehaviour.Popref_popi_pop1 => 3,
_ => throw new NotSupportedException($"StackBehaviourPop of {instruction.opcode.StackBehaviourPop} was not a pop for instruction '{instruction}'"),
};
}
public static int PushCount(this CodeInstruction instruction)
{
if (instruction.opcode == OpCodes.Call || instruction.opcode == OpCodes.Callvirt)
{
if (((MethodInfo)instruction.operand).ReturnType == typeof(void))
{
return 0;
}
return 1;
}
return instruction.opcode.StackBehaviourPush switch
{
StackBehaviour.Push0 => 0,
StackBehaviour.Push1 => 1,
StackBehaviour.Push1_push1 => 2,
StackBehaviour.Pushi => 1,
StackBehaviour.Pushi8 => 1,
StackBehaviour.Pushr4 => 1,
StackBehaviour.Pushr8 => 1,
StackBehaviour.Pushref => 1,
StackBehaviour.Varpush => throw new NotImplementedException("Variable push on non-call instruction"),
_ => throw new NotSupportedException($"StackBehaviourPush of {instruction.opcode.StackBehaviourPush} was not a push for instruction '{instruction}'"),
};
}
public static SequenceMatch InstructionRangeForStackItems(this List<CodeInstruction> instructions, int instructionIndex, int startIndex, int endIndex)
{
int num = -1;
int num2 = -1;
instructionIndex--;
int num3 = 0;
while (instructionIndex >= 0)
{
CodeInstruction instruction = instructions[instructionIndex];
int num4 = instruction.PushCount();
if (num2 == -1 && num3 == startIndex && num4 > 0)
{
num2 = instructionIndex + 1;
}
num3 += instruction.PushCount();
num3 -= instruction.PopCount();
if (num3 > endIndex)
{
num = instructionIndex;
break;
}
instructionIndex--;
}
if (num == -1 || num2 == -1)
{
return null;
}
return new SequenceMatch(num, num2);
}
public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingFlags, Type[] parameters)
{
return type.GetMethod(name, bindingFlags, null, parameters, null);
}
public static MethodInfo GetGenericMethod(this Type type, string name, BindingFlags bindingFlags, Type[] genericArguments, Type[] parameters)
{
MethodInfo[] methods = type.GetMethods(bindingFlags);
foreach (MethodInfo methodInfo in methods)
{
if (!(methodInfo.Name != name) && methodInfo.IsGenericMethodDefinition && methodInfo.GetGenericArguments().Length == genericArguments.Length)
{
MethodInfo methodInfo2 = methodInfo.MakeGenericMethod(genericArguments);
if ((from paramInfo in methodInfo2.GetParameters()
select paramInfo.ParameterType) == parameters)
{
return methodInfo2;
}
}
}
return null;
}
public static MethodInfo GetGenericMethod(this Type type, string name, Type[] genericArguments, Type[] parameters)
{
return type.GetGenericMethod(name, BindingFlags.Default, genericArguments, parameters);
}
}
[HarmonyPatch(typeof(ManualCameraRenderer))]
internal static class PatchManualCameraRenderer
{
private static readonly FieldInfo f_ManualCameraRenderer_radarTargets = typeof(ManualCameraRenderer).GetField("radarTargets");
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> updateMapTargetTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
list.InsertTerminalField(generator, new CodeInstruction(OpCodes.Ldloc_1, (object)null), Reflection.f_StartOfRound_mapScreenPlayerName, Reflection.f_Plugin_terminalMapScreenPlayerName);
return list;
}
[HarmonyPatch("MapCameraFocusOnPosition")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> MapCameraFocusOnPositionTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
list.InsertTerminalField(generator, new CodeInstruction(OpCodes.Ldarg_0, (object)null), Reflection.f_StartOfRound_radarCanvas, Reflection.f_Plugin_terminalMapScreenUICanvas);
return list;
}
[HarmonyPatch("ChangeNameOfTargetTransform")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> ChangeNameOfTargetTransformTranspiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
int num = list.FindIndex((CodeInstruction insn) => CodeInstructionExtensions.StoresField(insn, Reflection.f_TransformAndName_name));
SequenceMatch sequenceMatch = list.InstructionRangeForStackItems(num, 1, 1);
SequenceMatch range = list.InstructionRangeForStackItems(sequenceMatch.End - 1, 0, 0);
int index = num + 1;
List<CodeInstruction> list2 = new List<CodeInstruction>();
list2.AddRange(list.GetRangeView(range));
list2.Add(new CodeInstruction(OpCodes.Call, (object)Common.GetMethod(typeof(PatchManualCameraRenderer), "OnTargetNameChanged", BindingFlags.Static | BindingFlags.NonPublic, new Type[1] { typeof(int) })));
list.InsertRange(index, new <>z__ReadOnlyList<CodeInstruction>(list2));
return list;
}
private static void ApplyTargetNameChange(ManualCameraRenderer mapRenderer, int targetIndex)
{
if (targetIndex == mapRenderer.targetTransformIndex)
{
Plugin.StartTargetTransition(mapRenderer, mapRenderer.targetTransformIndex);
}
}
private static void OnTargetNameChanged(int targetIndex)
{
ApplyTargetNameChange(StartOfRound.Instance.mapScreen, targetIndex);
ApplyTargetNameChange(Plugin.TerminalMapRenderer, targetIndex);
}
[HarmonyPatch("RemoveTargetFromRadar")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> RemoveTargetFromRadarTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Expected O, but got Unknown
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
//IL_026b: Expected O, but got Unknown
MethodInfo m_List_RemoveAt = typeof(List<TransformAndName>).GetMethod("RemoveAt", new Type[1] { typeof(int) });
FieldInfo f_ManualCameraRenderer_targetTransformIndex = typeof(ManualCameraRenderer).GetField("targetTransformIndex");
MethodInfo m_List_Count = typeof(List<TransformAndName>).GetMethod("get_Count");
typeof(ManualCameraRenderer).GetMethod("SwitchRadarTargetForward", new Type[1] { typeof(bool) });
List<CodeInstruction> list = instructions.ToList();
SequenceMatch sequenceMatch = list.FindIndexOfSequence(new Predicate<CodeInstruction>[3]
{
(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_ManualCameraRenderer_radarTargets, false),
(CodeInstruction insn) => CodeInstructionExtensions.IsLdloc(insn, (LocalBuilder)null),
(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_List_RemoveAt)
});
CodeInstruction val = list[sequenceMatch.Start + 1];
SequenceMatch sequenceMatch2 = list.FindIndexOfSequence(new <>z__ReadOnlyArray<Predicate<CodeInstruction>>(new Predicate<CodeInstruction>[6]
{
(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_ManualCameraRenderer_targetTransformIndex, false),
(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_ManualCameraRenderer_radarTargets, false),
(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_List_Count),
(CodeInstruction insn) => insn.opcode == OpCodes.Blt || insn.opcode == OpCodes.Blt_S
}));
Label targetIsInBoundsLabel = (Label)list[sequenceMatch2.End - 1].operand;
int end = list.FindIndex(sequenceMatch2.End, (CodeInstruction insn) => insn.labels.Contains(targetIsInBoundsLabel));
list.RemoveAbsoluteRange(sequenceMatch2.Start, end);
list.InsertRange(sequenceMatch2.Start, new <>z__ReadOnlyArray<CodeInstruction>((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(val),
CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Call, (object)Common.GetMethod(typeof(PatchManualCameraRenderer), "RadarTargetWasRemoved", BindingFlags.Static | BindingFlags.NonPublic, new Type[1] { typeof(int) })), new Label[1] { targetIsInBoundsLabel })
}));
return list;
}
private static void FixUpRadarTargetRemovalFor(ManualCameraRenderer mapRenderer, int removedIndex)
{
bool flag = removedIndex <= mapRenderer.targetTransformIndex;
if (mapRenderer.targetTransformIndex >= mapRenderer.radarTargets.Count)
{
mapRenderer.targetTransformIndex--;
}
int nextValidTarget = Plugin.GetNextValidTarget(mapRenderer.radarTargets, mapRenderer.targetTransformIndex);
if (nextValidTarget == -1)
{
mapRenderer.targetedPlayer = null;
}
else if (flag)
{
Plugin.StartTargetTransition(mapRenderer, nextValidTarget);
}
}
private static void RadarTargetWasRemoved(int removedIndex)
{
FixUpRadarTargetRemovalFor(StartOfRound.Instance.mapScreen, removedIndex);
FixUpRadarTargetRemovalFor(Plugin.TerminalMapRenderer, removedIndex);
}
[HarmonyPatch("SyncOrderOfRadarBoostersInList")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> SyncOrderOfRadarBoostersInListPostfix(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction instruction in instructions)
{
if (CodeInstructionExtensions.StoresField(instruction, f_ManualCameraRenderer_radarTargets))
{
yield return new CodeInstruction(OpCodes.Call, (object)Common.GetMethod(typeof(PatchManualCameraRenderer), "ApplySortedTargets", BindingFlags.Static | BindingFlags.NonPublic, new Type[2]
{
typeof(ManualCameraRenderer),
typeof(List<TransformAndName>)
}));
}
else
{
yield return instruction;
}
}
}
private static void OnTargetListResorted(ManualCameraRenderer mapRenderer, List<TransformAndName> sortedTargets)
{
int targetTransformIndex = mapRenderer.targetTransformIndex;
if (mapRenderer.radarTargets[targetTransformIndex] != sortedTargets[targetTransformIndex])
{
mapRenderer.radarTargets = sortedTargets;
int nextValidTarget = Plugin.GetNextValidTarget(sortedTargets, targetTransformIndex);
if (nextValidTarget != -1)
{
Plugin.StartTargetTransition(mapRenderer, nextValidTarget);
}
}
}
private static void ApplySortedTargets(ManualCameraRenderer _, List<TransformAndName> sortedTargets)
{
OnTargetListResorted(StartOfRound.Instance.mapScreen, sortedTargets);
OnTargetListResorted(Plugin.TerminalMapRenderer, sortedTargets);
StartOfRound.Instance.mapScreen.radarTargets = sortedTargets;
Plugin.TerminalMapRenderer.radarTargets = sortedTargets;
}
}
[HarmonyPatch(typeof(ShipTeleporter))]
internal static class PatchShipTeleporter
{
public static readonly MethodInfo m_NetworkBehaviour___beginSendServerRpc = Common.GetMethod(typeof(NetworkBehaviour), "__beginSendServerRpc", BindingFlags.Instance | BindingFlags.NonPublic, new Type[3]
{
typeof(uint),
typeof(ServerRpcParams),
typeof(RpcDelivery)
});
public static readonly MethodInfo m_NetworkBehaviour___beginSendClientRpc = Common.GetMethod(typeof(NetworkBehaviour), "__beginSendClientRpc", BindingFlags.Instance | BindingFlags.NonPublic, new Type[3]
{
typeof(uint),
typeof(ClientRpcParams),
typeof(RpcDelivery)
});
public static readonly MethodInfo m_NetworkManager_get_IsListening = typeof(NetworkManager).GetMethod("get_IsListening");
public static readonly MethodInfo m_WriteCurrentTarget = Common.GetMethod(typeof(PatchShipTeleporter), "WriteCurrentTargetIndex", BindingFlags.Static | BindingFlags.NonPublic, new Type[1] { typeof(FastBufferWriter) });
public static readonly MethodInfo m_ReadTargetIndexAndSet = Common.GetMethod(typeof(PatchShipTeleporter), "ReadTargetIndexAndSet", BindingFlags.Static | BindingFlags.NonPublic, new Type[1] { typeof(FastBufferReader) });
public static readonly MethodInfo m_Plugin_SetTargetIndex = Common.GetMethod(typeof(Plugin), "SetTargetIndex", BindingFlags.Static | BindingFlags.NonPublic, new Type[2]
{
typeof(ManualCameraRenderer),
typeof(int)
});
public static readonly MethodInfo m_ShipTeleporter_PressTeleportButtonServerRpcHandler = Common.GetMethod(typeof(ShipTeleporter), "__rpc_handler_389447712", BindingFlags.Static | BindingFlags.NonPublic, new Type[3]
{
typeof(NetworkBehaviour),
typeof(FastBufferReader),
typeof(__RpcParams)
});
public static readonly MethodInfo m_ShipTeleporter_PressTeleportButtonClientRpc = typeof(ShipTeleporter).GetMethod("PressTeleportButtonClientRpc", Array.Empty<Type>());
private static readonly List<uint> rpcMessageIDs = new List<uint>(2);
[HarmonyPostfix]
[HarmonyPatch("OnEnable")]
private static void OnEnablePostfix(ShipTeleporter __instance)
{
if (!__instance.isInverseTeleporter)
{
Plugin.Teleporter = __instance;
}
}
[HarmonyPostfix]
[HarmonyPatch("OnDisable")]
private static void OnDisablePostfix(ShipTeleporter __instance)
{
if (!((Object)(object)__instance != (Object)(object)Plugin.Teleporter))
{
Plugin.Teleporter = null;
}
}
[HarmonyTranspiler]
[HarmonyPatch("PressTeleportButtonServerRpc")]
[HarmonyPatch("PressTeleportButtonClientRpc")]
private static IEnumerable<CodeInstruction> TranspileRPCSendToWriteTargetIndex(IEnumerable<CodeInstruction> instructions, MethodBase method)
{
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Expected O, but got Unknown
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
int num = list.FindIndex((CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_NetworkBehaviour___beginSendServerRpc) || CodeInstructionExtensions.Calls(insn, m_NetworkBehaviour___beginSendClientRpc));
if (num == -1)
{
Plugin.Instance.Logger.LogError((object)"No call to __beginSendServerRpc() was found.");
return instructions;
}
SequenceMatch sequenceMatch = list.InstructionRangeForStackItems(num, 2, 2);
if (sequenceMatch == null || sequenceMatch.Size != 1 || !CodeInstructionExtensions.LoadsConstant(list[sequenceMatch.Start]))
{
Plugin.Instance.Logger.LogError((object)$"No RPC message ID was found in {method}.");
return instructions;
}
rpcMessageIDs.Add((uint)(int)list[sequenceMatch.Start].operand);
list.InsertRange(num + 1, new <>z__ReadOnlyArray<CodeInstruction>((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Dup, (object)null),
new CodeInstruction(OpCodes.Call, (object)m_WriteCurrentTarget)
}));
return list;
}
[HarmonyPostfix]
[HarmonyPatch("InitializeRPCS_ShipTeleporter")]
private static void InitializeRPCS_ShipTeleporterPostfix()
{
PatchRPCReceiveHandlers(Plugin.Harmony);
}
private static void WriteCurrentTargetIndex(FastBufferWriter writer)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
((FastBufferWriter)(ref writer)).WriteValue<int>(ref StartOfRound.Instance.mapScreen.targetTransformIndex, default(ForPrimitives));
}
private static void PatchRPCReceiveHandlers(Harmony harmony)
{
MethodInfo method = Common.GetMethod(typeof(PatchShipTeleporter), "TranspileRPCReceiveHandlerToSetTarget", BindingFlags.Static | BindingFlags.NonPublic, new Type[3]
{
typeof(IEnumerable<CodeInstruction>),
typeof(ILGenerator),
typeof(MethodBase)
});
foreach (uint rpcMessageID in rpcMessageIDs)
{
MethodInfo methodInfo = ((Delegate)(object)NetworkManager.__rpc_func_table[rpcMessageID]).GetMethodInfo();
harmony.CreateProcessor((MethodBase)methodInfo).AddTranspiler(method).Patch();
}
}
private static IEnumerable<CodeInstruction> TranspileRPCReceiveHandlerToSetTarget(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase method)
{
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Expected O, but got Unknown
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Expected O, but got Unknown
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Expected O, but got Unknown
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Expected O, but got Unknown
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Expected O, but got Unknown
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Expected O, but got Unknown
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
SequenceMatch sequenceMatch = list.FindIndexOfSequence(new <>z__ReadOnlyArray<Predicate<CodeInstruction>>(new Predicate<CodeInstruction>[3]
{
(CodeInstruction insn) => CodeInstructionExtensions.IsLdloc(insn, (LocalBuilder)null),
(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_NetworkManager_get_IsListening),
(CodeInstruction insn) => insn.opcode == OpCodes.Brtrue || insn.opcode == OpCodes.Brtrue_S
}));
Label isListeningLabel = (Label)list[sequenceMatch.End - 1].operand;
int num = list.FindIndex(sequenceMatch.End, (CodeInstruction insn) => insn.labels.Contains(isListeningLabel));
int num2 = list.FindIndex(num, (CodeInstruction insn) => insn.opcode == OpCodes.Ret);
list[num].labels.Remove(isListeningLabel);
LocalBuilder localBuilder = generator.DeclareLocal(typeof(int));
CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[3]
{
CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_1, (object)null), new Label[1] { isListeningLabel }),
new CodeInstruction(OpCodes.Call, (object)m_ReadTargetIndexAndSet),
new CodeInstruction(OpCodes.Stloc, (object)localBuilder)
};
list.InsertRange(num, array);
num2 += array.Length;
CodeInstruction[] collection = (CodeInstruction[])(object)new CodeInstruction[4]
{
new CodeInstruction(OpCodes.Call, (object)Reflection.m_StartOfRound_Instance),
new CodeInstruction(OpCodes.Ldfld, (object)Reflection.f_StartOfRound_mapScreen),
new CodeInstruction(OpCodes.Ldloc, (object)localBuilder),
new CodeInstruction(OpCodes.Call, (object)m_Plugin_SetTargetIndex)
};
list.InsertRange(num2, collection);
return list;
}
private static int ReadTargetIndexAndSet(FastBufferReader reader)
{
//IL_0017: 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)
ManualCameraRenderer mapScreen = StartOfRound.Instance.mapScreen;
int targetTransformIndex = mapScreen.targetTransformIndex;
int targetIndex = default(int);
((FastBufferReader)(ref reader)).ReadValue<int>(ref targetIndex, default(ForPrimitives));
Plugin.SetTargetIndex(mapScreen, targetIndex);
return targetTransformIndex;
}
}
[HarmonyPatch(typeof(Terminal))]
internal static class PatchTerminal
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void AwakePostfix(Terminal __instance)
{
Plugin.Terminal = __instance;
TerminalCommands.Initialize();
}
[HarmonyPrefix]
[HarmonyPatch("Start")]
private static void StartPrefix()
{
//IL_0351: Unknown result type (might be due to invalid IL or missing references)
//IL_0356: Unknown result type (might be due to invalid IL or missing references)
//IL_0361: Unknown result type (might be due to invalid IL or missing references)
//IL_0367: Unknown result type (might be due to invalid IL or missing references)
//IL_0376: Expected O, but got Unknown
GameObject gameObject = ((Component)Plugin.Terminal).gameObject;
GameObject val = GameObject.Find("Systems/GameSystems/ItemSystems");
if ((Object)(object)val == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Could not find the ItemSystems object.");
return;
}
Transform obj = val.transform.Find("MapCamera");
GameObject val2 = ((obj != null) ? ((Component)obj).gameObject : null);
if ((Object)(object)val2 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Could not find the default map camera.");
return;
}
ManualCameraRenderer val3 = StartOfRound.Instance?.mapScreen;
if ((Object)(object)val3 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Default map camera renderer is null.");
return;
}
Transform obj2 = val.transform.Find("MapScreenUI");
GameObject val4 = ((obj2 != null) ? ((Component)obj2).gameObject : null);
if ((Object)(object)val4 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Could not find the map screen UI.");
return;
}
GameObject val5 = Object.Instantiate<GameObject>(val2, val.transform, false);
Camera val6 = ((val5 != null) ? val5.GetComponent<Camera>() : null);
if ((Object)(object)val6 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Failed to clone the default map camera.");
return;
}
((Object)val5).name = "TerminalMapCamera";
GameObject val7 = Object.Instantiate<GameObject>(val4, val.transform, false);
Canvas val8 = ((val7 != null) ? val7.GetComponent<Canvas>() : null);
val8.worldCamera = val6;
if ((Object)(object)val8 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Failed to clone the default map's UI.");
return;
}
((Object)val7).name = "TerminalMapScreenUI";
Transform obj3 = val7.transform.Find("PlanetVideoReel");
GameObject val9 = ((obj3 != null) ? ((Component)obj3).gameObject : null);
Transform obj4 = val7.transform.Find("PlanetDescription");
GameObject val10 = ((obj4 != null) ? ((Component)obj4).gameObject : null);
if ((Object)(object)val9 == (Object)null || (Object)(object)val10 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Failed to delete duplicated planet description.");
return;
}
Object.Destroy((Object)(object)val9);
Object.Destroy((Object)(object)val10);
Transform obj5 = val7.transform.Find("ArrowUI");
GameObject val11 = ((obj5 != null) ? ((Component)obj5).gameObject : null);
Transform val12 = val11.transform.Find("ArrowContainer");
if ((Object)(object)val11 == (Object)null || (Object)(object)val12 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Failed to get cloned ship arrow pointer.");
return;
}
Transform obj6 = val7.transform.Find("PlayerBeingMonitored");
TextMeshProUGUI val13 = ((obj6 != null) ? ((Component)obj6).GetComponent<TextMeshProUGUI>() : null);
((Behaviour)val13).enabled = true;
if ((Object)(object)val11 == (Object)null || (Object)(object)val12 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Failed to get cloned 'MONITORING:' text UI.");
return;
}
Animator componentInChildren = val5.GetComponentInChildren<Animator>();
if ((Object)(object)componentInChildren == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Failed to find new map flash animation.");
return;
}
Light componentInChildren2 = val5.GetComponentInChildren<Light>();
if ((Object)(object)componentInChildren2 == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Failed to find new map night vision light.");
return;
}
GameObject obj7 = GameObject.Find("Environment/HangarShip/Terminal");
if ((Object)(object)((obj7 != null) ? obj7.GetComponentInChildren<MeshRenderer>() : null) == (Object)null)
{
Plugin.Instance.Logger.LogError((object)"Failed to find terminal object mesh.");
return;
}
ManualCameraRenderer val14 = gameObject.AddComponent<ManualCameraRenderer>();
((Behaviour)val14).enabled = false;
val14.cam = val6;
val14.mapCamera = val6;
val14.cam.targetTexture = new RenderTexture(val3.cam.targetTexture)
{
name = "TerminalMapTexture",
filterMode = Plugin.TextureFiltering.Value
};
((Behaviour)val14.cam).enabled = false;
val14.shipArrowUI = val11;
val14.shipArrowPointer = val12;
val14.mapCameraAnimator = componentInChildren;
val14.mapCameraLight = componentInChildren2;
TerminalNode val15 = ((IEnumerable<CompatibleNoun>)((IEnumerable<TerminalKeyword>)Plugin.Terminal.terminalNodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword keyword) => keyword.word == "view"))?.compatibleNouns).FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun noun) => noun.noun.word == "monitor"))?.result;
if ((Object)(object)val15 != (Object)null)
{
val15.displayTexture = (Texture)(object)val14.cam.targetTexture;
Plugin.Instance.Logger.LogInfo((object)("Terminal node '" + ((Object)val15).name + "' will now use a separate texture."));
}
Plugin.TerminalMapRenderer = val14;
Plugin.TerminalMapScreenUICanvas = val8;
Plugin.TerminalMapScreenPlayerName = val13;
((Component)Plugin.Terminal.terminalUIScreen).gameObject.AddComponent<TerminalVisibilityTracker>();
val3.SyncOrderOfRadarBoostersInList();
Plugin.UpdateZoomFactors();
}
[HarmonyTranspiler]
[HarmonyPatch("RunTerminalEvents")]
[HarmonyPatch("ParsePlayerSentence")]
[HarmonyPatch("CheckForPlayerNameCommand")]
private static IEnumerable<CodeInstruction> TranspileRunTerminalEvents(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = instructions.ToList();
list.ReplaceMainMapWithTerminalMap();
return list;
}
[HarmonyPrefix]
[HarmonyPatch("RunTerminalEvents")]
private static bool RunTerminalEventsPrefix(TerminalNode __0)
{
return TerminalCommands.ProcessNode(__0);
}
}
internal static class PatchVanillaBugs
{
[HarmonyFinalizer]
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyAfter(new string[] { "Zaggy1024.OpenBodyCams" })]
private static void ConnectClientToPlayerObjectPostfix()
{
UpdateMonitoredPlayerNames();
OpenBodyCamsCompatibility.InitializeAtStartOfGame();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PlayerControllerB), "SendNewPlayerValuesClientRpc")]
private static IEnumerable<CodeInstruction> SendNewPlayerValuesClientRpcTranspiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Expected O, but got Unknown
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Expected O, but got Unknown
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Expected O, but got Unknown
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Expected O, but got Unknown
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Expected O, but got Unknown
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Expected O, but got Unknown
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Expected O, but got Unknown
MethodInfo method = typeof(ManualCameraRenderer).GetMethod("ChangeNameOfTargetTransform", new Type[2]
{
typeof(Transform),
typeof(string)
});
List<CodeInstruction> list = instructions.ToList();
int num = list.FindIndex((CodeInstruction insn) => CodeInstructionExtensions.StoresField(insn, Reflection.f_TransformAndName_name));
if (num == -1)
{
if (!Chainloader.PluginInfos.ContainsKey("mattymatty.LobbyControl"))
{
Plugin.Instance.Logger.LogWarning((object)"Failed to patch SendNewPlayerValuesClientRpc to set the correct transform index's name.");
Plugin.Instance.Logger.LogWarning((object)"LobbyControl is not installed, but another mod may have fixed this vanilla bug.");
}
return instructions;
}
SequenceMatch sequenceMatch = list.InstructionRangeForStackItems(num, 1, 1);
SequenceMatch sequenceMatch2 = list.InstructionRangeForStackItems(sequenceMatch.End - 1, 0, 0);
list.RemoveAt(num);
list.RemoveAbsoluteRange(sequenceMatch2.End, sequenceMatch.End);
list.RemoveAbsoluteRange(sequenceMatch.Start, sequenceMatch2.Start);
int start = sequenceMatch.Start;
CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[4]
{
new CodeInstruction(OpCodes.Call, (object)Reflection.m_StartOfRound_Instance),
new CodeInstruction(OpCodes.Ldfld, (object)Reflection.f_StartOfRound_mapScreen),
new CodeInstruction(OpCodes.Call, (object)Reflection.m_StartOfRound_Instance),
new CodeInstruction(OpCodes.Ldfld, (object)Reflection.f_StartOfRound_allPlayerScripts)
};
list.InsertRange(start, array);
start += array.Length;
start += sequenceMatch2.Size;
CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldelem, (object)typeof(PlayerControllerB)),
new CodeInstruction(OpCodes.Call, (object)Reflection.m_Component_Transform)
};
list.InsertRange(start, array2);
start += array2.Length;
start += num - sequenceMatch.End;
list.Insert(start, new CodeInstruction(OpCodes.Call, (object)method));
return list;
}
private static void UpdateMonitoredPlayerNames()
{
if (((NetworkBehaviour)StartOfRound.Instance).IsHost || ((NetworkBehaviour)StartOfRound.Instance).IsServer)
{
Plugin.EnsureAllMapRenderersHaveValidTargets();
}
}
[HarmonyPatch(typeof(StartOfRound), "OnClientConnect")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> OnClientConnectTranspiler(IEnumerable<CodeInstruction> instructions)
{
MethodInfo m_OnPlayerConnectedClientRpc = typeof(StartOfRound).GetMethod("OnPlayerConnectedClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);
foreach (CodeInstruction instruction in instructions)
{
yield return instruction;
if (CodeInstructionExtensions.Calls(instruction, m_OnPlayerConnectedClientRpc))
{
yield return new CodeInstruction(OpCodes.Call, (object)typeof(PatchVanillaBugs).GetMethod("SynchronizeMapTargetsToNewClient", BindingFlags.Static | BindingFlags.NonPublic));
}
}
}
private static void SynchronizeMapTargetsToNewClient()
{
StartOfRound.Instance.mapScreen.SwitchRadarTargetClientRpc(StartOfRound.Instance.mapScreen.targetTransformIndex);
Plugin.TerminalMapRenderer.SwitchRadarTargetClientRpc(Plugin.TerminalMapRenderer.targetTransformIndex);
}
}
public static class Reflection
{
public static readonly MethodInfo m_Component_Transform = typeof(Component).GetMethod("get_transform");
public static readonly MethodInfo m_StartOfRound_Instance = typeof(StartOfRound).GetMethod("get_Instance");
public static readonly FieldInfo f_StartOfRound_allPlayerScripts = typeof(StartOfRound).GetField("allPlayerScripts");
public static readonly FieldInfo f_StartOfRound_mapScreen = typeof(StartOfRound).GetField("mapScreen");
public static readonly FieldInfo f_StartOfRound_mapScreenPlayerName = typeof(StartOfRound).GetField("mapScreenPlayerName");
public static readonly FieldInfo f_StartOfRound_radarCanvas = typeof(StartOfRound).GetField("radarCanvas");
public static readonly FieldInfo f_Plugin_terminalMapRenderer = typeof(Plugin).GetField("TerminalMapRenderer");
public static readonly FieldInfo f_Plugin_terminalMapScreenUICanvas = typeof(Plugin).GetField("TerminalMapScreenUICanvas");
public static readonly FieldInfo f_Plugin_terminalMapScreenPlayerName = typeof(Plugin).GetField("TerminalMapScreenPlayerName");
public static readonly FieldInfo f_TransformAndName_name = typeof(TransformAndName).GetField("name");
public static readonly MethodInfo m_UnityEngine_Object_op_Equality = typeof(Object).GetMethod("op_Equality", new Type[2]
{
typeof(Object),
typeof(Object)
});
}
}
namespace TwoRadarMaps.Compatibility
{
internal static class EnhancedRadarBoosterCompatibility
{
internal const string ENHANCED_RADAR_BOOSTER_MOD_ID = "MrHydralisk.EnhancedRadarBooster";
internal const string IMMERSIVE_COMPANY_MOD_ID = "ImmersiveCompany";
private static MethodInfo m_MapCameraFocusOnPositionPostfixTranspiler;
internal static void Initialize(Harmony harmony)
{
m_MapCameraFocusOnPositionPostfixTranspiler = Common.GetMethod(typeof(EnhancedRadarBoosterCompatibility), "MapCameraFocusOnPositionPostfixTranspiler", BindingFlags.Static | BindingFlags.NonPublic, new Type[3]
{
typeof(IEnumerable<CodeInstruction>),
typeof(ILGenerator),
typeof(MethodBase)
});
if (m_MapCameraFocusOnPositionPostfixTranspiler == null)
{
Plugin.Instance.Logger.LogError((object)"MapCameraFocusOnPositionPostfixTranspiler was not found.");
Plugin.Instance.Logger.LogError((object)"Patches for MrHydralisk.EnhancedRadarBooster and ImmersiveCompany cannot be applied.");
return;
}
if (Chainloader.PluginInfos.ContainsKey("MrHydralisk.EnhancedRadarBooster"))
{
InitializeForEnhancedRadarBooster(harmony);
}
if (Chainloader.PluginInfos.ContainsKey("ImmersiveCompany"))
{
InitializeForImmersiveCompany(harmony);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeForEnhancedRadarBooster(Harmony harmony)
{
MethodInfo method = typeof(HarmonyPatches).GetMethod("MCR_MapCameraFocusOnPosition_Postfix", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(ManualCameraRenderer) }, null);
if (method == null)
{
Plugin.Instance.Logger.LogError((object)"MrHydralisk.EnhancedRadarBooster is present, but MCR_MapCameraFocusOnPosition_Postfix was not found.");
return;
}
try
{
harmony.CreateProcessor((MethodBase)method).AddTranspiler(m_MapCameraFocusOnPositionPostfixTranspiler).Patch();
}
catch (Exception ex)
{
Plugin.Instance.Logger.LogError((object)"Failed to transpile MrHydralisk.EnhancedRadarBooster's MCR_MapCameraFocusOnPosition_Postfix");
Plugin.Instance.Logger.LogError((object)ex);
}
Plugin.Instance.Logger.LogInfo((object)"Finished patching EnhancedRadarBooster for compatibility with the zoom command.");
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeForImmersiveCompany(Harmony harmony)
{
MethodInfo method = typeof(ManualCameraRendererPatch).GetMethod("MapCameraFocusPatch", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(ManualCameraRenderer) }, null);
if (method == null)
{
Plugin.Instance.Logger.LogError((object)"ImmersiveCompany is present, but MapCameraFocusPatch was not found.");
return;
}
try
{
harmony.CreateProcessor((MethodBase)method).AddTranspiler(m_MapCameraFocusOnPositionPostfixTranspiler).Patch();
}
catch (Exception ex)
{
Plugin.Instance.Logger.LogError((object)"Failed to transpile ImmersiveCompany's MapCameraFocusPatch");
Plugin.Instance.Logger.LogError((object)ex);
}
Plugin.Instance.Logger.LogInfo((object)"Finished patching ImmersiveCompany for compatibility with the zoom command.");
}
private static IEnumerable<CodeInstruction> MapCameraFocusOnPositionPostfixTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase method)
{
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Expected O, but got Unknown
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Expected O, but got Unknown
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Expected O, but got Unknown
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Expected O, but got Unknown
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Expected O, but got Unknown
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Expected O, but got Unknown
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Expected O, but got Unknown
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Expected O, but got Unknown
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Expected O, but got Unknown
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Expected O, but got Unknown
MethodInfo m_Camera_set_orthographicSize = typeof(Camera).GetMethod("set_orthographicSize");
FieldInfo field = typeof(TerminalCommands).GetField("CycleZoomNode");
List<CodeInstruction> list = instructions.ToList();
int startIndex = 0;
while (true)
{
startIndex = list.FindIndex(startIndex, (CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_Camera_set_orthographicSize));
if (startIndex == -1)
{
break;
}
Label label = generator.DefineLabel();
list[startIndex].labels.Add(label);
Label label2 = generator.DefineLabel();
list[startIndex + 1].labels.Add(label2);
CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[9]
{
new CodeInstruction(OpCodes.Ldsfld, (object)field),
new CodeInstruction(OpCodes.Brfalse_S, (object)label),
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Call, (object)Reflection.m_StartOfRound_Instance),
new CodeInstruction(OpCodes.Ldfld, (object)Reflection.f_StartOfRound_mapScreen),
new CodeInstruction(OpCodes.Beq_S, (object)label),
new CodeInstruction(OpCodes.Pop, (object)null),
new CodeInstruction(OpCodes.Pop, (object)null),
new CodeInstruction(OpCodes.Br_S, (object)label2)
};
list.InsertRange(startIndex, array);
startIndex += array.Length + 1;
}
list.InsertTerminalField(generator, new CodeInstruction(OpCodes.Ldarg_0, (object)null), Reflection.f_StartOfRound_radarCanvas, Reflection.f_Plugin_terminalMapScreenUICanvas);
return list;
}
}
internal static class LobbyControlCompatibility
{
internal const string MOD_ID = "mattymatty.LobbyControl";
}
internal static class OpenBodyCamsCompatibility
{
internal const string MOD_ID = "Zaggy1024.OpenBodyCams";
public static MonoBehaviour TerminalBodyCam;
private static bool ShouldUseCompatibilityMode()
{
if (!Chainloader.PluginInfos.ContainsKey("Zaggy1024.OpenBodyCams"))
{
return false;
}
if (Chainloader.PluginInfos["Zaggy1024.OpenBodyCams"].Metadata.Version < new Version(1, 2, 0))
{
return false;
}
return true;
}
internal static void Initialize()
{
if (ShouldUseCompatibilityMode())
{
InitializeInternal();
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeInternal()
{
Plugin.TerminalPiPBodyCamEnabled.SettingChanged += delegate
{
InitializeAtStartOfGameInternal();
};
Plugin.TerminalPiPPosition.SettingChanged += delegate
{
InitializeAtStartOfGameInternal();
};
Plugin.TerminalPiPWidth.SettingChanged += delegate
{
InitializeAtStartOfGameInternal();
};
}
internal static void InitializeAtStartOfGame()
{
if (ShouldUseCompatibilityMode())
{
InitializeAtStartOfGameInternal();
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeAtStartOfGameInternal()
{
Object.Destroy((Object)(object)TerminalBodyCam);
TerminalBodyCam = null;
if (!((Object)(object)TerminalCommands.PiPImage == (Object)null))
{
BodyCamComponent val = (BodyCamComponent)(object)(TerminalBodyCam = (MonoBehaviour)(object)BodyCam.CreateBodyCam(((Component)Plugin.Terminal).gameObject, (Material)null, Plugin.TerminalMapRenderer));
ShipObjects.MainBodyCam.OnRenderTextureCreated -= TerminalCommands.SetRenderTexture;
val.OnRenderTextureCreated += SetBodyCamTexture;
SetBodyCamTexture(val.GetCamera().targetTexture);
ShipObjects.MainBodyCam.OnBlankedSet -= TerminalCommands.SetBodyCamBlanked;
val.OnBlankedSet += SetBodyCamBlanked;
UpdateTerminalBodyCamSettings();
Plugin.BodyCamHorizontalResolution.SettingChanged += delegate
{
UpdateTerminalBodyCamSettings();
};
((Component)TerminalCommands.PiPImage).GetComponent<TerminalBodyCamVisibilityTracker>().BodyCamToActivate = val;
}
}
private static void UpdateTerminalBodyCamSettings()
{
try
{
UpdateTerminalBodyCamResolution();
}
catch
{
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void UpdateTerminalBodyCamResolution()
{
//IL_001d: 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)
int value = Plugin.BodyCamHorizontalResolution.Value;
Vector2Int resolution = default(Vector2Int);
((Vector2Int)(ref resolution))..ctor(value, value * 3 / 4);
((BodyCamComponent)TerminalBodyCam).Resolution = resolution;
}
public static void UpdateBodyCamTexture()
{
UpdateBodyCamTextureInternal();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void UpdateBodyCamTextureInternal()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
SetBodyCamTexture(((BodyCamComponent)TerminalBodyCam).GetCamera().targetTexture);
}
private static void SetBodyCamTexture(RenderTexture texture)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
((Texture)texture).filterMode = Plugin.TextureFiltering.Value;
TerminalCommands.PiPImage.texture = (Texture)(object)texture;
}
private static void SetBodyCamBlanked(bool blanked)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
((Graphic)TerminalCommands.PiPImage).color = (blanked ? Color.black : Color.white);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
int ICollection.Count => _items.Length;
bool ICollection.IsSynchronized => false;
object ICollection.SyncRoot => this;
object IList.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
bool IList.IsFixedSize => true;
bool IList.IsReadOnly => true;
int IReadOnlyCollection<T>.Count => _items.Length;
T IReadOnlyList<T>.this[int index] => _items[index];
int ICollection<T>.Count => _items.Length;
bool ICollection<T>.IsReadOnly => true;
T IList<T>.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
public <>z__ReadOnlyArray(T[] items)
{
_items = items;
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)_items).GetEnumerator();
}
void ICollection.CopyTo(Array array, int index)
{
((ICollection)_items).CopyTo(array, index);
}
int IList.Add(object value)
{
throw new NotSupportedException();
}
void IList.Clear()
{
throw new NotSupportedException();
}
bool IList.Contains(object value)
{
return ((IList)_items).Contains(value);
}
int IList.IndexOf(object value)
{
return ((IList)_items).IndexOf(value);
}
void IList.Insert(int index, object value)
{
throw new NotSupportedException();
}
void IList.Remove(object value)
{
throw new NotSupportedException();
}
void IList.RemoveAt(int index)
{
throw new NotSupportedException();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return ((IEnumerable<T>)_items).GetEnumerator();
}
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
void ICollection<T>.Clear()
{
throw new NotSupportedException();
}
bool ICollection<T>.Contains(T item)
{
return ((ICollection<T>)_items).Contains(item);
}
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
((ICollection<T>)_items).CopyTo(array, arrayIndex);
}
bool ICollection<T>.Remove(T item)
{
throw new NotSupportedException();
}
int IList<T>.IndexOf(T item)
{
return ((IList<T>)_items).IndexOf(item);
}
void IList<T>.Insert(int index, T item)
{
throw new NotSupportedException();
}
void IList<T>.RemoveAt(int index)
{
throw new NotSupportedException();
}
}
internal sealed class <>z__ReadOnlyList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
int ICollection.Count => _items.Count;
bool ICollection.IsSynchronized => false;
object ICollection.SyncRoot => this;
object IList.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
bool IList.IsFixedSize => true;
bool IList.IsReadOnly => true;
int IReadOnlyCollection<T>.Count => _items.Count;
T IReadOnlyList<T>.this[int index] => _items[index];
int ICollection<T>.Count => _items.Count;
bool ICollection<T>.IsReadOnly => true;
T IList<T>.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
public <>z__ReadOnlyList(List<T> items)
{
_items = items;
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)_items).GetEnumerator();
}
void ICollection.CopyTo(Array array, int index)
{
((ICollection)_items).CopyTo(array, index);
}
int IList.Add(object value)
{
throw new NotSupportedException();
}
void IList.Clear()
{
throw new NotSupportedException();
}
bool IList.Contains(object value)
{
return ((IList)_items).Contains(value);
}
int IList.IndexOf(object value)
{
return ((IList)_items).IndexOf(value);
}
void IList.Insert(int index, object value)
{
throw new NotSupportedException();
}
void IList.Remove(object value)
{
throw new NotSupportedException();
}
void IList.RemoveAt(int index)
{
throw new NotSupportedException();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return ((IEnumerable<T>)_items).GetEnumerator();
}
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
void ICollection<T>.Clear()
{
throw new NotSupportedException();
}
bool ICollection<T>.Contains(T item)
{
return _items.Contains(item);
}
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
_items.CopyTo(array, arrayIndex);
}
bool ICollection<T>.Remove(T item)
{
throw new NotSupportedException();
}
int IList<T>.IndexOf(T item)
{
return _items.IndexOf(item);
}
void IList<T>.Insert(int index, T item)
{
throw new NotSupportedException();
}
void IList<T>.RemoveAt(int index)
{
throw new NotSupportedException();
}
}