From 5ef0f28002cfc65af743032ef7b5568c7b86b4bd Mon Sep 17 00:00:00 2001 From: Laz Date: Tue, 14 Nov 2023 19:43:15 +0000 Subject: [PATCH] added get player ip function, added functions for starting/stopping fuses, more cleanup --- include/API/Types/AccountId.hpp | 20 +++ include/API/Types/BaseId.hpp | 3 +- include/API/Types/ClientId.hpp | 19 ++- include/API/Types/ShipId.hpp | 5 +- include/Core/ClientServerInterface.hpp | 2 +- include/Core/FLHook.hpp | 1 + include/Defs/Structs.hpp | 6 - project/FLHook.vcxproj | 1 + project/FLHook.vcxproj.filters | 3 + source/API/FLServer/Admin.cpp | 150 +----------------- source/API/Types/BaseId.cpp | 19 ++- source/API/Types/ClientId.cpp | 77 +++++++-- source/API/Types/ShipId.cpp | 72 +++++++++ source/Core/Timers.cpp | 94 +++++------ source/Hooks/ClientServerInterface/Base.cpp | 33 ++-- .../ClientServerInterface/LaunchComplete.cpp | 9 +- source/Hooks/ClientServerInterface/Trade.cpp | 1 - 17 files changed, 266 insertions(+), 249 deletions(-) create mode 100644 include/API/Types/AccountId.hpp diff --git a/include/API/Types/AccountId.hpp b/include/API/Types/AccountId.hpp new file mode 100644 index 000000000..ce307ce6d --- /dev/null +++ b/include/API/Types/AccountId.hpp @@ -0,0 +1,20 @@ +#pragma once + +class AccountId final +{ + CAccount* value = nullptr; + + public: + explicit AccountId(ClientId client); + explicit AccountId(std::wstring_view characterName); + explicit AccountId() = default; + + bool operator==(const CAccount* next) const { return value == next; } + explicit operator bool() const; + + [[nodiscard]] + CAccount* GetValue() const + { + return value; + } +}; diff --git a/include/API/Types/BaseId.hpp b/include/API/Types/BaseId.hpp index c8a0a3725..867151d57 100644 --- a/include/API/Types/BaseId.hpp +++ b/include/API/Types/BaseId.hpp @@ -20,7 +20,8 @@ class BaseId Action GetSpaceId() const; Action GetAffiliation() const; Action GetName() const; - Action, Error> GetDescription(); + Action, Error> GetBaseHealth() const; + Action, Error> GetDescription() const; Action, Error> GetItemsForSale() const; diff --git a/include/API/Types/ClientId.hpp b/include/API/Types/ClientId.hpp index 95dfea9be..60882731a 100644 --- a/include/API/Types/ClientId.hpp +++ b/include/API/Types/ClientId.hpp @@ -1,5 +1,6 @@ #pragma once +#include "API/Types/AccountId.hpp" #include "API/Types/BaseId.hpp" #include "API/Types/ShipId.hpp" #include "API/Types/SystemId.hpp" @@ -33,7 +34,6 @@ class ClientId explicit operator bool() const; // Returns the underlying value of the ClientId, it is generally recommended to not use this. - [[nodiscard]] uint GetValue() const { @@ -68,11 +68,11 @@ class ClientId /** * @brief Gets the Account of the clientId - * @returns On success : CAccount pointer of the Account. + * @returns On success : An account id class representing the Account. * @returns On fail : InvalidClientId if the client check fails. */ [[nodiscard]] - Action GetAccount() const; + Action GetAccount() const; /** * @brief Gets the Shiparch of the ship the client is using @@ -161,6 +161,19 @@ class ClientId */ [[nodiscard]] ClientData &GetData() const; + + /** + * @brief Gets the ip of the connected client + * @returns On success : A string containing the player's ip address + * @returns On fail : InvalidClientId + */ + [[nodiscard]] + Action GetPlayerIp() const; + + /** + * @brief Get's the current engine state of the client + * @returns A enum representing the engine state, defaulting to the player not being in space. + */ [[nodiscard]] EngineState GetEngineState() const; diff --git a/include/API/Types/ShipId.hpp b/include/API/Types/ShipId.hpp index 50ba36180..daf9e1ec2 100644 --- a/include/API/Types/ShipId.hpp +++ b/include/API/Types/ShipId.hpp @@ -7,7 +7,7 @@ class ShipId final : public ObjectId { public: explicit ShipId(const uint val) : ObjectId(val) {} - explicit ShipId() {} + explicit ShipId() = default; explicit ShipId(const ShipId& id) : ObjectId(id.GetValue()) {} [[nodiscard]] @@ -57,4 +57,7 @@ class ShipId final : public ObjectId return { equipment }; } + + Action IgniteFuse(uint fuseId, float id = 0.0f) const; + Action ExtinguishFuse(uint fuseId, float id = 0.0f) const; }; diff --git a/include/Core/ClientServerInterface.hpp b/include/Core/ClientServerInterface.hpp index a6b1329a1..ae2100654 100644 --- a/include/Core/ClientServerInterface.hpp +++ b/include/Core/ClientServerInterface.hpp @@ -10,7 +10,7 @@ class IServerImplHook std::wstring characterName; }; - inline static const std::unique_ptr chatData; + inline static std::unique_ptr chatData; inline static std::wstring charBefore; // The maximum number of players we can support is MaxClientId diff --git a/include/Core/FLHook.hpp b/include/Core/FLHook.hpp index 2c071371b..acac6d472 100644 --- a/include/Core/FLHook.hpp +++ b/include/Core/FLHook.hpp @@ -15,6 +15,7 @@ class FLHook final friend IServerImplHook; friend IClientImpl; friend InternalApi; + friend ClientId; // Static things diff --git a/include/Defs/Structs.hpp b/include/Defs/Structs.hpp index 59530b23a..4e65b46a4 100644 --- a/include/Defs/Structs.hpp +++ b/include/Defs/Structs.hpp @@ -84,12 +84,6 @@ struct PlayerInfo std::wstring hostname; }; -struct BaseHealth -{ - float currentHealth; - float maxHealth; -}; - struct DataMarketItem { uint archId; diff --git a/project/FLHook.vcxproj b/project/FLHook.vcxproj index 645fe9fb4..16e07325a 100644 --- a/project/FLHook.vcxproj +++ b/project/FLHook.vcxproj @@ -125,6 +125,7 @@ + diff --git a/project/FLHook.vcxproj.filters b/project/FLHook.vcxproj.filters index 94770181f..c70c90cb0 100644 --- a/project/FLHook.vcxproj.filters +++ b/project/FLHook.vcxproj.filters @@ -543,5 +543,8 @@ Include\API\Utils + + Include\API\Types + \ No newline at end of file diff --git a/source/API/FLServer/Admin.cpp b/source/API/FLServer/Admin.cpp index 10ce11248..fdb118748 100644 --- a/source/API/FLServer/Admin.cpp +++ b/source/API/FLServer/Admin.cpp @@ -1,155 +1,7 @@ #include "PCH.hpp" -#include "API/FLServer/Admin.hpp" -#include "API/FLServer/Client.hpp" -#include "Core/FLHook.hpp" #include "Core/ApiInternal.hpp" - - -std::wstring GetPlayerIP(ClientId client) -{ - const CDPClientProxy* cdpClient = FLHook::clientProxyArray[client - 1]; - if (!cdpClient) - { - return L""; - } - - // get ip - char* P1; - char* IdirectPlay8Address; - wchar_t hostname[] = L"hostname"; - memcpy(&P1, DWORD(FLHook::cdpServer) + 4, 4); - - wchar_t wIp[1024] = L""; - long sizeofIP = sizeof wIp; - long dataType = 1; - __asm { - push 0 ; flags - lea edx, IdirectPlay8Address - push edx ; address - mov edx, [cdpClient] - mov edx, [edx+8] - push edx ; dpnid - mov eax, [P1] - push eax - mov ecx, [eax] - call dword ptr[ecx + 0x28] ; GetClientAddress - cmp eax, 0 - jnz some_error - - lea eax, dataType - push eax - lea eax, sizeofIP - push eax - lea eax, wIP - push eax - lea eax, hostname - push eax - mov ecx, [IdirectPlay8Address] - push ecx - mov ecx, [ecx] - call dword ptr[ecx+0x40] ; GetComponentByName - - mov ecx, [IdirectPlay8Address] - push ecx - mov ecx, [ecx] - call dword ptr[ecx+0x08] ; Release - some_error: - } - - return wIp; -} - -Action GetPlayerInfo(const std::variant& player, bool alsoCharmenu) -{ - ClientId client = HkApi::ExtractClientID(player); - - if (client == UINT_MAX || (Client::IsInCharSelectMenu(client) && !alsoCharmenu)) - { - return { cpp::fail(Error::PlayerNotLoggedIn) }; - } - - PlayerInfo pi; - const wchar_t* activeCharname = (wchar_t*)Players.GetActiveCharacterName(client); - - pi.client = client; - pi.character = activeCharname ? activeCharname : L""; - pi.baseName = pi.systemName = L""; - - uint base = 0; - uint system = 0; - pub::Player::GetBase(client, base); - pub::Player::GetSystem(client, system); - pub::Player::GetShip(client, pi.ship); - - if (base) - { - char Basename[1024] = ""; - pub::GetBaseNickname(Basename, sizeof Basename, base); - pi.baseName = StringUtils::stows(Basename); - } - - if (system) - { - char Systemname[1024] = ""; - pub::GetSystemNickname(Systemname, sizeof Systemname, system); - pi.systemName = StringUtils::stows(Systemname); - pi.system = system; - } - - // get ping - auto ci = GetConnectionStats(client).Raw(); - if (ci.has_error()) - { - FLHook::GetLogger().Log(LogLevel::Warn, L"Invalid client ID provided when getting connection stats"); - return { cpp::fail(Error::PlayerNotLoggedIn) }; - } - pi.connectionInfo = ci.value(); - - // get ip - pi.IP = GetPlayerIP(client); - - pi.hostname = ClientInfo::At(client).hostname; - - return { pi }; -} - -std::list GetPlayers() -{ - std::list ret; - - PlayerData* playerDb = nullptr; - while ((playerDb = Players.traverse_active(playerDb))) - { - ClientId client = playerDb->onlineId; - - if (Client::IsInCharSelectMenu(client)) - { - continue; - } - - ret.emplace_back(GetPlayerInfo(client, false).Unwrap()); - } - return ret; -} - -Action GetConnectionStats(ClientId client) -{ - if (client < 1 || client > MaxClientId) - { - return { cpp::fail(Error::InvalidClientId) }; - } - - CDPClientProxy* cdpClient = FLHook::clientProxyArray[client - 1]; - - DPN_CONNECTION_INFO ci; - if (!cdpClient || !cdpClient->GetConnectionStats(&ci)) - { - return { cpp::fail(Error::InvalidClientId) }; - } - - return { ci }; -} +#include "Core/FLHook.hpp" Action ChangeNPCSpawn(bool disable) { diff --git a/source/API/Types/BaseId.cpp b/source/API/Types/BaseId.cpp index 480cd0a6d..ec3983f2d 100644 --- a/source/API/Types/BaseId.cpp +++ b/source/API/Types/BaseId.cpp @@ -82,9 +82,26 @@ Action BaseId::GetName() const return { FLHook::GetInfocardManager().GetInfocard(base->baseIdS) }; } -Action, Error> BaseId::GetDescription() + +Action, Error> BaseId::GetBaseHealth() const +{ + float curHealth; + float maxHealth; + const Universe::IBase* base = Universe::get_base(value); + + if (!base) + { + return { cpp::fail(Error::InvalidBase) }; + } + + pub::SpaceObj::GetHealth(base->spaceObjId, curHealth, maxHealth); + return { std::make_pair(curHealth, maxHealth) }; +} + +Action, Error> BaseId::GetDescription() const { ValidBaseCheck; + // TODO: Get internal description of base } diff --git a/source/API/Types/ClientId.cpp b/source/API/Types/ClientId.cpp index a96835a7e..2ecd7593e 100644 --- a/source/API/Types/ClientId.cpp +++ b/source/API/Types/ClientId.cpp @@ -1,6 +1,5 @@ #include "PCH.hpp" -#include "API/API.hpp" #include "API/Types/ClientId.hpp" #include "API/InternalApi.hpp" @@ -78,10 +77,9 @@ ClientId::operator bool() const return false; } - PlayerData* playerDb = nullptr; - while ((playerDb = Players.traverse_active(playerDb))) + for (auto client : FLHook::Clients()) { - if (playerDb->onlineId == value) + if (client.id.GetValue() == value) { return true; } @@ -287,8 +285,8 @@ bool ClientId::InCharacterSelect() const { return Players.GetActiveCharacterName bool ClientId::IsAlive() const { - bool charMenu = InCharacterSelect(); - bool docked = IsDocked(); + const bool charMenu = InCharacterSelect(); + const bool docked = IsDocked(); uint ship; pub::Player::GetShip(value, ship); @@ -331,6 +329,65 @@ Action, Error> ClientId::EnumCargo(int& remainingHoldSize) ClientData& ClientId::GetData() const { return FLHook::Clients()[value]; } +Action ClientId::GetPlayerIp() const +{ + const CDPClientProxy* cdpClient = FLHook::clientProxyArray[value - 1]; + // clang-format off + if (!cdpClient) + { + + // I hate labels, but it allows our inline asm to escape properly + invalid: + return { cpp::fail(Error::InvalidClientId) }; + // clang-format on + } + + // get ip + char* p1; + char* address; + // ReSharper disable once CppVariableCanBeMadeConstexpr + static const wchar_t hostname[] = L"hostname"; + memcpy(&p1, reinterpret_cast(reinterpret_cast(FLHook::cdpServer) + 4), 4); + + wchar_t wIp[1024] = L""; + long sizeOfIp = sizeof wIp; + long dataType = 1; + __asm { + push 0 ; flags + lea edx, address + push edx ; address + mov edx, [cdpClient] + mov edx, [edx+8] + push edx ; dpnid + mov eax, [p1] + push eax + mov ecx, [eax] + call dword ptr[ecx + 0x28] ; GetClientAddress + cmp eax, 0 + jnz invalid + + lea eax, dataType + push eax + lea eax, sizeOfIp + push eax + lea eax, wIP + push eax + lea eax, hostname + push eax + mov ecx, [address] + push ecx + mov ecx, [ecx] + call dword ptr[ecx+0x40] ; GetComponentByName + + mov ecx, [address] + push ecx + mov ecx, [ecx] + call dword ptr[ecx+0x08] ; Release + } + + return { std::wstring(wIp) }; +} + EngineState ClientId::GetEngineState() const { const auto& data = GetData(); @@ -371,7 +428,7 @@ Action ClientId::Kick(const std::optional& reaso if (reason.has_value()) { const std::wstring msg = StringUtils::ReplaceStr(FLHookConfig::i()->chatConfig.msgStyle.kickMsg, L"%reason", StringUtils::XmlText(reason.value())); - Hk::Chat::MsgU(msg); + FLHook::MessageUniverse(msg); } if (!delay.has_value()) @@ -394,7 +451,7 @@ Action ClientId::SaveChar() const ClientCheck; CharSelectCheck; - DWORD jmp = FLHook::Offset(FLHook::BinaryType::Server, AddressList::SaveCharacter); + const DWORD jmp = FLHook::Offset(FLHook::BinaryType::Server, AddressList::SaveCharacter); std::array nop = { 0x90, 0x90 }; std::array testAl = { 0x74, 0x44 }; @@ -402,7 +459,7 @@ Action ClientId::SaveChar() const pub::Save(value, 1); MemUtils::WriteProcMem(jmp, testAl.data(), testAl.size()); // restore - auto& data = FLHook::Clients()[value]; + const auto& data = FLHook::Clients()[value]; // Save account data const CAccount* acc = Players.FindAccountFromClientID(value); @@ -496,7 +553,7 @@ Action ClientId::Message(const std::wstring_view message, const Mes CharSelectCheck; const auto formattedMessage = StringUtils::FormatMsg(color, format, std::wstring(message)); - InternalApi::SendMessage(L"", *this, formattedMessage); + InternalApi::SendMessage(*this, formattedMessage); return { {} }; } diff --git a/source/API/Types/ShipId.cpp b/source/API/Types/ShipId.cpp index 774a07c47..bed8eff28 100644 --- a/source/API/Types/ShipId.cpp +++ b/source/API/Types/ShipId.cpp @@ -272,3 +272,75 @@ Action ShipId::AddCargo(uint good, uint count, bool mission) return { {} }; } + +Action ShipId::IgniteFuse(uint fuseId, float id) const +{ + auto tempVal = value; + IObjInspectImpl* inspect; + + if (uint _; !FLHook::GetShipInspect(tempVal, inspect, _)) + { + return { cpp::fail(Error::InvalidShip) }; + } + + // ReSharper disable once CppTooWideScopeInitStatement + bool success = false; + __asm + { + push ecx + lea eax, fuseId + push 0 // this was previously a float called skip. It is unknown what it does. + push id + push 0 // SUBOBJ_Id_NONE + push eax + push 0 // this was previously a float called lifetime. It is unknown what it does. + mov ecx, inspect + mov eax, [ecx] + call[eax + 0x1E4] + mov success, al + pop ecx + } + + // TODO: Validate the above asm left the stack in the correct way + if (!success) + { + return { cpp::fail(Error::InvalidInput) }; + } + + return { {} }; +} + +Action ShipId::ExtinguishFuse(uint fuseId, float id) const +{ + auto tempVal = value; + IObjInspectImpl* inspect; + + if (uint _; !FLHook::GetShipInspect(tempVal, inspect, _)) + { + return { cpp::fail(Error::InvalidShip) }; + } + + // ReSharper disable once CppTooWideScopeInitStatement + bool success = false; + __asm + { + push ecx + mov ecx, inspect + lea eax, fuseId + push id + push 0 // SUBOBJ_Id_NONE + push eax + mov eax, [ecx] + call [eax+0x1E8] + mov success, al + pop ecx + } + + // TODO: Validate the above asm left the stack in the correct way + if (!success) + { + return { cpp::fail(Error::InvalidInput) }; + } + + return { {} }; +} diff --git a/source/Core/Timers.cpp b/source/Core/Timers.cpp index ca263e496..ca6e06022 100644 --- a/source/Core/Timers.cpp +++ b/source/Core/Timers.cpp @@ -2,7 +2,6 @@ #include -#include "API/API.hpp" #include "Core/FLHook.hpp" #include "Core/MessageHandler.hpp" #include "Core/TempBan.hpp" @@ -46,21 +45,21 @@ void FLHook::PublishServerStats() GetProcessMemoryInfo(GetCurrentProcess(), &memCounter, sizeof memCounter); stats.memoryUsage = memCounter.WorkingSetSize; - PlayerData* pd = nullptr; - for (pd = Players.traverse_active(pd); pd; pd = Players.traverse_active(pd)) + for (auto client : Clients()) { - const auto info = Hk::Admin::GetPlayerInfo(pd->onlineId, false).Raw(); - if (info.has_error()) + if (client.characterName.empty()) { continue; } + auto system = client.id.GetSystemId().Unwrap(); + ServerStats::Player player; - player.clientId = pd->onlineId; - player.playerName = info.value().character; - player.systemName = info.value().systemName; - player.systemNick = StringUtils::stows(Universe::get_system(info.value().system)->nickname); - player.ipAddress = info.value().IP; + player.clientId = client.id.GetValue(); + player.playerName = client.characterName; + player.systemName = system.GetName().Unwrap(); + player.systemNick = system.GetNickName().Unwrap(); + player.ipAddress = client.id.GetPlayerIp().Unwrap(); stats.players.emplace_back(player); } @@ -81,58 +80,49 @@ void FLHook::TimerCheckKick() { TryHook { - // for all players - PlayerData* playerData = nullptr; - while ((playerData = Players.traverse_active(playerData))) + auto time = TimeUtils::UnixTime(); + for (auto client : Clients()) { - ClientId client = playerData->onlineId; - if (client < 1 || client > MaxClientId) + if (client.kickTime) { - continue; - } - - if (ClientInfo::At(client).tmKickTime) - { - if (TimeUtils::UnixMilliseconds() >= ClientInfo::At(client).tmKickTime) + if (time >= client.kickTime) { - Hk::Player::Kick(client); // kick time expired - ClientInfo::At(client).tmKickTime = 0; + client.id.Kick(); + client.kickTime = 0; } - continue; // player will be kicked anyway + + continue; } + const auto* config = FLHookConfig::c(); if (config->general.antiBaseIdle) { // anti base-idle check - uint baseId; - pub::Player::GetBase(client, baseId); - if (baseId && ClientInfo::At(client).baseEnterTime && time(nullptr) - ClientInfo::At(client).baseEnterTime >= config->general.antiBaseIdle) + if (client.baseEnterTime && time(nullptr) - client.baseEnterTime >= config->general.antiBaseIdle) { - // AddKickLog(client, "base idling"); - Hk::Player::MsgAndKick(client, L"Base idling", 10); - ClientInfo::At(client).baseEnterTime = 0; + client.id.Kick(L"Base idling", 10); + client.baseEnterTime = 0; } } if (config->general.antiCharMenuIdle) { // anti charmenu-idle check - if (Hk::Client::IsInCharSelectMenu(client)) + if (!client.characterName.empty()) { - if (!ClientInfo::At(client).charMenuEnterTime) + if (!client.charMenuEnterTime) { - ClientInfo::At(client).charMenuEnterTime = static_cast(time(nullptr)); + client.charMenuEnterTime = static_cast(time(nullptr)); } - else if (time(nullptr) - ClientInfo::At(client).charMenuEnterTime >= config->general.antiCharMenuIdle) + else if (time(nullptr) - client.charMenuEnterTime >= config->general.antiCharMenuIdle) { - // AddKickLog(client, "Charmenu idling"); - Hk::Player::Kick(client); - ClientInfo::At(client).charMenuEnterTime = 0; + client.id.Kick(); + client.charMenuEnterTime = 0; } } else { - ClientInfo::At(client).charMenuEnterTime = 0; + client.charMenuEnterTime = 0; } } } @@ -146,42 +136,36 @@ void FLHook::TimerNpcAndF1Check() ; TryHook { - PlayerData* playerData = nullptr; - while ((playerData = Players.traverse_active(playerData))) + auto time = TimeUtils::UnixTime(); + for (auto& client : Clients()) { - ClientId client = playerData->onlineId; - if (client < 1 || client > MaxClientId) - { - continue; - } - - if (ClientInfo::At(client).tmF1Time && TimeUtils::UnixMilliseconds() >= ClientInfo::At(client).tmF1Time) + if (client.f1Time && time >= client.f1Time) { // f1 - Server.CharacterInfoReq(client, false); - ClientInfo::At(client).tmF1Time = 0; + Server.CharacterInfoReq(client.id.GetValue(), false); + client.f1Time = 0; } - else if (ClientInfo::At(client).tmF1TimeDisconnect && TimeUtils::UnixMilliseconds() >= ClientInfo::At(client).tmF1TimeDisconnect) + else if (client.timeDisconnect && time >= client.timeDisconnect) { ulong dataArray[64] = { 0 }; - dataArray[26] = client; - + dataArray[26] = client.id.GetValue(); + DWORD rcDisconnect = static_cast(AddressList::RcDisconnect); __asm { pushad lea ecx, dataArray mov eax, [remoteClient] - add eax, ADDR_RC_DISCONNECT + add eax, rcDisconnect call eax // disconnect popad } - ClientInfo::At(client).tmF1TimeDisconnect = 0; + client.timeDisconnect = 0; continue; } } const auto* config = FLHookConfig::c(); - if (config->general.disableNPCSpawns && CoreGlobals::c()->serverLoadInMs >= config->general.disableNPCSpawns) + if (config->general.disableNPCSpawns && instance->serverLoadInMs >= config->general.disableNPCSpawns) { Hk::Admin::ChangeNPCSpawn(true); // serverload too high, disable npcs } diff --git a/source/Hooks/ClientServerInterface/Base.cpp b/source/Hooks/ClientServerInterface/Base.cpp index 5ed92b190..5a13b7e6f 100644 --- a/source/Hooks/ClientServerInterface/Base.cpp +++ b/source/Hooks/ClientServerInterface/Base.cpp @@ -1,6 +1,6 @@ #include "PCH.hpp" -#include "API/API.hpp" +#include "API/Utils/PerfTimer.hpp" #include "Core/ClientServerInterface.hpp" void BaseEnterInner([[maybe_unused]] uint baseId, [[maybe_unused]] ClientId client) @@ -12,28 +12,26 @@ void BaseEnterInnerAfter([[maybe_unused]] uint baseId, ClientId client) { TryHook { - // adjust cash, this is necessary when cash was added while use was in - // charmenu/had other char selected - std::wstring charName = StringUtils::ToLower(client.GetCharacterName().Unwrap()); - for (const auto& i : ClientInfo::At(client).moneyFix) + auto& data = client.GetData(); + // adjust cash, this is necessary when cash was added while use was in charmenu/had other char selected + const std::wstring charName = StringUtils::ToLower(client.GetCharacterName().Unwrap()); + for (const auto& i : data.moneyFix) { if (i.character == charName) { - Hk::Player::AddCash(charName, i.amount); - ClientInfo::At(client).moneyFix.remove(i); + client.AddCash(i.amount); + data.moneyFix.remove(i); break; } } // anti base-idle - ClientInfo::At(client).baseEnterTime = static_cast(time(nullptr)); + data.baseEnterTime = static_cast(time(nullptr)); // print to log if the char has too much money - if (const auto value = Hk::Player::GetShipValue((const wchar_t*)Players.GetActiveCharacterName(client)).Raw(); - value.has_value() && value.value() > 2000000000) + if (const auto value = client.GetWealth().Unwrap(); value > 2000000000) { - const std::wstring charname = (const wchar_t*)Players.GetActiveCharacterName(client); - FLHook::GetLogger().Log(LogLevel::Trace, std::format(L"Possible corrupt ship charname={} asset_value={}", charname, value.value())); + FLHook::GetLogger().Log(LogLevel::Trace, std::format(L"Possible corrupt ship charname={} asset_value={}", charName, value)); } } CatchHook({}) @@ -50,7 +48,7 @@ void __stdcall IServerImplHook::BaseEnter(uint baseId, ClientId client) if (!skip) { - CallServerPreamble { Server.BaseEnter(baseId, client); } + CallServerPreamble { Server.BaseEnter(baseId, client.GetValue()); } CallServerPostamble(true, ); } BaseEnterInnerAfter(baseId, client); @@ -61,8 +59,9 @@ void BaseExitInner(uint baseId, ClientId client) { TryHook { - ClientInfo::At(client).baseEnterTime = 0; - ClientInfo::At(client).lastExitedBaseId = baseId; + auto& data = client.GetData(); + data.baseEnterTime = 0; + data.lastExitedBaseId = baseId; } CatchHook({}) } @@ -83,7 +82,7 @@ void __stdcall IServerImplHook::BaseExit(uint baseId, ClientId client) if (!skip) { - CallServerPreamble { Server.BaseExit(baseId, client); } + CallServerPreamble { Server.BaseExit(baseId, client.GetValue()); } CallServerPostamble(true, ); } BaseExitInnerAfter(baseId, client); @@ -94,7 +93,7 @@ void __stdcall IServerImplHook::BaseExit(uint baseId, ClientId client) void __stdcall IServerImplHook::BaseInfoRequest(unsigned int unk1, unsigned int unk2, bool unk3) { FLHook::GetLogger().Log(LogLevel::Trace, - std::format(L"BaseInfoRequest(\n\tunsigned int unk1 = {}\n\tunsigned int unk2 = {}\n\tbool unk3 = {}\n)", unk1, unk2, unk3)); + std::format(L"BaseInfoRequest(\n\tunsigned int unk1 = {}\n\tunsigned int unk2 = {}\n\tbool unk3 = {}\n)", unk1, unk2, unk3)); if (const auto skip = CallPlugins(&Plugin::OnRequestBaseInfo, unk1, unk2, unk3); !skip) { diff --git a/source/Hooks/ClientServerInterface/LaunchComplete.cpp b/source/Hooks/ClientServerInterface/LaunchComplete.cpp index 3b92948a4..e22e7bae8 100644 --- a/source/Hooks/ClientServerInterface/LaunchComplete.cpp +++ b/source/Hooks/ClientServerInterface/LaunchComplete.cpp @@ -8,17 +8,18 @@ void LaunchCompleteInner(uint, uint shipId) TryHook { - if (ClientId client = Hk::Client::GetClientIdByShip(shipId).Unwrap()) + if (const auto client = ShipId(shipId).GetPlayer().value_or(ClientId())) { - ClientInfo::At(client).tmSpawnTime = TimeUtils::UnixMilliseconds(); // save for anti-dockkill + auto& data = client.GetData(); + data.spawnTime = TimeUtils::UnixTime(); // save for anti-dockkill // is there spawnprotection? if (FLHookConfig::i()->general.antiDockKill > 0) { - ClientInfo::At(client).spawnProtected = true; + data.spawnProtected = true; } else { - ClientInfo::At(client).spawnProtected = false; + data.spawnProtected = false; } } } diff --git a/source/Hooks/ClientServerInterface/Trade.cpp b/source/Hooks/ClientServerInterface/Trade.cpp index 50fe511dc..cccfd0cd7 100644 --- a/source/Hooks/ClientServerInterface/Trade.cpp +++ b/source/Hooks/ClientServerInterface/Trade.cpp @@ -2,7 +2,6 @@ #include "Core/ClientServerInterface.hpp" -#include "API/API.hpp" #include "API/Utils/PerfTimer.hpp" void InitiateTradeInner(const ClientId client1, const ClientId client2)