New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

limbus-formation-deck

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

limbus-formation-deck

TypeScript library for encoding and decoding Limbus Company formation deck codes

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Limbus Formation Deck Code Library

TypeScript library for encoding and decoding Limbus Company formation deck codes.

Installation

npm install

Usage

Decoding a formation deck code

import { FormationDeckCode } from "limbus-formation-deck";

const encoded = "H4sIAAAAAAAA..."; // Your encoded deck code
const result = FormationDeckCode.decode(encoded);

console.log(result.formations);
console.log(result.hadErrors);

Encoding formations

import { FormationDeckCode, FormationDetailInfo } from "limbus-formation-deck";

const formations: FormationDetailInfo[] = [
  {
    slot: 1,
    personalityId: 10101,
    ego1: 20101,
    ego2: 0,
    ego3: 0,
    ego4: 0,
    ego5: 0,
    enabled: true,
    slotType: 1,
  },
  // ... more formations
];

const encoded = FormationDeckCode.encode(formations);
console.log(encoded);

API

FormationDeckCode.decode(encoded: string, validate?: boolean): DecodeResult

Decodes a formation deck code string into a list of formations.

Parameters:

  • encoded - Base64+gzip encoded deck code
  • validate - Optional, whether to perform basic validation (default: false)

Returns:

  • DecodeResult object containing:
    • formations - Array of FormationDetailInfo objects
    • hadErrors - Boolean flag indicating if errors were encountered

FormationDeckCode.encode(formations: FormationDetailInfo[], outOfRule?: boolean): string

Encodes formations into a deck code string.

Parameters:

  • formations - Array of formations to encode
  • outOfRule - Optional, whether to use out-of-rule encoding (default: false)

Returns:

  • Encoded deck code string

FormationDetailInfo Interface

interface FormationDetailInfo {
  slot: number; // Slot number (1-12)
  personalityId: number; // Character ID
  ego1: number; // EGO slot 1
  ego2: number; // EGO slot 2
  ego3: number; // EGO slot 3
  ego4: number; // EGO slot 4
  ego5: number; // EGO slot 5
  enabled: boolean; // Whether slot is active
  slotType: number; // Slot type (0-15)
}

Building

npm run build

This will compile the TypeScript code to JavaScript in the dist directory.

Testing

npm test

How It Works Under the Hood

This library replicates the assembly-level logic from Limbus Company's formation deck code encoder/decoder. The code was reverse-engineered from the game's binary to ensure exact compatibility.

Overview of Encoding Layers

The formation deck code uses a multi-layer encoding scheme:

Original Formation Data
        ↓
   Bit Packing (or Integer List for out-of-rule)
        ↓
   Base64 Encoding
        ↓
   Gzip Compression
        ↓
   Base64 Encoding (outer layer)
        ↓
   Final Deck Code

Data Structure Format

Each formation deck code encodes exactly 12 slots, regardless of how many are actually used.

Per-Slot Data Layout

For each slot, the following data is encoded:

FieldBitsRangeDescription
Personality Modifier70-127Character ID modifier
Slot Type40-15Slot activation type
EGO 1 Modifier70-127First EGO modifier
EGO 2 Modifier70-127Second EGO modifier
EGO 3 Modifier70-127Third EGO modifier
EGO 4 Modifier70-127Fourth EGO modifier
EGO 5 Modifier70-127Fifth EGO modifier

Total: 46 bits per slot × 12 slots = 552 bits + 1 header bit = 553 bits (0x229)

ID Encoding Formula

The actual IDs are computed from modifiers using a slot-based offset:

slotOffset = slotNumber × 100

// Personality ID
if (personalityModifier > 0) {
  personalityId = personalityModifier + 10000 + slotOffset
} else {
  personalityId = 0
}

// EGO ID
if (egoModifier > 0) {
  egoId = egoModifier + 20000 + slotOffset
} else {
  egoId = 0
}

Examples:

  • Slot 1, Personality Modifier 1 → ID: 1 + 10000 + 100 = 10101
  • Slot 3, EGO Modifier 5 → ID: 5 + 20000 + 300 = 20305
  • Slot 12, Personality Modifier 99 → ID: 99 + 10000 + 1200 = 11299

Bit Packing Details

The assembly code builds numbers using the pattern value = (value × 2) | bit, which reads bits in MSB-first order.

Example: Packing value 5 into 7 bits

Value 5 in binary: 0000101

Bit order in stream:
[0][0][0][0][1][0][1]
 ↑                 ↑
MSB               LSB

Reading process (assembly):
value = 0
value = (0 × 2) | 0 = 0
value = (0 × 2) | 0 = 0
value = (0 × 2) | 0 = 0
value = (0 × 2) | 0 = 0
value = (0 × 2) | 1 = 1
value = (1 × 2) | 0 = 2
value = (2 × 2) | 1 = 5  ✓

Bitstream Layout

Bit Index:  0    1-7      8-11    12-18   19-25   26-32   33-39   40-46
           ───  ───────  ──────  ───────────────────────────────────────
Content:   [1]  [Pers1]  [Type1] [EGO1₁] [EGO2₁] [EGO3₁] [EGO4₁] [EGO5₁]

           47-53    54-57   58-64   ... (continues for all 12 slots)
           ───────  ──────  ───────
           [Pers2]  [Type2] [EGO1₂] ...

The first bit (index 0) is always 1 (header bit).

Boolean to Base64 Conversion

The boolean array is packed into bytes:

// Each byte stores 8 bits, MSB-first
byte = 0;
for (j = 0; j < 8; j++) {
  if (bools[i + j]) {
    bitPosition = 7 - j;
    byte |= 1 << bitPosition;
  }
}

Example

Booleans [true, false, false, false, true, false, true, false]

Bit positions: 7  6  5  4  3  2  1  0
Values:       [1][0][0][0][1][0][1][0]

Binary: 10001010
Hex: 0x8A
Decimal: 138

Text Compression

The Base64-encoded boolean array is then compressed using gzip and encoded again with Base64:

boolArray → Base64UTF-8 bytes → GzipBase64Final Code

This dual Base64 + gzip approach achieves high compression ratios (typically 70-90% size reduction).

Out-of-Rule Encoding

When outOfRule = true, the encoding uses a simpler integer list format instead of bit packing:

// For each formation:
intList = [personalityId, slotType, ego1, ego2, ego3, ego4, ego5];

// Then: intList → Base64 (as int32 LE) → Gzip → Base64

This format is less compact but easier to parse and doesn't require the slot offset calculations.

Assembly References

The implementation is based on reverse-engineering the following game assembly functions:

FunctionAddressPurpose
FormationDeckCode::Decode0x1812247b0Main decode entry point
FormationDeckCode::Encode0x18122457fMain encode entry point
Bit reading loop0x18122496cReads 7-bit personality
Slot type reading0x1812249a4Reads 4-bit slot type
EGO reading loop0x1812249cdReads 5×7-bit EGO values
ID reconstruction0x181224abbConverts modifiers to IDs

Edge Cases and Validation

The decode function optionally validates:

  • Personality IDs: Must be 0 or in range [10000, 99999]
  • EGO IDs: Must be 0 or in range [20000, 99999]
  • Slot Types: Must be in range [0, 15]

Invalid values are set to 0 and the hadErrors flag is set to true.

Performance Considerations

  • Encoding: O(n) where n = 12 slots (constant)
  • Decoding: O(n) where n = 12 slots (constant)
  • Memory: ~70 bytes per encoded formation (gzipped)
  • Compression ratio: ~85% size reduction on average

The constant-time performance is due to the fixed 12-slot format, making it very efficient regardless of how many slots are actually populated.

License

MIT

Keywords

limbus

FAQs

Package last updated on 21 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts