Decompiled source of SizeScaler v1.0.0

SizeScaler.dll

Decompiled 20 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using RoR2;
using RoR2.Projectile;
using SizeScaler.Changes;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SizeScaler")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SizeScaler")]
[assembly: AssemblyTitle("SizeScaler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 SizeScaler
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("com.Bloonjitsu7.SizeScaler", "SizeScaler", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MainPlugin : BaseUnityPlugin
	{
		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			Main main = new Main();
			Config.configFile = ((BaseUnityPlugin)this).Config;
			Config.SetupConfig(((BaseUnityPlugin)this).Config);
			main.Initialize();
		}
	}
}
namespace SizeScaler.Changes
{
	public static class Config
	{
		public static ConfigFile configFile;

		public static void SetupConfig(ConfigFile cfg)
		{
		}
	}
	public class Main
	{
		public class SizeScalingComponent : MonoBehaviour
		{
			public float scale;

			public float mass;

			public CharacterBody body;

			public void Start()
			{
				body = ((Component)this).gameObject.GetComponent<CharacterBody>();
				if (Object.op_Implicit((Object)(object)body))
				{
					ScaleTransitionManager.scaleChangeDuration = 0f;
					body.desiredScale = scale;
					if (Object.op_Implicit((Object)(object)body.characterMotor))
					{
						CharacterMotor characterMotor = body.characterMotor;
						characterMotor.mass *= mass;
					}
				}
			}

			public void FixedUpdate()
			{
				if (Object.op_Implicit((Object)(object)body))
				{
					ScaleTransitionManager.scaleChangeDuration = 0f;
					body.desiredScale = scale;
				}
			}
		}

		private static Hook hook;

		public static List<ConfigEntry<float>> configBodySize = new List<ConfigEntry<float>>();

		public static List<ConfigEntry<float>> configBodyMass = new List<ConfigEntry<float>>();

		public static List<ConfigEntry<float>> configProjectileSize = new List<ConfigEntry<float>>();

		public void Initialize()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnLoad));
			MethodInfo methodInfo = AccessTools.Method(typeof(ScaleTransitionManager), "StartScaleTransition", (Type[])null, (Type[])null);
			hook = new Hook((MethodBase)methodInfo, (Delegate)new Action<Action<CharacterBody>, CharacterBody>(OnStartTransition));
		}

		public void OnLoad()
		{
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Expected O, but got Unknown
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs)
			{
				configBodySize.Add(Config.configFile.Bind<float>(new string("Body " + ((Object)allBodyPrefab).name), "Size", 1f, "Changes the size multiplier of this entity."));
				configBodyMass.Add(Config.configFile.Bind<float>(new string("Body " + ((Object)allBodyPrefab).name), "Mass", 1f, "Changes the mass multiplier of this entity."));
				if (configBodySize[num].Value != 1f || configBodyMass[num].Value != 1f)
				{
					Log.Message(((Object)allBodyPrefab).name + ": scale set to " + configBodySize[num].Value);
					Log.Message(((Object)allBodyPrefab).name + ": mass set to " + configBodyMass[num].Value);
					SizeScalingComponent sizeScalingComponent = allBodyPrefab.AddComponent<SizeScalingComponent>();
					sizeScalingComponent.scale = configBodySize[num].Value;
					sizeScalingComponent.mass = configBodyMass[num].Value;
				}
				num++;
			}
			int num2 = 0;
			GameObject[] projectilePrefabs = ProjectileCatalog.projectilePrefabs;
			foreach (GameObject val in projectilePrefabs)
			{
				configProjectileSize.Add(Config.configFile.Bind<float>(new string("Projectile " + ((Object)val).name), "Size", 1f, "Changes the size of this projectile."));
				if (configProjectileSize[num2].Value != 1f)
				{
					Log.Message(((Object)val).name + ": scale set to " + configProjectileSize[num2].Value);
					ProjectileController component = val.GetComponent<ProjectileController>();
					if ((Object)(object)component != (Object)null)
					{
						GameObject val2 = ((AssetReference)component.ghostPrefabAddress).LoadAssetAsync<GameObject>().WaitForCompletion();
						if ((Object)(object)val2 != (Object)null)
						{
							Log.Message("Success");
							foreach (Transform componentInChild in val2.GetComponentInChildren<Transform>())
							{
								Transform val3 = componentInChild;
								val3.localScale *= configProjectileSize[num2].Value;
							}
						}
					}
					foreach (Transform componentInChild2 in val.GetComponentInChildren<Transform>())
					{
						Transform val4 = componentInChild2;
						val4.localScale *= configProjectileSize[num2].Value;
					}
				}
				num2++;
			}
		}

		public void OnStartTransition(Action<CharacterBody> orig, CharacterBody body)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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)
			SizeScalingComponent component = ((Component)body).GetComponent<SizeScalingComponent>();
			if ((Object)(object)component != (Object)null)
			{
				int transitionIndexForValidBody = ScaleTransitionManager.GetTransitionIndexForValidBody(body);
				ScaleTransitionInfo value = ScaleTransitionManager.currentScaleTransitions[transitionIndexForValidBody];
				float currentScale = body.currentScale;
				float scale = component.scale;
				value.valueApproacher = new ApproachValueLinear(currentScale, scale, Mathf.Abs(scale - currentScale) / 0.01f, TimeArg.op_Implicit(FixedTimeStamp.now));
				ScaleTransitionManager.currentScaleTransitions[transitionIndexForValidBody] = value;
			}
			else
			{
				orig(body);
			}
		}

		public static void DumpComponents(GameObject gameObject)
		{
			Component[] componentsInChildren = gameObject.GetComponentsInChildren(typeof(Component));
			foreach (Component data in componentsInChildren)
			{
				Log.Message(data);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}