Skip to content
StackZ edited this page Jun 17, 2021 · 1 revision

Script function: Read

UniversalEdit.Read(Offset, Count, DataType, Endian);

This function expects at least 2 parameters, but can have 2 optional ones.

  • Offset: The offset from where to start to read from the current file.
  • Count: The amount of elements to read from the specified datatype below.
  • DataType (Optional): The datatype to read from. See below for valid types. It defaults to "uint8_t".
  • Endian (Optional): The Endian to read from. false for Little Endian, true for Big Endian. It defaults to Little Endian.

NOTE: This function will return a table of the bytes, if you want to read a single variable from it, do so by using [0] after the function call.

Available Types

The following types are available:

  • uint8_t, u8: 1 byte.
  • uint16_t, u16: 2 byte.
  • uint32_t, u32: 4 byte.

The type needs to be specified as a string, like "uint8_t".

Example

-- The line below will read a single byte at offset 0x50 of the current file in Little Endian.
local SingleByte = UniversalEdit.Read(0x50, 1)[0];

-- The line below will read 2 4 byte variables starting at offset 0x70 in Big Endian.
local FourByteTimes2 = UniversalEdit.Read(0x70, 2, "uint32_t", true);

-- If we want to access the second variable from the four byte times 2 read table, we can do it by doing:
local Second = FourByteTimes2[1]; -- It's like in C++, array starting by 0.

Clone this wiki locally