Skip to content

Commit 709ef34

Browse files
committed
AetherBags compat
1 parent 1ec7924 commit 709ef34

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

AutoRetainer/AutoRetainer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ private void Tick(object _)
566566
MultiMode.Tick();
567567
NotificationHandler.Tick();
568568
NewYesAlreadyManager.Tick();
569+
S.AetherBagsManager.OnUpdate();
569570
ArtisanManager.ArtisanTick();
570571
FPSManager.Tick();
571572
PriorityManager.Tick();

AutoRetainer/Services/!AutoRetainerServiceManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ public static class AutoRetainerServiceManager
2121
public static WorkstationMonitor WorkstationMonitor;
2222
public static IpcConfigValuesProvider IpcConfigValuesProvider;
2323
public static InnCutsceneSkip InnCutsceneSkip;
24+
public static AetherBagsManager AetherBagsManager;
2425
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using AutoRetainer.Modules.Voyage;
2+
using ECommons.Throttlers;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace AutoRetainer.Services;
8+
9+
public class AetherBagsManager : IDisposable
10+
{
11+
string Identifier => $"{Svc.PluginInterface.Manifest.InternalName}_{ECommonsMain.InstanceUniqueId:X8}";
12+
volatile string Token = null;
13+
private bool IsBusy => VoyageScheduler.Enabled || P.TaskManager.IsBusy || AutoGCHandin.Operation;
14+
private AetherBagsManager()
15+
{
16+
}
17+
18+
public void OnUpdate()
19+
{
20+
if(!AetherBags.Available) return;
21+
if(IsBusy)
22+
{
23+
if(Token == null)
24+
{
25+
AcquireLock();
26+
PluginLog.Debug($"AetherBags locked");
27+
}
28+
else
29+
{
30+
if(EzThrottler.Check("ReacquireAetherBagsToken"))
31+
{
32+
AetherBags.ReleaseVanillaInventoryBypass(Token);
33+
AcquireLock();
34+
PluginLog.Debug($"AetherBags lock refresh");
35+
}
36+
}
37+
}
38+
else
39+
{
40+
if(Token != null)
41+
{
42+
AetherBags.ReleaseVanillaInventoryBypass(Token);
43+
Token = null;
44+
PluginLog.Debug($"AetherBags unlocked");
45+
}
46+
}
47+
}
48+
49+
private void AcquireLock()
50+
{
51+
Token = AetherBags.AcquireVanillaInventoryBypass(this.Identifier, 10000);
52+
EzThrottler.Throttle("ReacquireAetherBagsToken", 5000, true);
53+
}
54+
55+
public void Dispose()
56+
{
57+
Svc.Framework.RunOnFrameworkThread(() =>
58+
{
59+
if(Token != null)
60+
{
61+
AetherBags.ReleaseVanillaInventoryBypass(Token);
62+
PluginLog.Debug($"AetherBags force unlocked due to plugin disposal");
63+
}
64+
});
65+
}
66+
}

0 commit comments

Comments
 (0)