Decompiled source of AtlyssCharacterFreedom v1.3.0

AtlyssCharacterFreedom.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("portalsam")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+7baeb1bf7aa690f07bb04d2aab982b1ff7bcc6e2")]
[assembly: AssemblyProduct("AtlyssCharacterFreedom")]
[assembly: AssemblyTitle("AtlyssCharacterFreedom")]
[assembly: AssemblyVersion("1.3.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace AtlyssCharacterFreedom
{
	public static class CameraCollisionPatch
	{
		[HarmonyPatch(typeof(CameraCollision), "LateUpdate")]
		public static class CameraCollisionTranspilerPatch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Expected O, but got Unknown
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Expected O, but got Unknown
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				int num = -1;
				bool flag = false;
				for (int i = 0; i < list.Count - 1; i++)
				{
					if (list[i].opcode == OpCodes.Ldc_R4 && list[i].operand is float num2 && !flag && Mathf.Approximately(num2, 60f))
					{
						num = i;
						flag = true;
					}
					if (num != -1)
					{
						break;
					}
				}
				list.RemoveRange(num - 2, 7);
				MethodInfo methodInfo = AccessTools.Method(typeof(CameraCollisionPatch), "CalculateCameraClamp", new Type[1] { typeof(CameraCollision) }, (Type[])null);
				List<CodeInstruction> collection = new List<CodeInstruction>
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)methodInfo)
				};
				list.InsertRange(num - 2, collection);
				return list.AsEnumerable();
			}
		}

		public static void CalculateCameraClamp(CameraCollision instance)
		{
			float num = Player._mainPlayer._pVisual._playerAppearanceStruct._heightWeight.Remap(1f, 100f, 60f, 1500f);
			if (instance.maxDistance > num)
			{
				instance.maxDistance = num;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterCreationManager), "Handle_CharacterCreationDisplay")]
	internal static class CharacterCreationManagerPatch
	{
		private static readonly CharacterParamsGroup templateParamsGroup = new CharacterParamsGroup();

		private static void Prefix(CharacterCreationManager __instance)
		{
			object? value = ((object)__instance).GetType().GetField("_currentRaceModel", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
			((PlayerRaceModel)((value is PlayerRaceModel) ? value : null))._scriptablePlayerRace._raceDisplayParams = templateParamsGroup;
		}
	}
	[BepInPlugin("net.portalsam.AtlyssCharacterFreedom", "CharacterFreedom", "1.3.0.0")]
	[BepInProcess("ATLYSS.exe")]
	public class CharacterFreedom : BaseUnityPlugin
	{
		internal static CharacterFreedom Instance;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Configuration.BindConfiguration();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Logger.LogInfo((object)"CharacterFreedom has been initialized!");
		}

		internal static ConfigFile GetConfig()
		{
			return ((BaseUnityPlugin)Instance).Config;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class CharacterParamsGroupPatch
	{
		private static void Postfix(CharacterParamsGroup __instance)
		{
			__instance._armRange.x = Configuration.ArmMinimumRange.Value;
			__instance._bellyRange.x = Configuration.BellyMinimumRange.Value;
			__instance._boobRange.x = Configuration.BoobMinimumRange.Value;
			__instance._pitchRange.x = Configuration.PitchMinimumRange.Value;
			__instance._bottomRange.x = Configuration.BottomMinimumRange.Value;
			__instance._heightRange.x = Configuration.HeightMinimumRange.Value;
			__instance._torsoRange.x = Configuration.TorsoMinimumRange.Value;
			__instance._widthRange.x = Configuration.WidthMinimumRange.Value;
			__instance._headModRange.x = Configuration.HeadModMinimumRange.Value;
			__instance._headWidthRange.x = Configuration.HeadWidthMinimumRange.Value;
			__instance._armRange.y = Configuration.ArmMaximumRange.Value;
			__instance._bellyRange.y = Configuration.BellyMaximumRange.Value;
			__instance._boobRange.y = Configuration.BoobMaximumRange.Value;
			__instance._pitchRange.y = Configuration.PitchMaximumRange.Value;
			__instance._bottomRange.y = Configuration.BottomMaximumRange.Value;
			__instance._heightRange.y = Configuration.HeightMaximumRange.Value;
			__instance._torsoRange.y = Configuration.TorsoMaximumRange.Value;
			__instance._widthRange.y = Configuration.WidthMaximumRange.Value;
			__instance._headModRange.y = Configuration.HeadModMaximumRange.Value;
			__instance._headWidthRange.y = Configuration.HeadWidthMaximumRange.Value;
		}
	}
	internal static class Configuration
	{
		public static ConfigEntry<float> ArmMinimumRange;

		public static ConfigEntry<float> BellyMinimumRange;

		public static ConfigEntry<float> BoobMinimumRange;

		public static ConfigEntry<float> PitchMinimumRange;

		public static ConfigEntry<float> BottomMinimumRange;

		public static ConfigEntry<float> HeightMinimumRange;

		public static ConfigEntry<float> TorsoMinimumRange;

		public static ConfigEntry<float> WidthMinimumRange;

		public static ConfigEntry<float> HeadModMinimumRange;

		public static ConfigEntry<float> HeadWidthMinimumRange;

		public static ConfigEntry<float> ArmMaximumRange;

		public static ConfigEntry<float> BellyMaximumRange;

		public static ConfigEntry<float> BoobMaximumRange;

		public static ConfigEntry<float> PitchMaximumRange;

		public static ConfigEntry<float> BottomMaximumRange;

		public static ConfigEntry<float> HeightMaximumRange;

		public static ConfigEntry<float> TorsoMaximumRange;

		public static ConfigEntry<float> WidthMaximumRange;

		public static ConfigEntry<float> HeadModMaximumRange;

		public static ConfigEntry<float> HeadWidthMaximumRange;

		public static ConfigEntry<bool> SafetyEnabled;

		internal static void BindConfiguration()
		{
			ArmMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "ArmMinimumRange", -5f, "The minimum value that the arm slider will produce in character menus.");
			BellyMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "BellyMinimumRange", -20f, "The minimum value that the belly slider will produce in character menus.");
			BoobMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "BoobMinimumRange", -20f, "The minimum value that the boob slider will produce in character menus.");
			PitchMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "PitchMinimumRange", 0.5f, "The minimum value that the pitch slider will produce in character menus.");
			BottomMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "BottomMinimumRange", -50f, "The minimum value that the bottom slider will produce in character menus.");
			HeightMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "HeightMinimumRange", 0.05f, "The minimum value that the height slider will produce in character menus.");
			TorsoMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "TorsoMinimumRange", -10f, "The minimum value that the torso slider will produce in character menus.");
			WidthMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "WidthMinimumRange", 0.05f, "The minimum value that the width slider will produce in character menus.");
			HeadModMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "HeadModMinimumRange", 0f, "The minimum value that the head modification slider will produce in character menus.");
			HeadWidthMinimumRange = CharacterFreedom.GetConfig().Bind<float>("MinimumValues", "HeadWidthMinimumRange", 0.95f, "The minimum value that the head width slider will produce in character menus.");
			ArmMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "ArmMaximumRange", 105f, "The maximum value that the arm slider will produce in character menus.");
			BellyMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "BellyMaximumRange", 512f, "The maximum value that the belly slider will produce in character menus.");
			BoobMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "BoobMaximumRange", 512f, "The maximum value that the boob slider will produce in character menus.");
			PitchMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "PitchMaximumRange", 2f, "The maximum value that the pitch slider will produce in character menus.");
			BottomMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "BottomMaximumRange", 512f, "The maximum value that the bottom slider will produce in character menus.");
			HeightMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "HeightMaximumRange", 1.5f, "The maximum value that the height slider will produce in character menus.");
			TorsoMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "TorsoMaximumRange", 105f, "The maximum value that the torso slider will produce in character menus.");
			WidthMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "WidthMaximumRange", 1.5f, "The maximum value that the width slider will produce in character menus.");
			HeadModMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "HeadModMaximumRange", 100f, "The maximum value that the head modification slider will produce in character menus.");
			HeadWidthMaximumRange = CharacterFreedom.GetConfig().Bind<float>("MaximumValues", "HeadWidthMaximumRange", 1.15f, "The maximum value that the head width slider will produce in character menus.");
			SafetyEnabled = CharacterFreedom.GetConfig().Bind<bool>("Safety", "SafetyEnabled", false, "Enables safety settings, clamping other players avatars to the sizes defined in your personal config.");
		}
	}
	public static class MathfExtensions
	{
		public static float Remap(this float value, float inputMinimum, float inputMaximum, float outputMinimum, float outputMaximum)
		{
			return (value - inputMinimum) * (outputMaximum - outputMinimum) / (inputMaximum - inputMinimum) + outputMinimum;
		}
	}
	[HarmonyPatch(typeof(ScriptablePlayerRace), "Init_ParamsCheck")]
	internal static class ScriptablePlayerRacePatch
	{
		private static bool Prefix(ScriptablePlayerRace __instance, ref PlayerAppearance_Profile __result, PlayerAppearance_Profile _aP)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			CharacterParamsGroup raceDisplayParams = new CharacterParamsGroup();
			__instance._raceDisplayParams = raceDisplayParams;
			if (Configuration.SafetyEnabled.Value)
			{
				return true;
			}
			__result = _aP;
			return false;
		}
	}
}