using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
[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("gafoneo.fpschanger")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+80bfa3dd230fd53050b4e4b78a69337f5c38bd0e")]
[assembly: AssemblyProduct("FPSChanger")]
[assembly: AssemblyTitle("gafoneo.fpschanger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 FPSChanger
{
public class FPSCInputClass : LcInputActions
{
[InputAction(/*Could not decode attribute arguments.*/)]
public InputAction ChangeFPS { get; set; }
}
[BepInPlugin("gafoneo.fpschanger", "FPSChanger", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class FPSChanger : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <RemoveNextFrame>d__15 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public FPSChanger <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <RemoveNextFrame>d__15(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
FPSChanger fPSChanger = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = null;
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
fPSChanger.RemoveLCSTKeybinds();
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal static ManualLogSource Logger;
private ConfigEntry<string> fpsValues;
private ConfigEntry<bool> disableLCST;
internal string filePath = "LCGeneralSaveData";
internal int[] ingameFPSCaps = new int[6] { -1, 250, 144, 120, 60, 30 };
internal int currentGameIndex;
internal int currentModIndex;
internal int currentSetting;
internal int[] FPSValues;
internal static FPSCInputClass InputActionsInstance;
public static FPSChanger Instance { get; private set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
Logger.LogInfo((object)"Plugin gafoneo.fpschanger is loading!");
fpsValues = ((BaseUnityPlugin)this).Config.Bind<string>("FPSChanger", "FPS Values", CommaJoin(new int[2] { 30, 250 }), "Values of fps that would be cycled, comma-separated. Available options: 30, 60, 120, 144, 250, 0. 250 is written as \"Uncapped\" ingame and -1 is for Vsync");
disableLCST = ((BaseUnityPlugin)this).Config.Bind<bool>("Advanced", "Disable LCSoundTool keybinds", true, "LCSoundTool mod has in-built keybinds for F5 and F6, this settings disables them cause they can cause a lot of lag and are only used for debugging and modding");
if (!CommaSplit(fpsValues.Value, out FPSValues))
{
Logger.LogInfo((object)"Was not able to parse the config. The mod will not work, shutting it down");
return;
}
Logger.LogInfo((object)("Config values: " + GeneralExtensions.Join<string>(FPSValues.Select((int i) => i.ToString()), (Func<string, string>)null, ", ")));
if (!FPSValues.Select((int i) => ingameFPSCaps.Contains(i)).All((bool i) => i))
{
Logger.LogError((object)"Wrong option in your config was found. Shutting down.");
return;
}
currentGameIndex = ES3.Load<int>("FPSCap", filePath, 0);
currentSetting = ingameFPSCaps[currentGameIndex];
Logger.LogInfo((object)$"Current game index: {currentGameIndex}");
Logger.LogInfo((object)string.Format("Current FPS setting: {0}", (currentSetting != -1) ? ((object)currentSetting) : "Vsync"));
currentModIndex = Array.IndexOf(FPSValues, currentSetting);
Logger.LogInfo((object)$"Current mod index: {currentModIndex}");
InputActionsInstance = new FPSCInputClass();
SetupKeybindCallbacks();
if (disableLCST.Value)
{
((MonoBehaviour)this).StartCoroutine(RemoveNextFrame());
}
Logger.LogInfo((object)"Finished setting up");
}
[IteratorStateMachine(typeof(<RemoveNextFrame>d__15))]
private IEnumerator RemoveNextFrame()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RemoveNextFrame>d__15(0)
{
<>4__this = this
};
}
private void RemoveLCSTKeybinds()
{
Logger.LogInfo((object)"Checking if LCSoundTool is installed");
if (!Chainloader.PluginInfos.ContainsKey("LCSoundTool"))
{
Logger.LogInfo((object)"LCST is not installed");
return;
}
Logger.LogInfo((object)"LCST is installed, removing it's keybinds");
Assembly assembly = ((object)Chainloader.PluginInfos["LCSoundTool"].Instance).GetType().Assembly;
Type type = assembly.GetType("LCSoundTool.Utilities.InputHelper");
if (type == null)
{
Logger.LogDebug((object)"Getting InputHelper type failed, stopped trying to remove keybinds");
return;
}
FieldInfo field = type.GetField("keybinds", BindingFlags.Static | BindingFlags.Public);
if (field == null)
{
Logger.LogDebug((object)"Getting keybinds field from InputHelper failed, stopped trying to remove keybinds");
return;
}
if (!(field.GetValue(null) is IDictionary dictionary))
{
Logger.LogDebug((object)"Getting keybinds from the field failed, stopped trying to remove keybinds");
return;
}
dictionary.Clear();
Logger.LogInfo((object)"All LCST keybinds has been removed");
}
private static string CommaJoin(int[] i)
{
return GeneralExtensions.Join<int>((IEnumerable<int>)i, (Func<int, string>)null, ",").ToString();
}
private static bool CommaSplit(string input, out int[] values)
{
string[] array = input.Split(',');
values = new int[array.Length];
for (int i = 0; i < array.Length; i++)
{
if (!int.TryParse(array[i].Trim(), out values[i]))
{
values = Array.Empty<int>();
return false;
}
}
return true;
}
public void SetupKeybindCallbacks()
{
InputActionsInstance.ChangeFPS.performed += OnChangeFPSPressed;
}
public void OnChangeFPSPressed(CallbackContext changeFPSConext)
{
if (!((CallbackContext)(ref changeFPSConext)).performed)
{
return;
}
Settings settings = IngamePlayerSettings.Instance.settings;
if (settings == null)
{
Logger.LogError((object)"Settings not found!");
HUDManager.Instance.DisplayTip("FPSChanger", "Settings not found!", true, false, "LC_Tip1");
return;
}
currentGameIndex = settings.framerateCapIndex;
currentSetting = ingameFPSCaps[currentGameIndex];
if (!FPSValues.Contains(currentSetting))
{
Logger.LogInfo((object)$"Current FPS setting: {currentSetting}, not in the FPSValues array -> setting index to -1");
currentModIndex = -1;
}
currentModIndex = (currentModIndex + 1) % FPSValues.Length;
currentSetting = FPSValues[currentModIndex];
currentGameIndex = Array.IndexOf(ingameFPSCaps, currentSetting);
settings.framerateCapIndex = currentGameIndex;
try
{
ES3.Save<int>("FPSCap", currentGameIndex, filePath);
}
catch
{
Logger.LogWarning((object)"Was not able to write into the settings file");
}
IngamePlayerSettings.Instance.UpdateGameToMatchSettings();
string text = ((currentSetting == -1) ? "Vsync" : currentSetting.ToString());
HUDManager.Instance.DisplayTip("FPSChanger", "Changed FPS cap to " + text, false, false, "LC_Tip1");
Logger.LogInfo((object)$"FPS cap changed to: {text}, index: {currentGameIndex}");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "gafoneo.fpschanger";
public const string PLUGIN_NAME = "FPSChanger";
public const string PLUGIN_VERSION = "1.0.1";
}
}