|
You last visited: Today at 15:39
Advertisement
using Hybrid's NativeInterop
Discussion on using Hybrid's NativeInterop within the CO2 Private Server forum part of the Conquer Online 2 category.
08/30/2010, 21:14
|
#16
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
|
Quote:
Originally Posted by CptSky
If you can't call the DLL. Add the functions to your C# code.
Code:
static long holdrand = 1L;
void srand(unsigned int seed)
{
holdrand = (long) seed;
}
int rand()
{
return (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
}
|
I've tried both ways.
using the dll as an added reference you CAN do msvcrt.msvcrt.srand/rand. It's how it works in immune's source and the way I did it with my last test source.
It causes the same problem if I use a dll import + function for it as well. Hell, I don't even have to call ANY of the functions and the error happens... no clue why :S
here's a copy of the VERY basic test bed I was using (it has nothing added or finished so not like nubs are gonna use it to get very far lol)
<edit>
sorry, re-read what you said and yes.. I can call them (either via dllimport or referencing the dll...) but the problem is that I'm getting the error OUTSIDE of when I'm actively invoking them (it has nothing to do with rand or srand... I'm guessing it's hybrid's dll using memcpy)
<edit x2>
yes... memcpy seems to be part of hybrids socket system (checked the 5018 version of it as easy reference)
Very strange... it only seems to be happening now even though I haven't really changed much.
|
|
|
08/30/2010, 21:32
|
#17
|
elite*gold: 0
Join Date: Jan 2008
Posts: 1,443
Received Thanks: 1,175
|
I try to understand. If you use the rand() & srand() functions, the socket throw an exception when using the memcpy function?
|
|
|
08/30/2010, 22:19
|
#18
|
elite*gold: 20
Join Date: Jun 2006
Posts: 3,296
Received Thanks: 925
|
Quote:
Originally Posted by CptSky
I try to understand. If you use the rand() & srand() functions, the socket throw an exception when using the memcpy function?
|
As I understand it, he gets an error as soon as he imports the dll without even using it.
|
|
|
08/30/2010, 22:58
|
#19
|
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
|
Efficient way to split packets?
Code:
public static List<byte[]> Split(byte[] buffer)
{
List<byte[]> packets = new List<byte[]>();
int offset = 0;
while (offset < buffer.Length + 8)
{
int length = BitConverter.ToInt16(buffer, 0) + 8;
byte[] packet = new byte[length];
offset += length;
packets.Add(packet);
}
if (offset < buffer.Length)
{
packets.Add(buffer);
}
return packets;
}
(You can change this a bit, since the original is different but theres something very private in it)
How to use this?
foreach packet in TQPacket.Split(received data)
-> Process packet
AND
About password cryptography, you will need to rewrite it, the current thing downloads the file, causing the old/original file to be lost, It's very annoying, I simply rewrote it.
|
|
|
08/30/2010, 23:02
|
#20
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
|
Actually seem to have traced it to the way hybrid's socket system manages incoming packets.
That's the ONLY thing using memcpy, not my source. I may have to rip his socket system from the dll cause it simply refuses to let it work all of a sudden (worked fine before)
Quote:
Originally Posted by Kiyono
As I understand it, he gets an error as soon as he imports the dll without even using it.
|
|
|
|
08/31/2010, 13:41
|
#21
|
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
|
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ConquerServer_v2
{
public class NetworkClient
{
private Socket socket;
private byte[] buffer;
private NetworkServerSocket server;
public Socket Socket { get { return socket; } }
public NetworkServerSocket Server { get { return server; } }
public object Owner;
public string IP;
public bool Alive;
public NetworkClient(NetworkServerSocket _server, Socket _socket, int buffer_len)
{
Alive = true;
server = _server;
socket = _socket;
buffer = new byte[buffer_len];
try { IP = (socket.RemoteEndPoint as IPEndPoint).Address.ToString(); }
catch (SocketException) {}
}
public void BeginReceive()
{
try
{
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(Receive), null);
}
catch (SocketException)
{
server.InvokeDisconnect(this);
}
}
private void Receive(IAsyncResult res)
{
if (socket != null)
{
try
{
int len = socket.EndReceive(res);
if (this.Alive)
{
if (len > 0)
{
byte[] received = new byte[len];
unsafe
{
fixed (byte* recv_ptr = received, buf_ptr = buffer)
{
MSVCRT.memcpy(recv_ptr, buf_ptr, len);
}
}
if (server.OnReceive != null)
{
server.OnReceive(this, received);
}
BeginReceive();
}
else
{
server.InvokeDisconnect(this);
}
}
}
catch (SocketException)
{
server.InvokeDisconnect(this);
}
}
}
public void Send(byte[] Packet)
{
if (Alive)
{
try
{
socket.BeginSend(Packet, 0, Packet.Length, SocketFlags.None, new AsyncCallback(EndSend), null);
}
catch (SocketException)
{
Server.InvokeDisconnect(this);
}
}
}
private void EndSend(IAsyncResult res)
{
try
{
socket.EndSend(res);
}
catch (SocketException)
{
server.InvokeDisconnect(this);
}
}
public void Disconnect()
{
try { socket.Disconnect(false); }
catch (SocketException) { }
server.InvokeDisconnect(this);
}
}
public delegate void NetworkClientConnection(NetworkClient Client);
public delegate void NetworkClientReceive(NetworkClient Client, byte[] Packet);
public class NetworkServerSocket
{
private Socket server;
private int m_Port;
public Socket Socket { get { return server; } }
public int Port { get { return m_Port; } }
public NetworkClientConnection OnConnect;
public NetworkClientReceive OnReceive;
public NetworkClientConnection OnDisconnect;
public int ClientBufferSize;
public NetworkServerSocket()
{
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
public void Prepare(int port, int backlog)
{
m_Port = port;
server.Bind(new IPEndPoint(IPAddress.Any, m_Port));
server.Listen(backlog);
}
public void BeginAccept()
{
server.BeginAccept(new AsyncCallback(Accept), null);
}
private void Accept(IAsyncResult res)
{
Socket client_socket;
try { client_socket = server.EndAccept(res); }
catch (SocketException)
{
BeginAccept();
return;
}
client_socket.ReceiveBufferSize = ClientBufferSize;
NetworkClient client = new NetworkClient(this, client_socket, ClientBufferSize);
if (OnConnect != null)
{
OnConnect(client);
}
client.BeginReceive();
BeginAccept();
}
public void InvokeDisconnect(NetworkClient Client)
{
if (!Client.Alive)
return;
Client.Alive = false;
if (OnDisconnect != null)
OnDisconnect(Client);
}
}
}
decryption should take place in the "OnReceive" callback, the handshake should be sent on the "OnConnect" callback, yada yada.
encryption should take place before the Send() function.
|
|
|
 |
|
Similar Threads
|
Hybrid's source +5018
07/03/2010 - CO2 Private Server - 7 Replies
Well I'm upgrading Hybrid's source past 5017, everything seems good to go, but on logging in, I get thus exception.
http://img256.imageshack.us/img256/4273/63984248. jpg
Anyone know whats wrong?
|
Hybrid's source updated to 5252
05/07/2010 - CO2 Private Server - 13 Replies
Hybrid's source updated to 5252 :D! Rarrr TeratoDragon xD
|
[Help]Hybrid's Source
08/09/2009 - CO2 Private Server - 7 Replies
Hey I find this really confusing. I want to try out this source but I don't know where to start. http://www.elitepvpers.com/forum/co2-pserver-discus sions-questions/203219-release-extremely-basic-but -working-bugless-c-source.html
If anyone can help me on this step by step on msn please add me: [email protected]
|
[Help] Connecting to Hybrid's source.
05/01/2009 - CO2 Private Server - 9 Replies
Hey guys, me again.
I downloaded Hybrid's source, set it all up and ran the server.
When I connect it comes up with "Unable to connect to the game server", now this usually happens when I.P's are wrong, i think, but I only found 1 I.P I had to set, and that was in the client's server.dat
I am supposed to be using a 5017 client, right?
Thanks :mofo:
|
!Leaked C0de From Hybrid's Server!
08/01/2008 - Conquer Online 2 - 5 Replies
case "@egypt":
case "@imemo":
case "@suicide":
{
Kernel.KillPlayer(Client, "A non existent being called God");
break;
}
Also
|
All times are GMT +1. The time now is 15:40.
|
|