Skip to content

Commit

Permalink
Fix compile errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhett12321 committed Dec 10, 2023
1 parent 05d8990 commit 2b4b442
Show file tree
Hide file tree
Showing 14 changed files with 521 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static OnDebugRunScript HandleRunScriptEvent(CNWSMessage message, NwPlay
string scriptName = message.PeekMessageString(offset);
offset += scriptName.Length + 4;

uint oidTarget = player?.Player.SatisfiesBuild(8193, 14).ToBool() == true ? message.PeekMessage<uint>(offset) : NwObject.Invalid;
uint oidTarget = player?.Player.SatisfiesBuild(8193, 14, 0).ToBool() == true ? message.PeekMessage<uint>(offset) : NwObject.Invalid;
if (oidTarget == NwObject.Invalid)
{
oidTarget = player?.ControlledCreature;
Expand Down
16 changes: 6 additions & 10 deletions NWN.Anvil/src/main/API/Objects/NwPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public bool IsPlayerDM
return;
}

if (!playerInfo.SatisfiesBuild(8193, 14))
if (!playerInfo.SatisfiesBuild(8193, 14, 0))
{
Log.Warn("{PlayerName} cannot toggle DM mode as the player's client does not support PlayerDM functionality", PlayerName);
return;
Expand Down Expand Up @@ -1202,18 +1202,14 @@ public SQLQuery PrepareSQLQuery(string query)
/// <param name="gameObject">The game object to refresh.</param>
public unsafe void RefreshClientObject(NwGameObject gameObject)
{
CExoLinkedListInternal lastUpdateObjects = Player.m_pActiveObjectsLastUpdate.m_pcExoLinkedListInternal;
for (CExoLinkedListNode node = lastUpdateObjects.pHead; node != null; node = node.pNext)
CExoArrayListCLastUpdateObjectPtr lastUpdateObjects = Player.m_lstActiveObjectsLastUpdate;
for (int i = lastUpdateObjects.Count - 1; i >= 0; i--)
{
CLastUpdateObject luo = CLastUpdateObject.FromPointer(node.pObject, true);
CLastUpdateObject luo = lastUpdateObjects[i];
if (luo.m_nId == gameObject.ObjectId)
{
lastUpdateObjects.Remove(node);
luo.Dispose();
}
else
{
GC.SuppressFinalize(luo);
lastUpdateObjects.RemoveAt(i);
CLastUpdateObject.FromPointer(luo, true).Dispose();
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions NWN.Anvil/src/main/API/Ruleset/CRulesKeyHash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Anvil.API
{
public readonly struct CRulesKeyHash
{
public ulong Hash { get; }

public CRulesKeyHash(string key)
{
Hash = 14695981039346656037ul;
for (int i = 0; i < key.Length; i++)
{
Hash = (Hash ^ key[i]) * 1099511628211ul;
}
}

public static implicit operator CRulesKeyHash(string key)
{
return new CRulesKeyHash(key);
}

public static implicit operator ulong(CRulesKeyHash hash)
{
return hash.Hash;
}
}
}
10 changes: 10 additions & 0 deletions NWN.Anvil/src/main/API/Ruleset/NwSpell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ public SpellComponents SpellComponents
return spellId != null ? NwRuleset.Spells.ElementAtOrDefault(spellId.Value) : null;
}

/// <summary>
/// Resolves a <see cref="NwSpell"/> from a spell id.
/// </summary>
/// <param name="spellId">The id of the spell to resolve.</param>
/// <returns>The associated <see cref="NwSpell"/> instance. Null if the spell id is invalid.</returns>
public static NwSpell? FromSpellId(uint? spellId)
{
return spellId != null ? NwRuleset.Spells.ElementAtOrDefault((int)spellId.Value) : null;
}

/// <summary>
/// Resolves a <see cref="NwSpell"/> from a <see cref="Anvil.API.Spell"/>.
/// </summary>
Expand Down
428 changes: 428 additions & 0 deletions NWN.Anvil/src/main/API/Ruleset/RulesetKeys.cs

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions NWN.Anvil/src/main/API/TwoDimArray/Tables/NwGameTables.Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,40 +114,40 @@ private void LoadTables()
TwoDimArrayCache.Clear();
CTwoDimArrays arrays = NWNXLib.Rules().m_p2DArrays;

AppearanceTable = GetTable<AppearanceTableEntry>(arrays.m_pAppearanceTable);
ArmorTable = GetTable<ArmorTableEntry>(arrays.m_pArmorTable);
BodyBagTable = GetTable<BodyBagTableEntry>(arrays.m_pBodyBagTable);
AppearanceTable = GetTable<AppearanceTableEntry>(arrays.GetAppearanceTable());
ArmorTable = GetTable<ArmorTableEntry>(arrays.GetArmorTable());
BodyBagTable = GetTable<BodyBagTableEntry>(arrays.GetBodyBagTable());
EffectIconTable = GetTable<EffectIconTableEntry>("effecticons.2da")!;
EnvironmentPresetTable = GetTable<EnvironmentPreset>("environment.2da")!;
LightColorTable = GetTable<LightColorTableEntry>(arrays.m_pLightColorTable);
LightColorTable = GetTable<LightColorTableEntry>(arrays.GetLightColorTable());
LoadScreenTable = GetTable<LoadScreenTableEntry>("loadscreens.2da")!;
ItemPropertyCostTables = GetTable<ItemPropertyCostTablesEntry>("iprp_costtable.2da")!;
ItemPropertyParamTables = GetTable<ItemPropertyParamTablesEntry>("iprp_paramtable.2da")!;
ItemPropertyItemMapTable = GetTable<ItemPropertyItemMapTableEntry>(arrays.m_pItemPropsTable);
ItemPropertyTable = GetTable<ItemPropertyTableEntry>(arrays.m_pItemPropDefTable);
PartsBeltTable = GetTable<PartsTableEntry>(arrays.m_pPartsBelt);
PartsBicepTable = GetTable<PartsTableEntry>(arrays.m_pPartsBicep);
PartsChestTable = GetTable<PartsTableEntry>(arrays.m_pPartsChest);
PartsFootTable = GetTable<PartsTableEntry>(arrays.m_pPartsFoot);
PartsForearmTable = GetTable<PartsTableEntry>(arrays.m_pPartsForearm);
PartsHandTable = GetTable<PartsTableEntry>(arrays.m_pPartsHand);
PartsLegTable = GetTable<PartsTableEntry>(arrays.m_pPartsLegs);
PartsNeckTable = GetTable<PartsTableEntry>(arrays.m_pPartsNeck);
PartsPelvisTable = GetTable<PartsTableEntry>(arrays.m_pPartsPelvis);
PartsRobeTable = GetTable<PartsTableEntry>(arrays.m_pPartsRobe);
PartsShinTable = GetTable<PartsTableEntry>(arrays.m_pPartsShin);
PartsShoulderTable = GetTable<PartsTableEntry>(arrays.m_pPartsShoulder);
ItemPropertyItemMapTable = GetTable<ItemPropertyItemMapTableEntry>(arrays.GetItemPropsTable());
ItemPropertyTable = GetTable<ItemPropertyTableEntry>(arrays.GetItemPropDefTable());
PartsBeltTable = GetTable<PartsTableEntry>(arrays.GetPartsBelt());
PartsBicepTable = GetTable<PartsTableEntry>(arrays.GetPartsBicep());
PartsChestTable = GetTable<PartsTableEntry>(arrays.GetPartsChest());
PartsFootTable = GetTable<PartsTableEntry>(arrays.GetPartsFoot());
PartsForearmTable = GetTable<PartsTableEntry>(arrays.GetPartsForearm());
PartsHandTable = GetTable<PartsTableEntry>(arrays.GetPartsHand());
PartsLegTable = GetTable<PartsTableEntry>(arrays.GetPartsLegs());
PartsNeckTable = GetTable<PartsTableEntry>(arrays.GetPartsNeck());
PartsPelvisTable = GetTable<PartsTableEntry>(arrays.GetPartsPelvis());
PartsRobeTable = GetTable<PartsTableEntry>(arrays.GetPartsRobe());
PartsShinTable = GetTable<PartsTableEntry>(arrays.GetPartsShin());
PartsShoulderTable = GetTable<PartsTableEntry>(arrays.GetPartsShoulder());
PlaceableSoundTable = GetTable<PlaceableSoundTableEntry>("placeableobjsnds.2da")!; // arrays.m_pPlaceableSoundsTable does not exist in nwserver.
PlaceableTable = GetTable<PlaceableTableEntry>(arrays.m_pPlaceablesTable);
PlaceableTable = GetTable<PlaceableTableEntry>(arrays.GetPlaceablesTable());
PlaceableTypeTable = GetTable<PlaceableTypeTableEntry>("placeabletypes.2da")!;
PolymorphTable = GetTable<PolymorphTableEntry>(arrays.m_pPolymorphTable);
PortraitTable = GetTable<PortraitTableEntry>(arrays.m_pPortraitTable);
VisualEffectTable = GetTable<VisualEffectTableEntry>(arrays.m_pVisualEffectTable);
PolymorphTable = GetTable<PolymorphTableEntry>(arrays.GetPolymorphTable());
PortraitTable = GetTable<PortraitTableEntry>(arrays.GetPortraitTable());
VisualEffectTable = GetTable<VisualEffectTableEntry>(arrays.GetVisualEffectTable());
ProgrammedEffectTable = GetTable<ProgrammedEffectTableEntry>("progfx.2da")!; // arrays.m_pProgFxTable does not exist in nwserver.
PersistentEffectTable = GetTable<PersistentVfxTableEntry>(arrays.m_pPersistentVisualEffectTable); // arrays.m_pProgFxTable does not exist in nwserver.
PersistentEffectTable = GetTable<PersistentVfxTableEntry>(arrays.GetPersistentVisualEffectTable()); // arrays.m_pProgFxTable does not exist in nwserver.
DamageLevelTable = GetTable<DamageLevelEntry>("damagelevels.2da")!; // arrays.m_pDamageLevelTable does not exist in nwserver.
ExpTable = GetTable<ExpTableEntry>("exptable.2da")!;
SkillItemCostTable = GetTable<SkillItemCostTableEntry>(arrays.m_pSkillVsItemCostTable);
SkillItemCostTable = GetTable<SkillItemCostTableEntry>(arrays.GetSkillVsItemCostTable());
}

private void OnReloadAll(void* pRules)
Expand Down
4 changes: 2 additions & 2 deletions NWN.Anvil/src/main/API/Utils/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ internal IEnumerable<ScriptParam> GetCurrentContextScriptParams()

private int PopScriptContext()
{
CNWVirtualMachineCommands cmd = CNWVirtualMachineCommands.FromPointer(virtualMachine.m_pCmdImplementer.Pointer);
CNWSVirtualMachineCommands cmd = CNWSVirtualMachineCommands.FromPointer(virtualMachine.m_pCmdImplementer.Pointer);

if (--virtualMachine.m_nRecursionLevel != -1)
{
Expand All @@ -194,7 +194,7 @@ private int PopScriptContext()

private int PushScriptContext(uint oid, int scriptEventId)
{
CNWVirtualMachineCommands cmd = CNWVirtualMachineCommands.FromPointer(virtualMachine.m_pCmdImplementer.Pointer);
CNWSVirtualMachineCommands cmd = CNWSVirtualMachineCommands.FromPointer(virtualMachine.m_pCmdImplementer.Pointer);
bool valid = LowLevel.ServerExoApp.GetGameObject(oid) != null;

if (virtualMachine.m_nRecursionLevel++ == -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static class CNWSCreatureStats
[NativeFunction("_ZN17CNWSCreatureStats7LevelUpEP13CNWLevelStatshhhi", "?LevelUp@CNWSCreatureStats@@QEAAXPEAVCNWLevelStats@@EEEH@Z")]
public delegate void LevelUp(void* pCreatureStats, void* pLevelUpStats, byte nDomain1, byte nDomain2, byte nSchool, int bAddStatsToList);

[NativeFunction("_ZN17CNWSCreatureStats16LevelUpAutomaticEhih", "?LevelUpAutomatic@CNWSCreatureStats@@QEAAHEHE@Z")]
public delegate void LevelUpAutomatic(void* pCreatureStats, byte nClass, int bReadyAllSpells, byte nPackage);
[NativeFunction("_ZN17CNWSCreatureStats16LevelUpAutomaticEhij", "?LevelUpAutomatic@CNWSCreatureStats@@QEAAHEHI@Z")]
public delegate void LevelUpAutomatic(void* pCreatureStats, byte nClass, int bReadyAllSpells, uint nPackage);

[NativeFunction("_ZN17CNWSCreatureStats21SetMemorizedSpellSlotEhhjhhi", "?SetMemorizedSpellSlot@CNWSCreatureStats@@QEAAHEEIEEH@Z")]
public delegate int SetMemorizedSpellSlot(void* pCreatureStats, byte nMultiClass, byte nSpellSlot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ private void OnResolveInitiative(void* pCreature)
int mod = pStats.GetDEXMod(0);
if (pStats.HasFeat((ushort)Feat.EpicSuperiorInitiative).ToBool())
{
mod += rules.GetRulesetIntEntry("EPIC_SUPERIOR_INITIATIVE_BONUS".ToExoString(), 8);
mod += rules.GetRulesetIntEntry(RulesetKeys.EPIC_SUPERIOR_INITIATIVE_BONUS, 8);
}

else if (pStats.HasFeat((ushort)Feat.ImprovedInitiative).ToBool())
{
mod += rules.GetRulesetIntEntry("IMPROVED_INITIATIVE_BONUS".ToExoString(), 4);
mod += rules.GetRulesetIntEntry(RulesetKeys.IMPROVED_INITIATIVE_BONUS, 4);
}

if (pStats.HasFeat((ushort)Feat.Blooded).ToBool())
{
mod += rules.GetRulesetIntEntry("BLOODED_INITIATIVE_BONUS".ToExoString(), 2);
mod += rules.GetRulesetIntEntry(RulesetKeys.BLOODED_INITIATIVE_BONUS, 2);
}

if (pStats.HasFeat((ushort)Feat.Thug).ToBool())
{
mod += rules.GetRulesetIntEntry("THUG_INITIATIVE_BONUS".ToExoString(), 2);
mod += rules.GetRulesetIntEntry(RulesetKeys.THUG_INITIATIVE_BONUS, 2);
}

// Add creature bonus
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Anvil.API;
using Anvil.API.Events;
using Anvil.Internal;
Expand Down Expand Up @@ -257,22 +258,7 @@ private bool IsCreatureInLastUpdateObjectList(NwPlayer observer, NwPlayer target
return true;
}

CExoLinkedListInternal partyObjectsList = nwPlayer.m_pActivePartyObjectsLastUpdate.m_pcExoLinkedListInternal;
if (partyObjectsList == null)
{
return false;
}

for (CExoLinkedListNode head = partyObjectsList.pHead; head != null; head = head.pNext)
{
CLastUpdatePartyObject partyMember = CLastUpdatePartyObject.FromPointer(head.pObject);
if (partyMember != null && partyMember.m_nPlayerId == target.ControlledCreature?.ObjectId)
{
return true;
}
}

return false;
return nwPlayer.m_lstActivePartyObjectsLastUpdate.Any(partyObject => partyObject.m_nPlayerId == target.ControlledCreature?.ObjectId);
}

private bool IsValidCreature(CNWSCreature? creature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private uint OnAIActionRest(void* pCreature, void* pNode)
byte creatureLevel = creature.m_pStats.GetLevel(0);
int originalValue;

C2DA durationTable = NWNXLib.Rules().m_p2DArrays.m_pRestDurationTable;
C2DA durationTable = NWNXLib.Rules().m_p2DArrays.GetRestDurationTable();

durationTable.GetINTEntry(creatureLevel, DurationTableKey, &originalValue);
durationTable.SetINTEntry(creatureLevel, DurationTableKey, durationOverride);
Expand Down
16 changes: 8 additions & 8 deletions NWN.Anvil/src/main/Services/ELC/EnforceLegalCharacterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public EnforceLegalCharacterService(VirtualMachine virtualMachine, HookService h
skills = CNWSkillArray.FromPointer(pRules.m_lstSkills);
feats = CNWFeatArray.FromPointer(pRules.m_lstFeats);

epicGreatStatBonus = pRules.GetRulesetIntEntry("CRULES_EPIC_GREAT_STAT_BONUS".ToExoString(), 1);
charGenBaseAbilityMin = pRules.GetRulesetIntEntry("CHARGEN_BASE_ABILITY_MIN".ToExoString(), 8);
charGenBaseAbilityMax = pRules.GetRulesetIntEntry("CHARGEN_BASE_ABILITY_MAX".ToExoString(), 18);
abilityCostIncrement2 = pRules.GetRulesetIntEntry("CHARGEN_ABILITY_COST_INCREMENT2".ToExoString(), 14);
abilityCostIncrement3 = pRules.GetRulesetIntEntry("CHARGEN_ABILITY_COST_INCREMENT3".ToExoString(), 16);
skillMaxLevel1Bonus = pRules.GetRulesetIntEntry("CHARGEN_SKILL_MAX_LEVEL_1_BONUS".ToExoString(), 3);
epicGreatStatBonus = pRules.GetRulesetIntEntry(RulesetKeys.EPIC_GREAT_STAT_BONUS, 1);
charGenBaseAbilityMin = pRules.GetRulesetIntEntry(RulesetKeys.CHARGEN_BASE_ABILITY_MIN, 8);
charGenBaseAbilityMax = pRules.GetRulesetIntEntry(RulesetKeys.CHARGEN_BASE_ABILITY_MAX, 18);
abilityCostIncrement2 = pRules.GetRulesetIntEntry(RulesetKeys.CHARGEN_ABILITY_COST_INCREMENT2, 14);
abilityCostIncrement3 = pRules.GetRulesetIntEntry(RulesetKeys.CHARGEN_ABILITY_COST_INCREMENT3, 16);
skillMaxLevel1Bonus = pRules.GetRulesetIntEntry(RulesetKeys.CHARGEN_SKILL_MAX_LEVEL_1_BONUS, 3);
}

public event Action<OnELCCustomCheck>? OnCustomCheck;
Expand Down Expand Up @@ -325,7 +325,7 @@ private int OnValidateCharacter(void* player, int* bFailedServerRestriction)
}
// **********************************************************************************************************************

if (pCreatureStats.m_nNumMultiClasses > Math.Clamp(NWNXLib.Rules().GetRulesetIntEntry("MULTICLASS_LIMIT".ToExoString(), 3), 1, 8))
if (pCreatureStats.m_nNumMultiClasses > Math.Clamp(NWNXLib.Rules().GetRulesetIntEntry(RulesetKeys.MULTICLASS_LIMIT, 3), 1, 8))
{
if (HandleValidationFailure(out int strRefFailure, new OnELCValidationFailure
{
Expand Down Expand Up @@ -1764,7 +1764,7 @@ int GetSkillPointAbilityAdjust()
if (nSchool != 0)
{
int nOppositionSchool;
if (pRules.m_p2DArrays.m_pSpellSchoolTable.GetINTEntry(nSchool, "Opposition".ToExoString(), &nOppositionSchool).ToBool())
if (pRules.m_p2DArrays.GetSpellSchoolTable().GetINTEntry(nSchool, "Opposition".ToExoString(), &nOppositionSchool).ToBool())
{
if (pSpell.m_nSchool == nOppositionSchool)
{
Expand Down
22 changes: 6 additions & 16 deletions NWN.Anvil/src/main/Services/Resources/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.InteropServices;
using Anvil.API;
using NLog;
using NWN.Core;
using NWN.Native.API;
using ResRefType = Anvil.API.ResRefType;

Expand Down Expand Up @@ -122,20 +123,9 @@ public IEnumerable<string> FindResourcesOfType(ResRefType type, bool moduleOnly
/// </summary>
/// <param name="scriptName">The name of the script to get the contents of.</param>
/// <returns>The script file contents or "" on error.</returns>
public string? GetNSSContents(CExoString scriptName)
public string GetNSSContents(string scriptName)
{
CScriptSourceFile scriptSourceFile = new CScriptSourceFile();
byte* data;
uint size = 0;

if (scriptSourceFile.LoadScript(scriptName, &data, &size) == 0)
{
string retVal = StringHelper.ReadFixedLengthString(data, (int)size);
scriptSourceFile.UnloadScript();
return retVal;
}

return null;
return NWScript.ResManGetFileContents(scriptName, NWScript.RESTYPE_NSS);
}

/// <summary>
Expand All @@ -149,8 +139,8 @@ public IEnumerable<string> FindResourcesOfType(ResRefType type, bool moduleOnly
switch (type)
{
case ResRefType.NSS:
string? source = GetNSSContents(name.ToExoString());
return source != null ? StringHelper.Encoding.GetBytes(source) : null;
string source = GetNSSContents(name);
return StringHelper.Encoding.GetBytes(source);
case ResRefType.NCS:
return null;
default:
Expand All @@ -169,7 +159,7 @@ public IEnumerable<string> FindResourcesOfType(ResRefType type, bool moduleOnly
switch (type)
{
case ResRefType.NSS:
return GetNSSContents(name.ToExoString());
return GetNSSContents(name);
case ResRefType.NCS:
return null;
default:
Expand Down
2 changes: 1 addition & 1 deletion NWN.Anvil/src/main/Services/Weapon/WeaponService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private int OnGetAttackModifierVersus(void* pStats, void* pCreature)

if (EnableSlingGoodAimFeat && baseItem == (uint)BaseItem.Sling && stats.m_nRace != (ushort)RacialType.Halfling && stats.HasFeat((ushort)Feat.GoodAim).ToBool())
{
int goodAimModifier = NWNXLib.Rules().GetRulesetIntEntry("GOOD_AIM_MODIFIER".ToExoString(), 1);
int goodAimModifier = NWNXLib.Rules().GetRulesetIntEntry(RulesetKeys.GOOD_AIM_MODIFIER, 1);
attackMod += goodAimModifier;

if ((*NWNXLib.EnableCombatDebugging()).ToBool() && stats.m_bIsPC.ToBool())
Expand Down

0 comments on commit 2b4b442

Please sign in to comment.