aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj2
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters6
-rw-r--r--NorthstarDedicatedTest/clientchathooks.cpp19
-rw-r--r--NorthstarDedicatedTest/dllmain.cpp10
-rw-r--r--NorthstarDedicatedTest/localchatwriter.cpp41
-rw-r--r--NorthstarDedicatedTest/localchatwriter.h28
-rw-r--r--NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp25
-rw-r--r--NorthstarDedicatedTest/scriptservertoclientstringcommand.h3
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp4
-rw-r--r--NorthstarDedicatedTest/squirrel.h12
10 files changed, 100 insertions, 50 deletions
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
index 554825f1..083ae51f 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
@@ -561,6 +561,7 @@
<ClInclude Include="scriptsrson.h" />
<ClInclude Include="serverauthentication.h" />
<ClInclude Include="sha256.h" />
+ <ClInclude Include="scriptservertoclientstringcommand.h" />
<ClInclude Include="sigscanning.h" />
<ClInclude Include="socketcreator.h" />
<ClInclude Include="sourceconsole.h" />
@@ -630,6 +631,7 @@
<ClCompile Include="miscserverscript.cpp" />
<ClCompile Include="serverchathooks.cpp" />
<ClCompile Include="sha256.cpp" />
+ <ClCompile Include="scriptservertoclientstringcommand.cpp" />
<ClCompile Include="sigscanning.cpp" />
<ClCompile Include="socketcreator.cpp" />
<ClCompile Include="sourceconsole.cpp" />
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
index 8caebc3b..38428d12 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
@@ -1471,6 +1471,9 @@
<Filter>Header Files\Client</Filter>
</ClInclude>
<ClInclude Include="localchatwriter.h">
+ <Filter>Header Files\Client</Filter>
+ </ClInclude>
+ <ClInclude Include="scriptservertoclientstringcommand.h">
<Filter>Header Files\Client</Filter>
</ClInclude>
<ClInclude Include="plugins.h">
@@ -1662,6 +1665,9 @@
<Filter>Source Files\Client</Filter>
</ClCompile>
<ClCompile Include="localchatwriter.cpp">
+ <Filter>Source Files\Client</Filter>
+ </ClCompile>
+ <ClCompile Include="scriptservertoclientstringcommand.cpp">
<Filter>Source Files\Client</Filter>
</ClCompile>
<ClCompile Include="plugins.cpp">
diff --git a/NorthstarDedicatedTest/clientchathooks.cpp b/NorthstarDedicatedTest/clientchathooks.cpp
index 62166cb2..74418c06 100644
--- a/NorthstarDedicatedTest/clientchathooks.cpp
+++ b/NorthstarDedicatedTest/clientchathooks.cpp
@@ -17,14 +17,14 @@ struct ChatTags
static void CHudChat__AddGameLineHook(void* self, const char* message, int inboxId, bool isTeam, bool isDead)
{
- if (g_ClientSquirrelManager->setupfunc("CHudChat_ProcessMessageStartThread") != SQRESULT_ERROR)
+ // This hook is called for each HUD, but we only want our logic to run once.
+ if (self != *CHudChat::allHuds)
{
- // This hook is called for each HUD, but we only want our logic to run once.
- if (!IsFirstHud(self))
- {
- return;
- }
+ return;
+ }
+ if (g_ClientSquirrelManager->setupfunc("CHudChat_ProcessMessageStartThread") != SQRESULT_ERROR)
+ {
int senderId = inboxId & CUSTOM_MESSAGE_INDEX_MASK;
bool isAnonymous = senderId == 0;
bool isCustom = isAnonymous || (inboxId & CUSTOM_MESSAGE_INDEX_BIT);
@@ -46,7 +46,12 @@ static void CHudChat__AddGameLineHook(void* self, const char* message, int inbox
g_ClientSquirrelManager->call(5);
}
else
- CHudChat__AddGameLine(self, message, inboxId, isTeam, isDead);
+ {
+ for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next)
+ {
+ CHudChat__AddGameLine(hud, message, inboxId, isTeam, isDead);
+ }
+ }
}
// void NSChatWrite( int context, string str )
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index 4d55b6e5..53e8d59f 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -37,6 +37,7 @@
#include "serverchathooks.h"
#include "clientchathooks.h"
#include "localchatwriter.h"
+#include "scriptservertoclientstringcommand.h"
#include "plugin_abi.h"
#include "plugins.h"
#include "host_state.h"
@@ -91,7 +92,11 @@ bool LoadPlugins()
std::vector<fs::path> paths;
std::string pluginPath = GetNorthstarPrefix() + "/plugins";
-
+ if (!fs::exists(pluginPath))
+ {
+ spdlog::warn("Could not find a plugins directory. Skipped loading plugins");
+ return false;
+ }
// ensure dirs exist
fs::recursive_directory_iterator iterator(pluginPath);
if (std::filesystem::begin(iterator) == std::filesystem::end(iterator))
@@ -104,9 +109,7 @@ bool LoadPlugins()
if (fs::is_regular_file(entry) && entry.path().extension() == ".dll")
paths.emplace_back(entry.path().filename());
}
- // system("pause");
initGameState();
- // spdlog::info("Loading the following DLLs in plugins folder:");
for (fs::path path : paths)
{
std::string pathstring = (pluginPath / path).string();
@@ -237,6 +240,7 @@ bool InitialiseNorthstar()
AddDllLoadCallback("client.dll", InitialisePluginCommands);
AddDllLoadCallback("client.dll", InitialiseClientChatHooks);
AddDllLoadCallback("client.dll", InitialiseLocalChatWriter);
+ AddDllLoadCallback("client.dll", InitialiseScriptServerToClientStringCommands);
}
AddDllLoadCallback("engine.dll", InitialiseEngineSpewFuncHooks);
diff --git a/NorthstarDedicatedTest/localchatwriter.cpp b/NorthstarDedicatedTest/localchatwriter.cpp
index fada3c33..8f7555b2 100644
--- a/NorthstarDedicatedTest/localchatwriter.cpp
+++ b/NorthstarDedicatedTest/localchatwriter.cpp
@@ -65,34 +65,11 @@ class CGameFloatVar
float value;
};
-class CHudChat
-{
- public:
- char unknown1[720];
-
- vgui_Color m_sameTeamColor;
- vgui_Color m_enemyTeamColor;
- vgui_Color m_mainTextColor;
- vgui_Color m_networkNameColor;
-
- char unknown2[12];
-
- int m_unknownContext;
-
- char unknown3[8];
-
- vgui_BaseRichText* m_richText;
-
- CHudChat* next;
- CHudChat* previous;
-};
-
CGameSettings** gGameSettings;
CGameFloatVar** gChatFadeLength;
CGameFloatVar** gChatFadeSustain;
-// Linked list of CHudChats
-CHudChat** gHudChatList;
+CHudChat** CHudChat::allHuds;
typedef void(__fastcall* ConvertANSIToUnicodeType)(LPCSTR ansi, int ansiCharLength, LPWSTR unicode, int unicodeCharLength);
ConvertANSIToUnicodeType ConvertANSIToUnicode;
@@ -315,7 +292,7 @@ void LocalChatWriter::WriteLine(const char* str)
void LocalChatWriter::InsertChar(wchar_t ch)
{
- for (CHudChat* hud = *gHudChatList; hud != NULL; hud = hud->next)
+ for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next)
{
if (hud->m_unknownContext != (int)m_context)
continue;
@@ -334,7 +311,7 @@ void LocalChatWriter::InsertText(const char* str)
WCHAR messageUnicode[288];
ConvertANSIToUnicode(str, -1, messageUnicode, 274);
- for (CHudChat* hud = *gHudChatList; hud != NULL; hud = hud->next)
+ for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next)
{
if (hud->m_unknownContext != (int)m_context)
continue;
@@ -347,7 +324,7 @@ void LocalChatWriter::InsertText(const char* str)
void LocalChatWriter::InsertText(const wchar_t* str)
{
- for (CHudChat* hud = *gHudChatList; hud != NULL; hud = hud->next)
+ for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next)
{
if (hud->m_unknownContext != (int)m_context)
continue;
@@ -360,7 +337,7 @@ void LocalChatWriter::InsertText(const wchar_t* str)
void LocalChatWriter::InsertColorChange(vgui_Color color)
{
- for (CHudChat* hud = *gHudChatList; hud != NULL; hud = hud->next)
+ for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next)
{
if (hud->m_unknownContext != (int)m_context)
continue;
@@ -387,7 +364,7 @@ static vgui_Color GetHudSwatchColor(CHudChat* hud, LocalChatWriter::SwatchColor
void LocalChatWriter::InsertSwatchColorChange(SwatchColor swatchColor)
{
- for (CHudChat* hud = *gHudChatList; hud != NULL; hud = hud->next)
+ for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next)
{
if (hud->m_unknownContext != (int)m_context)
continue;
@@ -439,7 +416,7 @@ void LocalChatWriter::InsertDefaultFade()
fadeSustain = (*gChatFadeSustain)->value;
}
- for (CHudChat* hud = *gHudChatList; hud != NULL; hud = hud->next)
+ for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next)
{
if (hud->m_unknownContext != (int)m_context)
continue;
@@ -447,14 +424,12 @@ void LocalChatWriter::InsertDefaultFade()
}
}
-bool IsFirstHud(void* hud) { return hud == *gHudChatList; }
-
void InitialiseLocalChatWriter(HMODULE baseAddress)
{
gGameSettings = (CGameSettings**)((char*)baseAddress + 0x11BAA48);
gChatFadeLength = (CGameFloatVar**)((char*)baseAddress + 0x11BAB78);
gChatFadeSustain = (CGameFloatVar**)((char*)baseAddress + 0x11BAC08);
- gHudChatList = (CHudChat**)((char*)baseAddress + 0x11BA9E8);
+ CHudChat::allHuds = (CHudChat**)((char*)baseAddress + 0x11BA9E8);
ConvertANSIToUnicode = (ConvertANSIToUnicodeType)((char*)baseAddress + 0x7339A0);
}
diff --git a/NorthstarDedicatedTest/localchatwriter.h b/NorthstarDedicatedTest/localchatwriter.h
index b9ca3220..8048e084 100644
--- a/NorthstarDedicatedTest/localchatwriter.h
+++ b/NorthstarDedicatedTest/localchatwriter.h
@@ -9,6 +9,32 @@ struct vgui_Color
unsigned char a;
};
+class vgui_BaseRichText;
+
+class CHudChat
+{
+ public:
+ static CHudChat** allHuds;
+
+ char unknown1[720];
+
+ vgui_Color m_sameTeamColor;
+ vgui_Color m_enemyTeamColor;
+ vgui_Color m_mainTextColor;
+ vgui_Color m_networkNameColor;
+
+ char unknown2[12];
+
+ int m_unknownContext;
+
+ char unknown3[8];
+
+ vgui_BaseRichText* m_richText;
+
+ CHudChat* next;
+ CHudChat* previous;
+};
+
class LocalChatWriter
{
public:
@@ -45,6 +71,4 @@ class LocalChatWriter
void InsertDefaultFade();
};
-bool IsFirstHud(void* hud);
-
void InitialiseLocalChatWriter(HMODULE baseAddress);
diff --git a/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp
new file mode 100644
index 00000000..58d92ec6
--- /dev/null
+++ b/NorthstarDedicatedTest/scriptservertoclientstringcommand.cpp
@@ -0,0 +1,25 @@
+#include "pch.h"
+#include "scriptservertoclientstringcommand.h"
+#include "squirrel.h"
+#include "convar.h"
+#include "concommand.h"
+#include "dedicated.h"
+
+void ConCommand_ns_script_servertoclientstringcommand(const CCommand& arg)
+{
+ if (g_ClientSquirrelManager->sqvm && g_ClientSquirrelManager->setupfunc("NSClientCodeCallback_RecievedServerToClientStringCommand") != SQRESULT_ERROR)
+ {
+ g_ClientSquirrelManager->pusharg(arg.ArgS());
+ g_ClientSquirrelManager->call(1); // todo: doesn't throw or log errors from within this, probably not great behaviour
+ }
+}
+
+void InitialiseScriptServerToClientStringCommands(HMODULE baseAddress)
+{
+ if (IsDedicated())
+ return;
+
+ RegisterConCommand(
+ "ns_script_servertoclientstringcommand", ConCommand_ns_script_servertoclientstringcommand, "",
+ FCVAR_CLIENTDLL | FCVAR_SERVER_CAN_EXECUTE);
+} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/scriptservertoclientstringcommand.h b/NorthstarDedicatedTest/scriptservertoclientstringcommand.h
new file mode 100644
index 00000000..609c6105
--- /dev/null
+++ b/NorthstarDedicatedTest/scriptservertoclientstringcommand.h
@@ -0,0 +1,3 @@
+#pragma once
+
+void InitialiseScriptServerToClientStringCommands(HMODULE baseAddress); \ No newline at end of file
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index 528b7ce1..9ec66b9f 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -458,8 +458,8 @@ char __fastcall CNetChan___ProcessMessagesHook(void* self, void* buf)
g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime,
Cvar_net_chan_limit_msec_per_sec->GetInt());
- // nonzero = kick, 0 = warn
- if (Cvar_net_chan_limit_mode->GetInt())
+ // nonzero = kick, 0 = warn, but never kick local player
+ if (Cvar_net_chan_limit_mode->GetInt() && strcmp(g_LocalPlayerUserID, (char*)sender + 0xF500))
{
CBaseClient__Disconnect(sender, 1, "Exceeded net channel processing limit");
return false;
diff --git a/NorthstarDedicatedTest/squirrel.h b/NorthstarDedicatedTest/squirrel.h
index b01618f2..7801ada7 100644
--- a/NorthstarDedicatedTest/squirrel.h
+++ b/NorthstarDedicatedTest/squirrel.h
@@ -205,14 +205,20 @@ template <ScriptContext context> class SquirrelManager
ClientSq_pushroottable(sqvm2);
ClientSq_pushstring(sqvm2, funcname, -1);
result = ClientSq_sq_get(sqvm2, -2);
- ClientSq_pushroottable(sqvm2);
+ if (result != SQRESULT_ERROR)
+ {
+ ClientSq_pushroottable(sqvm2);
+ }
}
else if (context == ScriptContext::SERVER)
{
ServerSq_pushroottable(sqvm2);
ServerSq_pushstring(sqvm2, funcname, -1);
result = ServerSq_sq_get(sqvm2, -2);
- ServerSq_pushroottable(sqvm2);
+ if (result != SQRESULT_ERROR)
+ {
+ ServerSq_pushroottable(sqvm2);
+ }
}
return result;
}
@@ -282,4 +288,4 @@ template <ScriptContext context> class SquirrelManager
extern SquirrelManager<ScriptContext::CLIENT>* g_ClientSquirrelManager;
extern SquirrelManager<ScriptContext::SERVER>* g_ServerSquirrelManager;
-extern SquirrelManager<ScriptContext::UI>* g_UISquirrelManager; \ No newline at end of file
+extern SquirrelManager<ScriptContext::UI>* g_UISquirrelManager;