Skip to content

Commit 971f6db

Browse files
committed
Merge branch 'development'
2 parents 3341b4f + ea94dbf commit 971f6db

File tree

18 files changed

+110
-23
lines changed

18 files changed

+110
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ 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.37.2
7+
https://github.com/nwn-dotnet/Anvil/compare/v8193.37.1...v8193.37.2
8+
9+
### Changed
10+
- Improved invalid object detection in some edge cases.
11+
612
## 8193.37.1
713
https://github.com/nwn-dotnet/Anvil/compare/v8193.37.0...v8193.37.1
814

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Numerics;
4+
using Anvil.Native;
45
using Anvil.Services;
56
using NWN.Core;
67
using NWN.Native.API;
@@ -30,6 +31,8 @@ internal NwArea(CNWSArea area) : base(area)
3031
this.area = area;
3132
}
3233

34+
public override bool IsValid => NWNXUtils.AsNWSArea(NWNXUtils.GetGameObject(ObjectId)) == area.Pointer;
35+
3336
/// <summary>
3437
/// Sets the daytime ambient track for this area.<br/>
3538
/// See "ambientsound.2da" for track numbers.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using Anvil.Native;
34
using NWN.Core;
45
using NWN.Native.API;
56

@@ -28,6 +29,8 @@ internal NwAreaOfEffect(CNWSAreaOfEffectObject areaOfEffect) : base(areaOfEffect
2829
this.areaOfEffect = areaOfEffect;
2930
}
3031

32+
public override bool IsValid => NWNXUtils.AsNWSAreaOfEffectObject(NWNXUtils.GetGameObject(ObjectId)) == areaOfEffect.Pointer;
33+
3134
/// <summary>
3235
/// Gets the creator of this Area of Effect.
3336
/// </summary>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ internal NwCreature(CNWSCreature creature) : base(creature)
5757
Inventory = new Inventory(this, Creature.m_pcItemRepository);
5858
}
5959

60+
public override bool IsValid => NWNXUtils.AsNWSCreature(NWNXUtils.GetGameObject(ObjectId)) == creature.Pointer;
61+
6062
/// <summary>
6163
/// Gets this creature's armour class.
6264
/// </summary>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ internal NwDoor(CNWSDoor door) : base(door)
2929
this.door = door;
3030
}
3131

32+
public override bool IsValid => NWNXUtils.AsNWSDoor(NWNXUtils.GetGameObject(ObjectId)) == door.Pointer;
33+
3234
/// <summary>
3335
/// Gets or sets the dialog ResRef for this door.
3436
/// </summary>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ internal NwEncounter(CNWSEncounter encounter) : base(encounter)
2929
this.encounter = encounter;
3030
}
3131

32+
public override bool IsValid => NWNXUtils.AsNWSEncounter(NWNXUtils.GetGameObject(ObjectId)) == encounter.Pointer;
33+
3234
/// <summary>
3335
/// Gets or sets a value indicating whether this encounter is spawned and active.
3436
/// </summary>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ internal NwItem(CNWSItem item) : base(item)
3838
Appearance = new ItemAppearance(this);
3939
}
4040

41+
public override bool IsValid => NWNXUtils.AsNWSItem(NWNXUtils.GetGameObject(ObjectId)) == item.Pointer;
42+
4143
/// <summary>
4244
/// Gets the armor class of this item.
4345
/// <remarks>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ internal NwModule(CNWSModule module) : base(module)
3232
this.module = module;
3333
}
3434

35+
public override bool IsValid => true;
36+
3537
/// <summary>
3638
/// Gets or sets the max possible ability score penalty from temporary effects/items (Default: 30).
3739
/// </summary>

NWN.Anvil/src/main/API/Objects/NwObject.Create.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Reflection;
44
using Anvil.Internal;
5+
using Anvil.Native;
56
using NWN.Core;
67
using NWN.Native.API;
78

@@ -126,18 +127,18 @@ public static IEnumerable<T> FindObjectsWithTag<T>(params string[] tags) where T
126127
{
127128
return (ObjectType)gameObject.m_nObjectType switch
128129
{
129-
ObjectType.Creature => new NwCreature(gameObject.AsNWSCreature()),
130-
ObjectType.Item => new NwItem(gameObject.AsNWSItem()),
131-
ObjectType.Placeable => new NwPlaceable(gameObject.AsNWSPlaceable()),
130+
ObjectType.Creature => new NwCreature(CNWSCreature.FromPointer(NWNXUtils.AsNWSCreature(gameObject.Pointer))),
131+
ObjectType.Item => new NwItem(CNWSItem.FromPointer(NWNXUtils.AsNWSItem(gameObject.Pointer))),
132+
ObjectType.Placeable => new NwPlaceable(CNWSPlaceable.FromPointer(NWNXUtils.AsNWSPlaceable(gameObject.Pointer))),
132133
ObjectType.Module => NwModule.Instance,
133-
ObjectType.Area => new NwArea(gameObject.AsNWSArea()),
134-
ObjectType.Trigger => new NwTrigger(gameObject.AsNWSTrigger()),
135-
ObjectType.Door => new NwDoor(gameObject.AsNWSDoor()),
136-
ObjectType.Waypoint => new NwWaypoint(gameObject.AsNWSWaypoint()),
137-
ObjectType.Encounter => new NwEncounter(gameObject.AsNWSEncounter()),
138-
ObjectType.Store => new NwStore(gameObject.AsNWSStore()),
139-
ObjectType.Sound => new NwSound(gameObject.AsNWSSoundObject()),
140-
ObjectType.AreaOfEffect => new NwAreaOfEffect(gameObject.AsNWSAreaOfEffectObject()),
134+
ObjectType.Area => new NwArea(CNWSArea.FromPointer(NWNXUtils.AsNWSArea(gameObject.Pointer))),
135+
ObjectType.Trigger => new NwTrigger(CNWSTrigger.FromPointer(NWNXUtils.AsNWSTrigger(gameObject.Pointer))),
136+
ObjectType.Door => new NwDoor(CNWSDoor.FromPointer(NWNXUtils.AsNWSDoor(gameObject.Pointer))),
137+
ObjectType.Waypoint => new NwWaypoint(CNWSWaypoint.FromPointer(NWNXUtils.AsNWSWaypoint(gameObject.Pointer))),
138+
ObjectType.Encounter => new NwEncounter(CNWSEncounter.FromPointer(NWNXUtils.AsNWSEncounter(gameObject.Pointer))),
139+
ObjectType.Store => new NwStore(CNWSStore.FromPointer(NWNXUtils.AsNWSStore(gameObject.Pointer))),
140+
ObjectType.Sound => new NwSound(CNWSSoundObject.FromPointer(NWNXUtils.AsNWSSoundObject(gameObject.Pointer))),
141+
ObjectType.AreaOfEffect => new NwAreaOfEffect(CNWSAreaOfEffectObject.FromPointer(NWNXUtils.AsNWSAreaOfEffectObject(gameObject.Pointer))),
141142
_ => null,
142143
};
143144
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4-
using System.Runtime.CompilerServices;
54
using System.Threading.Tasks;
6-
using Anvil.Internal;
75
using Anvil.Services;
86
using NWN.Core;
97
using NWN.Native.API;
@@ -63,7 +61,7 @@ public string Description
6361
/// <summary>
6462
/// Gets a value indicating whether this is a valid object.
6563
/// </summary>
66-
public bool IsValid => LowLevel.ServerExoApp.GetGameObject(ObjectId) != null;
64+
public abstract bool IsValid { get; }
6765

6866
/// <summary>
6967
/// Gets all local variables assigned on this object.
@@ -382,10 +380,9 @@ public async Task WaitForObjectContext()
382380
await tcs.Task;
383381
}
384382

385-
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
386383
protected void AssertObjectValid()
387384
{
388-
if (LowLevel.ServerExoApp.GetGameObject(ObjectId) == null)
385+
if (!IsValid)
389386
{
390387
throw new InvalidOperationException("Object is not valid.");
391388
}

0 commit comments

Comments
 (0)