using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BalancedCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BalancedCompany")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cd4ba972-ea9e-439a-a2ea-e2bcf04dea26")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Kittros.BalancedCompany;
[BepInPlugin("Kittros.balancedcompany", "BalancedCompany", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public enum FPSPosition
{
TopLeft,
TopRight,
BottomLeft,
BottomRight
}
public enum FPSColor
{
Red,
Orange,
Yellow,
Green,
Blue,
Indigo,
Violet,
White,
Black
}
[CompilerGenerated]
private sealed class <EnableInstancingAsync>d__19 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public Plugin <>4__this;
private Material[] <allMaterials>5__1;
private int <totalMaterials>5__2;
private int <batchSize>5__3;
private int <i>5__4;
private int <j>5__5;
private Material <mat>5__6;
private Material <pooledMaterial>5__7;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <EnableInstancingAsync>d__19(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<allMaterials>5__1 = null;
<mat>5__6 = null;
<pooledMaterial>5__7 = null;
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<allMaterials>5__1 = Resources.FindObjectsOfTypeAll<Material>();
<totalMaterials>5__2 = <allMaterials>5__1.Length;
<batchSize>5__3 = 100;
<i>5__4 = 0;
break;
case 1:
<>1__state = -1;
<i>5__4 += <batchSize>5__3;
break;
}
if (<i>5__4 < <totalMaterials>5__2)
{
<j>5__5 = <i>5__4;
while (<j>5__5 < Mathf.Min(<i>5__4 + <batchSize>5__3, <totalMaterials>5__2))
{
<mat>5__6 = <allMaterials>5__1[<j>5__5];
if ((Object)(object)<mat>5__6.shader != (Object)null && <mat>5__6.shader.isSupported)
{
<pooledMaterial>5__7 = <>4__this.instancingPool.GetObject();
<pooledMaterial>5__7 = <mat>5__6;
<pooledMaterial>5__7.enableInstancing = true;
<pooledMaterial>5__7 = null;
}
<mat>5__6 = null;
<j>5__5++;
}
<>2__current = null;
<>1__state = 1;
return true;
}
((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"[BalancedCompany] Instancing enabled for all materials.");
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();
}
}
private ConfigEntry<bool> cfg_ShowFPS;
private ConfigEntry<FPSPosition> cfg_Position;
private ConfigEntry<FPSColor> cfg_Color;
private ConfigEntry<float> cfg_RefreshRate;
private ConfigEntry<int> cfg_FontSize;
private ConfigEntry<float> fixedDelta;
private ConfigEntry<int> solverIter;
private ConfigEntry<int> shaderLOD;
private ConfigEntry<bool> enableInstancing;
private float lastUpdateTime = 0f;
private float fps = 0f;
private int xPos = 10;
private int yPos = 10;
private GUIStyle fpsStyle;
private MaterialPool instancingPool;
private void Awake()
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected O, but got Unknown
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Expected O, but got Unknown
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Expected O, but got Unknown
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Expected O, but got Unknown
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01eb: Expected O, but got Unknown
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Expected O, but got Unknown
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Expected O, but got Unknown
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Expected O, but got Unknown
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_0232: Expected O, but got Unknown
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Expected O, but got Unknown
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Expected O, but got Unknown
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Expected O, but got Unknown
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Expected O, but got Unknown
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Expected O, but got Unknown
//IL_0285: Unknown result type (might be due to invalid IL or missing references)
//IL_0290: Expected O, but got Unknown
//IL_0296: Expected O, but got Unknown
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Expected O, but got Unknown
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Expected O, but got Unknown
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Expected O, but got Unknown
//IL_02bd: Expected O, but got Unknown
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02c2: Expected O, but got Unknown
//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
//IL_02d6: Expected O, but got Unknown
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Expected O, but got Unknown
//IL_02e8: Expected O, but got Unknown
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_02ed: Expected O, but got Unknown
//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"[BalancedCompany] Plugin loaded.");
cfg_ShowFPS = ((BaseUnityPlugin)this).Config.Bind<bool>("FPS", "ShowFPS", true, "This setting allows you to toggle the FPS (Frames Per Second) display on or off. If enabled, the FPS will be displayed in the game window.");
cfg_Position = ((BaseUnityPlugin)this).Config.Bind<FPSPosition>("FPS", "Position", FPSPosition.BottomRight, "This setting controls where the FPS counter appears on the screen.\n\nTopLeft: Displays the FPS in the top-left corner.\nTopRight: Displays the FPS in the top-right corner.\nBottomLeft: Displays the FPS in the bottom-left corner.\nBottomRight: Displays the FPS in the bottom-right corner.\n\nChoose the position based on your preference or the area where it doesn’t obstruct important game elements.");
cfg_Color = ((BaseUnityPlugin)this).Config.Bind<FPSColor>("FPS", "Color", FPSColor.Green, "This setting allows you to change the color of the FPS counter.\n\nColors: You can select from Red, Orange, Yellow, Green, Blue, Indigo, Violet, White, or Black.\n\nChanging the color can make it easier to read, or it can match the style of the game’s interface.");
cfg_RefreshRate = ((BaseUnityPlugin)this).Config.Bind<float>("FPS", "RefreshRate", 0.2f, new ConfigDescription("This setting defines how often the FPS value updates.\n\nLower values will update the FPS more frequently, making the FPS display more responsive, but this can reduce performance slightly.\n\nHigher values will update the FPS less often, which can help improve performance but make the FPS value less precise.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.02f, 2f), Array.Empty<object>()));
cfg_FontSize = ((BaseUnityPlugin)this).Config.Bind<int>("FPS", "FontSize", 18, new ConfigDescription("This setting controls the font size of the FPS display.\n\nIncreasing the font size makes the FPS more visible, but it will take up more space on the screen.\n\nDecreasing the font size makes it less obtrusive but may be harder to read if the screen is large.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 60), Array.Empty<object>()));
fixedDelta = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "FixedDeltaTime", 0.05f, "This setting defines the simulation tickrate for the physics engine.\n\nLower values improve the precision of physics calculations but can reduce the overall performance of the game.\nHigher values can improve performance, but physics calculations will become less accurate.");
solverIter = ((BaseUnityPlugin)this).Config.Bind<int>("Physics", "SolverIterations", 3, "This setting controls the number of solver iterations used in the physics engine.\n\nIncreasing the number of iterations improves the accuracy of physics simulations, such as collision detection and object interactions, but can impact performance.\nDecreasing the number of iterations will improve performance but may result in less precise simulations.");
shaderLOD = ((BaseUnityPlugin)this).Config.Bind<int>("Rendering", "ShaderMaxLOD", 200, "This setting defines the maximum level of detail for shaders in the game.\n\nHigher values improve visual quality by increasing the detail of shaders, but they also reduce performance.\nLower values boost performance by reducing shader complexity, but the game may appear less visually polished.");
enableInstancing = ((BaseUnityPlugin)this).Config.Bind<bool>("Rendering", "EnableInstancing", true, "This setting enables or disables GPU instancing.\n\nGPU instancing is a technique that reduces CPU load by grouping identical objects together to render them all in a single draw call.\nEnabling this setting can significantly improve performance in scenes with many identical objects, such as trees, rocks, or other repeated assets.");
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(cfg_ShowFPS, new BoolCheckBoxOptions
{
Name = "[FPS] by Kittros",
RequiresRestart = false
}));
LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<FPSPosition>(cfg_Position, new EnumDropDownOptions
{
Name = "Position",
RequiresRestart = false
}));
LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<FPSColor>(cfg_Color, new EnumDropDownOptions
{
Name = "Color",
RequiresRestart = false
}));
ConfigEntry<float> obj = cfg_RefreshRate;
FloatSliderOptions val = new FloatSliderOptions
{
Name = "Refresh Rate"
};
((BaseRangeOptions<float>)val).Min = 0.02f;
((BaseRangeOptions<float>)val).Max = 2f;
((BaseOptions)val).RequiresRestart = false;
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(obj, val));
ConfigEntry<int> obj2 = cfg_FontSize;
IntSliderOptions val2 = new IntSliderOptions
{
Name = "Font Size"
};
((BaseRangeOptions<int>)val2).Min = 8;
((BaseRangeOptions<int>)val2).Max = 60;
((BaseOptions)val2).RequiresRestart = false;
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(obj2, val2));
ConfigEntry<float> obj3 = fixedDelta;
FloatSliderOptions val3 = new FloatSliderOptions();
((BaseRangeOptions<float>)val3).Min = 0.02f;
((BaseRangeOptions<float>)val3).Max = 0.1f;
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(obj3, val3));
ConfigEntry<int> obj4 = solverIter;
IntSliderOptions val4 = new IntSliderOptions();
((BaseRangeOptions<int>)val4).Min = 1;
((BaseRangeOptions<int>)val4).Max = 10;
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(obj4, val4));
ConfigEntry<int> obj5 = shaderLOD;
IntSliderOptions val5 = new IntSliderOptions();
((BaseRangeOptions<int>)val5).Min = 100;
((BaseRangeOptions<int>)val5).Max = 400;
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(obj5, val5));
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(enableInstancing, false));
instancingPool = new MaterialPool(100);
ApplyOptimizations();
}
private void ApplyOptimizations()
{
if (Time.fixedDeltaTime != fixedDelta.Value)
{
Time.fixedDeltaTime = fixedDelta.Value;
}
if (Physics.defaultSolverIterations != solverIter.Value)
{
Physics.defaultSolverIterations = solverIter.Value;
Physics.defaultSolverVelocityIterations = 1;
}
if (Shader.globalMaximumLOD != shaderLOD.Value)
{
Shader.globalMaximumLOD = shaderLOD.Value;
}
if (enableInstancing.Value)
{
((MonoBehaviour)this).StartCoroutine(EnableInstancingAsync());
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"[BalancedCompany] Performance parameters applied.");
}
[IteratorStateMachine(typeof(<EnableInstancingAsync>d__19))]
private IEnumerator EnableInstancingAsync()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <EnableInstancingAsync>d__19(0)
{
<>4__this = this
};
}
private void Start()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_0042: Expected O, but got Unknown
fpsStyle = new GUIStyle
{
fontSize = cfg_FontSize.Value,
normal = new GUIStyleState
{
textColor = GetColor(cfg_Color.Value)
}
};
}
private void Update()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
if (cfg_ShowFPS.Value)
{
if (Time.time - lastUpdateTime >= cfg_RefreshRate.Value)
{
fps = 1f / Time.unscaledDeltaTime;
lastUpdateTime = Time.time;
}
UpdatePosition();
if (fpsStyle.normal.textColor != GetColor(cfg_Color.Value))
{
fpsStyle.normal.textColor = GetColor(cfg_Color.Value);
}
if (fpsStyle.fontSize != cfg_FontSize.Value)
{
fpsStyle.fontSize = cfg_FontSize.Value;
}
}
}
private void OnGUI()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
if (cfg_ShowFPS.Value)
{
GUI.Label(new Rect((float)xPos, (float)yPos, 200f, 20f), $"FPS: {fps:0}", fpsStyle);
}
}
private void UpdatePosition()
{
switch (cfg_Position.Value)
{
case FPSPosition.TopLeft:
xPos = 10;
yPos = 10;
fpsStyle.alignment = (TextAnchor)0;
break;
case FPSPosition.TopRight:
xPos = Screen.width - 210;
yPos = 10;
fpsStyle.alignment = (TextAnchor)2;
break;
case FPSPosition.BottomLeft:
xPos = 10;
yPos = Screen.height - 30;
fpsStyle.alignment = (TextAnchor)6;
break;
case FPSPosition.BottomRight:
xPos = Screen.width - 210;
yPos = Screen.height - 30;
fpsStyle.alignment = (TextAnchor)8;
break;
}
}
private Color GetColor(FPSColor color)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: 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_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: 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_0093: 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_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
return (Color)(color switch
{
FPSColor.Red => Color.red,
FPSColor.Orange => new Color(1f, 0.647f, 0f),
FPSColor.Yellow => Color.yellow,
FPSColor.Green => Color.green,
FPSColor.Blue => Color.blue,
FPSColor.Indigo => new Color(0.294f, 0f, 0.51f),
FPSColor.Violet => new Color(0.933f, 0.51f, 0.933f),
FPSColor.White => Color.white,
FPSColor.Black => Color.black,
_ => Color.white,
});
}
}
public class MaterialPool
{
private Queue<Material> pool;
private int poolSize;
public MaterialPool(int size)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
poolSize = size;
pool = new Queue<Material>(size);
for (int i = 0; i < poolSize; i++)
{
pool.Enqueue(new Material(Shader.Find("Standard")));
}
}
public Material GetObject()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
return (Material)((pool.Count > 0) ? ((object)pool.Dequeue()) : ((object)new Material(Shader.Find("Standard"))));
}
public void ReturnObject(Material mat)
{
if (pool.Count < poolSize)
{
pool.Enqueue(mat);
}
}
}