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
#pragma once
#include "ModuleHook.h"
namespace NosSmoothCore
{
public delegate bool NetworkCallback(System::String^ packet);
typedef bool(__stdcall* PacketCallback)(const char* packet);
class NetworkUnmanaged
{
public:
void Setup(NosSmoothCore::ModuleHook moduleHook);
/// <summary>
/// Send the given packet to the server.
/// </summary>
/// <param name="packet">The packed to send.</param>
void SendPacket(const char * packet);
/// <summary>
/// Receive the given packet on the client.
/// </summary>
/// <param name="packet">The packet to receive.</param>
void ReceivePacket(const char * packet);
/// <summary>
/// Sets the receive callback delegate to be called when packet is received.
/// </summary>
/// <param name="callback"></param>
void SetReceiveCallback(PacketCallback callback);
/// <summary>
/// Sets the send callback delegate to be called when the packet is sent.
/// </summary>
/// <param name="callback"></param>
void SetSendCallback(PacketCallback callback);
/// <summary>
/// Resets all the function hooks.
/// </summary>
void ResetHooks();
bool ExecuteSendCallback(const char *packet);
bool ExecuteReceiveCallback(const char *packet);
static NetworkUnmanaged* GetInstance()
{
static NetworkUnmanaged instance;
return reinterpret_cast<NetworkUnmanaged*>(&instance);
}
private:
unsigned int _callerObject;
unsigned int _receivePacketAddress;
unsigned int _sendPacketAddress;
PacketCallback _sendCallback;
PacketCallback _receiveCallback;
};
}