mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-03-21 17:34:46 -05:00
- Fixed another server error when two players are present, but only one player is using a profile. - Added support for the "ranking" field. Gitadora will now correctly display your server ranking (based on Skill) on the post-game screen. - Added logging for profile loading/saving when Asphyxia is running in dev mode. - Added more logging to mdb (song database) loading. - "Recommended to friends" songs are now saved and loaded correctly. Since you don't have any friends, this won't be terribly useful, but it does at least provide an extra five slots for saving your favourite songs. - Fixed "Recommended to friends" song list being incorrectly initialized to "I think about you". - Removed some unneeded duplicate code. - Latest getPlayer() and savePlayers() API requests and responses are now saved to file when Asphyxia is in dev mode. Useful for debugging. NOTE: The above has only been tested on Gitadora Exchain.
134 lines
3.5 KiB
TypeScript
134 lines
3.5 KiB
TypeScript
import Logger from "../../utils/logger";
|
|
|
|
export interface CommonMusicDataField {
|
|
id: KITEM<"s32">;
|
|
cont_gf: KITEM<"bool">;
|
|
cont_dm: KITEM<"bool">;
|
|
is_secret: KITEM<"bool">;
|
|
is_hot: KITEM<"bool">;
|
|
data_ver: KITEM<"s32">;
|
|
diff: KARRAY<"u16">;
|
|
}
|
|
|
|
export interface CommonMusicData {
|
|
music: CommonMusicDataField[]
|
|
}
|
|
|
|
export enum DATAVersion {
|
|
HIGHVOLTAGE = "hv",
|
|
NEXTAGE = "nt",
|
|
EXCHAIN = "ex",
|
|
MATTIX = "mt"
|
|
}
|
|
|
|
type processRawDataHandler = (path: string) => Promise<CommonMusicData>
|
|
|
|
const logger = new Logger("mdb")
|
|
|
|
export async function readXML(path: string) {
|
|
logger.debugInfo(`Loading MDB data from ${path}.`)
|
|
const xml = await IO.ReadFile(path, 'utf-8');
|
|
const json = U.parseXML(xml, false)
|
|
return json
|
|
}
|
|
|
|
export async function readJSON(path: string) {
|
|
logger.debugInfo(`Loading MDB data from ${path}.`)
|
|
const str = await IO.ReadFile(path, 'utf-8');
|
|
const json = JSON.parse(str)
|
|
return json
|
|
}
|
|
|
|
export async function readJSONOrXML(jsonPath: string, xmlPath: string, processHandler: processRawDataHandler): Promise<CommonMusicData> {
|
|
if (!IO.Exists(jsonPath)) {
|
|
logger.debugInfo(`Loading MDB data from ${xmlPath}.`)
|
|
const data = await processHandler(xmlPath)
|
|
await IO.WriteFile(jsonPath, JSON.stringify(data))
|
|
return data
|
|
} else {
|
|
logger.debugInfo(`Loading MDB data from ${jsonPath}.`)
|
|
const json = JSON.parse(await IO.ReadFile(jsonPath, 'utf-8'))
|
|
return json
|
|
}
|
|
}
|
|
|
|
export async function readB64JSON(b64path: string) {
|
|
logger.debugInfo(`Loading MDB data from ${b64path}.`)
|
|
const buff = await IO.ReadFile(b64path, 'utf-8');
|
|
return JSON.parse(Buffer.from(buff, 'base64').toString('utf-8'));
|
|
}
|
|
|
|
export function gameVerToDataVer(ver: string): DATAVersion {
|
|
switch(ver) {
|
|
case 'highvoltage':
|
|
return DATAVersion.HIGHVOLTAGE
|
|
case 'nextage':
|
|
return DATAVersion.NEXTAGE
|
|
case 'exchain':
|
|
return DATAVersion.EXCHAIN
|
|
case 'matixx':
|
|
default:
|
|
return DATAVersion.MATTIX
|
|
}
|
|
}
|
|
|
|
export async function processDataBuilder(gameVer: string, processHandler?: processRawDataHandler) {
|
|
const ver = gameVerToDataVer(gameVer)
|
|
const base = `data/mdb/${ver}`
|
|
if (IO.Exists(`${base}.b64`)) {
|
|
return await readB64JSON(`${base}.b64`);
|
|
}
|
|
const { music } = await readJSONOrXML(`${base}.json`, `${base}.xml`, processHandler ?? defaultProcessRawData)
|
|
// await IO.WriteFile(`${base}.b64`, Buffer.from(JSON.stringify({music})).toString("base64"))
|
|
return { music };
|
|
}
|
|
|
|
export async function defaultProcessRawData(path: string): Promise<CommonMusicData> {
|
|
const data = await readXML(path)
|
|
const mdb = $(data).elements("mdb.mdb_data");
|
|
const music: any[] = [];
|
|
for (const m of mdb) {
|
|
const d = m.numbers("xg_diff_list");
|
|
const contain = m.numbers("contain_stat");
|
|
const gf = contain[0];
|
|
const dm = contain[1];
|
|
|
|
if (gf == 0 && dm == 0) {
|
|
continue;
|
|
}
|
|
|
|
let type = gf;
|
|
if (gf == 0) {
|
|
type = dm;
|
|
}
|
|
|
|
music.push({
|
|
id: K.ITEM('s32', m.number("music_id")),
|
|
cont_gf: K.ITEM('bool', gf == 0 ? 0 : 1),
|
|
cont_dm: K.ITEM('bool', dm == 0 ? 0 : 1),
|
|
is_secret: K.ITEM('bool', 0),
|
|
is_hot: K.ITEM('bool', type == 2 ? 0 : 1),
|
|
data_ver: K.ITEM('s32', m.number("data_ver", 115)),
|
|
diff: K.ARRAY('u16', [
|
|
d[0],
|
|
d[1],
|
|
d[2],
|
|
d[3],
|
|
d[4],
|
|
d[10],
|
|
d[11],
|
|
d[12],
|
|
d[13],
|
|
d[14],
|
|
d[5],
|
|
d[6],
|
|
d[7],
|
|
d[8],
|
|
d[9],
|
|
]),
|
|
});
|
|
}
|
|
return {
|
|
music,
|
|
};
|
|
} |