Skip to content

Commit

Permalink
Include player list packet handling in custom builds
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalh committed Sep 15, 2024
1 parent d5a55ba commit c0cded0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 30 deletions.
6 changes: 0 additions & 6 deletions common/include/common/config/BuildConfig.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#pragma once

#ifdef HAS_PF
#define MASK_AS_PF 1
#else
#define MASK_AS_PF 0
#endif

#define NO_CD_FIX 1
#define SPECTATE_MODE_SHOW_WEAPON 1
#define D3D_SWAP_DISCARD 1 // needed for MSAA
Expand Down
20 changes: 11 additions & 9 deletions game_patch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
file(GLOB EXPERIMENTAL_SRCS experimental/*.cpp experimental/*.h)

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/purefaction/pf_secret.cpp")
set(PF_SRCS
purefaction/pf.cpp
purefaction/pf.h
purefaction/pf_packets.h
set(PF_AC_SRCS
purefaction/pf_secret_packets.h
purefaction/pf_secret.cpp
purefaction/pf_secret.h
)
else()
set(PF_AC_SRCS
purefaction/pf_ac_stubs.cpp
)
endif()


set(SRCS
main/main.cpp
main/main.h
Expand Down Expand Up @@ -172,7 +173,11 @@ set(SRCS
sound/sound.h
sound/sound_ds.cpp
res/resources.rc
${PF_SRCS}
purefaction/pf.cpp
purefaction/pf.h
purefaction/pf_ac.h
purefaction/pf_packets.h
${PF_AC_SRCS}
${EXPERIMENTAL_SRCS}
)

Expand Down Expand Up @@ -206,9 +211,6 @@ endif()

target_compile_definitions(DashFaction PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX BUILD_DLL)

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/purefaction/pf_secret.cpp")
target_compile_definitions(DashFaction PRIVATE HAS_PF)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/experimental/experimental.cpp")
target_compile_definitions(DashFaction PRIVATE HAS_EXPERIMENTAL)
endif()
Expand Down
17 changes: 3 additions & 14 deletions game_patch/multi/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
#include <common/config/BuildConfig.h>
#include <common/rfproto.h>
#include <common/version/version.h>
#include <common/utils/enum-bitwise-operators.h>
#include <common/utils/list-utils.h>
#include <common/ComPtr.h>
#include <xlog/xlog.h>
#include <patch_common/CallHook.h>
#include <patch_common/FunHook.h>
#include <patch_common/CodeInjection.h>
#include <patch_common/AsmWriter.h>
#include <patch_common/ShortTypes.h>
#include <common/ComPtr.h>
#include "multi.h"
#include "server.h"
#include "server_internal.h"
Expand All @@ -36,13 +38,8 @@
#include "../misc/misc.h"
#include "../misc/player.h"
#include "../object/object.h"
#include <common/utils/enum-bitwise-operators.h>
#include <common/utils/list-utils.h>
#include "../os/console.h"

#if MASK_AS_PF
#include "../purefaction/pf.h"
#endif

// NET_IFINDEX_UNSPECIFIED is not defined in MinGW headers
#ifndef NET_IFINDEX_UNSPECIFIED
Expand Down Expand Up @@ -994,19 +991,15 @@ CodeInjection send_state_info_injection{
[](auto& regs) {
rf::Player* player = regs.edi;
trigger_send_state_info(player);
#if MASK_AS_PF
pf_player_level_load(player);
#endif
},
};

FunHook<void(rf::Player*)> send_players_packet_hook{
0x00481C70,
[](rf::Player *player) {
send_players_packet_hook.call_target(player);
#if MASK_AS_PF
pf_player_init(player);
#endif
if (rf::is_server) {
server_reliable_socket_ready(player);
}
Expand All @@ -1028,9 +1021,7 @@ FunHook<void __fastcall(void*, int, int, bool, int)> multi_io_stats_add_hook{0x0
static void process_custom_packet([[maybe_unused]] void* data, [[maybe_unused]] int len,
[[maybe_unused]] const rf::NetAddr& addr, [[maybe_unused]] rf::Player* player)
{
#if MASK_AS_PF
pf_process_packet(data, len, addr, player);
#endif
}

CodeInjection multi_io_process_packets_injection{
Expand All @@ -1053,11 +1044,9 @@ CodeInjection multi_io_process_packets_injection{
CallHook<void(const void*, size_t, const rf::NetAddr&, rf::Player*)> process_unreliable_game_packets_hook{
0x00479244,
[](const void* data, size_t len, const rf::NetAddr& addr, rf::Player* player) {
#if MASK_AS_PF
if (pf_process_raw_unreliable_packet(data, len, addr)) {
return;
}
#endif
rf::multi_io_process_packets(data, len, addr, player);
},
};
Expand Down
2 changes: 1 addition & 1 deletion game_patch/purefaction/pf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "../multi/multi.h"
#include "pf.h"
#include "pf_packets.h"
#include "pf_secret.h"
#include "pf_ac.h"

void pf_send_reliable_packet(rf::Player* player, const void* data, int len)
{
Expand Down
18 changes: 18 additions & 0 deletions game_patch/purefaction/pf_ac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <cstddef>
#include "pf_packets.h"

// Forward declarations
namespace rf {
struct NetAddr;
struct Player;
}

bool pf_ac_process_packet(const void* data, size_t len, const rf::NetAddr& addr, rf::Player* player);
void pf_ac_init_player(rf::Player* player);
void pf_ac_verify_player(rf::Player* player);
pf_pure_status pf_ac_get_pure_status(rf::Player* player);

// callback
void pf_player_verified(rf::Player* player, pf_pure_status pure_status);
22 changes: 22 additions & 0 deletions game_patch/purefaction/pf_ac_stubs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "pf_ac.h"
#include "pf_packets.h"
#include "../rf/player/player.h"
#include "../rf/multi.h"

bool pf_ac_process_packet(const void*, size_t, const rf::NetAddr&, rf::Player*)
{
return false;
}

void pf_ac_init_player(rf::Player*)
{
}

void pf_ac_verify_player(rf::Player*)
{
}

pf_pure_status pf_ac_get_pure_status(rf::Player*)
{
return pf_pure_status::none;
}

0 comments on commit c0cded0

Please sign in to comment.