~ruther/NosSmooth

ref: 8dcf58cbe2cee392418cb457c78eddff0bf612b5 NosSmooth/Local/NosSmooth.LocalCore/Network.cpp -rw-r--r-- 1.4 KiB
8dcf58cb — František Boháček chore: add DI dependency to Tests 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
#include "Network.h"
#include "NostaleString.h"

using namespace NosSmoothCore;
using namespace System::Runtime::InteropServices;
using namespace System;

Network::Network(ModuleHook moduleHook)
{
    _networkUnmanaged = NetworkUnmanaged::GetInstance();
    _networkUnmanaged->Setup(moduleHook);
}

void Network::ResetHooks()
{
    NetworkUnmanaged::GetInstance()->ResetHooks();
}

void Network::SendPacket(System::String^ packet)
{
    char* str = (char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(packet)).ToPointer();
	NetworkUnmanaged::GetInstance()->SendPacket(NostaleStringA(str).get());
}

void Network::ReceivePacket(System::String^ packet)
{
    char* str = (char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(packet)).ToPointer();
    NetworkUnmanaged::GetInstance()->ReceivePacket(NostaleStringA(str).get());
}

void Network::SetReceiveCallback(NetworkCallback^ callback)
{
    IntPtr functionPointer = Marshal::GetFunctionPointerForDelegate(callback);
    _receiveCallback = callback;
    NetworkUnmanaged::GetInstance()->SetReceiveCallback(static_cast<PacketCallback>(functionPointer.ToPointer()));
}

void Network::SetSendCallback(NetworkCallback^ callback)
{
    IntPtr functionPointer = Marshal::GetFunctionPointerForDelegate(callback);
    _sendCallback = callback;
    NetworkUnmanaged::GetInstance()->SetSendCallback(static_cast<PacketCallback>(functionPointer.ToPointer()));
}
Do not follow this link