Skip to content

Commit

Permalink
8193.37 Initial Support (#798)
Browse files Browse the repository at this point in the history
* Update NWN.Core to 8183.37.0. Update NWN.Native to 8193.37.1.

* Update API/service code for 8193.37 changes.

* Implement new bootstrap code. Close IServiceManager interface.

* Remove hook from removed function "WriteToErrorFile".

* Update additional hooks.

* Update dockerfile/NWNX version.

* Fix code analysis warnings.
  • Loading branch information
jhett12321 authored Jan 19, 2025
1 parent 0627996 commit 05007eb
Show file tree
Hide file tree
Showing 38 changed files with 119 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NWNX_VERSION=30482a7
NWNX_VERSION=a6c5f09
4 changes: 2 additions & 2 deletions NWN.Anvil.TestRunner/NWN.Anvil.TestRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NWN.Core" Version="8193.36.5" PrivateAssets="compile" />
<PackageReference Include="NWN.Native" Version="8193.36.7" PrivateAssets="compile" />
<PackageReference Include="NWN.Core" Version="8193.37.0" PrivateAssets="compile" />
<PackageReference Include="NWN.Native" Version="8193.37.1" PrivateAssets="compile" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions NWN.Anvil.Tests/NWN.Anvil.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Include="NWN.Core" Version="8193.36.5" PrivateAssets="compile" />
<PackageReference Include="NWN.Native" Version="8193.36.7" PrivateAssets="compile" />
<PackageReference Include="NWN.Core" Version="8193.37.0" PrivateAssets="compile" />
<PackageReference Include="NWN.Native" Version="8193.37.1" PrivateAssets="compile" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion NWN.Anvil.Tests/src/main/API/TwoDimArray/TwoDimArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Anvil.Services;
using NUnit.Framework;
using NWN.Native.API;
using NWNX.NET.Native;

namespace Anvil.Tests.API
{
Expand All @@ -27,7 +28,7 @@ 2 Test2 "Test 2" 0x00000002 2.0f
""";

string resourceName = "testtemp.2da";
ResourceManager.WriteTempResource(resourceName, StringHelper.Encoding.GetBytes(twoDimArray));
ResourceManager.WriteTempResource(resourceName, StringUtils.Encoding.GetBytes(twoDimArray));
createdTempResources.Add(resourceName);

TwoDimArray array = NwGameTables.GetTable(resourceName)!;
Expand Down
4 changes: 2 additions & 2 deletions NWN.Anvil/NWN.Anvil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.3.4" />
<PackageReference Include="Paket.Core" Version="8.0.3" PrivateAssets="all" />
<PackageReference Include="NWN.Core" Version="8193.36.5" PrivateAssets="compile" />
<PackageReference Include="NWN.Native" Version="8193.36.7" PrivateAssets="compile" />
<PackageReference Include="NWN.Core" Version="8193.37.0" PrivateAssets="compile" />
<PackageReference Include="NWN.Native" Version="8193.37.1" PrivateAssets="compile" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions NWN.Anvil/src/main/API/Color.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Newtonsoft.Json;
using NWN.Native.API;
using NWNX.NET.Native;

namespace Anvil.API
{
Expand Down Expand Up @@ -154,7 +154,7 @@ public string ToColorToken()
{
const byte tokenMinVal = 1;
ReadOnlySpan<byte> tokenBytes = [Math.Max(Red, tokenMinVal), Math.Max(Green, tokenMinVal), Math.Max(Blue, tokenMinVal)];
return StringHelper.Encoding.GetString(tokenBytes);
return StringUtils.Encoding.GetString(tokenBytes);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions NWN.Anvil/src/main/API/EngineStructures/EngineStructure.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using NWN.Core;
using NWNX.NET;

namespace Anvil.API
{
Expand Down Expand Up @@ -40,7 +40,7 @@ private void ReleaseUnmanagedResources()
if (memoryOwn)
{
memoryOwn = false;
VM.FreeGameDefinedStructure(StructureId, handle);
NWNXAPI.FreeGameDefinedStructure(StructureId, handle);
handle = IntPtr.Zero;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static IReadOnlyList<NwItem> GetBarterItems(CNWSBarter barter)
[UnmanagedCallersOnly]
private static int OnSendServerToPlayerBarterCloseBarter(void* pMessage, uint nInitiatorId, uint nRecipientId, int bAccepted)
{
NwPlayer? player = LowLevel.ServerExoApp.GetClientObjectByPlayerId(nInitiatorId).AsNWSPlayer().ToNwPlayer();
NwPlayer? player = LowLevel.ServerExoApp.GetClientObjectByPlayerId(nInitiatorId).ToNwPlayer();
if (player == null)
{
return sendServerToPlayerBarterCloseBarterHook.CallOriginal(pMessage, nInitiatorId, nRecipientId, bAccepted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static unsafe int OnSendServerToPlayerCharList(void* pMessage, void* pPl
PlayerName = playerInfo.m_sPlayerName.ToString()!,
ClientVersion = new Version(playerInfo.m_nBuildVersion, playerInfo.m_nPatchRevision),
ClientPlatform = (PlayerPlatform)playerInfo.m_nPlatformId,
CDKey = playerInfo.m_lstKeys[0].sPublic.ToString()!,
CDKey = playerInfo.m_cCDKey.sPublic.ToString()!,
DM = playerInfo.m_bGameMasterPrivileges.ToBool(),
IP = ipAddress,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override IDisposable[] RequestHooks()
[UnmanagedCallersOnly]
private static int OnSendServerToPlayerAmbientBattleMusicPlay(void* pMessage, uint nPlayer, int bPlay)
{
NwPlayer? player = ServerExoApp.GetClientObjectByPlayerId(nPlayer).AsNWSPlayer().ToNwPlayer();
NwPlayer? player = ServerExoApp.GetClientObjectByPlayerId(nPlayer).ToNwPlayer();
OnCombatStatusChange? eventData = null;

if (player != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public sealed class OnItemUnequip : IEvent

public sealed unsafe class Factory : HookEventFactory
{
private static FunctionHook<Functions.CNWSCreature.UnequipItem> Hook { get; set; } = null!;
private static FunctionHook<Functions.CNWSCreature.RunUnequip> Hook { get; set; } = null!;

protected override IDisposable[] RequestHooks()
{
delegate* unmanaged<void*, uint, uint, byte, byte, int, uint, int> pHook = &OnUnequipItem;
Hook = HookService.RequestHook<Functions.CNWSCreature.UnequipItem>(pHook, HookOrder.Early);
Hook = HookService.RequestHook<Functions.CNWSCreature.RunUnequip>(pHook, HookOrder.Early);
return [Hook];
}

Expand Down
23 changes: 12 additions & 11 deletions NWN.Anvil/src/main/API/Extensions/IntegerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,34 +146,35 @@ public static int ToInt(this bool value)
/// <param name="objectId">The object ID to convert.</param>
/// <param name="playerSearch">Methods to use to resolve the player.</param>
/// <returns>The associated player for this object, otherwise null.</returns>
public static unsafe NwPlayer? ToNwPlayer(this uint objectId, PlayerSearch playerSearch = PlayerSearch.All)
public static NwPlayer? ToNwPlayer(this uint objectId, PlayerSearch playerSearch = PlayerSearch.All)
{
if (objectId == NwObject.Invalid)
{
return null;
}

CNWSPlayer? player = null;
if (playerSearch.HasFlag(PlayerSearch.Controlled))
{
player = LowLevel.ServerExoApp.GetClientObjectByObjectId(objectId);
CNWSPlayer? player = LowLevel.ServerExoApp.GetClientObjectByObjectId(objectId);
if (player != null)
{
return new NwPlayer(player);
}
}

if ((player == null || player.Pointer == IntPtr.Zero) && playerSearch.HasFlag(PlayerSearch.Login))
if (playerSearch.HasFlag(PlayerSearch.Login))
{
CExoLinkedListInternal players = LowLevel.ServerExoApp.m_pcExoAppInternal.m_pNWSPlayerList.m_pcExoLinkedListInternal;
for (CExoLinkedListNode node = players.pHead; node != null; node = node.pNext)
CExoArrayListCNWSPlayerPtr? players = LowLevel.ServerExoApp.m_pcExoAppInternal.m_lstPlayerList;
foreach (CNWSPlayer player in players)
{
CNWSPlayer current = CNWSPlayer.FromPointer(node.pObject);
if (current.m_oidPCObject == objectId)
if (player.m_oidPCObject == objectId)
{
player = current;
break;
return new NwPlayer(player);
}
}
}

return player != null && player.Pointer != IntPtr.Zero ? new NwPlayer(player) : null;
return null;
}
}
}
1 change: 1 addition & 0 deletions NWN.Anvil/src/main/API/Objects/NwArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Anvil.Services;
using NWN.Core;
using NWN.Native.API;
using NWNX.NET.Native;

namespace Anvil.API
{
Expand Down
11 changes: 4 additions & 7 deletions NWN.Anvil/src/main/API/Objects/NwModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Anvil.Internal;
using Anvil.Native;
using NWN.Core;
using NWN.Native.API;

Expand Down Expand Up @@ -131,7 +130,7 @@ public int MaxHenchmen
/// <summary>
/// Gets the current player count.
/// </summary>
public uint PlayerCount => LowLevel.ServerExoApp.m_pcExoAppInternal.m_pNWSPlayerList.Count();
public int PlayerCount => LowLevel.ServerExoApp.m_pcExoAppInternal.m_lstPlayerList.Count;

/// <summary>
/// Gets all current online players.
Expand All @@ -140,12 +139,10 @@ public IEnumerable<NwPlayer> Players
{
get
{
CExoLinkedListCNWSClient playerList = LowLevel.ServerExoApp.m_pcExoAppInternal.m_pNWSPlayerList;

for (CExoLinkedListNode node = playerList.GetHeadPos(); node != null; node = node.pNext)
CExoArrayListCNWSPlayerPtr? playerList = LowLevel.ServerExoApp.m_pcExoAppInternal.m_lstPlayerList;
foreach (CNWSPlayer player in playerList)
{
CNWSPlayer player = playerList.GetAtPos(node).AsNWSPlayer();
yield return player.ToNwPlayer()!;
yield return new NwPlayer(player);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions NWN.Anvil/src/main/API/Objects/NwPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ public bool IsValid
{
get
{
CNWSClient client = LowLevel.ServerExoApp.GetClientObjectByPlayerId(PlayerId);
return client != null && client.AsNWSPlayer() == player;
CNWSPlayer? playerById = LowLevel.ServerExoApp.GetClientObjectByPlayerId(PlayerId);
return playerById == player;
}
}

Expand Down Expand Up @@ -1687,7 +1687,7 @@ private void AssertPlayerValid()

internal static NwPlayer? FromPlayerId(uint playerId)
{
CNWSPlayer? player = LowLevel.ServerExoApp.GetClientObjectByPlayerId(playerId, 0)?.AsNWSPlayer();
CNWSPlayer? player = LowLevel.ServerExoApp.GetClientObjectByPlayerId(playerId);
return player != null ? new NwPlayer(player) : null;
}
}
Expand Down
1 change: 1 addition & 0 deletions NWN.Anvil/src/main/API/Objects/PlayerQuickBarButton.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NWN.Native.API;
using NWNX.NET.Native;

namespace Anvil.API
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using NWN.Native.API;
using NWNX.NET.Native;

namespace Anvil.API
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using NWN.Native.API;
using NWNX.NET.Native;

namespace Anvil.API
{
Expand All @@ -22,10 +23,10 @@ internal GffResourceFieldStruct(CResGFF resGff, CResStruct resStruct) : base(res
for (uint i = 0; i < fieldCount; i++)
{
byte* fieldIdPtr = ResGff.GetFieldLabel(resStruct, i);
string key = StringHelper.ReadNullTerminatedString(fieldIdPtr);
string? key = StringUtils.ReadNullTerminatedString(fieldIdPtr);
GffResourceField? value = Create(resGff, resStruct, i, fieldIdPtr);

if (value == null)
if (key == null || value == null)
{
continue;
}
Expand Down
6 changes: 4 additions & 2 deletions NWN.Anvil/src/main/API/Resources/Gff/GffResource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using NWN.Native.API;
using NWNX.NET.Native;

namespace Anvil.API
{
Expand All @@ -8,11 +9,12 @@ public sealed class GffResource : IDisposable
private readonly CResGFF resGff;
private readonly CResStruct rootStruct;

internal GffResource(string name, CResGFF resGff)
internal unsafe GffResource(string name, CResGFF resGff)
{
this.resGff = resGff;
NativeArray<byte>? fileType = this.resGff.m_pFileType;

FileType = resGff.m_pFileType.ReadFixedLengthString().Trim();
FileType = StringUtils.ReadFixedLengthString(fileType.Pointer, fileType.Length).Trim();

rootStruct = new CResStruct();
if (!resGff.GetTopLevelStruct(rootStruct).ToBool())
Expand Down
10 changes: 9 additions & 1 deletion NWN.Anvil/src/main/API/Ruleset/NwBaseItem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using NWN.Native.API;
using NWNX.NET.Native;

namespace Anvil.API
{
Expand Down Expand Up @@ -189,7 +190,14 @@ internal NwBaseItem(uint baseItemId, CNWBaseItem baseItemInfo)
/// Gets the ResRef of the item's model, or the base part of the resref.<br/>
/// This property is dependent on <see cref="ModelType"/>. See https://nwn.wiki/display/NWN1/baseitems.2da for more info.
/// </summary>
public string? ItemClass => BaseItemInfo.m_ItemClassResRefChunk.ReadFixedLengthString();
public string ItemClass
{
get
{
NativeArray<byte>? resRefChunk = BaseItemInfo.m_ItemClassResRefChunk;
return StringUtils.ReadFixedLengthString(resRefChunk.Pointer, resRefChunk.Length);
}
}

/// <summary>
/// Gets the maximum number of "cast spell" properties items of this type can be given when designed in the Toolset.
Expand Down
5 changes: 3 additions & 2 deletions NWN.Anvil/src/main/API/Utils/NativeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Anvil.Services;
using NLog;
using NWN.Native.API;
using NWNX.NET.Native;
using Vector = NWN.Native.API.Vector;

namespace Anvil.API
Expand Down Expand Up @@ -132,13 +133,13 @@ public static T PeekMessage<T>(this CNWSMessage message, int offset) where T : u
public static string PeekMessageResRef(this CNWSMessage message, int offset)
{
byte* ptr = message.m_pnReadBuffer + message.m_nReadBufferPtr + offset;
return StringHelper.ReadFixedLengthString(ptr, 16);
return StringUtils.ReadFixedLengthString(ptr, 16);
}

public static string PeekMessageString(this CNWSMessage message, int offset)
{
byte* ptr = message.m_pnReadBuffer + message.m_nReadBufferPtr + offset;
return StringHelper.ReadNullTerminatedString(ptr);
return StringUtils.ReadNullTerminatedString(ptr)!;
}

public static byte[]? SerializeGff(string fileType, string version, Func<CResGFF, CResStruct, bool> serializeAction)
Expand Down
Loading

0 comments on commit 05007eb

Please sign in to comment.