From 2d498ae02b021f7fbb7e7f38866942bb3e48bd31 Mon Sep 17 00:00:00 2001 From: Lost-MSth Date: Fri, 12 Apr 2024 16:16:35 +0800 Subject: [PATCH] [Enhance] Link Play Unlock for ETR - Add support for the new client with ETR difficulty in Link Play #160 --- latest version/core/item.py | 3 ++- latest version/core/linkplay.py | 30 +++++++----------------------- latest version/core/score.py | 2 +- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/latest version/core/item.py b/latest version/core/item.py index fcf5bd9..24278f4 100644 --- a/latest version/core/item.py +++ b/latest version/core/item.py @@ -1,5 +1,6 @@ from .config_manager import Config -from .error import DataExist, InputError, ItemNotEnough, ItemUnavailable, NoData +from .error import (DataExist, InputError, ItemNotEnough, ItemUnavailable, + NoData) class Item: diff --git a/latest version/core/linkplay.py b/latest version/core/linkplay.py index 29bccf2..9184512 100644 --- a/latest version/core/linkplay.py +++ b/latest version/core/linkplay.py @@ -11,33 +11,17 @@ from .util import aes_gcm_128_decrypt, aes_gcm_128_encrypt socket.setdefaulttimeout(Constant.LINKPLAY_TIMEOUT) -def get_song_unlock(client_song_map: dict) -> bytes: +def get_song_unlock(client_song_map: 'dict[str, list]') -> bytes: '''处理可用歌曲bit,返回bytes''' user_song_unlock = [0] * Constant.LINKPLAY_UNLOCK_LENGTH - for i in range(0, Constant.LINKPLAY_UNLOCK_LENGTH*2, 2): - x = 0 - y = 0 - if str(i) in client_song_map: - if client_song_map[str(i)][0]: - x += 1 - if client_song_map[str(i)][1]: - x += 2 - if client_song_map[str(i)][2]: - x += 4 - if client_song_map[str(i)][3]: - x += 8 - if str(i+1) in client_song_map: - if client_song_map[str(i+1)][0]: - y += 1 - if client_song_map[str(i+1)][1]: - y += 2 - if client_song_map[str(i+1)][2]: - y += 4 - if client_song_map[str(i+1)][3]: - y += 8 - user_song_unlock[i // 2] = y*16 + x + for k, v in client_song_map.items(): + for i in range(5): + if not v[i]: + continue + index = int(k) * 5 + i + user_song_unlock[index // 8] |= 1 << (index % 8) return bytes(user_song_unlock) diff --git a/latest version/core/score.py b/latest version/core/score.py index 4f37ca5..5ad712e 100644 --- a/latest version/core/score.py +++ b/latest version/core/score.py @@ -11,7 +11,7 @@ from .item import ItemCore from .song import Chart from .sql import Connect, Query, Sql from .util import get_today_timestamp, md5 -from .world import WorldPlay, BeyondWorldPlay, BreachedWorldPlay +from .world import BeyondWorldPlay, BreachedWorldPlay, WorldPlay class Score: