diff --git a/LiteLoader/BugFix.cpp b/LiteLoader/BugFix.cpp index fcf39a1e12..5026c5fa86 100644 --- a/LiteLoader/BugFix.cpp +++ b/LiteLoader/BugFix.cpp @@ -1,6 +1,7 @@ #include "pch.h" bool isFixDisconnectBug(); +bool isFixListenPort(); //Fix disconnect packet crash bug THook(void, "?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@AEBVDisconnectPacket@@@Z", ServerNetworkHandler* thi, NetworkIdentifier* ni, void* packet) { @@ -8,4 +9,19 @@ THook(void, "?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@AEBVDisco return; } return original(thi, ni, packet); +} +//Fix the listening port twice +//From https://github.com/Redbeanw44602/FixIPLogger +bool a_call = true; +THook(__int64, "?LogIPSupport@RakPeerHelper@@AEAAXXZ", + void* _this) { + if (isFixListenPort()) { + if (a_call) { + a_call = false; + return original(_this); + } + return 0; + } else { + return original(_this); + } } \ No newline at end of file diff --git a/LiteLoader/Config.cpp b/LiteLoader/Config.cpp index b6d1921c5f..4cdf4dc58c 100644 --- a/LiteLoader/Config.cpp +++ b/LiteLoader/Config.cpp @@ -6,6 +6,7 @@ extern Logger LOG; bool LoaderDebugMode = false; bool FixDisconnectBug = true; +bool FixListenPort = true; LIAPI bool loaderapi::isDebugMode() { return LoaderDebugMode; @@ -15,17 +16,21 @@ bool isFixDisconnectBug() { return FixDisconnectBug; } +bool isFixListenPort() { + return FixListenPort; +} + void loadConfig() { std::string config_file = "liteloader.json"; std::ifstream fs; fs.open(config_file, std::ios::in); if (!fs) { - LOG(config_file, " not found, creating configuration file"); + LOG("", config_file, "not found, creating configuration file"); std::ofstream of(config_file); if (of) { - of << "{\n \"DebugMode\": false,\n \"FixDisconnectBug\": true\n}"; + of << "{\n \"DebugMode\": false,\n \"FixDisconnectBug\": true,\n \"FixListenPort\": true\n}"; } else { - LOG("Configuration file creation failed"); + LOG(" Configuration file creation failed"); } } else { std::string json; @@ -38,12 +43,17 @@ void loadConfig() { if (!document["DebugMode"].IsNull()) { LoaderDebugMode = document["DebugMode"].GetBool(); } else { - LOG("Could not found DebugMoade in config"); + LOG(" Could not found DebugMoade in config"); } if (!document["FixDisconnectBug"].IsNull()) { FixDisconnectBug = document["FixDisconnectBug"].GetBool(); } else { - LOG("Could not found FixDisconnectBug in config"); + LOG(" Could not found FixDisconnectBug in config"); + } + if (!document["FixListenPort"].IsNull()) { + FixListenPort = document["FixListenPort"].GetBool(); + } else { + LOG(" Could not found FixListenPort in config"); } } } \ No newline at end of file