From 91ef301a23bb88c1047948cac943dbc906289530 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 15 Dec 2019 12:02:43 -0600 Subject: [PATCH] memory callbacks - log error if a scope is passed in that is not available --- .../lua/EmuLuaLibrary.Events.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs index 137a527776..418d802b00 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Events.cs @@ -123,6 +123,11 @@ namespace BizHawk.Client.Common Log($"{Emulator.Attributes().CoreName} does not implement memory execute callbacks"); } + private void LogScopeNotAvailable(string scope) + { + Log($"{scope} is not an avaialble scope for {Emulator.Attributes().CoreName}"); + } + #endregion @@ -192,6 +197,12 @@ namespace BizHawk.Client.Common if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable() && DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable) { + if (!HasScope(scope)) + { + LogScopeNotAvailable(scope); + return Guid.Empty.ToString(); + } + var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentFile, name); RegisteredFunctions.Add(nlf); DebuggableCore.MemoryCallbacks.Add( @@ -218,6 +229,12 @@ namespace BizHawk.Client.Common if (DebuggableCore?.MemoryCallbacksAvailable() == true && DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable) { + if (!HasScope(scope)) + { + LogScopeNotAvailable(scope); + return Guid.Empty.ToString(); + } + var nlf = new NamedLuaFunction(luaf, "OnMemoryExecuteAny", LogOutputCallback, CurrentFile, name); RegisteredFunctions.Add(nlf); DebuggableCore.MemoryCallbacks.Add(new MemoryCallback( @@ -246,8 +263,14 @@ namespace BizHawk.Client.Common { try { - if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable()) + if (DebuggableCore?.MemoryCallbacksAvailable() == true) { + if (!HasScope(scope)) + { + LogScopeNotAvailable(scope); + return Guid.Empty.ToString(); + } + var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentFile, name); RegisteredFunctions.Add(nlf); DebuggableCore.MemoryCallbacks.Add( @@ -271,8 +294,14 @@ namespace BizHawk.Client.Common { try { - if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable()) + if (DebuggableCore?.MemoryCallbacksAvailable() == true) { + if (!HasScope(scope)) + { + LogScopeNotAvailable(scope); + return Guid.Empty.ToString(); + } + var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentFile, name); RegisteredFunctions.Add(nlf); DebuggableCore.MemoryCallbacks.Add( @@ -350,5 +379,10 @@ namespace BizHawk.Client.Common return scope; } + + private bool HasScope(string scope) + { + return string.IsNullOrWhiteSpace(scope) || DebuggableCore.MemoryCallbacks.AvailableScopes.Contains(scope); + } } }