Decompiled source of Player Resize v1.1.0

PlayerResize.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GTFO.API;
using GTFO.API.Utilities;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ModifierAPI;
using OptionalNetworking;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PlayerResize")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a0ea3b90dcd89bba21a3362c8e43857837800783")]
[assembly: AssemblyProduct("PlayerResize")]
[assembly: AssemblyTitle("PlayerResize")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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 PlayerResize
{
	public static class Configuration
	{
		private static readonly ConfigEntry<float> _sizeMulti;

		private static readonly ConfigEntry<float> _jumpForceMulti;

		private static readonly ConfigEntry<float> _speedMulti;

		private static readonly ConfigEntry<float> _healthMulti;

		private static readonly ConfigFile _configFile;

		public static float SizeMulti => _sizeMulti.Value;

		public static float JumpForceMulti => _jumpForceMulti.Value;

		public static float SpeedMulti => _speedMulti.Value;

		public static float HealthMulti => _healthMulti.Value;

		static Configuration()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			_configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "PlayerResize.cfg"), true);
			string text = "Value Settings";
			string text2 = "Player size multiplier. Scales height and hitbox size.";
			_sizeMulti = _configFile.Bind<float>(text, "Player Size Multi", 0.35f, text2);
			text2 = "Movement speed multiplier.";
			_speedMulti = _configFile.Bind<float>(text, "Movement Speed Multi", 0.65f, text2);
			text2 = "Jump force multiplier.";
			_jumpForceMulti = _configFile.Bind<float>(text, "Jump Force Multi", 0.85f, text2);
			text2 = "Health multiplier.";
			_healthMulti = _configFile.Bind<float>(text, "Health Multi", 1f, text2);
		}

		internal static void Init()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			LiveEdit.CreateListener(Paths.ConfigPath, "PlayerResize.cfg", false).FileChanged += new LiveEditEventHandler(OnFileReloaded);
		}

		private static void OnFileReloaded(LiveEditEventArgs _)
		{
			_configFile.Reload();
			PlayerResize.OnConfigReload();
		}
	}
	internal static class DinoLogger
	{
		private static readonly ManualLogSource _logger = Logger.CreateLogSource("PlayerResize");

		public static void Log(string format, params object[] args)
		{
			Log(string.Format(format, args));
		}

		public static void Log(string str)
		{
			if (_logger != null)
			{
				_logger.Log((LogLevel)8, (object)str);
			}
		}

		public static void Warning(string format, params object[] args)
		{
			Warning(string.Format(format, args));
		}

		public static void Warning(string str)
		{
			if (_logger != null)
			{
				_logger.Log((LogLevel)4, (object)str);
			}
		}

		public static void Error(string format, params object[] args)
		{
			Error(string.Format(format, args));
		}

		public static void Error(string str)
		{
			if (_logger != null)
			{
				_logger.Log((LogLevel)2, (object)str);
			}
		}

		public static void Debug(string format, params object[] args)
		{
			Debug(string.Format(format, args));
		}

		public static void Debug(string str)
		{
			if (_logger != null)
			{
				_logger.Log((LogLevel)32, (object)str);
			}
		}
	}
	[BepInPlugin("com.Brandonious.PlayerResize", "PlayerResize", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal sealed class EntryPoint : BasePlugin
	{
		public const string MODNAME = "PlayerResize";

		public override void Load()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Configuration.Init();
			PlayerResize.Init();
			new Harmony("PlayerResize").PatchAll();
			DinoLogger.Log("Loaded PlayerResize");
		}
	}
	[HarmonyPatch]
	public static class PlayerResize
	{
		private struct ResizeData
		{
			public float Size;

			public float Health;
		}

		private static readonly HashSet<IntPtr> _modifiedAgents = new HashSet<IntPtr>();

		private static readonly IStatModifier _speedModifier = MoveSpeedAPI.AddModifier(1f, (StackLayer)0, "PlayerResize");

		private static ModInfo _modInfo = null;

		private static CustomDataManager<ResizeData> _data = null;

		private static float _jump;

		private static float _walkFootstep;

		private static float _runFootstep;

		private static float _crouchFootstep;

		private static float _camPos;

		private static float _camPosCrouch;

		private static PlayerDataBlock? _playerData;

		private static PlayerAgent? _localPlayer;

		internal static void Init()
		{
			LevelAPI.OnEnterLevel += LevelStarted;
			_modInfo = OptionalNetworkAPI.RegisterMod("PlayerResize");
			_modInfo.OnLobbyLeft += OnLobbyLeft;
			_modInfo.OnPlayerSpawned += OnSpawn;
			_modInfo.OnPlayerDespawned += OnDespawn;
			_data = _modInfo.AddCustomDataManager<ResizeData>((Func<SNet_Player, ResizeData>)((SNet_Player _) => CreateData()));
			_data.PreDataSet += PreSetData;
			_data.OnDataRemoved += RemoveData;
		}

		private static ResizeData CreateData()
		{
			return new ResizeData
			{
				Size = Configuration.SizeMulti,
				Health = Configuration.HealthMulti
			};
		}

		internal static void OnConfigReload()
		{
			//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)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Invalid comparison between Unknown and I4
			//IL_00a1: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Invalid comparison between Unknown and I4
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			((CustomDataSender<ResizeData>)(object)_data).SendData(CreateData(), (SNet_Player)null, (SNet_ChannelType)0);
			if (SNet.IsMaster)
			{
				foreach (SNet_Player bot in _modInfo.Bots)
				{
					((CustomDataSender<ResizeData>)(object)_data).SendData(bot, CreateData(), (SNet_Player)null, (SNet_ChannelType)0);
				}
			}
			_speedModifier.Mod = Configuration.SpeedMulti;
			ReloadDB();
			if ((Object)(object)_localPlayer != (Object)null && _playerData != null)
			{
				PLOC_State currentStateEnum = _localPlayer.Locomotion.m_currentStateEnum;
				Vector3 val = (((int)currentStateEnum == 1) ? _playerData.camPosCrouch : (((int)currentStateEnum != 7) ? _playerData.camPosDefault : Vector3.zero));
				Vector3 val2 = val;
				if (val2 != Vector3.zero)
				{
					_localPlayer.FPSCamera.SetNewPosOffset(val2);
				}
			}
		}

		private static void PreSetData(SNet_Player player, ResizeData data)
		{
			if (RundownManager.ExpeditionIsStarted && player.HasPlayerAgent)
			{
				PlayerAgent val = ((Il2CppObjectBase)player.PlayerAgent).Cast<PlayerAgent>();
				ResizeData resizeData = default(ResizeData);
				if (_data.TryGetData(player, ref resizeData) && _modifiedAgents.Contains(((Il2CppObjectBase)player).Pointer))
				{
					Dam_PlayerDamageBase damage = val.Damage;
					((Dam_SyncedDamageBase)damage).Health = ((Dam_SyncedDamageBase)damage).Health / resizeData.Health;
					Dam_PlayerDamageBase damage2 = val.Damage;
					((Dam_SyncedDamageBase)damage2).HealthMax = ((Dam_SyncedDamageBase)damage2).HealthMax / resizeData.Health;
				}
				ApplyData(val, data);
			}
		}

		private static void RemoveData(SNet_Player player, ResizeData data)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (RundownManager.ExpeditionIsStarted && player.HasPlayerAgent)
			{
				PlayerAgent val = ((Il2CppObjectBase)player.PlayerAgent).Cast<PlayerAgent>();
				if (_modifiedAgents.Remove(((Il2CppObjectBase)player).Pointer))
				{
					((Component)val).transform.localScale = Vector3.one;
					Dam_PlayerDamageBase damage = val.Damage;
					((Dam_SyncedDamageBase)damage).Health = ((Dam_SyncedDamageBase)damage).Health / data.Health;
					Dam_PlayerDamageBase damage2 = val.Damage;
					((Dam_SyncedDamageBase)damage2).HealthMax = ((Dam_SyncedDamageBase)damage2).HealthMax / data.Health;
				}
			}
		}

		private static void ApplyData(PlayerAgent player, ResizeData data)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			((Component)player).transform.localScale = Vector3.one * data.Size;
			_modifiedAgents.Add(((Il2CppObjectBase)player).Pointer);
			Dam_PlayerDamageBase damage = player.Damage;
			((Dam_SyncedDamageBase)damage).Health = ((Dam_SyncedDamageBase)damage).Health * data.Health;
			Dam_PlayerDamageBase damage2 = player.Damage;
			((Dam_SyncedDamageBase)damage2).HealthMax = ((Dam_SyncedDamageBase)damage2).HealthMax * data.Health;
		}

		private static void OnSpawn(PlayerAgent player)
		{
			if (((Agent)player).IsLocallyOwned)
			{
				_localPlayer = player;
			}
			ResizeData data = default(ResizeData);
			if (RundownManager.ExpeditionIsStarted && _data.TryGetData(player.Owner, ref data) && !_modifiedAgents.Contains(((Il2CppObjectBase)player).Pointer))
			{
				ApplyData(player, data);
			}
		}

		private static void OnDespawn(PlayerAgent player)
		{
			if (((Agent)player).IsLocallyOwned)
			{
				_localPlayer = null;
			}
			_modifiedAgents.Remove(((Il2CppObjectBase)player).Pointer);
		}

		private static void OnLobbyLeft()
		{
			_localPlayer = null;
			_modifiedAgents.Clear();
		}

		private static void LevelStarted()
		{
			//IL_0046: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<PlayerAgent> enumerator = PlayerManager.PlayerAgentsInLevel.GetEnumerator();
			ResizeData data = default(ResizeData);
			while (enumerator.MoveNext())
			{
				PlayerAgent current = enumerator.Current;
				if (_data.TryGetData(current.Owner, ref data))
				{
					ApplyData(current, data);
				}
			}
			((Component)_localPlayer.AnimatorArms).transform.localScale = Vector3.one * 0.1f;
			((Component)_localPlayer.AnimatorBody).transform.localScale = Vector3.one * 0.1f;
			_speedModifier.Enable(Configuration.SpeedMulti);
			ModifyDB();
		}

		private static void ReloadDB()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if (_playerData != null)
			{
				_playerData.jumpVelInitial = _jump;
				_playerData.walkFootstepLength = _walkFootstep;
				_playerData.runFootstepLength = _runFootstep;
				_playerData.crouchFootstepLength = _crouchFootstep;
				_playerData.camPosDefault = new Vector3(0f, _camPos, 0f);
				_playerData.camPosCrouch = new Vector3(0f, _camPosCrouch, 0f);
				_playerData = null;
				ModifyDB();
			}
		}

		private static void ModifyDB()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			PlayerDataBlock block = GameDataBlockBase<PlayerDataBlock>.GetBlock(1u);
			PlayerDataBlock? playerData = _playerData;
			if (!(((playerData != null) ? new IntPtr?(((Il2CppObjectBase)playerData).Pointer) : ((IntPtr?)null)) == ((Il2CppObjectBase)block).Pointer))
			{
				_playerData = block;
				_jump = _playerData.jumpVelInitial;
				PlayerDataBlock? playerData2 = _playerData;
				playerData2.jumpVelInitial *= Configuration.JumpForceMulti;
				_walkFootstep = _playerData.walkFootstepLength;
				PlayerDataBlock? playerData3 = _playerData;
				playerData3.walkFootstepLength *= Configuration.SpeedMulti;
				_runFootstep = _playerData.runFootstepLength;
				PlayerDataBlock? playerData4 = _playerData;
				playerData4.runFootstepLength *= Configuration.SpeedMulti;
				_crouchFootstep = _playerData.crouchFootstepLength;
				PlayerDataBlock? playerData5 = _playerData;
				playerData5.crouchFootstepLength *= Configuration.SpeedMulti;
				_camPos = _playerData.camPosDefault.y;
				_playerData.camPosDefault = new Vector3(0f, _camPos * Configuration.SizeMulti, 0f);
				_camPosCrouch = _playerData.camPosCrouch.y;
				_playerData.camPosCrouch = new Vector3(0f, _camPosCrouch * Configuration.SizeMulti, 0f);
			}
		}
	}
}