diff --git a/AxibugEmuOnline.Client/Assets/AxiProjectTools/Editors/AxiProjectTools.cs b/AxibugEmuOnline.Client/Assets/AxiProjectTools/Editors/AxiProjectTools.cs index eae87d5..740bb4c 100644 --- a/AxibugEmuOnline.Client/Assets/AxiProjectTools/Editors/AxiProjectTools.cs +++ b/AxibugEmuOnline.Client/Assets/AxiProjectTools/Editors/AxiProjectTools.cs @@ -8,85 +8,85 @@ using UnityEngine; public class AxiProjectTools : EditorWindow { - static string cachecfgPath = "Assets/AxiComToolCache.asset"; - static string toolSenceName = "AxiProjectTools"; - static string outCsDir = Application.dataPath + "/AxiCom/"; - static Dictionary ComType2GUID = new Dictionary(); + static string cachecfgPath = "Assets/AxiComToolCache.asset"; + static string toolSenceName = "AxiProjectTools"; + static string outCsDir = Application.dataPath + "/AxiCom/"; + static Dictionary ComType2GUID = new Dictionary(); - static void GoTAxiProjectToolsSence() - { - string[] sceneGuids = AssetDatabase.FindAssets("t:scene"); - foreach (string guid in sceneGuids) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - if (path.Contains(toolSenceName)) - { - EditorSceneManager.OpenScene(path); - return; - } - } - } + static void GoTAxiProjectToolsSence() + { + string[] sceneGuids = AssetDatabase.FindAssets("t:scene"); + foreach (string guid in sceneGuids) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + if (path.Contains(toolSenceName)) + { + EditorSceneManager.OpenScene(path); + return; + } + } + } - [MenuItem("Axibug移植工具/[1]采集所有预制体和场景下的UGUI组件")] - public static void Part1() - { - GoTAxiProjectToolsSence(); - ComType2GUID.Clear(); - string[] sceneGuids = AssetDatabase.FindAssets("t:scene"); - foreach (string guid in sceneGuids) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - if (path.Contains(toolSenceName)) - continue; + [MenuItem("Axibug移植工具/[1]采集所有预制体和场景下的UGUI组件")] + public static void Part1() + { + GoTAxiProjectToolsSence(); + ComType2GUID.Clear(); + string[] sceneGuids = AssetDatabase.FindAssets("t:scene"); + foreach (string guid in sceneGuids) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + if (path.Contains(toolSenceName)) + continue; - EditorSceneManager.OpenScene(path); + EditorSceneManager.OpenScene(path); - // 创建一个列表来存储根节点 - List rootNodes = new List(); + // 创建一个列表来存储根节点 + List rootNodes = new List(); - // 遍历场景中的所有对象 - GameObject[] allObjects = FindObjectsOfType(); - foreach (GameObject obj in allObjects) - { - // 检查对象是否有父对象 - if (obj.transform.parent == null) - { - // 如果没有父对象,则它是一个根节点 - rootNodes.Add(obj); - } - } + // 遍历场景中的所有对象 + GameObject[] allObjects = FindObjectsOfType(); + foreach (GameObject obj in allObjects) + { + // 检查对象是否有父对象 + if (obj.transform.parent == null) + { + // 如果没有父对象,则它是一个根节点 + rootNodes.Add(obj); + } + } - foreach (var node in rootNodes) - LoopPrefabNode(path, node, 0); - } + foreach (var node in rootNodes) + LoopPrefabNode(path, node, 0); + } - string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab"); - foreach (string guid in prefabGuids) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - GetPrefab(path); - } + string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab"); + foreach (string guid in prefabGuids) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + GetPrefab(path); + } - AxiPrefabCache cache = ScriptableObject.CreateInstance(); - foreach (var data in ComType2GUID) - cache.caches.Add(data.Value); - AssetDatabase.CreateAsset(cache, cachecfgPath); - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - GoTAxiProjectToolsSence(); - Debug.Log("处理完毕 [1]采集所有预制体和场景下的UGUI组件"); - } - - static void GetPrefab(string path) - { - GameObject prefab = AssetDatabase.LoadAssetAtPath(path); - LoopPrefabNode(path, prefab.gameObject, 0); - } - static void LoopPrefabNode(string rootPath, GameObject trans, int depth) - { - string nodename = $"{rootPath}>{trans.name}"; + AxiPrefabCache cache = ScriptableObject.CreateInstance(); + foreach (var data in ComType2GUID) + cache.caches.Add(data.Value); + AssetDatabase.CreateAsset(cache, cachecfgPath); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + GoTAxiProjectToolsSence(); + Debug.Log("处理完毕 [1]采集所有预制体和场景下的UGUI组件"); + } + static void GetPrefab(string path) + { + GameObject prefab = AssetDatabase.LoadAssetAtPath(path); + LoopPrefabNode(path, prefab.gameObject, 0); + } + static void LoopPrefabNode(string rootPath, GameObject trans, int depth) + { + string nodename = $"{rootPath}>{trans.name}"; +#if UNITY_5_4_OR_NEWER && !UNITY_2018_4_OR_NEWER GameObject prefabRoot = trans.gameObject; int comCount = prefabRoot.GetComponentCount(); for (int i = 0; i < comCount; i++) @@ -130,250 +130,253 @@ public class AxiProjectTools : EditorWindow //遍历 foreach (Transform child in trans.transform) LoopPrefabNode(nodename, child.gameObject, depth + 1); - } +#else + Debug.Log("低版本不要执行本函数"); +#endif + } - [MenuItem("Axibug移植工具/[2]生成中间脚本代码")] - public static void Part2() - { - if (UnityEngine.Windows.Directory.Exists(outCsDir)) - UnityEngine.Windows.Directory.Delete(outCsDir); - Directory.CreateDirectory(outCsDir); - AxiPrefabCache cache = AssetDatabase.LoadAssetAtPath(cachecfgPath); - foreach (var data in cache.caches) - { - string toName = "Axi" + data.SrcName; - string toPath = outCsDir + toName + ".cs"; - string codeStr = "namespace AxibugCom { public class " + toName + " : " + data.SrcFullName + " {} }"; - try - { - System.IO.File.WriteAllText(toPath, codeStr); - data.ToName = toName; - data.ToPATH = toPath; - } - catch (Exception ex) - { - Debug.LogError("写入失败" + ex.ToString()); - } - } - Debug.Log("写入完毕"); - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - Debug.Log("处理完毕 [2]生成中间脚本代码"); - } + [MenuItem("Axibug移植工具/[2]生成中间脚本代码")] + public static void Part2() + { + if (UnityEngine.Windows.Directory.Exists(outCsDir)) + UnityEngine.Windows.Directory.Delete(outCsDir); + Directory.CreateDirectory(outCsDir); + AxiPrefabCache cache = AssetDatabase.LoadAssetAtPath(cachecfgPath); + foreach (var data in cache.caches) + { + string toName = "Axi" + data.SrcName; + string toPath = outCsDir + toName + ".cs"; + string codeStr = "namespace AxibugCom { public class " + toName + " : " + data.SrcFullName + " {} }"; + try + { + System.IO.File.WriteAllText(toPath, codeStr); + data.ToName = toName; + data.ToPATH = toPath; + } + catch (Exception ex) + { + Debug.LogError("写入失败" + ex.ToString()); + } + } + Debug.Log("写入完毕"); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + Debug.Log("处理完毕 [2]生成中间脚本代码"); + } - [MenuItem("Axibug移植工具/[3]收集生成的脚本")] - public static void Part3() - { - AxiPrefabCache cache = AssetDatabase.LoadAssetAtPath(cachecfgPath); - List allMonoScripts = FindAllAssetsOfType(); - foreach (var data in cache.caches) - { - MonoScript monoScript = allMonoScripts.FirstOrDefault(w => w.name == data.ToName); - if (monoScript == null) - { - Debug.LogError("没找到" + data.ToName); - continue; - } - string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(monoScript)); - data.ToGUID = guid; - data.monoScript = monoScript; - } - Debug.Log("写入完毕"); - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - Debug.Log("处理完毕 [3]收集生成的脚本"); - } + [MenuItem("Axibug移植工具/[3]收集生成的脚本")] + public static void Part3() + { + AxiPrefabCache cache = AssetDatabase.LoadAssetAtPath(cachecfgPath); + List allMonoScripts = FindAllAssetsOfType(); + foreach (var data in cache.caches) + { + MonoScript monoScript = allMonoScripts.FirstOrDefault(w => w.name == data.ToName); + if (monoScript == null) + { + Debug.LogError("没找到" + data.ToName); + continue; + } + string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(monoScript)); + data.ToGUID = guid; + data.monoScript = monoScript; + } + Debug.Log("写入完毕"); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + Debug.Log("处理完毕 [3]收集生成的脚本"); + } - static List FindAllAssetsOfType() where T : UnityEngine.Object - { - List assets = new List(); + static List FindAllAssetsOfType() where T : UnityEngine.Object + { + List assets = new List(); - string[] allGuids = AssetDatabase.FindAssets(""); - foreach (string guid in allGuids) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - if (path.EndsWith(".cs") || path.EndsWith(".js") || path.EndsWith(".boo")) // Unity支持多种脚本语言,但现代Unity主要使用C# - { - T asset = AssetDatabase.LoadAssetAtPath(path); - if (asset != null) - { - assets.Add(asset); - } - } - } - return assets; - } + string[] allGuids = AssetDatabase.FindAssets(""); + foreach (string guid in allGuids) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + if (path.EndsWith(".cs") || path.EndsWith(".js") || path.EndsWith(".boo")) // Unity支持多种脚本语言,但现代Unity主要使用C# + { + T asset = AssetDatabase.LoadAssetAtPath(path); + if (asset != null) + { + assets.Add(asset); + } + } + } + return assets; + } - [MenuItem("Axibug移植工具/[4]替换所有预制体和场景中的组件")] - public static void Part4() - { - AxiPrefabCache cache = AssetDatabase.LoadAssetAtPath(cachecfgPath); - Dictionary tempReplaceDict = new Dictionary(); - foreach (var data in cache.caches) - { - tempReplaceDict[data.GUID] = data.ToGUID; - } - ProcessAllPrefabs("*.prefab", tempReplaceDict); - ProcessAllPrefabs("*.unity", tempReplaceDict); - ProcessAllPrefabs("*.anim", tempReplaceDict); - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - Debug.Log("处理完毕 [4]替换所有预制体和场景中的组件"); - } + [MenuItem("Axibug移植工具/[4]替换所有预制体和场景中的组件")] + public static void Part4() + { + AxiPrefabCache cache = AssetDatabase.LoadAssetAtPath(cachecfgPath); + Dictionary tempReplaceDict = new Dictionary(); + foreach (var data in cache.caches) + { + tempReplaceDict[data.GUID] = data.ToGUID; + } + ProcessAllPrefabs("*.prefab", tempReplaceDict); + ProcessAllPrefabs("*.unity", tempReplaceDict); + ProcessAllPrefabs("*.anim", tempReplaceDict); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + Debug.Log("处理完毕 [4]替换所有预制体和场景中的组件"); + } - static void ProcessAllPrefabs(string form, Dictionary tempReplaceDict, bool reverse = false) - { - List prefabs = new List(); - var resourcesPath = Application.dataPath; - var absolutePaths = Directory.GetFiles(resourcesPath, form, SearchOption.AllDirectories); - for (int i = 0; i < absolutePaths.Length; i++) - { - Debug.Log("prefab name: " + absolutePaths[i]); - foreach (var VARIABLE in tempReplaceDict) - { - string oldValue = reverse ? VARIABLE.Value : VARIABLE.Key; - string newValue = reverse ? VARIABLE.Key : VARIABLE.Value; - ReplaceValue(absolutePaths[i], oldValue, newValue); - } - EditorUtility.DisplayProgressBar("处理预制体……", "处理预制体中……", (float)i / absolutePaths.Length); - } - EditorUtility.ClearProgressBar(); - } + static void ProcessAllPrefabs(string form, Dictionary tempReplaceDict, bool reverse = false) + { + List prefabs = new List(); + var resourcesPath = Application.dataPath; + var absolutePaths = Directory.GetFiles(resourcesPath, form, SearchOption.AllDirectories); + for (int i = 0; i < absolutePaths.Length; i++) + { + Debug.Log("prefab name: " + absolutePaths[i]); + foreach (var VARIABLE in tempReplaceDict) + { + string oldValue = reverse ? VARIABLE.Value : VARIABLE.Key; + string newValue = reverse ? VARIABLE.Key : VARIABLE.Value; + ReplaceValue(absolutePaths[i], oldValue, newValue); + } + EditorUtility.DisplayProgressBar("处理预制体……", "处理预制体中……", (float)i / absolutePaths.Length); + } + EditorUtility.ClearProgressBar(); + } - /// - /// 替换值 - /// - /// 文件路径 - static void ReplaceValue(string strFilePath, string oldLine, string newLine) - { - if (File.Exists(strFilePath)) - { - string[] lines = File.ReadAllLines(strFilePath); - for (int i = 0; i < lines.Length; i++) - { - lines[i] = lines[i].Replace(oldLine, newLine); - } - File.WriteAllLines(strFilePath, lines); - } - } + /// + /// 替换值 + /// + /// 文件路径 + static void ReplaceValue(string strFilePath, string oldLine, string newLine) + { + if (File.Exists(strFilePath)) + { + string[] lines = File.ReadAllLines(strFilePath); + for (int i = 0; i < lines.Length; i++) + { + lines[i] = lines[i].Replace(oldLine, newLine); + } + File.WriteAllLines(strFilePath, lines); + } + } - [MenuItem("Axibug移植工具/[5]UnPack所有预制体")] - public static void UnpackPrefabs() - { + [MenuItem("Axibug移植工具/[5]UnPack所有预制体")] + public static void UnpackPrefabs() + { - string[] allAssetPaths = AssetDatabase.GetAllAssetPaths(); - int prefabCount = 0; + string[] allAssetPaths = AssetDatabase.GetAllAssetPaths(); + int prefabCount = 0; - foreach (string path in allAssetPaths) - { - if (Path.GetExtension(path).Equals(".prefab")) - { - Debug.Log($"Unpacking {path}"); - UnpackPrefab(path); - prefabCount++; - } - } - Debug.Log($"Unpacked {prefabCount} prefabs."); + foreach (string path in allAssetPaths) + { + if (Path.GetExtension(path).Equals(".prefab")) + { + Debug.Log($"Unpacking {path}"); + UnpackPrefab(path); + prefabCount++; + } + } + Debug.Log($"Unpacked {prefabCount} prefabs."); - Debug.Log("处理完毕 [5]UnPack所有预制体"); - } + Debug.Log("处理完毕 [5]UnPack所有预制体"); + } - static void UnpackPrefab(string prefabPath) - { - GameObject prefabInstance = AssetDatabase.LoadAssetAtPath(prefabPath); - if (prefabInstance == null) - { - Debug.LogError($"Failed to load prefab at path: {prefabPath}"); - return; - } + static void UnpackPrefab(string prefabPath) + { + GameObject prefabInstance = AssetDatabase.LoadAssetAtPath(prefabPath); + if (prefabInstance == null) + { + Debug.LogError($"Failed to load prefab at path: {prefabPath}"); + return; + } - var obj = GameObject.Instantiate(prefabInstance, null); - TraverseHierarchy(obj); - PrefabUtility.SaveAsPrefabAsset(obj, prefabPath); - GameObject.DestroyImmediate(obj); - } + var obj = GameObject.Instantiate(prefabInstance, null); + TraverseHierarchy(obj); + PrefabUtility.SaveAsPrefabAsset(obj, prefabPath); + GameObject.DestroyImmediate(obj); + } - static void TraverseHierarchy(GameObject obj) - { - // 检查该对象是否是预制体的实例 - if (PrefabUtility.IsPartOfPrefabInstance(obj)) - { - // 将预制体实例转换为普通游戏对象 - PrefabUtility.UnpackPrefabInstance(obj, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); - Debug.Log("Prefab instance converted to game object: " + obj.name); - } + static void TraverseHierarchy(GameObject obj) + { + // 检查该对象是否是预制体的实例 + if (PrefabUtility.IsPartOfPrefabInstance(obj)) + { + // 将预制体实例转换为普通游戏对象 + PrefabUtility.UnpackPrefabInstance(obj, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); + Debug.Log("Prefab instance converted to game object: " + obj.name); + } - // 递归遍历子对象 - for (int i = 0; i < obj.transform.childCount; i++) - { - TraverseHierarchy(obj.transform.GetChild(i).gameObject); - } - } + // 递归遍历子对象 + for (int i = 0; i < obj.transform.childCount; i++) + { + TraverseHierarchy(obj.transform.GetChild(i).gameObject); + } + } - [MenuItem("Axibug移植工具/[6]修复Sprite")] - public static void FixMultipleMaterialSprites() - { - string[] guids = AssetDatabase.FindAssets("t:sprite"); - List spritesToFix = new List(); + [MenuItem("Axibug移植工具/[6]修复Sprite")] + public static void FixMultipleMaterialSprites() + { + string[] guids = AssetDatabase.FindAssets("t:sprite"); + List spritesToFix = new List(); - foreach (string guid in guids) - { - string path = AssetDatabase.GUIDToAssetPath(guid); - Sprite sprite = AssetDatabase.LoadAssetAtPath(path); + foreach (string guid in guids) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + Sprite sprite = AssetDatabase.LoadAssetAtPath(path); - // 检查是否有多个材质 - if (IsUsingMultipleMaterials(sprite)) - { - spritesToFix.Add(sprite); - Debug.Log("Found sprite with multiple materials: " + path); - } - } + // 检查是否有多个材质 + if (IsUsingMultipleMaterials(sprite)) + { + spritesToFix.Add(sprite); + Debug.Log("Found sprite with multiple materials: " + path); + } + } - // 修复每个找到的Sprite - foreach (var sprite in spritesToFix) - { - FixSprite(sprite); - } + // 修复每个找到的Sprite + foreach (var sprite in spritesToFix) + { + FixSprite(sprite); + } - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - Debug.Log("处理完毕 [6]修复Sprite"); - } + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + Debug.Log("处理完毕 [6]修复Sprite"); + } - private static bool IsUsingMultipleMaterials(Sprite sprite) - { - if (sprite == null) return false; + private static bool IsUsingMultipleMaterials(Sprite sprite) + { + if (sprite == null) return false; - // 获取精灵的材质 - var textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(sprite)) as TextureImporter; + // 获取精灵的材质 + var textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(sprite)) as TextureImporter; - return textureImporter != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple; - } + return textureImporter != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple; + } - private static void FixSprite(Sprite sprite) - { - // 获取Sprite的路径 - string path = AssetDatabase.GetAssetPath(sprite); - var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; + private static void FixSprite(Sprite sprite) + { + // 获取Sprite的路径 + string path = AssetDatabase.GetAssetPath(sprite); + var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; - if (textureImporter != null) - { - // 保存当前切割信息 - SpriteMetaData[] originalMetaData = textureImporter.spritesheet; + if (textureImporter != null) + { + // 保存当前切割信息 + SpriteMetaData[] originalMetaData = textureImporter.spritesheet; - // 临时禁用Sprite导入 - textureImporter.spriteImportMode = SpriteImportMode.None; - textureImporter.SaveAndReimport(); + // 临时禁用Sprite导入 + textureImporter.spriteImportMode = SpriteImportMode.None; + textureImporter.SaveAndReimport(); - // 重新启用Sprite导入并保持原样切割参数 - textureImporter.spriteImportMode = SpriteImportMode.Multiple; - textureImporter.spritesheet = originalMetaData; // 恢复原来的切割信息 + // 重新启用Sprite导入并保持原样切割参数 + textureImporter.spriteImportMode = SpriteImportMode.Multiple; + textureImporter.spritesheet = originalMetaData; // 恢复原来的切割信息 - // 重新导入以应用更改 - textureImporter.SaveAndReimport(); - } - } + // 重新导入以应用更改 + textureImporter.SaveAndReimport(); + } + } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/BLOCKHDR.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/BLOCKHDR.cs index f3aafa6..027cb5c 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/BLOCKHDR.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/BLOCKHDR.cs @@ -2,7 +2,7 @@ { public struct BLOCKHDR : IStateBufferObject { - public readonly bool Valid => !string.IsNullOrEmpty(ID); + public bool Valid => !string.IsNullOrEmpty(ID); /// 鎬绘槸8涓瓧鑺 public string ID; public ushort Reserved; @@ -11,12 +11,12 @@ - public readonly uint GetSize() + public uint GetSize() { return (uint)(8 + sizeof(ushort) + sizeof(ushort) + sizeof(uint)); } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { if (Valid) { diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/CTRSTAT.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/CTRSTAT.cs index 0f9e29d..ad7d1ec 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/CTRSTAT.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/CTRSTAT.cs @@ -8,12 +8,12 @@ public uint pad4bit; public byte strobe; - public readonly uint GetSize() + public uint GetSize() { return sizeof(uint) * 4 + sizeof(byte); } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { buffer.Write(pad1bit); buffer.Write(pad2bit); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/EXCTRSTAT.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/EXCTRSTAT.cs index 802a463..8484be4 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/EXCTRSTAT.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/EXCTRSTAT.cs @@ -4,12 +4,12 @@ { public uint data; - public readonly uint GetSize() + public uint GetSize() { return sizeof(uint); } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { buffer.Write(data); } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/FILEHDR2.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/FILEHDR2.cs index cf10d3e..4406ccb 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/FILEHDR2.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/FILEHDR2.cs @@ -14,12 +14,12 @@ - public readonly uint GetSize() + public uint GetSize() { return (uint)(ID.Length + sizeof(ushort) + sizeof(uint) + sizeof(ushort) + sizeof(ushort)); } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { buffer.Write(ID); buffer.Write(BlockVersion); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/MMCSTAT.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/MMCSTAT.cs index e23ed91..f761abe 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/MMCSTAT.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/MMCSTAT.cs @@ -9,12 +9,12 @@ return new MMCSTAT() { mmcdata = new byte[256] }; } - public readonly uint GetSize() + public uint GetSize() { return 256; } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { buffer.Write(mmcdata); } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/RAMSTAT.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/RAMSTAT.cs index 5d3929b..f4d4888 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/RAMSTAT.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/RAMSTAT.cs @@ -22,12 +22,12 @@ namespace VirtualNes.Core return res; } - public readonly uint GetSize() + public uint GetSize() { return (uint)(RAM.Length + BGPAL.Length + SPPAL.Length + SPRAM.Length); } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { buffer.Write(RAM); buffer.Write(BGPAL); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/REGSTAT.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/REGSTAT.cs index 13e0e8d..ecc6ec6 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/REGSTAT.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/REGSTAT.cs @@ -7,12 +7,12 @@ - public readonly uint GetSize() + public uint GetSize() { return cpureg.GetSize() + ppureg.GetSize(); } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { cpureg.SaveState(buffer); ppureg.SaveState(buffer); @@ -45,12 +45,12 @@ public long emul_cycles; public long base_cycles; - public readonly uint GetSize() + public uint GetSize() { return 32; } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { buffer.Write(PC); buffer.Write(A); @@ -102,12 +102,12 @@ public ushort loopy_v; public ushort loopy_x; - public readonly uint GetSize() + public uint GetSize() { return 12; } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { buffer.Write(reg0); buffer.Write(reg1); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/SNDSTAT.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/SNDSTAT.cs index f80a114..1cdef6e 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/SNDSTAT.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/SNDSTAT.cs @@ -9,12 +9,12 @@ return new SNDSTAT() { snddata = new byte[0x800] }; } - public readonly uint GetSize() + public uint GetSize() { return (uint)snddata.Length; } - public readonly void SaveState(StateBuffer buffer) + public void SaveState(StateBuffer buffer) { buffer.Write(snddata); } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs index 4038f60..9ff9d6e 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/State/State.cs @@ -36,7 +36,7 @@ namespace VirtualNes.Core public BLOCKHDR exctrBLOCK; public EXCTRSTAT exctr; - public readonly byte[] ToBytes() + public byte[] ToBytes() { StateBuffer buffer = new StateBuffer(); diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs index 22b7bcc..6f9182a 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs @@ -22,14 +22,18 @@ namespace VirtualNes.Core public bool HasButton(int player, EnumButtonType button) { - uint raw = player switch + uint raw; + + switch (player) { - 0 => raw0, - 1 => raw1, - 2 => raw2, - 3 => raw3, - _ => 0 - }; + case 0: raw = raw0; break; + case 1: raw = raw1; break; + case 2: raw = raw2; break; + case 3: raw = raw3; break; + default: + raw = 0; + break; + } return (raw & (uint)button) == (uint)button; } @@ -51,10 +55,30 @@ namespace VirtualNes.Core public override int GetHashCode() { - return HashCode.Combine(raw0, raw1, raw2, raw3, valid); - } - - public static bool operator ==(ControllerState left, ControllerState right) + //return HashCode.Combine(raw0, raw1, raw2, raw3, valid); + return ComputeHashCode(raw0, raw1, raw2, raw3, valid); + } + + public static int ComputeHashCode(uint raw0, uint raw1, uint raw2, uint raw3, bool valid) + { + unchecked // 鍏佽婧㈠嚭锛屼娇寰楀搱甯岀爜璁$畻鏇村姞鍚堢悊 + { + int hash = 17; // 閫夋嫨涓涓潪闆剁殑鍒濆鍊 + + // 灏嗘瘡涓 uint 绫诲瀷鐨勫艰浆鎹负 int 骞跺悎骞跺埌鍝堝笇鐮佷腑 + hash = hash * 31 + (int)raw0; + hash = hash * 31 + (int)raw1; + hash = hash * 31 + (int)raw2; + hash = hash * 31 + (int)raw3; + + // 灏 bool 绫诲瀷鐨勫艰浆鎹负 int 骞跺悎骞跺埌鍝堝笇鐮佷腑 + hash = hash * 31 + (valid ? 1 : 0); + + return hash; + } + } + + public static bool operator ==(ControllerState left, ControllerState right) { return left.raw0 == right.raw0 &&