level_from_code

Function level_from_code 

Source
pub fn level_from_code(code: u64) -> Option<(u8, u8)>
Expand description

Decode level from token (level code)

BL4 max level is 50. Encoding varies by context:

  • For tokens 1-50: level = token directly
  • For tokens >= 128: level = 2 * (code - 120), capped at 50
    • Code 128 → 16, Code 135 → 30, Code 145 → 50
    • Codes > 145 are capped at 50 (e.g., 196 → 50)
  • Tokens 51-127: invalid (return None)

Note: This applies to VarBit-first equipment (level = 2nd VarBit) and VarInt-first weapons (level = 4th VarInt). The encoding may differ slightly between item types - needs more in-game verification. Decode a level from a raw code value. Returns (decoded_level, raw_decoded_value) tuple. If raw_decoded_value > 50, our decoding may be wrong.