Roblox CDN, How do I know which one to use?

Hi, I am trying to use the api https://thumbnails.roblox.com/docs#!/Avatar/get_v1_users_avatar_3d however it returns https://t2.rbxcdn.com/ef63c826300347dde39b499e56bc874b and then those values returned in the form of text for example.

{"camera":{"position":{"x":-2.61652,"y":105.715,"z":-4.94401},"direction":{"x":-0.40558,"y":0.40558,"z":-0.819152},"fov":70.0},"aabb":{"min":{"x":-2.46031,"y":100.01,"z":-1.03069},"max":{"x":2.36335,"y":106.331,"z":1.285}},"mtl":"58f8c8dfcad7ad36d17e1773a698223e","obj":"4844b24bb4b6696ccbafda0c79d2c406","textures":["21e00b04dc20ddc07659af859d4c1eaa"]}

the OBJ file comes in the format 4844b24bb4b6696ccbafda0c79d2c406 now what CDN does that come from. If you said the same as the origin (https://t2.rbxcdn.com/) you are wrong it comes form https://t4.rbxcdn.com/4844b24bb4b6696ccbafda0c79d2c406

This subdomain varies from player to player for OBJs and MTL files, so is there a API to tell me what the correct subdomain is? Or am I going mad? Please Help??

– Gerald

3 Likes

If you want to solve this problem without sending a request or looping through all CDNs, this trick works.

Here’s a little JavaScript code snippet that’ll do the job:

function get(hash) {
    for (var i = 31, t = 0; t < 32; t++)
        i ^= hash[t].charCodeAt(0);
    return `https://t${(i % 8).toString()}.rbxcdn.com/${hash}`;
}

and the same thing in Python:

def get(hash):
    i = 31
    for char in hash[:32]:
        i ^= ord(char)  # i ^= int(char, 16) also works
    return f"https://t{i%8}.rbxcdn.com/{hash}"

It creates a variable i with a value of 31, iterates through the first 32 characters of the string, and, on each iteration, sets i to itself Bitwise XORed against the integer representation of that character (or, alternatively, just the integer version of the hex value with int(char, 16) if you prefer it - as far as I can tell, it works in the same way)

Thanks to @juliaoverflow for helping me with the same problem three months ago.

9 Likes

Thanks so much, I wish this was documented somewhere, this saved so much time thanks.

1 Like

Hello, roblox has done it again and updated stuff!!

Updated solution as of 06/12/23 (I am british so I use the better date system)

Happy Coding
– Gerald :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.