Read raw bytes in memory from a pointer? (Wonkey)

Started by RotorSpinz, October 11, 2023, 13:13:32

Previous topic - Next topic

RotorSpinz

Is it possible to have a pointer to a type(class,struct,enum?) and read the bytes straight from memory from the whole type in sequence of the fields?
I need to pass a type like a Short and dont want to construct a short myself from the fields ;)

EDIT:
Struct test
   Field a:Ubyte = $ff
   Field b:Ubyte = $ff
   Field c:Ubyte = $00
   Field d:Ubyte = $ff
End

local myInt:test = New test

Local result:UInt ptr = Cast<UInt Ptr>(Varptr myInt)
Print(Hex(result[0]))

This prints out FF00FFFF wich is all the fields from the struct in one int.

SToS

I'm no "Wonkey" expert, but if I understand what you are asking then...

Using you code example, you need to use a UByte pointer not a Uint for result:

Struct test
   Field a:Ubyte = $ff
   Field b:Ubyte = $ff
   Field c:Ubyte = $00
   Field d:Ubyte = $ff
End

Function main()
Local myInt:test = New test

Local result:UByte ptr = Cast<UByte Ptr>(Varptr myInt)

Print Hex(result[0])
Print Hex(result[1])
Print Hex(result[2])
Print Hex(result[3])
End