,"acmp3ts":False,"acwm":"maybe","acwmts":False,"ocpt":False,"vco":"","vcots":False,"vch":"probably","vchts":True,"vcw":"probably","vcwts":True,"vc3":"maybe","vc3ts":False,"vcmp":"","vcmpts":False,"vcq":"maybe","vcqts":False,"vc1":"probably","vc1ts":True,"dvm":8,"sqt":False,"so":"landscape-primary","bda":False,"wdw":True,"prm":True,"tzp":True,"cvs":True,"usb":True,"cap":True,"tbf":False,"lgs":True,"tpd":True
        }),
        'eventCounters': '[]',
        'jsType': 'ch',
        'cid': 'KOWn3t9QNk3dJJJEkpZJpspfb2HPZIVs0KSR7RYTscx5iO7o84cw95j40zFFG7mpfbKxmfhAOs~bM8Lr8cHia2JZ3Cq2LAn5k6XAKkONfSSad99Wu36EhKYyODGCZwae',
        'ddk': 'AE3F04AD3F0D3A462481A337485081',
        'Referer': 'https://account.garena.com/',
        'request': '/',
        'responsePage': 'origin',
        'ddv': '4.35.4'
    }
    data = '&'.join(f'{k}={urllib.parse.quote(str(v))}' for k, v in payload.items())
    try:
        response = session.post(url, headers=headers, data=data)
        response.raise_for_status()  # Raise an exception for HTTP errors
        response_json = response.json()
        if response_json['status'] == 200 and 'cookie' in response_json:  # Check the response status and if cookie is present
            cookie_string = response_json['cookie']
            datadome = cookie_string.split(';')[0].split('=')[1]
            logging.info(f"Successfully retrieved datadome: {datadome}")  # Log success
            return datadome
        else:
            logging.error(f"Error Status code: {response_json['status']}")  # Log error if status is not 200
            logging.error(f"Response: {response.text[:200]}...")  # Log the first 200 characters of the response for debugging
            return None
    except requests.exceptions.RequestException as e:  # Catch any request-related errors (e.g., network issues)
        logging.error(f"Error getting DataDome cookie: {e}")  # Log request exceptions
        return None
    except Exception as e:  # Catch any other exceptions
        logging.error(f"Unexpected error: {e}")  # Log unexpected errors
        return None
def prelogin(session, account):
    url = 'https://sso.garena.com/api/prelogin'
    params = {
        'app_id': '10100',
        'account': account,
        'format': 'json',
        'id': str(int(time.time() * 1000))
    }
    headers = {
        'accept': 'application/json, text/plain, */*',
        'accept-encoding': 'gzip, deflate, br, zstd',
        'accept-language': 'en-US,en;q=0.9',
        'cache-control': 'no-cache',
        'connection': 'keep-alive',
        'host': 'sso.garena.com',
        'pragma': 'no-cache',
        'referer': 'https://sso.garena.com/universal/login?app_id=10100&redirect_uri=https%3A%2F%2Faccount.garena.com%2F&locale=en-PH',
        'sec-ch-ua': '"Chromium";v="130", "Microsoft Edge";v="130", "Not?A_Brand";v="99"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0'
    }
    try:
        response = session.get(url, headers=headers, params=params)
        response.raise_for_status()  # Raise an exception for HTTP errors
        data = response.json()
        new_datadome = response.cookies.get('datadome')  # Retrieve the 'datadome' cookie
        if 'error' in data:  # Check for any error in the response data
            logging.error(f"{Fore.RED}[ERROR]{Style.RESET_ALL} {account}: {data['error']}")
            return None, None, new_datadome  # Return None for v1, v2 on error
        logging.info(f"{Fore.GREEN}[INFO]{Style.RESET_ALL} Prelogin successful for {account}")
        return data.get('v1'), data.get('v2'), new_datadome  # Return v1, v2 and the new datadome cookie