Skip to content

Commit

Permalink
8193.37-13 Support (#1804)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daztek authored Jan 9, 2025
1 parent 09544eb commit b4c211f
Show file tree
Hide file tree
Showing 246 changed files with 65,597 additions and 14,035 deletions.
42 changes: 40 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,43 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased
https://github.com/nwnxee/unified/compare/build8193.36.12...HEAD
https://github.com/nwnxee/unified/compare/build8193.37.13...HEAD

### Added
- N/A

##### New Plugins
- N/A

##### New NWScript Functions
- N/A

### Changed
- N/A

### Deprecated
- N/A

### Removed
- N/A

### Fixed
- N/A

## 8193.37.13
https://github.com/nwnxee/unified/compare/build8193.36.10...build8193.37.13

**Notice: NWNX API Update**

The NWNX API has been updated, resulting in the removal of nwnx.nss. All nwnx_*.nss files have been modified to use the new API functions.

What You Need to Do:

* Replace all outdated NWNX include files with the updated versions.
* Update your custom nwnx_*.nss files to use the new API.
* Recompile your module

Calling NWNX functions when NWNX is not running will now **abort the script**. To prevent this, use the base game function NWNXGetIsAvailable() to check if NWNX is available before making any NWNX function calls.

### Added
- DotNET: Added `NWNX_DOTNET_METHOD` option to change entrypoint method (default: `Bootstrap`)
Expand Down Expand Up @@ -43,13 +79,15 @@ https://github.com/nwnxee/unified/compare/build8193.36.12...HEAD
- Item: Added parameter `bUpdateCreatureAppearance` to SetItemAppearance() to update the appearance of the item's possessor.
- Events: Added PLAYER_NAME, CDKEY as event data to the client disconnect events `NWNX_ON_CLIENT_DISCONNECT_{BEFORE|AFTER}`.
- Profiler: fixed order of parameters in nss script for PushPerfScope()
- Core: **!!Breaking Change!!** `NWNX_PluginExists` has been renamed to `NWNX_Core_PluginExists` and moved to `nwnx_core.nss`

### Deprecated
- DotNET: GetFunctionPointer()
- DotNET: GetNWNXExportedGlobals()

### Removed
- N/A
- ServerLogRedirector: removed `NWNX_SERVERLOGREDIRECTOR_HIDE_VALIDATEGFFRESOURCE_MESSAGES`
- Tweaks: removed `NWNX_TWEAKS_FIX_ITEM_NULLPTR_IN_CITEMREPOSITORY`

### Fixed
- Race: Documentation updated as `NWNX_Utils` is no longer required with introduction of native `Get2DARowCount()`.
Expand Down
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ find_package(Sanitizers)

execute_process(COMMAND git rev-parse --short HEAD OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE SHORT_HASH)
set(TARGET_NWN_BUILD 8193)
set(TARGET_NWN_BUILD_REVISION 36)
set(TARGET_NWN_BUILD_POSTFIX 12)
set(TARGET_NWN_BUILD_REVISION 37)
set(TARGET_NWN_BUILD_POSTFIX 13)
set(NWNX_BUILD_SHA ${SHORT_HASH})
set(PLUGIN_PREFIX NWNX_)

Expand Down Expand Up @@ -69,6 +69,17 @@ add_definitions(-DNWNX_TARGET_NWN_BUILD_REVISION=${TARGET_NWN_BUILD_REVISION})
add_definitions(-DNWNX_TARGET_NWN_BUILD_POSTFIX=${TARGET_NWN_BUILD_POSTFIX})
add_definitions(-DNWNX_BUILD_SHA="${NWNX_BUILD_SHA}")

# Tracy stuff, not sure if all of it is actually needed
string(LENGTH "${CMAKE_SOURCE_DIR}/" CMAKE_SOURCE_DIR_LENGTH)
add_definitions("-DCMAKE_SOURCE_DIR_LENGTH=${CMAKE_SOURCE_DIR_LENGTH}")
add_definitions(-DTRACY_ENABLE)
add_definitions(-DTRACY_ON_DEMAND)
add_definitions(-DTRACY_NO_CODE_TRANSFER)
add_definitions(-DTRACY_MANUAL_LIFETIME -DTRACY_DELAYED_INIT)
add_definitions(-DTRACY_NO_BROADCAST)
add_definitions(-DTRACY_ONLY_IPV4)
add_definitions(-DTRACY_NO_CRASH_HANDLER)

# Provides the NWN API and other useful things as a static lib.
add_subdirectory(NWNXLib)

Expand Down
1 change: 0 additions & 1 deletion Compatibility/nwnx_time.nss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/// @brief Provides various time related functions
/// @{
/// @file nwnx_time.nss
#include "nwnx"
#include "nwnx_util"
#include "inc_sqlite_time"

Expand Down
109 changes: 54 additions & 55 deletions Core/NWNXCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,10 @@ void NWNXCore::ConfigureLogLevel(const std::string& plugin)

void NWNXCore::InitialSetupHooks()
{
m_vmSetVarHook = Hooks::HookFunction(&CNWSVirtualMachineCommands::ExecuteCommandSetVar, &SetVarHandler, Hooks::Order::Final);
m_vmGetVarHook = Hooks::HookFunction(&CNWSVirtualMachineCommands::ExecuteCommandGetVar, &GetVarHandler, Hooks::Order::Final);
m_vmTagEffectHook = Hooks::HookFunction(&CNWSVirtualMachineCommands::ExecuteCommandTagEffect, &TagEffectHandler, Hooks::Order::Final);
m_vmTagItemProperyHook = Hooks::HookFunction(&CNWSVirtualMachineCommands::ExecuteCommandTagItemProperty, &TagItemPropertyHandler, Hooks::Order::Final);
m_vmPlaySoundHook = Hooks::HookFunction(&CNWSVirtualMachineCommands::ExecuteCommandPlaySound, &PlaySoundHandler, Hooks::Order::Final);


m_destroyServerHook = Hooks::HookFunction(&CAppManager::DestroyServer, &DestroyServerHandler, Hooks::Order::Final);
m_mainLoopInternalHook = Hooks::HookFunction(&CServerExoAppInternal::MainLoop, &MainLoopInternalHandler, Hooks::Order::Final);
m_vmPlaySoundHook = Hooks::HookFunction(&CNWSVirtualMachineCommands::ExecuteCommandPlaySound, &PlaySoundHandler, Hooks::Order::Final);
m_nwnxFunctionManagementHook = Hooks::HookFunction(&CNWSVirtualMachineCommands::ExecuteCommandNWNXFunctionManagement, &NWNXFunctionManagementHandler, Hooks::Order::Final);
m_destroyServerHook = Hooks::HookFunction(&CAppManager::DestroyServer, &DestroyServerHandler, Hooks::Order::Final);
m_mainLoopInternalHook = Hooks::HookFunction(&CServerExoAppInternal::MainLoop, &MainLoopInternalHandler, Hooks::Order::Final);

POS::InitializeHooks();

Expand Down Expand Up @@ -367,69 +362,73 @@ void NWNXCore::InitialSetupPlugins()

void NWNXCore::InitialSetupResourceDirectories()
{
auto nwnxResDirPath = Config::Get<std::string>("NWNX_RESOURCE_DIRECTORY_PATH", Globals::ExoBase()->m_sUserDirectory.CStr() + std::string("/nwnx"));
auto nwnxResDirPriority = Config::Get<int32_t>("NWNX_RESOURCE_DIRECTORY_PRIORITY", 70000000);
static Hooks::Hook s_SetupDefaultSearchPathHook = Hooks::HookFunction(&CExoResMan::SetupDefaultSearchPath,
+[](CExoResMan *pThis) -> void
{
s_SetupDefaultSearchPathHook->CallOriginal<void>(pThis);

std::unordered_map<std::string, std::pair<std::string, int32_t>> resourceDirectories;
resourceDirectories.emplace("NWNX", std::make_pair(nwnxResDirPath, nwnxResDirPriority));
if (g_CoreShuttingDown)
return;

if (auto customResmanDefinition = Config::Get<std::string>("CUSTOM_RESMAN_DEFINITION"))
{
std::string crdPath = *customResmanDefinition;
FILE* file = std::fopen(crdPath.c_str(), "r");
auto nwnxResDirPath = Config::Get<std::string>("NWNX_RESOURCE_DIRECTORY_PATH", Globals::ExoBase()->m_sUserDirectory.CStr() + std::string("/nwnx"));
auto nwnxResDirPriority = Config::Get<int32_t>("NWNX_RESOURCE_DIRECTORY_PRIORITY", 70000000);

if (file)
{
LOG_INFO("Custom Resman Definition File: %s", crdPath);
std::unordered_map<std::string, std::pair<std::string, int32_t>> resourceDirectories;
resourceDirectories.emplace("NWNX", std::make_pair(nwnxResDirPath, nwnxResDirPriority));

char line[640];
char alias[64];
char path[512];
int32_t priority;
if (auto customResmanDefinition = Config::Get<std::string>("CUSTOM_RESMAN_DEFINITION"))
{
std::string crdPath = *customResmanDefinition;
FILE* file = std::fopen(crdPath.c_str(), "r");

while (std::fgets(line, 640, file))
if (file)
{
if (sscanf(line, "%s %s %i", alias, path, &priority) == 3)
{
resourceDirectories.try_emplace(alias, std::make_pair(path, priority));
}
else
LOG_INFO("Custom Resman Definition File: %s", crdPath);

char line[640];
char alias[64];
char path[512];
int32_t priority;

while (std::fgets(line, 640, file))
{
std::string errorLine = std::string(line);
LOG_WARNING("Invalid Custom Resman Definition Line: %s", String::Trim(errorLine));
if (sscanf(line, "%s %s %i", alias, path, &priority) == 3)
{
resourceDirectories.try_emplace(alias, std::make_pair(path, priority));
}
else
{
std::string errorLine = std::string(line);
LOG_WARNING("Invalid Custom Resman Definition Line: %s", String::Trim(errorLine));
}
}
}

std::fclose(file);
std::fclose(file);
}
else
LOG_ERROR("Failed to open Custom Resman Definition File: %s", crdPath);
}
else
LOG_ERROR("Failed to open Custom Resman Definition File: %s", crdPath);
}

Tasks::QueueOnMainThread([resourceDirectories]
for (const auto& resDir : resourceDirectories)
{
if (g_CoreShuttingDown)
return;
CExoString alias = CExoString(resDir.first + ":");
CExoString path = CExoString(resDir.second.first);

for (const auto& resDir : resourceDirectories)
if (Globals::ExoBase()->m_pcExoAliasList->GetAliasPath(alias).IsEmpty())
{
CExoString alias = CExoString(resDir.first + ":");
CExoString path = CExoString(resDir.second.first);

if (Globals::ExoBase()->m_pcExoAliasList->GetAliasPath(alias).IsEmpty())
{
LOG_INFO("Setting up Resource Directory: %s%s (Priority: %i)", alias, path, resDir.second.second);
LOG_INFO("Setting up Resource Directory: %s%s (Priority: %i)", alias, path, resDir.second.second);

g_core->m_CustomResourceDirectoryAliases.emplace_back(resDir.first);
g_core->m_CustomResourceDirectoryAliases.emplace_back(resDir.first);

Globals::ExoBase()->m_pcExoAliasList->Add(resDir.first, path);
Globals::ExoResMan()->CreateDirectory(alias);
Globals::ExoResMan()->AddResourceDirectory(alias, resDir.second.second, true);
}
else
LOG_WARNING("Resource Directory with alias '%s' already exists. Please use nwn.ini to redefine base game resource directories.", alias);
Globals::ExoBase()->m_pcExoAliasList->Add(resDir.first, path);
Globals::ExoResMan()->CreateDirectory(alias);
Globals::ExoResMan()->AddResourceDirectory(alias, resDir.second.second, true);
}
});
else
LOG_WARNING("Resource Directory with alias '%s' already exists. Please use nwn.ini to redefine base game resource directories.", alias);
}

}, Hooks::Order::Early);
}

void NWNXCore::InitialSetupCommands()
Expand Down
16 changes: 4 additions & 12 deletions Core/NWNXCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,16 @@ class NWNXCore
NWNXCore();
~NWNXCore();

static int32_t GetVarHandler(CNWSVirtualMachineCommands*, int32_t, int32_t);
static int32_t SetVarHandler(CNWSVirtualMachineCommands*, int32_t, int32_t);
static int32_t TagEffectHandler(CNWSVirtualMachineCommands*, int32_t, int32_t);
static int32_t TagItemPropertyHandler(CNWSVirtualMachineCommands*, int32_t, int32_t);
static int32_t PlaySoundHandler(CNWSVirtualMachineCommands*, int32_t, int32_t);

std::unique_ptr<NWNXLib::Services::ServiceList> m_services;

const std::vector<std::string>& GetCustomResourceDirectoryAliases() const { return m_CustomResourceDirectoryAliases; }

NWNXLib::Hooks::Hook m_vmSetVarHook;
NWNXLib::Hooks::Hook m_vmGetVarHook;

private:
NWNXLib::Hooks::Hook m_createServerHook;
NWNXLib::Hooks::Hook m_vmTagEffectHook;
NWNXLib::Hooks::Hook m_vmTagItemProperyHook;
NWNXLib::Hooks::Hook m_vmPlaySoundHook;
NWNXLib::Hooks::Hook m_destroyServerHook;
NWNXLib::Hooks::Hook m_mainLoopInternalHook;
NWNXLib::Hooks::Hook m_vmPlaySoundHook;
NWNXLib::Hooks::Hook m_nwnxFunctionManagementHook;

std::unique_ptr<NWNXLib::Services::ProxyServiceList> m_coreServices;

Expand All @@ -57,6 +47,8 @@ class NWNXCore
static void CreateServerHandler(CAppManager*);
static void DestroyServerHandler(CAppManager*);
static int32_t MainLoopInternalHandler(CServerExoAppInternal*);
static int32_t PlaySoundHandler(CNWSVirtualMachineCommands*, int32_t, int32_t);
static int32_t NWNXFunctionManagementHandler(CNWSVirtualMachineCommands*, int32_t, int32_t);

int m_ScriptChunkRecursion;
std::vector<std::string> m_CustomResourceDirectoryAliases;
Expand Down
Loading

0 comments on commit b4c211f

Please sign in to comment.