Building Packets In Memory (The Easy Way)
Posted: Tue Jul 10, 2012 12:10 am
I came up with something sorta like C# class's. This makes building packets in memory simple, fast, and easy. And the include itself takes less then 5 minutes to write!
Then you could do something simple like...
And it will send 01 02. I only need them three data types, but you can add all the other in a minute. 
Code: Select all
; ----------------------------
;
; Packet Building Include
; By Warmonger
;
; ----------------------------
Global Pos = 0
; ------------------------------------------------------------
; AddInt32 - Add Integer To Memory
; ------------------------------------------------------------
Procedure AddInt32(*Memory, iData.l)
PokeL(*Memory + Pos, iData)
Pos = Pos + 4
EndProcedure
; ------------------------------------------------------------
; AddByte - Add Byte To Memory
; ------------------------------------------------------------
Procedure AddByte(*Memory, bData.b)
PokeB(*Memory + Pos, bData)
Pos = Pos + 1
EndProcedure
; ------------------------------------------------------------
; AddBytes - Add Bytes To Memory
; ------------------------------------------------------------
Procedure AddBytes(*oldMemory, *newMemory, DataSize)
MoveMemory(*oldMemory, *newMemory + Pos, DataSize)
Pos = Pos + DataSize
EndProcedure
; ------------------------------------------------------------
; AddString - Add String To Memory
; ------------------------------------------------------------
Procedure AddString(*Memory, sData.s)
PokeS(*Memory + Pos, sData, Len(sData))
Pos = Pos + Len(sData)
EndProcedure
; ------------------------------------------------------------
; FreePos - Reset Pos Pointer
; ------------------------------------------------------------
Procedure FreePos()
Pos = 0
EndProcedure
Code: Select all
Procedure SendPacket(ClientID)
Protected *Packet = AllocateMemory(100)
AddByte(*Packet, $01)
AddByte(*Packet, $02)
SendNetworkData(ClientID, *Packet, Pos)
FreeMemory(*Packet)
FreePos()
EndProcedure
