diff --git a/CHANGELOG.md b/CHANGELOG.md index 967d6821..67661f08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [unreleased] + +## Fixed + +### Compatibility + +- AsyncOperation's InvokeCompletionEvent is only disabled for tracked AsyncOperation instances + # [v0.6.0] - 2024-11-18 ## Added diff --git a/UniTAS/Patcher/Patches/Harmony/UnityInit/AsyncOperationPatch.cs b/UniTAS/Patcher/Patches/Harmony/UnityInit/AsyncOperationPatch.cs index bbb1ff66..c125cdc7 100644 --- a/UniTAS/Patcher/Patches/Harmony/UnityInit/AsyncOperationPatch.cs +++ b/UniTAS/Patcher/Patches/Harmony/UnityInit/AsyncOperationPatch.cs @@ -47,10 +47,10 @@ private static Exception Cleanup(MethodBase original, Exception ex) return PatchHelper.CleanupIgnoreFail(original, ex); } - private static bool Prefix() + private static bool Prefix(AsyncOperation __instance) { StaticLogger.Trace($"patch prefix invoke\n{new StackTrace()}"); - return AsyncOperationIsInvokingOnComplete.IsInvokingOnComplete; + return AsyncOperationIsInvokingOnComplete.IsInvokingOnComplete(__instance, out var invoking) && invoking; } } diff --git a/UniTAS/Patcher/Services/UnityAsyncOperationTracker/AsyncOperationTracker.cs b/UniTAS/Patcher/Services/UnityAsyncOperationTracker/AsyncOperationTracker.cs index ca278b13..0a0a5536 100644 --- a/UniTAS/Patcher/Services/UnityAsyncOperationTracker/AsyncOperationTracker.cs +++ b/UniTAS/Patcher/Services/UnityAsyncOperationTracker/AsyncOperationTracker.cs @@ -224,15 +224,27 @@ public object GetAssetBundleRequestMultiple(AsyncOperation asyncOperation) private readonly MethodBase _invokeCompletionEvent = AccessTools.Method("UnityEngine.AsyncOperation:InvokeCompletionEvent", Type.EmptyTypes); - public bool IsInvokingOnComplete { get; private set; } + private bool _isInvokingOnComplete; + + public bool IsInvokingOnComplete(AsyncOperation asyncOperation, out bool wasInvoked) + { + if (_tracked.Contains(asyncOperation)) + { + wasInvoked = _isInvokingOnComplete; + return true; + } + + wasInvoked = default; + return false; + } private void InvokeOnComplete(AsyncOperation asyncOperation) { if (_invokeCompletionEvent == null) return; - IsInvokingOnComplete = true; + _isInvokingOnComplete = true; logger.LogDebug("invoking completion event"); _invokeCompletionEvent.Invoke(asyncOperation, null); - IsInvokingOnComplete = false; + _isInvokingOnComplete = false; } private class AsyncSceneLoadData( diff --git a/UniTAS/Patcher/Services/UnityAsyncOperationTracker/IAsyncOperationIsInvokingOnComplete.cs b/UniTAS/Patcher/Services/UnityAsyncOperationTracker/IAsyncOperationIsInvokingOnComplete.cs index a432e12e..59a83cc3 100644 --- a/UniTAS/Patcher/Services/UnityAsyncOperationTracker/IAsyncOperationIsInvokingOnComplete.cs +++ b/UniTAS/Patcher/Services/UnityAsyncOperationTracker/IAsyncOperationIsInvokingOnComplete.cs @@ -1,6 +1,8 @@ +using UnityEngine; + namespace UniTAS.Patcher.Services.UnityAsyncOperationTracker; public interface IAsyncOperationIsInvokingOnComplete { - bool IsInvokingOnComplete { get; } + bool IsInvokingOnComplete(AsyncOperation asyncOperation, out bool wasInvoked); } \ No newline at end of file