fix: auth magics
This commit is contained in:
parent
f8221a0f50
commit
5426ad5059
66
src/file.ts
66
src/file.ts
|
@ -1,63 +1,45 @@
|
||||||
/* eslint-disable no-extend-native */
|
/* eslint-disable no-extend-native */
|
||||||
|
|
||||||
import scoreinfo from './scoreinfo'
|
import scoreinfo from './scoreinfo'
|
||||||
import { onPackLoad, webpackContext } from './webpack-hook'
|
import { onPackLoad, loadAllPacks } from './webpack-hook'
|
||||||
|
|
||||||
type FileType = 'img' | 'mp3' | 'midi'
|
type FileType = 'img' | 'mp3' | 'midi'
|
||||||
|
|
||||||
const AUTH_REG = /,((\d+\.\..+?)?function\(\)\{var \w=Array.prototype.slice.*?)\)(\[|\.then)/
|
const AUTH_REG = /,((\d+\.\..+?)?function\(\)\{var \w=Array.prototype.slice.*?)\)(\[|\.then)/
|
||||||
const PACK_ID_REG = /\((\{.*?"\})\[\w\]\|\|\w\)/
|
|
||||||
const packIdPromise: Promise<Record<FileType, (string | number)>> = webpackContext.then((ctx) => {
|
|
||||||
const ids = {
|
|
||||||
img: '9',
|
|
||||||
midi: '',
|
|
||||||
mp3: '',
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
enum PACK_HINT {
|
||||||
const fn = ctx.e.toString()
|
img = 'getImageRef',
|
||||||
const packsData = fn.match(PACK_ID_REG)[1] as string
|
midi = 'midi:',
|
||||||
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
mp3 = 'setVolume:',
|
||||||
const packs = Function(`return (${packsData})`)() as { [id: string]: string }
|
}
|
||||||
|
|
||||||
Object.entries(packs).forEach(([id, name]) => {
|
|
||||||
if (name.includes('audio') && !ids['mp3']) ids['mp3'] = id
|
|
||||||
if (name.includes('piano_roll') && !ids['midi']) ids['midi'] = id
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ids
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I know this is super hacky.
|
* I know this is super hacky.
|
||||||
*/
|
*/
|
||||||
const magicHookConstr = async (type: FileType) => {
|
const magicHookConstr = async (type: FileType) => {
|
||||||
const packId = await packIdPromise
|
|
||||||
|
|
||||||
// request pack
|
// request pack
|
||||||
// eslint-disable-next-line no-void, @typescript-eslint/no-unsafe-return
|
await loadAllPacks()
|
||||||
void webpackContext.then((ctx) => ctx.e(packId[type]))
|
|
||||||
|
|
||||||
return new Promise<string>((resolve) => {
|
return new Promise<string>((resolve) => {
|
||||||
onPackLoad((pack) => {
|
onPackLoad((pack) => {
|
||||||
if (pack[0].includes(packId[type]) || pack[0].includes(+packId[type])) {
|
Object.values(pack[1]).forEach((mod) => {
|
||||||
Object.values(pack[1]).forEach((mod) => {
|
const str = mod.toString()
|
||||||
const m = mod.toString().match(AUTH_REG)
|
if (!str.includes(PACK_HINT[type])) {
|
||||||
if (m) {
|
return
|
||||||
const code = m[1]
|
}
|
||||||
try {
|
|
||||||
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
const m = str.match(AUTH_REG)
|
||||||
const magic = Function(`return (${code})`)()
|
if (m) {
|
||||||
resolve(magic)
|
const code = m[1]
|
||||||
} catch (err) {
|
try {
|
||||||
console.error(err)
|
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
||||||
}
|
const magic = Function(`return (${code})`)()
|
||||||
|
resolve(magic)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue