Skip to content

Commit 4322170

Browse files
committed
Merge branch 'development'
2 parents bdde90b + 65dedbb commit 4322170

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

6+
## 8193.34.28
7+
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.27...v8193.34.28
8+
9+
### Fixed
10+
- NwCreature: Fixed an issue where GetAssociates would return an empty list for certain associate types.
11+
- VirtualMachine: Fix an issue where the context object would be incorrectly flagged as invalid.
12+
- Creature.OnDeath: Support Area/Module as the killer of the creature.
13+
- EventService: More reliable handling of game events.
14+
615
## 8193.34.27
716
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.26...v8193.34.27
817

NWN.Anvil/src/main/API/Events/Game/CreatureEvents/CreatureEvents.OnDeath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class OnDeath : IEvent
2323
/// <summary>
2424
/// Gets the <see cref="NwGameObject"/> that killed <see cref="NwCreature"/>.
2525
/// </summary>
26-
public NwGameObject Killer { get; } = NWScript.GetLastKiller().ToNwObject<NwGameObject>()!;
26+
public NwObject? Killer { get; } = NWScript.GetLastKiller().ToNwObject();
2727

2828
NwObject IEvent.Context => KilledCreature;
2929
}

NWN.Anvil/src/main/API/Events/Game/GameEventFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ScriptHandleResult IScriptDispatcher.ExecuteScript(string? scriptName, uint oidS
4444
return ScriptHandleResult.NotHandled;
4545
}
4646

47-
EventScriptType eventScriptType = (EventScriptType)NWScript.GetCurrentlyRunningEvent();
47+
EventScriptType eventScriptType = (EventScriptType)NWScript.GetCurrentlyRunningEvent(false.ToInt());
4848
if (eventScriptType == EventScriptType.None)
4949
{
5050
return ScriptHandleResult.NotHandled;

NWN.Anvil/src/main/API/Objects/NwCreature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ private List<NwCreature> GetAssociates(AssociateType associateType)
25482548
List<NwCreature> associates = new List<NwCreature>();
25492549
int type = (int)associateType;
25502550

2551-
for (int i = 0;; i++)
2551+
for (int i = 1;; i++)
25522552
{
25532553
NwCreature? associate = NWScript.GetAssociate(type, this, i).ToNwObject<NwCreature>();
25542554
if (associate == null || associates.Contains(associate))

NWN.Anvil/src/main/API/Scripts/CallInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public CallInfo(string scriptName, NwObject? objSelf)
1616
{
1717
ScriptName = scriptName;
1818
ObjectSelf = objSelf;
19-
ScriptType = (EventScriptType)NWScript.GetCurrentlyRunningEvent();
19+
ScriptType = (EventScriptType)NWScript.GetCurrentlyRunningEvent(false.ToInt());
2020
}
2121

2222
/// <summary>

NWN.Anvil/src/main/API/Utils/VirtualMachine.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Threading;
4+
using Anvil.Internal;
45
using Anvil.Services;
56
using NLog;
67
using NWN.Core;
@@ -89,9 +90,9 @@ public void Execute(string scriptName, params (string ParamName, string ParamVal
8990
Execute(scriptName, null, scriptParams);
9091
}
9192

92-
public void ExecuteInScriptContext(System.Action action, uint objectId = NwObject.Invalid, int scriptEventId = 0, bool valid = false)
93+
public void ExecuteInScriptContext(System.Action action, uint objectId = NwObject.Invalid, int scriptEventId = 0)
9394
{
94-
int spBefore = PushScriptContext(objectId, scriptEventId, valid);
95+
int spBefore = PushScriptContext(objectId, scriptEventId);
9596
try
9697
{
9798
action();
@@ -106,9 +107,9 @@ public void ExecuteInScriptContext(System.Action action, uint objectId = NwObjec
106107
}
107108
}
108109

109-
public T ExecuteInScriptContext<T>(System.Func<T> action, uint objectId = NwObject.Invalid, int scriptEventId = 0, bool valid = false)
110+
public T ExecuteInScriptContext<T>(System.Func<T> action, uint objectId = NwObject.Invalid, int scriptEventId = 0)
110111
{
111-
int spBefore = PushScriptContext(objectId, scriptEventId, valid);
112+
int spBefore = PushScriptContext(objectId, scriptEventId);
112113

113114
try
114115
{
@@ -181,9 +182,10 @@ private int PopScriptContext()
181182
return virtualMachine.m_cRunTimeStack.GetStackPointer();
182183
}
183184

184-
private int PushScriptContext(uint oid, int scriptEventId, bool valid)
185+
private int PushScriptContext(uint oid, int scriptEventId)
185186
{
186187
CNWVirtualMachineCommands cmd = CNWVirtualMachineCommands.FromPointer(virtualMachine.m_pCmdImplementer.Pointer);
188+
bool valid = LowLevel.ServerExoApp.GetGameObject(oid) != null;
187189

188190
if (virtualMachine.m_nRecursionLevel++ == -1)
189191
{
@@ -196,7 +198,10 @@ private int PushScriptContext(uint oid, int scriptEventId, bool valid)
196198
virtualMachine.m_oidObjectRunScript[virtualMachine.m_nRecursionLevel] = oid;
197199
virtualMachine.m_bValidObjectRunScript[virtualMachine.m_nRecursionLevel] = valid.ToInt();
198200

199-
virtualMachine.m_pVirtualMachineScript[virtualMachine.m_nRecursionLevel].m_nScriptEventID = scriptEventId;
201+
CVirtualMachineScript script = virtualMachine.m_pVirtualMachineScript[virtualMachine.m_nRecursionLevel];
202+
script.m_nScriptEventID = scriptEventId;
203+
204+
virtualMachine.m_pVirtualMachineScript[virtualMachine.m_nRecursionLevel] = script;
200205
cmd.m_oidObjectRunScript = virtualMachine.m_oidObjectRunScript[virtualMachine.m_nRecursionLevel];
201206
cmd.m_bValidObjectRunScript = virtualMachine.m_bValidObjectRunScript[virtualMachine.m_nRecursionLevel];
202207

NWN.Anvil/src/main/Services/ScriptDispatch/ScriptHandleResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Anvil.Services
22
{
33
public enum ScriptHandleResult
44
{
5-
NotHandled = -1,
5+
NotHandled = ~0,
66
Handled = 0,
77
False = 0,
88
True = 1,

0 commit comments

Comments
 (0)