Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetModuleFile() to the Util functions #1666

Merged
merged 11 commits into from
Jul 3, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ https://github.com/nwnxee/unified/compare/build8193.35.40...HEAD
- Object: GetLastSpellInstant()
- Creature: {Get|Set}MaxSellToStorePriceOverride()
- Creature: {Get|Set}AbilityIncreaseByLevel()
- Util: GetModuleFile()

### Changed
- Creature: Added an argument for passing a class package to `NWNX_Creature_LevelUp()`
Expand Down
10 changes: 10 additions & 0 deletions Plugins/Util/NWScript/nwnx_util.nss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ int NWNX_Util_Hash(string str);
/// @return The mtime of the module file.
int NWNX_Util_GetModuleMtime();

/// @brief Gets the module short file name.
/// @return The module file as a string.
string NWNX_Util_GetModuleFile();

/// @brief Gets the value of customTokenNumber.
/// @param customTokenNumber The token number to query.
/// @return The string representation of the token value.
Expand Down Expand Up @@ -275,6 +279,12 @@ int NWNX_Util_GetModuleMtime()
return NWNX_GetReturnValueInt();
}

string NWNX_Util_GetModuleFile()
{
NWNX_CallFunction(NWNX_Util, "GetModuleFile");
return NWNX_GetReturnValueString();
}

string NWNX_Util_GetCustomToken(int customTokenNumber)
{
string sFunc = "GetCustomToken";
Expand Down
3 changes: 3 additions & 0 deletions Plugins/Util/NWScript/nwnx_util_t.nss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void main()
"t2.seconds: " + IntToString(t2.seconds) + "; " +
"t2.microseconds: " + IntToString(t2.microseconds) + "; ");
NWNX_Tests_Report("NWNX_Util", "GetHighResTimeStamp", t1.microseconds != t2.microseconds);

string sModMame = NWNX_Util_GetModuleFile();
NWNX_Tests_Report("NWNX_Util", "GetModuleFile", sModMame != "");

WriteTimestampedLogEntry("NWNX_Util unit test end.");
}
6 changes: 6 additions & 0 deletions Plugins/Util/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ NWNX_EXPORT ArgumentStack GetModuleMtime(ArgumentStack&&)
return 0;
}

NWNX_EXPORT ArgumentStack GetModuleFile(ArgumentStack&&)
{
CNWSModule *pMod = Utils::GetModule();
return pMod->m_sModuleResourceName.SubString(12); // discard "CURRENTGAME:"
}

NWNX_EXPORT ArgumentStack GetCustomToken(ArgumentStack&& args)
{
std::string retVal;
Expand Down