using System;
using System.Collections;
using System.Collections.Generic;
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 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 DaggerAce.Jericho_941F;
[BepInPlugin("DaggerAce.Jericho_941F", "Jericho_941F", "1.0.0")]
[BepInProcess("h3vr.exe")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class Jericho_941FPlugin : BaseUnityPlugin
{
private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
private void Awake()
{
LoadAssets();
}
private void LoadAssets()
{
OtherLoader.RegisterDirectLoad(BasePath, "DaggerAce.Jericho_941F", "", "", "jericho", "");
}
}
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");
}
}