npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xcom2charpool

v1.0.0

Published

Library for reading, manipulating, and managing XCOM 2 character pool binary files, supporting both browser and Node.js environments.

Downloads

207

Readme

xcom2charpool

Overview

xcom2charpool is a TypeScript library designed for reading and manipulating the charpool binary files used in the XCOM 2 game. It provides a robust set of tools for parsing, serializing, and managing the complex data structures within these binary files, enabling developers and modders to create, modify, and analyze charpool data efficiently. The library is not tied to a specific fs implementation; however, it includes an ArrayBuffer-based implementation that works seamlessly in both browser and Node.js environments.

Installation

npm i xcom2charpool

Usage

import { Unpacker, Packer, ArrayBufferReader, ArrayBufferWriter } from 'xcom2charpool';
import * as fs from 'node:fs/promises';
import * as path from 'node:path';
import * as os from 'node:os';

async function main() {
    const charpoolPath = path.join(os.homedir(), 'Documents/My Games/XCOM2 War of the Chosen/XComGame/CharacterPool');

    // Read data from the current character pool
    const { state, data } = await readCharpool(path.join(charpoolPath, 'DefaultCharacterPool.bin'));

    console.log('Soldiers:');
    for (const soldier of data.items) {
        console.log(`- ${soldier.value.strFirstName} ${soldier.value.strNickName} ${soldier.value.strLastName}`);
    }

    // Change name for characters
    for (const char of data.items) {
        char.value.strFirstName = 'XCom';
        char.value.strLastName = 'Studio';
    }

    // Save data to new character pool
    await writeCharpool(path.join(charpoolPath, 'Importable', 'XCom-Studio.bin'), state, data);
}

// Function to read and parse a charpool binary file
async function readCharpool(filePath: string) {
    // Read the binary file
    const buffer = await fs.readFile(filePath);

    // Create a DataView from the buffer
    const dataView = new DataView(buffer.buffer);

    // Initialize the reader and unpacker
    const reader = new ArrayBufferReader(dataView);
    const unpacker = new Unpacker(reader);

    // Parse the file
    return unpacker.readFile();
}

// Function to create and write a charpool binary file
async function writeCharpool(filePath: string, state: Record<string, any>, data: any) {
    // Initialize the writer and packer
    const writer = new ArrayBufferWriter();
    const packer = new Packer(writer);

    // Serialize the data into binary format
    packer.writeFile({ state, data });

    // Retrieve the binary buffer
    const buffer = writer.getBuffer();
    console.log(buffer.byteLength);

    // Write the buffer to a file
    await fs.writeFile(filePath, Buffer.from(buffer));
}

main();

API Reference

  • Serialization Utilities:

    • Packer: Handles the serialization of data structures into binary format.
    • Unpacker: Handles the deserialization of binary data into structured formats.
  • Reader & Writer:

    • ArrayBufferReader: Implements the Reader interface for reading binary data.
    • ArrayBufferWriter: Implements the Writer interface with dynamic buffer resizing and encoding support.
  • Property Classes:

    • IntProperty, StrProperty, BoolProperty, ByteProperty, NameProperty, NoneProperty, StructProperty: Define various property types for handling different data formats.
    • PropertyFactory: Interface for property creation and serialization.
  • Array Handling:

    • ArrayOfStructs, CharacterPoolDataElements, ArrayOfInt: Manage arrays of structured data and integers.
    • ArrayFactory: Interface for creating array instances.

Testing

The library includes a number of unit tests to ensure the correctness of reading and writing operations.

pnpm test