Skip to content

Commit f357c2b

Browse files
committed
add premium pass hack for p2d
1 parent 8e56b43 commit f357c2b

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/services/p2d/user.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { inject, injectable } from "tsyringe";
33
import { PlayerPlayData, PlayerMusicData, PlayerPlayLog, PlayerCourseLog, PlayerCustomizeSetting, PlayerRivalData } from "../../types/p2d/index.js";
44
import { Pdata } from "../../types/p2d/pdata.js";
55
import { fromKBinXml, toObject } from "../../utils/kbinxml.js";
6+
import { to_bin, to_xml } from "@geekidos/kbinxml";
7+
import { sha256 } from "../../utils/sha256.js";
68

79
@injectable()
810
export class UserService {
@@ -143,6 +145,15 @@ export class UserService {
143145
if (!result)
144146
return undefined;
145147

148+
// TODO: implement actual kbinxml encoding/decoding library in js
149+
// to avoid hacking like this and in utils/kbinxml/kxml-value.ts
150+
let { data } = to_xml(result.pdata.buffer)
151+
if (!data.includes("premium_pass")) {
152+
data = data.replace("<pdata>", "<pdata><premium_pass __type=\"bool\">1</premium_pass>")
153+
result.pdata.buffer = to_bin(data).data;
154+
result.check_sum = sha256(Buffer.from(result.pdata.buffer));
155+
}
156+
146157
return {
147158
pdata: Buffer.from(result.pdata.buffer),
148159
check_sum: result.check_sum,
@@ -153,19 +164,19 @@ export class UserService {
153164
const binary = await this.getPDataBinary(player);
154165
if (!binary) return undefined;
155166

156-
return toObject(fromKBinXml(binary.pdata)).pdata;
167+
return toObject(fromKBinXml(binary.pdata as Uint8Array)).pdata;
157168
}
158169

159170
upsertPDataBinary(player: string, pdata: Buffer, check_sum: string) {
160-
const unpacked = toObject(fromKBinXml(pdata)) as { pdata: Pdata };
171+
const unpacked = toObject(fromKBinXml(pdata as Uint8Array)) as { pdata: Pdata };
161172
const { djname, infinitas_id } = unpacked.pdata.player;
162173

163174
return this.playDataCol
164175
.updateOne({ _id: player }, {
165176
$set: {
166177
djname, infinitas_id,
167178

168-
pdata: new Binary(pdata),
179+
pdata: new Binary(pdata as Uint8Array),
169180
check_sum,
170181
}
171182
}, { upsert: true });

src/types/p2d/pdata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface Pdata {
2+
premium_pass: boolean;
23
bit: Bit;
34
dan: Dan;
45
effector: Effector;

src/utils/kbinxml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export function toKBinXml(topName: string, obj: Serializable, encoding: 'UTF-8'
283283

284284
const bin = to_bin(xml);
285285
if (dumpXml) {
286-
writeFileSync('dump.bin', Buffer.from(bin.data));
286+
writeFileSync('dump.bin', Uint8Array.from(bin.data));
287287
}
288288

289289
return bin;

src/utils/sha256.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { createHash } from "crypto";
22

33
export function sha256(data: Buffer) {
44
return createHash('sha256')
5-
.update(data)
5+
.update(Uint8Array.from(data))
66
.digest('hex');
77
}

0 commit comments

Comments
 (0)