Skip to content

Commit

Permalink
InvokeCompletionEvent is only disabled if tracked as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Nov 18, 2024
1 parent 92a8fb4 commit 740479e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using UnityEngine;

namespace UniTAS.Patcher.Services.UnityAsyncOperationTracker;

public interface IAsyncOperationIsInvokingOnComplete
{
bool IsInvokingOnComplete { get; }
bool IsInvokingOnComplete(AsyncOperation asyncOperation, out bool wasInvoked);
}

0 comments on commit 740479e

Please sign in to comment.