Files
WoW-Hybrid-gateway/native/source_creation_options.h

26 lines
1.2 KiB
C

#pragma once
#include <stdint.h>
#include <stddef.h>
/* Source creation challenges: bit zero is realm Hardcore.
* UI request state never travels in a native create flag. */
struct gw_source_creation_options { uint32_t challenge_mask; };
static inline int gw_source_creation_options_valid(struct gw_source_creation_options o) {
return (o.challenge_mask & ~UINT32_C(0x1ffe)) == 0 &&
(o.challenge_mask & UINT32_C(0x820)) != UINT32_C(0x820);
}
static inline int gw_source_creation_apply(unsigned char *body, size_t size,
struct gw_source_creation_options o) {
size_t name = 0, i;
if (!body || !gw_source_creation_options_valid(o)) return 0;
while (name < size && body[name]) ++name;
/* Name NUL, race/class/sex, five appearance bytes, outfit, uint32 mask. */
if (!name || name > 63 || size != name + 14) return 0;
if (o.challenge_mask & UINT32_C(0x400)) {
unsigned char klass = body[name + 2];
if (klass < 1 || klass > 4) return 0;
}
for (i = size - 4; i < size; ++i) if (body[i]) return 0;
for (i = 0; i < 4; ++i) body[size - 4 + i] = (unsigned char)(o.challenge_mask >> (8*i));
return 1;
}