Skip to content

Commit

Permalink
Add support for latest danser versions
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterIO02 committed Oct 16, 2022
1 parent 7e22bb5 commit 6c95abb
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 99 deletions.
6 changes: 3 additions & 3 deletions files/checkDanserVersion.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ module.exports = async () => {
if (data) hash.update(data)
else {
const axios = require("axios")
const correctmd5 = await axios.get("https://ordr-api.issou.best/dansermd5")
if (correctmd5.data.correctHashes.indexOf(hash.digest("hex")) === -1) {
const { data: data } = await axios.get("https://apis.issou.best/ordr/dansermd5")
if (data.correctHashes.indexOf(hash.digest("hex")) === -1) {
console.log("The version of danser is too old, updating now")
const danserUpdater = require("./danserUpdater")
await danserUpdater()
await danserUpdater(() => {}, data.version)
} else {
startServer()
}
Expand Down
8 changes: 5 additions & 3 deletions files/danserHandler.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ exports.startDanser = async (danserArguments, videoName) => {
isRendering = true

let danserStuckTimeout,
clearedTimeout = false
clearedTimeout = false,
canGetProgress = false
function resetStuckDanserTimeout() {
clearTimeout(danserStuckTimeout)
if (!clearedTimeout) {
Expand All @@ -29,17 +30,18 @@ exports.startDanser = async (danserArguments, videoName) => {
clearTimeout(danserStuckTimeout)
}

danserProcess = spawn(`files/danser/danser`, danserArguments)
danserProcess = spawn("./danser", danserArguments, { cwd: "files/danser" })
const { sendProgression, reportPanic } = require("./server")
danserProcess.stdout.setEncoding("utf8")
danserProcess.stdout.on(`data`, data => {
resetStuckDanserTimeout()
if (data.includes("Progress")) {
if (data.includes("Progress") && canGetProgress) {
if (!config.showFullDanserLogs) {
console.log(data)
}
sendProgression(data)
}
if (data.includes("Starting encoding")) canGetProgress = true
if (data.includes("Finished.")) {
clearDanserStuckTimeout()
console.log(`Rendering done.`)
Expand Down
78 changes: 38 additions & 40 deletions files/danserUpdater.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
const path = require("path")
const wget = require("wget-improved")
const unzipper = require("unzipper")
const fs = require("fs")
const inquirer = require("inquirer")
const config = require(process.cwd() + "/config.json")
const { startServer } = require("./server")
const settingsGenerator = require("./settingsGenerator")
const { exit } = require("./util")
const { asyncDownload, asyncExtract } = require("./util")
const { spawn } = require("child_process")

module.exports = async cb => {
var link
module.exports = async (cb, version) => {
let link, filename
if (process.platform === "win32") {
link = `https://dl.issou.best/ordr/danser-latest-win.zip`
link = `https://github.com/Wieku/danser-go/releases/download/${version}/danser-${version}-win.zip`
filename = `danser-${version}-win.zip`
} else {
link = `https://dl.issou.best/ordr/danser-latest-linux.zip`
link = `https://github.com/Wieku/danser-go/releases/download/${version}/danser-${version}-linux.zip`
filename = `danser-${version}-linux.zip`
}
const output = path.resolve("files/danser/danser.zip")
let download = wget.download(link, output)
download.on("error", err => {
console.log(err)
let { confirmedDownload } = await inquirer.prompt({
name: "confirmedDownload",
type: "confirm",
message: "WARNING: a danser update needs to be made. The o!rdr client will now download external non MIT-licensed binaries. Do you want to proceed?",
default: true
})
download.on("start", fileSize => {
console.log(`Downloading danser at ${link}: ${fileSize} bytes to download...`)
})
download.on("end", () => {
try {
fs.createReadStream(output)
.pipe(
unzipper.Extract({
path: `files/danser`
})
)
.on("close", () => {
console.log(`Finished downloading danser.`)
if (config.id) {
startServer()
} else {
settingsGenerator("new")
}
if (process.platform === "linux") {
fs.chmodSync("files/danser/danser", "755")
}
if (cb) {
cb()
}
})
} catch (err) {
console.log("An error occured while unpacking Danser: " + err)
exit()
if (confirmedDownload) {
const output = path.resolve("files/danser/danser.zip")
await asyncDownload(link, output, filename, "file")
await asyncExtract(output, "files/danser", filename, "file")

if (process.platform === "linux") {
fs.rmSync("files/danser/danser")
fs.renameSync("files/danser/danser-cli", "files/danser/danser")
fs.chmodSync("files/danser/danser", "755")
} else {
fs.rmSync("files/danser/danser.exe")
fs.renameSync("files/danser/danser-cli.exe", "files/danser/danser.exe")
}
})

if (config.id) {
startServer()
} else {
settingsGenerator("new")
}
spawn("./danser", ["-settings=", "-noupdatecheck"], { cwd: "files/danser" }).addListener("exit", () => {
cb()
})
} else {
process.exit(0)
}
}
6 changes: 4 additions & 2 deletions files/dataProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ module.exports = async data => {
danserConfig.Gameplay.HitCounter.Show = data.showHitCounter
danserConfig.Gameplay.AimErrorMeter.Show = data.showAimErrorMeter

danserConfig.Gameplay.StrainGraph.Show = false

if (config.customServer.apiUrl === "") {
danserConfig.Gameplay.PPCounter.Align = "TopLeft"
danserConfig.Gameplay.PPCounter.XPosition = data.elementsPosition.ppCounter.x
Expand Down Expand Up @@ -319,9 +321,9 @@ module.exports = async data => {

danserConfig.Recording.AudioCodec = "aac"
if (data.turboMode) {
danserConfig.Recording.AudioOptions = "-b:a 24k"
danserConfig.Recording.aac.Bitrate = "24k"
} else {
danserConfig.Recording.AudioOptions = "-b:a 192k"
danserConfig.Recording.aac.Bitrate = "160k"
}

await writeDanserConfig(danserConfig)
Expand Down
25 changes: 11 additions & 14 deletions files/firstLaunch.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ module.exports = async () => {
if (!fs.existsSync("files")) fs.mkdirSync(process.cwd() + "/files")
fs.mkdirSync(process.cwd() + "/files/danser")
}
await danserUpdater(() => {
const { data: data } = await axios.get("http://apis.issou.best/ordr/dansermd5")
danserUpdater(() => {
startFirstLaunch()
})
}, data.version)
}

async function startFirstLaunch() {
Expand All @@ -71,7 +72,7 @@ module.exports = async () => {
name: "renderType",
type: "list",
message: "Choose your rendering type:",
choices: ["CPU", "NVIDIA GPU (NVENC)", "AMD GPU (VCE)", "Intel GPU (QSV)"],
choices: ["CPU", "NVIDIA GPU (NVENC)", "Intel GPU (QSV)"],
default: "CPU"
})

Expand Down Expand Up @@ -110,14 +111,6 @@ module.exports = async () => {
confirmed()
})
break
case "AMD GPU (VCE)":
renderingType = "gpu"
config.encoder = "amd"
writeConfig()
settingsGenerator("change", "", false, () => {
confirmed()
})
break
case "Intel GPU (QSV)":
renderingType = "gpu"
config.encoder = "intel"
Expand Down Expand Up @@ -173,7 +166,7 @@ module.exports = async () => {

function startBenchmark() {
var danserArguments = ["-replay", "rawReplays/BENCHMARK-replay-osu_1869933_2948907816.osr", "-record"]
const danser = spawn(`files/danser/danser`, danserArguments)
const danser = spawn("./danser", danserArguments, { cwd: "files/danser" })
var fpsHistory = [],
fps
danser.stdout.setEncoding("utf8")
Expand Down Expand Up @@ -389,10 +382,14 @@ module.exports = async () => {
},
{
name: "ibAccount",
message: "Do you have an issou.best / o!rdr account? If yes, you can enter your username here to link this client instance with it and get rewarded credits for each video recorded. Else, just press enter.",
message: "Do you have an issou.best account? If yes, you can enter your username here to link this client instance with it and get rewarded credits for each video recorded. Else, just press enter.",
default: "Don't have any"
},
{ name: "contact", message: "Please enter a way to contact you (Discord username preferred, to know who you are and set you the Renderer role in the o!rdr Discord server).", default: "No way to contact = rejection :(" }
{
name: "contact",
message: "Please enter your Discord username (make sure to be in the o!rdr Discord server).",
default: "x"
}
]))
}

Expand Down
75 changes: 38 additions & 37 deletions files/settingsGenerator.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
var spawn = require("child_process").spawn
const config = require(process.cwd() + "/config.json")
const fs = require("fs")
const { asyncDownload, asyncExtract } = require("./util")

module.exports = async (type, resolution, turbo, cb) => {
if (type === "new") {
fs.mkdirSync("files/danser/Songs")
fs.mkdirSync("files/danser/Skins", { recursive: true })
fs.mkdirSync("files/danser/rawReplays")
fs.mkdirSync("files/danser/videos")
if (!fs.existsSync("files/danser/Songs")) fs.mkdirSync("files/danser/Songs")
if (!fs.existsSync("files/danser/Skins")) fs.mkdirSync("files/danser/Skins", { recursive: true })
if (!fs.existsSync("files/danser/rawReplays")) fs.mkdirSync("files/danser/rawReplays")
if (!fs.existsSync("files/danser/videos")) fs.mkdirSync("files/danser/videos")
} else if (type === "change") {
if (config.usingOsuApi) {
if (!fs.existsSync("files/danser/api.txt")) {
fs.writeFileSync("files/danser/api.txt", config.osuApiKey, "utf-8", err => {
if (err) throw err
})
}
const currentApi = fs.readFileSync("files/danser/api.txt", "utf-8")
if (currentApi !== config.osuApiKey) {
fs.writeFileSync("files/danser/api.txt", config.osuApiKey, "utf-8", err => {
const danserCredentials = require(process.cwd() + "/files/danser/settings/credentials.json")
if (danserCredentials.ApiV1Key !== config.osuApiKey) {
danserCredentials.ApiV1Key = config.osuApiKey
fs.writeFileSync("files/danser/settings/credentials.json", JSON.stringify(danserCredentials, null, 1), "utf-8", err => {
if (err) throw err
})
}
}

if (!fs.existsSync("files/danser/Skins/default_fallback")) {
await asyncDownload("https://dl.issou.best/ordr/default_fallback_skin.zip", "files/danser/Skins/default_fallback.zip", "default_fallback_skin", "skin")
await asyncExtract("files/danser/Skins/default_fallback.zip", "files/danser/Skins/default_fallback", "default_fallback", "skin")
}

if (fs.existsSync(`${process.cwd()}/files/danser/settings/default.json`)) {
await fs.promises.unlink(`${process.cwd()}/files/danser/settings/default.json`, err => {
if (err) throw err
})
}
// using -settings= argument to not trigger the rickroll
var danserArguments = ["-settings="]
spawn("files/danser/danser", danserArguments).addListener("exit", () => {
spawn("./danser", ["-settings=", "-noupdatecheck"], { cwd: "files/danser" }).addListener("exit", () => {
const danserConfig = require(process.cwd() + "/files/danser/settings/default.json")
function writeDanserConfig() {
fs.writeFileSync("files/danser/settings/default.json", JSON.stringify(danserConfig, null, 1), "utf-8", err => {
Expand All @@ -47,46 +49,45 @@ module.exports = async (type, resolution, turbo, cb) => {
case "cpu":
danserConfig.Recording.Encoder = "libx264"
if (turbo) {
danserConfig.Recording.EncoderOptions = "-crf 51 -g 450"
danserConfig.Recording.Preset = "ultrafast"
danserConfig.Recording.libx264.CRF = 51
danserConfig.Recording.libx264.Preset = "ultrafast"
danserConfig.Recording.libx264.AdditionalOptions = "-g 450"
} else {
danserConfig.Recording.EncoderOptions = "-crf 21 -g 450"
danserConfig.Recording.Preset = "faster"
danserConfig.Recording.libx264.CRF = 21
danserConfig.Recording.libx264.Preset = "faster"
danserConfig.Recording.libx264.AdditionalOptions = "-g 450"
}
break
case "nvidia":
danserConfig.Recording.Encoder = "h264_nvenc"
if (turbo) {
danserConfig.Recording.EncoderOptions = "-rc constqp -qp 51 -g 450"
danserConfig.Recording.Preset = "p1"
} else {
danserConfig.Recording.EncoderOptions = "-rc constqp -qp 26 -g 450"
danserConfig.Recording.Preset = "p7"
}
break
case "amd":
danserConfig.Recording.Encoder = "h264_amf"
if (turbo) {
danserConfig.Recording.EncoderOptions = "-rc cqp -qp_p 51 -qp_i 51 -quality speed"
danserConfig.Recording.Preset = "slow"
danserConfig.Recording.h264_nvenc.RateControl = "cqp"
danserConfig.Recording.h264_nvenc.CQ = 51
danserConfig.Recording.h264_nvenc.Preset = "p1"
danserConfig.Recording.h264_nvenc.AdditionalOptions = "-g 450"
} else {
danserConfig.Recording.EncoderOptions = "-rc cqp -qp_p 17 -qp_i 17 -quality quality"
danserConfig.Recording.Preset = "slow" // H264_amf doesn't support -preset, instead using -quality (for some reason), keeping preset so it doesn't break anything
danserConfig.Recording.h264_nvenc.RateControl = "cqp"
danserConfig.Recording.h264_nvenc.CQ = 26
danserConfig.Recording.h264_nvenc.Preset = "p7"
danserConfig.Recording.h264_nvenc.AdditionalOptions = "-g 450"
}
break
case "intel":
danserConfig.Recording.Encoder = "h264_qsv"
if (turbo) {
danserConfig.Recording.EncoderOptions = "-global_quality 51 -g 450"
danserConfig.Recording.Preset = "veryfast"
danserConfig.Recording.h264_qsv.ICQ = 51
danserConfig.Recording.h264_qsv.Preset = "veryfast"
danserConfig.Recording.h264_qsv.AdditionalOptions = "-g 450"
} else {
// -global_quality was 31 before and looked okay-ish on 1080p but very bad on 720p
if (resolution === "1920x1080" || resolution === "3840x2160") {
danserConfig.Recording.EncoderOptions = "-global_quality 28 -g 450"
danserConfig.Recording.h264_qsv.Quality = 28
danserConfig.Recording.h264_qsv.AdditionalOptions = "-g 450"
} else {
danserConfig.Recording.EncoderOptions = "-global_quality 25 -g 450"
danserConfig.Recording.h264_qsv.Quality = 25
danserConfig.Recording.h264_qsv.AdditionalOptions = "-g 450"
}
danserConfig.Recording.Preset = "veryslow"
danserConfig.Recording.h264_qsv.Preset = "veryslow"
}
break
}
Expand Down

0 comments on commit 6c95abb

Please sign in to comment.