From 85e958331ac9aafc2d2c05ed96c591c8a245f665 Mon Sep 17 00:00:00 2001 From: wolf109909 <1486234278@qq.com> Date: Sun, 16 Jan 2022 00:15:18 +0800 Subject: Fixes and optimizations around title and server names Server name now supports UTF-8 chars in Unicode codepoints. Dedicated server now displays server name for better itentification. --- NorthstarDedicatedTest/dedicated.cpp | 4 +- NorthstarDedicatedTest/masterserver.cpp | 82 +++++++++++++++++++++++++++++++-- NorthstarDedicatedTest/masterserver.h | 8 +++- 3 files changed, 87 insertions(+), 7 deletions(-) (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index e6115415..1555eaaf 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -3,7 +3,7 @@ #include "hookutils.h" #include "gameutils.h" #include "serverauthentication.h" - +#include "masterserver.h" bool IsDedicated() { //return CommandLine()->CheckParm("-dedicated"); @@ -68,7 +68,7 @@ void RunServer(CDedicatedExports* dedicated) if (!maxPlayers) maxPlayers = "6"; - SetConsoleTitleA(fmt::format("Titanfall 2 dedicated server - {} {}/{} players ({})", g_pHostState->m_levelName, g_ServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers, GetCurrentPlaylistName()).c_str()); + SetConsoleTitleA(fmt::format("{} - {} {}/{} players ({})", g_MasterServerManager->ns_auth_srvName, g_pHostState->m_levelName, g_ServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers, GetCurrentPlaylistName()).c_str()); std::this_thread::sleep_for(std::chrono::duration>(Cvar_base_tickinterval_mp->m_fValue - fmin(Plat_FloatTime() - frameStart, 0.25))); } } diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index c040a239..00310338 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -11,7 +11,8 @@ #include "rapidjson/error/en.h" #include "modmanager.h" #include "misccommands.h" - +#include +#include // NOTE for anyone reading this: we used to use httplib for requests here, but it had issues, so we're moving to curl now for masterserver requests // so httplib is used exclusively for server stuff now @@ -40,6 +41,79 @@ CHostState__State_ChangeLevelSPType CHostState__State_ChangeLevelSP; typedef void(*CHostState__State_GameShutdownType)(CHostState* hostState); CHostState__State_GameShutdownType CHostState__State_GameShutdown; + +int htod(char c) { + if (c >= 'A' && c <= 'F') { + return c - 'A' + 10; + } + else if (c >= 'a' && c <= 'f') { + return c - 'a' + 10; + } + else { + return c - '0'; + } +} +// Shoutout to Wtz_LASR for helping me with this: +// These functions should interprets all unicode strings like \u4e2d\u6587 to UTF8. + +void unescape_unicode(std::string& str) { + std::regex r("\\\\u([a-f\\d]{4})", std::regex::icase); + std::smatch sm; + while (regex_search(str, sm, r)) { + unsigned int cp = 0; + std::string conv; + for (int i = 2; i <= 5; ++i) { + cp *= 16; + cp += htod(sm[0].str()[i]); + } + + if (cp >= 0x00 && cp <= 0x7F) { + conv.push_back(cp); + } + else if (cp >= 0x80 && cp <= 0x7FF) { + unsigned char c1 = cp >> 6; + c1 = c1 | (1 << 7); + c1 = c1 | (1 << 6); + c1 = c1 & (~(1 << 5)); + unsigned char c2 = cp & ((1 << 6) - 1); + c2 = c2 | (1 << 7); + c2 = c2 & (~(1 << 6)); + conv.push_back(c1); + conv.push_back(c2); + } + else if (cp >= 0x800 && cp <= 0xFFFF) { + unsigned char c1 = cp >> 12; + c1 = c1 | (1 << 7); + c1 = c1 | (1 << 6); + c1 = c1 | (1 << 5); + c1 = c1 & (~(1 << 4)); + unsigned char c2 = (cp >> 6) & ((1 << 6) - 1); + c2 = c2 | (1 << 7); + c2 = c2 & (~(1 << 6)); + unsigned char c3 = cp & ((1 << 6) - 1); + c3 = c3 | (1 << 7); + c3 = c3 & (~(1 << 6)); + conv.push_back(c1); + conv.push_back(c2); + conv.push_back(c3); + } + str.replace(sm[0].first, sm[0].second, conv); + } +} + + +void UpdateServerInfoFromUnicodeToUTF8() +{ + //This reads server name and desc from convar, interprets all unicode strings to UTF8. + g_MasterServerManager->ns_auth_srvName = Cvar_ns_server_name->m_pszString; + g_MasterServerManager->ns_auth_srvDesc = Cvar_ns_server_desc->m_pszString; + unescape_unicode(g_MasterServerManager->ns_auth_srvName); + unescape_unicode(g_MasterServerManager->ns_auth_srvDesc); + //std::cout << g_MasterServerManager -> ns_auth_srvName << std::endl; + + +} + const char* HttplibErrorToString(httplib::Error error) { switch (error) @@ -786,8 +860,8 @@ void MasterServerManager::AddSelfToServerList(int port, int authPort, char* name // send all registration info so we have all necessary info to reregister our server if masterserver goes down, without a restart // this isn't threadsafe :terror: { - char* escapedNameNew = curl_easy_escape(curl, Cvar_ns_server_name->m_pszString, NULL); - char* escapedDescNew = curl_easy_escape(curl, Cvar_ns_server_desc->m_pszString, NULL); + char* escapedNameNew = curl_easy_escape(curl, g_MasterServerManager->ns_auth_srvName.c_str(), NULL); + char* escapedDescNew = curl_easy_escape(curl, g_MasterServerManager->ns_auth_srvDesc.c_str(), NULL); char* escapedMapNew = curl_easy_escape(curl, g_pHostState->m_levelName, NULL); char* escapedPlaylistNew = curl_easy_escape(curl, GetCurrentPlaylistName(), NULL); char* escapedPasswordNew = curl_easy_escape(curl, Cvar_ns_server_password->m_pszString, NULL); @@ -1044,6 +1118,8 @@ void CHostState__State_NewGameHook(CHostState* hostState) // Copy new server name cvar to source Cvar_hostname->m_pszString = Cvar_ns_server_name->m_pszString; Cvar_hostname->m_StringLength = Cvar_ns_server_name->m_StringLength; + // This calls the function that converts unicode strings from servername and serverdesc to UTF-8 + UpdateServerInfoFromUnicodeToUTF8(); g_MasterServerManager->AddSelfToServerList(Cvar_hostport->m_nValue, Cvar_ns_player_auth_port->m_nValue, Cvar_ns_server_name->m_pszString, Cvar_ns_server_desc->m_pszString, hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers, Cvar_ns_server_password->m_pszString); g_ServerAuthenticationManager->StartPlayerAuthServer(); diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h index d7071b6c..b1119564 100644 --- a/NorthstarDedicatedTest/masterserver.h +++ b/NorthstarDedicatedTest/masterserver.h @@ -1,7 +1,8 @@ #pragma once #include "convar.h" #include - +#include +#include struct RemoteModInfo { public: @@ -73,6 +74,8 @@ public: char m_ownClientAuthToken[33]; std::string m_ownModInfoJson; + std::string ns_auth_srvName; // Unicode unescaped version of Cvar_ns_auth_servername for support in cjk characters + std::string ns_auth_srvDesc; // Unicode unescaped version of Cvar_ns_auth_serverdesc for support in cjk characters bool m_bOriginAuthWithMasterServerDone = false; bool m_bOriginAuthWithMasterServerInProgress = false; @@ -112,7 +115,8 @@ public: void WritePlayerPersistentData(char* playerId, char* pdata, size_t pdataSize); void RemoveSelfFromServerList(); }; - +void unescape_unicode(std::string& str); +void UpdateServerInfoFromUnicodeToUTF8(); void InitialiseSharedMasterServer(HMODULE baseAddress); extern MasterServerManager* g_MasterServerManager; -- cgit v1.2.3 From 2b8f635def54026539d35d35852108ad635e9612 Mon Sep 17 00:00:00 2001 From: Wtz_LASR Date: Mon, 17 Jan 2022 11:49:54 +0800 Subject: Fix recursive matching issue and optimized further --- NorthstarDedicatedTest/masterserver.cpp | 72 ++++++++++++--------------------- NorthstarDedicatedTest/masterserver.h | 2 +- 2 files changed, 26 insertions(+), 48 deletions(-) (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index 00310338..c61c69e5 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -41,8 +41,8 @@ CHostState__State_ChangeLevelSPType CHostState__State_ChangeLevelSP; typedef void(*CHostState__State_GameShutdownType)(CHostState* hostState); CHostState__State_GameShutdownType CHostState__State_GameShutdown; - -int htod(char c) { +// Convert a hex digit char to integer. +inline int hctod(char c) { if (c >= 'A' && c <= 'F') { return c - 'A' + 10; } @@ -53,65 +53,43 @@ int htod(char c) { return c - '0'; } } -// Shoutout to Wtz_LASR for helping me with this: -// These functions should interprets all unicode strings like \u4e2d\u6587 to UTF8. -void unescape_unicode(std::string& str) { +// This function interprets all 4-hexadecimal-digit unicode codepoint characters like \u4E2D to UTF-8 encoding. +std::string unescape_unicode(const std::string &str) { + std::string result; std::regex r("\\\\u([a-f\\d]{4})", std::regex::icase); - std::smatch sm; - while (regex_search(str, sm, r)) { + auto matches_begin = std::sregex_iterator(str.begin(), str.end(), r); + auto matches_end = std::sregex_iterator(); + std::smatch last_match; + for (std::sregex_iterator i = matches_begin; i != matches_end; ++i) { + last_match = *i; + result.append(last_match.prefix()); unsigned int cp = 0; - std::string conv; for (int i = 2; i <= 5; ++i) { cp *= 16; - cp += htod(sm[0].str()[i]); + cp += hctod(last_match.str()[i]); } - - if (cp >= 0x00 && cp <= 0x7F) { - conv.push_back(cp); + if (cp <= 0x7F) { + result.push_back(cp); } - else if (cp >= 0x80 && cp <= 0x7FF) { - unsigned char c1 = cp >> 6; - c1 = c1 | (1 << 7); - c1 = c1 | (1 << 6); - c1 = c1 & (~(1 << 5)); - unsigned char c2 = cp & ((1 << 6) - 1); - c2 = c2 | (1 << 7); - c2 = c2 & (~(1 << 6)); - conv.push_back(c1); - conv.push_back(c2); + else if (cp <= 0x7FF) { + result.push_back((cp >> 6) | 0b11000000 & (~(1 << 5))); + result.push_back(cp & ((1 << 6) - 1) | 0b10000000 & (~(1 << 6))); } - else if (cp >= 0x800 && cp <= 0xFFFF) { - unsigned char c1 = cp >> 12; - c1 = c1 | (1 << 7); - c1 = c1 | (1 << 6); - c1 = c1 | (1 << 5); - c1 = c1 & (~(1 << 4)); - unsigned char c2 = (cp >> 6) & ((1 << 6) - 1); - c2 = c2 | (1 << 7); - c2 = c2 & (~(1 << 6)); - unsigned char c3 = cp & ((1 << 6) - 1); - c3 = c3 | (1 << 7); - c3 = c3 & (~(1 << 6)); - conv.push_back(c1); - conv.push_back(c2); - conv.push_back(c3); + else if (cp <= 0xFFFF) { + result.push_back((cp >> 12) | 0b11100000 & (~(1 << 4))); + result.push_back((cp >> 6) & ((1 << 6) - 1) | 0b10000000 & (~(1 << 6))); + result.push_back(cp & ((1 << 6) - 1) | 0b10000000 & (~(1 << 6))); } - str.replace(sm[0].first, sm[0].second, conv); } + result.append(last_match.suffix()); + return result; } - void UpdateServerInfoFromUnicodeToUTF8() { - //This reads server name and desc from convar, interprets all unicode strings to UTF8. - g_MasterServerManager->ns_auth_srvName = Cvar_ns_server_name->m_pszString; - g_MasterServerManager->ns_auth_srvDesc = Cvar_ns_server_desc->m_pszString; - unescape_unicode(g_MasterServerManager->ns_auth_srvName); - unescape_unicode(g_MasterServerManager->ns_auth_srvDesc); - //std::cout << g_MasterServerManager -> ns_auth_srvName << std::endl; - - + g_MasterServerManager->ns_auth_srvName = unescape_unicode(Cvar_ns_server_name->m_pszString); + g_MasterServerManager->ns_auth_srvDesc = unescape_unicode(Cvar_ns_server_desc->m_pszString); } const char* HttplibErrorToString(httplib::Error error) diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h index b1119564..2e7468b4 100644 --- a/NorthstarDedicatedTest/masterserver.h +++ b/NorthstarDedicatedTest/masterserver.h @@ -115,7 +115,7 @@ public: void WritePlayerPersistentData(char* playerId, char* pdata, size_t pdataSize); void RemoveSelfFromServerList(); }; -void unescape_unicode(std::string& str); +std::string unescape_unicode(const std::string &str); void UpdateServerInfoFromUnicodeToUTF8(); void InitialiseSharedMasterServer(HMODULE baseAddress); -- cgit v1.2.3 From 2da9440b478dd4c98d67222412747682ee4144df Mon Sep 17 00:00:00 2001 From: Barichello Date: Thu, 20 Jan 2022 16:30:59 -0300 Subject: Revert "Add legal notices file to builds" This reverts commit f23b97708d02e55cdaf6cde11fe003e176d62a85. We are moving the LEGAL.txt file to the main repository so it can be used by GitHub actions --- Northstar-Legal.txt | 313 --------------------- .../NorthstarDedicatedTest.vcxproj | 3 - 2 files changed, 316 deletions(-) delete mode 100644 Northstar-Legal.txt (limited to 'NorthstarDedicatedTest') diff --git a/Northstar-Legal.txt b/Northstar-Legal.txt deleted file mode 100644 index aa0adb13..00000000 --- a/Northstar-Legal.txt +++ /dev/null @@ -1,313 +0,0 @@ -This file contains licenses and copyright notices of the Northstar client, and -third-party libraries and software utilized by it. - -NORTHSTAR CLIENT -================ - -MIT License - -Copyright (c) 2021 R2Northstar - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - ------ - - -CURL -==== - -cURL License - -Copyright (c) 1996 - 2021, Daniel Stenberg, daniel@haxx.se, and many contributors, see the THANKS file. - -All rights reserved. - -Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder. - - -HTTPLIB -======= -MIT License - -Copyright (c) 2021 Yuji Hirose. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ------ - - -MINHOOK -======= - -FreeBSD License - -MinHook - The Minimalistic API Hooking Library for x64/x86 -Copyright (C) 2009-2017 Tsuda Kageyu. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ------ - - -OPENSSL -======= - -Apache License - -Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. - - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - ------ - - -RAPIDJSON -========= - -MIT License - -Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ------ - - -SPDLOG -====== - -MIT License - -Copyright(c) 2015-present, Gabi Melman & spdlog contributors. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ------ diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj index 93b35e5c..8aa300c8 100644 --- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj +++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj @@ -627,9 +627,6 @@ - - - -- cgit v1.2.3 From f31c452286cf8861f328b94b6b51c004a46984e0 Mon Sep 17 00:00:00 2001 From: pg9182 <96569817+pg9182@users.noreply.github.com> Date: Thu, 20 Jan 2022 14:14:08 -0500 Subject: Limit title update interval to 500ms --- NorthstarDedicatedTest/dedicated.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/dedicated.cpp b/NorthstarDedicatedTest/dedicated.cpp index 1555eaaf..e140281a 100644 --- a/NorthstarDedicatedTest/dedicated.cpp +++ b/NorthstarDedicatedTest/dedicated.cpp @@ -58,17 +58,24 @@ void RunServer(CDedicatedExports* dedicated) // note: we no longer manually set map and hoststate to start server in g_pHostState, we just use +map which seems to initialise stuff better // main loop + double frameTitle = 0; while (g_pEngine->m_nQuitting == EngineQuitState::QUIT_NOTQUITTING) { double frameStart = Plat_FloatTime(); g_pEngine->Frame(); - // this way of getting playercount/maxplayers honestly really sucks, but not got any other methods of doing it rn - const char* maxPlayers = GetCurrentPlaylistVar("max_players", false); - if (!maxPlayers) - maxPlayers = "6"; + // only update the title after at least 500ms since the last update + if ((frameStart - frameTitle) > 0.5) { + frameTitle = frameStart; + + // this way of getting playercount/maxplayers honestly really sucks, but not got any other methods of doing it rn + const char* maxPlayers = GetCurrentPlaylistVar("max_players", false); + if (!maxPlayers) + maxPlayers = "6"; + + SetConsoleTitleA(fmt::format("{} - {} {}/{} players ({})", g_MasterServerManager->ns_auth_srvName, g_pHostState->m_levelName, g_ServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers, GetCurrentPlaylistName()).c_str()); + } - SetConsoleTitleA(fmt::format("{} - {} {}/{} players ({})", g_MasterServerManager->ns_auth_srvName, g_pHostState->m_levelName, g_ServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers, GetCurrentPlaylistName()).c_str()); std::this_thread::sleep_for(std::chrono::duration>(Cvar_base_tickinterval_mp->m_fValue - fmin(Plat_FloatTime() - frameStart, 0.25))); } } -- cgit v1.2.3 From 75d99e1a81bfbd0dbbaf0b1ace144a8156a47148 Mon Sep 17 00:00:00 2001 From: p0358 Date: Mon, 24 Jan 2022 19:43:21 +0100 Subject: Misc improvements --- LauncherInjector/main.cpp | 18 ++++++++++-- NorthstarDedicatedTest/languagehooks.cpp | 8 +++-- loader_launcher_proxy/dllmain.cpp | 9 ++++-- loader_wsock32_proxy/dllmain.cpp | 50 ++++++++++++++++++++++---------- loader_wsock32_proxy/loader.cpp | 13 ++++++--- loader_wsock32_proxy/loader.h | 5 ++-- 6 files changed, 74 insertions(+), 29 deletions(-) (limited to 'NorthstarDedicatedTest') diff --git a/LauncherInjector/main.cpp b/LauncherInjector/main.cpp index 7697e80d..a5d70f76 100644 --- a/LauncherInjector/main.cpp +++ b/LauncherInjector/main.cpp @@ -65,17 +65,29 @@ FARPROC GetLauncherMain() void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* location) { - char text[4096]; + char text[8192]; std::string message = std::system_category().message(dwMessageId); - sprintf_s(text, "Failed to load the %ls at \"%ls\" (%lu):\n\n%hs\n\nMake sure you followed the Northstar installation instructions carefully.", libName, location, dwMessageId, message.c_str()); + sprintf_s(text, "Failed to load the %ls at \"%ls\" (%lu):\n\n%hs\n\nMake sure you followed the Northstar installation instructions carefully before reaching out for help.", libName, location, dwMessageId, message.c_str()); - if (!fs::exists("Titanfall2.exe") && fs::exists("..\\Titanfall2.exe")) + if (dwMessageId == 126 && std::filesystem::exists(location)) + { + sprintf_s(text, "%s\n\nThe file at the specified location DOES exist, so this error indicates that one of its *dependencies* failed to be found.\n\nTry the following steps:\n1. Install Visual C++ 2022 Redistributable: https://aka.ms/vs/17/release/vc_redist.x64.exe\n2. Repair game files", text); + } + else if (!fs::exists("Titanfall2.exe") && (fs::exists("..\\Titanfall2.exe") || fs::exists("..\\..\\Titanfall2.exe"))) { auto curDir = std::filesystem::current_path().filename().string(); auto aboveDir = std::filesystem::current_path().parent_path().filename().string(); sprintf_s(text, "%s\n\nWe detected that in your case you have extracted the files into a *subdirectory* of your Titanfall 2 installation.\nPlease move all the files and folders from current folder (\"%s\") into the Titanfall 2 installation directory just above (\"%s\").\n\nPlease try out the above steps by yourself before reaching out to the community for support.", text, curDir.c_str(), aboveDir.c_str()); } + else if (!fs::exists("Titanfall2.exe")) + { + sprintf_s(text, "%s\n\nRemember: you need to unpack the contents of this archive into your Titanfall 2 game installation directory, not just to any random folder.", text); + } + else if (fs::exists("Titanfall2.exe")) + { + sprintf_s(text, "%s\n\nTitanfall2.exe has been found in the current directory: is the game installation corrupted or did you not unpack all Northstar files here?", text); + } MessageBoxA(GetForegroundWindow(), text, "Northstar Launcher Error", 0); } diff --git a/NorthstarDedicatedTest/languagehooks.cpp b/NorthstarDedicatedTest/languagehooks.cpp index 0929b73d..3a69df9d 100644 --- a/NorthstarDedicatedTest/languagehooks.cpp +++ b/NorthstarDedicatedTest/languagehooks.cpp @@ -26,6 +26,9 @@ std::vector file_list(fs::path dir, std::regex ext_pattern) { std::vector result; + if (!fs::exists(dir) || !fs::is_directory(dir)) + return result; + using iterator = fs::directory_iterator; const iterator end; @@ -77,7 +80,8 @@ char* GetGameLanguageHook() auto lang = GetGameLanguageOriginal(); if (!CheckLangAudioExists(lang)) { - spdlog::info("Origin detected language \"{}\", but we do not have audio for it installed, falling back to the next option", lang); + if (strcmp(lang, "russian") != 0) // don't log for "russian" since it's the default and that means Origin detection just didn't change it most likely + spdlog::info("Origin detected language \"{}\", but we do not have audio for it installed, falling back to the next option", lang); } else @@ -95,7 +99,7 @@ char* GetGameLanguageHook() { spdlog::warn("Caution, audio for this language does NOT exist. You might want to override your game language with -language command line option."); auto lang = GetAnyInstalledAudioLanguage(); - spdlog::warn("Falling back to first installed audio language: {}", lang.c_str()); + spdlog::warn("Falling back to the first installed audio language: {}", lang.c_str()); strncpy(ingameLang1, lang.c_str(), 256); return ingameLang1; } diff --git a/loader_launcher_proxy/dllmain.cpp b/loader_launcher_proxy/dllmain.cpp index cf69d63e..1215ca1f 100644 --- a/loader_launcher_proxy/dllmain.cpp +++ b/loader_launcher_proxy/dllmain.cpp @@ -5,6 +5,7 @@ #include #include #include +#include HMODULE hLauncherModule; HMODULE hHookModule; @@ -44,9 +45,13 @@ FARPROC GetLauncherMain() void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* location) { - char text[2048]; - std::string message = std::system_category().message(dwMessageId); + char text[4096]; + std::string message = std::system_category().message(dwMessageId); sprintf_s(text, "Failed to load the %ls at \"%ls\" (%lu):\n\n%hs", libName, location, dwMessageId, message.c_str()); + if (dwMessageId == 126 && std::filesystem::exists(location)) + { + sprintf_s(text, "%s\n\nThe file at the specified location DOES exist, so this error indicates that one of its *dependencies* failed to be found.", text); + } MessageBoxA(GetForegroundWindow(), text, "Northstar Launcher Proxy Error", 0); } diff --git a/loader_wsock32_proxy/dllmain.cpp b/loader_wsock32_proxy/dllmain.cpp index 0b518dbe..f4c0d604 100644 --- a/loader_wsock32_proxy/dllmain.cpp +++ b/loader_wsock32_proxy/dllmain.cpp @@ -18,8 +18,8 @@ bool GetExePathWide(wchar_t* dest, DWORD destSize) } wchar_t exePath[4096]; -wchar_t dllPath[8192]; -wchar_t dllPath2[4096]; +wchar_t buffer1[8192]; +wchar_t buffer2[12288]; BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID) { @@ -30,30 +30,48 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID) if (!GetExePathWide(exePath, 4096)) { MessageBoxA(GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Northstar Wsock32 Proxy Error", 0); - return 1; + return true; } if (!ProvisionNorthstar()) // does not call InitialiseNorthstar yet, will do it on LauncherMain hook - return 1; + return true; // copy the original library for system to our local directory, with changed name so that we can load it - swprintf_s(dllPath, L"%s\\bin\\x64_retail\\wsock32.org.dll", exePath); - GetSystemDirectoryW(dllPath2, 4096); - swprintf_s(dllPath2, L"%s\\wsock32.dll", dllPath2); + swprintf_s(buffer1, L"%s\\bin\\x64_retail\\wsock32.org.dll", exePath); + GetSystemDirectoryW(buffer2, 4096); + swprintf_s(buffer2, L"%s\\wsock32.dll", buffer2); try { - std::filesystem::copy_file(dllPath2, dllPath); + std::filesystem::copy_file(buffer2, buffer1); } - catch (const std::exception& e) + catch (const std::exception& e1) { - if (!std::filesystem::exists(dllPath)) + if (!std::filesystem::exists(buffer1)) { - swprintf_s(dllPath, L"Failed copying wsock32.dll from system32 to \"%s\"\n\n%S", dllPath, e.what()); - MessageBoxW(GetForegroundWindow(), dllPath, L"Northstar Wsock32 Proxy Error", 0); + // fallback by copying to temp dir... + // because apparently games installed by EA Desktop app don't have write permissions in their directories + auto temp_dir = std::filesystem::temp_directory_path() / L"wsock32.org.dll"; + try + { + std::filesystem::copy_file(buffer2, temp_dir); + } + catch (const std::exception& e2) + { + if (!std::filesystem::exists(temp_dir)) + { + swprintf_s(buffer2, L"Failed copying wsock32.dll from system32 to \"%s\"\n\n%S\n\nFurthermore, we failed copying wsock32.dll into temporary directory at \"%s\"\n\n%S", buffer1, e1.what(), temp_dir.c_str(), e2.what()); + MessageBoxW(GetForegroundWindow(), buffer2, L"Northstar Wsock32 Proxy Error", 0); + return false; + } + } + swprintf_s(buffer1, L"%s", temp_dir.c_str()); } } - hL = LoadLibraryExW(dllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); - if (!hL) return false; + hL = LoadLibraryExW(buffer1, 0, LOAD_WITH_ALTERED_SEARCH_PATH); + if (!hL) { + LibraryLoadError(GetLastError(), L"wsock32.org.dll", buffer1); + return false; + } // load the functions to proxy // it's only some of them, because in case of wsock32 most of the functions can actually be natively redirected @@ -75,10 +93,10 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID) if (reason == DLL_PROCESS_DETACH) { FreeLibrary(hL); - return 1; + return true; } - return 1; + return true; } extern "C" diff --git a/loader_wsock32_proxy/loader.cpp b/loader_wsock32_proxy/loader.cpp index 907caa9d..61b4daf3 100644 --- a/loader_wsock32_proxy/loader.cpp +++ b/loader_wsock32_proxy/loader.cpp @@ -5,12 +5,17 @@ #include #include #include +#include void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* location) { - char text[2048]; + char text[4096]; std::string message = std::system_category().message(dwMessageId); sprintf_s(text, "Failed to load the %ls at \"%ls\" (%lu):\n\n%hs", libName, location, dwMessageId, message.c_str()); + if (dwMessageId == 126 && std::filesystem::exists(location)) + { + sprintf_s(text, "%s\n\nThe file at the specified location DOES exist, so this error indicates that one of its *dependencies* failed to be found.", text); + } MessageBoxA(GetForegroundWindow(), text, "Northstar Wsock32 Proxy Error", 0); } @@ -37,12 +42,12 @@ bool LoadNorthstar() { FARPROC Hook_Init = nullptr; { - swprintf_s(dllPath, L"%s\\Northstar.dll", exePath); - auto hHookModule = LoadLibraryExW(dllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH); + swprintf_s(buffer1, L"%s\\Northstar.dll", exePath); + auto hHookModule = LoadLibraryExW(buffer1, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if (hHookModule) Hook_Init = GetProcAddress(hHookModule, "InitialiseNorthstar"); if (!hHookModule || Hook_Init == nullptr) { - LibraryLoadError(GetLastError(), L"Northstar.dll", dllPath); + LibraryLoadError(GetLastError(), L"Northstar.dll", buffer1); return false; } } diff --git a/loader_wsock32_proxy/loader.h b/loader_wsock32_proxy/loader.h index 9a14b2e7..0c6fb053 100644 --- a/loader_wsock32_proxy/loader.h +++ b/loader_wsock32_proxy/loader.h @@ -1,8 +1,9 @@ #pragma once extern wchar_t exePath[4096]; -extern wchar_t dllPath[8192]; -extern wchar_t dllPath2[4096]; +extern wchar_t buffer1[8192]; +extern wchar_t buffer2[12288]; +void LibraryLoadError(DWORD dwMessageId, const wchar_t* libName, const wchar_t* location); bool ShouldLoadNorthstar(); bool ProvisionNorthstar(); -- cgit v1.2.3 From b85b357a496ab633bb42f46735c42ef0abade392 Mon Sep 17 00:00:00 2001 From: p0358 Date: Mon, 24 Jan 2022 22:17:52 +0100 Subject: check for -northstar in wrong place --- NorthstarDedicatedTest/hooks.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'NorthstarDedicatedTest') diff --git a/NorthstarDedicatedTest/hooks.cpp b/NorthstarDedicatedTest/hooks.cpp index ce4d75ad..cdb5fef9 100644 --- a/NorthstarDedicatedTest/hooks.cpp +++ b/NorthstarDedicatedTest/hooks.cpp @@ -73,6 +73,10 @@ LPSTR GetCommandLineAHook() argBuffer << cmdlineArgFile.rdbuf(); cmdlineArgFile.close(); + // if some other command line option includes "-northstar" in the future then you have to refactor this check to check with both either space after or ending with + if (!isDedi && argBuffer.str().find("-northstar") != std::string::npos) + MessageBoxA(NULL, "The \"-northstar\" command line option is NOT supposed to go into ns_startup_args.txt file!\n\nThis option is supposed to go into Origin/Steam game launch options, and then you are supposed to launch the original Titanfall2.exe rather than NorthstarLauncher.exe to make use of it.", "Northstar Warning", MB_ICONWARNING); + args.append(argBuffer.str()); } -- cgit v1.2.3