Last active
May 1, 2022 14:47
-
-
Save Sucareto/dfb4b1cb1bf2d46ce221ffa0846ce073 to your computer and use it in GitHub Desktop.
Asphyxia转Asphyxia Core的数据转换工具
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import sample, randint | |
from string import ascii_letters, digits | |
import json | |
from re import search | |
from time import time | |
import shutil | |
from colorama import init | |
init(autoreset=True) | |
# 全局变量 | |
appealID = 0 | |
akanameID = 0 | |
refid = "" | |
uid = "" | |
def readID(): # TODO 支持多用户,输入卡号导入指定用户 | |
print("\033[1;34;40m读取 CORE 存档记录 ... ") | |
global refid, uid | |
with open('savedata.db', 'r', encoding='utf-8') as db: | |
for line in db.readlines(): | |
if search(r'"__s":"card"', line): | |
refid = json.loads(line)['__refid'] | |
elif search(r'"collection":"profile"', line): | |
uid = json.loads(line)['id'] | |
def sdvx_appeal(): | |
global appealID, akanameID | |
try: | |
with open('sdvx_appeal.json', 'r', encoding='utf-8') as f: | |
appeal = json.load(f) | |
appealID = appeal['appealID'] | |
akanameID = appeal['akanameID'] | |
print("\033[1;34;40m自定义头像称号 已读取!") | |
except: | |
print("\033[1;31;40m sdvx_appeal.json 读取错误,跳过。") | |
def sdvx_profile(): | |
print("开始处理 基础资料 ... ", end='') | |
data = "" | |
try: | |
with open('sdvx.json', 'r', encoding='utf-8') as f: | |
tmp = {} | |
sdvx = json.load(f) | |
tmp['pluginVer'] = 1 | |
tmp['collection'] = "profile" | |
tmp['id'] = uid | |
tmp['name'] = sdvx['name'] | |
tmp['appeal'] = sdvx['appealID'] if appealID < 1 else appealID | |
tmp['akaname'] = akanameID | |
tmp['blocks'] = sdvx['blocks'] | |
tmp['packets'] = sdvx['packets'] | |
tmp['arsOption'] = sdvx['arsOption'] | |
tmp['drawAdjust'] = sdvx['drawAdjust'] | |
tmp['earlyLateDisp'] = sdvx['earlyLateDisp'] | |
tmp['effCLeft'] = sdvx['effCLeft'] | |
tmp['effCRight'] = sdvx['effCRight'] | |
tmp['gaugeOption'] = sdvx['gaugeOption'] | |
tmp['hiSpeed'] = sdvx['hiSpeed'] | |
tmp['laneSpeed'] = sdvx['laneSpeed'] | |
tmp['narrowDown'] = sdvx['narrowDown'] | |
tmp['notesOption'] = sdvx['notesOption'] | |
tmp['blasterCount'] = sdvx['blasterCount'] | |
tmp['blasterEnergy'] = sdvx['blasterEnergy'] | |
tmp['headphone'] = sdvx['headphone'] | |
tmp['musicID'] = sdvx['lastMusicID'] | |
tmp['musicType'] = sdvx['lastMusicType'] | |
tmp['sortType'] = sdvx['sortType'] | |
tmp['__a'] = 'sdvx@asphyxia' | |
tmp['__s'] = 'plugins_profile' | |
tmp['__refid'] = refid | |
tmp['_id'] = ''.join(sample(ascii_letters + digits, 16)) | |
tmp['createdAt'] = {'$$date': int(round(time() * 1000))} | |
tmp['updatedAt'] = {'$$date': int(round(time() * 1000))} | |
data += json.dumps(tmp, separators=(',', ':')) + "\n" | |
print("\033[1;32;40m 处理完成!") | |
return data | |
except: | |
print("\033[1;31;40m sdvx.json 读取错误!") | |
return "" | |
def sdvx_skill(): | |
print("开始处理 skill ... ", end='') | |
data = "" | |
try: | |
with open('sdvx.json', 'r', encoding='utf-8') as f: | |
skill = json.load(f) | |
tmp = {} | |
tmp['collection'] = "skill" | |
tmp['version'] = 5 | |
tmp['__a'] = 'sdvx@asphyxia' | |
tmp['__s'] = 'plugins_profile' | |
tmp['__refid'] = refid | |
tmp['base'] = skill['skillBaseID']['sv5'] | |
tmp['level'] = skill['skillLevel']['sv5'] | |
tmp['name'] = skill['skillNameID']['sv5'] | |
tmp['_id'] = ''.join(sample(ascii_letters + digits, 16)) | |
tmp['createdAt'] = {'$$date': int(round(time() * 1000))} | |
tmp['updatedAt'] = {'$$date': int(round(time() * 1000))} | |
data += json.dumps(tmp, separators=(',', ':')) + "\n" | |
print("\033[1;32;40m 处理完成!") | |
return data | |
except: | |
print("\033[1;31;40m sdvx.json 读取错误,跳过。") | |
return "" | |
def sdvx_scores(): | |
print("开始处理 scores ... ", end='') | |
try: | |
data = "" | |
with open('sdvx_scores.json', 'r', encoding='utf-8') as f: # 读取歌曲成绩 | |
scores = json.load(f) | |
keys = list(scores) | |
keys.sort() | |
for key in keys: | |
tmp = {} | |
tmp['collection'] = "music" | |
tmp['mid'] = int(key.split(':')[0]) | |
tmp['type'] = int(key.split(':')[1]) | |
tmp['score'] = scores[key]['score'] | |
tmp['clear'] = scores[key]['clearType'] | |
tmp['grade'] = scores[key]['scoreGrade'] | |
tmp['buttonRate'] = scores[key]['buttonRate'] | |
tmp['longRate'] = scores[key]['longRate'] | |
tmp['volRate'] = scores[key]['volRate'] | |
tmp['__a'] = 'sdvx@asphyxia' | |
tmp['__s'] = 'plugins_profile' | |
tmp['__refid'] = refid | |
tmp['_id'] = ''.join(sample(ascii_letters + digits, 16)) | |
tmp['createdAt'] = {'$$date': int(round(time() * 1000))} | |
tmp['updatedAt'] = {'$$date': int(round(time() * 1000))} | |
data += json.dumps(tmp, separators=(',', ':')) + "\n" | |
print("\033[1;32;40m 处理完成!") | |
return data | |
except: | |
print("\033[1;31;40m sdvx_scores.json 读取错误,跳过。") | |
return "" | |
def sdvx_params(): | |
print("开始处理 params ... ", end='') | |
data = "" | |
try: | |
with open('sdvx.json', 'r', encoding='utf-8') as f: | |
params = json.load(f) | |
keys = list(params['params']) | |
for key in keys: | |
tmp = {} | |
tmp['collection'] = "param" | |
tmp['type'] = int(key.split(':')[0]) | |
tmp['id'] = int(key.split(':')[1]) | |
tmp['__a'] = 'sdvx@asphyxia' | |
tmp['__s'] = 'plugins_profile' | |
tmp['__refid'] = refid | |
tmp['param'] = params['params'][key] | |
tmp['_id'] = ''.join(sample(ascii_letters + digits, 16)) | |
tmp['createdAt'] = {'$$date': int(round(time() * 1000))} | |
tmp['updatedAt'] = {'$$date': int(round(time() * 1000))} | |
data += json.dumps(tmp, separators=(',', ':')) + "\n" | |
print("\033[1;32;40m 处理完成!") | |
return data | |
except: | |
print("\033[1;31;40m sdvx.json 读取错误,跳过。") | |
return "" | |
def sdvx_items(): | |
print("开始处理 items ... ", end='') | |
data = "" | |
try: | |
with open('sdvx.json', 'r', encoding='utf-8') as f: | |
items = json.load(f) | |
keys = list(items['items']) | |
for key in keys: | |
tmp = {} | |
tmp['collection'] = "item" | |
tmp['type'] = int(key.split(':')[0]) | |
tmp['id'] = int(key.split(':')[1]) | |
tmp['__a'] = 'sdvx@asphyxia' | |
tmp['__s'] = 'plugins_profile' | |
tmp['__refid'] = refid | |
tmp['param'] = items['items'][key] | |
tmp['_id'] = ''.join(sample(ascii_letters + digits, 16)) | |
tmp['createdAt'] = {'$$date': int(round(time() * 1000))} | |
tmp['updatedAt'] = {'$$date': int(round(time() * 1000))} | |
data += json.dumps(tmp, separators=(',', ':')) + "\n" | |
print("\033[1;32;40m 处理完成!") | |
return data | |
except: | |
print("\033[1;31;40m sdvx.json 读取错误,跳过。") | |
return "" | |
def sdvx_mixes(): | |
print("开始处理 Mixes ... ", end='') | |
data = "" | |
try: | |
with open('sdvx_mixes.json', 'r', encoding='utf-8') as f: | |
mixes = json.load(f) | |
keys = list(mixes) | |
keys.sort() | |
for key in keys: | |
tmp = {} | |
tmp['collection'] = "mix" | |
tmp['id'] = int(key) | |
tmp['code'] = str(randint(100000000000, 999999999999)) | |
tmp['name'] = mixes[key]['name'] | |
tmp['creator'] = mixes[key]['name'].split()[0] | |
tmp['param'] = str(mixes[key]['param']).replace( | |
'\"', '\\\"').replace('\'', '\"') # TODO 需要组合 | |
tmp['tag'] = mixes[key]['tag'] | |
tmp['jacket'] = mixes[key]['jacketID'] | |
tmp['__s'] = 'plugins' | |
tmp['__a'] = 'sdvx@asphyxia' | |
tmp['_id'] = ''.join(sample(ascii_letters + digits, 16)) | |
tmp['createdAt'] = {'$$date': int(round(time() * 1000))} | |
tmp['updatedAt'] = {'$$date': int(round(time() * 1000))} | |
data += json.dumps(tmp, separators=(',', ':')) + "\n" | |
print("\033[1;32;40m 处理完成!") | |
return data | |
except: | |
print("\033[1;31;40m sdvx_mixes.json 读取错误,跳过。") | |
return "" | |
def clearData(): | |
data = "" | |
with open('savedata.db', 'r', encoding='utf-8') as db: | |
for line in db.readlines(): | |
if search(r'("__s":"card"|"__s":"profile")', line) is None and search(refid, line): | |
pass | |
else: | |
data += line | |
print("\033[1;34;40msavedata.db 已读取并清理!") | |
return data | |
def readData(): | |
data = "" | |
with open('savedata.db', 'r', encoding='utf-8') as db: | |
for line in db.readlines(): | |
if search(r'"collection":"profile"', line) and search(refid, line): | |
pass | |
else: | |
data += line | |
print("\033[1;34;40msavedata.db 已读取!") | |
return data | |
print('\033[1;36;40mSDVX 存档转换 by Mahuyo\033[0m \n\ | |
===========================================================================================\n\ | |
Asphyxia v0.2.0a 转 Asphyxia CORE v1.20f : Plugins 0.42\n\ | |
先在 CORE 刷卡游玩一局结算存档;\n\ | |
把 CORE 的 savedata.db 和 Asphyxia v0.2.0a 目录下以 sdvx 开头的所有文件复制到当前目录下。\n\ | |
===========================================================================================') | |
try: | |
shutil.copy('savedata.db', 'savedata.db.bak') | |
print('原文件已备份到 savedata.db.bak') | |
readID() | |
sdvx_appeal() | |
print('\033[0;36;40m按回车开始转换。\n输入c再按回车则会在转换前清除数据库多余记录。') | |
Data = clearData() if input() == 'c' else readData() | |
Data += sdvx_profile() + sdvx_skill() + sdvx_scores() + \ | |
sdvx_items() + sdvx_mixes() + sdvx_params() | |
with open('savedata.db', 'w', encoding='utf-8') as db: | |
db.write(Data) | |
print("\033[1;34;40m转换完成!") | |
except: | |
print("\033[1;31;40m文件读取错误!") | |
input("按回车退出...") |
需要旧版Asphyxia的数据文件,转换后的是数据只支持asphyxia-core v1.30f及以前的版本,之后的版本没测试过了。
如果你要用的话,需要用v1.30f之前的版本开一个存档,然后使用此脚本转换导入,再运行v1.30f自动迁移存档,再运行最新版本的core应该就ok。
我有舊版Asphyxia 0.2.0a的json 數據文件 也是用v1.30f版本開存檔
json數據文件跟.db數據都放在同一個文件夾下
執行後出現以下錯誤提示
Traceback (most recent call last):
File "G:\下載暫存\SDVX\Asp2Core.py", line 7, in
from colorama import init
ModuleNotFoundError: No module named 'colorama'
ModuleNotFoundError: No module named 'colorama'
你这是缺模块,运行pip3 install colorama
安装后再运行就好了。
感謝 已成功轉移存檔
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
請問這個工具還能用嗎 好像沒法直接執行