sledgehammer fix any remaining issues with RAIntegration

This commit is contained in:
CasualPokePlayer 2023-01-26 08:00:43 -08:00
parent e67e646ca5
commit c4f2bed9fd
2 changed files with 22 additions and 13 deletions

View File

@ -12,23 +12,35 @@ namespace BizHawk.Client.EmuHawk
{ {
public partial class RAIntegration public partial class RAIntegration
{ {
private static RAInterface _RA;
private static DynamicLibraryImportResolver _resolver; private static DynamicLibraryImportResolver _resolver;
private static Version _version; private static Version _version;
public static bool IsAvailable => _RA != null;
// can't have both a proxy with a monitor and without one, so...
private class DummyMonitor : IMonitor
{
public void Enter() {}
public void Exit() {}
public static readonly DummyMonitor Singleton = new();
}
private static void AttachDll() private static void AttachDll()
{ {
_resolver = new("RA_Integration-x64.dll", hasLimitedLifetime: true); _resolver = new("RA_Integration-x64.dll", hasLimitedLifetime: true);
RA = BizInvoker.GetInvoker<RAInterface>(_resolver, CallingConventionAdapters.Native); _RA = BizInvoker.GetInvoker<RAInterface>(_resolver, DummyMonitor.Singleton, CallingConventionAdapters.Native);
_version = new(Marshal.PtrToStringAnsi(RA.IntegrationVersion())!); _version = new(Marshal.PtrToStringAnsi(_RA.IntegrationVersion())!);
Console.WriteLine($"Loaded RetroAchievements v{_version}"); Console.WriteLine($"Loaded RetroAchievements v{_version}");
} }
private static void DetachDll() private static void DetachDll()
{ {
RA?.Shutdown(); _RA?.Shutdown();
_resolver?.Dispose(); _resolver?.Dispose();
_resolver = null; _resolver = null;
RA = null; _RA = null;
_version = new(0, 0); _version = new(0, 0);
} }

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.BizInvoke;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -13,8 +14,7 @@ namespace BizHawk.Client.EmuHawk
{ {
public partial class RAIntegration : RetroAchievements public partial class RAIntegration : RetroAchievements
{ {
private static RAInterface RA; private readonly RAInterface RA;
public static bool IsAvailable => RA != null;
static RAIntegration() static RAIntegration()
{ {
@ -117,6 +117,8 @@ namespace BizHawk.Client.EmuHawk
_memGuard = new(_memLock, _memSema, _memSync); _memGuard = new(_memLock, _memSema, _memSync);
_memAccess = new(_memLock, _memSema, _memSync); _memAccess = new(_memLock, _memSema, _memSync);
RA = BizInvoker.GetInvoker<RAInterface>(_resolver, _memAccess, CallingConventionAdapters.Native);
RA.InitClient(_mainForm.Handle, "BizHawk", VersionInfo.GetEmuVersion()); RA.InitClient(_mainForm.Handle, "BizHawk", VersionInfo.GetEmuVersion());
_isActive = () => !Emu.IsNull(); _isActive = () => !Emu.IsNull();
@ -153,11 +155,10 @@ namespace BizHawk.Client.EmuHawk
HandleHardcoreModeDisable("Loading savestates is not allowed in hardcore mode."); HandleHardcoreModeDisable("Loading savestates is not allowed in hardcore mode.");
} }
using var access = _memAccess.EnterExit();
RA.OnLoadState(path); RA.OnLoadState(path);
} }
private static void QuickLoadCallback(object _, BeforeQuickLoadEventArgs e) private void QuickLoadCallback(object _, BeforeQuickLoadEventArgs e)
{ {
if (RA.HardcoreModeIsActive()) if (RA.HardcoreModeIsActive())
{ {
@ -236,8 +237,6 @@ namespace BizHawk.Client.EmuHawk
public override void Update() public override void Update()
{ {
using var access = _memAccess.EnterExit();
if (RA.HardcoreModeIsActive()) if (RA.HardcoreModeIsActive())
{ {
CheckHardcoreModeConditions(); CheckHardcoreModeConditions();
@ -268,8 +267,6 @@ namespace BizHawk.Client.EmuHawk
public override void OnFrameAdvance() public override void OnFrameAdvance()
{ {
using var access = _memAccess.EnterExit();
var input = _inputManager.ControllerOutput; var input = _inputManager.ControllerOutput;
if (input.Definition.BoolButtons.Any(b => (b.Contains("Power") || b.Contains("Reset")) && input.IsPressed(b))) if (input.Definition.BoolButtons.Any(b => (b.Contains("Power") || b.Contains("Reset")) && input.IsPressed(b)))
{ {