using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MissionRework")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MissionRework")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1378a4e9-1f10-4206-862b-1ce097b407ee")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MissionRework;
public static class Extensions
{
public static object GetPrivateField(this object obj, string field)
{
return Traverse.Create(obj).Field(field).GetValue();
}
public static T GetPrivateField<T>(this object obj, string field)
{
return (T)obj.GetPrivateField(field);
}
public static object GetPrivateField<T>(string field)
{
return Traverse.Create(typeof(T)).Field(field).GetValue();
}
public static T GetPrivateField<T, E>(string field)
{
return (T)GetPrivateField<E>(field);
}
public static void SetPrivateField(this object obj, string field, object value)
{
Traverse.Create(obj).Field(field).SetValue(value);
}
public static void SetPrivateField<T>(string field, object value)
{
Traverse.Create(typeof(T)).Field(field).SetValue(value);
}
public static object InvokePrivateMethod(this object obj, string method, params object[] parameters)
{
return AccessTools.Method(obj.GetType(), method, (Type[])null, (Type[])null).Invoke(obj, parameters);
}
public static T InvokePrivateMethod<T>(this object obj, string method, params object[] parameters)
{
return (T)obj.InvokePrivateMethod(method, parameters);
}
public static object InvokePrivateMethod<T>(string method, params object[] parameters)
{
return AccessTools.Method(typeof(T), method, (Type[])null, (Type[])null).Invoke(null, parameters);
}
public static T InvokePrivateMethod<T, E>(string method, params object[] parameters)
{
return (T)InvokePrivateMethod<E>(method, parameters);
}
public static T GetCopyOf<T>(this Component comp, T other) where T : Component
{
Type type = ((object)comp).GetType();
if (type != ((object)other).GetType())
{
return default(T);
}
BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
PropertyInfo[] properties = type.GetProperties(bindingAttr);
PropertyInfo[] array = properties;
foreach (PropertyInfo propertyInfo in array)
{
if (propertyInfo.CanWrite)
{
try
{
propertyInfo.SetValue(comp, propertyInfo.GetValue(other, null), null);
}
catch
{
}
}
}
FieldInfo[] fields = type.GetFields(bindingAttr);
FieldInfo[] array2 = fields;
foreach (FieldInfo fieldInfo in array2)
{
fieldInfo.SetValue(comp, fieldInfo.GetValue(other));
}
return (T)(object)((comp is T) ? comp : null);
}
public static Transform GetChildByName(this Transform transform, string childName)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
foreach (Transform item in transform)
{
Transform val = item;
if (((Object)val).name == childName)
{
return val;
}
}
return null;
}
}
public enum MissionType
{
Available,
Active,
Last
}
internal class GPMissionTypeButton : GoPointerButton
{
public TextMesh text;
public static Port currentPort;
public static PortDude portDude;
public static MissionType missionType = MissionType.Available;
private static string[] sortingStrings = new string[2] { "Available", "Active" };
public override void OnActivate()
{
if (missionType == MissionType.Available)
{
missionType = MissionType.Active;
}
else
{
missionType = MissionType.Available;
}
UpdateMissions();
UpdateText();
}
public static void UpdateMissions()
{
if ((Object)(object)currentPort != (Object)null)
{
switch (missionType)
{
case MissionType.Active:
MissionListUI.instance.EnablePortMissionUI(PlayerMissions.missions, portDude.GetPrivateField<Transform>("missionTable"), portDude);
MissionListUI.instance.GetPrivateField<GameObject>("pageButtons").SetActive(false);
MissionListUI.instance.SetPrivateField("closeCooldown", 0f);
break;
case MissionType.Available:
MissionListUI.instance.EnablePortMissionUI(currentPort.GetPrivateField<Mission[]>("missions"), portDude.GetPrivateField<Transform>("missionTable"), portDude);
MissionListUI.instance.ChangePage(0);
MissionListUI.instance.SetPrivateField("closeCooldown", 0f);
MissionListUI.instance.InvokePrivateMethod("UpdatePageCountText");
break;
}
}
}
public void UpdateText()
{
string text = missionType.ToString();
if ((int)missionType < sortingStrings.Length)
{
text = sortingStrings[(int)missionType];
}
this.text.text = "Showing: " + text;
}
}
[BepInPlugin("com.nandbrew.missionrework", "Mission Rework", "1.0.3")]
internal class Main : BaseUnityPlugin
{
public const string GUID = "com.nandbrew.missionrework";
public const string NAME = "Mission Rework";
public const string VERSION = "1.0.3";
internal static ConfigEntry<bool> safety;
private void Awake()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.nandbrew.missionrework");
safety = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Safety", false, new ConfigDescription("\"Abandon\" button will read \"(wrong port)\" or \"(no goods in area)\" and must be clicked twice", (AcceptableValueBase)null, Array.Empty<object>()));
}
}
internal class MissionPatches
{
[HarmonyPatch(typeof(MissionListUI))]
private class MissionListUIPatches
{
[HarmonyPostfix]
[HarmonyPatch("EnablePortMissionUI")]
public static void EnablePortMissionUIPatch()
{
Refs.SetPlayerControl(false);
}
[HarmonyPostfix]
[HarmonyPatch("DisablePortMissionUI")]
public static void DisablePortMissionUIPatch()
{
Refs.SetPlayerControl(true);
}
[HarmonyPrefix]
[HarmonyPatch("ToggleMenu")]
public static bool ToggleMenuPatch(MissionListUI __instance, bool ___UIActive)
{
sortButton.SetActive(false);
backButton.SetActive(false);
acceptCancelButton.SetActive(false);
return true;
}
}
[HarmonyPatch(typeof(IslandMarketWarehouseArea))]
private static class MissionGoodRegistrationPatch
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
public static void Register(IslandMarketWarehouseArea __instance, IslandMarket ___market)
{
currentPortIndex = ___market.GetPortIndex();
if (!portLists.ContainsKey(currentPortIndex))
{
portLists.Add(currentPortIndex, new List<Good>());
}
}
[HarmonyPostfix]
[HarmonyPatch("OnTriggerEnter")]
public static void OnTriggerEnterPatch(IslandMarketWarehouseArea __instance, Collider other, IslandMarket ___market)
{
currentPortIndex = ___market.GetPortIndex();
currentMarket = ___market;
if (!portLists.ContainsKey(currentPortIndex))
{
portLists.Add(currentPortIndex, new List<Good>());
}
Good component = ((Component)other).GetComponent<Good>();
List<Good> list = portLists[currentPortIndex];
if (Object.op_Implicit((Object)(object)component) && !list.Contains(component) && component.GetMissionIndex() != -1)
{
list.Add(component);
}
}
[HarmonyPostfix]
[HarmonyPatch("OnTriggerExit")]
public static void OnTriggerExitPatch(IslandMarketWarehouseArea __instance, Collider other, IslandMarket ___market)
{
currentPortIndex = ___market.GetPortIndex();
currentMarket = ___market;
List<Good> list = portLists[currentPortIndex];
Good component = ((Component)other).GetComponent<Good>();
if (Object.op_Implicit((Object)(object)component) && list.Contains(component))
{
list.Remove(component);
}
}
}
[HarmonyPatch(typeof(MissionDetailsUI))]
private static class MissionDetailsUiPatch
{
[HarmonyPrefix]
[HarmonyPatch("Start")]
public static void StartPatch(MissionDetailsUI __instance, GameObject ___UI)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Expected O, but got Unknown
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Expected O, but got Unknown
foreach (Transform item in ___UI.transform.parent)
{
Transform val = item;
if (!(((Object)val).name == "current mission buttons"))
{
continue;
}
foreach (Transform item2 in val)
{
Transform val2 = item2;
if (((Object)val2).name == "page buttons")
{
GameObject gameObject = ((Component)val2.Find("mission button (back)")).gameObject;
GameObject val3 = Object.Instantiate<GameObject>(gameObject);
val3.transform.parent = val;
gameObject.transform.parent = val;
Transform transform = val3.transform;
Vector3 localPosition = gameObject.transform.localPosition;
transform.localPosition = new Vector3(((Vector3)(ref localPosition))[0], 0.22f, 0.03f);
val3.transform.localRotation = gameObject.transform.localRotation;
val3.transform.localScale = gameObject.transform.localScale;
((Object)val3).name = "sort button";
GameObject gameObject2 = ((Component)val3.GetComponentInChildren<GoPointerButton>()).gameObject;
Object.Destroy((Object)(object)gameObject2.GetComponent<GoPointerButton>());
GPMissionTypeButton gPMissionTypeButton = gameObject2.AddComponent<GPMissionTypeButton>();
gPMissionTypeButton.text = val3.GetComponentInChildren<TextMesh>();
gPMissionTypeButton.UpdateText();
MissionListUI.instance.SetPrivateField("closeCooldown", 0f);
sortButton = val3;
backButton = gameObject;
val3.SetActive(false);
}
}
}
foreach (Transform item3 in ___UI.transform)
{
Transform val4 = item3;
foreach (Transform item4 in val4)
{
Transform val5 = item4;
if (((Object)val5).name == "accept/cancel button")
{
acceptCancelButton = ((Component)val5).gameObject;
}
}
}
}
[HarmonyPrefix]
[HarmonyPatch("ClickButton")]
public static bool ClickButton(MissionDetailsUI __instance, ref bool ___clickable, bool ___mapZoomedIn, ref Mission ___currentMission, ref GameObject ___UI, ref TextMesh ___buttonText)
{
int portIndex = ___currentMission.destinationPort.portIndex;
if (GPMissionTypeButton.missionType == MissionType.Available)
{
return true;
}
List<Good> list = portLists[portIndex];
if (!___mapZoomedIn && ___currentMission.missionIndex != -1)
{
if (___clickable)
{
if (currentPortIndex == portIndex && list.Count > 0)
{
int num = 0;
while (num < list.Count)
{
if (___currentMission == list[num].GetAssignedMission())
{
list[num].Deliver();
list.Remove(list[num]);
}
else
{
num++;
}
}
int num2 = ___currentMission.goodCount - ___currentMission.GetDeliveredCount();
if (num2 > 0)
{
int num3 = num2 * 100;
___currentMission.AbandonMission();
NotificationUi.instance.ShowNotification("Ended mission:\n" + ___currentMission.missionName + "\nReputation penalty: " + num3);
UISoundPlayer.instance.PlayWritingSound();
PlayerMissions.missions[___currentMission.missionIndex] = null;
LoggedMission obj = MissionLog.instance.loggedMissions[0];
obj.totalRep -= num3;
MissionLog.instance.UpdateTexts();
}
MissionListUI.instance.RefreshList();
__instance.InvokePrivateMethod("UpdateTexts");
MissionListUI.instance.GetPrivateField<GameObject>("book").SetActive(false);
MissionListUI.instance.GetPrivateField<PortDude>("currentPortDude").ActivateMissionListUI(false);
foreach (Good item in portLists[currentPortIndex])
{
((Component)item).GetComponent<ShipItem>().GetItemRigidbody().InvokePrivateMethod("SetDynamicColTimer");
}
}
else
{
PlayerMissions.AbandonMission(___currentMission.missionIndex);
MissionListUI.instance.RefreshList();
MissionListUI.instance.GetPrivateField<GameObject>("book").SetActive(false);
MissionListUI.instance.GetPrivateField<PortDude>("currentPortDude").ActivateMissionListUI(false);
Debug.Log((object)"Button Clicked!");
}
}
else
{
___buttonText.text = "Abandon";
___clickable = true;
}
}
return false;
}
[HarmonyPostfix]
[HarmonyPatch("UpdateTexts")]
private static void UpdateTextsPatch(ref bool ___clickable, ref TextMesh ___buttonText, Mission ___currentMission, ref TextMesh ___amount)
{
int portIndex = ___currentMission.destinationPort.portIndex;
List<Good> list = portLists[currentPortIndex];
if (___currentMission.missionIndex == -1 || !((Object)(object)MissionListUI.instance.GetPrivateField<PortDude>("currentPortDude") != (Object)null))
{
return;
}
___amount.text = ___currentMission.GetDeliveredCount() + " / " + ___amount.text;
int num = 0;
foreach (Good item in list)
{
if (___currentMission == item.GetAssignedMission())
{
num++;
}
}
if (currentPortIndex == portIndex)
{
if (num > 0)
{
if (num < ___currentMission.goodCount)
{
___buttonText.text = "Deliver\npartial (" + num + ")";
}
if (num >= ___currentMission.goodCount)
{
___buttonText.text = "Deliver all";
}
___clickable = true;
}
else if (Main.safety.Value)
{
___buttonText.text = "(no goods\nin area)";
___clickable = false;
}
}
else if (Main.safety.Value)
{
___buttonText.text = "(wrong port)";
___clickable = false;
}
}
}
[HarmonyPatch(typeof(PortDude))]
private static class ActivateMissionListUIPatch
{
[HarmonyPrefix]
[HarmonyPatch("ActivateMissionListUI")]
public static bool ActivateMissionListUI(PortDude __instance, bool openEconomyUI)
{
if (!openEconomyUI)
{
GPMissionTypeButton.currentPort = __instance.GetPort();
GPMissionTypeButton.portDude = __instance;
sortButton.SetActive(true);
backButton.SetActive(true);
acceptCancelButton.SetActive(true);
GPMissionTypeButton.UpdateMissions();
return false;
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch("DeactivateMissionListUI")]
public static void DeactivateMissionListUI(PortDude __instance)
{
GPMissionTypeButton.currentPort = null;
GPMissionTypeButton.portDude = null;
sortButton.SetActive(false);
backButton.SetActive(false);
}
[HarmonyPrefix]
[HarmonyPatch("OnTriggerEnter")]
public static bool OnTriggerEnter()
{
return false;
}
}
[HarmonyPatch(typeof(PlayerMissions))]
private static class PlayerMissionsPatches
{
[HarmonyPrefix]
[HarmonyPatch("AbandonMission")]
public static bool AbandonMissionPatch(int missionIndex)
{
int num = -100 * (PlayerMissions.missions[missionIndex].goodCount - PlayerMissions.missions[missionIndex].GetDeliveredCount());
PlayerMissions.missions[missionIndex].destinationPort.IncreaseDemand(PlayerMissions.missions[missionIndex]);
PlayerMissions.missions[missionIndex].AbandonMission();
NotificationUi.instance.ShowNotification("Abandoning mission:\n" + PlayerMissions.missions[missionIndex].missionName + "\n" + num + " reputation");
PlayerMissions.missions[missionIndex] = null;
return false;
}
}
private static GameObject sortButton;
private static GameObject backButton;
private static GameObject acceptCancelButton;
public static int currentPortIndex;
public static Dictionary<int, List<Good>> portLists = new Dictionary<int, List<Good>>();
private static IslandMarket currentMarket;
}