using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using Il2Cpp; using Il2CppInterop.Runtime.InteropTypes.Arrays; using MelonLoader; using ModelMod; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: MelonInfo(typeof(CessnaImporter), "Cessna Importer Ultimate", "3.0.0", "Scott", null)] [assembly: MelonGame(null, null)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("3d modil importer")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("3d modil importer")] [assembly: AssemblyTitle("3d modil importer")] [assembly: AssemblyVersion("1.0.0.0")] namespace ModelMod; public class CessnaImporter : MelonMod { private bool _showMenu = false; private string _folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "game"); private string _status = "Ready"; private Color _statusColor = Color.white; private Rect _windowRect = new Rect(100f, 100f, 400f, 450f); private GameObject _spawnedModel; private float _scale = 1f; private Vector3 _rotation = Vector3.zero; private Texture2D _loadedTex; private GUIStyle _windowStyle; private GUIStyle _labelStyle; private GUIStyle _buttonStyle; private GUIStyle _textFieldStyle; private GUIStyle _headerStyle; private bool _stylesInitialized = false; public override void OnUpdate() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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) if (Input.GetKeyDown((KeyCode)277)) { _showMenu = !_showMenu; if (_showMenu) { Cursor.visible = true; Cursor.lockState = (CursorLockMode)0; } } if ((Object)(object)_spawnedModel != (Object)null) { _spawnedModel.transform.localScale = Vector3.one * _scale; _spawnedModel.transform.localRotation = Quaternion.Euler(_rotation); } } public override void OnGUI() { //IL_002b: 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) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) if (_showMenu) { InitializeStyles(); GUI.backgroundColor = new Color(0.05f, 0.05f, 0.05f, 0.95f); _windowRect = GUI.Window(0, _windowRect, WindowFunction.op_Implicit((Action)DrawWindow), "✈\ufe0f Cessna Importer Pro"); } } private void InitializeStyles() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Expected O, but got Unknown if (!_stylesInitialized) { _windowStyle = new GUIStyle(GUI.skin.window); _windowStyle.padding = new RectOffset(15, 15, 25, 15); _headerStyle = new GUIStyle(GUI.skin.label); _headerStyle.fontStyle = (FontStyle)1; _headerStyle.fontSize = 14; _headerStyle.normal.textColor = new Color(0.8f, 0.8f, 1f); _labelStyle = new GUIStyle(GUI.skin.label); _labelStyle.fontSize = 12; _buttonStyle = new GUIStyle(GUI.skin.button); _buttonStyle.fixedHeight = 35f; _buttonStyle.fontStyle = (FontStyle)1; _buttonStyle.hover.textColor = Color.cyan; _textFieldStyle = new GUIStyle(GUI.skin.textField); _textFieldStyle.fixedHeight = 25f; _textFieldStyle.alignment = (TextAnchor)3; _stylesInitialized = true; } } private void DrawWindow(int id) { //IL_00b0: 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_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Expected O, but got Unknown //IL_025d: 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_0238: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) GUILayout.BeginVertical((Il2CppReferenceArray)null); GUILayout.Label("MODEL SOURCE CONFIGURATION", _headerStyle, (Il2CppReferenceArray)null); GUILayout.Space(5f); GUILayout.Label("Directory Path:", _labelStyle, (Il2CppReferenceArray)null); _folderPath = GUILayout.TextField(_folderPath, _textFieldStyle, Array.Empty()); GUILayout.Space(15f); if (GUILayout.Button("IMPORT MODEL & TEXTURE", _buttonStyle, Array.Empty())) { if (Directory.Exists(_folderPath)) { UpdateStatus("Processing model...", Color.yellow); LoadModel(_folderPath); } else { UpdateStatus("Error: Directory not found!", Color.red); } } if ((Object)(object)_spawnedModel != (Object)null && GUILayout.Button("CLEAR SPAWNED MODEL", _buttonStyle, Array.Empty())) { Object.Destroy((Object)(object)_spawnedModel); _spawnedModel = null; UpdateStatus("Cleared.", Color.white); } GUILayout.Space(20f); if ((Object)(object)_spawnedModel != (Object)null) { GUILayout.Label("TRANSFORM CONTROLS", _headerStyle, (Il2CppReferenceArray)null); GUILayout.BeginHorizontal((Il2CppReferenceArray)null); GUILayout.Label($"Scale: {_scale:F2}", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }); _scale = GUILayout.HorizontalSlider(_scale, 0.01f, 10f, Array.Empty()); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal((Il2CppReferenceArray)null); GUILayout.Label("Rotation Y:", _labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }); _rotation.y = GUILayout.HorizontalSlider(_rotation.y, 0f, 360f, Array.Empty()); GUILayout.EndHorizontal(); if (GUILayout.Button("Reset Transform", (Il2CppReferenceArray)null)) { _scale = 1f; _rotation = Vector3.zero; } } GUILayout.FlexibleSpace(); GUIStyle val = new GUIStyle(_labelStyle); val.normal.textColor = _statusColor; val.fontStyle = (FontStyle)1; val.alignment = (TextAnchor)4; GUILayout.BeginVertical(GUI.skin.box, (Il2CppReferenceArray)null); GUILayout.Label(_status, val, (Il2CppReferenceArray)null); GUILayout.EndVertical(); GUILayout.EndVertical(); GUI.DragWindow(); } private void UpdateStatus(string msg, Color col) { //IL_0009: 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) _status = msg; _statusColor = col; MelonLogger.Msg(msg); } public void LoadModel(string path) { //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown //IL_00d6: 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_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Expected O, but got Unknown //IL_0252: 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) string path2 = Path.Combine(path, "model.obj"); string path3 = Path.Combine(path, "texture.png"); if (!File.Exists(path2)) { UpdateStatus("Error: model.obj missing!", Color.red); return; } PlayerControl val = Object.FindObjectOfType(); if ((Object)(object)val == (Object)null) { UpdateStatus("Error: Player not found!", Color.red); return; } try { if ((Object)(object)_spawnedModel != (Object)null) { Object.Destroy((Object)(object)_spawnedModel); } Mesh val2 = ParseObj(path2); if ((Object)(object)val2 == (Object)null) { UpdateStatus("Error: Mesh parsing failed!", Color.red); return; } _spawnedModel = new GameObject("Cessna_Visible_Object"); _spawnedModel.transform.position = ((Component)val).transform.position + ((Component)val).transform.forward * 7f + Vector3.up * 2f; _spawnedModel.transform.rotation = ((Component)val).transform.rotation; _spawnedModel.AddComponent().mesh = val2; MeshRenderer val3 = _spawnedModel.AddComponent(); MeshCollider val4 = _spawnedModel.AddComponent(); val4.sharedMesh = val2; val4.convex = false; Shader shader = ((Renderer)((Component)val).GetComponentInChildren()).material.shader; Material val5 = new Material(shader); if (File.Exists(path3)) { byte[] array = File.ReadAllBytes(path3); _loadedTex = new Texture2D(2, 2, (TextureFormat)4, false); ImageConversion.LoadImage(_loadedTex, Il2CppStructArray.op_Implicit(array), false); ((Texture)_loadedTex).filterMode = (FilterMode)2; ((Texture)_loadedTex).anisoLevel = 4; _loadedTex.Apply(true); string[] array2 = new string[4] { "_MainTex", "_BaseMap", "_Albedo", "_MainTexture" }; string[] array3 = array2; foreach (string text in array3) { if (val5.HasProperty(text)) { val5.SetTexture(text, (Texture)(object)_loadedTex); } } val5.color = Color.white; UpdateStatus("Success: Model & Texture Loaded!", Color.green); } else { UpdateStatus("Model loaded (No texture).", Color.yellow); } ((Renderer)val3).material = val5; _spawnedModel.SetActive(true); Object.DontDestroyOnLoad((Object)(object)_spawnedModel); } catch (Exception ex) { UpdateStatus("Critical Error: " + ex.Message, Color.red); MelonLogger.Error(ex.ToString()); } } private Mesh ParseObj(string path) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0227: 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_0105: Unknown result type (might be due to invalid IL or missing references) Mesh val = new Mesh(); List list = new List(); List list2 = new List(); List list3 = new List(); List list4 = new List(); List list5 = new List(); Dictionary h = new Dictionary(); string[] array = File.ReadAllLines(path); string[] array2 = array; foreach (string text in array2) { string text2 = text.Trim(); if (string.IsNullOrEmpty(text2) || text2.StartsWith("#")) { continue; } string[] array3 = text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array3.Length < 2) { continue; } if (array3[0] == "v") { list.Add(new Vector3(float.Parse(array3[1]), float.Parse(array3[2]), float.Parse(array3[3]))); } else if (array3[0] == "vt") { list2.Add(new Vector2(float.Parse(array3[1]), float.Parse(array3[2]))); } else if (array3[0] == "f") { for (int j = 1; j < array3.Length - 2; j++) { AddPoint(array3[1], list, list2, list3, list4, list5, h); AddPoint(array3[j + 1], list, list2, list3, list4, list5, h); AddPoint(array3[j + 2], list, list2, list3, list4, list5, h); } } } if (list3.Count == 0) { return null; } val.vertices = Il2CppStructArray.op_Implicit(list3.ToArray()); val.uv = Il2CppStructArray.op_Implicit((Vector2[])((list4.Count == list3.Count) ? ((Array)list4.ToArray()) : ((Array)new Vector2[list3.Count]))); val.triangles = Il2CppStructArray.op_Implicit(list5.ToArray()); val.RecalculateNormals(); val.RecalculateBounds(); val.bounds = new Bounds(Vector3.zero, Vector3.one * 5000f); return val; } private void AddPoint(string pt, List tv, List tuv, List ov, List ouv, List ot, Dictionary h) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) if (h.ContainsKey(pt)) { ot.Add(h[pt]); return; } string[] array = pt.Split('/'); int num = int.Parse(array[0]); if (num < 0) { num = tv.Count + num + 1; } ov.Add(tv[num - 1]); if (array.Length > 1 && !string.IsNullOrEmpty(array[1])) { int num2 = int.Parse(array[1]); if (num2 < 0) { num2 = tuv.Count + num2 + 1; } ouv.Add(tuv[num2 - 1]); } else { ouv.Add(Vector2.zero); } int num3 = ov.Count - 1; ot.Add(num3); h.Add(pt, num3); } }