RoSniperX

frontend launcher hijack mobile stream sniper

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         RoSniperX
// @namespace    http://tampermonkey.net/
// @version      6.2
// @description  frontend launcher hijack mobile stream sniper
// @author       Lukas Dobbles
// @match        https://www.roblox.com/*
// @grant        none
// ==/UserScript==

(function () {
"use strict";

const sleep = (ms) => new Promise(r => setTimeout(r, ms));

const getJSON = async (url, args = {}) => {
    args.headers = args.headers || {};
    args.credentials = "include";

    let retries = 5;

    while (retries--) {
        try {
            const res = await fetch(url, args);

            if (res.status === 429) {
                await sleep(2000);
                continue;
            }

            return await res.json();
        } catch (e) {
            if (retries <= 0) throw e;
            await sleep(1500);
        }
    }
};

const search = async (placeId, name, setStatus, cb, setThumb) => {
    try {
        const userId = await getUserId(name);

        if (!userId) {
            setStatus("User not found.");
            cb({ found: false });
            return;
        }

        const thumbUrl = await getThumb(userId);
        setThumb(thumbUrl);
        setStatus("Target avatar loaded...");

        let cursor = null;
        let serverQueue = [];
        let serversScraped = 0;
        let playersScraped = 0;
        const startTime = Date.now();

        do {
            const servers = await getServer(placeId, cursor);
            if (!servers || !servers.data) break;

            for (const place of servers.data) {
                serversScraped++;
                if (place.playerTokens && place.playerTokens.length) {
                    playersScraped += place.playerTokens.length;
                    for (const token of place.playerTokens) {
                        serverQueue.push({ token, place });
                    }
                }
            }

            cursor = servers.nextPageCursor;
            setStatus(`Scanned ${serversScraped} servers / ${playersScraped} players`);
            await sleep(700);

        } while (cursor);

        setStatus(`Comparing ${serverQueue.length} player thumbnails...`);

        let checked = 0;

        while (serverQueue.length > 0) {
            const batch = serverQueue.splice(0, 100);

            try {
                const thumbs = await fetchThumbs(batch.map(x => x.token));
                if (!thumbs || !thumbs.data) {
                    await sleep(1000);
                    continue;
                }

                checked += batch.length;
                setStatus(`Compared ${checked}/${playersScraped} thumbnails...`);

                for (const thumb of thumbs.data) {
                    if (!thumb || !thumb.imageUrl) continue;

                    if (thumb.imageUrl === thumbUrl) {
                        const thumbToken = thumb.requestId.split(":")[1];
                        const matchedPlace = batch.find(x => x.token === thumbToken)?.place;

                        if (matchedPlace) {
                            setStatus(`FOUND TARGET after ${(Date.now() - startTime) / 1000}s`);
                            cb({ found: true, place: matchedPlace });
                            return;
                        }
                    }
                }

                await sleep(500);

            } catch {
                await sleep(1000);
            }
        }

        cb({ found: false });

    } catch (e) {
        setStatus("Search failed: " + e);
        cb({ found: false });
    }
};

const getUserId = (name) =>
getJSON("https://users.roblox.com/v1/usernames/users", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
        usernames: [name],
        excludeBannedUsers: true
    })
}).then(d => d?.data?.[0]?.id);

const getThumb = (id) =>
getJSON(`https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${id}&format=Png&size=150x150`)
.then(d => d.data[0].imageUrl);

const getServer = (placeId, cursor) => {
    let url = `https://games.roblox.com/v1/games/${placeId}/servers/Public?limit=100`;
    if (cursor) url += "&cursor=" + cursor;
    return getJSON(url);
};

const fetchThumbs = (tokens) => {
    const body = tokens.map(token => ({
        requestId: `0:${token}:AvatarHeadshot:150x150:png:regular`,
        type: "AvatarHeadShot",
        token,
        format: "png",
        size: "150x150"
    }));

    return getJSON("https://thumbnails.roblox.com/v1/batch", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            Accept: "application/json"
        },
        body: JSON.stringify(body)
    });
};

const hijackLaunchAndJoin = async (targetGameId, setStatus) => {
    try {
        setStatus("Installing launcher capture hooks...");

        let captured = null;

        const captureUrl = (u) => {
            if (typeof u === "string" && u.includes("robloxmobile://")) {
                captured = u;
                return true;
            }
            return false;
        };

        const oldOpen = window.open;
        window.open = function(url) {
            if (captureUrl(url)) return null;
            return oldOpen.apply(this, arguments);
        };

        const oldClick = HTMLElement.prototype.click;
        HTMLElement.prototype.click = function() {
            try {
                if (this.href && captureUrl(this.href)) return;
            } catch {}
            return oldClick.apply(this, arguments);
        };

        const oldFetch = window.fetch;
        window.fetch = async function() {
            const res = await oldFetch.apply(this, arguments);
            try {
                const clone = res.clone();
                const txt = await clone.text();
                const match = txt.match(/robloxmobile:\/\/[^\s"'<>]+/);
                if (match) captured = match[0];
            } catch {}
            return res;
        };

        const observer = new MutationObserver(() => {
            document.querySelectorAll("a[href^='robloxmobile://']").forEach(a => {
                if (!captured) captured = a.href;
            });
        });

        observer.observe(document.documentElement, {
            childList: true,
            subtree: true
        });

        const playBtn =
            document.querySelector('[data-testid="play-button"]') ||
            document.querySelector('.btn-common-play-game-lg') ||
            document.querySelector('.game-play-button') ||
            document.querySelector('#game-detail-play-button') ||
            document.querySelector('button[data-testid="game-play-button"]');

        if (!playBtn) {
            setStatus("Could not locate Roblox Play button.");
            return;
        }

        setStatus("Triggering Roblox trusted play...");
        playBtn.click();

        let waited = 0;
        while (!captured && waited < 15000) {
            await sleep(500);
            waited += 500;
            document.querySelectorAll("a[href*='robloxmobile://']").forEach(a => {
                if (!captured) captured = a.href;
            });
        }

        observer.disconnect();
        window.open = oldOpen;
        HTMLElement.prototype.click = oldClick;
        window.fetch = oldFetch;

        if (!captured) {
            setStatus("Failed to capture launcher URI.");
            return;
        }

        setStatus("Captured launcher. Injecting target server...");

        let finalUrl = captured;

        if (/gameInstanceId=/i.test(finalUrl)) {
            finalUrl = finalUrl.replace(/gameInstanceId=([^&]+)/i, `gameInstanceId=${targetGameId}`);
        } else if (/gameid=/i.test(finalUrl)) {
            finalUrl = finalUrl.replace(/gameid=([^&]+)/i, `gameid=${targetGameId}`);
        } else {
            finalUrl += `&gameInstanceId=${targetGameId}`;
        }

        setStatus("Launching target exact server...");
        window.location.href = finalUrl;

    } catch (e) {
        setStatus("Launch hijack failed: " + e);
    }
};

const instancesContainer = document.getElementById("running-game-instances-container");

if (instancesContainer) {
    const containerHeader = document.createElement("div");
    containerHeader.id = "rosniperx";

    const headerText = document.createElement("h2");
    headerText.innerText = "RoSniperX";
    containerHeader.appendChild(headerText);

    const form = document.createElement("form");

    const thumbImage = document.createElement("img");
    thumbImage.height = "40";
    thumbImage.style.display = "none";
    containerHeader.appendChild(thumbImage);

    const usernameInput = document.createElement("input");
    usernameInput.classList = "input-field";
    usernameInput.placeholder = "Username";
    form.appendChild(usernameInput);

    const submitButton = document.createElement("button");
    submitButton.classList = "btn-primary-md";
    submitButton.innerText = "Search";
    submitButton.disabled = true;
    form.appendChild(submitButton);

    usernameInput.addEventListener("keyup", e => {
        submitButton.disabled = e.target.value.length === 0;
    });

    const statusText = document.createElement("p");
    form.appendChild(statusText);

    const joinBtn = document.createElement("button");
    joinBtn.style.display = "none";
    joinBtn.innerText = "Join Exact Server";
    joinBtn.classList = "btn-control-xs btn-primary-md";

    containerHeader.appendChild(form);
    containerHeader.appendChild(joinBtn);

    instancesContainer.insertBefore(containerHeader, instancesContainer.firstChild);

    form.addEventListener("submit", evt => {
        evt.preventDefault();
        joinBtn.style.display = "none";

        const placeId = location.href.match(/games\/(\d+)/)?.[1];

        search(
            placeId,
            usernameInput.value,
            txt => statusText.innerText = txt,
            place => {
                if (!place.found) {
                    statusText.innerText = "Couldn't find them after full scan.";
                    return;
                }

                joinBtn.style.display = "";

                joinBtn.onclick = () => {
                    hijackLaunchAndJoin(place.place.id, txt => statusText.innerText = txt);
                };
            },
            src => {
                thumbImage.src = src;
                thumbImage.style.display = "";
            }
        );
    });
}
})();