Skip to main content

bl

A C++20 library primarily for encoding and decoding Build Logic savestrings. I reverse-engineered the format myself without any external help so keep that in mind.

Python bindings are also available thanks to pybind11. Python packaging is available thanks to scikit-build-core.

Note that this library is still a WIP. In the future I plan to add more sophisticated features and also clean up the code a bit more.

See DOCS.md for information on how the savestring format works.

Getting bl

You can easily install the Python bindings using pip:

pip install python-bl

If you want to build bl from source, you can use CMake:

git clone https://github.com/I-OCode/bl
cd bl
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build # or use Debug for debug builds
cmake --build build

To use bl in your project, link against the bl::bl CMake target.

To build the Python bindings, enable the BL_BUILD_PYTHON_BINDINGS option. You can do this by adding -DBL_BUILD_PYTHON_BINDINGS=ON to the arguments of cmake. The result is a Python extension module in the build directory that you can use.

Using bl

To encode savestrings, first create a bl::emplacement object. Then you can use the place() method to place blocks. The place() method accepts a bl::block object that contains info for the block. There are bl::block_name and bl::material enums for block names and block materials respectively. Finally, there are the bl::vec3 and bl::rotation classes, where vec3 can store a 3D position within the Build Logic world or a color and rotation stores rotations of blocks.

#include <bl.hpp>

int main() {
    bl::emplacement empl;

    bl::block blk = {
        .value = "foobar", // Value of the block.
        .name = bl::block_name::eBlock, // Name of the block.
        .mat = bl::material::eDefault, // Material of the block.
        .pos = bl::vec3(127, 0, 127), // Position of the block.
        .color = bl::vec3(255, 255, 255), // Color of the block.
        .rot = bl::rotation(), // Rotation of the block.
        .activated = false // Whether the block is activated or not (this
                           // applies to things like levers).
    };

    // Place the block.
    empl.place(blk);
}

Then you can encode the emplacement.

std::string s = empl.save(); // The `save()` method returns a savestring.

The place() method also returns an ID that you can then pass into the remove() method to remove the block, or you can pass it into connect() to create wire connections.

auto id = empl.place(blk);
empl.remove(id);

// Or you can make wire connections.

auto id1 = empl.place(some_example_block1);
auto id2 = empl.place(some_example_block2);

bl::block_wire wire = {
    .from_blk = id1, // Source block.
    .to_blk = id2, // Destination block.
    .from_con = '6', // Source connector.
    .to_con = '9' // Destination connector.
};

empl.connect(wire);

connect() itself returns an ID that can be passed to the disconnect() method, which removes wires. You can use the clear() method to clear all blocks and wires. You can also directly access the blks and wires members of emplacements.

There are human-readable constants for connectors. These are stored in the bl::con namespace. For example, these are the connectors for the AND gate:

bl::con::eAND_Gate::a // First input.
bl::con::eAND_Gate::b // Second input.
bl::con::eAND_Gate::q // Output.

You can load emplacements from savestrings by using the constructor of bl::emplacement.

bl::emplacement empl{"G$Bwf"};

// `empl` should now contain a block at pos (127, 0, 127).

// This also works (but this is a pretty inefficient way to copy emplacements).
bl::emplacement empl2{empl.save()};

// Better just to copy emplacements directly.
bl::emplacement empl2b{empl};

Using the Python bindings is also straightforward:

# Direct Python equivalent of the C++ code samples.

import pybl

empl = pybl.emplacement()

blk = pybl.block(
    value="foobar", # Value of the block.
    name=pybl.block_name.eBlock, # Name of the block.
    mat=pybl.material.eDefault, # Material of the block.
    pos=pybl.vec3(127, 0, 127), # Position of the block.
    color=pybl.vec3(255, 255, 255), # Color of the block.
    rot=pybl.rotation(), # Rotation of the block.
    activated=False # Whether the block is activated or not (this applies to
                    # things like levers).
)

# Place the block.
empl.place(blk)

s = empl.save() # The `save()` method returns a savestring.

id = empl.place(blk)
empl.remove(id)

# Or you can make wire connections.

id1 = empl.place(some_example_block1)
id2 = empl.place(some_example_block2)

wire = pybl.block_wire(
    from_blk=id1, # Source block.
    to_blk=id2, # Destination block.
    from_con="6", # Source connector.
    to_con="9" # Destination connector.
)

empl.connect(wire)

pybl.con.eAND_Gate.a # First input.
pybl.con.eAND_Gate.b # Second input.
pybl.con.eAND_Gate.q # Output.

# `empl` should now contain a block at pos (127, 0, 127).
empl = pybl.emplacement("G$Bwf")

# This also works (but this is a pretty inefficient way to copy emplacements).
empl2 = pybl.emplacement(empl.save())

# Better just to copy emplacements directly.
empl2b = pybl.emplacement(empl)

Limitations

  • Beams, kill modules, and player detectors may contain control characters like \x02 when encoded. This may make copying/pasting the savestrings difficult on some systems.

Demos/Examples

Build Logic's first 100 block tall nuclear PP:

Nuclear PP

The same PP except now it's exploding:

Exploding Nuclear PP

Time to do some trolling

I reverse-engineered the keypad encoding format too. And bl is open-source. So you can crack any keypad in Build Logic for free :D

#include <print>
#include <bl.hpp>

int main() {
    // Step 1. In the game, press the "L" key or run the command "/m debug" to
    //         open the debug menu.
    // Step 2. Hover your mouse over the keypad you want to crack.
    // Step 3. Look for "Value" and type out the text to the right of it into
    //         the `val` variable in the code here.
    // Step 4. Run the program, and voila! The keypad code digits get printed
    //         out and you are now officially a criminal.
    std::string val = "<keypad value goes here>";
    std::println("{}", bl::keypad_cfg(val).code_digits);
}

If you're in a hurry, you can also do this with Python:

>>> import pybl
>>> pybl.keypad_cfg("<keypad value goes here>").code_digits

Hopefully Tomtom doesn't make a new super-duper keypad with cryptographically-secure encryption to stop people like me. Tomtom, if you're reading this, you won't do that. Right?

Contributing

To contribute you could just open an issue, or you could open pull requests. To do this, make a fork of bl, put your changes in there, and make a pull request to bl from your fork.

Important: You should follow the coding style when contributing code.

License

bl is licensed under the MIT license. See LICENSE.txt for the details.

Metadata

Release files for python-bl 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-bl 0.9.1
File Size Uploaded Provenance Actions
python_bl-0.9.1.tar.gz 3.9 MB Without provenance Details for python_bl-0.9.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for python-bl 0.9.1
File Interpreter ABI Platform Actions
python_bl-0.9.1-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for python_bl-0.9.1-cp312-abi3-win_amd64.whl
python_bl-0.9.1-cp312-abi3-manylinux_2_39_x86_64.whl CPython 3.12 abi3 Linux glibc 2.39+ x86-64 Details for python_bl-0.9.1-cp312-abi3-manylinux_2_39_x86_64.whl

Total release size: 4.8 MB

Release files / python_bl-0.9.1.tar.gz

Download URL python_bl-0.9.1.tar.gz
Size 3.9 MB
Tags Source
SHA-256 checksum
How to use checksums
253d2e1bb246c13fca6ae54ca37ca8a81a1567e48b2c4a51711ce6d5f7375ed6
BLAKE2b-256 checksum
How to use checksums
4328bfd53ad2fc2613812d48e0ef10ca08cf2244d01b381df6a88f726ddb1fba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / python_bl-0.9.1-cp312-abi3-win_amd64.whl

Download URL python_bl-0.9.1-cp312-abi3-win_amd64.whl
Size 388.6 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
96459f8325352358498b150794f40113cac20f4f639c0ccb0e6cb830ed1b085d
BLAKE2b-256 checksum
How to use checksums
4c4c45f0b2dfdb89a25dd314c7b236557e6235ab6df6b301767ded609573d08e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / python_bl-0.9.1-cp312-abi3-manylinux_2_39_x86_64.whl

Download URL python_bl-0.9.1-cp312-abi3-manylinux_2_39_x86_64.whl
Size 461.1 kB
Tags CPython 3.12 Linux glibc 2.39+ x86-64 abi3
SHA-256 checksum
How to use checksums
aafc811f81aac4c43b02e12cc23367d2c784584e1275dbf6621e564df4d27280
BLAKE2b-256 checksum
How to use checksums
f70ce8b51895a55fde16ec8fe66b5e16471715b013063d62b0af158056ba72ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for python-bl 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.1 This release

3 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page