Decompiled source of Chief v1.0.5

ChiefMod.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 HunkMod.Modules;
using HunkMod.Modules.Components;
using HunkMod.Modules.Survivors;
using HunkMod.Modules.Weapons;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RoR2;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.Rendering;

[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("ChiefMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+370d15f3e87f756455252d0c88fb8cbc4548297d")]
[assembly: AssemblyProduct("ChiefMod")]
[assembly: AssemblyTitle("ChiefMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ChiefMod
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.LONK.ChiefMod", "ChiefMod", "1.0.5")]
	public class ChiefPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.LONK.ChiefMod";

		public const string PluginAuthor = "LONK";

		public const string PluginName = "ChiefMod";

		public const string PluginVersion = "1.0.5";

		internal static Harmony Harm;

		public static ChiefPlugin Instance { get; private set; }

		internal static ConfigEntry<bool> UseGlobalSkins { get; private set; }

		public void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			Instance = this;
			Harm = new Harmony("com.LONK.ChiefMod");
			Harm.CreateClassProcessor(typeof(PickupPrefabFix)).Patch();
			UseGlobalSkins = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Use Global Weapon Skins", false, "If disabled, only Hunk's Chief skin will use Halo's weapon reskins");
			Log.Init(((BaseUnityPlugin)this).Logger);
			ChiefSkin.Init();
			WeaponManager.Init();
			ChiefSkin.OnChiefSkinLoaded += AddWeapons;
			ApplySoundReplacements();
		}

		public static void AddWeapons(SkinDef chiefSkin)
		{
			WeaponManager.AddWeapon<SMGBehavior>(((BaseWeapon)BaseWeapon<SMG>.instance).weaponDef, "mdlSMGHalo", chiefSkin);
			WeaponManager.AddWeapon<MUPBehavior>(((BaseWeapon)BaseWeapon<MUP>.instance).weaponDef, "mdlMUPHalo", chiefSkin);
			WeaponManager.AddWeapon<ARBehavior>(((BaseWeapon)BaseWeapon<AssaultRifle>.instance).weaponDef, "mdlAssaultRifleHalo", chiefSkin);
			WeaponManager.AddWeapon(((BaseWeapon)BaseWeapon<Shotgun>.instance).weaponDef, "mdlShotgunHalo", chiefSkin);
		}

		private void ApplySoundReplacements()
		{
		}
	}
	internal static class ChiefSkin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__AddRobHunkBodyChiefSkin;

			public static hook_LoadStrings <1>__Language_LoadStrings;
		}

		internal static string skinName = "Master Chief";

		internal static string skinNameToken = "LONK_SKIN_CHIEF_NAME";

		internal static event Action<SkinDef> OnChiefSkinLoaded;

		public static void Init()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)AddRobHunkBodyChiefSkin);
			object obj = <>O.<1>__Language_LoadStrings;
			if (obj == null)
			{
				hook_LoadStrings val = Language_LoadStrings;
				<>O.<1>__Language_LoadStrings = val;
				obj = (object)val;
			}
			Language.LoadStrings += (hook_LoadStrings)obj;
		}

		private static void Language_LoadStrings(orig_LoadStrings orig, Language self)
		{
			orig.Invoke(self);
			self.SetStringByToken(skinNameToken, skinName);
		}

		public static void AddRobHunkBodyChiefSkin()
		{
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = BodyCatalog.FindBodyPrefab("RobHunkBody");
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.Warning("Failed to add \"" + skinName + "\" skin because \"RobHunkBody\" doesn't exist");
				return;
			}
			ModelLocator component = val.GetComponent<ModelLocator>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				Log.Warning("Failed to add \"" + skinName + "\" skin to \"RobHunkBody\" because it doesn't have \"ModelLocator\" component");
				return;
			}
			GameObject gameObject = ((Component)component.modelTransform).gameObject;
			ModelSkinController val2 = (Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<ModelSkinController>() : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				Log.Warning("Failed to add \"" + skinName + "\" skin to \"RobHunkBody\" because it doesn't have \"ModelSkinController\" component");
				return;
			}
			CharacterModel component2 = gameObject.GetComponent<CharacterModel>();
			if (!Object.op_Implicit((Object)(object)component2))
			{
				Log.Warning("Failed to add \"" + skinName + "\" skin to \"RobHunkBody\" because it doesn't have \"CharacterModel\" component");
				return;
			}
			Renderer[] array = component2.baseRendererInfos.Select((RendererInfo info) => info.renderer).ToArray();
			SkinDef val3 = Skins.CreateSkinDef(skinNameToken, WeaponManager.LoadAsset<Sprite>("Assets/Chief/Skin/Icons/ChiefIcon.png"), (RendererInfo[])(object)new RendererInfo[2]
			{
				new RendererInfo
				{
					defaultMaterial = WeaponManager.LoadAsset<Material>("Assets/Chief/Skin/Materials/Bodu.mat"),
					defaultShadowCastingMode = (ShadowCastingMode)1,
					ignoreOverlays = false,
					renderer = array[0]
				},
				new RendererInfo
				{
					defaultMaterial = WeaponManager.LoadAsset<Material>("Assets/Chief/Skin/Materials/Head.mat"),
					defaultShadowCastingMode = (ShadowCastingMode)1,
					ignoreOverlays = false,
					renderer = array[1]
				}
			}, component2.mainSkinnedMeshRenderer, gameObject);
			val3.meshReplacements = (MeshReplacement[])(object)new MeshReplacement[7]
			{
				new MeshReplacement
				{
					mesh = WeaponManager.LoadAsset<Mesh>("Assets/Chief/Skin/Meshes/body.asset"),
					renderer = array[0]
				},
				new MeshReplacement
				{
					mesh = WeaponManager.LoadAsset<Mesh>("Assets/Chief/Skin/Meshes/head.asset"),
					renderer = array[1]
				},
				new MeshReplacement
				{
					mesh = null,
					renderer = array[2]
				},
				new MeshReplacement
				{
					mesh = null,
					renderer = array[3]
				},
				new MeshReplacement
				{
					mesh = null,
					renderer = array[4]
				},
				new MeshReplacement
				{
					mesh = null,
					renderer = array[5]
				},
				new MeshReplacement
				{
					mesh = null,
					renderer = array[6]
				}
			};
			Array.Resize(ref val2.skins, val2.skins.Length + 1);
			val2.skins[^1] = val3;
			BodyCatalog.skins[BodyCatalog.FindBodyIndex(val)] = val2.skins;
			ChiefSkin.OnChiefSkinLoaded?.Invoke(ChiefPlugin.UseGlobalSkins.Value ? null : val3);
		}
	}
	internal static class Log
	{
		internal 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 ErrorAsset(string assetName)
		{
			Error("failed to load asset, " + assetName + ", because it does not exist in any asset bundle");
		}

		internal static void ErrorAssetBundle(string assetName)
		{
			Error("failed to load asset bundle " + assetName);
		}

		internal static void ErrorTargetMethod(string typeName)
		{
			Error("failed to find target property modelPrefab because it does not exist in the class " + typeName);
		}

		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);
		}
	}
	[HarmonyPatch]
	internal class EscapeSequence
	{
		[HarmonyPatch(typeof(HunkController), "StartBGM")]
		[HarmonyPrefix]
		public static bool MusicReplacement(HunkController __instance)
		{
			__instance.bgmPlayID = Util.PlaySound("Halo_Sound_String", ((Component)__instance).gameObject);
			return false;
		}
	}
	[HarmonyPatch]
	internal class PickupPrefabFix
	{
		public static readonly Dictionary<ushort, (GameObject oldPrefab, GameObject newPrefab)> prefabsByWeaponIndex = new Dictionary<ushort, (GameObject, GameObject)>();

		public static void AddPair(HunkWeaponDef weaponDef, GameObject newPrefab)
		{
			prefabsByWeaponIndex[weaponDef.index] = (weaponDef.itemDef.pickupModelPrefab, newPrefab);
		}

		[HarmonyPatch(typeof(HunkController), "Start")]
		[HarmonyPostfix]
		public static void ReplacePickupModel(HunkController __instance)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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)
			if (Hunk.gunSkins.Count == 0 || !Object.op_Implicit((Object)(object)__instance.modelSkinController) || !Object.op_Implicit((Object)(object)__instance.characterBody) || !__instance.characterBody.isPlayerControlled || !__instance.characterBody.hasEffectiveAuthority)
			{
				return;
			}
			SkinDef val = __instance.modelSkinController.skins[__instance.characterBody.skinIndex];
			foreach (HunkGunSkin gunSkin in Hunk.gunSkins)
			{
				if (prefabsByWeaponIndex.TryGetValue(gunSkin.weaponDef.index, out (GameObject, GameObject) value))
				{
					GameObject obj;
					if (Object.op_Implicit((Object)(object)gunSkin.skinDef) && !((Object)(object)gunSkin.skinDef == (Object)(object)val))
					{
						(obj, _) = value;
					}
					else
					{
						obj = value.Item2;
					}
					GameObject val2 = obj;
					gunSkin.weaponDef.itemDef.pickupModelPrefab = val2;
					PickupCatalog.GetPickupDef(PickupCatalog.FindPickupIndex(gunSkin.weaponDef.itemDef.itemIndex)).displayPrefab = val2;
				}
			}
		}
	}
	internal static class WeaponManager
	{
		internal static readonly Dictionary<string, AssetBundle> loadedBundles = new Dictionary<string, AssetBundle>();

		internal static readonly Dictionary<string, IEnumerable<string>> loadedBundleAssetNames = new Dictionary<string, IEnumerable<string>>();

		internal static event Action OnLoadCompleted;

		internal static void Init()
		{
			IEnumerable<string> enumerable = from p in Directory.EnumerateFiles(Path.GetDirectoryName(((BaseUnityPlugin)ChiefPlugin.Instance).Info.Location), "*", SearchOption.AllDirectories)
				where !Path.HasExtension(p)
				select p;
			int bundleCount = enumerable.Count();
			foreach (string bundleName in enumerable)
			{
				((AsyncOperation)AssetBundle.LoadFromFileAsync(bundleName)).completed += delegate(AsyncOperation o)
				{
					AssetBundle assetBundle = ((AssetBundleCreateRequest)((o is AssetBundleCreateRequest) ? o : null)).assetBundle;
					if ((Object)(object)assetBundle != (Object)null)
					{
						Log.Debug("Loading assetbundle " + ((Object)assetBundle).name + "...");
						loadedBundles[((Object)assetBundle).name] = assetBundle;
						loadedBundleAssetNames[((Object)assetBundle).name] = assetBundle.GetAllAssetNames().AsEnumerable();
						if (loadedBundles.Count == bundleCount)
						{
							WeaponManager.OnLoadCompleted?.Invoke();
						}
					}
					else
					{
						Log.ErrorAssetBundle(bundleName);
					}
				};
			}
		}

		public static void AddWeapon<T>(HunkWeaponDef weaponDef, string prefabReplacementName, SkinDef chiefSkin = null) where T : MonoBehaviour
		{
			if (!prefabReplacementName.StartsWith("Assets/Chief/Weapons/"))
			{
				prefabReplacementName = "Assets/Chief/Weapons/" + prefabReplacementName;
			}
			GameObject val = WeaponManager.LoadAsset<GameObject>(prefabReplacementName + ".prefab");
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.ErrorAsset(prefabReplacementName);
				return;
			}
			val.AddComponent<T>();
			Log.Info("Replacing " + ((Object)weaponDef).name + " with " + prefabReplacementName);
			Hunk.AddGunSkin(chiefSkin, weaponDef, val);
			AddPickupPrefab(weaponDef, prefabReplacementName);
		}

		public static void AddWeapon(HunkWeaponDef weaponDef, string prefabReplacementName, SkinDef chiefSkin = null)
		{
			if (!prefabReplacementName.StartsWith("Assets/Chief/Weapons/"))
			{
				prefabReplacementName = "Assets/Chief/Weapons/" + prefabReplacementName;
			}
			GameObject val = WeaponManager.LoadAsset<GameObject>(prefabReplacementName + ".prefab");
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.ErrorAsset(prefabReplacementName);
				return;
			}
			Log.Info("Replacing " + ((Object)weaponDef).name + " with " + prefabReplacementName);
			Hunk.AddGunSkin(chiefSkin, weaponDef, val);
			AddPickupPrefab(weaponDef, prefabReplacementName);
		}

		private static void AddPickupPrefab(HunkWeaponDef weaponDef, string prefabReplacementName)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = WeaponManager.LoadAsset<GameObject>(prefabReplacementName + "Pickup.prefab");
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.ErrorAsset(prefabReplacementName);
				return;
			}
			ModelPanelParameters val2 = default(ModelPanelParameters);
			if (!val.TryGetComponent<ModelPanelParameters>(ref val2))
			{
				val2 = val.AddComponent<ModelPanelParameters>();
			}
			Transform transform = val.transform;
			if (!Object.op_Implicit((Object)(object)val2.focusPointTransform))
			{
				val2.focusPointTransform = transform.Find("FocusPoint") ?? new GameObject("FocusPoint").transform;
				val2.focusPointTransform.SetParent(transform);
			}
			if (!Object.op_Implicit((Object)(object)val2.cameraPositionTransform))
			{
				val2.cameraPositionTransform = transform.Find("CameraPosition") ?? new GameObject("CameraPosition").transform;
				val2.cameraPositionTransform.SetParent(val.transform);
			}
			PickupPrefabFix.AddPair(weaponDef, val);
		}

		public static T LoadAsset<T>(string path) where T : Object
		{
			foreach (KeyValuePair<string, IEnumerable<string>> loadedBundleAssetName in loadedBundleAssetNames)
			{
				if (loadedBundleAssetName.Value.Contains(path.ToLower()))
				{
					return loadedBundles[loadedBundleAssetName.Key].LoadAsset<T>(path);
				}
			}
			Log.ErrorAsset(path);
			Log.Warning("Current asset paths");
			foreach (string item in loadedBundleAssetNames.SelectMany((KeyValuePair<string, IEnumerable<string>> kvp) => kvp.Value))
			{
				Log.Error(item);
			}
			return default(T);
		}
	}
}
namespace ChiefMod.Modules
{
	internal class PlasmaRifle : BaseWeapon<PlasmaRifle>
	{
		private SkillDef _primarySkillDef;

		private GameObject _crosshairPrefab;

		public override string weaponNameToken => "";

		public override string weaponNameTokenFull => ((BaseWeapon)this).weaponNameTokenFull;

		public override string weaponDescToken => ((BaseWeapon)this).weaponDescToken;

		public override string weaponName => "";

		public override string weaponDesc => "";

		public override string iconName => "";

		public override GameObject crosshairPrefab => _crosshairPrefab;

		public override int magSize => 0;

		public override float magPickupMultiplier => 0f;

		public override int startingMags => 0;

		public override float reloadDuration => 0f;

		public override string ammoName => "";

		public override SkillDef primarySkillDef => _primarySkillDef;

		public override GameObject modelPrefab => WeaponManager.LoadAsset<GameObject>("mdlPlasmaRifle");

		public override AnimationSet animationSet => (AnimationSet)1;

		public override bool storedOnBack => false;

		public override bool storedOnHolster => true;

		public override float damageFillValue => 0f;

		public override float rangefillValue => 0f;

		public override float fireRateFillValue => 0f;

		public override float reloadFillValue => 0f;

		public override float accuracyFillValue => 0f;

		public override string aimSoundString => "";

		public override string equipSoundString => "";

		public override void Init()
		{
			((BaseWeapon)this).Init();
		}
	}
	[HarmonyPatch(typeof(HunkDialogue))]
	internal class Sound_replacement
	{
		[HarmonyPatch("Step1")]
		[HarmonyPrefix]
		public static bool Replacestep1()
		{
			return false;
		}
	}
}