Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Zer0 on September 26, 2006, 10:01 PM

Title: MakeWORD Problem
Post by: Zer0 on September 26, 2006, 10:01 PM
ok i dont see anything wroung with this but mabey im just stupid or somthn? i am using VB.Net


Public Function MakeWORD(ByRef Value As Short) As String
Dim Result As New VB6.FixedLengthString(2)
CopyMemory(Result.Value, Value, 2)
MakeWORD = Result.Value
End Function


it is telling me there is a error in

CopyMemory(Result.Value, Value, 2)
Title: Re: MakeWORD Problem
Post by: FrostWraith on September 26, 2006, 10:05 PM
Don't scream at me if this doesnt work but in VB you only user parentheses when calling or setting to a variable. Try this:
CopyMemory Result.Value, Value, 2
Title: Re: MakeWORD Problem
Post by: topaz on September 26, 2006, 10:13 PM
Quote from: Zer0 on September 26, 2006, 10:01 PM
ok i dont see anything wroung with this but mabey im just stupid or somthn? i am using VB.Net


Public Function MakeWORD(ByRef Value As Short) As String
Dim Result As New VB6.FixedLengthString(2)
CopyMemory(Result.Value, Value, 2)
MakeWORD = Result.Value
End Function


it is telling me there is a error in

CopyMemory(Result.Value, Value, 2)


1. What's the error
2. The value you're trying to convert is probably not the right size
Title: Re: MakeWORD Problem
Post by: l2k-Shadow on September 26, 2006, 10:40 PM
try placing ByVal in front of Result.Value so

CopyMemory(ByVal Result.Value, Value, 2)
Title: Re: MakeWORD Problem
Post by: MyndFyre on September 26, 2006, 10:52 PM
The problem is that you're using CopyMemory in VB.NET where there are 30 better ways for you to do it.
Title: Re: MakeWORD Problem
Post by: Zer0 on September 26, 2006, 10:55 PM
shadow when i tryed using ByVal i got...
Expression expected.

and MyndFyre u mind telling me a better one?
Title: Re: MakeWORD Problem
Post by: MyndFyre on September 27, 2006, 12:55 AM
In .NET, you should be treating your binary data as byte arrays, not as strings.  That's because they're handled efficiently in .NET, and the Framework Class Library has classes that support using byte arrays for data.  Not only that, but converting from a string back to a byte array to be sent via a Socket, NetworkStream, TcpClient, or any of the other classes will cause data loss and truncation.

To convert from a Short to a Byte(), use BitConverter.GetBytes(ByVal s As Short).  To convert two bytes at a specific byte array index, use BitConverter.ToInt16(ByVal arr() As Byte, ByVal index As Integer).  Alternatively, you may want to investigate the System.IO.MemoryStream class, which treats memory sort of like a pointer.

MBNCSUtil (http://www.jinxbot.net/mbncsutil/) has packet buffers and data readers written in C# that demonstrate how to use this functionality in the class library.  I highly suggest that you check it out.
Title: Re: MakeWORD Problem
Post by: Zer0 on September 27, 2006, 01:19 AM
wow lol from looking at what u just showd me im going to have to re-write almost the entire bot. Is there a source out there for a example of a working .Net bot so i can get a little clearer idea because i am still rather new to .Net. Thx for the help MyndFyre n everyone else who tried :)
Title: Re: MakeWORD Problem
Post by: FrOzeN on September 27, 2006, 03:10 AM
Quote from: Zer0 on September 27, 2006, 01:19 AM
Is there a source out there for a example of a working .Net bot so i can get a little clearer idea because i am still rather new to .Net. Thx for the help MyndFyre n everyone else who tried :)
Yeah, most likely. Though IMO, I think you'll find that trying to develop a bot yourself, you'll grasp a much better understand of how it works. You'll also gain more skills investigating and learning how to handle packets, debug better, etc. Having a source code as a reference takes away these things, and won't give you as much understanding of your code.