Decompiled source of ThloatereGearMod v1.0.2

GearPartCustomization/GearPartCustomization.dll

Decompiled a week 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 BepInEx;
using BepInEx.IL2CPP;
using BepInEx.Logging;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppSystem;
using MTFO.Managers;
using Newtonsoft.Json;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("GearPartCustomization")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GearPartCustomization")]
[assembly: AssemblyTitle("GearPartCustomization")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GearPartCustomization;

[BepInPlugin("com.Mccad.GearPartCustomization", "Mccad.GearPartCustomization", "1.0.0")]
public class BasePlugin : BasePlugin
{
	public override void Load()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0021: Expected O, but got Unknown
		Harmony val = new Harmony("com.Mccad.GearPartCustomization");
		Patch_GearPartHolder.Inject(val, ((BasePlugin)this).Log);
		Patch_GameDataInit.Inject(val, ((BasePlugin)this).Log);
	}
}
public class GearPartTransformDatablock
{
	public uint OfflineID { get; set; }

	public string Name { get; set; }

	[JsonIgnore]
	public string PlayfabInstanceID => "OfflineGear_ID_" + OfflineID;

	public List<PartsConfig> Parts { get; set; }

	public bool InternalEnabled { get; set; }
}
public class PartsConfig
{
	public string PartHolderObject { get; set; }

	public eGearComponent PartType { get; set; }

	public bool ParentVisible { get; set; }

	public bool Enabled { get; set; }

	public PartTransformConfig PartTransform { get; set; }

	public List<ChildrenConfig> Children { get; set; }
}
public struct PartTransformConfig
{
	public Vector3Wrapper LocalPosition { get; set; }

	public Vector3Wrapper Scale { get; set; }

	public Vector3Wrapper Rotation { get; set; }
}
public struct ChildrenConfig
{
	public string ChildName { get; set; }

	public bool Enabled { get; set; }

	public PartTransformConfig PartTransform { get; set; }
}
public struct Vector3Wrapper
{
	public float X { get; set; }

	public float Y { get; set; }

	public float Z { get; set; }

	public Vector3Wrapper(float x, float y, float z)
	{
		X = x;
		Y = y;
		Z = z;
	}

	public static implicit operator Vector3(Vector3Wrapper wrapper)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(wrapper.X, wrapper.Y, wrapper.Z);
	}
}
internal class GearPartTransformManager
{
	public static List<GearPartTransformDatablock> Config { get; set; }

	public static bool Deserialize()
	{
		Debug.Log(Object.op_Implicit("GearPartCustomization by mccad: Deserializing the datablock"));
		string text = Path.Combine(ConfigManager.CustomPath, "GearPartTransform.json");
		if (!File.Exists(text))
		{
			Debug.LogWarning(Object.op_Implicit("GearPartTransform.json not found, generating"));
			Serialize(text);
		}
		Config = JsonConvert.DeserializeObject<List<GearPartTransformDatablock>>(File.ReadAllText(text));
		return true;
	}

	public static void CustomizationSetup(GearPartHolder offlineGear)
	{
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: 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_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		if (Config == null)
		{
			Debug.LogError(Object.op_Implicit("GearPartCustomization: Deserialzed contents null!"));
			return;
		}
		foreach (GearPartTransformDatablock item in Config)
		{
			if (offlineGear.GearIDRange.PlayfabItemInstanceId != item.PlayfabInstanceID)
			{
				continue;
			}
			if (!item.InternalEnabled)
			{
				Debug.LogWarning(Object.op_Implicit("GearPartCustomization: " + item.Name + " disabled; skipping"));
				continue;
			}
			Debug.Log(Object.op_Implicit($"GearPartCustomization: Applying customization {item.Name} to offline gear ID {item.OfflineID}"));
			foreach (PartsConfig part2 in item.Parts)
			{
				if (part2.PartHolderObject == null)
				{
					if ((int)part2.PartType == 0)
					{
						Debug.LogError(Object.op_Implicit("GearPartCustomization: Empty part on " + item.Name));
						continue;
					}
					eGearComponent partType = part2.PartType;
					part2.PartHolderObject = ((object)(eGearComponent)(ref partType)).ToString();
				}
				Debug.Log(Object.op_Implicit("GearPartCustomization: Attempting to modify part object " + part2.PartHolderObject));
				if (TryGetPart(part2.PartHolderObject, offlineGear, out var part))
				{
					part.SetActive(part2.Enabled);
					part.transform.localPosition = part2.PartTransform.LocalPosition;
					part.transform.localScale = part2.PartTransform.Scale;
					part.transform.localEulerAngles = part2.PartTransform.Rotation;
				}
				foreach (ChildrenConfig child in part2.Children)
				{
					Debug.Log(Object.op_Implicit("GearPartCustomization: Attempting to modify child object " + child.ChildName));
					Transform val = part.transform.FindChild(child.ChildName);
					if ((Object)(object)val == (Object)null)
					{
						Debug.LogError(Object.op_Implicit("GearPartCustomization: child object " + child.ChildName + " is null"));
						continue;
					}
					((Component)val).gameObject.SetActive(child.Enabled);
					val.localPosition = child.PartTransform.LocalPosition;
					val.localScale = child.PartTransform.Scale;
					val.localEulerAngles = child.PartTransform.Rotation;
					Debug.Log(Object.op_Implicit("GearPartCustomization: Modify child object " + child.ChildName + " complete"));
				}
				Debug.Log(Object.op_Implicit("GearPartCustomization: Modify part object " + part2.PartHolderObject + " complete"));
			}
			Debug.Log(Object.op_Implicit("GearPartCustomization: Modify weapon parts " + item.Name + " complete"));
		}
	}

	public static bool TryGetPart(string partHolderObject, GearPartHolder offlineGear, out GameObject part)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Expected O, but got Unknown
		PropertyInfo property = ((object)offlineGear).GetType().GetProperty(partHolderObject);
		if (property == null)
		{
			part = null;
			return false;
		}
		part = (GameObject)property.GetValue(offlineGear);
		return (Object)(object)part != (Object)null;
	}

	public static void Serialize(string filepath)
	{
		string text = "[\r\n{\r\n    \"OfflineID\": 0,\r\n    \"Name\": \"Gear customization example\",\r\n    \"Parts\": [\r\n        {\r\n            \"PartHolderObject\": \"FrontPart\",\r\n            \"PartType\": 12,\r\n            \"ParentVisible\": true,\r\n            \"Enabled\": true,\r\n            \"PartTransform\": {\r\n                \"LocalPosition\": {\r\n                    \"X\": 0.0,\r\n                    \"Y\": 0.0,\r\n                    \"Z\": 0.0\r\n                },\r\n                \"Scale\": {\r\n                    \"X\": 1.0,\r\n                    \"Y\": 1.0,\r\n                    \"Z\": 1.0\r\n                },\r\n                \"Rotation\": {\r\n                    \"X\": 0.0,\r\n                    \"Y\": 0.0,\r\n                    \"Z\": 0.0\r\n                }\r\n            },\r\n            \"Children\": [\r\n                {\r\n                    \"ChildName\": \"Example\",\r\n                    \"Enabled\": false,\r\n                    \"PartTransform\": {\r\n                        \"LocalPosition\": {\r\n                            \"X\": 0.0,\r\n                            \"Y\": 0.0,\r\n                            \"Z\": 0.0\r\n                        },\r\n                        \"Scale\": {\r\n                            \"X\": 1.0,\r\n                            \"Y\": 1.0,\r\n                            \"Z\": 1.0\r\n                        },\r\n                        \"Rotation\": {\r\n                            \"X\": 0.0,\r\n                            \"Y\": 0.0,\r\n                            \"Z\": 0.0\r\n                        }\r\n                    }\r\n                }\r\n            ]\r\n        }\r\n    ],\r\n    \"InternalEnabled\": false\r\n}\r\n]";
		File.WriteAllText(filepath, text);
		Config = JsonConvert.DeserializeObject<List<GearPartTransformDatablock>>(text);
	}
}
internal class Patch_GameDataInit
{
	public static void Inject(Harmony instance, ManualLogSource log)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		Type typeFromHandle = typeof(GameDataInit);
		Type typeFromHandle2 = typeof(Patch_GameDataInit);
		instance.Patch((MethodBase)typeFromHandle.GetMethod("Initialize"), (HarmonyMethod)null, new HarmonyMethod(typeFromHandle2, "Initialize", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	public static void Initialize()
	{
		GearPartTransformManager.Deserialize();
	}
}
internal class Patch_GearPartHolder
{
	public static void Inject(Harmony instance, ManualLogSource log)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		Type typeFromHandle = typeof(GearPartHolder);
		Type typeFromHandle2 = typeof(Patch_GearPartHolder);
		instance.Patch((MethodBase)typeFromHandle.GetMethod("OnAllPartsSpawned"), (HarmonyMethod)null, new HarmonyMethod(typeFromHandle2, "OnAllPartsSpawned", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	public static void OnAllPartsSpawned(GearPartHolder __instance)
	{
		GearPartTransformManager.CustomizationSetup(__instance);
	}
}