""" Original code by frms. on discord / shr2mp on roblox """ """ wow we need to clean up a lot. """ import requests import json import uuid def get_game_instance_data(cookie, place_id, game_id): url = "https://gamejoin.roblox.com/v1/join-game-instance" headers = { "Host": "gamejoin.roblox.com", "Accept": "*/*", "Cookie": f".ROBLOSECURITY={cookie}", "Cache-Control": "no-cache", "User-Agent": "Roblox/DarwinRobloxApp/0.663.0.6630659 (GlobalDist; RobloxDirectDownload)", "Content-Type": "application/json", "PlayerCount": "0", "Requester": "Client", "Pragma": "no-cache" } payload = { "placeId": place_id, "gameId": game_id, "isPlayTogetherGame": False, "gameJoinAttemptId": str(uuid.uuid4()) } try: response = requests.post(url, headers=headers, json=payload) response.raise_for_status() data = response.json() join_script = data.get("joinScript", {}) analytics_session_id = join_script.get("AnalyticsSessionId") universe_id = join_script.get("UniverseId") game_id = join_script.get("GameId") place_id = join_script.get("PlaceId") if not analytics_session_id and isinstance(data.get("SessionId"), str): session_data = json.loads(data["SessionId"]) analytics_session_id = session_data.get("SessionId") universe_id = session_data.get("UniverseId") game_id = session_data.get("GameId") place_id = session_data.get("PlaceId") return { "AnalyticsSessionId": analytics_session_id, "UniverseId": universe_id, "GameId": game_id, "PlaceId": place_id } except requests.exceptions.RequestException as e: print("Request failed:", e) return None def get_collectible_details(cookie, item_id): url = f"https://economy.roblox.com/v2/assets/{item_id}/details" headers = { "Host": "economy.roblox.com", "Accept": "application/json", "Cookie": f".ROBLOSECURITY={cookie}", "Cache-Control": "no-cache", "User-Agent": "Roblox/DarwinRobloxApp/0.663.0.6630659 (GlobalDist; RobloxDirectDownload)" } try: response = requests.get(url, headers=headers) response.raise_for_status() data = response.json() return { "CollectibleItemId": data.get("CollectibleItemId"), "CollectibleProductId": data.get("CollectibleProductId") } except requests.exceptions.RequestException as e: print("Request failed:", e) return None def get_game_id_from_presence(cookie, user_id): url = "https://presence.roblox.com/v1/presence/users" headers = { "Host": "presence.roblox.com", "Accept": "application/json", "Cookie": f".ROBLOSECURITY={cookie}", "Cache-Control": "no-cache", "User-Agent": "Roblox/DarwinRobloxApp/0.663.0.6630659 (GlobalDist; RobloxDirectDownload)", "Content-Type": "application/json" } payload = { "userIds": [user_id] } try: response = requests.post(url, headers=headers, json=payload) response.raise_for_status() data = response.json() user_presences = data.get("userPresences", []) if user_presences: return user_presences[0].get("gameId") print("User is not in a game.") return None except requests.exceptions.RequestException as e: print("Request failed:", e) return None def purchase_item(cookie, collectible_item_id, collectible_product_id, analytics_session_id, price, user_id, place_id, universe_id, game_id): url = f"https://apis.roblox.com/marketplace-sales/v1/item/{collectible_item_id}/purchase-item" headers = { "Host": "apis.roblox.com", "Accept": "application/json", "Cookie": f".ROBLOSECURITY={cookie}", "Cache-Control": "no-cache", "User-Agent": "Roblox/DarwinRobloxApp/0.663.0.6630659 (GlobalDist; RobloxDirectDownload)", "Roblox-Place-Id": str(place_id), "Roblox-Universe-Id": str(universe_id), "Roblox-Game-Id": str(game_id), "PlayerCount": "5", "Requester": "Client" } payload = { "expectedCurrency": 1, "expectedPrice": price, "expectedPurchaserId": user_id, "expectedPurchaserType": "User", "collectibleProductId": collectible_product_id, "idempotencyKey": analytics_session_id, "purchaseAuthToken": "" } try: response = requests.post(url, headers=headers, json=payload) if response.status_code == 403 and "x-csrf-token" in response.headers: csrf_token = response.headers["x-csrf-token"] headers["x-csrf-token"] = csrf_token response = requests.post(url, headers=headers, json=payload) return response.json() except requests.exceptions.RequestException as e: print("Request failed:", e) return None server_id = get_game_id_from_presence(cookie, user_id) server_result = get_game_instance_data(cookie, place_id, server_id) item_result = get_collectible_details(cookie, item_id) if server_result and item_result: purchase_result = purchase_item( cookie, item_result["CollectibleItemId"], item_result["CollectibleProductId"], server_result["AnalyticsSessionId"], price, user_id, server_result["PlaceId"], server_result["UniverseId"], server_result["GameId"] ) print("Purchase Result:", purchase_result)