Decompiled source of Mega Magnus Blaster v1.0.0

Mega_Magnus_Blaster.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OtherLoader;
using UnityEditor;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace CustomScripts
{
	[HelpURL("https://h3vr-modding.github.io/wiki/docs/h3vr/FistVR.CartridgeBox.html")]
	public class FTR_AmmoBox : FVRFireArmMagazine
	{
		public enum CartridgeBoxState
		{
			Closed,
			Open
		}

		[Header("Cartridge Box Stuff")]
		public FTR_AmmoBoxOpenControl Control;

		public int RoundsX = 5;

		public BoxCollider GrabCollider;

		public List<BoxCollider> Colliders;

		public List<Transform> BoxPieces;

		public Transform InnerPiece;

		public Transform EjectPos;

		public BoxCollider GrabTrigger;

		public BoxCollider ReloadTriggerCol;

		public CartridgeBoxState BoxState;

		[Header("Audio")]
		public AudioEvent RoundsFallout_Many;

		public AudioEvent RoundsFallout_Few;

		public AudioEvent AudEvent_ShakeHard;

		public AudioEvent AudEvent_ShakeLight;

		[NonSerialized]
		public float timeSinceShakeSound = 1f;

		[NonSerialized]
		public Vector3 lastVel = Vector3.zero;

		[NonSerialized]
		public float height;

		[NonSerialized]
		public float width;

		[NonSerialized]
		public float timeSinceDumpSound = 0.1f;

		[NonSerialized]
		public int m_capacityCache;

		public override void FVRFixedUpdate()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			((FVRFireArmMagazine)this).FVRFixedUpdate();
			Vector3 velocity = ((FVRPhysicalObject)this).RootRigidbody.velocity;
			if ((Object)(object)((FVRPhysicalObject)this).QuickbeltSlot == (Object)null)
			{
				float magnitude = ((Vector3)(ref velocity)).magnitude;
				float magnitude2 = ((Vector3)(ref lastVel)).magnitude;
				if (base.m_numRounds > RoundsX && timeSinceShakeSound > 0.2f)
				{
					if (Mathf.Abs(magnitude - magnitude2) > 1f)
					{
						SM.PlayCoreSound((FVRPooledAudioType)10, AudEvent_ShakeHard, ((Component)this).transform.position);
						timeSinceShakeSound = 0f;
					}
					if (Mathf.Abs(magnitude - magnitude2) > 0.25f)
					{
						SM.PlayCoreSound((FVRPooledAudioType)10, AudEvent_ShakeLight, ((Component)this).transform.position);
						timeSinceShakeSound = 0f;
					}
				}
			}
			lastVel = velocity;
			if (timeSinceShakeSound < 1f)
			{
				timeSinceShakeSound += Time.deltaTime;
			}
		}

		public override void Start()
		{
			((FVRInteractiveObject)this).Start();
			base.HideAllProxies = true;
			((Collider)ReloadTriggerCol).enabled = false;
		}

		public void DumpAll()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (base.m_numRounds >= 1 && base.m_numRounds > 0 && timeSinceDumpSound > 0.15f)
			{
				if (base.m_numRounds > RoundsX)
				{
					timeSinceDumpSound = 0f;
					SM.PlayCoreSound((FVRPooledAudioType)10, RoundsFallout_Many, ((Component)this).transform.position);
				}
				else
				{
					timeSinceDumpSound = 0f;
					SM.PlayCoreSound((FVRPooledAudioType)10, RoundsFallout_Few, ((Component)this).transform.position);
				}
			}
		}

		public override void FVRUpdate()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			((FVRFireArmMagazine)this).FVRUpdate();
			if (timeSinceDumpSound < 1f)
			{
				timeSinceDumpSound += Time.deltaTime;
			}
			float num = Vector3.Angle(((Component)this).transform.up, -Vector3.up);
			if (num < 30f)
			{
				DumpAll();
			}
			if (m_capacityCache != base.m_numRounds)
			{
				m_capacityCache = base.m_numRounds;
			}
		}

		public void SetBoxState(CartridgeBoxState cbs)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if (BoxState == cbs)
			{
				return;
			}
			if ((int)cbs != 0)
			{
				if ((int)cbs == 1)
				{
					base.HideAllProxies = false;
					((FVRFireArmMagazine)this).UpdateBulletDisplay();
					((Collider)ReloadTriggerCol).enabled = true;
				}
			}
			else
			{
				base.HideAllProxies = true;
				((FVRFireArmMagazine)this).UpdateBulletDisplay();
				((Collider)ReloadTriggerCol).enabled = false;
			}
			BoxState = cbs;
		}
	}
	[HelpURL("https://h3vr-modding.github.io/wiki/docs/h3vr/FistVR.CartridgeBox_GrabTrigger.html")]
	public class FTR_AmmoBoxGrabTrigger : FVRInteractiveObject
	{
		public FTR_AmmoBox Mag;

		public override bool IsInteractable()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			return ((FVRFireArmMagazine)Mag).HasARound() && (int)Mag.BoxState != 0 && ((FVRInteractiveObject)this).IsInteractable();
		}

		public override void SimpleInteraction(FVRViveHand hand)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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)
			if (((FVRFireArmMagazine)Mag).HasARound())
			{
				GameObject val = ((FVRFireArmMagazine)Mag).RemoveRound(false);
				Vector3 position = ((FVRFireArmMagazine)Mag).DisplayBullets[Mathf.Clamp(((FVRFireArmMagazine)Mag).m_numRounds - 1, 0, ((FVRFireArmMagazine)Mag).DisplayBullets.Length - 1)].transform.position;
				Quaternion rotation = ((FVRFireArmMagazine)Mag).DisplayBullets[Mathf.Clamp(((FVRFireArmMagazine)Mag).m_numRounds - 1, 0, ((FVRFireArmMagazine)Mag).DisplayBullets.Length - 1)].transform.rotation;
				GameObject val2 = Object.Instantiate<GameObject>(val, ((FVRFireArmMagazine)Mag).DisplayBullets[((FVRFireArmMagazine)Mag).m_numRounds].transform.position, ((FVRFireArmMagazine)Mag).DisplayBullets[((FVRFireArmMagazine)Mag).m_numRounds].transform.rotation);
				FVRFireArmRound component = val2.GetComponent<FVRFireArmRound>();
				((Component)component).GetComponent<FVRFireArmRound>().BeginAnimationFrom(position, rotation);
				hand.ForceSetInteractable((FVRInteractiveObject)(object)component);
				((FVRInteractiveObject)component).BeginInteraction(hand);
			}
		}
	}
	[HelpURL("https://h3vr-modding.github.io/wiki/docs/h3vr/FistVR.CartridgeBoxOpeningControl.html")]
	public class FTR_AmmoBoxOpenControl : FVRInteractiveObject
	{
		public FTR_AmmoBox Box;

		public AudioEvent AudEvent_Grab;

		public AudioEvent AudEvent_End;

		public override bool IsInteractable()
		{
			return ((FVRInteractiveObject)Box).IsHeld;
		}

		public override void BeginInteraction(FVRViveHand hand)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			SM.PlayCoreSound((FVRPooledAudioType)0, AudEvent_Grab, ((HandInput)(ref hand.Input)).Pos);
			((FVRInteractiveObject)this).BeginInteraction(hand);
		}

		public override void UpdateInteraction(FVRViveHand hand)
		{
			((FVRInteractiveObject)this).UpdateInteraction(hand);
		}

		public override void EndInteraction(FVRViveHand hand)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			SM.PlayCoreSound((FVRPooledAudioType)0, AudEvent_End, ((HandInput)(ref hand.Input)).Pos);
			((FVRInteractiveObject)this).EndInteraction(hand);
		}
	}
}
namespace Sora101Ven.Mega_Magnus_Blaster
{
	[BepInPlugin("Sora101Ven.Mega_Magnus_Blaster", "Mega_Magnus_Blaster", "1.0.0")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class Mega_Magnus_BlasterPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadAssets();
		}

		private void LoadAssets()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Sora101Ven.Mega_Magnus_Blaster");
			OtherLoader.RegisterDirectLoad(BasePath, "Sora101Ven.Mega_Magnus_Blaster", "", "", "magnusnerf", "");
		}
	}
}
public class OBJExporter : ScriptableWizard
{
	public bool onlySelectedObjects = false;

	public bool applyPosition = true;

	public bool applyRotation = true;

	public bool applyScale = true;

	public bool generateMaterials = true;

	public bool exportTextures = true;

	public bool splitObjects = true;

	public bool autoMarkTexReadable = false;

	public bool objNameAddIdNum = false;

	private string versionString = "v2.0";

	private string lastExportFolder;

	private bool StaticBatchingEnabled()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		PlayerSettings[] array = Resources.FindObjectsOfTypeAll<PlayerSettings>();
		if (array == null)
		{
			return false;
		}
		SerializedObject val = new SerializedObject((Object[])(object)array);
		SerializedProperty val2 = val.FindProperty("m_BuildTargetBatching");
		for (int i = 0; i < val2.arraySize; i++)
		{
			SerializedProperty arrayElementAtIndex = val2.GetArrayElementAtIndex(i);
			if (arrayElementAtIndex == null)
			{
				continue;
			}
			IEnumerator enumerator = arrayElementAtIndex.GetEnumerator();
			if (enumerator == null)
			{
				continue;
			}
			while (enumerator.MoveNext())
			{
				SerializedProperty val3 = (SerializedProperty)enumerator.Current;
				if (val3 != null && val3.name == "m_StaticBatching")
				{
					return val3.boolValue;
				}
			}
		}
		return false;
	}

	private void OnWizardUpdate()
	{
		((ScriptableWizard)this).helpString = "Aaro4130's OBJ Exporter " + versionString;
	}

	private Vector3 RotateAroundPoint(Vector3 point, Vector3 pivot, Quaternion angle)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		return angle * (point - pivot) + pivot;
	}

	private Vector3 MultiplyVec3s(Vector3 v1, Vector3 v2)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
	}

	private void OnWizardCreate()
	{
		if (StaticBatchingEnabled() && Application.isPlaying)
		{
			EditorUtility.DisplayDialog("Error", "Static batching is enabled. This will cause the export file to look like a mess, as well as be a large filesize. Disable this option, and restart the player, before continuing.", "OK");
			return;
		}
		if (autoMarkTexReadable)
		{
			int num = EditorUtility.DisplayDialogComplex("Warning", "This will convert all textures to Advanced type with the read/write option set. This is not reversible and will permanently affect your project. Continue?", "Yes", "No", "Cancel");
			if (num > 0)
			{
				return;
			}
		}
		string @string = EditorPrefs.GetString("a4_OBJExport_lastPath", "");
		string string2 = EditorPrefs.GetString("a4_OBJExport_lastFile", "unityexport.obj");
		string text = EditorUtility.SaveFilePanel("Export OBJ", @string, string2, "obj");
		if (text.Length > 0)
		{
			FileInfo fileInfo = new FileInfo(text);
			EditorPrefs.SetString("a4_OBJExport_lastFile", fileInfo.Name);
			EditorPrefs.SetString("a4_OBJExport_lastPath", fileInfo.Directory.FullName);
			Export(text);
		}
	}

	private void Export(string exportPath)
	{
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_0386: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_0468: Unknown result type (might be due to invalid IL or missing references)
		//IL_046b: Unknown result type (might be due to invalid IL or missing references)
		//IL_046d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03be: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_048a: Unknown result type (might be due to invalid IL or missing references)
		//IL_048f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		//IL_0498: Unknown result type (might be due to invalid IL or missing references)
		//IL_049d: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_04af: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0565: Unknown result type (might be due to invalid IL or missing references)
		//IL_056a: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<string, bool> dictionary = new Dictionary<string, bool>();
		FileInfo fileInfo = new FileInfo(exportPath);
		lastExportFolder = fileInfo.Directory.FullName;
		string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(exportPath);
		EditorUtility.DisplayProgressBar("Exporting OBJ", "Please wait.. Starting export.", 0f);
		MeshFilter[] array;
		if (onlySelectedObjects)
		{
			List<MeshFilter> list = new List<MeshFilter>();
			GameObject[] gameObjects = Selection.gameObjects;
			foreach (GameObject val in gameObjects)
			{
				MeshFilter component = val.GetComponent<MeshFilter>();
				if ((Object)(object)component != (Object)null)
				{
					list.Add(component);
				}
			}
			array = list.ToArray();
		}
		else
		{
			array = Object.FindObjectsOfType(typeof(MeshFilter)) as MeshFilter[];
		}
		if (Application.isPlaying)
		{
			MeshFilter[] array2 = array;
			foreach (MeshFilter val2 in array2)
			{
				MeshRenderer component2 = ((Component)val2).gameObject.GetComponent<MeshRenderer>();
				if ((Object)(object)component2 != (Object)null && ((Renderer)component2).isPartOfStaticBatch)
				{
					EditorUtility.ClearProgressBar();
					EditorUtility.DisplayDialog("Error", "Static batched object detected. Static batching is not compatible with this exporter. Please disable it before starting the player.", "OK");
					return;
				}
			}
		}
		StringBuilder stringBuilder = new StringBuilder();
		StringBuilder stringBuilder2 = new StringBuilder();
		stringBuilder.AppendLine("# Export of " + Application.loadedLevelName);
		stringBuilder.AppendLine("# from Aaro4130 OBJ Exporter " + versionString);
		if (generateMaterials)
		{
			stringBuilder.AppendLine("mtllib " + fileNameWithoutExtension + ".mtl");
		}
		float num = array.Length + 1;
		int num2 = 0;
		for (int k = 0; k < array.Length; k++)
		{
			string name = ((Object)((Component)array[k]).gameObject).name;
			float num3 = (float)(k + 1) / num;
			EditorUtility.DisplayProgressBar("Exporting objects... (" + Mathf.Round(num3 * 100f) + "%)", "Exporting object " + name, num3);
			MeshFilter val3 = array[k];
			MeshRenderer component3 = ((Component)array[k]).gameObject.GetComponent<MeshRenderer>();
			if (splitObjects)
			{
				string text = name;
				if (objNameAddIdNum)
				{
					text = text + "_" + k;
				}
				stringBuilder.AppendLine("g " + text);
			}
			if ((Object)(object)component3 != (Object)null && generateMaterials)
			{
				Material[] sharedMaterials = ((Renderer)component3).sharedMaterials;
				foreach (Material val4 in sharedMaterials)
				{
					if (!dictionary.ContainsKey(((Object)val4).name))
					{
						dictionary[((Object)val4).name] = true;
						stringBuilder2.Append(MaterialToString(val4));
						stringBuilder2.AppendLine();
					}
				}
			}
			Mesh sharedMesh = val3.sharedMesh;
			int num4 = (int)Mathf.Clamp(((Component)val3).gameObject.transform.lossyScale.x * ((Component)val3).gameObject.transform.lossyScale.z, -1f, 1f);
			Vector3[] vertices = sharedMesh.vertices;
			foreach (Vector3 val5 in vertices)
			{
				Vector3 val6 = val5;
				if (applyScale)
				{
					val6 = MultiplyVec3s(val6, ((Component)val3).gameObject.transform.lossyScale);
				}
				if (applyRotation)
				{
					val6 = RotateAroundPoint(val6, Vector3.zero, ((Component)val3).gameObject.transform.rotation);
				}
				if (applyPosition)
				{
					val6 += ((Component)val3).gameObject.transform.position;
				}
				val6.x *= -1f;
				stringBuilder.AppendLine("v " + val6.x + " " + val6.y + " " + val6.z);
			}
			Vector3[] normals = sharedMesh.normals;
			foreach (Vector3 val7 in normals)
			{
				Vector3 val8 = val7;
				if (applyScale)
				{
					Vector3 v = val8;
					Vector3 lossyScale = ((Component)val3).gameObject.transform.lossyScale;
					val8 = MultiplyVec3s(v, ((Vector3)(ref lossyScale)).normalized);
				}
				if (applyRotation)
				{
					val8 = RotateAroundPoint(val8, Vector3.zero, ((Component)val3).gameObject.transform.rotation);
				}
				val8.x *= -1f;
				stringBuilder.AppendLine("vn " + val8.x + " " + val8.y + " " + val8.z);
			}
			Vector2[] uv = sharedMesh.uv;
			for (int num5 = 0; num5 < uv.Length; num5++)
			{
				Vector2 val9 = uv[num5];
				stringBuilder.AppendLine("vt " + val9.x + " " + val9.y);
			}
			for (int num6 = 0; num6 < sharedMesh.subMeshCount; num6++)
			{
				if ((Object)(object)component3 != (Object)null && num6 < ((Renderer)component3).sharedMaterials.Length)
				{
					string name2 = ((Object)((Renderer)component3).sharedMaterials[num6]).name;
					stringBuilder.AppendLine("usemtl " + name2);
				}
				else
				{
					stringBuilder.AppendLine("usemtl " + name + "_sm" + num6);
				}
				int[] triangles = sharedMesh.GetTriangles(num6);
				for (int num7 = 0; num7 < triangles.Length; num7 += 3)
				{
					int index = triangles[num7] + 1 + num2;
					int index2 = triangles[num7 + 1] + 1 + num2;
					int index3 = triangles[num7 + 2] + 1 + num2;
					if (num4 < 0)
					{
						stringBuilder.AppendLine("f " + ConstructOBJString(index) + " " + ConstructOBJString(index2) + " " + ConstructOBJString(index3));
					}
					else
					{
						stringBuilder.AppendLine("f " + ConstructOBJString(index3) + " " + ConstructOBJString(index2) + " " + ConstructOBJString(index));
					}
				}
			}
			num2 += sharedMesh.vertices.Length;
		}
		File.WriteAllText(exportPath, stringBuilder.ToString());
		if (generateMaterials)
		{
			File.WriteAllText(fileInfo.Directory.FullName + "\\" + fileNameWithoutExtension + ".mtl", stringBuilder2.ToString());
		}
		EditorUtility.ClearProgressBar();
	}

	private string TryExportTexture(string propertyName, Material m)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		if (m.HasProperty(propertyName))
		{
			Texture texture = m.GetTexture(propertyName);
			if ((Object)(object)texture != (Object)null)
			{
				return ExportTexture((Texture2D)texture);
			}
		}
		return "false";
	}

	private string ExportTexture(Texture2D t)
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		try
		{
			if (autoMarkTexReadable)
			{
				string assetPath = AssetDatabase.GetAssetPath((Object)(object)t);
				AssetImporter atPath = AssetImporter.GetAtPath(assetPath);
				TextureImporter val = (TextureImporter)(object)((atPath is TextureImporter) ? atPath : null);
				if ((Object)(object)val != (Object)null)
				{
					val.textureType = (TextureImporterType)0;
					if (!val.isReadable)
					{
						val.isReadable = true;
						AssetDatabase.ImportAsset(assetPath);
						AssetDatabase.Refresh();
					}
				}
			}
			string text = lastExportFolder + "\\" + ((Object)t).name + ".png";
			Texture2D val2 = new Texture2D(((Texture)t).width, ((Texture)t).height, (TextureFormat)5, false);
			val2.SetPixels(t.GetPixels());
			File.WriteAllBytes(text, val2.EncodeToPNG());
			return text;
		}
		catch (Exception)
		{
			Debug.Log((object)("Could not export texture : " + ((Object)t).name + ". is it readable?"));
			return "null";
		}
	}

	private string ConstructOBJString(int index)
	{
		string text = index.ToString();
		return text + "/" + text + "/" + text;
	}

	private string MaterialToString(Material m)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//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_00ae: 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_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("newmtl " + ((Object)m).name);
		if (m.HasProperty("_Color"))
		{
			stringBuilder.AppendLine("Kd " + m.color.r + " " + m.color.g + " " + m.color.b);
			if (m.color.a < 1f)
			{
				stringBuilder.AppendLine("Tr " + (1f - m.color.a));
				stringBuilder.AppendLine("d " + m.color.a);
			}
		}
		if (m.HasProperty("_SpecColor"))
		{
			Color color = m.GetColor("_SpecColor");
			stringBuilder.AppendLine("Ks " + color.r + " " + color.g + " " + color.b);
		}
		if (exportTextures)
		{
			string text = TryExportTexture("_MainTex", m);
			if (text != "false")
			{
				stringBuilder.AppendLine("map_Kd " + text);
			}
			text = TryExportTexture("_SpecMap", m);
			if (text != "false")
			{
				stringBuilder.AppendLine("map_Ks " + text);
			}
			text = TryExportTexture("_BumpMap", m);
			if (text != "false")
			{
				stringBuilder.AppendLine("map_Bump " + text);
			}
		}
		stringBuilder.AppendLine("illum 2");
		return stringBuilder.ToString();
	}

	[MenuItem("File/Export/Wavefront OBJ")]
	private static void CreateWizard()
	{
		ScriptableWizard.DisplayWizard("Export OBJ", typeof(OBJExporter), "Export");
	}
}