From 5c612929e283c27748d331e928aab36738f95939 Mon Sep 17 00:00:00 2001 From: Thome Valentin Date: Sat, 30 Apr 2022 07:00:28 +0200 Subject: [PATCH 1/2] Secret music (unlocked songs) are now saved and loaded correctly. Partially fixes issue #34. Rewards are now saved and loaded correctly. Partially fixes issue #34. --- gitadora@asphyxia/handlers/profiles.ts | 76 +++++++++++++++++--- gitadora@asphyxia/models/profile.ts | 5 ++ gitadora@asphyxia/models/secretmusicentry.ts | 5 ++ 3 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 gitadora@asphyxia/models/secretmusicentry.ts diff --git a/gitadora@asphyxia/handlers/profiles.ts b/gitadora@asphyxia/handlers/profiles.ts index 38a3cf5..59d0b8e 100644 --- a/gitadora@asphyxia/handlers/profiles.ts +++ b/gitadora@asphyxia/handlers/profiles.ts @@ -8,6 +8,7 @@ import { Scores } from "../models/scores"; import { PLUGIN_VER } from "../const"; import Logger from "../utils/logger" import { isAsphyxiaDebugMode } from "../Utils/index"; +import { SecretMusicEntry } from "../models/secretmusicentry"; const logger = new Logger("profiles") @@ -374,15 +375,13 @@ export const getPlayer: EPR = async (info, data, send) => { } } + const innerSecretMusic = getSecretMusicResponse(profile) + const response = { player: K.ATTR({ 'no': `${no}` }, { now_date: K.ITEM('u64', time), - secretmusic: { // TODO: FIX THIS - music: { - musicid: K.ITEM('s32', 0), - seq: K.ITEM('u16', 255), - kind: K.ITEM('s32', 40), - } + secretmusic: { + music: innerSecretMusic }, chara_list: {}, title_parts: {}, @@ -390,7 +389,7 @@ export const getPlayer: EPR = async (info, data, send) => { info: K.ARRAY('u32', Array(50).fill(0)), }, reward: { - status: K.ARRAY('u32', Array(50).fill(0)), + status: K.ARRAY('u32', extra.reward_status ?? Array(50).fill(0)), }, rivaldata: {}, frienddata: {}, @@ -615,7 +614,10 @@ async function registerUser(refid: string, version: string, id = _.random(0, 999 full_music_num: 0, exce_music_num: 0, clear_seq_num: 0, - classic_all_skill: 0 + classic_all_skill: 0, + secretmusic: { + music: [] + } } }; @@ -842,6 +844,11 @@ async function saveSinglePlayer(dataplayer: KDataReader, refid: string, no: numb } }; + let newSecretMusic = parseSecretMusic(dataplayer) + profile.secretmusic = { + music: newSecretMusic + } + autoSet('max_skill', 'record.max.skill'); autoSet('max_all_skill', 'record.max.all_skill'); autoSet('clear_diff', 'record.max.clear_diff'); @@ -939,14 +946,20 @@ async function saveSinglePlayer(dataplayer: KDataReader, refid: string, no: numb autoExtra('playstyle', 'customdata.playstyle', true); autoExtra('custom', 'customdata.custom', true); + autoExtra('reward_status', 'reward.status', true) await DB.Upsert(refid, { collection: 'profile', game, version }, profile) await DB.Upsert(refid, { collection: 'record', game, version }, rec) await DB.Upsert(refid, { collection: 'extra', game, version }, extra) - const stages = dataplayer.elements('stage'); + const playedStages = dataplayer.elements('stage'); + const scores = await updatePlayerScoreCollection(refid, playedStages, version, game) + await saveScore(refid, version, game, scores); +} + +async function updatePlayerScoreCollection(refid, playedStages, version, game) { const scores = (await getScore(refid, version, game)).scores; - for (const stage of stages) { + for (const stage of playedStages) { const mid = stage.number('musicid', -1); const seq = stage.number('seq', -1); @@ -986,8 +999,9 @@ async function saveSinglePlayer(dataplayer: KDataReader, refid: string, no: numb }; } - await saveScore(refid, version, game, scores); + return scores } + async function getPlayerRanking(refid: string, version: string, game: 'gf' | 'dm') : Promise { let profiles = await getAllProfiles(version, game) let playerCount = profiles.length @@ -1086,3 +1100,43 @@ async function saveScore(refid: string, version: string, game: 'gf' | 'dm', scor scores }) } + +function parseSecretMusic(playerData: KDataReader) : SecretMusicEntry[] +{ + let response : SecretMusicEntry[] = [] + + let elements = playerData.element('secretmusic')?.elements('music') + if (!elements) { + return response + } + + for (let el of elements) { + let item : SecretMusicEntry = { + musicid: el.number('musicid'), + seq: el.number('seq'), + kind: el.number('kind') + } + + response.push(item) + } + return response +} + +function getSecretMusicResponse(profile: Profile) { + let response = [] + + if (!profile.secretmusic?.music ) { + return response + } + + for (let music of profile.secretmusic.music) { + response.push({ + musicid: K.ITEM('s32', music.musicid), + seq: K.ITEM('u16', music.seq), + kind: K.ITEM('s32', music.kind) + }) + } + + return response +} + diff --git a/gitadora@asphyxia/models/profile.ts b/gitadora@asphyxia/models/profile.ts index b27746d..3829578 100644 --- a/gitadora@asphyxia/models/profile.ts +++ b/gitadora@asphyxia/models/profile.ts @@ -1,3 +1,5 @@ +import { SecretMusicEntry } from "./secretmusicentry"; + export interface Profile { collection: 'profile'; @@ -54,4 +56,7 @@ export interface Profile { exce_music_num: number; clear_seq_num: number; classic_all_skill: number; + secretmusic: { + music: SecretMusicEntry[]; + } } diff --git a/gitadora@asphyxia/models/secretmusicentry.ts b/gitadora@asphyxia/models/secretmusicentry.ts new file mode 100644 index 0000000..cca28b1 --- /dev/null +++ b/gitadora@asphyxia/models/secretmusicentry.ts @@ -0,0 +1,5 @@ +export interface SecretMusicEntry { + musicid: number; + seq: number; + kind: number; +} From 6c8585a2584038dbdb9273ee0ccca7fe42d5df77 Mon Sep 17 00:00:00 2001 From: Thome Valentin Date: Sun, 1 May 2022 12:50:14 +0200 Subject: [PATCH 2/2] Update readme file. --- gitadora@asphyxia/README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gitadora@asphyxia/README.md b/gitadora@asphyxia/README.md index 7cd500e..662985e 100644 --- a/gitadora@asphyxia/README.md +++ b/gitadora@asphyxia/README.md @@ -1,6 +1,6 @@ GITADORA Plugin for Asphyxia-Core ================================= -![Version: v1.2.0](https://img.shields.io/badge/version-v1.2.0-blue) +![Version: v1.2.1](https://img.shields.io/badge/version-v1.2.1-blue) This plugin is based on converted from public-exported Asphyxia's Routes. @@ -23,13 +23,20 @@ The folder structure between v1.0 and v1.1 is quite different. Do not overwrite Known Issues ============ - * Information dialog keep showing as plugin doesn't store item data currently. + * ~Information dialog keep showing as plugin doesn't store item data currently.~ (Fixed as of version 1.2.1) * Special Premium Encore on Nextage - Bandage solution is implemented. Try it. Release Notes ============= +v1.2.1 +---------------- +* Secret Music (unlocked songs) are now saved and loaded correctly. Partially fixes Github issue #34. Note that all songs are already marked as unlocked by the server - there is no need to unlock them manually. If you would like to lock them, consider using a custom MDB. +* Rewards field is now saved and loaded correctly. Fixes Github issue #34 + +NOTE: Rewards and secret music is saved at the end of each session, so you will see the unlock notifications one last time after updating the plugin to this version. + v1.2.0 ---------------- * Fixed server error when saving profiles for two Guitar Freaks players at the end of a session. Fixes Github issue #39.