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
{
private static RAInterface _RA;
private static DynamicLibraryImportResolver _resolver;
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()
{
_resolver = new("RA_Integration-x64.dll", hasLimitedLifetime: true);
RA = BizInvoker.GetInvoker<RAInterface>(_resolver, CallingConventionAdapters.Native);
_version = new(Marshal.PtrToStringAnsi(RA.IntegrationVersion())!);
_RA = BizInvoker.GetInvoker<RAInterface>(_resolver, DummyMonitor.Singleton, CallingConventionAdapters.Native);
_version = new(Marshal.PtrToStringAnsi(_RA.IntegrationVersion())!);
Console.WriteLine($"Loaded RetroAchievements v{_version}");
}
private static void DetachDll()
{
RA?.Shutdown();
_RA?.Shutdown();
_resolver?.Dispose();
_resolver = null;
RA = null;
_RA = null;
_version = new(0, 0);
}

View File

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