Emotional Code|

Nolca

园龄:6年9个月粉丝:12关注:9

balatro save mod

#!/bin/env python
import regex as re
import argparse
import os
SAVE = "/media/n/data/SteamLibrary/steamapps/compatdata/2379780/pfx/dosdevices/c:/users/steamuser/AppData/Roaming/Balatro/1/save.jkr"
def find_default():
global SAVE
default = '/1/save.jkr'
import sys
OS = sys.platform
if OS == 'win32':
default = "%AppData%/Balatro" + default
elif OS == 'darwin':
default = "~/Library/Application Support/Balatro" + default
elif OS == 'linux':
default = "~/.local/share/Steam/steamapps/compatdata/2379780/pfx/drive_c/users/steamuser/AppData/Roaming/Balatro" + default
else:
print(f'OS={OS} not supported')
return
default = os.path.expanduser(default)
if not os.path.exists(default):
print(f'default save path not found:{default}')
return
SAVE = default
_set('SAVE', SAVE)
def _set(var_name='VAR', value=None, file=__file__, insert_able=True, ONLY_GLOBAL_VAR=True):
"""
Used to record var in self `.py` file
"""
self_py = ''
value = str(value)
re_newline = r'(?<=\n)' if ONLY_GLOBAL_VAR else ''
re_pattern = ''
re_repl = ''
if value.find('\n') != -1:
re_pattern = '"""((.|\n)*?)"""'
re_repl = f'{var_name} = """\n{value}\n"""\n'
else:
re_pattern = '"(.*?)"'
re_repl = f'{var_name} = "{value}"\n'
re_pattern = f'{re_newline}{var_name}={re_pattern}'
with open(file, 'r', encoding='utf-8') as f:
self_py = f.read()
if re.search(re_pattern, self_py):
self_py = re.sub(re_pattern, re_repl, self_py)
else:
if insert_able:
self_py = re.sub(r'(?<=\n)', re_repl, self_py, count=1) # insert after 1st line
else:
print(f'{var_name} not found in {file}')
return
with open(file, 'w', encoding='utf-8') as f:
f.write(self_py)
def timestamp():
import time
return time.strftime('%m-%d_%H:%M:%S')
def save():
"""copy SAVE to SAVE.bak"""
bak = f'{SAVE},{timestamp()}.bak'
with open(SAVE, 'rb') as f:
with open(bak, 'wb') as f2:
f2.write(f.read())
print(f'💾 game saved to {SAVE}')
def list_saves():
"""list all save files"""
import glob
l = []
for i in glob.glob(SAVE + '*.bak'):
l.append(i)
# 按时间排序,最新的在最前
l.sort(key=lambda x: os.path.getmtime(x), reverse=True)
for i in l:
print(i.split('/')[-1])
return l
def load():
"""copy SAVE.bak to SAVE"""
bak = list_saves()[0]
if not os.path.exists(bak):
print(f'file not found: {bak}')
return
with open(bak, 'rb') as f:
with open(SAVE, 'wb') as f2:
f2.write(f.read())
print(f'📂 game loaded from {bak.split('/')[-1]}')
def main():
global SAVE
parse = argparse.ArgumentParser()
# save.py [-l|--load] [-s|--save <save_name>] -p|--path <save_file_path>
parse.add_argument('-s', '--save', action='store_true', help='save game to file')
parse.add_argument('-l', '--load', action='store_true', help='load game from file')
parse.add_argument('-p', '--path', help='set default save path')
args = parse.parse_args()
if args.path:
SAVE = args.path
_set('SAVE', SAVE)
try:
if not SAVE or not os.path.exists(SAVE):
print(f'file not found: {SAVE}')
raise FileNotFoundError
except NameError or FileNotFoundError:
find_default()
finally:
if args.save:
save()
elif args.load:
load()
else:
print(f'current save file = {SAVE}')
list_saves()
if __name__ == '__main__':
main()

本文作者:Nolca

本文链接:https://www.cnblogs.com/nolca/p/18665461

版权声明:本作品采用 收益分享revenue sharing 许可协议进行许可。

posted @   Nolca  阅读(14)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 ⏩intro 山姆精
  2. 2 🎸吉他 马叉
  3. 3 ☁升调 山姆精
  4. 4 🐦Flutter Virtual Riot/Madi
  5. 5 🎶纯律 山姆精
  6. 6 👻yeah~Color Bass! VR
⏩intro - 山姆精
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.