using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using DM; using HarmonyLib; using InControl; using Landfall.TABS; using Landfall.TABS.GameState; using Landfall.TABS.TeamEdge; using Landfall.TABS.Workshop; using Landfall.TABS_Input; using LevelCreator; using Microsoft.CodeAnalysis; using Pathfinding; using SCPE; using TFBGames; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Networking; using UnityEngine.Rendering; using UnityEngine.Rendering.PostProcessing; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Mod name")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("made in SFT by FhpSlime")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("3a45c3cf-230c-4310-952f-0887d4266a22")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [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; } } } public class Item : MonoBehaviour { public enum kind { Weapon, Cloth, Skill, Unit, Projectile, Other } public string name; public kind Kind; } namespace MAPX { public static class ColorPickerLocalization { public static bool IsChinese { get { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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_0035: Invalid comparison between Unknown and I4 try { return typeof(Localizer).GetField("m_locale", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) is Language val && (int)val == 7; } catch { return false; } } } public static string GetOpacityText(int percent) { if (!IsChinese) { return $"Opacity: {percent}%"; } return $"不透明度: {percent}%"; } public static string GetEmissionText(int percent) { if (!IsChinese) { return $"Emission: {percent}%"; } return $"发光度: {percent}%"; } public static string GetSmoothnessText(int percent) { if (!IsChinese) { return $"Smoothness: {percent}%"; } return $"平滑度: {percent}%"; } } public class CustomMusicManager : MonoBehaviour { public static CustomMusicManager Instance; public static string MusicBasePath; public List CustomCategories = new List(); public Dictionary PlacementClips = new Dictionary(); public Dictionary BattleClips = new Dictionary(); public string CurrentCustomMusicCategory = string.Empty; public static void Create() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if ((Object)Instance == (Object)null) { GameObject val = new GameObject("CustomMusicManager"); Instance = val.AddComponent(); Object.DontDestroyOnLoad((Object)val); } } private void Awake() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0034: 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_0044: Expected O, but got Unknown //IL_0044: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown if ((Object)Instance == (Object)null) { Instance = this; Object.DontDestroyOnLoad((Object)((Component)this).gameObject); Initialize(); } else if ((Object)Instance != (Object)this) { Object.Destroy((Object)((Component)this).gameObject); } } private void Start() { if (string.IsNullOrEmpty(MusicBasePath)) { Initialize(); } ((MonoBehaviour)this).StartCoroutine(SetupGameStateListenerCoroutine()); } private void Initialize() { MusicBasePath = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "BepInEx", "plugins", "MMusic"); if (!Directory.Exists(MusicBasePath)) { try { Directory.CreateDirectory(MusicBasePath); Debug.Log((object)("[CustomMusicManager] Created music directory at " + MusicBasePath)); } catch (Exception ex) { Debug.LogError((object)("[CustomMusicManager] Failed to create directory: " + ex.Message)); return; } } ((MonoBehaviour)this).StartCoroutine(LoadAllMusic()); } private IEnumerator LoadAllMusic() { if (!Directory.Exists(MusicBasePath)) { yield break; } Debug.Log((object)("[CustomMusicManager] Scanning for music in " + MusicBasePath)); string[] directories = Directory.GetDirectories(MusicBasePath); string[] array = directories; foreach (string text in array) { string categoryName = Path.GetFileName(text); string text2 = Path.Combine(text, "P"); string fDir = Path.Combine(text, "F"); if (!Directory.Exists(text2) || !Directory.Exists(fDir)) { continue; } bool pLoaded = false; bool fLoaded = false; yield return ((MonoBehaviour)this).StartCoroutine(LoadClipFromDir(text2, categoryName, isPlacement: true, delegate(bool success) { pLoaded = success; })); yield return ((MonoBehaviour)this).StartCoroutine(LoadClipFromDir(fDir, categoryName, isPlacement: false, delegate(bool success) { fLoaded = success; })); if (pLoaded && fLoaded) { CustomCategories.Add(categoryName); Debug.Log((object)("[CustomMusicManager] Loaded custom music category: " + categoryName)); MusicHandler service = ServiceLocator.GetService(); if ((Object)service != (Object)null) { AddToHandler(service, categoryName); } } } } private IEnumerator LoadClipFromDir(string dir, string category, bool isPlacement, Action callback) { string text = Directory.GetFiles(dir).FirstOrDefault((string f) => f.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase)); if (text != null) { string url = "file://" + text; AudioType val = (AudioType)0; if (text.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)) { val = (AudioType)20; } else if (text.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase)) { val = (AudioType)14; } else if (text.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase)) { val = (AudioType)13; } UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, val); try { yield return www.SendWebRequest(); if (!www.isNetworkError && !www.isHttpError) { AudioClip content = DownloadHandlerAudioClip.GetContent(www); ((Object)content).name = category + (isPlacement ? "_Placement" : "_Battle"); if (isPlacement) { PlacementClips[category] = content; } else { BattleClips[category] = content; } callback(obj: true); } else { Debug.LogError((object)("[CustomMusicManager] Failed to load audio: " + url + ", Error: " + www.error)); callback(obj: false); } } finally { ((IDisposable)www)?.Dispose(); } } else { callback(obj: false); } } public void AddToHandler(MusicHandler handler, string category) { if (PlacementClips.TryGetValue(category, out var value)) { CreateSongInstance(handler, category + "/Placement", value); } if (BattleClips.TryGetValue(category, out var value2)) { CreateSongInstance(handler, category + "/Battle", value2); } } private void CreateSongInstance(MusicHandler handler, string refKey, AudioClip clip) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) if (!handler.m_songs.ContainsKey(refKey)) { SongInstance val = new SongInstance(); val.clip = clip; val.songRef = refKey; val.positionInSong = 0; val.soundEffectInstance = new SoundEffectInstance(); val.soundEffectInstance.volume = Vector2.one; val.soundEffectInstance.pitch = Vector2.one; val.soundEffectInstance.priority = 128; val.soundEffectInstance.lengthInMeasures = clip.samples; val.soundEffectInstance.transitionMeasures = new int[1]; val.soundEffectInstance.soundRef = refKey; handler.m_songs.Add(refKey, val); } } private IEnumerator SetupGameStateListenerCoroutine() { yield return (object)new WaitUntil((Func)(() => ServiceLocator.GetService() != null)); GameStateManager service = ServiceLocator.GetService(); if (service != null) { service.GameStateChanged += OnGameStateChanged; Debug.Log((object)"[CustomMusicManager] Game state listener registered"); } } private void OnGameStateChanged(GameState newGameState) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 if (string.IsNullOrEmpty(CurrentCustomMusicCategory)) { return; } MusicHandler service = ServiceLocator.GetService(); if (!((Object)service == (Object)null)) { string text = (((int)newGameState == 1) ? "/Battle" : "/Placement"); string text2 = CurrentCustomMusicCategory + text; if (service.m_songs.ContainsKey(text2)) { service.PlaySong(text2); Debug.Log((object)("[CustomMusicManager] Switched to " + text.Substring(1) + " music: " + text2)); } } } private void OnDestroy() { GameStateManager service = ServiceLocator.GetService(); if (service != null) { service.GameStateChanged -= OnGameStateChanged; } } } internal static class ExternalModelRegistry { [Serializable] private class PrefabData { public string name; public Vector3 position; public Quaternion rotation; public Vector3 scale; public bool active; } [Serializable] private class RegistryState { public List RegisteredIds; public string Timestamp; } private static readonly HashSet s_registeredIds = new HashSet(); private const string Category = "Custom"; private const string Group = "Other"; private const string IdPrefix = "mod.external."; private static readonly Dictionary s_externalPrefabs = new Dictionary(); private static readonly string SaveModelPath = Path.Combine(Paths.PluginPath, "savemodel"); private static readonly HashSet s_persistentRegisteredIds = new HashSet(); private static readonly string RegistryStatePath = Path.Combine(Paths.PluginPath, "external_models_registry.json"); private static readonly HashSet s_negativeCache = new HashSet(); private static readonly Dictionary s_pathCache = new Dictionary(); private static readonly HashSet s_pathNotFoundCache = new HashSet(); private static GameObject s_hiddenHolder; private static AssetBundle s_cachedEmbeddedBundle = null; private static DMEditorObjectTable s_cachedEmbeddedTable = null; private static string MakeId(string bundlePath, string prefabName) { string text = Path.GetFileNameWithoutExtension(bundlePath)?.ToLowerInvariant() ?? "bundle"; string text2 = prefabName?.ToLowerInvariant() ?? "unnamed"; return "mod.external." + text + "." + text2; } private static string MakeRadialPath(string displayName) { string text = Sanitize(displayName); return "Custom/Other/" + text; } private static string Sanitize(string name) { if (string.IsNullOrWhiteSpace(name)) { return "Item"; } char[] invalid = Path.GetInvalidFileNameChars(); return new string(name.Select((char c) => (!invalid.Contains(c)) ? c : '_').ToArray()).Replace('/', '_').Replace('\\', '_').Trim(); } private static IEnumerable<(string, GameObject)> LoadExternalPrefabs() { string path = Path.Combine(Paths.PluginPath, "newmodel"); if (!Directory.Exists(path)) { yield break; } string[] source = new string[3] { ".bundle", ".ab", ".assetbundle" }; List<(string, GameObject)> results = new List<(string, GameObject)>(); foreach (string item in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) { string text = Path.GetExtension(item).ToLowerInvariant(); if (source.Contains(text)) { AssetBundle val = null; try { val = AssetBundle.LoadFromFile(item); if ((Object)val == (Object)null) { Debug.LogWarning((object)("[ExternalModelRegistry] Failed to load AssetBundle: " + item)); continue; } GameObject[] array = val.LoadAllAssets(); if (array == null) { continue; } GameObject[] array2 = array; foreach (GameObject val2 in array2) { if ((Object)val2 != (Object)null) { results.Add((item, val2)); } } } finally { if ((Object)val != (Object)null) { val.Unload(false); } } continue; } if (text == ".obj") { GameObject val3 = TryLoadObjAsGameObject(item); if ((Object)val3 != (Object)null) { results.Add((item, val3)); } } if (text == ".fbx") { GameObject val4 = TryLoadFbxAsGameObject(item); if ((Object)val4 != (Object)null) { results.Add((item, val4)); } } } for (int j = 0; j < results.Count; j++) { yield return results[j]; } } private static void SetIfExists(object obj, string member, object value) { Type type = obj.GetType(); PropertyInfo property = type.GetProperty(member, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.CanWrite) { try { property.SetValue(obj, value); return; } catch { } } FieldInfo field = type.GetField(member, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { try { field.SetValue(obj, value); } catch { } } } private static Sprite CreatePlaceholderSprite() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown try { Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false); Color32[] pixels = Enumerable.Repeat(new Color32((byte)200, (byte)200, (byte)220, byte.MaxValue), 4096).ToArray(); val.SetPixels32(pixels); val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 64f); } catch { return null; } } private static GameObject TryLoadObjAsGameObject(string objPath) { //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Expected O, but got Unknown try { Type type; if ((type = Type.GetType("Dummiesman.OBJLoader, Assembly-CSharp")) == null) { type = (from a in AppDomain.CurrentDomain.GetAssemblies() select a.GetType("Dummiesman.OBJLoader")).FirstOrDefault((Type t) => t != null); } Type type2 = type; if (type2 == null) { Debug.LogWarning((object)("[ExternalModelRegistry] OBJLoader not found, skip .obj: " + objPath)); return null; } object obj = Activator.CreateInstance(type2); string text = Path.Combine(Path.GetDirectoryName(objPath) ?? string.Empty, Path.GetFileNameWithoutExtension(objPath) + ".mtl"); GameObject val = null; if (!string.IsNullOrEmpty(text) && File.Exists(text)) { MethodInfo method = type2.GetMethod("Load", BindingFlags.Instance | BindingFlags.Public, null, new Type[2] { typeof(string), typeof(string) }, null); if (method != null) { object obj2 = method.Invoke(obj, new object[2] { objPath, text }); val = (GameObject)((obj2 is GameObject) ? obj2 : null); } } if ((Object)val == (Object)null) { MethodInfo method2 = type2.GetMethod("Load", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(string) }, null); object obj3 = ((method2 != null) ? method2.Invoke(obj, new object[1] { objPath }) : null); val = (GameObject)((obj3 is GameObject) ? obj3 : null); } if ((Object)val == (Object)null) { return null; } AddCollidersToAllMeshes(val); val.transform.SetParent(GetHiddenHolder().transform); return val; } catch (Exception ex) { Debug.LogError((object)("[ExternalModelRegistry] OBJ load error: " + objPath + " :: " + ex)); return null; } } public static int RegisterIntoEditor(DMEditor editor) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Expected O, but got Unknown //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Expected O, but got Unknown //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Expected O, but got Unknown //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Expected O, but got Unknown if ((Object)editor == (Object)null || (Object)editor.editorObjectTable == (Object)null) { Debug.LogError((object)"[ExternalModelRegistry] Editor or editorObjectTable is null"); return 0; } int num = MergeEmbeddedTableIntoEditor(editor); RestoreEmbeddedModelReferences(editor); LoadPersistentRegistryState(); int num2 = 0; int num3 = 0; int num4 = 0; HashSet hashSet = new HashSet(); foreach (string s_persistentRegisteredId in s_persistentRegisteredIds) { DMEditorObjectRow rowValue = ((DataTable)(object)editor.editorObjectTable).GetRowValue(s_persistentRegisteredId); if (rowValue == null) { if (!FileExistsForId(s_persistentRegisteredId)) { hashSet.Add(s_persistentRegisteredId); num4++; continue; } GameObject val = LoadPrefabFromFile(s_persistentRegisteredId); if ((Object)val != (Object)null) { string originalModelPath = GetOriginalModelPath(s_persistentRegisteredId); string displayName = ((!string.IsNullOrEmpty(originalModelPath)) ? Path.GetFileNameWithoutExtension(originalModelPath) : ((Object)val).name); DMEditorObjectRow val2 = CreateRow(val, displayName, s_persistentRegisteredId, originalModelPath); if (val2 != null) { ((DataTable)(object)editor.editorObjectTable).AddRow(s_persistentRegisteredId, val2); s_registeredIds.Add(s_persistentRegisteredId); s_externalPrefabs[s_persistentRegisteredId] = val; num3++; } } else { hashSet.Add(s_persistentRegisteredId); num4++; } continue; } if (!s_registeredIds.Contains(s_persistentRegisteredId)) { s_registeredIds.Add(s_persistentRegisteredId); } if (!((Object)rowValue.EditorObject == (Object)null) && !((Object)rowValue.GameObject == (Object)null)) { continue; } if (!FileExistsForId(s_persistentRegisteredId)) { hashSet.Add(s_persistentRegisteredId); num4++; continue; } GameObject val3 = LoadPrefabFromFile(s_persistentRegisteredId); if ((Object)val3 != (Object)null) { string originalModelPath2 = GetOriginalModelPath(s_persistentRegisteredId); string displayName2 = ((!string.IsNullOrEmpty(originalModelPath2)) ? Path.GetFileNameWithoutExtension(originalModelPath2) : ((Object)val3).name); DMEditorObjectRow val4 = CreateRow(val3, displayName2, s_persistentRegisteredId, originalModelPath2); if (val4 != null) { rowValue.EditorObject = val4.EditorObject; rowValue.GameObject = val4.GameObject; rowValue.Thumbnail = val4.Thumbnail; rowValue.ObjectName = val4.ObjectName; s_externalPrefabs[s_persistentRegisteredId] = val3; } } else { hashSet.Add(s_persistentRegisteredId); num4++; } } foreach (string item in hashSet) { s_persistentRegisteredIds.Remove(item); } foreach (var item2 in LoadExternalPrefabs()) { try { string text = MakeId(item2.Item1, ((Object)item2.Item2).name); DMEditorObjectRow rowValue2 = ((DataTable)(object)editor.editorObjectTable).GetRowValue(text); if (!s_registeredIds.Contains(text) && rowValue2 == null) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item2.Item1); DMEditorObjectRow val5 = CreateRow(item2.Item2, fileNameWithoutExtension, text, item2.Item1); if (val5 != null) { ((DataTable)(object)editor.editorObjectTable).AddRow(text, val5); s_registeredIds.Add(text); s_persistentRegisteredIds.Add(text); s_externalPrefabs[text] = item2.Item2; SavePrefabToFile(text, item2.Item2); num2++; } } else { if (rowValue2 == null) { continue; } if (!s_registeredIds.Contains(text)) { s_registeredIds.Add(text); } if ((Object)rowValue2.EditorObject == (Object)null || (Object)rowValue2.GameObject == (Object)null) { string originalModelPath3 = GetOriginalModelPath(text); string text2 = ((!string.IsNullOrEmpty(originalModelPath3)) ? Path.GetFileNameWithoutExtension(originalModelPath3) : ((Object)item2.Item2).name); DMEditorObjectRow val6 = CreateRow(item2.Item2, text2, text, item2.Item1); if (val6 != null) { rowValue2.EditorObject = val6.EditorObject; rowValue2.GameObject = val6.GameObject; rowValue2.Thumbnail = val6.Thumbnail; rowValue2.ObjectName = val6.ObjectName; s_externalPrefabs[text] = item2.Item2; Debug.Log((object)("[ExternalModelRegistry] 恢复外部模型引用: " + text + " - " + text2)); } } continue; } } catch (Exception ex) { Debug.LogError((object)("[ExternalModelRegistry] Failed to register prefab into editor: " + ex)); } } if (hashSet.Count > 0) { SavePersistentRegistryState(); } if (num2 > 0 || num3 > 0 || num4 > 0 || num > 0) { Debug.Log((object)$"[ExternalModelRegistry] Registered {num2} new, restored {num3} missing, removed {num4} invalid external prefabs, merged {num} embedded objects"); } return num2 + num3 + num; } public static int RegisterIntoSpawnLevel(SpawnLevel spawnLevel) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown if ((Object)spawnLevel == (Object)null) { return 0; } FieldInfo field = typeof(SpawnLevel).GetField("editorObjectTable", BindingFlags.Instance | BindingFlags.NonPublic); if (field == null) { Debug.LogError((object)"[ExternalModelRegistry] Could not find SpawnLevel.editorObjectTable field"); return 0; } DMEditorObjectTable dMEditorObjectTable = null; ref DMEditorObjectTable reference = ref dMEditorObjectTable; object value = field.GetValue(spawnLevel); reference = (DMEditorObjectTable)((value is DMEditorObjectTable) ? value : null); if ((Object)dMEditorObjectTable == (Object)null) { Debug.LogError((object)"[ExternalModelRegistry] SpawnLevel.editorObjectTable is null"); return 0; } int embeddedCount = 0; try { DMEditorObjectTable val = LoadEmbeddedObjectTable(); if ((Object)val != (Object)null) { ((DataTable)(object)val).ForEachRow((Action)delegate(string key, DMEditorObjectRow row) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown try { DMEditorObjectRow rowValue = ((DataTable)(object)dMEditorObjectTable).GetRowValue(key); if (rowValue == null) { ((DataTable)(object)dMEditorObjectTable).AddRow(key, row); embeddedCount++; Debug.Log((object)("[ExternalModelRegistry] 合并嵌入式对象到SpawnLevel: " + key + " - " + row.ObjectName)); } else if (((Object)rowValue.EditorObject == (Object)null || (Object)rowValue.GameObject == (Object)null) && (Object)row.EditorObject != (Object)null && (Object)row.GameObject != (Object)null) { rowValue.EditorObject = row.EditorObject; rowValue.GameObject = row.GameObject; embeddedCount++; Debug.Log((object)("[ExternalModelRegistry] 恢复SpawnLevel中嵌入式对象的引用: " + key)); } } catch (Exception arg2) { Debug.LogError((object)$"[ExternalModelRegistry] 合并嵌入式对象到SpawnLevel失败 {key}: {arg2}"); } }); } } catch (Exception arg) { Debug.LogError((object)$"[ExternalModelRegistry] 合并嵌入式表格到SpawnLevel失败: {arg}"); } int num = 0; foreach (var item in LoadExternalPrefabs()) { try { string text = MakeId(item.Item1, ((Object)item.Item2).name); MethodInfo method = typeof(DMEditorObjectTable).GetMethod("GetRowValue", BindingFlags.Instance | BindingFlags.Public); if (((method != null) ? method.Invoke(dMEditorObjectTable, new object[1] { text }) : null) == null) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item.Item1); DMEditorObjectRow val2 = CreateRowForSpawnLevel(item.Item2, fileNameWithoutExtension, text); if (val2 != null) { ((DataTable)(object)dMEditorObjectTable).AddRow(text, val2); s_registeredIds.Add(text); s_externalPrefabs[text] = item.Item2; Debug.Log((object)("[ExternalModelRegistry] Stored prefab reference for id: " + text + ", prefab: " + fileNameWithoutExtension)); num++; } } } catch (Exception ex) { Debug.LogError((object)("[ExternalModelRegistry] Failed to register prefab into SpawnLevel: " + ex)); } } Debug.Log((object)$"[ExternalModelRegistry] Registered {num} external prefabs, merged {embeddedCount} embedded objects into SpawnLevel table"); return num + embeddedCount; } private static DMEditorObjectRow CreateRowForSpawnLevel(GameObject prefab, string displayName, string id) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0084: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00af: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown try { if ((Object)prefab == (Object)null) { return null; } string text = displayName; if (!string.IsNullOrWhiteSpace(text)) { if (text.Contains(".")) { text = Path.GetFileNameWithoutExtension(text); } } else { text = ((Object)prefab).name; if (text.Contains(".")) { text = Path.GetFileNameWithoutExtension(text); } } string text2 = Sanitize(text); if (string.IsNullOrWhiteSpace(text2)) { return null; } return new DMEditorObjectRow { ObjectName = text2, RadialMenuTheme = (RadialThemes)0, RadialMenuGroup = "Other", RadialMenuSlotName = text2, EditorObject = null, GameObject = null, Thumbnail = CreatePlaceholderSprite(), NormalizedSize = 1f, PivotOffset = Vector3.zero, InitialScale = 1f, InitialRotation = Vector3.zero, defaultSlopeAngle = 0f, IsEffect = false, CanSimulatePhysics = false }; } catch (Exception ex) { Debug.LogError((object)("[ExternalModelRegistry] Failed to create DMEditorObjectRow for SpawnLevel: " + ex)); return null; } } public static bool IsExternalModelId(string id) { if (string.IsNullOrEmpty(id)) { return false; } if (!id.StartsWith("mod.external.")) { return false; } if (s_negativeCache.Contains(id)) { return false; } bool flag = s_registeredIds.Contains(id); if (!flag) { flag = s_persistentRegisteredIds.Contains(id); if (flag) { s_registeredIds.Add(id); } else { s_negativeCache.Add(id); } } return flag; } public static GameObject GetExternalPrefabById(string id) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown if (s_externalPrefabs.TryGetValue(id, out var value) && (Object)value != (Object)null) { return value; } value = LoadPrefabFromFile(id); if ((Object)value != (Object)null) { s_externalPrefabs[id] = value; return value; } return null; } private static void SavePrefabToFile(string id, GameObject prefab) { try { if (!Directory.Exists(SaveModelPath)) { Directory.CreateDirectory(SaveModelPath); } string path = id + ".prefab"; Path.Combine(SaveModelPath, path); Debug.Log((object)("[ExternalModelRegistry] Saved prefab reference to memory for id: " + id)); } catch (Exception arg) { Debug.LogError((object)$"[ExternalModelRegistry] Failed to save prefab to file: {arg}"); } } private static GameObject LoadPrefabFromFile(string id) { try { string originalModelPath = GetOriginalModelPath(id); if (string.IsNullOrEmpty(originalModelPath)) { return null; } string text = Path.GetExtension(originalModelPath).ToLowerInvariant(); if (text == ".fbx") { return TryLoadFbxAsGameObject(originalModelPath); } if (text == ".obj") { return TryLoadObjAsGameObject(originalModelPath); } return null; } catch (Exception arg) { Debug.LogError((object)$"[ExternalModelRegistry] Failed to load prefab from file: {arg}"); return null; } } private static string GetOriginalModelPath(string id) { if (!id.StartsWith("mod.external.")) { return null; } if (s_pathNotFoundCache.Contains(id)) { return null; } if (s_pathCache.TryGetValue(id, out var value)) { return value; } string[] array = id.Substring("mod.external.".Length).Split(new char[1] { '.' }); if (array.Length >= 2) { string text = array[0]; string[] array2 = new string[5] { ".obj", ".fbx", ".bundle", ".ab", ".assetbundle" }; foreach (string text2 in array2) { string text3 = Path.Combine(Paths.PluginPath, "newmodel", text + text2); if (File.Exists(text3)) { s_pathCache[id] = text3; return text3; } } } s_pathNotFoundCache.Add(id); return null; } private static void SavePersistentRegistryState() { try { string contents = JsonUtility.ToJson((object)new RegistryState { RegisteredIds = s_persistentRegisteredIds.ToList(), Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }, true); File.WriteAllText(RegistryStatePath, contents); Debug.Log((object)$"[ExternalModelRegistry] Saved persistent registry state with {s_persistentRegisteredIds.Count} entries"); } catch (Exception arg) { Debug.LogError((object)$"[ExternalModelRegistry] Failed to save persistent registry state: {arg}"); } } private static void LoadPersistentRegistryState() { try { if (!File.Exists(RegistryStatePath)) { Debug.Log((object)"[ExternalModelRegistry] No persistent registry state file found"); return; } RegistryState registryState = JsonUtility.FromJson(File.ReadAllText(RegistryStatePath)); if (registryState?.RegisteredIds == null) { return; } s_persistentRegisteredIds.Clear(); foreach (string registeredId in registryState.RegisteredIds) { s_persistentRegisteredIds.Add(registeredId); } Debug.Log((object)$"[ExternalModelRegistry] Loaded persistent registry state with {s_persistentRegisteredIds.Count} entries from {registryState.Timestamp}"); } catch (Exception arg) { Debug.LogError((object)$"[ExternalModelRegistry] Failed to load persistent registry state: {arg}"); } } private static bool FileExistsForId(string id) { try { string originalModelPath = GetOriginalModelPath(id); return !string.IsNullOrEmpty(originalModelPath) && File.Exists(originalModelPath); } catch { return false; } } private static GameObject GetHiddenHolder() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown if ((Object)s_hiddenHolder == (Object)null) { s_hiddenHolder = new GameObject("ExternalModelHolder"); s_hiddenHolder.SetActive(false); Object.DontDestroyOnLoad((Object)s_hiddenHolder); } return s_hiddenHolder; } public static void ClearRegisteredIds() { s_registeredIds.Clear(); Debug.Log((object)"[ExternalModelRegistry] Cleared registered session IDs cache"); } private static DMEditorObjectRow CreateRow(GameObject prefab, string displayName, string id, string modelFilePath = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_0081: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: 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) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: 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_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Expected O, but got Unknown try { if ((Object)prefab == (Object)null) { return null; } string text = displayName; if (!string.IsNullOrWhiteSpace(text)) { if (text.Contains(".")) { text = Path.GetFileNameWithoutExtension(text); } } else { text = ((Object)prefab).name; if (text.Contains(".")) { text = Path.GetFileNameWithoutExtension(text); } } string text2 = Sanitize(text); if (string.IsNullOrWhiteSpace(text2)) { return null; } Sprite val = LoadThumbnailFromPng(modelFilePath); if ((Object)val == (Object)null) { val = CreatePlaceholderSprite(); } return new DMEditorObjectRow { ObjectName = text2, RadialMenuTheme = (RadialThemes)0, RadialMenuGroup = "Other", RadialMenuSlotName = text2, EditorObject = prefab, GameObject = prefab, Thumbnail = val, NormalizedSize = 1f, PivotOffset = Vector3.zero, InitialScale = 1f, InitialRotation = Vector3.zero, defaultSlopeAngle = 0f, IsEffect = false, CanSimulatePhysics = false }; } catch (Exception ex) { Debug.LogError((object)("[ExternalModelRegistry] Failed to create DMEditorObjectRow: " + ex)); return null; } } private static Sprite LoadThumbnailFromPng(string modelFilePath) { //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown if (string.IsNullOrEmpty(modelFilePath) || !File.Exists(modelFilePath)) { return null; } try { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(modelFilePath); if (string.IsNullOrEmpty(fileNameWithoutExtension)) { return null; } string directoryName = Path.GetDirectoryName(modelFilePath); if (string.IsNullOrEmpty(directoryName) || !Directory.Exists(directoryName)) { return null; } string text = Path.Combine(directoryName, fileNameWithoutExtension + ".png"); if (!File.Exists(text)) { string[] files = Directory.GetFiles(directoryName, "*.png", SearchOption.TopDirectoryOnly); foreach (string text2 in files) { if (string.Equals(Path.GetFileNameWithoutExtension(text2), fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase)) { text = text2; break; } } if (!File.Exists(text)) { return null; } } byte[] array = File.ReadAllBytes(text); if (array == null || array.Length == 0) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, array)) { Object.Destroy((Object)val); return null; } Sprite result = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); Debug.Log((object)("[ExternalModelRegistry] Loaded thumbnail from PNG: " + text)); return result; } catch (Exception ex) { Debug.LogWarning((object)("[ExternalModelRegistry] Failed to load thumbnail PNG for " + modelFilePath + ": " + ex.Message)); return null; } } private static GameObject TryLoadFbxAsGameObject(string fbxPath) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown try { GameObject val = TryLoadFbxWithAssetDatabase(fbxPath); if ((Object)val != (Object)null) { Debug.Log((object)("[ExternalModelRegistry] Successfully loaded FBX using AssetDatabase: " + fbxPath)); AddCollidersToAllMeshes(val); val.transform.SetParent(GetHiddenHolder().transform); return val; } val = TryLoadFbxWithReflection(fbxPath); if ((Object)val != (Object)null) { Debug.Log((object)("[ExternalModelRegistry] Successfully loaded FBX using reflection: " + fbxPath)); AddCollidersToAllMeshes(val); val.transform.SetParent(GetHiddenHolder().transform); return val; } Debug.LogWarning((object)("[ExternalModelRegistry] FBX文件无法在运行时直接加载。\n原因:Unity需要先将FBX文件通过导入管道处理才能使用,而导入管道只在编辑器中可用。\n解决方案(任选其一):\n1. 将FBX转换为AssetBundle格式:在Unity编辑器中导出为 .bundle/.ab/.assetbundle 文件\n2. 将FBX转换为OBJ格式:使用Blender、3ds Max等工具导出为 .obj 文件\n文件路径: " + fbxPath)); return null; } catch (Exception ex) { Debug.LogError((object)("[ExternalModelRegistry] FBX load error: " + fbxPath + " :: " + ex)); return null; } } private static GameObject TryLoadFbxWithAssetDatabase(string fbxPath) { //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Expected O, but got Unknown try { Type type = Type.GetType("UnityEditor.AssetDatabase, UnityEditor"); if (type == null) { return null; } MethodInfo method = type.GetMethod("LoadAssetAtPath", new Type[2] { typeof(string), typeof(Type) }); if (method == null) { return null; } string text = fbxPath; if (fbxPath.Contains("Assets")) { int startIndex = fbxPath.IndexOf("Assets"); text = fbxPath.Substring(startIndex); } else { string pluginPath = Paths.PluginPath; if (fbxPath.StartsWith(pluginPath)) { DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(fbxPath)); while (directoryInfo != null && directoryInfo.Exists) { DirectoryInfo directoryInfo2 = directoryInfo.GetDirectories("Assets").FirstOrDefault(); if (directoryInfo2 != null) { text = "Assets" + fbxPath.Substring(directoryInfo2.Parent.FullName.Length).Replace('\\', '/'); break; } directoryInfo = directoryInfo.Parent; } } } object obj = method.Invoke(null, new object[2] { text, typeof(GameObject) }); return (GameObject)((obj is GameObject) ? obj : null); } catch (Exception) { return null; } } private static GameObject TryLoadFbxWithReflection(string fbxPath) { try { _ = (from a in AppDomain.CurrentDomain.GetAssemblies() select a.GetType("UnityEditor.ModelImporter", throwOnError: false)).FirstOrDefault((Type t) => t != null) == null; return null; } catch { return null; } } private static void AddCollidersToAllMeshes(GameObject root) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown if ((Object)root == (Object)null) { return; } MeshFilter[] componentsInChildren = root.GetComponentsInChildren(true); int num = 0; MeshFilter[] array = componentsInChildren; foreach (MeshFilter val in array) { if (!((Object)val == (Object)null) && !((Object)val.sharedMesh == (Object)null) && !((Object)((Component)val).GetComponent() != (Object)null)) { MeshCollider obj = ((Component)val).gameObject.AddComponent(); obj.sharedMesh = val.sharedMesh; obj.convex = false; num++; } } if (num > 0) { Debug.Log((object)$"[ExternalModelRegistry] Added {num} MeshColliders to {((Object)root).name} and its children"); } } private static DMEditorObjectTable LoadEmbeddedObjectTable() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Expected O, but got Unknown //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Expected O, but got Unknown //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Expected O, but got Unknown if ((Object)s_cachedEmbeddedTable != (Object)null) { Debug.Log((object)"[ExternalModelRegistry] 使用缓存的嵌入式DMEditorObjectTable"); return s_cachedEmbeddedTable; } try { if ((Object)s_cachedEmbeddedBundle != (Object)null) { DMEditorObjectTable val = s_cachedEmbeddedBundle.LoadAsset("newmodel"); if ((Object)val == (Object)null) { val = s_cachedEmbeddedBundle.LoadAsset("newmodel.asset"); if ((Object)val == (Object)null) { DMEditorObjectTable[] array = s_cachedEmbeddedBundle.LoadAllAssets(); if (array != null && array.Length != 0) { val = array[0]; } } } if ((Object)val != (Object)null) { s_cachedEmbeddedTable = val; Debug.Log((object)"[ExternalModelRegistry] 从缓存的AssetBundle加载嵌入式DMEditorObjectTable"); return val; } } using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("model"); if (stream == null) { Debug.LogWarning((object)"[ExternalModelRegistry] 找不到嵌入式资源: model"); return null; } byte[] array2 = new byte[stream.Length]; stream.Read(array2, 0, array2.Length); AssetBundle val2 = AssetBundle.GetAllLoadedAssetBundles().FirstOrDefault((Func)((AssetBundle b) => ((Object)b).name == "Memory" || ((Object)b).name == "")); if ((Object)val2 != (Object)null) { Debug.Log((object)"[ExternalModelRegistry] 检测到已加载的AssetBundle,尝试重用"); s_cachedEmbeddedBundle = val2; } else { AssetBundle val3 = AssetBundle.LoadFromMemory(array2); if ((Object)val3 == (Object)null) { Debug.LogError((object)"[ExternalModelRegistry] 无法从嵌入式资源加载AssetBundle: model"); return null; } s_cachedEmbeddedBundle = val3; } DMEditorObjectTable val4 = s_cachedEmbeddedBundle.LoadAsset("newmodel"); if ((Object)val4 == (Object)null) { val4 = s_cachedEmbeddedBundle.LoadAsset("newmodel.asset"); if ((Object)val4 == (Object)null) { DMEditorObjectTable[] array3 = s_cachedEmbeddedBundle.LoadAllAssets(); if (array3 != null && array3.Length != 0) { val4 = array3[0]; Debug.Log((object)$"[ExternalModelRegistry] 找到 {array3.Length} 个DMEditorObjectTable,使用第一个"); } } } if ((Object)val4 != (Object)null) { s_cachedEmbeddedTable = val4; Debug.Log((object)"[ExternalModelRegistry] 成功加载并缓存嵌入式DMEditorObjectTable: newmodel"); } else { Debug.LogWarning((object)"[ExternalModelRegistry] AssetBundle中未找到DMEditorObjectTable资源: newmodel"); string[] allAssetNames = s_cachedEmbeddedBundle.GetAllAssetNames(); Debug.Log((object)("[ExternalModelRegistry] AssetBundle包含的资源: " + string.Join(", ", allAssetNames))); } return s_cachedEmbeddedTable; } catch (Exception arg) { Debug.LogError((object)$"[ExternalModelRegistry] 加载嵌入式资源失败: {arg}"); return null; } } private static int MergeEmbeddedTableIntoEditor(DMEditor editor) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown int mergedCount = 0; int restoredCount = 0; try { DMEditorObjectTable val = LoadEmbeddedObjectTable(); if ((Object)val == (Object)null) { return 0; } ((DataTable)(object)val).ForEachRow((Action)delegate(string key, DMEditorObjectRow row) { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Expected O, but got Unknown //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Expected O, but got Unknown try { DMEditorObjectRow rowValue = ((DataTable)(object)editor.editorObjectTable).GetRowValue(key); if (rowValue == null) { ((DataTable)(object)editor.editorObjectTable).AddRow(key, row); if (!s_registeredIds.Contains(key)) { s_registeredIds.Add(key); } mergedCount++; Debug.Log((object)("[ExternalModelRegistry] 合并嵌入式对象: " + key + " - " + row.ObjectName)); } else { if (!s_registeredIds.Contains(key)) { s_registeredIds.Add(key); } if ((Object)rowValue.EditorObject == (Object)null || (Object)rowValue.GameObject == (Object)null) { if ((Object)row.EditorObject != (Object)null && (Object)row.GameObject != (Object)null) { rowValue.EditorObject = row.EditorObject; rowValue.GameObject = row.GameObject; restoredCount++; Debug.Log((object)("[ExternalModelRegistry] 恢复嵌入式对象的EditorObject引用: " + key + " - " + row.ObjectName)); } else { Debug.LogWarning((object)("[ExternalModelRegistry] 嵌入式对象 " + key + " 的EditorObject引用为null,无法恢复")); } } } } catch (Exception arg2) { Debug.LogError((object)$"[ExternalModelRegistry] 合并对象失败 {key}: {arg2}"); } }); if (mergedCount > 0 || restoredCount > 0) { Debug.Log((object)$"[ExternalModelRegistry] 成功合并 {mergedCount} 个嵌入式对象,恢复 {restoredCount} 个对象的引用到编辑器表格"); } } catch (Exception arg) { Debug.LogError((object)$"[ExternalModelRegistry] 合并嵌入式表格失败: {arg}"); } return mergedCount + restoredCount; } public static int RestoreEmbeddedModelReferences(DMEditor editor) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown int restoredCount = 0; try { DMEditorObjectTable embeddedTable = LoadEmbeddedObjectTable(); if ((Object)embeddedTable == (Object)null) { Debug.LogWarning((object)"[ExternalModelRegistry] 无法加载嵌入式表格,无法恢复引用"); return 0; } HashSet embeddedKeys = new HashSet(); ((DataTable)(object)embeddedTable).ForEachRow((Action)delegate(string key, DMEditorObjectRow row) { embeddedKeys.Add(key); }); ((DataTable)(object)editor.editorObjectTable).ForEachRow((Action)delegate(string key, DMEditorObjectRow row) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown if (embeddedKeys.Contains(key) && ((Object)row.EditorObject == (Object)null || (Object)row.GameObject == (Object)null)) { DMEditorObjectRow rowValue = ((DataTable)(object)embeddedTable).GetRowValue(key); if (rowValue != null && (Object)rowValue.EditorObject != (Object)null && (Object)rowValue.GameObject != (Object)null) { row.EditorObject = rowValue.EditorObject; row.GameObject = rowValue.GameObject; restoredCount++; Debug.Log((object)("[ExternalModelRegistry] 恢复嵌入式模型引用: " + key + " - " + row.ObjectName)); } else { Debug.LogWarning((object)("[ExternalModelRegistry] 无法恢复嵌入式模型引用,嵌入式表格中的引用也为null: " + key)); } } }); if (restoredCount > 0) { Debug.Log((object)$"[ExternalModelRegistry] 成功恢复 {restoredCount} 个嵌入式模型的EditorObject引用"); } } catch (Exception arg) { Debug.LogError((object)$"[ExternalModelRegistry] 恢复嵌入式模型引用失败: {arg}"); } return restoredCount; } } public static class ExternalWeatherManager { private static Dictionary s_externalWeatherPrefabs = new Dictionary(); private static List s_loadedExternalWeathers = new List(); private static bool s_isInitialized = false; private static AssetBundle s_weatherAssetBundle = null; public static void Initialize() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown if (s_isInitialized) { return; } s_externalWeatherPrefabs.Clear(); if (!LoadFromEmbeddedResources("Mod_Name.weather")) { GameObject[] array = Resources.LoadAll("weather"); foreach (GameObject val in array) { if ((Object)val != (Object)null) { s_externalWeatherPrefabs[((Object)val).name] = val; } } } s_isInitialized = true; } public static List GetExternalWeatherNames() { Initialize(); return new List(s_externalWeatherPrefabs.Keys); } public static void InstantiateExternalWeathers(Transform weatherParent) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown Initialize(); foreach (GameObject s_loadedExternalWeather in s_loadedExternalWeathers) { if ((Object)s_loadedExternalWeather != (Object)null) { Object.Destroy((Object)s_loadedExternalWeather); } } s_loadedExternalWeathers.Clear(); foreach (KeyValuePair s_externalWeatherPrefab in s_externalWeatherPrefabs) { GameObject val = Object.Instantiate(s_externalWeatherPrefab.Value, weatherParent); ((Object)val).name = s_externalWeatherPrefab.Key; val.SetActive(false); s_loadedExternalWeathers.Add(val); } } public static bool HasExternalWeathers() { Initialize(); return s_externalWeatherPrefabs.Count > 0; } public static int GetExternalWeatherCount() { Initialize(); return s_externalWeatherPrefabs.Count; } private static bool LoadFromEmbeddedResources(string resourceName) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown try { Assembly executingAssembly = Assembly.GetExecutingAssembly(); Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(resourceName); if (manifestResourceStream == null) { string[] manifestResourceNames = executingAssembly.GetManifestResourceNames(); foreach (string text in manifestResourceNames) { if (text.Contains("weather") || text.EndsWith(".weather") || text.EndsWith("weather")) { manifestResourceStream = executingAssembly.GetManifestResourceStream(text); if (manifestResourceStream != null) { resourceName = text; break; } } } } if (manifestResourceStream != null) { using (manifestResourceStream) { byte[] array = new byte[manifestResourceStream.Length]; manifestResourceStream.Read(array, 0, array.Length); s_weatherAssetBundle = AssetBundle.LoadFromMemory(array); if ((Object)s_weatherAssetBundle != (Object)null) { GameObject[] array2 = s_weatherAssetBundle.LoadAllAssets(); foreach (GameObject val in array2) { if ((Object)val != (Object)null) { s_externalWeatherPrefabs[((Object)val).name] = val; } } return true; } } } } catch (Exception ex) { Debug.LogWarning((object)("[ExternalWeatherManager] 从DLL内部资源加载失败: " + ex.Message)); } return false; } public static void Cleanup() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown if ((Object)s_weatherAssetBundle != (Object)null) { s_weatherAssetBundle.Unload(false); s_weatherAssetBundle = null; } s_externalWeatherPrefabs.Clear(); s_isInitialized = false; } } public class FilterListItem : MonoBehaviour { private PostProcessProfile m_profile; private FilterMenu m_menu; private Button m_button; private Text m_nameText; public void Initialize(PostProcessProfile profile, FilterMenu menu) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown m_profile = profile; m_menu = menu; m_button = ((Component)this).GetComponent