Skip to content

Instantly share code, notes, and snippets.

@yousan
Created May 11, 2026 01:03
Show Gist options
  • Select an option

  • Save yousan/b098d09c0721a6ea2358d2edebca7cbc to your computer and use it in GitHub Desktop.

Select an option

Save yousan/b098d09c0721a6ea2358d2edebca7cbc to your computer and use it in GitHub Desktop.
Factorio 2.0.67+: dump game blueprint library from a running headless server via RCON (no restart, no mods)

Factorio 稼働中サーバから「ゲームのブループリントライブラリ」を吸い出す

Factorio のヘッドレスサーバを 再起動せず・mod も追加せず、サーバ内の 「ゲーム(ワールド)のブループリントライブラリ」を全件まとめて取り出すレシピです。

仕組み

層は 3 段:

  1. Lua API — Factorio プロセス内で動くスクリプト用 API。game.blueprints 等。外から直接は触れない。
  2. コンソールコマンド/silent-command, /c, /sc。Lua VM への唯一の入口。
  3. RCON — TCP/IP で外から繋げる唯一の口。/silent-command rcon.print(...) を送ると、Lua の結果が応答として返る。

つまり「外から Lua を叩く」=「RCON で /silent-command を送る」です。

Factorio 2.0.67 で LuaRecord:export_record() が追加された

それ以前は「ブループリントライブラリの中身は Lua から触れない」が定説でしたが、 2.0.67 で LuaRecord:export_record() が公開され、ライブラリ内の各レコードを ブループリント文字列としてエクスポートできるようになりました。

  • ゲーム(ワールド)ライブラリ: game.blueprintsLuaRecord[]
  • 個人ライブラリ: player.blueprintsLuaRecord[]

この Gist の対象はゲームライブラリです。

前提

  • Factorio headless server 2.0.67 以上 で稼働中
  • server-settings.json などで RCON が有効になっていて、パスワードがある
  • RCON ポートに届けるツール(ここでは rcon.py 系の Python 1 ファイルラッパーを想定)

出力先

サーバプロセスの作業ディレクトリ配下の script-output/blueprints/ に書き出されます。中身はゲーム内で 「ブループリント文字列としてインポート」にそのまま貼れる base64 文字列です。

  • game_NNN_blueprint.txt または game_NNN_blueprint-book.txt
  • MANIFEST.tsv — index / type / バイト数 / ファイル名

注意

  • /silent-command は実行時に「実績無効化」フラグを立てますが、 マルチプレイサーバなら元々関係ないので無害。
  • 1 レコードあたり数百 KB 超になる場合があり、RCON のレスポンス 上限に当たるので rcon.print で文字列を返さず、Lua の helpers.write_file でサーバ側ファイルに書くのがコツ。
  • 復元時は、もとのライブラリに「貼り戻す」操作はゲームクライアント 側でやる必要がある(mod なしでサーバから push する API は無い)。

使い方

./extract-game-blueprints.sh 127.0.0.1 27015 /path/to/rconpw

実体は /silent-command を 1 発投げるだけ。サーバの script-output/blueprints/ を覗いてください。

-- Factorio 2.0.67+ : dump all game-library blueprints to script-output/blueprints/
-- Run via RCON: /silent-command <this whole snippet, on one line>
local bps = game.blueprints
local n = #bps
local manifest = {"count=" .. n}
for i = 1, n do
local r = bps[i]
local s = r.export_record(r)
local fn = string.format("blueprints/game_%03d_%s.txt", i, r.type)
helpers.write_file(fn, s, false)
table.insert(manifest, string.format("%d\t%s\t%d\t%s", i, r.type, #s, fn))
end
helpers.write_file("blueprints/MANIFEST.tsv", table.concat(manifest, "\n"), false)
rcon.print("wrote " .. n .. " files; see script-output/blueprints/")
#!/usr/bin/env bash
# Usage: ./extract-game-blueprints.sh <host> <port> <rconpw-file-or-string>
# Requires: python3 + a small rcon client (e.g. factorio-rcon-py's rcon.py).
# Writes files into the server's script-output/blueprints/ directory.
set -euo pipefail
HOST="${1:-127.0.0.1}"
PORT="${2:-27015}"
PW_ARG="${3:?path to rcon password file, or the password itself}"
RCON_PY="${RCON_PY:-$HOME/games/factorio1/maps/rcon.py}"
if [[ -f "$PW_ARG" ]]; then
PW="$(cat "$PW_ARG")"
else
PW="$PW_ARG"
fi
# Single-line Lua payload — Factorio's /silent-command does not like literal newlines.
LUA='local bps=game.blueprints local n=#bps local manifest={"count="..n} for i=1,n do local r=bps[i] local s=r.export_record(r) local fn=string.format("blueprints/game_%03d_%s.txt",i,r.type) helpers.write_file(fn,s,false) table.insert(manifest,string.format("%d\t%s\t%d\t%s",i,r.type,#s,fn)) end helpers.write_file("blueprints/MANIFEST.tsv",table.concat(manifest,"\n"),false) rcon.print("wrote "..n.." files; see script-output/blueprints/")'
python3 "$RCON_PY" "$HOST" "$PORT" "$PW" "/silent-command $LUA"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment