Skip to content

Commit

Permalink
Update APIs (NWNX: aacaa9f, NWN: 8193.36-12).
Browse files Browse the repository at this point in the history
  • Loading branch information
jhett12321 committed Aug 16, 2024
1 parent 6cb45c0 commit 0266079
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/NWNX/Plugins/DamagePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static DamageEventData GetDamageEventData()
data.iCustom17 = VM.NWNX.StackPopInt();
data.iCustom18 = VM.NWNX.StackPopInt();
data.iCustom19 = VM.NWNX.StackPopInt();
data.iSpellId = VM.NWNX.StackPopInt();
return data;
}

Expand Down Expand Up @@ -312,6 +313,7 @@ public struct DamageEventData
public int iCustom17;
public int iCustom18;
public int iCustom19;
public int iSpellId;
}

public struct AttackEventData
Expand Down
109 changes: 109 additions & 0 deletions src/NWNX/Plugins/HttpclientPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using static NWN.Core.NWScript;

namespace NWN.Core.NWNX
{
[NWNXPlugin(NWNX_HTTPClient)]
public class HttpclientPlugin
{
public const string NWNX_HTTPClient = "NWNX_HTTPClient";

///< @private
/// @name Request Types
/// @anchor request_types
///
/// @{
public const int NWNX_HTTPCLIENT_REQUEST_METHOD_GET = 0;
public const int NWNX_HTTPCLIENT_REQUEST_METHOD_POST = 1;
public const int NWNX_HTTPCLIENT_REQUEST_METHOD_DELETE = 2;
public const int NWNX_HTTPCLIENT_REQUEST_METHOD_PATCH = 3;
public const int NWNX_HTTPCLIENT_REQUEST_METHOD_PUT = 4;
public const int NWNX_HTTPCLIENT_REQUEST_METHOD_OPTION = 5;
public const int NWNX_HTTPCLIENT_REQUEST_METHOD_HEAD = 6;

///@}
/// @name Content Types
/// @anchor content_types
///
/// @{
public const int NWNX_HTTPCLIENT_CONTENT_TYPE_HTML = 0;
public const int NWNX_HTTPCLIENT_CONTENT_TYPE_PLAINTEXT = 1;
public const int NWNX_HTTPCLIENT_CONTENT_TYPE_JSON = 2;
public const int NWNX_HTTPCLIENT_CONTENT_TYPE_FORM_URLENCODED = 3;
public const int NWNX_HTTPCLIENT_CONTENT_TYPE_XML = 4;

///@}
/// @name HTTP Authentication Types
/// @anchor auth_types
///
/// @{
public const int NWNX_HTTPCLIENT_AUTH_TYPE_NONE = 0;
public const int NWNX_HTTPCLIENT_AUTH_TYPE_BASIC = 1;
public const int NWNX_HTTPCLIENT_AUTH_TYPE_DIGEST = 2;
public const int NWNX_HTTPCLIENT_AUTH_TYPE_BEARER_TOKEN = 3;

///@}
/// A structure for an HTTP Client Request
/// Sends an http method to the given host.
/// <param name="s">The structured NWNX_HTTPClient_Request information.</param>
/// <returns>A unique identifier for the request for later access in the REQUEST_ID event data.</returns>
public static int SendRequest(Request s)
{
const string sFunc = "SendRequest";
VM.NWNX.SetFunction(NWNX_HTTPClient, sFunc);
VM.NWNX.StackPush(s.sHeaders);
VM.NWNX.StackPush(s.nPort);
VM.NWNX.StackPush(s.sAuthPassword);
VM.NWNX.StackPush(s.sAuthUserOrToken);
VM.NWNX.StackPush(s.nAuthType);
VM.NWNX.StackPush(s.sData);
VM.NWNX.StackPush(s.nContentType);
VM.NWNX.StackPush(s.sPath);
VM.NWNX.StackPush(s.sHost);
VM.NWNX.StackPush(s.nRequestMethod);
VM.NWNX.StackPush(s.sTag);
VM.NWNX.Call();
return VM.NWNX.StackPopInt();
}

/// Returns an NWNX_HTTP_Client_Request structure
/// <param name="nRequestId">The request id returned from NWNX_HTTPClient_SendRequest()</param>
/// <returns>The structured NWNX_HTTPClient_Request information</returns>
public static Request GetRequest(int nRequestId)
{
const string sFunc = "GetRequest";
VM.NWNX.SetFunction(NWNX_HTTPClient, sFunc);
VM.NWNX.StackPush(nRequestId);
VM.NWNX.Call();
Request s = default;
s.sTag = VM.NWNX.StackPopString();
s.nRequestMethod = VM.NWNX.StackPopInt();
s.sHost = VM.NWNX.StackPopString();
s.sPath = VM.NWNX.StackPopString();
s.nContentType = VM.NWNX.StackPopInt();
s.sData = VM.NWNX.StackPopString();
s.nAuthType = VM.NWNX.StackPopInt();
s.sAuthUserOrToken = VM.NWNX.StackPopString();
s.sAuthPassword = VM.NWNX.StackPopString();
s.nPort = VM.NWNX.StackPopInt();
s.sHeaders = VM.NWNX.StackPopString();
return s;
}

// @}
}

public struct Request
{
public int nRequestMethod;
public string sTag;
public string sHost;
public string sPath;
public string sData;
public int nContentType;
public int nAuthType;
public string sAuthUserOrToken;
public string sAuthPassword;
public int nPort;
public string sHeaders;
}
}
33 changes: 33 additions & 0 deletions src/NWNX/Plugins/ObjectPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,39 @@ public static void SetTrapCreator(uint oObject, uint oCreator)
VM.NWNX.Call();
}

/// Return the name of the object for nLanguage.
/// <param name="oObject">an object</param>
/// <param name="nLanguage">A PLAYER_LANGUAGE constant.</param>
/// <param name="nGender"> Gender to use, 0 or 1.</param>
/// <returns>The localized string.</returns>
public static string GetLocalizedName(uint oObject, int nLanguage, int nGender = 0)
{
const string sFunc = "GetLocalizedName";
VM.NWNX.SetFunction(NWNX_Object, sFunc);
VM.NWNX.StackPush(nGender);
VM.NWNX.StackPush(nLanguage);
VM.NWNX.StackPush(oObject);
VM.NWNX.Call();
return VM.NWNX.StackPopString();
}

/// Set the name of the object as set in the toolset for nLanguage.
/// @note You may have to SetName(oObject, &quot;&quot;) for the translated string to show.
/// <param name="oObject">an object</param>
/// <param name="sName">New value to set</param>
/// <param name="nLanguage">A PLAYER_LANGUAGE constant.</param>
/// <param name="nGender"> Gender to use, 0 or 1.</param>
public static void SetLocalizedName(uint oObject, string sName, int nLanguage, int nGender = 0)
{
const string sFunc = "SetLocalizedName";
VM.NWNX.SetFunction(NWNX_Object, sFunc);
VM.NWNX.StackPush(nGender);
VM.NWNX.StackPush(nLanguage);
VM.NWNX.StackPush(sName);
VM.NWNX.StackPush(oObject);
VM.NWNX.Call();
}

// @}
}

Expand Down
24 changes: 23 additions & 1 deletion src/NWNX/Plugins/PlayerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,12 @@ public static void SetCreatureNameOverride(uint oPlayer, uint oCreature, string
/// <param name="oPlayer">The player to display the text to.</param>
/// <param name="oCreature">The creature to display the text above.</param>
/// <param name="sText">The text to display.</param>
public static void FloatingTextStringOnCreature(uint oPlayer, uint oCreature, string sText)
/// <param name="bChatWindow">If TRUE, sText will be displayed in oPlayer&apos;s chat window.</param>
public static void FloatingTextStringOnCreature(uint oPlayer, uint oCreature, string sText, int bChatWindow = TRUE)
{
const string sFunc = "FloatingTextStringOnCreature";
VM.NWNX.SetFunction(NWNX_Player, sFunc);
VM.NWNX.StackPush(bChatWindow);
VM.NWNX.StackPush(sText);
VM.NWNX.StackPush(oCreature);
VM.NWNX.StackPush(oPlayer);
Expand Down Expand Up @@ -806,6 +808,16 @@ public static void SetTlkOverride(uint oPlayer, int nStrRef, string sOverride, i
VM.NWNX.Call();
}

/// Make the player reload it&apos;s TlkTable.
/// <param name="oPlayer">The player.</param>
public static void ReloadTlk(uint oPlayer)
{
const string sFunc = "ReloadTlk";
VM.NWNX.SetFunction(NWNX_Player, sFunc);
VM.NWNX.StackPush(oPlayer);
VM.NWNX.Call();
}

/// Update wind for oPlayer only.
/// <param name="oPlayer">The player.</param>
/// <param name="vDirection">The Wind&apos;s direction.</param>
Expand Down Expand Up @@ -920,6 +932,16 @@ public static uint GetTURD(uint oPlayer)
return VM.NWNX.StackPopObject();
}

/// Reloads the color palettes for oPlayer
/// <param name="oPlayer">The player to reload the color palette for</param>
public static void ReloadColorPalettes(uint oPlayer)
{
const string sFunc = "ReloadColorPalettes";
VM.NWNX.SetFunction(NWNX_Player, sFunc);
VM.NWNX.StackPush(oPlayer);
VM.NWNX.Call();
}

// @}
public static void INTERNAL_StopGuiTimingBar(uint player, string script = "", int id = -1)
{
Expand Down
9 changes: 9 additions & 0 deletions src/NWNX/Plugins/SqlPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ public static void PreparedNULL(int position)
VM.NWNX.Call();
}

/// Set the Json value of a prepared statement at given position.
/// Convienence function to match other Prepared(type) functions.
/// <param name="position">The nth ? in a prepared statement.</param>
/// <param name="value">The value to set.</param>
public static void PreparedJson(int position, System.IntPtr value)
{
PreparedString(position, JsonDump(value));
}

/// Like NWNX_SQL_ReadDataInActiveRow, but for full serialized objects.
///
/// The object will be deserialized and created in the game. New object ID is returned.
Expand Down
111 changes: 111 additions & 0 deletions src/NWNX/Plugins/StorePlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using static NWN.Core.NWScript;

namespace NWN.Core.NWNX
{
[NWNXPlugin(NWNX_Store)]
public class StorePlugin
{
public const string NWNX_Store = "NWNX_Store";

///&lt; @private
/// Return status of a base item purchase status.
/// <param name="oStore">The store object.</param>
/// <param name="nBaseItem">A BASE_ITEM_* value</param>
/// <returns>TRUE if the quest has been completed. -1 if the player does not have the journal entry.</returns>
public static int GetIsRestrictedBuyItem(uint oStore, int nBaseItem)
{
const string sFunc = "GetIsRestrictedBuyItem";
VM.NWNX.SetFunction(NWNX_Store, sFunc);
VM.NWNX.StackPush(nBaseItem);
VM.NWNX.StackPush(oStore);
VM.NWNX.Call();
return VM.NWNX.StackPopInt();
}

/// Return the blackmarket mark down of a store
/// <param name="oStore">The store object.</param>
/// <returns>mark down of a store, -1 on error</returns>
public static int GetBlackMarketMarkDown(uint oStore)
{
const string sFunc = "GetBlackMarketMarkDown";
VM.NWNX.SetFunction(NWNX_Store, sFunc);
VM.NWNX.StackPush(oStore);
VM.NWNX.Call();
return VM.NWNX.StackPopInt();
}

/// Set the blackmarket mark down of a store
/// <param name="oStore">The store object.</param>
/// <param name="nValue">The amount.</param>
public static void SetBlackMarketMarkDown(uint oStore, int nValue)
{
const string sFunc = "SetBlackMarketMarkDown";
VM.NWNX.SetFunction(NWNX_Store, sFunc);
VM.NWNX.StackPush(nValue);
VM.NWNX.StackPush(oStore);
VM.NWNX.Call();
}

/// Return the mark down of a store
/// <param name="oStore">The store object.</param>
/// <returns>mark down of a store, -1 on error</returns>
public static int GetMarkDown(uint oStore)
{
const string sFunc = "GetMarkDown";
VM.NWNX.SetFunction(NWNX_Store, sFunc);
VM.NWNX.StackPush(oStore);
VM.NWNX.Call();
return VM.NWNX.StackPopInt();
}

/// Set the mark down of a store
/// <param name="oStore">The store object.</param>
/// <param name="nValue">The amount.</param>
public static void SetMarkDown(uint oStore, int nValue)
{
const string sFunc = "SetMarkDown";
VM.NWNX.SetFunction(NWNX_Store, sFunc);
VM.NWNX.StackPush(nValue);
VM.NWNX.StackPush(oStore);
VM.NWNX.Call();
}

/// Return the mark up of a store
/// <param name="oStore">The store object.</param>
/// <returns>mark up of a store, -1 on error</returns>
public static int GetMarkUp(uint oStore)
{
const string sFunc = "GetMarkUp";
VM.NWNX.SetFunction(NWNX_Store, sFunc);
VM.NWNX.StackPush(oStore);
VM.NWNX.Call();
return VM.NWNX.StackPopInt();
}

/// Set the mark up of a store
/// <param name="oStore">The store object.</param>
/// <param name="nValue">The amount.</param>
public static void SetMarkUp(uint oStore, int nValue)
{
const string sFunc = "SetMarkUp";
VM.NWNX.SetFunction(NWNX_Store, sFunc);
VM.NWNX.StackPush(nValue);
VM.NWNX.StackPush(oStore);
VM.NWNX.Call();
}

/// Return current customer count
/// <param name="oStore">The store object.</param>
/// <returns>count, or -1 on error</returns>
public static int GetCurrentCustomersCount(uint oStore)
{
const string sFunc = "GetCurrentCustomersCount";
VM.NWNX.SetFunction(NWNX_Store, sFunc);
VM.NWNX.StackPush(oStore);
VM.NWNX.Call();
return VM.NWNX.StackPopInt();
}

// @}
}
}
10 changes: 10 additions & 0 deletions src/NWNX/Plugins/UtilPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,16 @@ public static int CleanResourceDirectory(string sAlias, int nResType = 65535)
return VM.NWNX.StackPopInt();
}

/// Return the filename of the tlk file.
/// <returns>The name</returns>
public static string GetModuleTlkFile()
{
const string sFunc = "GetModuleTlkFile";
VM.NWNX.SetFunction(NWNX_Util, sFunc);
VM.NWNX.Call();
return VM.NWNX.StackPopString();
}

// @}
}

Expand Down

0 comments on commit 0266079

Please sign in to comment.