Struct HkxHeader

Source
#[repr(C)]
pub struct HkxHeader {
Show 18 fields pub magic0: i32, pub magic1: i32, pub user_tag: i32, pub file_version: i32, pub pointer_size: u8, pub endian: u8, pub padding_option: u8, pub base_class: u8, pub section_count: i32, pub contents_section_index: i32, pub contents_section_offset: i32, pub contents_class_name_section_index: i32, pub contents_class_name_section_offset: i32, pub contents_version_string: [u8; 15], pub contents_version_string_separator: u8, pub flags: i32, pub max_predicate: i16, pub section_offset: i16,
}
Expand description

The 64bytes HKX header contains metadata information about the HKX file.

Fields§

§magic0: i32

First magic number (0x57E0E057)

§magic1: i32

Second magic number (0x10C0C010)

§user_tag: i32

User-defined tag.

§file_version: i32

Version of the file.

§pointer_size: u8

Size of pointers in bytes (4 or 8)

§endian: u8

Endianness of the file (0 for big-endian, 1 for little-endian).

§padding_option: u8

Padding option used in the file.

§base_class: u8

Base class.

§section_count: i32

Number of sections in the HKX file.

§Examples

For SkyrimSE, the bytes are arranged in the following order.

  • __classnames__
  • __types__
  • __data__
§contents_section_index: i32

Index of the contents section.

§contents_section_offset: i32

Offset of the contents section.

§contents_class_name_section_index: i32

Index of the contents class name section.

§contents_class_name_section_offset: i32

Offset of the contents class name section.

§contents_version_string: [u8; 15]

Version string of the contents.

§Bytes Example

  • SkyrimSE
assert_eq!(
  *b"hk_2010.2.0-r1\0",
  [0x68, 0x6B, 0x5F, 0x32, 0x30, 0x31, 0x30, 0x2E, 0x32, 0x2E, 0x30, 0x2D, 0x72, 0x31, 0x00]
);
§contents_version_string_separator: u8

Version string of the contents separator. Always 0xff

§flags: i32

Various flags.

§max_predicate: i16

Maximum predicate. None is -1 (== 0xFF 0xFF)

§section_offset: i16

Section offset. None is -1 (== 0xFF 0xFF)

If this number is 16, read 64bytes header plus an extra 16bytes as padding.

Implementations§

Source§

impl HkxHeader

Source

pub const fn endian(&self) -> Endianness

Return Big-endian or little-endian

§Note

Endian must be 0(big) or 1(little).

  • If you used the from_bytes constructor, it is not a problem because the endian check is already done.
Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>

Create a header by parsing 64bytes from bytes.

§Errors

If invalid header format

Source

pub fn parser<'a>() -> impl Parser<&'a [u8], Self, ContextError>

Check valid endian & Parse as hkx root header.

Source

pub fn to_bytes(&self) -> [u8; 64]

Convert to bytes.

§Note

If self.endian is 0, the data is converted to binary data as little endian, otherwise as big endian.

Source

pub const fn padding_size(&self) -> u32

Get padding size.

§Note

If Self.section_offset is negative, 0 is returned.

Source

pub fn contents_version_string(&self) -> ModalResult<&str>

Get contents_version_string as str

§Errors

Returns Err if the slice is not UTF-8.

§Expected bytes examples
  • SkyrimSE
assert_eq!(
    b"hk_2010.2.0-r1\0",
    [0x68, 0x6B, 0x5F, 0x32, 0x30, 0x31, 0x30, 0x2E, 0x32, 0x2E, 0x30, 0x2D, 0x72, 0x31, 0x00].as_slice()
); // To "hk_2010.2.0-r1"
Source

pub const fn new_skyrim_se() -> Self

Create a new HkXHeader instance with default values for Skyrim Special Edition.

§Features
  • file version: 8
  • pointer size: 8 bytes(64bit)
  • endian: 1(little endian)
  • base class: 1
  • section count: 3(__classnames__, __type__, __data__)
  • content section index: 2. In zero-based index, data section means the third section.
  • content class name section offset: 0x4B
  • max predicate: -1 (Always 0xff 0xff in ver. hk2010)
  • section offset: -1 (Always 0xff 0xff in ver. hk2010)
Source

pub const fn new_skyrim_le() -> Self

Create a new HkXHeader instance with default values for Skyrim Legendary Edition.

§Features

Almost the same as SkyrimSE, only the pointer_size is different, 4 instead of 8. This means that the pointer_size is 32 bits(4 bytes), for a 32-bit application.

  • file version: 8
  • pointer size: 4 bytes(32bit)
  • endian: 1(little endian)
  • base class: 1
  • section count: 3(__classnames__, __type__, __data__)
  • content section index: 2. In zero-based index, data section means the third section.
  • content class name section offset: 0x4B
  • max predicate: -1 (Always 0xff 0xff in ver. hk2010)
  • section offset: -1 (Always 0xff 0xff in ver. hk2010)

Trait Implementations§

Source§

impl Clone for HkxHeader

Source§

fn clone(&self) -> HkxHeader

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HkxHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HkxHeader

Source§

fn default() -> HkxHeader

Returns the “default value” for a type. Read more
Source§

impl Hash for HkxHeader

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for HkxHeader

Source§

fn eq(&self, other: &HkxHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for HkxHeader

Source§

impl StructuralPartialEq for HkxHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoResult<T> for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more