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 System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CustomStoryLogs.Tools;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
[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("Yorimor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.4.3.0")]
[assembly: AssemblyInformationalVersion("1.4.3+66e6450277d2cae7e56af6a9a0fd2a618a98b868")]
[assembly: AssemblyProduct("CustomStoryLogs")]
[assembly: AssemblyTitle("Yorimor.CustomStoryLogs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.3.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 CustomStoryLogs
{
public class CustomLogData
{
public string ModGUID;
public int LogID;
public bool Unlocked;
public bool Hidden;
public string LogName;
public string LogText;
public string Keyword;
public LogCollected Event;
public void UpdateText(string newText)
{
LogText = newText;
Terminal val = Object.FindObjectOfType<Terminal>();
if (!Object.op_Implicit((Object)(object)val))
{
return;
}
foreach (TerminalNode logEntryFile in val.logEntryFiles)
{
if (logEntryFile.storyLogFileID == LogID)
{
logEntryFile.displayText = newText;
break;
}
}
}
}
public class LogCollectableData
{
public string ModGUID;
public Vector3 Position;
public Vector3 Rotation;
public int LogID;
public int ModelID;
}
public class CustomLogInteract : NetworkBehaviour
{
public LogCollectableData data;
public int storyLogID = -1;
private bool collected;
public void CollectLog()
{
if (!((Object)(object)NetworkManager.Singleton == (Object)null) && !((Object)(object)GameNetworkManager.Instance == (Object)null) && !collected && storyLogID != -1 && !CustomStoryLogs.GetUnlockedList().Contains(storyLogID))
{
CustomStoryLogs.UnlockStoryLogOnServer(storyLogID);
}
}
public void LocalCollectLog()
{
collected = true;
RemoveLogCollectible();
}
private void Start()
{
((Object)this).name = "CustomStoryLog." + storyLogID;
if (CustomStoryLogs.GetUnlockedList().Contains(storyLogID))
{
RemoveLogCollectible();
}
}
private void RemoveLogCollectible()
{
MeshRenderer[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<MeshRenderer>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
Renderer val = (Renderer)(object)componentsInChildren[i];
val.enabled = false;
}
((Component)this).gameObject.GetComponent<InteractTrigger>().interactable = false;
Collider[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Collider>();
foreach (Collider val2 in componentsInChildren2)
{
val2.enabled = false;
}
}
}
public struct JsonLogsFile
{
public string username;
public string modname;
public string version;
public Dictionary<string, JsonLogData> logs;
}
public struct JsonLogData
{
public string name;
public string text;
public string moon;
public Vector3 position;
public Vector3 rotation;
}
public class JsonLogReader
{
public static void LoadLogsFromUserFiles()
{
foreach (string item in Directory.GetDirectories(Paths.PluginPath, "CustomStoryLogs", SearchOption.AllDirectories).ToList())
{
string path = Path.Combine(item, "logs");
if (!Directory.Exists(path))
{
continue;
}
string[] files = Directory.GetFiles(path);
string[] array = files;
foreach (string text in array)
{
if (Path.GetExtension(text) == ".json" || Path.GetExtension(text) == ".txt")
{
LoadLogsFromJsonFile(text);
}
}
}
}
public static void LoadLogsFromJsonFile(string jsonPath)
{
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
CustomStoryLogs.Logger.LogInfo((object)("Loading logs from " + jsonPath.Split("BepInEx").Last()));
string text = File.ReadAllText(jsonPath);
JsonLogsFile jsonLogsFile = default(JsonLogsFile);
try
{
jsonLogsFile = JsonConvert.DeserializeObject<JsonLogsFile>(text);
}
catch (Exception ex)
{
CustomStoryLogs.Logger.LogError((object)("There was a problem loading the file " + jsonPath));
CustomStoryLogs.Logger.LogError((object)ex.GetBaseException());
return;
}
string modGUID = jsonLogsFile.username + "-" + jsonLogsFile.modname + "-" + jsonLogsFile.version;
foreach (JsonLogData value in jsonLogsFile.logs.Values)
{
CustomStoryLogs.Logger.LogDebug((object)$"(Json log) Adding {value.name} to {value.moon} @ {value.position}");
int logID = CustomStoryLogs.RegisterCustomLog(modGUID, value.name, value.text);
CustomStoryLogs.RegisterCustomLogCollectable(modGUID, logID, value.moon, value.position, value.rotation);
}
}
}
public delegate void LogCollected(int logID);
[BepInPlugin("Yorimor.CustomStoryLogs", "CustomStoryLogs", "1.4.5")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CustomStoryLogs : BaseUnityPlugin
{
public const string PLUGIN_GUID = "Yorimor.CustomStoryLogs";
public const string PLUGIN_NAME = "CustomStoryLogs";
public const string PLUGIN_VERSION = "1.4.5";
private static List<string> UsedKeywords = new List<string>();
public static Dictionary<int, CustomLogData> RegisteredLogs = new Dictionary<int, CustomLogData>();
public static Dictionary<string, List<int>> PlanetCollectables = new Dictionary<string, List<int>>();
public static Dictionary<int, LogCollectableData> Collectables = new Dictionary<int, LogCollectableData>();
public static string UnlockedSaveKey = "Yorimor.CustomStoryLogs-Unlocked";
public static LethalNetworkVariable<List<int>> UnlockedNetwork = new LethalNetworkVariable<List<int>>("UnlockedList");
public static List<int> UnlockedLocal = new List<int>();
public static LethalServerMessage<string> SpawnLogsServer = new LethalServerMessage<string>("SpawnLogs", (Action<string, ulong>)null);
public static LethalClientMessage<string> SpawnLogsClient = new LethalClientMessage<string>("SpawnLogs", (Action<string>)null, (Action<string, ulong>)null);
public static LethalServerMessage<int> UnlockLogServer = new LethalServerMessage<int>("UnlockLog", (Action<int, ulong>)null);
public static LethalClientMessage<int> UnlockLogClient = new LethalClientMessage<int>("UnlockLog", (Action<int>)null, (Action<int, ulong>)null);
public static AssetBundle MyAssets;
public static GameObject CustomLogObj;
public static List<GameObject> CustomModels = new List<GameObject>();
public static LogCollected AnyLogCollectEvent;
public string AssemblyLocation;
public static ConfigEntry<bool> ToolEnabled;
public static ConfigEntry<bool> HideVanillaLogs;
public static CustomStoryLogs Instance { get; private set; } = null;
internal static ManualLogSource Logger { get; private set; } = null;
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
AssemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
MyAssets = AssetBundle.LoadFromFile(Path.Combine(AssemblyLocation, "yorimor.customlogs"));
if ((Object)(object)MyAssets == (Object)null)
{
Logger.LogError((object)"Failed to load custom assets.");
return;
}
CustomLogObj = MyAssets.LoadAsset<GameObject>("Assets/Yorimor/CustomStoryLogs/CustomStoryModel.prefab");
NetworkPrefabs.RegisterNetworkPrefab(CustomLogObj);
UnlockedNetwork.Value = new List<int>();
SpawnLogsClient.OnReceived += SpawnLogsLocally;
UnlockLogServer.OnReceived += ReceiveUnlockFromClient;
UnlockLogClient.OnReceived += ReceiveUnlockMsgFromServer;
Patch();
ToolEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("PlacementTool", "ToolEnabled", false, "Enable/Disable the in game placement tool");
Logger.LogInfo((object)$"Placement Tool Enabled: {ToolEnabled.Value}");
HideVanillaLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("VanillaLogs", "HideVanillaLogs", false, "Show/Hide the vanilla story logs");
Logger.LogInfo((object)$"Hide Vanilla Logs: {HideVanillaLogs.Value}");
UsedKeywords = new List<string>(134)
{
"buy", "pro flashlight", "money", "confirm", "deny", "help", "info", "store", "pro flashlight", "survival kit",
"flashlight", "lockpicker", "mapper", "shovel", "jetpack", "boombox", "bestiary", "stun", "reset credits", "view",
"inside cam", "moons", "vow", "experimentation", "assurance", "offense", "adamance", "route", "television", "teleporter",
"rend", "march", "dine", "titan", "artifice", "embrion", "company", "walkie-talkie", "spray paint", "brackens",
"forest keeper", "earth leviathan", "lasso", "spore lizards", "snare fleas", "eyeless dogs", "hoarding bugs", "bunker spiders", "hygroderes", "coil-heads",
"manticoils", "baboon hawks", "nutcracker", "old birds", "butler", "circuit bees", "locusts", "thumpers", "jester", "decor",
"upgrades", "tzp", "green suit", "hazard suit", "pajama suit", "cozy lights", "sigurd", "signal", "toilet", "record",
"shower", "table", "romantic table", "file cabinet", "cupboard", "bunkbeds", "storage", "other", "scan", "b3",
"c1", "c2", "c7", "d6", "f2", "h5", "i1", "j6", "k9", "l0",
"m6", "m9", "o5", "p1", "r2", "r4", "t2", "u2", "u9", "v0",
"x8", "y9", "z3", "first", "smells", "swing", "shady", "sound", "goodbye", "screams",
"golden", "idea", "nonsense", "hiding", "desmond", "real", "zap gun", "monitor", "switch", "loud horn",
"extension ladder", "inverse teleporter", "jackolantern", "radar", "eject", "welcome mat", "goldfish", "plushie pajama man", "purple suit", "purple",
"bee", "bunny", "disco", "tulip"
};
AnyLogCollectEvent = (LogCollected)Delegate.Combine(AnyLogCollectEvent, new LogCollected(EmptyOnCollect));
JsonLogReader.LoadLogsFromUserFiles();
Logger.LogInfo((object)"Yorimor.CustomStoryLogs v1.4.5 loaded!");
}
private static void AddTestLogs()
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
int num = RegisterCustomLogModel(MyAssets.LoadAsset<GameObject>("Assets/Yorimor/CustomStoryLogs/Cube.prefab"));
int num2 = RegisterCustomLog("Yorimor.CustomStoryLogs", "Test - Test", "Model Test\n\n/\\\n\\/");
RegisterCustomLogCollectable("Yorimor.CustomStoryLogs", num2, "71 Gordion", new Vector3(-28f, -2f, -15f), Vector3.zero);
CustomLogData customLogData = RegisteredLogs[num2];
customLogData.Event = (LogCollected)Delegate.Combine(customLogData.Event, new LogCollected(TestEvent));
RegisteredLogs[num2].UpdateText("New text");
AnyLogCollectEvent = (LogCollected)Delegate.Combine(AnyLogCollectEvent, new LogCollected(TestEventAny));
}
private static void TestEvent(int logID)
{
Logger.LogInfo((object)$"TEST EVENT {logID}");
RegisteredLogs[logID].UpdateText("new text :P");
}
private static void TestEventAny(int logID)
{
Logger.LogInfo((object)$"TEST EVENT ANY {logID}");
}
internal static 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("Yorimor.CustomStoryLogs");
}
Harmony.PatchAll();
}
internal static void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
public static int RegisterCustomLog(string modGUID, string logName, string text, bool unlocked = false, bool hidden = false)
{
CustomLogData customLogData = new CustomLogData();
string[] array = logName.Trim().Split("-")[0].Trim().Split(" ");
customLogData.Keyword = array[0].ToLower();
if (UsedKeywords.Contains(customLogData.Keyword))
{
Logger.LogError((object)("Unable to add story log [" + logName + "], keyword [" + customLogData.Keyword + "] already in use!"));
return -1;
}
UsedKeywords.Add(customLogData.Keyword);
customLogData.LogName = logName;
customLogData.LogText = text + "\n\n\n\n\n\n";
customLogData.Unlocked = unlocked;
customLogData.Hidden = hidden;
customLogData.ModGUID = modGUID;
customLogData.LogID = (modGUID + customLogData.Keyword).GetHashCode();
RegisteredLogs[customLogData.LogID] = customLogData;
Logger.LogDebug((object)$"Added new log [{modGUID}/{customLogData.Keyword}] with ID [{customLogData.LogID}]");
return customLogData.LogID;
}
public static void RegisterCustomLogCollectable(string modGUID, int logID, string planetName, Vector3 position, Vector3 rotation, int modelID = 0)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
LogCollectableData logCollectableData = new LogCollectableData();
if (!RegisteredLogs.ContainsKey(logID))
{
Logger.LogError((object)$"Custom log not found with ID {logID} for collectable added by {modGUID}");
return;
}
logCollectableData.ModGUID = modGUID;
logCollectableData.LogID = logID;
logCollectableData.Position = position;
logCollectableData.Rotation = rotation;
if (modelID > CustomModels.Count || modelID < 0)
{
Logger.LogError((object)$"[{modGUID}/{logID}] Custom ModelID {modelID} invalid! Setting to default/zero.");
modelID = 0;
}
logCollectableData.ModelID = modelID;
if (!PlanetCollectables.ContainsKey(planetName))
{
PlanetCollectables[planetName] = new List<int>();
}
Collectables[logCollectableData.LogID] = logCollectableData;
PlanetCollectables[planetName].Add(logCollectableData.LogID);
}
public static int RegisterCustomLogModel(GameObject customModel)
{
CustomModels.Add(customModel);
int count = CustomModels.Count;
Logger.LogInfo((object)$"Added model {((Object)customModel).name} with ID {count}");
return count;
}
private static void ReceiveUnlockFromClient(int logID, ulong client)
{
if (!RegisteredLogs.ContainsKey(logID))
{
Logger.LogError((object)$"Log {logID} unlocked by {client} but it does not exist!");
return;
}
Logger.LogInfo((object)$"Log {logID} unlocked by {client}");
UnlockedNetwork.Value.Add(logID);
Logger.LogDebug((object)$"Telling clients to unlock log {logID}");
UnlockLogServer.SendAllClients(logID, true);
}
public static List<int> GetUnlockedList()
{
return UnlockedNetwork.Value.Union(UnlockedLocal).ToList();
}
public static void UnlockStoryLogOnServer(int logID)
{
Logger.LogDebug((object)$"Telling server to unlock log {logID}");
UnlockLogClient.SendServer(logID);
}
private static void ReceiveUnlockMsgFromServer(int logID)
{
Logger.LogDebug((object)$"Unlocking log {logID}");
HUDManager.Instance.DisplayGlobalNotification("Found journal entry: '" + RegisteredLogs[logID].LogName + "'");
GameObject obj = GameObject.Find("CustomStoryLog." + logID);
if (obj != null)
{
obj.GetComponent<CustomLogInteract>()?.LocalCollectLog();
}
UnlockedLocal.Add(logID);
RegisteredLogs[logID].Event?.Invoke(logID);
AnyLogCollectEvent?.Invoke(logID);
}
private static void SpawnLogsLocally(string planetName)
{
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
Logger.LogInfo((object)("Loading logs for: " + planetName));
foreach (int item in PlanetCollectables[planetName])
{
LogCollectableData logCollectableData = Collectables[item];
string text = "CustomStoryLog." + logCollectableData.LogID;
if (Object.op_Implicit((Object)(object)GameObject.Find(text)))
{
continue;
}
Logger.LogInfo((object)$"Spawning collectable log {logCollectableData.LogID}");
GameObject val = Object.Instantiate<GameObject>(CustomLogObj);
if (logCollectableData.ModelID > 0)
{
GameObject val2 = Object.Instantiate<GameObject>(CustomModels[logCollectableData.ModelID - 1], val.transform);
((Renderer)val.GetComponent<MeshRenderer>()).enabled = false;
BoxCollider component = val.GetComponent<BoxCollider>();
BoxCollider component2 = val2.GetComponent<BoxCollider>();
if (Object.op_Implicit((Object)(object)component2))
{
((Collider)component2).enabled = false;
component.size = component2.size;
component.center = component2.center;
}
}
CustomLogInteract component3 = val.GetComponent<CustomLogInteract>();
component3.storyLogID = logCollectableData.LogID;
component3.data = logCollectableData;
((Object)val).name = text;
val.transform.position = logCollectableData.Position;
val.transform.rotation = Quaternion.Euler(logCollectableData.Rotation);
Logger.LogDebug((object)$"Spawned log {text} @ {val.transform.position}");
}
}
public static void DespawnLogsLocally(string planetName)
{
Logger.LogInfo((object)("Removing logs for: " + planetName));
foreach (int item in PlanetCollectables[planetName])
{
LogCollectableData logCollectableData = Collectables[item];
string text = "CustomStoryLog." + logCollectableData.LogID;
GameObject val = GameObject.Find(text);
if (Object.op_Implicit((Object)(object)val))
{
Object.Destroy((Object)(object)val);
}
}
}
public static void EmptyOnCollect(int logID)
{
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Yorimor.CustomStoryLogs";
public const string PLUGIN_NAME = "CustomStoryLogs";
public const string PLUGIN_VERSION = "1.4.3";
}
}
namespace CustomStoryLogs.Tools
{
internal delegate void SimpleMethodDelegate();
internal class KeyBindManager
{
public static InputActionMap? customActionMap;
public static InputAction CreateInputAction(string _inputName, string _binding, string _interactions)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
if (customActionMap == null)
{
customActionMap = new InputActionMap("CustomStoryLogs");
}
InputAction val = customActionMap.FindAction(_inputName, false);
if (val == null)
{
CustomStoryLogs.Logger.LogInfo((object)"ACTION NULL");
customActionMap.Disable();
val = InputActionSetupExtensions.AddAction(customActionMap, _inputName, (InputActionType)0, (string)null, (string)null, (string)null, (string)null, (string)null);
BindingSyntax val2 = InputActionSetupExtensions.AddBinding(val, _binding, (string)null, (string)null, (string)null);
((BindingSyntax)(ref val2)).WithInteraction(_interactions);
customActionMap.Enable();
}
return val;
}
}
public class LogPlacementTool : MonoBehaviour
{
public InputAction modifierKey;
public InputAction activateToolAction;
public InputAction activateUIAction;
public InputAction escKey;
private GameObject dummyLogPrefab;
private GameObject dummyLog;
private GameObject canvasPrefab;
private Transform canvas;
private LogPlacementUI canvasUI;
private LayerMask layerMask;
private Camera cam;
private PlayerControllerB playerController;
private bool isToolActive;
private bool isUIActive;
private void Start()
{
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
escKey = KeyBindManager.CreateInputAction("EscKey", "<Keyboard>/escape", "press");
modifierKey = KeyBindManager.CreateInputAction("ModifierKey", "<Keyboard>/alt", "press");
activateToolAction = KeyBindManager.CreateInputAction("ActivateLogPositionTool", "<Keyboard>/l", "press");
activateUIAction = KeyBindManager.CreateInputAction("ActivateUITool", "<Keyboard>/k", "press");
dummyLogPrefab = CustomStoryLogs.MyAssets.LoadAsset<GameObject>("assets/yorimor/customstorylogs/logpreview.prefab");
canvasPrefab = CustomStoryLogs.MyAssets.LoadAsset<GameObject>("Assets/Yorimor/CustomStoryLogs/LogToolUI.prefab");
cam = StartOfRound.Instance.activeCamera;
playerController = StartOfRound.Instance.localPlayerController;
layerMask = LayerMask.op_Implicit(LayerMask.op_Implicit(layerMask) | 1);
layerMask = LayerMask.op_Implicit(LayerMask.op_Implicit(layerMask) | 0x100);
layerMask = LayerMask.op_Implicit(LayerMask.op_Implicit(layerMask) | 0x800);
CustomStoryLogs.Logger.LogInfo((object)"Log Placement tool initialised. Alt+L to Open Tool");
}
private void Update()
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
if (modifierKey.IsPressed())
{
if (activateToolAction.triggered)
{
ActivateTool();
}
if (activateUIAction.triggered)
{
ActivateUI();
}
}
if (escKey.triggered && isToolActive)
{
if (isUIActive)
{
ActivateUI();
}
ActivateTool();
}
if (!((Object)(object)dummyLog == (Object)null) && !((Object)(object)cam == (Object)null))
{
Ray val = default(Ray);
((Ray)(ref val))..ctor(((Component)cam).transform.position, ((Component)cam).transform.forward);
RaycastHit val2 = default(RaycastHit);
if (Physics.Raycast(val, ref val2, 100f, LayerMask.op_Implicit(layerMask)))
{
dummyLog.transform.position = ((RaycastHit)(ref val2)).point;
dummyLog.transform.up = ((RaycastHit)(ref val2)).normal;
Transform transform = dummyLog.transform;
Vector3 position = transform.position;
Vector3 up = dummyLog.transform.up;
transform.position = position + ((Vector3)(ref up)).normalized * 0.04f;
dummyLog.transform.Rotate(0f, 0f, -90f);
}
}
}
private void ActivateTool()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)dummyLogPrefab == (Object)null) && !((Object)(object)canvasPrefab == (Object)null))
{
isToolActive = !isToolActive;
if (isToolActive)
{
CustomStoryLogs.Logger.LogDebug((object)"Activate Log Placement Tool");
dummyLog = Object.Instantiate<GameObject>(dummyLogPrefab, Vector3.zero, Quaternion.identity);
canvas = Object.Instantiate<GameObject>(canvasPrefab, Vector3.zero, Quaternion.identity).transform;
canvasUI = ((Component)canvas).GetComponent<LogPlacementUI>();
canvasUI.LogTransform = dummyLog.transform;
}
else
{
CustomStoryLogs.Logger.LogDebug((object)"Deactivate Log Placement Tool");
Object.Destroy((Object)(object)dummyLog);
Object.Destroy((Object)(object)((Component)canvas).gameObject);
isUIActive = false;
LockPlayerCamera(_lock: false);
}
}
}
private void ActivateUI()
{
if (isToolActive && !((Object)(object)canvas == (Object)null) && !((Object)(object)canvasUI == (Object)null))
{
isUIActive = !isUIActive;
if (isUIActive)
{
CustomStoryLogs.Logger.LogDebug((object)"Enable Log Placement Tool Edit Mode");
canvasUI.TweakModeOn = true;
LockPlayerCamera(_lock: true);
}
else
{
CustomStoryLogs.Logger.LogDebug((object)"Disable Log Placement Tool Edit Mode");
canvasUI.TweakModeOn = false;
LockPlayerCamera(_lock: false);
}
}
}
private void LockPlayerCamera(bool _lock)
{
if (!((Object)(object)playerController == (Object)null))
{
if (_lock)
{
playerController.disableLookInput = true;
Cursor.visible = true;
Cursor.lockState = (CursorLockMode)0;
}
else
{
playerController.disableLookInput = false;
Cursor.visible = false;
Cursor.lockState = (CursorLockMode)1;
}
}
}
}
public class LogPlacementUI : MonoBehaviour
{
public TMP_InputField MoonName;
public XYZButtonGroup Position;
public XYZButtonGroup Rotation;
public Button[] SaveButtons;
public Transform LogTransform;
public bool TweakModeOn;
public void OnSave(int btnID)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
CustomStoryLogs.Logger.LogInfo((object)$"Saving Tool Data {btnID}!");
PlacementToolData placementToolData = new PlacementToolData();
placementToolData.moon = StartOfRound.Instance.currentLevel.PlanetName;
placementToolData.position = new PlacementToolVector();
placementToolData.position.x = LogTransform.position.x;
placementToolData.position.y = LogTransform.position.y;
placementToolData.position.z = LogTransform.position.z;
placementToolData.rotation = new PlacementToolVector();
PlacementToolVector rotation = placementToolData.rotation;
Quaternion rotation2 = LogTransform.rotation;
rotation.x = ((Quaternion)(ref rotation2)).eulerAngles.x;
PlacementToolVector rotation3 = placementToolData.rotation;
rotation2 = LogTransform.rotation;
rotation3.y = ((Quaternion)(ref rotation2)).eulerAngles.y;
PlacementToolVector rotation4 = placementToolData.rotation;
rotation2 = LogTransform.rotation;
rotation4.z = ((Quaternion)(ref rotation2)).eulerAngles.z;
string text = Path.Combine(Paths.PluginPath, "Yorimor-CustomStoryLogs", "tool_data");
Directory.CreateDirectory(text);
text = Path.Combine(text, $"position-{btnID}.json");
string contents = JsonConvert.SerializeObject((object)placementToolData, (Formatting)1);
File.WriteAllText(text, contents);
CustomStoryLogs.Logger.LogInfo((object)("Log position saved to " + text));
}
public void Update()
{
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)LogTransform == (Object)null))
{
if (Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel))
{
MoonName.text = "\"" + StartOfRound.Instance.currentLevel.PlanetName + "\"";
}
else
{
MoonName.text = "Not on a moon!";
}
if (TweakModeOn)
{
LogTransform.position = Position.vector;
LogTransform.rotation = Quaternion.Euler(Rotation.vector);
return;
}
Position.NewVector(LogTransform.position);
XYZButtonGroup rotation = Rotation;
Quaternion rotation2 = LogTransform.rotation;
rotation.NewVector(((Quaternion)(ref rotation2)).eulerAngles);
}
}
}
public class XYZButton : MonoBehaviour
{
public TMP_InputField Value;
public Button Increment;
public Button Decrement;
public float SmallChange = 0.01f;
public float LargeChange = 0.1f;
public bool IsRotation;
public void OnIncrement()
{
Value.text = FixValue(GetFloat() + LargeChange).ToString("0.00");
}
public void OnDecrement()
{
Value.text = FixValue(GetFloat() - LargeChange).ToString("0.00");
}
public float GetFloat()
{
if (float.TryParse(Value.text, out var result))
{
return result;
}
return 0f;
}
public float FixValue(float _value)
{
if (IsRotation)
{
if (_value < 0f)
{
_value = 360f - _value * -1f % 360f;
}
if (_value > 360f)
{
_value %= 360f;
}
}
return _value;
}
}
public class XYZButtonGroup : MonoBehaviour
{
public XYZButton X;
public XYZButton Y;
public XYZButton Z;
public Vector3 vector;
public void UpdateVector()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
vector = new Vector3(X.GetFloat(), Y.GetFloat(), Z.GetFloat());
}
public void NewVector(Vector3 _vector)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
vector = _vector;
X.Value.text = vector.x.ToString("0.00");
Y.Value.text = vector.y.ToString("0.00");
Z.Value.text = vector.z.ToString("0.00");
}
}
public class PlacementToolData
{
public string moon;
public PlacementToolVector position;
public PlacementToolVector rotation;
}
public class PlacementToolVector
{
public float x;
public float y;
public float z;
}
}
namespace CustomStoryLogs.Patches
{
[HarmonyPatch(typeof(GameNetworkManager))]
public class GameNetPatches
{
[HarmonyPatch("SaveGameValues")]
[HarmonyPostfix]
private static void SaveUnlockedLogs(GameNetworkManager __instance)
{
if (!__instance.isHostingGame)
{
return;
}
CustomStoryLogs.Logger.LogDebug((object)"Saving Unlocked logs");
try
{
ES3.Save<List<int>>(CustomStoryLogs.UnlockedSaveKey, CustomStoryLogs.GetUnlockedList(), __instance.currentSaveFileName);
}
catch (Exception arg)
{
Debug.LogError((object)$"Error while trying to save unlocked custom logs: {arg}");
}
}
[HarmonyPatch("ResetSavedGameValues")]
[HarmonyPostfix]
private static void ResetUnlockedLogs(GameNetworkManager __instance)
{
if (__instance.isHostingGame)
{
ES3.Save<List<int>>(CustomStoryLogs.UnlockedSaveKey, new List<int>(), __instance.currentSaveFileName);
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("ConnectClientToPlayerObject")]
[HarmonyPostfix]
public static void ConnectClientToPlayerObjectPatch(ref PlayerControllerB __instance)
{
if (((NetworkBehaviour)__instance).IsOwner && ((NetworkBehaviour)__instance).IsHost && CustomStoryLogs.ToolEnabled.Value)
{
((Component)__instance).gameObject.AddComponent<LogPlacementTool>();
}
}
}
[HarmonyPatch(typeof(RoundManager))]
public class RoundManagerPatches
{
[HarmonyPatch("LoadNewLevel")]
[HarmonyPostfix]
private static void AddInLevelStoryLogs(RoundManager __instance, int randomSeed, SelectableLevel newLevel)
{
if (((NetworkBehaviour)__instance).IsHost)
{
LoadLogsForLevel(newLevel.PlanetName);
LoadLogsForLevel(newLevel.sceneName);
}
}
private static void LoadLogsForLevel(string planetName)
{
if (CustomStoryLogs.PlanetCollectables.ContainsKey(planetName))
{
CustomStoryLogs.Logger.LogDebug((object)"Telling clients to spawn log objects");
CustomStoryLogs.SpawnLogsServer.SendAllClients(planetName, true);
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class StartOfRoundPatches
{
[HarmonyPatch("ShipHasLeft")]
[HarmonyPostfix]
private static void CleanupLevel(StartOfRound __instance)
{
string planetName = __instance.currentLevel.PlanetName;
if (CustomStoryLogs.PlanetCollectables.ContainsKey(planetName))
{
CustomStoryLogs.DespawnLogsLocally(planetName);
}
}
}
[HarmonyPatch(typeof(StoryLog))]
public class StoryLogPatches
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void HideLogPatch(StoryLog __instance)
{
if (CustomStoryLogs.HideVanillaLogs.Value)
{
CustomStoryLogs.Logger.LogDebug((object)$"Hiding vanilla story log [{__instance.storyLogID}]");
__instance.RemoveLogCollectible();
}
}
}
[HarmonyPatch(typeof(Terminal))]
public class TerminalPatches
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void AddCustomLogs(Terminal __instance)
{
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Expected O, but got Unknown
if (((NetworkBehaviour)__instance).IsServer)
{
CustomStoryLogs.Logger.LogInfo((object)"Loading unlocked logs");
CustomStoryLogs.UnlockedNetwork.Value = ES3.Load<List<int>>(CustomStoryLogs.UnlockedSaveKey, GameNetworkManager.Instance.currentSaveFileName, new List<int>());
}
CustomStoryLogs.UnlockedLocal = CustomStoryLogs.UnlockedNetwork.Value;
foreach (int item in CustomStoryLogs.UnlockedLocal)
{
if (CustomStoryLogs.RegisteredLogs.ContainsKey(item))
{
CustomStoryLogs.RegisteredLogs[item].Event?.Invoke(item);
CustomStoryLogs.AnyLogCollectEvent?.Invoke(item);
}
}
CustomStoryLogs.Logger.LogInfo((object)"Adding logs");
TerminalKeyword val = null;
TerminalKeyword[] allKeywords = __instance.terminalNodes.allKeywords;
foreach (TerminalKeyword val2 in allKeywords)
{
if (val2.word == "view")
{
val = val2;
}
}
if (!Object.op_Implicit((Object)(object)val))
{
return;
}
foreach (CustomLogData value in CustomStoryLogs.RegisteredLogs.Values)
{
TerminalNode val3 = ScriptableObject.CreateInstance<TerminalNode>();
((Object)val3).name = value.LogName;
val3.displayText = value.LogText;
val3.storyLogFileID = value.LogID;
val3.clearPreviousText = true;
TerminalKeyword val4 = ScriptableObject.CreateInstance<TerminalKeyword>();
val4.word = value.Keyword;
CompatibleNoun val5 = new CompatibleNoun();
val5.result = val3;
val5.noun = val4;
if (value.Unlocked && !CustomStoryLogs.GetUnlockedList().Contains(value.LogID))
{
CustomStoryLogs.UnlockedNetwork.Value.Add(value.LogID);
CustomStoryLogs.UnlockedLocal.Add(value.LogID);
}
val.compatibleNouns = val.compatibleNouns.Append(val5).ToArray();
__instance.logEntryFiles.Add(val3);
__instance.terminalNodes.allKeywords = __instance.terminalNodes.allKeywords.Append(val4).ToArray();
}
}
[HarmonyPatch("TextPostProcess")]
[HarmonyPrefix]
private static void FixInvalidUnlockedLogIDs(Terminal __instance, string modifiedDisplayText, TerminalNode node)
{
if (!((Object)node).name.Contains("LogsHub"))
{
return;
}
List<int> list = new List<int>();
foreach (int unlockedStoryLog in __instance.unlockedStoryLogs)
{
if (unlockedStoryLog < __instance.logEntryFiles.Count)
{
list.Add(unlockedStoryLog);
}
}
__instance.unlockedStoryLogs = list;
List<int> newlyUnlockedStoryLogs = new List<int>();
foreach (int newlyUnlockedStoryLog in __instance.newlyUnlockedStoryLogs)
{
if (newlyUnlockedStoryLog < __instance.logEntryFiles.Count)
{
list.Add(newlyUnlockedStoryLog);
}
}
__instance.newlyUnlockedStoryLogs = newlyUnlockedStoryLogs;
}
[HarmonyPatch("TextPostProcess")]
[HarmonyPrefix]
private static void RemoveVanillaLogs(Terminal __instance, TerminalNode node)
{
if (((Object)node).name.Contains("LogsHub") && CustomStoryLogs.HideVanillaLogs.Value)
{
CustomStoryLogs.Logger.LogDebug((object)"Resetting vanilla unlocked logs to hide from terminal");
__instance.unlockedStoryLogs = new List<int>();
}
}
[HarmonyPatch("TextPostProcess")]
[HarmonyPostfix]
private static void AddCustomLogsToTerminalDisplay(Terminal __instance, string modifiedDisplayText, TerminalNode node, ref string __result)
{
if (!((Object)node).name.Contains("LogsHub"))
{
return;
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("\n");
int num = 0;
foreach (int unlocked in CustomStoryLogs.GetUnlockedList())
{
if (CustomStoryLogs.RegisteredLogs.ContainsKey(unlocked))
{
CustomLogData customLogData = CustomStoryLogs.RegisteredLogs[unlocked];
if (!customLogData.Hidden)
{
stringBuilder.Append("\n" + customLogData.LogName);
num++;
}
}
}
stringBuilder.Append("\n\n\n\n");
if (num > 0)
{
__result = __result.Replace("[currentUnlockedLogsList]", "");
__result = __result.Replace("[ALL DATA HAS BEEN CORRUPTED OR OVERWRITTEN]", "");
}
__result = __result.TrimEnd() + stringBuilder.ToString();
}
[HarmonyPatch("AttemptLoadStoryLogFileNode")]
[HarmonyPostfix]
private static void LoadCustomLog(Terminal __instance, TerminalNode node)
{
int storyLogFileID = node.storyLogFileID;
if (CustomStoryLogs.RegisteredLogs.ContainsKey(storyLogFileID) && CustomStoryLogs.GetUnlockedList().Contains(storyLogFileID))
{
__instance.LoadNewNode(node);
}
}
}
}