-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIpc.h
More file actions
69 lines (59 loc) · 2.45 KB
/
Copy pathIpc.h
File metadata and controls
69 lines (59 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
/// @file
/// @brief Named-event IPC primitive shared by the launcher and the injected DLL.
#include <Windows.h>
// Lightweight inter-process signaling between the launcher and the injected DLL, built on
// named Win32 events. This is distinct from the in-game event bus in
// Internal/scripting/Events.h — that one dispatches inside the game; this one crosses the
// launcher/DLL process boundary. Both processes run in the same user session, so the
// "Local\" event namespace is used.
//
// Usage:
// Launcher: HANDLE e = Ipc::Create(Ipc::Event::Initialized); // then Ipc::Wait(e, ms)
// DLL: Ipc::Signal(Ipc::Event::Initialized); // once init succeeds
/// Cross-process signaling helpers over named Win32 events (Local\ session namespace).
namespace Ipc
{
/// Export name of the DLL's WH_GETMESSAGE hook procedure (dllmain.cpp), resolved by the
/// launcher via GetProcAddress. The proc is `extern "C"`, so this plain, undecorated name is
/// stable across signature/scope changes instead of an MSVC-mangled string — see
/// docs/hooking.md.
inline constexpr char CallbackExport[] = "SplitgateCallBack";
/// Distinct signals that can cross the launcher/DLL boundary; each maps to one named event.
enum class Event
{
Initialized, // the DLL finished Hook::Init(); the launcher may stop waiting
};
/// Maps an Event to its stable "Local\" event name (a fallback name for unknown values).
inline const wchar_t* Name(Event event)
{
switch (event)
{
case Event::Initialized:
return L"Local\\SplitgateInitialized";
}
return L"Local\\SplitgateUnknown";
}
/// DLL side: signal that the event occurred. Returns false if nobody is listening (no
/// launcher created the event) or the signal failed.
inline bool Signal(Event event)
{
HANDLE handle = OpenEventW(EVENT_MODIFY_STATE, FALSE, Name(event));
if (!handle) return false;
const bool ok = SetEvent(handle);
CloseHandle(handle);
return ok;
}
/// Launcher side: create the manual-reset event to wait on. Returns a raw HANDLE the
/// caller owns — wrap it in Launcher::UniqueHandle. Created before the DLL is triggered so
/// the DLL can open it.
inline HANDLE Create(Event event)
{
return CreateEventW(nullptr, TRUE, FALSE, Name(event));
}
/// Launcher side: wait up to timeoutMs for the event to be signaled.
inline bool Wait(HANDLE handle, DWORD timeoutMs)
{
return WaitForSingleObject(handle, timeoutMs) == WAIT_OBJECT_0;
}
}; // namespace Ipc