Decompiled source of RepoOptimizer v1.0.4

RepoOptimizer.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Scripting;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RepoOptimizationMod;

[BepInPlugin("com.kostyan_321.repo.optimization", "RepoOptimizer by kostyan_321", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
	public static ManualLogSource Log;

	private List<Light> _allLights = new List<Light>();

	private List<SkinnedMeshRenderer> _allSkins = new List<SkinnedMeshRenderer>();

	private List<ParticleSystem> _allParticles = new List<ParticleSystem>();

	private int _lightIndex = 0;

	private int _partIndex = 0;

	private float _cacheTimer = 0f;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"!!! [RepoOptimizer] Safe & No Audio Loaded !!!");
		Application.SetStackTraceLogType((LogType)3, (StackTraceLogType)0);
		Application.SetStackTraceLogType((LogType)2, (StackTraceLogType)0);
		GarbageCollector.GCMode = (Mode)1;
		ApplyGlobalSettings();
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		ApplyGlobalSettings();
		Resources.UnloadUnusedAssets();
		GC.Collect();
		_allLights.Clear();
		_allSkins.Clear();
		_allParticles.Clear();
		_lightIndex = 0;
		_partIndex = 0;
		_cacheTimer = 0f;
	}

	private void ApplyGlobalSettings()
	{
		QualitySettings.antiAliasing = 0;
		QualitySettings.anisotropicFiltering = (AnisotropicFiltering)0;
		QualitySettings.shadows = (ShadowQuality)1;
		QualitySettings.shadowCascades = 1;
		QualitySettings.shadowDistance = 15f;
		QualitySettings.pixelLightCount = 2;
		QualitySettings.lodBias = 1f;
		QualitySettings.softParticles = false;
		QualitySettings.softVegetation = false;
		QualitySettings.realtimeReflectionProbes = false;
		QualitySettings.particleRaycastBudget = 0;
		QualitySettings.streamingMipmapsActive = false;
		Time.maximumDeltaTime = 0.1f;
		Camera main = Camera.main;
		if ((Object)(object)main != (Object)null)
		{
			main.farClipPlane = 150f;
			float[] array = new float[32];
			for (int i = 8; i < 32; i++)
			{
				array[i] = 60f;
			}
			main.layerCullDistances = array;
			main.layerCullSpherical = true;
		}
	}

	private void Update()
	{
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		_cacheTimer += Time.deltaTime;
		if (_cacheTimer < 10f)
		{
			return;
		}
		if (_allLights.Count == 0)
		{
			_allLights.AddRange(Object.FindObjectsByType<Light>((FindObjectsSortMode)0));
			_allParticles.AddRange(Object.FindObjectsByType<ParticleSystem>((FindObjectsSortMode)0));
			_allSkins.AddRange(Object.FindObjectsByType<SkinnedMeshRenderer>((FindObjectsSortMode)0));
			foreach (SkinnedMeshRenderer allSkin in _allSkins)
			{
				if ((Object)(object)allSkin != (Object)null)
				{
					allSkin.updateWhenOffscreen = false;
				}
			}
			Log.LogInfo((object)$"[Optimizer] Cached: {_allLights.Count} Lights, {_allParticles.Count} Particles, {_allSkins.Count} Skins.");
		}
		Camera main = Camera.main;
		if (!((Object)(object)main == (Object)null))
		{
			Vector3 position = ((Component)main).transform.position;
			ProcessLightSlice(position);
			ProcessParticleSlice(position);
		}
	}

	private void ProcessLightSlice(Vector3 playerPos)
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Invalid comparison between Unknown and I4
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Invalid comparison between Unknown and I4
		if (_allLights.Count == 0)
		{
			return;
		}
		int num = 0;
		while (num < 50 && _lightIndex < _allLights.Count)
		{
			Light val = _allLights[_lightIndex];
			_lightIndex++;
			num++;
			if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.layer != 5 && (int)val.type == 2 && val.range < 15f && (int)val.shadows != 0)
			{
				val.shadows = (LightShadows)0;
			}
		}
		if (_lightIndex >= _allLights.Count)
		{
			_lightIndex = 0;
		}
	}

	private void ProcessParticleSlice(Vector3 playerPos)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_006c: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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)
		if (_allParticles.Count == 0)
		{
			return;
		}
		int num = 0;
		while (num < 50 && _partIndex < _allParticles.Count)
		{
			ParticleSystem val = _allParticles[_partIndex];
			_partIndex++;
			num++;
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			Vector3 val2 = ((Component)val).transform.position - playerPos;
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			EmissionModule emission;
			if (sqrMagnitude > 1600f)
			{
				emission = val.emission;
				if (((EmissionModule)(ref emission)).enabled)
				{
					((EmissionModule)(ref emission)).enabled = false;
				}
			}
			else
			{
				emission = val.emission;
				if (!((EmissionModule)(ref emission)).enabled)
				{
					((EmissionModule)(ref emission)).enabled = true;
				}
			}
		}
		if (_partIndex >= _allParticles.Count)
		{
			_partIndex = 0;
		}
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
	}
}