mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
Merge pull request #233 from dmitmel/master
[pull] master from dmitmel:master
This commit is contained in:
commit
49b67aea8d
5 changed files with 111 additions and 4 deletions
8
pyrightconfig.json
Normal file
8
pyrightconfig.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"executionEnvironments": [
|
||||
{
|
||||
"root": "scripts",
|
||||
"extraPaths": ["script-resources"]
|
||||
}
|
||||
]
|
||||
}
|
65
script-resources/factorio/property_tree.py
Normal file
65
script-resources/factorio/property_tree.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
# <https://wiki.factorio.com/Property_tree>
|
||||
# <factorio.https://wiki.factorio.com/Data_types>
|
||||
# <https://github.com/credomane/factoriomodsettings/blob/master/src/ModSettingsDeserialiser.js>
|
||||
# <https://github.com/credomane/factoriomodsettings/blob/master/src/ModSettingsSerialiser.js>
|
||||
# <https://www.devdungeon.com/content/working-binary-data-python>
|
||||
|
||||
import struct
|
||||
|
||||
|
||||
def read_bool(buf):
|
||||
return buf.read(1)[0] == 1
|
||||
|
||||
|
||||
def read_number(buf):
|
||||
return struct.unpack("<d", buf.read(8))[0]
|
||||
|
||||
|
||||
def _read_length(buf):
|
||||
return struct.unpack("<I", buf.read(4))[0]
|
||||
|
||||
|
||||
def read_string(buf):
|
||||
is_empty = read_bool(buf)
|
||||
if is_empty:
|
||||
return ""
|
||||
len_ = buf.read(1)[0]
|
||||
if len_ == 0xFF:
|
||||
len_ = _read_length(buf)
|
||||
return buf.read(len_).decode("utf8")
|
||||
|
||||
|
||||
def read_dictionary(buf):
|
||||
len_ = _read_length(buf)
|
||||
value = {}
|
||||
for _ in range(len_):
|
||||
key = read_string(buf)
|
||||
value[key] = read(buf)
|
||||
return value
|
||||
|
||||
|
||||
def read_list(buf):
|
||||
len_ = _read_length(buf)
|
||||
value = []
|
||||
for _ in range(len_):
|
||||
read_string(buf)
|
||||
value.append(read(buf))
|
||||
return value
|
||||
|
||||
|
||||
def read(buf):
|
||||
type_, _any_type_flag = buf.read(2)
|
||||
if type_ == 0:
|
||||
return None
|
||||
elif type_ == 1:
|
||||
return read_bool(buf)
|
||||
elif type_ == 2:
|
||||
return read_number(buf)
|
||||
elif type_ == 3:
|
||||
return read_string(buf)
|
||||
elif type_ == 4:
|
||||
return read_list(buf)
|
||||
elif type_ == 5:
|
||||
return read_dictionary(buf)
|
||||
else:
|
||||
raise Exception("unknown property tree type 0x{:02x}".format(type_))
|
|
@ -8,8 +8,7 @@ import urllib.parse
|
|||
import urllib.request
|
||||
|
||||
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
||||
|
||||
import common_script_utils # noqa: E402
|
||||
import common_script_utils
|
||||
|
||||
|
||||
DEFAULT_REGISTRY_DUMP_URL = "https://stronghold.crosscode.ru/~ccbot/emote-registry.json"
|
||||
|
|
36
scripts/factorio-dump-mod-settings
Executable file
36
scripts/factorio-dump-mod-settings
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python3
|
||||
# <https://wiki.factorio.com/Mod_settings_file_format>
|
||||
# <https://forums.factorio.com/59851>
|
||||
# <https://www.dropbox.com/sh/uscmj9y3cjfwpsr/AAD35_ZZu64EBi0awLA07fxga?dl=0>
|
||||
# <https://github.com/credomane/factoriomodsettings/blob/master/src/FactorioModSettings.js>
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import json
|
||||
|
||||
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
||||
import factorio.property_tree
|
||||
|
||||
|
||||
with open(Path.home() / ".factorio" / "mods" / "mod-settings.dat", "rb") as f:
|
||||
|
||||
version_main, version_major, version_minor, version_developer = struct.unpack(
|
||||
"<HHHH", f.read(8)
|
||||
)
|
||||
|
||||
always_false_flag = factorio.property_tree.read_bool(f)
|
||||
assert not always_false_flag
|
||||
|
||||
deserialized_data = {
|
||||
"factorio_version": {
|
||||
"main": version_main,
|
||||
"major": version_major,
|
||||
"minor": version_minor,
|
||||
"developer": version_developer,
|
||||
},
|
||||
"data": factorio.property_tree.read(f),
|
||||
}
|
||||
|
||||
print(json.dumps(deserialized_data, indent=2))
|
|
@ -17,8 +17,7 @@ import sqlite3
|
|||
import collections
|
||||
|
||||
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
|
||||
|
||||
import common_script_utils # noqa: E402
|
||||
import common_script_utils
|
||||
|
||||
|
||||
if sys.platform == "darwin":
|
||||
|
|
Loading…
Reference in a new issue