Did you try using intptr and addressof as I previously stated?
Did you try using intptr and addressof as I previously stated?
Yeah.. but could that be the problem?
I am sry but I do not really understand that part. :SOriginally Posted by DarkstaR
Well, in C++ arrays are simply pointers. This means a BYTE* (BYTE[]) is actually an address to a buffer in memory when referenced with no indexer. All the indexer does is increase that address by SizeOf(Type) * Index and read from that address. So, since the DLL is loaded into memory when called, it has access to the memory of Klusberts program. This means that by passing the address of his buffer using AddressOf, he is simulating passing it as a native BYTE*.Originally Posted by Dark Pallys
@Klusbert: Do both of the following things
Public Declare Sub SendPacketToServer Lib "Tibiasock.dll" (ByVal handle As Integer, ByRef bytes As IntPtr, ByVal lenght As Integer)
SendPacketToServer(Tibia, AddressOf(packet.Data(0)), packet.Length)
SendPacketToServer(Tibia, AddressOf(packet.Data), packet.Length)
One of them should work.
sry they dont, Im trying more tomorow I dead :P
Oh, I may have forgot to mention that you do not begin your packet with the 2-BYTE length. Everything is done for you. You provide a literally RAW packet.
EDIT:
I am also unable to get this working with VB. Tomorrow I will try to update the library and see if I can get it working. I believe it has something to do with the differences in the way memory is managed using the .NET CLR as apposed to native code.
I doubt this is the problem.. but it may have something to do with Safe Arrays, I know they are used in vb6, not sure about vb.net though
[code=vb]Public Declare Sub SendPacketToServer Lib "Tibiasock.dll" (ByVal handle As IntPtr, ByRef bytes As Byte, ByVal lenght As Integer)[/code]
or
[code=vb]Public Declare Sub SendPacketToServer Lib "Tibiasock.dll" (ByVal handle As IntPtr, ByRef bytes As Byte(), ByVal lenght As Integer)[/code]
or
[code=vb]Public Declare Sub SendPacketToServer Lib "Tibiasock.dll" (ByVal handle As IntPtr, ByRef bytes() As Byte, ByVal lenght As Integer)[/code]
I can't remember where the bracket goes lol
[code=vb]
dim phandle as IntPtr= openprocess(.....)
dim bpacket(2) as byte
dim plength as integer
bpacket(0) = &H1
bpacket(1) = &H96
bpacket(2) = &H1
plength = bpacket.length - 1
SendPacketToServer(phandle, bpacket(0), pLength)
'or
SendPacketToServer(phandle, bpacket, pLength)
[/code]
AddressOf is only used for functions.. unlike in vb6.. the other option would be to use Marshall GHAlloc.. etc
I'm not sure if this code will work.. it *should* work.. but yeah..
I was using a similar code and it kept freezing tibia.. so who knows wtf is going on :/
it's 6am here, and I'm a weeeee bit tired :P can't be bothered thinking about this anymore
Yeah like I said any misuse can go quite bad. I may add valid read checks etc.
Ah yeah, in VB.net I tried marshaling raw data and copying the buffer over and passing that intptr, still didn't work. I have a lot to get done by the end of the day so I might not get a fixed version today, but I will soon.
Cool Library Darkstar.I've done a library similar to yours in delphi, using yaboomaster method to send Packets to Server(like you) and RecvStream method(stepler).But i've get some trouble injecting procedures, i really don't remember.
Anyway,i really like this. It was a long time we are needing a library to send packets to client, even if its is implemented in c++(i really don't like it, personal opinion).