diff --git a/popn@asphyxia/handler/eclale.ts b/popn@asphyxia/handler/eclale.ts index deb9ab9..6d071eb 100644 --- a/popn@asphyxia/handler/eclale.ts +++ b/popn@asphyxia/handler/eclale.ts @@ -229,6 +229,27 @@ const getProfile = async (refid: string, name?: string) => { await utils.writeProfile(refid, profile); } + let myBest = Array(10).fill(-1); + const scores = await utils.readScores(refid, version, true); + if(Object.entries(scores.scores).length > 0) { + const playCount = new Map(); + for(const key in scores.scores) { + const keyData = key.split(':'); + const music = parseInt(keyData[0], 10); + playCount.set(music, (playCount.get(music) || 0) + scores.scores[key].cnt); + } + + const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1])); + let i = 0; + for (const value of sortedPlayCount.keys()) { + if(i >= 10) { + break; + } + myBest[i] = value; + i++; + } + } + let player: any = { result: K.ITEM('s8', 0), account: { @@ -247,7 +268,7 @@ const getProfile = async (refid: string, name?: string) => { consecutive_days: K.ITEM('s16', 365), total_days: K.ITEM('s16', 366), interval_day: K.ITEM('s16', 1), - my_best: K.ARRAY('s16', Array(10).fill(-1)), + my_best: K.ARRAY('s16', myBest), latest_music: K.ARRAY('s16', [-1, -1, -1, -1, -1]), active_fr_num: K.ITEM('u8', 0), }, diff --git a/popn@asphyxia/handler/fantasia.ts b/popn@asphyxia/handler/fantasia.ts index 454252e..eb8db7a 100644 --- a/popn@asphyxia/handler/fantasia.ts +++ b/popn@asphyxia/handler/fantasia.ts @@ -71,6 +71,7 @@ export const getProfile = async (refid: string, name?: string) => { let clear_medal_sub = Array(GAME_MAX_MUSIC_ID).fill(0); const scoresData = await utils.readScores(refid, version); + const playCount = new Map(); for (const key in scoresData.scores) { const keyData = key.split(':'); const score = scoresData.scores[key]; @@ -106,6 +107,19 @@ export const getProfile = async (refid: string, name?: string) => { hiscore_array[hiscore_byte_pos] = hiscore_array[hiscore_byte_pos] | (hiscore_value & 0xFF); hiscore_array[hiscore_byte_pos + 1] = hiscore_array[hiscore_byte_pos + 1] | ((hiscore_value >> 8) & 0xFF); hiscore_array[hiscore_byte_pos + 2] = hiscore_array[hiscore_byte_pos + 2] | ((hiscore_value >> 16) & 0xFF); + + playCount.set(music, (playCount.get(music) || 0) + score.cnt); + } + + let myBest = Array(20).fill(-1); + const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1])); + let i = 0; + for (const value of sortedPlayCount.keys()) { + if (i >= 20) { + break; + } + myBest[i] = value; + i++; } let player: any = { @@ -114,16 +128,16 @@ export const getProfile = async (refid: string, name?: string) => { g_pm_id: K.ITEM('str', '1234-5678'), staff: K.ITEM('s8', 0), is_conv: K.ITEM('s8', -1), + my_best: K.ARRAY('s16', myBest), + clear_medal: K.ARRAY('u16', clear_medal), + clear_medal_sub: K.ARRAY('u8', clear_medal_sub), // TODO: replace with real data total_play_cnt: K.ITEM('s32', 100), today_play_cnt: K.ITEM('s16', 50), consecutive_days: K.ITEM('s16', 365), - my_best: K.ARRAY('s16', Array(20).fill(-1)), latest_music: K.ARRAY('s16', [-1, -1, -1]), active_fr_num: K.ITEM('u8', 0), - clear_medal: K.ARRAY('u16', clear_medal), - clear_medal_sub: K.ARRAY('u8', clear_medal_sub), }, player_card: { // TODO: replace with real data @@ -155,6 +169,8 @@ export const getProfile = async (refid: string, name?: string) => { const params = await utils.readParams(refid, version); utils.addExtraData(player, params, extraData); + player.player_card.best_music = myBest.slice(0, 3); + return player; } diff --git a/popn@asphyxia/handler/lapistoria.ts b/popn@asphyxia/handler/lapistoria.ts index 925e9f2..3828500 100644 --- a/popn@asphyxia/handler/lapistoria.ts +++ b/popn@asphyxia/handler/lapistoria.ts @@ -133,7 +133,6 @@ const getProfile = async (refid: string, name?: string) => { consecutive_days: K.ITEM('s16', 365), total_days: K.ITEM('s16', 366), interval_day: K.ITEM('s16', 1), - my_best: K.ARRAY('s16', Array(10).fill(-1)), latest_music: K.ARRAY('s16', [-1, -1, -1, -1, -1]), active_fr_num: K.ITEM('u8', 0), }, @@ -174,6 +173,7 @@ const getProfile = async (refid: string, name?: string) => { // Add Score const scoresData = await utils.readScores(refid, version); + const playCount = new Map(); for (const key in scoresData.scores) { const keyData = key.split(':'); const score = scoresData.scores[key]; @@ -208,8 +208,22 @@ const getProfile = async (refid: string, name?: string) => { old_score: K.ITEM('s32', 0), old_clear_type: K.ITEM('u8', 0), }); + + playCount.set(music, (playCount.get(music) || 0) + score.cnt); } + let myBest = Array(10).fill(-1); + const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1])); + let i = 0; + for (const value of sortedPlayCount.keys()) { + if (i >= 10) { + break; + } + myBest[i] = value; + i++; + } + player.account.my_best = K.ARRAY('s16', myBest); + // Add achievements const achievements = await utils.readAchievements(refid, version, defaultAchievements); diff --git a/popn@asphyxia/handler/sunny.ts b/popn@asphyxia/handler/sunny.ts index 903290a..f73c50c 100644 --- a/popn@asphyxia/handler/sunny.ts +++ b/popn@asphyxia/handler/sunny.ts @@ -67,6 +67,7 @@ export const getProfile = async (refid: string, name?: string) => { let clear_medal_sub = Array(GAME_MAX_MUSIC_ID).fill(0); const scoresData = await utils.readScores(refid, version); + const playCount = new Map(); for (const key in scoresData.scores) { const keyData = key.split(':'); const score = scoresData.scores[key]; @@ -102,6 +103,19 @@ export const getProfile = async (refid: string, name?: string) => { hiscore_array[hiscore_byte_pos] = hiscore_array[hiscore_byte_pos] | (hiscore_value & 0xFF); hiscore_array[hiscore_byte_pos + 1] = hiscore_array[hiscore_byte_pos + 1] | ((hiscore_value >> 8) & 0xFF); hiscore_array[hiscore_byte_pos + 2] = hiscore_array[hiscore_byte_pos + 2] | ((hiscore_value >> 16) & 0xFF); + + playCount.set(music, (playCount.get(music) || 0) + score.cnt); + } + + let myBest = Array(20).fill(-1); + const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1])); + let i = 0; + for (const value of sortedPlayCount.keys()) { + if (i >= 20) { + break; + } + myBest[i] = value; + i++; } let player: any = { @@ -111,16 +125,16 @@ export const getProfile = async (refid: string, name?: string) => { staff: K.ITEM('s8', 0), is_conv: K.ITEM('s8', -1), collabo: K.ITEM('u8', 255), + my_best: K.ARRAY('s16', myBest), + clear_medal: K.ARRAY('u16', clear_medal), + clear_medal_sub: K.ARRAY('u8', clear_medal_sub), // TODO: replace with real data total_play_cnt: K.ITEM('s32', 100), today_play_cnt: K.ITEM('s16', 50), consecutive_days: K.ITEM('s16', 365), - my_best: K.ARRAY('s16', Array(20).fill(-1)), latest_music: K.ARRAY('s16', [-1, -1, -1]), active_fr_num: K.ITEM('u8', 0), - clear_medal: K.ARRAY('u16', clear_medal), - clear_medal_sub: K.ARRAY('u8', clear_medal_sub), }, netvs: { rank_point: K.ITEM('s32', 0), diff --git a/popn@asphyxia/handler/tunestreet.ts b/popn@asphyxia/handler/tunestreet.ts index 9d17dd9..efca0fd 100644 --- a/popn@asphyxia/handler/tunestreet.ts +++ b/popn@asphyxia/handler/tunestreet.ts @@ -76,6 +76,7 @@ export const getProfile = async (refid: string, name?: string) => { let hiscore_array = Array(Math.floor((((GAME_MAX_MUSIC_ID * 7) * 17) + 7) / 8)).fill(0); const scoresData = await utils.readScores(refid, version); + const playCount = new Map(); for (const key in scoresData.scores) { const keyData = key.split(':'); const score = scoresData.scores[key]; @@ -114,6 +115,26 @@ export const getProfile = async (refid: string, name?: string) => { hiscore_array[hiscore_byte_pos] = hiscore_array[hiscore_byte_pos] | (hiscore_value & 0xFF); hiscore_array[hiscore_byte_pos + 1] = hiscore_array[hiscore_byte_pos + 1] | ((hiscore_value >> 8) & 0xFF); hiscore_array[hiscore_byte_pos + 2] = hiscore_array[hiscore_byte_pos + 2] | ((hiscore_value >> 16) & 0xFF); + + playCount.set(music, (playCount.get(music) || 0) + score.cnt); + } + + let myBest = Array(20).fill(-1); + const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1])); + let i = 0; + for (const value of sortedPlayCount.keys()) { + if (i >= 20) { + break; + } + myBest[i] = value; + i++; + } + + let profile_pos = 68 + for (const musicid of myBest) { + binary_profile[profile_pos] = musicid & 0xFF + binary_profile[profile_pos + 1] = (musicid >> 8) & 0xFF + profile_pos = profile_pos + 2 } const player = { @@ -169,7 +190,7 @@ export const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promi if (!refid) return send.deny(); const params = await utils.readParams(refid, version); - + params.params['play_mode'] = parseInt($(data).attr()['play_mode']); params.params['chara'] = parseInt($(data).attr()['chara_num']); params.params['option'] = parseInt($(data).attr()['option']); @@ -193,7 +214,7 @@ export const write = async (req: EamuseInfo, data: any, send: EamuseSend): Promi continue; } - if(params.params['play_mode'] == 4) { + if (params.params['play_mode'] == 4) { if ([2, 6, 7].indexOf(sheet) != -1) { continue; } diff --git a/popn@asphyxia/handler/usaneko.ts b/popn@asphyxia/handler/usaneko.ts index 09e3994..783ec17 100644 --- a/popn@asphyxia/handler/usaneko.ts +++ b/popn@asphyxia/handler/usaneko.ts @@ -267,7 +267,26 @@ const getProfile = async (refid: string, version: string, name?: string) => { await utils.writeProfile(refid, profile); } - const achievements = await utils.readAchievements(refid, version, {...defaultAchievements, version}); + let myBest = Array(10).fill(-1); + const scores = await utils.readScores(refid, version, true); + if(Object.entries(scores.scores).length > 0) { + const playCount = new Map(); + for(const key in scores.scores) { + const keyData = key.split(':'); + const music = parseInt(keyData[0], 10); + playCount.set(music, (playCount.get(music) || 0) + scores.scores[key].cnt); + } + + const sortedPlayCount = new Map([...playCount.entries()].sort((a, b) => b[1] - a[1])); + let i = 0; + for (const value of sortedPlayCount.keys()) { + if(i >= 10) { + break; + } + myBest[i] = value; + i++; + } + } let player: any = { result: K.ITEM('s8', 0), @@ -279,6 +298,7 @@ const getProfile = async (refid: string, version: string, name?: string) => { item_id: K.ITEM('s16', 0), is_conv: K.ITEM('s8', 0), license_data: K.ARRAY('s16', Array(20).fill(-1)), + my_best: K.ARRAY('s16', myBest), // TODO: replace with real data total_play_cnt: K.ITEM('s16', 100), @@ -286,9 +306,6 @@ const getProfile = async (refid: string, version: string, name?: string) => { consecutive_days: K.ITEM('s16', 365), total_days: K.ITEM('s16', 366), interval_day: K.ITEM('s16', 1), - - // TODO: replace with real data - my_best: K.ARRAY('s16', Array(10).fill(-1)), latest_music: K.ARRAY('s16', [-1, -1, -1, -1, -1]), active_fr_num: K.ITEM('u8', 0), }, @@ -354,6 +371,8 @@ const getProfile = async (refid: string, version: string, name?: string) => { stamp: [], }; + const achievements = await utils.readAchievements(refid, version, {...defaultAchievements, version}); + const profileCharas = achievements.charas || {}; for (const chara_id in profileCharas) { player.chara_param.push({