using System;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
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.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8dc4e6f347d01091dcca1939c80d0bc2096bc682")]
[assembly: AssemblyProduct("FPSChanger")]
[assembly: AssemblyTitle("gafoneo.fpschanger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class FPSChanger : BaseUnityPlugin
{
internal static ManualLogSource Logger;
private ConfigEntry<string> fpsValues;
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");
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();
}
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;
IngamePlayerSettings.Instance.UpdateGameToMatchSettings();
try
{
ES3.Save<int>("FPSCap", currentGameIndex, filePath);
}
catch
{
Logger.LogWarning((object)"Was not able to write into the settings file");
}
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.0";
}
}