Decompiled source of BigWok v1.0.2

BigWok.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigWok")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BigWok")]
[assembly: AssemblyTitle("BigWok")]
[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 bigwok
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BigWok";

		public const string PLUGIN_NAME = "BigWok";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace BigWok
{
	public enum BodyPartType
	{
		Nose,
		Foot
	}
	[BepInPlugin("deck.bigwalk.bigwok", "BigWok", "1.0.0")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "deck.bigwalk.bigwok";

		public const string Name = "BigWok";

		public const string Version = "1.0.0";

		public static ManualLogSource Log;

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<string> ObjFile;

		public static ConfigEntry<bool> InvertFaces;

		public static ConfigEntry<bool> ReplaceNose;

		public static ConfigEntry<bool> ReplaceFeet;

		public static ConfigEntry<bool> AutoFit;

		public static ConfigEntry<bool> FlipDirection;

		public static ConfigEntry<float> Scale;

		public static ConfigEntry<float> ScaleX;

		public static ConfigEntry<float> ScaleY;

		public static ConfigEntry<float> ScaleZ;

		public static ConfigEntry<float> RotX;

		public static ConfigEntry<float> RotY;

		public static ConfigEntry<float> RotZ;

		public static ConfigEntry<float> FootRotX;

		public static ConfigEntry<float> FootRotY;

		public static ConfigEntry<float> FootOffsetY;

		public static ConfigEntry<float> FootOffsetZ;

		public static ConfigEntry<float> OffsetX;

		public static ConfigEntry<float> OffsetY;

		public static ConfigEntry<float> OffsetZ;

		public static ConfigEntry<bool> DumpHierarchy;

		public override void Load()
		{
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master toggle to enable or disable BIG WOK.");
			ObjFile = ((BasePlugin)this).Config.Bind<string>("General", "ObjFile", "wok.obj", "Wavefront .obj file to load for the replacement mesh.");
			InvertFaces = ((BasePlugin)this).Config.Bind<bool>("General", "InvertFaces", false, "Invert triangle face winding if model renders inside-out.");
			ReplaceNose = ((BasePlugin)this).Config.Bind<bool>("Body Parts", "ReplaceNose", true, "Replace the character's nose with a wok.");
			ReplaceFeet = ((BasePlugin)this).Config.Bind<bool>("Body Parts", "ReplaceFeet", true, "Replace the character's feet with woks.");
			AutoFit = ((BasePlugin)this).Config.Bind<bool>("Transform", "AutoFit", true, "Automatically scale the wok to fit target mesh bounds.");
			FlipDirection = ((BasePlugin)this).Config.Bind<bool>("Transform", "FlipDirection", true, "Flip model orientation end-for-end.");
			Scale = ((BasePlugin)this).Config.Bind<float>("Transform", "Scale", 1f, "Global scale multiplier.");
			ScaleX = ((BasePlugin)this).Config.Bind<float>("Transform", "ScaleX", 1f, "Scale factor along X axis.");
			ScaleY = ((BasePlugin)this).Config.Bind<float>("Transform", "ScaleY", 1f, "Scale factor along Y axis.");
			ScaleZ = ((BasePlugin)this).Config.Bind<float>("Transform", "ScaleZ", 1f, "Scale factor along Z axis.");
			RotX = ((BasePlugin)this).Config.Bind<float>("Transform", "RotationX", 0f, "Rotation offset around X axis in degrees.");
			RotY = ((BasePlugin)this).Config.Bind<float>("Transform", "RotationY", 0f, "Rotation offset around Y axis in degrees.");
			RotZ = ((BasePlugin)this).Config.Bind<float>("Transform", "RotationZ", -90f, "Rotation offset around Z axis in degrees.");
			FootRotX = ((BasePlugin)this).Config.Bind<float>("Transform", "FootRotationX", -20f, "X-axis tilt correction to keep feet flat when knees bend.");
			FootRotY = ((BasePlugin)this).Config.Bind<float>("Transform", "FootRotationY", 90f, "Extra Y-axis rotation offset applied specifically to feet to face forward.");
			FootOffsetY = ((BasePlugin)this).Config.Bind<float>("Transform", "FootOffsetY", 0.18f, "Vertical position nudge to lift woks clear of the ground.");
			FootOffsetZ = ((BasePlugin)this).Config.Bind<float>("Transform", "FootOffsetZ", 0.02f, "Forward/backward position nudge for feet.");
			OffsetX = ((BasePlugin)this).Config.Bind<float>("Transform", "OffsetX", 0f, "Local position offset nudge along X.");
			OffsetY = ((BasePlugin)this).Config.Bind<float>("Transform", "OffsetY", 0f, "Local position offset nudge along Y.");
			OffsetZ = ((BasePlugin)this).Config.Bind<float>("Transform", "OffsetZ", 0f, "Local position offset nudge along Z.");
			DumpHierarchy = ((BasePlugin)this).Config.Bind<bool>("Debug", "DumpHierarchy", false, "Dump full transform hierarchy tree into BepInEx logs.");
			Harmony.CreateAndPatchAll(typeof(WokPatches), "deck.bigwalk.bigwok");
			ClassInjector.RegisterTypeInIl2Cpp<WokRuntime>();
			GameObject val = new GameObject("BigWokRuntime")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)(object)val);
			val.AddComponent<WokRuntime>();
			Log.LogInfo((object)"BIG WOK plugin initialized successfully.");
		}
	}
	[HarmonyPatch]
	internal static class WokPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerLips), "Initialize")]
		private static void OnLipsInitialized(PlayerLips __instance)
		{
			if (!Plugin.Enabled.Value || __instance == null)
			{
				return;
			}
			Component val = ((Il2CppObjectBase)__instance).Cast<Component>();
			if ((Object)(object)val != (Object)null && (Object)(object)val.gameObject != (Object)null)
			{
				PlayerCharacter componentInParent = val.gameObject.GetComponentInParent<PlayerCharacter>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					WokRuntime.Queue(componentInParent);
				}
			}
		}
	}
	public class WokRuntime : MonoBehaviour
	{
		private static readonly List<PlayerCharacter> Pending = new List<PlayerCharacter>();

		private bool _loaded;

		private float _nextSweep;

		public WokRuntime(IntPtr ptr)
			: base(ptr)
		{
		}

		public static void Queue(PlayerCharacter character)
		{
			lock (Pending)
			{
				Pending.Add(character);
			}
		}

		private void Update()
		{
			if (!_loaded)
			{
				_loaded = true;
				WokSwapper.LoadModel();
			}
			if (Pending.Count > 0)
			{
				PlayerCharacter[] array;
				lock (Pending)
				{
					array = Pending.ToArray();
					Pending.Clear();
				}
				PlayerCharacter[] array2 = array;
				foreach (PlayerCharacter val in array2)
				{
					if ((Object)(object)val != (Object)null)
					{
						WokSwapper.ApplyCharacter(val);
					}
				}
			}
			if (Time.unscaledTime >= _nextSweep)
			{
				_nextSweep = Time.unscaledTime + 3f;
				SweepNow();
			}
		}

		private static void SweepNow()
		{
			if (!Plugin.Enabled.Value)
			{
				return;
			}
			try
			{
				List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
				if (allPlayerCharacters == null)
				{
					return;
				}
				for (int i = 0; i < allPlayerCharacters.Count; i++)
				{
					PlayerCharacter val = allPlayerCharacters[i];
					if ((Object)(object)val != (Object)null)
					{
						WokSwapper.ApplyCharacter(val);
					}
				}
			}
			catch
			{
			}
		}
	}
	internal static class WokSwapper
	{
		private static Mesh _source;

		private static readonly Dictionary<int, Mesh> Originals = new Dictionary<int, Mesh>();

		private static readonly Dictionary<int, Mesh> Fitted = new Dictionary<int, Mesh>();

		public static bool LoadModel()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			string text = ResolveModelPath(Plugin.ObjFile.Value);
			bool flag = default(bool);
			if (text == null)
			{
				ManualLogSource log = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(43, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Model '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Plugin.ObjFile.Value);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' not found next to plugin or under ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Paths.PluginPath);
				}
				log.LogError(val);
				return false;
			}
			string error;
			Mesh val2 = ObjMesh.Load(text, Plugin.InvertFaces.Value, out error);
			if ((Object)(object)val2 == (Object)null)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to read ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Path.GetFileName(text));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(error);
				}
				log2.LogError(val);
				return false;
			}
			((Object)val2).hideFlags = (HideFlags)61;
			_source = val2;
			Fitted.Clear();
			ManualLogSource log3 = Plugin.Log;
			BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(20, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Successfully loaded ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(Path.GetFileName(text));
			}
			log3.LogInfo(val3);
			return true;
		}

		private static string ResolveModelPath(string file)
		{
			if (string.IsNullOrEmpty(file))
			{
				return null;
			}
			if (Path.IsPathRooted(file) && File.Exists(file))
			{
				return file;
			}
			string directoryName = Path.GetDirectoryName(typeof(WokSwapper).Assembly.Location);
			if (!string.IsNullOrEmpty(directoryName))
			{
				string text = Path.Combine(directoryName, file);
				if (File.Exists(text))
				{
					return text;
				}
			}
			try
			{
				if (!string.IsNullOrEmpty(Paths.PluginPath) && Directory.Exists(Paths.PluginPath))
				{
					string[] files = Directory.GetFiles(Paths.PluginPath, Path.GetFileName(file), SearchOption.AllDirectories);
					if (files.Length != 0)
					{
						return files[0];
					}
				}
			}
			catch
			{
			}
			return null;
		}

		public static void ApplyCharacter(PlayerCharacter character)
		{
			if (!((Object)(object)character == (Object)null) && !((Object)(object)_source == (Object)null))
			{
				if (Plugin.ReplaceNose.Value)
				{
					ApplyPart(character, BodyPartType.Nose);
				}
				if (Plugin.ReplaceFeet.Value)
				{
					ApplyPart(character, BodyPartType.Foot);
				}
			}
		}

		private static void ApplyPart(PlayerCharacter character, BodyPartType part)
		{
			List<Renderer> list = FindRenderersForPart(character, part);
			foreach (Renderer item in list)
			{
				if (!((Object)(object)item == (Object)null))
				{
					int instanceID = ((Object)item).GetInstanceID();
					Mesh mesh = GetMesh(item);
					if ((Object)(object)mesh != (Object)null && !Originals.ContainsKey(instanceID))
					{
						Originals[instanceID] = mesh;
					}
					Mesh val = (Originals.ContainsKey(instanceID) ? Originals[instanceID] : mesh);
					if ((Object)(object)val != (Object)null)
					{
						SetMesh(item, BuildFitted(val, item, part), part);
					}
				}
			}
		}

		private static List<Renderer> FindRenderersForPart(PlayerCharacter character, BodyPartType part)
		{
			List<Renderer> list = new List<Renderer>();
			if (part == BodyPartType.Nose && character.lips != null)
			{
				try
				{
					Transform lipTransform = character.lips.lipTransform;
					if ((Object)(object)lipTransform != (Object)null)
					{
						Renderer[] array = Il2CppArrayBase<Renderer>.op_Implicit(((Component)lipTransform).GetComponentsInChildren<Renderer>(true));
						Renderer[] array2 = array;
						foreach (Renderer val in array2)
						{
							if ((Object)(object)val != (Object)null)
							{
								list.Add(val);
							}
						}
					}
				}
				catch
				{
				}
				if (list.Count > 0)
				{
					return list;
				}
			}
			Renderer[] array3 = Il2CppArrayBase<Renderer>.op_Implicit(((Component)character).GetComponentsInChildren<Renderer>(true));
			Renderer[] array4 = array3;
			foreach (Renderer val2 in array4)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					string text = ((Object)((Component)val2).gameObject).name.ToLower();
					if (part == BodyPartType.Foot && (text.Contains("foot") || text.Contains("ankle") || text.Contains("toe")))
					{
						list.Add(val2);
					}
				}
			}
			return list;
		}

		private static Mesh GetMesh(Renderer r)
		{
			SkinnedMeshRenderer val = ((Il2CppObjectBase)r).TryCast<SkinnedMeshRenderer>();
			if ((Object)(object)val != (Object)null)
			{
				return val.sharedMesh;
			}
			MeshFilter component = ((Component)r).GetComponent<MeshFilter>();
			return ((Object)(object)component != (Object)null) ? component.sharedMesh : null;
		}

		private static void SetMesh(Renderer r, Mesh mesh, BodyPartType part)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mesh == (Object)null)
			{
				return;
			}
			SkinnedMeshRenderer val = ((Il2CppObjectBase)r).TryCast<SkinnedMeshRenderer>();
			if ((Object)(object)val != (Object)null)
			{
				((Renderer)val).enabled = false;
				Transform transform = ((Component)val).transform;
				Transform val2 = transform.Find("WokFootInstance");
				if ((Object)(object)val2 == (Object)null)
				{
					GameObject val3 = new GameObject("WokFootInstance");
					val3.transform.SetParent(transform, false);
					val2 = val3.transform;
				}
				if (part == BodyPartType.Foot)
				{
					val2.localPosition = new Vector3(0f, Plugin.FootOffsetY.Value + 0.35f, Plugin.FootOffsetZ.Value - 0.1f);
					val2.localRotation = Quaternion.Euler(90f + Plugin.FootRotX.Value, 0f + Plugin.FootRotY.Value, 0f);
					val2.localRotation = Quaternion.Euler(45f + Plugin.FootRotX.Value, Plugin.FootRotY.Value, 0f);
				}
				MeshFilter val4 = ((Component)val2).gameObject.GetComponent<MeshFilter>() ?? ((Component)val2).gameObject.AddComponent<MeshFilter>();
				MeshRenderer val5 = ((Component)val2).gameObject.GetComponent<MeshRenderer>() ?? ((Component)val2).gameObject.AddComponent<MeshRenderer>();
				val4.sharedMesh = mesh;
				((Renderer)val5).sharedMaterials = ((Renderer)val).sharedMaterials;
			}
			else
			{
				MeshFilter component = ((Component)r).GetComponent<MeshFilter>();
				if ((Object)(object)component != (Object)null)
				{
					component.sharedMesh = mesh;
				}
			}
		}

		private static Mesh BuildFitted(Mesh original, Renderer renderer, BodyPartType part)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)original).GetInstanceID();
			if (Fitted.TryGetValue(instanceID, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Vector3 val = Vector3.zero;
			Quaternion identity = Quaternion.identity;
			float num = 1f;
			if (Plugin.AutoFit.Value)
			{
				Bounds bounds = original.bounds;
				float num2 = Mathf.Max(new float[3]
				{
					((Bounds)(ref bounds)).size.x,
					((Bounds)(ref bounds)).size.y,
					((Bounds)(ref bounds)).size.z
				});
				Bounds bounds2 = _source.bounds;
				float num3 = Mathf.Max(new float[3]
				{
					((Bounds)(ref bounds2)).size.x,
					((Bounds)(ref bounds2)).size.y,
					((Bounds)(ref bounds2)).size.z
				});
				num = num2 / Mathf.Max(num3, 0.0001f);
				val = ((Bounds)(ref bounds)).center;
			}
			Vector3 val2 = new Vector3(Plugin.ScaleX.Value, Plugin.ScaleY.Value, Plugin.ScaleZ.Value) * (Plugin.Scale.Value * num);
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(Plugin.RotX.Value, Plugin.RotY.Value, Plugin.RotZ.Value);
			Quaternion val4 = identity * Quaternion.Euler(val3);
			Vector3 val5 = val + new Vector3(Plugin.OffsetX.Value, Plugin.OffsetY.Value, Plugin.OffsetZ.Value);
			Bounds bounds3 = _source.bounds;
			Matrix4x4 val6 = Matrix4x4.Translate(new Vector3(0f - ((Bounds)(ref bounds3)).center.x, 0f - ((Bounds)(ref bounds3)).center.y, 0f - ((Bounds)(ref bounds3)).min.z));
			Matrix4x4 val7 = Matrix4x4.TRS(val5, val4, val2) * val6;
			Mesh val8 = new Mesh
			{
				name = ((Object)_source).name + "_fitted",
				hideFlags = (HideFlags)61
			};
			Il2CppStructArray<Vector3> vertices = _source.vertices;
			Il2CppStructArray<Vector3> val9 = new Il2CppStructArray<Vector3>((long)((Il2CppArrayBase<Vector3>)(object)vertices).Length);
			for (int i = 0; i < ((Il2CppArrayBase<Vector3>)(object)vertices).Length; i++)
			{
				((Il2CppArrayBase<Vector3>)(object)val9)[i] = ((Matrix4x4)(ref val7)).MultiplyPoint3x4(((Il2CppArrayBase<Vector3>)(object)vertices)[i]);
			}
			val8.vertices = val9;
			if (_source.uv != null && ((Il2CppArrayBase<Vector2>)(object)_source.uv).Length == ((Il2CppArrayBase<Vector3>)(object)vertices).Length)
			{
				val8.uv = _source.uv;
			}
			val8.triangles = _source.triangles;
			val8.RecalculateNormals();
			val8.RecalculateTangents();
			val8.RecalculateBounds();
			Fitted[instanceID] = val8;
			return val8;
		}
	}
	internal static class ObjMesh
	{
		private static readonly char[] Sep = new char[2] { ' ', '\t' };

		public static Mesh Load(string path, bool invert, out string error)
		{
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Expected O, but got Unknown
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			error = null;
			try
			{
				List<Vector3> list = new List<Vector3>();
				List<Vector2> list2 = new List<Vector2>();
				Dictionary<string, int> remap = new Dictionary<string, int>();
				List<Vector3> list3 = new List<Vector3>();
				List<Vector2> list4 = new List<Vector2>();
				List<int> list5 = new List<int>();
				string[] array = File.ReadAllLines(path);
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					if (text.Length == 0 || text[0] == '#')
					{
						continue;
					}
					string[] array2 = text.Split(Sep, StringSplitOptions.RemoveEmptyEntries);
					if (array2.Length == 0)
					{
						continue;
					}
					switch (array2[0])
					{
					case "v":
						if (array2.Length >= 4)
						{
							list.Add(new Vector3(0f - F(array2[1]), F(array2[2]), F(array2[3])));
						}
						break;
					case "vt":
						if (array2.Length >= 3)
						{
							list2.Add(new Vector2(F(array2[1]), F(array2[2])));
						}
						break;
					case "f":
					{
						if (array2.Length < 4)
						{
							break;
						}
						int[] array3 = new int[array2.Length - 1];
						for (int j = 1; j < array2.Length; j++)
						{
							array3[j - 1] = Corner(array2[j], list, list2, remap, list3, list4);
						}
						for (int k = 1; k < array3.Length - 1; k++)
						{
							list5.Add(array3[0]);
							if (invert)
							{
								list5.Add(array3[k]);
								list5.Add(array3[k + 1]);
							}
							else
							{
								list5.Add(array3[k + 1]);
								list5.Add(array3[k]);
							}
						}
						break;
					}
					}
				}
				if (list3.Count == 0 || list5.Count == 0)
				{
					error = "no geometry found in " + Path.GetFileName(path);
					return null;
				}
				Mesh val = new Mesh
				{
					name = "BigWok_" + Path.GetFileNameWithoutExtension(path)
				};
				Il2CppStructArray<Vector3> val2 = new Il2CppStructArray<Vector3>((long)list3.Count);
				for (int l = 0; l < list3.Count; l++)
				{
					((Il2CppArrayBase<Vector3>)(object)val2)[l] = list3[l];
				}
				val.vertices = val2;
				if (list4.Count == list3.Count)
				{
					Il2CppStructArray<Vector2> val3 = new Il2CppStructArray<Vector2>((long)list4.Count);
					for (int m = 0; m < list4.Count; m++)
					{
						((Il2CppArrayBase<Vector2>)(object)val3)[m] = list4[m];
					}
					val.uv = val3;
				}
				Il2CppStructArray<int> val4 = new Il2CppStructArray<int>((long)list5.Count);
				for (int n = 0; n < list5.Count; n++)
				{
					((Il2CppArrayBase<int>)(object)val4)[n] = list5[n];
				}
				val.triangles = val4;
				val.RecalculateNormals();
				val.RecalculateTangents();
				val.RecalculateBounds();
				return val;
			}
			catch (Exception ex)
			{
				error = ex.Message;
				return null;
			}
		}

		private static int Corner(string token, List<Vector3> positions, List<Vector2> texcoords, Dictionary<string, int> remap, List<Vector3> verts, List<Vector2> uvs)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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)
			if (remap.TryGetValue(token, out var value))
			{
				return value;
			}
			string[] array = token.Split('/');
			int num = Index(array[0], positions.Count);
			int num2 = ((array.Length > 1 && array[1].Length > 0) ? Index(array[1], texcoords.Count) : (-1));
			verts.Add((num >= 0) ? positions[num] : Vector3.zero);
			uvs.Add((num2 >= 0) ? texcoords[num2] : Vector2.zero);
			return remap[token] = verts.Count - 1;
		}

		private static int Index(string s, int count)
		{
			if (!int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return -1;
			}
			if (result > 0)
			{
				return result - 1;
			}
			if (result < 0)
			{
				return count + result;
			}
			return -1;
		}

		private static float F(string s)
		{
			if (!float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
			{
				return 0f;
			}
			return result;
		}
	}
}