using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ESN.StarterPack.NetcodePatcher;
using EasyTextEffects.Editor.MyBoxCopy.Extensions;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using StarterPack.Patches;
using TerminalApi;
using TerminalApi.Classes;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ESN.StarterPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.7.0")]
[assembly: AssemblyInformationalVersion("1.0.7+f78ce78f50ea23420e56e135a03822afdf103a1f")]
[assembly: AssemblyProduct("StarterPack")]
[assembly: AssemblyTitle("ESN.StarterPack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
}
}
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 StarterPack
{
internal class Commands
{
public static string DefaultCMD()
{
return "Not Yet Implemented";
}
public static string TestCMD()
{
Terminal val = Object.FindObjectOfType<Terminal>();
TerminalAccessibleObject[] array = Object.FindObjectsOfType<TerminalAccessibleObject>();
StarterPack.Logger.LogInfo((object)$"Found {array.Length} objectsOfType");
TerminalAccessibleObject[] array2 = array;
foreach (TerminalAccessibleObject val2 in array2)
{
StarterPack.Logger.LogInfo((object)$"{val2}");
StarterPack.Logger.LogInfo((object)$"\t{val2.terminalCodeEvent}");
StarterPack.Logger.LogInfo((object)("\t" + ((Object)((Component)val2).transform).name));
StarterPack.Logger.LogInfo((object)("\t" + ((Object)((Component)val2).transform.parent).name));
}
return "Success\n";
}
public static string CheckTimeCMD()
{
float normalizedTimeOfDay = TimeOfDay.Instance.normalizedTimeOfDay;
int numberOfHours = TimeOfDay.Instance.numberOfHours;
int num = (int)(normalizedTimeOfDay * (60f * (float)numberOfHours)) + 360;
int num2 = (int)Mathf.Floor((float)(num / 60));
string text;
if (num2 >= 24)
{
text = "12:00 AM";
}
else
{
string text2 = ((num2 >= 12) ? " PM" : " AM");
if (num2 > 12)
{
num2 %= 12;
}
int num3 = num % 60;
text = $"{num2:00}:{num3:00}".TrimStart('0') + text2;
}
if (StartOfRound.Instance.currentLevel.planetHasTime && StartOfRound.Instance.shipDoorsEnabled)
{
return "The time is currently " + text + ".\n";
}
return "You're not on a moon. There is no time here.\n";
}
}
public class ExampleNetworkHandler : NetworkBehaviour
{
public static ExampleNetworkHandler Instance { get; private set; }
public static event Action<string> LevelEvent;
public override void OnNetworkSpawn()
{
StarterPack.Logger.LogError((object)"OnNetworkSpawn() called");
ExampleNetworkHandler.LevelEvent = null;
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
{
ExampleNetworkHandler instance = Instance;
if (instance != null)
{
((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
}
}
Instance = this;
((NetworkBehaviour)this).OnNetworkSpawn();
}
[ClientRpc]
public void EventClientRpc(string eventName)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2946218065u, val, (RpcDelivery)0);
bool flag = eventName != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(eventName, false);
}
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2946218065u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
StarterPack.Logger.LogError((object)"EventClientRpc() called");
StarterPack.Logger.LogError((object)("LevelEvent is " + ((ExampleNetworkHandler.LevelEvent == null) ? "NULL" : "Not null")));
ExampleNetworkHandler.LevelEvent?.Invoke(eventName);
}
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_ExampleNetworkHandler()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(2946218065u, new RpcReceiveHandler(__rpc_handler_2946218065));
}
private static void __rpc_handler_2946218065(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string eventName = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref eventName, false);
}
target.__rpc_exec_stage = (__RpcExecStage)2;
((ExampleNetworkHandler)(object)target).EventClientRpc(eventName);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
protected internal override string __getTypeName()
{
return "ExampleNetworkHandler";
}
}
[HarmonyPatch]
public class NetworkObjectManager
{
private static GameObject networkPrefab;
[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
public static void Init()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
if (!((Object)(object)networkPrefab != (Object)null))
{
networkPrefab = (GameObject)StarterPack.Assets.LoadAsset("ExampleNetworkHandler");
networkPrefab.AddComponent<ExampleNetworkHandler>();
NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
StarterPack.Logger.LogError((object)"ExampleNetworkHandler successfully added");
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "Awake")]
private static void SpawnNetworkHandler()
{
//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)
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
{
GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
val.GetComponent<NetworkObject>().Spawn(false);
StarterPack.Logger.LogError((object)"NetworkObject successfully spawned");
}
}
}
[BepInPlugin("ESN.StarterPack", "StarterPack", "1.0.7")]
[BepInDependency("atomic.terminalapi", "1.5.0")]
public class StarterPack : BaseUnityPlugin
{
public static ConfigEntry<string> configGreeting;
public static ConfigEntry<bool> configDisplayGreeting;
public static ConfigEntry<bool> configEnableTests;
public static ConfigEntry<bool> configFreeTeleporter;
public static ConfigEntry<bool> configFreeInverseTeleporter;
public static ConfigEntry<bool> configWalkie;
public static ConfigEntry<bool> configStartWithExtraCredits;
public static ConfigEntry<int> configStartWithExtraCreditsValue;
public static AssetBundle Assets;
public static StarterPack Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony Harmony { get; set; }
private void SetupConfigBinds()
{
configGreeting = ((BaseUnityPlugin)this).Config.Bind<string>("General", "GreetingText", "Hello, world!", "A greeting text to show when the game is launched");
configDisplayGreeting = ((BaseUnityPlugin)this).Config.Bind<bool>("General.Toggles", "DisplayGreeting", true, "Whether or not to show the greeting text");
configEnableTests = ((BaseUnityPlugin)this).Config.Bind<bool>("General.Toggles", "EnableTests", false, "Enable test features and debug functionality");
configFreeTeleporter = ((BaseUnityPlugin)this).Config.Bind<bool>("Items", "FreeTeleporter", true, "Automatically unlock teleporter at game start");
configFreeInverseTeleporter = ((BaseUnityPlugin)this).Config.Bind<bool>("Items", "FreeInverseTeleporter", false, "Automatically unlock inverse teleporter at game start");
configWalkie = ((BaseUnityPlugin)this).Config.Bind<bool>("Items", "FreeWalkie", false, "Start with free walkie-talkie. Not yet implemented !");
configStartWithExtraCredits = ((BaseUnityPlugin)this).Config.Bind<bool>("Economy", "StartWithExtraCredits", false, "Start new games with extra credits");
configStartWithExtraCreditsValue = ((BaseUnityPlugin)this).Config.Bind<int>("Economy", "StartingCreditsAmount", 101, "Starting credit value (if enabled)");
}
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
SetupConfigBinds();
LoadAssets();
Patch();
CreateTerminalCommands();
if (configDisplayGreeting.Value)
{
Logger.LogDebug((object)configGreeting.Value);
}
Logger.LogInfo((object)"ESN.StarterPack v1.0.7 has loaded!");
}
private static void LoadAssets()
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Assets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "assets/esnassets"));
if ((Object)(object)Assets == (Object)null)
{
Logger.LogError((object)"Failed to load custom assets.");
return;
}
Logger.LogDebug((object)"Assets loaded");
string[] allAssetNames = Assets.GetAllAssetNames();
string[] array = allAssetNames;
foreach (string text in array)
{
Logger.LogDebug((object)(text ?? ""));
}
}
private static void CreateTerminalCommands()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
CommandInfo val = new CommandInfo();
val.Category = "other";
val.Description = "Displays the current time.";
val.DisplayTextSupplier = Commands.CheckTimeCMD;
TerminalApi.AddCommand("time", val, "check", true);
val = new CommandInfo();
val.Category = "other";
val.Description = "Testing command";
val.DisplayTextSupplier = Commands.TestCMD;
TerminalApi.AddCommand("test", val, (string)null, true);
}
private static void NetcodePatcher()
{
Logger.LogDebug((object)"Patching netcode...");
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array2 = methods;
foreach (MethodInfo methodInfo in array2)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
Logger.LogDebug((object)"Patching netcode... complete");
}
internal void Patch()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("ESN.StarterPack");
}
Logger.LogDebug((object)"Patching...");
if (configEnableTests.Value)
{
Harmony.PatchAll();
NetcodePatcher();
}
else if (configStartWithExtraCredits.Value || configFreeTeleporter.Value || configFreeInverseTeleporter.Value)
{
Logger.LogDebug((object)"Patching StartWithExtras");
Harmony.PatchAll(typeof(StartWithExtras));
Harmony.PatchAll(typeof(TestTerminalNodePatch));
}
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ESN.StarterPack";
public const string PLUGIN_NAME = "StarterPack";
public const string PLUGIN_VERSION = "1.0.7";
}
}
namespace StarterPack.Patches
{
[HarmonyPatch(typeof(ManualCameraRenderer))]
public class ExampleScreenPatch
{
[HarmonyPatch("SwitchScreenButton")]
[HarmonyPostfix]
private static void SwitchScreenButton(ManualCameraRenderer __instance)
{
StarterPack.Logger.LogDebug((object)"SwitchScreenButton() called");
StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.isScreenOn);
}
}
[HarmonyPatch(typeof(TVScript))]
public class ExampleTVPatch
{
[HarmonyPatch("SwitchTVLocalClient")]
[HarmonyPostfix]
private static void SwitchTVPrefix(TVScript __instance)
{
StarterPack.Logger.LogDebug((object)"SwitchTVPrefix() called");
StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.tvOn);
}
[HarmonyPatch("TurnTVOnOff")]
[HarmonyPrefix]
public static bool TurnTVOnOff(bool on, TVScript __instance)
{
StarterPack.Logger.LogDebug((object)"TurnTVOnOff() called");
return false;
}
}
[HarmonyPatch(typeof(ShipLights))]
public class LightPatch
{
[HarmonyPatch("ToggleShipLights")]
[HarmonyPostfix]
private static void ToggleShipLightsPostfix(ShipLights __instance)
{
bool areLightsOn = __instance.areLightsOn;
StarterPack.Logger.LogDebug((object)"ToggleShipLightsPostfix() called");
StarterPack.Logger.LogDebug((object)$"Lights are {areLightsOn}");
ManualCameraRenderer val = Object.FindObjectOfType<ManualCameraRenderer>();
Terminal val2 = Object.FindAnyObjectByType<Terminal>();
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
{
int groupCredits = 500;
val2.useCreditsCooldown = true;
val2.groupCredits = groupCredits;
val2.SyncGroupCreditsServerRpc(val2.groupCredits, val2.numberOfItemsInDropship);
}
NetworkTest.SendEventToClients("light");
if (val != null && MyReflection.HasMethod((object)val, "SwitchScreenOn"))
{
StarterPack.Logger.LogDebug((object)$"TVon is {val.isScreenOn}");
}
else
{
StarterPack.Logger.LogDebug((object)("Could not find 'ManualCameraRenderer' : " + (object)val));
}
}
}
[HarmonyPatch]
internal class NetworkTest
{
[HarmonyPostfix]
[HarmonyPatch(typeof(RoundManager), "GenerateNewFloor")]
private static void SubscribeToHandler()
{
StarterPack.Logger.LogError((object)"SubscribeToHandler() called");
ExampleNetworkHandler.LevelEvent += ReceivedEventFromServer;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
private static void UnsubscribeFromHandler()
{
StarterPack.Logger.LogError((object)"UnsubscribeFromHandler() called");
ExampleNetworkHandler.LevelEvent -= ReceivedEventFromServer;
}
private static void ReceivedEventFromServer(string eventName)
{
StarterPack.Logger.LogError((object)"Successfully received RPC");
}
public static void SendEventToClients(string eventName)
{
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
{
StarterPack.Logger.LogError((object)"Sending RPC...");
ExampleNetworkHandler.Instance.EventClientRpc(eventName);
}
}
}
[HarmonyPatch(typeof(GrabbableObject))]
public class PatchGrabbable
{
[HarmonyPatch("EquipItem")]
[HarmonyPostfix]
private static void EquipItemPostfix(GrabbableObject __instance)
{
string itemName = __instance.itemProperties.itemName;
StarterPack.Logger.LogDebug((object)itemName);
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class StartWithExtras
{
private static readonly string TELEPORTER_NAME = "Teleporter";
private static readonly string INVERSE_NAME = "Inverse Teleporter";
private static int teleporterID = -1;
private static int inverseTeleporterID = -1;
private static bool idsInitialized;
private static bool isFirstDayAboutToStart = false;
private static bool gameAlreadyReset = false;
private static void getTeleporterIDs(StartOfRound instance)
{
StarterPack.Logger.LogInfo((object)"Getting item IDs");
for (int i = 0; i < instance.unlockablesList.unlockables.Count; i++)
{
UnlockableItem val = instance.unlockablesList.unlockables[i];
string text = val.unlockableName.ToLower();
if (text.Equals(TELEPORTER_NAME.ToLower()))
{
StarterPack.Logger.LogInfo((object)$"{TELEPORTER_NAME} ID: {i}");
teleporterID = i;
}
else if (text.Equals(INVERSE_NAME.ToLower()))
{
StarterPack.Logger.LogInfo((object)$"{INVERSE_NAME} ID: {i}");
inverseTeleporterID = i;
}
}
idsInitialized = true;
}
private static void setCredits(int credits)
{
Terminal val = Object.FindAnyObjectByType<Terminal>();
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
{
val.useCreditsCooldown = true;
val.groupCredits = credits;
val.SyncGroupCreditsServerRpc(val.groupCredits, val.numberOfItemsInDropship);
}
}
private static void UnlockShipItem(int id)
{
StartOfRound instance = StartOfRound.Instance;
if (!instance.unlockablesList.unlockables[id].hasBeenUnlockedByPlayer)
{
int groupCredits = Object.FindObjectOfType<Terminal>().groupCredits;
instance.BuyShipUnlockableServerRpc(id, groupCredits);
}
else
{
StarterPack.Logger.LogError((object)$"Ship Unlockable id={id} already unlocked...");
}
}
private static void ApplyGifts()
{
StarterPack.Logger.LogDebug((object)"Applying first day on the job gifts");
StartOfRound instance = StartOfRound.Instance;
if (((NetworkBehaviour)instance).NetworkManager.IsHost || ((NetworkBehaviour)instance).NetworkManager.IsServer)
{
if (StarterPack.configFreeTeleporter.Value)
{
if (!idsInitialized)
{
getTeleporterIDs(instance);
}
StarterPack.Logger.LogDebug((object)"Unlocking teleporter...");
UnlockShipItem(teleporterID);
}
if (StarterPack.configFreeInverseTeleporter.Value)
{
if (!idsInitialized)
{
getTeleporterIDs(instance);
}
StarterPack.Logger.LogDebug((object)"Unlocking inverse teleporter...");
UnlockShipItem(inverseTeleporterID);
}
if (StarterPack.configStartWithExtraCredits.Value)
{
StarterPack.Logger.LogDebug((object)$"Setting start credits to {StarterPack.configStartWithExtraCreditsValue.Value}");
setCredits(StarterPack.configStartWithExtraCreditsValue.Value);
}
}
else
{
StarterPack.Logger.LogInfo((object)"User is not host. Not applying starting gifts");
}
}
[HarmonyPatch(typeof(StartOfRound), "PlayFirstDayShipAnimation")]
[HarmonyPostfix]
private static void PlayFirstDayShipAnimationPatch(StartOfRound __instance)
{
StarterPack.Logger.LogDebug((object)"PlayFirstDayShipAnimationPatch() called");
if (!gameAlreadyReset)
{
gameAlreadyReset = false;
isFirstDayAboutToStart = true;
}
}
[HarmonyPatch(typeof(StartOfRound), "ResetShip")]
[HarmonyPostfix]
private static void ResetShipPatch(StartOfRound __instance)
{
StarterPack.Logger.LogDebug((object)"ResetShipPatch() called");
gameAlreadyReset = true;
ApplyGifts();
}
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyPostfix]
private static void ConnectClientToPlayerObjectPatch(StartOfRound __instance)
{
StarterPack.Logger.LogDebug((object)"ConnectClientToPlayerObjectPatch() called");
if (isFirstDayAboutToStart)
{
isFirstDayAboutToStart = false;
ApplyGifts();
}
}
}
[HarmonyPatch]
internal class TestTerminalNodePatch
{
private static int myItemIndex = -1;
public static TerminalKeyword CreateTerminalKeyword(string word, bool isVerb = false, CompatibleNoun[] compatibleNouns = null, TerminalNode specialKeywordResult = null, TerminalKeyword defaultVerb = null, bool accessTerminalObjects = false)
{
TerminalKeyword val = ScriptableObject.CreateInstance<TerminalKeyword>();
((Object)val).name = word;
val.word = word;
val.isVerb = isVerb;
val.compatibleNouns = compatibleNouns;
val.specialKeywordResult = specialKeywordResult;
val.defaultVerb = defaultVerb;
val.accessTerminalObjects = accessTerminalObjects;
return val;
}
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyPostfix]
private static void ConnectClientToPlayerObjectPatch(StartOfRound __instance)
{
}
[HarmonyPatch(typeof(Terminal), "Awake")]
[HarmonyPrefix]
public static bool TerminalAwakePatch(Terminal __instance)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Expected O, but got Unknown
Terminal val = Object.FindAnyObjectByType<Terminal>();
TerminalNode val2 = StarterPack.Assets.LoadAsset<TerminalNode>("WI TerminalNode");
Item val3 = new Item();
val3.creditsWorth = 101;
val3.itemName = "Starting Kit";
List<Item> list = val.buyableItemsList.ToList();
list.Add(val3);
int num = 0;
foreach (Item item in list)
{
StarterPack.Logger.LogDebug((object)$"index #{num++} - Item {item.itemName} (id={item.itemId}) cost {item.creditsWorth}");
}
val.buyableItemsList = list.ToArray();
TerminalKeyword val4 = val.terminalNodes.allKeywords.First((TerminalKeyword keyword) => keyword.word == "buy");
TerminalNode result = val2.terminalOptions[0].result;
TerminalKeyword noun = val2.terminalOptions[0].noun;
TerminalNode result2 = val2.terminalOptions[1].result;
TerminalKeyword noun2 = val2.terminalOptions[1].noun;
myItemIndex = list.Count - 1;
val2.buyItemIndex = myItemIndex;
result.buyItemIndex = myItemIndex;
val2.itemCost = 101;
result.itemCost = 101;
StarterPack.Logger.LogDebug((object)$"Item price: {val2.itemCost}, Item index: {val2.buyItemIndex}");
TerminalKeyword val5 = CreateTerminalKeyword("start", isVerb: false, null, null, val4);
List<CompatibleNoun> list2 = val4.compatibleNouns.ToList();
list2.Add(new CompatibleNoun
{
noun = val5,
result = val2
});
val4.compatibleNouns = list2.ToArray();
List<TerminalKeyword> list3 = val.terminalNodes.allKeywords.ToList();
list3.Add(val5);
list3.Add(noun);
list3.Add(noun2);
val.terminalNodes.allKeywords = list3.ToArray();
return true;
}
[HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")]
[HarmonyPrefix]
public static bool TerminalLoadNewNodeIfAffordablePatch(TerminalNode node, Terminal __instance)
{
if (node.buyItemIndex == myItemIndex)
{
StarterPack.Logger.LogDebug((object)"Intercepted buy node");
StarterPack.Logger.LogDebug((object)$"Price : {node.itemCost}");
StarterPack.Logger.LogDebug((object)$"IsConfirmation : {node.isConfirmationNode}");
if (node.isConfirmationNode)
{
return true;
}
int num = 0;
int num2 = 0;
for (int i = 0; i < 3; i++)
{
num += (int)((double)__instance.buyableItemsList[num2].creditsWorth * ((double)__instance.itemSalesPercentages[num2] / 100.0) * (double)__instance.playerDefinedAmount);
__instance.orderedItemsFromTerminal.Add(num2);
}
num2 = 1;
for (int j = 0; j < 1; j++)
{
num += (int)((double)__instance.buyableItemsList[num2].creditsWorth * ((double)__instance.itemSalesPercentages[num2] / 100.0) * (double)__instance.playerDefinedAmount);
__instance.orderedItemsFromTerminal.Add(num2);
}
num2 = 4;
for (int k = 0; k < 2; k++)
{
num += (int)((double)__instance.buyableItemsList[num2].creditsWorth * ((double)__instance.itemSalesPercentages[num2] / 100.0) * (double)__instance.playerDefinedAmount);
__instance.orderedItemsFromTerminal.Add(num2);
}
__instance.numberOfItemsInDropship += 6;
__instance.totalCostOfItems = num;
if (__instance.groupCredits < __instance.totalCostOfItems)
{
__instance.LoadNewNode(__instance.terminalNodes.specialNodes[2]);
}
else
{
__instance.groupCredits = Mathf.Clamp(__instance.groupCredits - __instance.totalCostOfItems, 0, 10000000);
__instance.LoadNewNode(node);
}
return false;
}
return true;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace ESN.StarterPack.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}