Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # GW2 Item/Recipe ID Toolkit
- # Authored by Reddit user NotTheHead
- # On December 24, 2013
- #
- # It should be noted that much of the error checking that could be
- # included is left out for simplicity's sake. Don't use negative
- # numbers or zero and you should be fine.
- from base64 import *
- def GetRecipeCode(recipe_id):
- """Using a Recipe's ID, create a chat code you can share in-game.
- Parameters:
- recipe_id -- The ID of the recipe to create a chat code for.
- Returns:
- A string containing the chat code to type in-game.
- """
- hexa = '\x09'
- for i in range(4): #For both Python 3 and 2.
- #Little endian format
- hexa += chr(recipe_id % 256)
- recipe_id /= 256
- return '[&' + b64encode(hexa) + ']'
- def GetItemCode(item_id, num_items=1):
- """Using an Item's ID, create a chat code you can share in-game.
- Parameters:
- item_id -- The ID of the item to create a chat code for.
- Returns:
- A string containing the chat code to type in-game.
- """
- hexa = '\x02' + chr(num_items)
- for i in range(4): #For both Python 3 and 2.
- #Little endian format
- hexa += chr(item_id % 256)
- item_id /= 256
- return '[&' + b64encode(hexa) + ']'
- def GetChatCodeB64(chat_code):
- """Strips the [& and ] off of the chat code, if they are on the
- chat code at all.
- Parameters:
- chat_code -- The chat code to be processed.
- Returns:
- A string containing the chat code's b64 portion without the
- containing braces.
- """
- if chat_code[0] == '[':
- chat_code = chat_code[1:]
- if chat_code[0] == '&':
- chat_code = chat_code[1:]
- if chat_code[-1] == ']':
- chat_code = chat_code[:-1]
- return chat_code
- def GetRecipeID(chat_code):
- """Using a Recipe's chat code, retrieve the Recipe's ID.
- WARNING: Do not use the chat code given in-game. As of the writing
- of this code, those item codes are wrong. They use an incorrect
- header, and some give the wrong ID as well.
- Parameters:
- chat_code -- The chat code of the recipe.
- Returns:
- The recipe's ID in numerical form.
- """
- hexa = b64decode(GetChatCodeB64(chat_code))[1:] #Remove header
- decimal = 0
- for byte in reversed(hexa): #Little endian format
- decimal *= 256
- decimal += ord(byte)
- return decimal
- def GetItemID(chat_code):
- """Using an Item's chat code, retrieve the Recipe's ID.
- Parameters:
- chat_code -- The chat code of the item.
- Returns:
- The item's ID in numerical form.
- """
- hexa = b64decode(GetChatCodeB64(chat_code))[2:] #Remove header
- decimal = 0
- for byte in reversed(hexa): #Little endian format
- decimal *= 256
- decimal += ord(byte)
- return decimal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement