Skip to content

Commit

Permalink
Add instant join button
Browse files Browse the repository at this point in the history
  • Loading branch information
6ixfalls committed Jan 23, 2022
1 parent a5fc658 commit b047ebe
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 60 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ let configCorrupt = false;
let configJSON = global.configJSON = {
defaultIconKey: "logo_shiny", // logo_old, logo_red, logo_shiny
enabled: true,
studioEnabled: true
studioEnabled: true,
bypassPrivacy: false,
};
if (fs.existsSync(configFile)) {
try {
Expand Down Expand Up @@ -51,6 +52,14 @@ global.rpc.on("ready", async () => {
configJSON.enabled = !configJSON.enabled;
contextMenu.items[0].checked = configJSON.enabled;
saveConfig();
},
},
{
label: "Bypass Privacy Settings", type: "checkbox", checked: configJSON.bypassPrivacy, click: function () {
log.info("Toggling privacy bypass");
configJSON.bypassPrivacy = !configJSON.bypassPrivacy;
contextMenu.items[1].checked = configJSON.bypassPrivacy;
saveConfig();
}
},
{ type: "separator" },
Expand Down
52 changes: 2 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 48 additions & 8 deletions richPresence.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const express = require("express");
const { json } = require("body-parser");

let CachedProcess;
let joinButtonRetry;
let CachedIcons = {};

async function getGameFromCache(gameid) {
Expand Down Expand Up @@ -200,20 +201,58 @@ async function BeginListener() {

log.info("Playing", game.name, "by", game.by);
global.tray.setTitle(game.name, "by", game.by);

var redeem = await fetch('https://auth.roblox.com/v1/authentication-ticket/redeem', { method: 'POST', headers: { "RBXAuthenticationNegotiation": "https://github.com/6ixfalls/RPresence", "Content-Type": "application/json" }, body: JSON.stringify({ authenticationTicket: util.getTicket(proc.arguments) }) });
var ROBLOSECURITY = util.getSecurityCookie(redeem.headers.raw()['set-cookie']);
var userId = await fetch(`https://users.roblox.com/v1/users/authenticated`, { headers: { Cookie: ROBLOSECURITY } });
var userData = await userId.json();

var startTimestamp = + new Date();

joinButtonRetry = setInterval(async () => {
var gameInfoHeaders = { 'Content-Type': "application/json" };

if (global.configJSON.bypassPrivacy) {
gameInfoHeaders['Cookie'] = ROBLOSECURITY;
}

var gameInfo = await fetch(`https://presence.roblox.com/v1/presence/users`, {
method: 'POST',
headers: gameInfoHeaders,
body: `{"userIds":[${userData.id}]}`
});
var gameInfoResponse = await gameInfo.json();

if (gameInfoResponse.userPresences) {
var gameInfoData = gameInfoResponse.userPresences[0];

if (gameInfoData.gameId && gameInfoData.lastLocation) {
rpc.setActivity({
details: game.name,
state: `by ${game.by}`,
startTimestamp: startTimestamp,
largeImageKey: game.iconkey,
buttons: [{
label: "Join Game",
url: `https://xiva.xyz/RPresence/?placeID=${game.id}&gameInstanceID=${gameInfoData.gameId}&gameName=${encodeURIComponent(game.name)}`
}],
instance: false
});

log.info("Found join url: " + `https://xiva.xyz/RPresence/?placeID=${game.id}&gameInstanceID=${gameInfoData.gameId}&gameName=${encodeURIComponent(game.name)}`);

clearInterval(joinButtonRetry);
}
}
}, 10000);

rpc.setActivity({
details: game.name,
state: `by ${game.by}`,
startTimestamp: + new Date(),
startTimestamp: startTimestamp,
largeImageKey: game.iconkey,
buttons: [
{
label: "Join Game",
url: "https://www.roblox.com/games/" + (game.id || game.iconkey)
}
],
instance: false
});

CachedProcess = pid;
} else {
log.info("Started process was not Roblox");
Expand All @@ -224,6 +263,7 @@ async function BeginListener() {
} else if (data.type == "deletion") {
if (CachedProcess == pid) {
CachedProcess = undefined;
clearInterval(joinButtonRetry);
rpc.clearActivity();
global.tray.setTitle("");
log.info("[Detect:Proc] Process with PID " + pid + " has been closed");
Expand Down
21 changes: 20 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ function getProcesses(args) {
return new Promise((a, r) => ps.lookup(args, (err, data) => (err ? r : a)(data)));
}

function getTicket(arg) {
var lastArg;
for (let argument of arg) {
if (lastArg == "-t") {
return argument;
}

lastArg = argument;
}
return false;
}
function getScriptUrl(arg) {
for (let argument of arg) {
if (argument.startsWith("https://") && argument.includes("placeId=")) {
Expand All @@ -13,8 +24,16 @@ function getScriptUrl(arg) {
}
return false;
}
function getSecurityCookie(arg) {
for (let argument of arg) {
if (argument.startsWith(".ROBLOSECURITY=") && argument.includes("HttpOnly")) {
return argument.split(";")[0];
}
}
return false;
}
function getActiveWindow() {
return new Promise((a, r) => activeWindow.getActiveWindow(a, 0, 0));
}

module.exports = { getProcesses, getScriptUrl, getActiveWindow };
module.exports = { getProcesses, getTicket, getScriptUrl, getSecurityCookie, getActiveWindow };

0 comments on commit b047ebe

Please sign in to comment.