memory callbacks - log error if a scope is passed in that is not available

This commit is contained in:
adelikat 2019-12-15 12:02:43 -06:00
parent 9676fd97df
commit 91ef301a23
1 changed files with 36 additions and 2 deletions
BizHawk.Client.Common/lua

View File

@ -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);
}
}
}