Skip to content

Commit

Permalink
Fixed disconnecting the client breaking the pipe permanently
Browse files Browse the repository at this point in the history
  • Loading branch information
arcturus-prime committed Jul 9, 2024
1 parent 86f0510 commit 7962d05
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "studio-packet-dumper-client"
name = "client"
version = "0.1.0"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion client/src/packet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub enum Packet {
Test {
RemoteEvent {
hello: u8,
}
}
8 changes: 4 additions & 4 deletions dumper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
project(StudioPacketDumper LANGUAGES CXX C)

add_library(StudioPacketDumper SHARED "src/main.cpp")
add_library(dumper SHARED "src/main.cpp")

if(MSVC)
target_compile_options(StudioPacketDumper PRIVATE /W4 /WX)
target_compile_options(dumper PRIVATE /W4 /WX)
else()
target_compile_options(StudioPacketDumper PRIVATE -Wall -Wextra -Wpedantic -Werror)
target_compile_options(dumper PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()

target_compile_features(StudioPacketDumper PRIVATE cxx_std_17)
target_compile_features(dumper PRIVATE cxx_std_17)
25 changes: 15 additions & 10 deletions dumper/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

#include <cstdint>
#include <cstdio>
#include <fileapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winsock.h>

constexpr size_t PIPE_BUFFER_SIZE = 512 * 1024; // 512 KB

CRITICAL_SECTION g_receiveLock;
StudioDumper::VFTable g_vftable;
HANDLE g_pipe;
HANDLE g_pipe = INVALID_HANDLE_VALUE;

HANDLE CreatePipe() {
return CreateNamedPipe(TEXT("\\\\.\\pipe\\StudioDumper"), PIPE_ACCESS_DUPLEX,
void MakePipe()
{
g_pipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\StudioDumper"), PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT, 1, PIPE_BUFFER_SIZE,
PIPE_BUFFER_SIZE, 500, NULL);
}
Expand All @@ -30,11 +29,17 @@ void hook_24(RakNet::RakPeer* rakPeer, char _1)
{
auto packet = rakPeer->queue_2.array[i];

if (g_pipe == INVALID_HANDLE_VALUE)
break;

DWORD num;
WriteFile(g_pipe, packet->data, packet->size, &num, NULL);
auto result = WriteFile(g_pipe, packet->data, packet->size, &num, NULL);

if (result)
continue;

if (GetLastError() == ERROR_NO_DATA)
{
CloseHandle(g_pipe);
MakePipe();
}
}

LeaveCriticalSection(&g_receiveLock);
Expand Down Expand Up @@ -64,7 +69,7 @@ void Attach()
g_vftable = vftable_optional.value();
printf("Found RakPeer VFTable at 0x%llx with length %llu!\n", g_vftable.get_address(), g_vftable.get_size());

g_pipe = CreatePipe();
MakePipe();

if (g_pipe == INVALID_HANDLE_VALUE)
{
Expand Down

0 comments on commit 7962d05

Please sign in to comment.