~ruther/NosSmooth

ref: c6be7bd2a809904ae8a4259b0fa2512051b4d4e1 NosSmooth/Local/NosSmooth.LocalCore/NetworkUnmanaged.h -rw-r--r-- 1.6 KiB
c6be7bd2 — František Boháček chore: remove NosCore dependency 3 years ago
                                                                                
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
#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:
		NetworkUnmanaged();
		unsigned int _callerObject;
		unsigned int _receivePacketAddress;
		unsigned int _sendPacketAddress;

		PacketCallback _sendCallback;
		PacketCallback _receiveCallback;
	};
}
Do not follow this link