Skip to content

Commit

Permalink
Add IPCs Brio.FreezePhysics & Brio.UnFreezePhysics
Browse files Browse the repository at this point in the history
  • Loading branch information
Minmoose committed Jan 4, 2025
1 parent 8ac1dca commit 0d877cb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
32 changes: 31 additions & 1 deletion Brio/IPC/BrioIPCService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Brio.Game.Actor.Extensions;
using Brio.Game.Core;
using Brio.Game.GPose;
using Brio.Game.Posing;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Plugin;
using Dalamud.Plugin.Ipc;
Expand Down Expand Up @@ -91,6 +92,12 @@ internal class BrioIPCService : IDisposable

public const string Actor_UnFreeze_IPCName = "Brio.Actor.UnFreeze";
private ICallGateProvider<IGameObject, bool>? Actor_UnFreeze_IPC;

public const string FreezePhysics_IPCName = "Brio.FreezePhysics";
private ICallGateProvider<bool>? FreezePhysics_IPC;

public const string UnFreezePhysics_IPCName = "Brio.UnFreezePhysics";
private ICallGateProvider<bool>? UnFreezePhysics_IPC;

//

Expand All @@ -100,15 +107,18 @@ internal class BrioIPCService : IDisposable
private readonly EntityManager _entityManager;
private readonly IDalamudPluginInterface _pluginInterface;
private readonly IFramework _framework;
private readonly PhysicsService _physicsService;

public BrioIPCService(ActorSpawnService actorSpawnService, GPoseService gPoseService, ConfigurationService configurationService, EntityManager entityManager, IDalamudPluginInterface pluginInterface, IFramework framework)
public BrioIPCService(ActorSpawnService actorSpawnService, GPoseService gPoseService, ConfigurationService configurationService, EntityManager entityManager,
IDalamudPluginInterface pluginInterface, IFramework framework, PhysicsService physicsService)
{
_actorSpawnService = actorSpawnService;
_gPoseService = gPoseService;
_configurationService = configurationService;
_entityManager = entityManager;
_pluginInterface = pluginInterface;
_framework = framework;
_physicsService = physicsService;

if(_configurationService.Configuration.IPC.EnableBrioIPC)
CreateIPC();
Expand Down Expand Up @@ -186,6 +196,12 @@ private void CreateIPC()
Actor_UnFreeze_IPC = _pluginInterface.GetIpcProvider<IGameObject, bool>(Actor_UnFreeze_IPCName);
Actor_UnFreeze_IPC.RegisterFunc(UnFreezActor_Impl);

FreezePhysics_IPC = _pluginInterface.GetIpcProvider <bool> (FreezePhysics_IPCName);
FreezePhysics_IPC.RegisterFunc(FreezePhysics_Impl);

UnFreezePhysics_IPC = _pluginInterface.GetIpcProvider <bool> (UnFreezePhysics_IPCName);
UnFreezePhysics_IPC.RegisterFunc(UnFreezePhysics_Impl);

IsIPCEnabled = true;
}
private void DisposeIPC()
Expand Down Expand Up @@ -512,6 +528,20 @@ private unsafe bool UnFreezActor_Impl(IGameObject actor)
return false;
}

public bool FreezePhysics_Impl()
{
if(_gPoseService.IsGPosing == false) return false;

return _physicsService.FreezeEnable();
}

public bool UnFreezePhysics_Impl()
{
if(_gPoseService.IsGPosing == false) return false;

return _physicsService.FreezeRevert();
}

public void Dispose()
{
_configurationService.OnConfigurationChanged -= OnConfigurationChanged;
Expand Down
21 changes: 21 additions & 0 deletions BrioTester/BrioAPI_V2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static class BrioAPI
private static ICallGateSubscriber<IGameObject, bool> Actor_Freeze_IPC;
private static ICallGateSubscriber<IGameObject, bool> Actor_UnFreeze_IPC;

private static ICallGateSubscriber<bool> FreezePhysics_IPC;
private static ICallGateSubscriber<bool> UnFreezePhysics_IPC;

//
//

Expand Down Expand Up @@ -79,6 +82,9 @@ public static void InitBrioAPI(IDalamudPluginInterface pluginInterface)

Actor_Freeze_IPC = pluginInterface.GetIpcSubscriber<IGameObject, bool>("Brio.Actor.Freeze");
Actor_UnFreeze_IPC = pluginInterface.GetIpcSubscriber<IGameObject, bool>("Brio.Actor.UnFreeze");

FreezePhysics_IPC = pluginInterface.GetIpcSubscriber<bool>("Brio.FreezePhysics");
UnFreezePhysics_IPC = pluginInterface.GetIpcSubscriber<bool>("Brio.UnFreezePhysics");
}

/// <summary>
Expand Down Expand Up @@ -359,4 +365,19 @@ public static bool UnFreezeActor(IGameObject actor)

return Actor_UnFreeze_IPC.InvokeFunc(actor);
}

public static bool FreezePhysics()
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");

return FreezePhysics_IPC.InvokeFunc();
}

public static bool UnFreezePhysics()
{
if (hasInit is false) throw new Exception("Call BrioAPI.InitBrioAPI first!");

return UnFreezePhysics_IPC.InvokeFunc();
}

}

0 comments on commit 0d877cb

Please sign in to comment.