Skip to content

Commit

Permalink
- Use partially reversed BestPathInfo for IServerImpl::RequestBestPat…
Browse files Browse the repository at this point in the history
…h hook

- Add Hk::Player::SendBestPath function which sets the waypoints of a player
  • Loading branch information
Schmackbolzen committed Jan 22, 2024
1 parent 29e2925 commit 1185002
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/Tools/Hk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ namespace Hk
DLL cpp::result<int, Error> IncrementPvpKills(const std::variant<uint, std::wstring>& player);
DLL cpp::result<const uint, Error> GetSystemByNickname(std::variant<std::string, std::wstring> nickname);
DLL CShip* CShipFromShipDestroyed(const DWORD** ecx);
DLL cpp::result<int, Error> SendBestPath(const std::variant<uint, std::wstring>& player, int iStartSysId, Vector vStartPos, int iTargetSysId, Vector vTargetPos);
} // namespace Player

namespace Solar
Expand Down
25 changes: 25 additions & 0 deletions source/Helpers/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1780,4 +1780,29 @@ namespace Hk::Player

return {};
}

cpp::result<int, Error> SendBestPath(const std::variant<uint, std::wstring>& player, int iStartSysId, Vector vStartPos, int iTargetSysId, Vector vTargetPos)
{
ClientId client = Hk::Client::ExtractClientID(player);
if (client == UINT_MAX)
{
return cpp::fail(Error::PlayerNotLoggedIn);
}

BestPathInfo bpi;
bpi.iWaypointStartIndex = 1; //Use 1 as start index so the waypoints of the player get overwritten
bpi.iStartSysId = iStartSysId;
bpi.vStartPos = vStartPos;
bpi.iTargetSysId = iTargetSysId;
bpi.vTargetPos = vTargetPos;
bpi.iDunno1 = 2;
bpi.bDunno2 = 0;
bpi.iDunno3 = 0;
bpi.iDunno4 = 0;

// The original asm code sets 52 as size for the struct. So better hard code it instead of sizeof in case someone messes up the struct in a commit.
Server.RequestBestPath(client, (uchar*)&bpi, 52);

return {};
}
} // namespace Hk::Player
10 changes: 5 additions & 5 deletions source/HkClientServerInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4717,24 +4717,24 @@ namespace IServerImplHook

namespace IServerImplHook
{
void __stdcall RequestBestPath(ClientId client, uint _genArg1, int _genArg2)
void __stdcall RequestBestPath(ClientId client, BestPathInfo* bpi, int bestPathInfoStructSize)
{
AddLog(LogType::Normal,
LogLevel::Debug,
std::format("RequestBestPath(\n\tClientId client = {}\n\tuint _genArg1 = 0x{:08X}\n\tint _genArg2 = {}\n)", client, _genArg1, _genArg2));
std::format("RequestBestPath(\n\tClientId client = {}\n\tuint _genArg1 = 0x{:08X}\n\tint _genArg2 = {}\n)", client, (uint)bpi, bestPathInfoStructSize));


if (auto skip = CallPluginsBefore<void>(HookedCall::IServerImpl__RequestBestPath, client, _genArg1, _genArg2);
if (auto skip = CallPluginsBefore<void>(HookedCall::IServerImpl__RequestBestPath, client, bpi, bestPathInfoStructSize);
!skip)
{
CALL_SERVER_PREAMBLE
{
Server.RequestBestPath(client, (uchar*)_genArg1, _genArg2);
Server.RequestBestPath(client, (uchar*)bpi, bestPathInfoStructSize);
}
CALL_SERVER_POSTAMBLE(true, );
}

CallPluginsAfter(HookedCall::IServerImpl__RequestBestPath, client, _genArg1, _genArg2);
CallPluginsAfter(HookedCall::IServerImpl__RequestBestPath, client, bpi, bestPathInfoStructSize);
}
} // namespace IServerImplHook

Expand Down

0 comments on commit 1185002

Please sign in to comment.