using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using crecheng.DSPModSave;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("CameraMemory")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Saves your camera angle and zoom with each save and restores them when you load it")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+dc5f8c3f6821ff0938cd914b42d2cd60f18350f8")]
[assembly: AssemblyProduct("CameraMemory")]
[assembly: AssemblyTitle("CameraMemory")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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]
[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 CameraMemory
{
[BepInPlugin("com.geostyx.dsp.cameramemory", "CameraMemory", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[HarmonyPatch]
public class Plugin : BaseUnityPlugin, IModCanSave
{
[Serializable]
internal class CameraState
{
public float rtsYaw;
public float rtsPitchCoef;
public float rtsDistCoef;
public Quaternion sailRotation;
public float sailDistCoef;
}
private Harmony? _harmony;
private static CameraState? _savedCamera;
private void Awake()
{
_harmony = Harmony.CreateAndPatchAll(typeof(Plugin), "com.geostyx.dsp.cameramemory");
((BaseUnityPlugin)this).Logger.LogInfo((object)"CameraMemory 0.1.0 loaded");
}
private void OnDestroy()
{
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
_harmony = null;
}
[HarmonyPatch(typeof(DSPGame), "StartGame", new Type[] { typeof(string) })]
[HarmonyPostfix]
private static void StartGamePostfix()
{
Object.FindObjectOfType<GameLoader>().onLoadComplete += RestoreCamera;
}
private static void RestoreCamera()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
if (_savedCamera != null)
{
GameCamera instance = GameCamera.instance;
SailPoser sailPoser = instance.sailPoser;
sailPoser.targetURotWanted = _savedCamera.sailRotation;
sailPoser.distCoefWanted = _savedCamera.sailDistCoef;
sailPoser.ToWanted();
RTSPoser rtsPoser = instance.rtsPoser;
rtsPoser.yawWanted = _savedCamera.rtsYaw;
rtsPoser.pitchCoefWanted = _savedCamera.rtsPitchCoef;
rtsPoser.distCoefWanted = _savedCamera.rtsDistCoef;
rtsPoser.ToWanted();
if (!GameMain.mainPlayer.sailing)
{
CameraPose cameraPose = ((CameraPoser)rtsPoser).cameraPose;
((CameraPose)(ref cameraPose)).ApplyToCamera(GameCamera.main);
}
}
}
public void Export(BinaryWriter w)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
GameCamera instance = GameCamera.instance;
CameraState cameraState = new CameraState
{
rtsYaw = instance.rtsPoser.yawWanted,
rtsPitchCoef = instance.rtsPoser.pitchCoefWanted,
rtsDistCoef = instance.rtsPoser.distCoefWanted,
sailRotation = instance.sailPoser.targetURotWanted,
sailDistCoef = instance.sailPoser.distCoefWanted
};
w.Write(JsonUtility.ToJson((object)cameraState));
}
public void Import(BinaryReader r)
{
try
{
_savedCamera = JsonUtility.FromJson<CameraState>(r.ReadString());
}
catch (Exception ex)
{
_savedCamera = null;
((BaseUnityPlugin)this).Logger.LogWarning((object)("Ignoring unreadable camera state: " + ex.Message));
}
}
public void IntoOtherSave()
{
_savedCamera = null;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.geostyx.dsp.cameramemory";
public const string PLUGIN_NAME = "CameraMemory";
public const string PLUGIN_VERSION = "0.1.0";
}
}