Decompiled source of OldCamera v1.0.0

Mods/OldCamera.dll

Decompiled 4 days 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 Il2Cpp;
using Il2CppCinemachine;
using Il2CppFemur;
using Il2CppGB.Core;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using Microsoft.CodeAnalysis;
using OldCamera;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(OldCameraMod), "OldCamera", "1.0.0", "Zooks", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("OldCamera")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("mod for Gang Beasts")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OldCamera")]
[assembly: AssemblyTitle("OldCamera")]
[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 OldCamera
{
	public class OldCameraMod : MelonMod
	{
		private float _cameraFrameDamping = 2.7f;

		private float _springConstant = 12f;

		private float _dampingCoefficient = 4f;

		private float _initialDummyWeight = 2.5f;

		private float _initialDummyRadius = 5f;

		private float _deathRemovalDelay = 2f;

		private float _fadeTimeMultiplier = 1.2f;

		private float _springDelay = 0.4f;

		private float _springRampDuration = 0.6f;

		private float _distanceThreshold = 200f;

		private float _distanceMaxThreshold = 300f;

		private List<Actor> _actors = new List<Actor>();

		private Dictionary<GangBeastsGroupComposer, float> _origDampings = new Dictionary<GangBeastsGroupComposer, float>();

		private HashSet<string> _aliveActorKeys = new HashSet<string>();

		private Dictionary<string, Vector3> _lastKnownPositions = new Dictionary<string, Vector3>();

		private Dictionary<string, GameObject> _trackingDummies = new Dictionary<string, GameObject>();

		private Dictionary<string, float> _dummyWeights = new Dictionary<string, float>();

		private Dictionary<string, Vector3> _dummyVelocities = new Dictionary<string, Vector3>();

		private Dictionary<string, float> _dummyLifetimes = new Dictionary<string, float>();

		private Dictionary<string, float> _dummyInitialDistances = new Dictionary<string, float>();

		private CMTargetGroupHandler _handler;

		private CMTargetGroupPool _pool;

		private float _origHumanWeight = 1f;

		private float _origHumanRadius = 2f;

		private float _origAiWeight;

		private float _origAiRadius = 2f;

		private float _origDeadRemovalDelay = 1f;

		private float _origDistanceThreshold = 15f;

		private float _origDistanceMaxThreshold = 25f;

		private bool _origTrackAi;

		private bool _hasCached;

		private float _debugTimer;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("oldcamera loaded.");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			_handler = null;
			_pool = null;
			_hasCached = false;
			_aliveActorKeys.Clear();
			_lastKnownPositions.Clear();
			_trackingDummies.Clear();
			_dummyWeights.Clear();
			_dummyVelocities.Clear();
			_dummyLifetimes.Clear();
			_dummyInitialDistances.Clear();
			((MelonBase)this).LoggerInstance.Msg("scene loaded: " + sceneName);
		}

		public override void OnUpdate()
		{
			ApplyTracking();
		}

		private void SafeAddToTargetGroup(CMTargetGroupPool pool, Transform target, TargetGroupAndTrackingInfo groupInfo, bool isHuman, float weight, float radius)
		{
			if ((Object)(object)pool == (Object)null || (Object)(object)target == (Object)null || groupInfo == null || (Object)(object)groupInfo.group == (Object)null)
			{
				return;
			}
			try
			{
				pool.AddToTargetGroup(target, groupInfo, isHuman, weight, radius, true, false);
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("[warning] safe add failed for " + ((Object)target).name + ": " + ex.Message);
			}
		}

		private void SafeRemoveFromTargetGroup(CMTargetGroupPool pool, Transform target, TargetGroupAndTrackingInfo groupInfo)
		{
			if ((Object)(object)pool == (Object)null || (Object)(object)target == (Object)null || groupInfo == null || (Object)(object)groupInfo.group == (Object)null)
			{
				return;
			}
			try
			{
				if (pool.Tracking(target, groupInfo.group))
				{
					pool.RemoveFromTargetGroup(target, groupInfo, false);
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("[warning] safe remove failed for " + ((Object)target).name + ": " + ex.Message);
			}
		}

		private void SetTargetPropertiesDirect(TargetGroupAndTrackingInfo groupInfo, Transform target, float weight, float radius)
		{
			if (groupInfo == null || (Object)(object)groupInfo.group == (Object)null || (Object)(object)target == (Object)null)
			{
				return;
			}
			try
			{
				Il2CppReferenceArray<Target> targets = groupInfo.group.m_Targets;
				if (targets == null)
				{
					return;
				}
				for (int i = 0; i < ((Il2CppArrayBase<Target>)(object)targets).Length; i++)
				{
					if ((Object)(object)((Il2CppArrayBase<Target>)(object)targets)[i].target == (Object)(object)target)
					{
						((Il2CppArrayBase<Target>)(object)targets)[i].weight = weight;
						((Il2CppArrayBase<Target>)(object)targets)[i].radius = radius;
						break;
					}
				}
			}
			catch (Exception)
			{
			}
		}

		private void ApplyTracking()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_051f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0556: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0586: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Invalid comparison between Unknown and I4
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f7: Expected O, but got Unknown
			//IL_0606: Unknown result type (might be due to invalid IL or missing references)
			//IL_0639: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0669: Unknown result type (might be due to invalid IL or missing references)
			//IL_066e: Unknown result type (might be due to invalid IL or missing references)
			//IL_076f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0774: Unknown result type (might be due to invalid IL or missing references)
			//IL_0776: Unknown result type (might be due to invalid IL or missing references)
			//IL_077b: Unknown result type (might be due to invalid IL or missing references)
			//IL_077e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0780: Unknown result type (might be due to invalid IL or missing references)
			//IL_0793: Unknown result type (might be due to invalid IL or missing references)
			//IL_0798: Unknown result type (might be due to invalid IL or missing references)
			//IL_079d: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07db: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0801: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (string.IsNullOrEmpty(name) || name == Global.MENU_SCENE_NAME)
			{
				return;
			}
			if ((Object)(object)_handler == (Object)null)
			{
				_handler = CMTargetGroupHandler.Instance ?? Object.FindObjectOfType<CMTargetGroupHandler>();
			}
			if ((Object)(object)_pool == (Object)null)
			{
				_pool = CMTargetGroupPool.Instance ?? Object.FindObjectOfType<CMTargetGroupPool>();
			}
			_debugTimer += Time.deltaTime;
			bool flag = _debugTimer >= 2f;
			if (flag)
			{
				_debugTimer = 0f;
			}
			if ((Object)(object)_handler == (Object)null || (Object)(object)_pool == (Object)null)
			{
				if (flag)
				{
					((MelonBase)this).LoggerInstance.Warning($"[warning] waiting for game systems... handler: {(Object)(object)_handler != (Object)null}, pool: {(Object)(object)_pool != (Object)null}");
				}
				return;
			}
			try
			{
				if (!_hasCached && CMTargetGroupHandler._HumanTrackingWeight > 0.01f)
				{
					_origHumanWeight = CMTargetGroupHandler._HumanTrackingWeight;
					_origHumanRadius = CMTargetGroupHandler._HumanTrackingRadius;
					_origAiWeight = CMTargetGroupHandler._AITrackingWeight;
					_origAiRadius = CMTargetGroupHandler._AITrackingRadius;
					_origTrackAi = _handler.TrackAI;
					_origDeadRemovalDelay = _handler.DeadBeastRemovalDelay;
					_origDistanceThreshold = _handler.remoteActorDistanceThreshold;
					_origDistanceMaxThreshold = _handler.remoteActorDistanceMaxThreshold;
					_hasCached = true;
				}
				_handler.DeadBeastRemovalDelay = _deathRemovalDelay;
				_handler.remoteActorDistanceThreshold = _distanceThreshold;
				_handler.remoteActorDistanceMaxThreshold = _distanceMaxThreshold;
				CMTargetGroupHandler._HumanTrackingWeight = _origHumanWeight;
				CMTargetGroupHandler._HumanTrackingRadius = _origHumanRadius;
				CMTargetGroupHandler._AITrackingWeight = _origHumanWeight;
				CMTargetGroupHandler._AITrackingRadius = _origHumanRadius;
				_handler.TrackAI = true;
				Il2CppArrayBase<GangBeastsGroupComposer> val = Object.FindObjectsOfType<GangBeastsGroupComposer>();
				if (val != null)
				{
					foreach (GangBeastsGroupComposer item in val)
					{
						if (!((Object)(object)item == (Object)null))
						{
							if (!_origDampings.ContainsKey(item))
							{
								_origDampings[item] = item.m_FrameDamping;
							}
							if (item.m_FrameDamping != _cameraFrameDamping)
							{
								item.m_FrameDamping = _cameraFrameDamping;
							}
						}
					}
				}
				TargetGroupAndTrackingInfo localPlayerTargetGroup = _pool.GetLocalPlayerTargetGroup();
				TargetGroupAndTrackingInfo allLiving = _pool.AllLiving;
				if (flag)
				{
					Instance loggerInstance = ((MelonBase)this).LoggerInstance;
					CMVcamTargeter activeCamera = _handler.GetActiveCamera();
					loggerInstance.Msg("[debug] active camera: " + (((activeCamera != null) ? ((Object)activeCamera).name : null) ?? "null"));
					Instance loggerInstance2 = ((MelonBase)this).LoggerInstance;
					object obj;
					if (localPlayerTargetGroup == null)
					{
						obj = null;
					}
					else
					{
						CinemachineTargetGroup obj2 = localPlayerTargetGroup.group;
						obj = ((obj2 != null) ? ((Object)obj2).name : null);
					}
					if (obj == null)
					{
						obj = "null";
					}
					object obj3;
					if (allLiving == null)
					{
						obj3 = null;
					}
					else
					{
						CinemachineTargetGroup obj4 = allLiving.group;
						obj3 = ((obj4 != null) ? ((Object)obj4).name : null);
					}
					if (obj3 == null)
					{
						obj3 = "null";
					}
					loggerInstance2.Msg("[debug] target groups -> local: " + (string?)obj + ", living: " + (string?)obj3);
				}
				HashSet<string> hashSet = new HashSet<string>();
				List<CMTrackedObject> trackedObjects = _handler.TrackedObjects;
				if (trackedObjects != null)
				{
					for (int i = 0; i < trackedObjects.Count; i++)
					{
						CMTrackedObject val2 = trackedObjects[i];
						if (val2 == null || (Object)(object)val2.beast == (Object)null)
						{
							continue;
						}
						Actor beast = val2.beast;
						Transform val3 = beast.GetTrackingTransform() ?? ((Component)beast).transform;
						if ((Object)(object)val3 == (Object)null)
						{
							continue;
						}
						bool flag2 = (int)beast.actorState == 1;
						string text = ((Object)val3).GetInstanceID().ToString();
						if (!flag2)
						{
							BodyHandeler bodyHandeler = beast.bodyHandeler;
							if ((Object)(object)bodyHandeler != (Object)null)
							{
								Il2CppReferenceArray<Rigidbody> allRigidbodies = bodyHandeler.GetAllRigidbodies();
								if (allRigidbodies != null)
								{
									for (int j = 0; j < ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies).Length; j++)
									{
										if ((Object)(object)((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies)[j] != (Object)null && ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies)[j].IsSleeping())
										{
											((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies)[j].WakeUp();
										}
									}
								}
							}
						}
						if (beast.IsAI)
						{
							beast.isTrackedByCamera = !flag2;
							if (!flag2)
							{
								SafeAddToTargetGroup(_pool, val3, localPlayerTargetGroup, isHuman: true, 1f, 2f);
								SafeAddToTargetGroup(_pool, val3, allLiving, isHuman: true, 1f, 2f);
							}
							else
							{
								SafeRemoveFromTargetGroup(_pool, val3, localPlayerTargetGroup);
								SafeRemoveFromTargetGroup(_pool, val3, allLiving);
							}
						}
						else
						{
							beast.isTrackedByCamera = !flag2;
							if (!flag2)
							{
								SafeAddToTargetGroup(_pool, val3, localPlayerTargetGroup, isHuman: true, 1f, 2f);
							}
							else
							{
								SafeRemoveFromTargetGroup(_pool, val3, localPlayerTargetGroup);
							}
						}
						if (!flag2)
						{
							hashSet.Add(text);
							_lastKnownPositions[text] = val3.position;
						}
					}
				}
				Vector3 val4 = Vector3.zero;
				int num = 0;
				foreach (string item2 in hashSet)
				{
					if (_lastKnownPositions.ContainsKey(item2))
					{
						val4 += _lastKnownPositions[item2];
						num++;
					}
				}
				if (num > 0)
				{
					val4 /= (float)num;
				}
				foreach (string key2 in _lastKnownPositions.Keys)
				{
					if (!hashSet.Contains(key2) && !_trackingDummies.ContainsKey(key2) && _lastKnownPositions.ContainsKey(key2))
					{
						GameObject val5 = new GameObject("death_dummy_" + key2);
						val5.transform.position = _lastKnownPositions[key2];
						_trackingDummies[key2] = val5;
						_dummyWeights[key2] = 1f;
						_dummyVelocities[key2] = Vector3.zero;
						_dummyLifetimes[key2] = 0f;
						float value = ((num > 0) ? Vector3.Distance(_lastKnownPositions[key2], val4) : 30f);
						_dummyInitialDistances[key2] = value;
						SafeAddToTargetGroup(_pool, val5.transform, localPlayerTargetGroup, isHuman: true, 1f, 2f);
						SafeAddToTargetGroup(_pool, val5.transform, allLiving, isHuman: true, 1f, 2f);
					}
				}
				List<string> list = new List<string>();
				List<string> list2 = new List<string>(_trackingDummies.Keys);
				for (int k = 0; k < list2.Count; k++)
				{
					string text2 = list2[k];
					GameObject val6 = _trackingDummies[text2];
					if ((Object)(object)val6 == (Object)null)
					{
						list.Add(text2);
						continue;
					}
					if (num > 0)
					{
						float num2 = Mathf.Clamp01((_dummyLifetimes[text2] - _springDelay) / _springRampDuration);
						float num3 = _springConstant * num2;
						Vector3 val7 = val6.transform.position - val4;
						Vector3 val8 = (0f - num3) * val7 - _dampingCoefficient * _dummyVelocities[text2];
						Dictionary<string, Vector3> dummyVelocities = _dummyVelocities;
						string key = text2;
						dummyVelocities[key] += val8 * Time.deltaTime;
						Transform transform = val6.transform;
						transform.position += _dummyVelocities[text2] * Time.deltaTime * 1.3f;
					}
					_dummyLifetimes[text2] += Time.deltaTime;
					float num4 = (_dummyInitialDistances.ContainsKey(text2) ? _dummyInitialDistances[text2] : 15f);
					float num5 = 1f;
					if (num4 < 15f)
					{
						num5 = Mathf.Lerp(1.4f, 1f, num4 / 15f);
					}
					_dummyWeights[text2] -= Time.deltaTime / _fadeTimeMultiplier * num5;
					float num6 = Mathf.Max(0f, _dummyWeights[text2]);
					if (num6 > 0.01f)
					{
						float weight = num6 * _initialDummyWeight;
						float radius = Mathf.Lerp(_origHumanRadius, _initialDummyRadius, num6);
						SetTargetPropertiesDirect(localPlayerTargetGroup, val6.transform, weight, radius);
						SetTargetPropertiesDirect(allLiving, val6.transform, weight, radius);
					}
					else
					{
						SafeRemoveFromTargetGroup(_pool, val6.transform, localPlayerTargetGroup);
						SafeRemoveFromTargetGroup(_pool, val6.transform, allLiving);
						Object.Destroy((Object)(object)val6);
						list.Add(text2);
					}
				}
				for (int l = 0; l < list.Count; l++)
				{
					_trackingDummies.Remove(list[l]);
					_dummyWeights.Remove(list[l]);
					_dummyVelocities.Remove(list[l]);
					_dummyLifetimes.Remove(list[l]);
					_dummyInitialDistances.Remove(list[l]);
					_lastKnownPositions.Remove(list[l]);
				}
			}
			catch (Exception)
			{
			}
		}
	}
}