diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs index c23d826f..4ca46464 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/IEmuCore.cs @@ -13,7 +13,7 @@ namespace AxibugEmuOnline.Client void Pause(); void Resume(); void SetupScheme(); - void StartGame(RomFile romFile); + MsgBool StartGame(RomFile romFile); void DoReset(); IControllerSetuper GetControllerSetuper(); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs index 5bed4b24..9012dbe9 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs @@ -56,19 +56,27 @@ namespace AxibugEmuOnline.Client.Manager break; } - m_emuCore.StartGame(romFile); - LaunchUI.Instance.HideMainMenu(); - InGameUI.Instance.Show(romFile, m_emuCore); - - m_emuCore.SetupScheme(); - - m_controllerSetuper = m_emuCore.GetControllerSetuper(); + var result = m_emuCore.StartGame(romFile); + if (result) + { + LaunchUI.Instance.HideMainMenu(); + InGameUI.Instance.Show(romFile, m_emuCore); - //自动分配0号手柄到0号手柄位 - m_controllerSetuper.SetConnect(con0ToSlot: 0); - Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged); - - Eventer.Instance.RegisterEvent(EEvent.OnRoomSlotDataChanged, OnSlotDataChanged); + m_emuCore.SetupScheme(); + + m_controllerSetuper = m_emuCore.GetControllerSetuper(); + + //自动分配0号手柄到0号手柄位 + m_controllerSetuper.SetConnect(con0ToSlot: 0); + Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged); + + Eventer.Instance.RegisterEvent(EEvent.OnRoomSlotDataChanged, OnSlotDataChanged); + } + else + { + StopGame(); + OverlayManager.PopTip(result); + } } private void OnSlotDataChanged() diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs index 68c80391..6cd9e04d 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/RomLib/RomFile.cs @@ -95,12 +95,13 @@ namespace AxibugEmuOnline.Client var bytes = File.ReadAllBytes(LocalFilePath); if (Path.GetExtension(LocalFilePath).ToLower() == ".zip") { - var zip = new ZipInputStream(new MemoryStream(bytes)); - var entry = zip.GetNextEntry() as ZipEntry; - - while (entry != null) + var zip = new ZipInputStream(new MemoryStream(bytes)); + while (true) { - if (!entry.Name.ToLower().EndsWith(".nes")) continue; + var currentEntry = zip.GetNextEntry(); + if (currentEntry == null) break; + + if (!currentEntry.Name.ToLower().EndsWith(".nes")) continue; var buffer = new byte[1024]; MemoryStream output = new MemoryStream(); @@ -124,38 +125,38 @@ namespace AxibugEmuOnline.Client private IEnumerator DownloadRemoteRom(Action callback) { - downloadRequest = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{webData.url}"); - - while (!downloadRequest.downloadHandler.isDone) - { - yield return null; - Debug.Log($"下载进度:{downloadRequest.downloadHandler.DownLoadPr} ->{downloadRequest.downloadHandler.loadedLenght}/{downloadRequest.downloadHandler.NeedloadedLenght}"); - } - AxiHttpProxy.ShowAxiHttpDebugInfo(downloadRequest.downloadHandler); + downloadRequest = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{webData.url}"); + + while (!downloadRequest.downloadHandler.isDone) + { + yield return null; + Debug.Log($"下载进度:{downloadRequest.downloadHandler.DownLoadPr} ->{downloadRequest.downloadHandler.loadedLenght}/{downloadRequest.downloadHandler.NeedloadedLenght}"); + } + AxiHttpProxy.ShowAxiHttpDebugInfo(downloadRequest.downloadHandler); var request = downloadRequest; - downloadRequest = null; - - if (!request.downloadHandler.bHadErr) - callback(request.downloadHandler.data); - else - callback(null); - - //downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}"); - //yield return downloadRequest.SendWebRequest(); - - //var request = downloadRequest; - //downloadRequest = null; - - //if (request.result != UnityWebRequest.Result.Success) - //{ - // callback(null); - //} - //else - //{ - // callback(request.downloadHandler.data); - //} - } + downloadRequest = null; + + if (!request.downloadHandler.bHadErr) + callback(request.downloadHandler.data); + else + callback(null); + + //downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}"); + //yield return downloadRequest.SendWebRequest(); + + //var request = downloadRequest; + //downloadRequest = null; + + //if (request.result != UnityWebRequest.Result.Success) + //{ + // callback(null); + //} + //else + //{ + // callback(request.downloadHandler.data); + //} + } public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo) { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs index f6483667..3ecf771b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesEmulator.cs @@ -63,7 +63,7 @@ namespace AxibugEmuOnline.Client /// /// 指定ROM开始游戏 /// - public void StartGame(RomFile rom) + public MsgBool StartGame(RomFile rom) { StopGame(); @@ -76,11 +76,13 @@ namespace AxibugEmuOnline.Client try { NesCore = new NES(rom.FileName); + return true; } catch (Exception ex) { NesCore = null; App.log.Error(ex.ToString()); + return ex.Message; } } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs index 64d01d10..61f83b09 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs @@ -19,7 +19,7 @@ namespace VirtualNes.Core raw3 = (uint)states[3]; valid = true; } - + public bool HasButton(int player, EnumButtonType button) { uint raw = player switch