Skip to content

Commit

Permalink
Fix flserver crashing on login hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazrius committed Nov 18, 2023
1 parent b621358 commit 0822183
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 63 deletions.
4 changes: 2 additions & 2 deletions include/Core/AddressList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ enum class AddressList : uint
CharFileEncryption = 0x6E10D,
CharFileEncryption2 = 0x6BFA6,
CrcAntiCheat = 0x6FAF0,
CpList = 0x43D74,
CdpServer = 0xA284,
CreateChar = 0x6B790,
FlNew = 0x80012,
ServerFlServer = 0x1BC90,
Expand All @@ -25,10 +23,12 @@ enum class AddressList : uint

RcDisconnect = 0x93E0,
RcSendChat = 0x7F30,
CpList = 0x43D74,

// Dalib.dll Offsets

DalibDiscSuppress = 0x49C6,
CdpServer = 0xA284,

// Server.dll Offsets

Expand Down
2 changes: 1 addition & 1 deletion include/Core/FLHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class FLHook final
bool allocated;
};

std::array<Entry, 128> entries;
std::vector<Entry> entries;
};

static PatchInfo exePatch;
Expand Down
5 changes: 0 additions & 5 deletions source/FLHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ FLHook::FLHook()
LoadLibraryA(lib);
}

Logger::Log(LogLevel::Info, L"Loading Freelancer INIs");

// Force constructor to run
// TODO:NPC Personalities. Hk::Personalities::LoadPersonalities();

PatchClientImpl();

CallPlugins(&Plugin::OnLoadSettings);
Expand Down
1 change: 0 additions & 1 deletion source/Hooks/ClientServerInterface/Login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
bool LoginInnerBefore(const SLoginInfo& li, ClientId client)
{
// The startup cache disables reading of the banned file. Check this manually on login and boot the player if they are banned.

if (auto acc = client.GetAccount().Unwrap())
{
const auto dir = acc.GetDirectoryName().Unwrap();
Expand Down
120 changes: 66 additions & 54 deletions source/Hooks/HookInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,69 @@
#include "Core/IEngineHook.hpp"
#include "Core/IpResolver.hpp"

FLHook::PatchInfo FLHook::exePatch = { "flserver.exe",
0x0400000,
{ {
{ 0x041B094, &IEngineHook::UpdateTime, 4, nullptr, false },
{ 0x041BAB0, &IEngineHook::ElapseTime, 4, nullptr, false },
} } };

FLHook::PatchInfo FLHook::contentPatch = { "content.dll",
0x6EA0000,
{ {
{ 0x6FB358C, &IEngineHook::DockCall, 4, nullptr, false },
} } };

FLHook::PatchInfo FLHook::commonPatch = { "common.dll",
0x6260000,
{ {

{ 0x0639C138, &IEngineHook::NakedCShipInit, 4, &IEngineHook::oldInitCShip, false },
{ 0x0639C064, &IEngineHook::NakedCShipDestroy, 4, &IEngineHook::oldDestroyCShip, false },
} } };

FLHook::PatchInfo FLHook::serverPatch = { "server.dll",
0x6CE0000,
{ {
{ 0x6D67274, &IEngineHook::NakedShipDestroyed, 4, &oldShipDestroyed, false },
{ 0x6D641EC, &IEngineHook::NakedAddDamageEntry, 4, nullptr, false },
{ 0x6D67320, &IEngineHook::NakedGuidedHit, 4, &oldGuidedHit, false },
{ 0x6D65448, &IEngineHook::NakedGuidedHit, 4, nullptr, false },
{ 0x6D67670, &IEngineHook::NakedGuidedHit, 4, nullptr, false },
{ 0x6D653F4, &IEngineHook::NakedDamageHit, 4, &oldDamageHit, false },
{ 0x6D672CC, &IEngineHook::NakedDamageHit, 4, nullptr, false },
{ 0x6D6761C, &IEngineHook::NakedDamageHit, 4, nullptr, false },
{ 0x6D65458, &IEngineHook::NakedDamageHit2, 4, &oldDamageHit2, false },
{ 0x6D67330, &IEngineHook::NakedDamageHit2, 4, nullptr, false },
{ 0x6D67680, &IEngineHook::NakedDamageHit2, 4, nullptr, false },
{ 0x6D67668, &IEngineHook::NakedNonGunWeaponHitsBase, 4, &oldNonGunWeaponHitsBase, false },
{ 0x6D6420C, &IEngineHook::NakedLaunchPosition, 4, &IEngineHook::oldLaunchPosition, false },
{ 0x6D648E0, &IEngineHook::FreeReputationVibe, 4, nullptr, false },
} } };

FLHook::PatchInfo FLHook::remoteClientPatch = { "remoteclient.dll",
0x6B30000,
{ {
{ 0x6B6BB80, &IServerImplHook::SendChat, 4, &rcSendChatMsg, false },
} } };

FLHook::PatchInfo FLHook::dalibPatch = { "dalib.dll",
0x65C0000,
{ {
{ 0x65C4BEC, &IEngineHook::NakedDisconnectPacketSent, 4, &oldDisconnectPacketSent, false },
} } };
FLHook::PatchInfo FLHook::exePatch = {
"flserver.exe",
0x0400000,
{
{ 0x041B094, &IEngineHook::UpdateTime, 4, nullptr, false },
{ 0x041BAB0, &IEngineHook::ElapseTime, 4, nullptr, false },
}
};

FLHook::PatchInfo FLHook::contentPatch = {
"content.dll",
0x6EA0000,
{
{ 0x6FB358C, &IEngineHook::DockCall, 4, nullptr, false },
}
};

FLHook::PatchInfo FLHook::commonPatch = {
"common.dll",
0x6260000,
{

{ 0x0639C138, &IEngineHook::NakedCShipInit, 4, &IEngineHook::oldInitCShip, false },
{ 0x0639C064, &IEngineHook::NakedCShipDestroy, 4, &IEngineHook::oldDestroyCShip, false },
}
};

FLHook::PatchInfo FLHook::serverPatch = {
"server.dll",
0x6CE0000,
{
{ 0x6D67274, &IEngineHook::NakedShipDestroyed, 4, &oldShipDestroyed, false },
{ 0x6D641EC, &IEngineHook::NakedAddDamageEntry, 4, nullptr, false },
{ 0x6D67320, &IEngineHook::NakedGuidedHit, 4, &oldGuidedHit, false },
{ 0x6D65448, &IEngineHook::NakedGuidedHit, 4, nullptr, false },
{ 0x6D67670, &IEngineHook::NakedGuidedHit, 4, nullptr, false },
{ 0x6D653F4, &IEngineHook::NakedDamageHit, 4, &oldDamageHit, false },
{ 0x6D672CC, &IEngineHook::NakedDamageHit, 4, nullptr, false },
{ 0x6D6761C, &IEngineHook::NakedDamageHit, 4, nullptr, false },
{ 0x6D65458, &IEngineHook::NakedDamageHit2, 4, &oldDamageHit2, false },
{ 0x6D67330, &IEngineHook::NakedDamageHit2, 4, nullptr, false },
{ 0x6D67680, &IEngineHook::NakedDamageHit2, 4, nullptr, false },
{ 0x6D67668, &IEngineHook::NakedNonGunWeaponHitsBase, 4, &oldNonGunWeaponHitsBase, false },
{ 0x6D6420C, &IEngineHook::NakedLaunchPosition, 4, &IEngineHook::oldLaunchPosition, false },
{ 0x6D648E0, &IEngineHook::FreeReputationVibe, 4, nullptr, false },
}
};

FLHook::PatchInfo FLHook::remoteClientPatch = {
"remoteclient.dll",
0x6B30000,
{
{ 0x6B6BB80, &IServerImplHook::SendChat, 4, &rcSendChatMsg, false },
}
};

FLHook::PatchInfo FLHook::dalibPatch = {
"dalib.dll",
0x65C0000,
{
{ 0x65C4BEC, &IEngineHook::NakedDisconnectPacketSent, 4, &oldDisconnectPacketSent, false },
}
};

bool FLHook::ApplyPatch(PatchInfo& pi)
{
Expand Down Expand Up @@ -268,13 +280,13 @@ void FLHook::InitHookExports()

auto loadRepFromCharFile = reinterpret_cast<FARPROC>(IEngineHook::NakedLoadReputationFromCharacterFile);

IEngineHook::oldLoadReputationFromCharacterFile = reinterpret_cast<FARPROC>(
Offset(BinaryType::Server, static_cast<AddressList>(static_cast<DWORD>(AddressList::SaveFileHouseEntrySaveAndLoadPatch) + 1)));

MemUtils::WriteProcMem(address, movEax.data(), 1);
MemUtils::WriteProcMem(address + 1, &loadRepFromCharFile, 4);
MemUtils::WriteProcMem(address + 5, jumpEax.data(), 2);

IEngineHook::oldLoadReputationFromCharacterFile =
reinterpret_cast<FARPROC>(Offset(BinaryType::Server, AddressList::SaveFileHouseEntrySaveAndLoadPatch) + 7);

// crc anti-cheat
crcAntiCheat = reinterpret_cast<CRCAntiCheatT>(Offset(BinaryType::Server, AddressList::CrcAntiCheat));

Expand Down

0 comments on commit 0822183

Please sign in to comment.