-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
841 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
NWN_VERSION=8193.34 | ||
NWNX_VERSION=fe195ec | ||
NWNX_VERSION=2692ecb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Anvil.API | ||
{ | ||
public enum DoorOpenState | ||
{ | ||
/// <summary> | ||
/// The closed state of the door. | ||
/// </summary> | ||
Closed = 0, | ||
|
||
/// <summary> | ||
/// The forward open state of the door. This is the direction of the arrow as shown in the toolset. | ||
/// </summary> | ||
OpenForward = 1, | ||
|
||
/// <summary> | ||
/// The backward open state of the door. This is the opposite direction of the arrow as shown in the toolset. | ||
/// </summary> | ||
OpenBackward = 2, | ||
|
||
/// <summary> | ||
/// The destroyed state of the door. | ||
/// </summary> | ||
Destroyed = 3, | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
NWN.Anvil/src/main/API/Events/Native/ObjectEvents/OnDoorSetOpenState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Anvil.API.Events; | ||
using Anvil.Services; | ||
using NWN.Native.API; | ||
|
||
namespace Anvil.API.Events | ||
{ | ||
/// <summary> | ||
/// Called when a door's open state is changed (open/closed/destroyed). | ||
/// </summary> | ||
public sealed class OnDoorSetOpenState : IEvent | ||
{ | ||
/// <summary> | ||
/// The door that is being open/closed. | ||
/// </summary> | ||
public NwDoor Door { get; private init; } = null!; | ||
|
||
/// <summary> | ||
/// The new open state of the door. | ||
/// </summary> | ||
public DoorOpenState OpenState { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets if the door state should not be changed. | ||
/// </summary> | ||
public bool PreventStateChange { get; set; } | ||
|
||
NwObject IEvent.Context => Door; | ||
|
||
public sealed unsafe class Factory : HookEventFactory | ||
{ | ||
private static FunctionHook<SetOpenStateHook> Hook { get; set; } = null!; | ||
|
||
private delegate void SetOpenStateHook(void* pDoor, byte nOpenState); | ||
|
||
protected override IDisposable[] RequestHooks() | ||
{ | ||
delegate* unmanaged<void*, byte, void> pHook = &OnSetOpenState; | ||
Hook = HookService.RequestHook<SetOpenStateHook>(pHook, FunctionsLinux._ZN8CNWSDoor12SetOpenStateEh, HookOrder.Early); | ||
return new IDisposable[] { Hook }; | ||
} | ||
|
||
[UnmanagedCallersOnly] | ||
private static void OnSetOpenState(void* pDoor, byte nOpenState) | ||
{ | ||
NwDoor? door = CNWSDoor.FromPointer(pDoor).ToNwObject<NwDoor>(); | ||
if (door == null) | ||
{ | ||
Hook.CallOriginal(pDoor, nOpenState); | ||
return; | ||
} | ||
|
||
OnDoorSetOpenState eventData = ProcessEvent(EventCallbackType.Before, new OnDoorSetOpenState | ||
{ | ||
Door = door, | ||
OpenState = (DoorOpenState)nOpenState, | ||
}); | ||
|
||
if (!eventData.PreventStateChange) | ||
{ | ||
Hook.CallOriginal(pDoor, (byte)eventData.OpenState); | ||
} | ||
|
||
ProcessEvent(EventCallbackType.After, eventData); | ||
} | ||
} | ||
} | ||
} | ||
|
||
namespace Anvil.API | ||
{ | ||
public sealed partial class NwDoor | ||
{ | ||
/// <inheritdoc cref="Events.OnDoorSetOpenState"/> | ||
public event Action<OnDoorSetOpenState> OnDoorSetOpenState | ||
{ | ||
add => EventService.Subscribe<OnDoorSetOpenState, OnDoorSetOpenState.Factory>(this, value); | ||
remove => EventService.Unsubscribe<OnDoorSetOpenState, OnDoorSetOpenState.Factory>(this, value); | ||
} | ||
} | ||
|
||
public sealed partial class NwModule | ||
{ | ||
/// <inheritdoc cref="Events.OnDoorSetOpenState"/> | ||
public event Action<OnDoorSetOpenState> OnDoorSetOpenState | ||
{ | ||
add => EventService.SubscribeAll<OnDoorSetOpenState, OnDoorSetOpenState.Factory>(value); | ||
remove => EventService.UnsubscribeAll<OnDoorSetOpenState, OnDoorSetOpenState.Factory>(value); | ||
} | ||
} | ||
} |
Oops, something went wrong.