Lymia

MiscPeripheral token algorithm (OLD!)

Feb 13th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. private static NBTTagCompound keyNbtTag = null;
  2.  
  3. public static int generateStackToken(ItemStack theStack, World worldp) {
  4.   if ((worldp == null) || (!(worldp instanceof WorldServer)))
  5.     throw new IllegalStateException("Item UUID encoding failed due to the world being null. Please report this!");
  6.  
  7.   WorldServer world = (WorldServer) worldp;
  8.  
  9.   String itemIdXorKey     = "a";
  10.   String itemDamageXorKey = "b";
  11.  
  12.   String idKeyA = "c";
  13.   String idKeyB = "d";
  14.   String idKeyC = "e";
  15.  
  16.   if (keyNbtTag == null) {
  17.     File keyFile = new File(world.getChunkSaveLocation(), "iuuidk.dat");
  18.     if (keyFile.exists()) {
  19.       try {
  20.         keyNbtTag = CompressedStreamTools.read(keyFile);
  21.       } catch (Throwable e) {
  22.         keyNbtTag.printStackTrace();
  23.         throw new IllegalStateException("Corrupted world UUID keys, please report this!");
  24.       }
  25.     } else {
  26.       keyNbtTag = new NBTTagCompound();
  27.       // RichardG867 is immature, Exhibit A
  28.       keyNbtTag.setByte("IF_YOURE_WILLING_TO_CHEAT_GO_AHEAD", 0);
  29.  
  30.       keyNbtTag.setShort(itemIdXorKey    , (short)world.rand.nextInt(32768));
  31.       keyNbtTag.setShort(itemDamageXorKey, (short)world.rand.nextInt(32768));
  32.  
  33.       keyNbtTag.setInteger(idKeyA, Math.abs(world.rand.nextInt()));
  34.       keyNbtTag.setInteger(idKeyB, Math.abs(world.rand.nextInt()));
  35.       keyNbtTag.setInteger(idKeyC, Math.abs(world.rand.nextInt()));
  36.  
  37.       try {
  38.         CompressedStreamTools.write(keyNbtTag, keyFile);
  39.       } catch (Throwable e) {
  40.         throw new IllegalStateException("Corrupted world UUID keys, please report this!");
  41.       }
  42.     }
  43.   }
  44.  
  45.   // RichardG867 is immature, Exhibit B
  46.   String[] DIE_IN_A_FIRE = { "You are breaking the fun for other people who want to play this legit. Please go away." };
  47.  
  48.   short itemDamage            = (theStack.getItem() != null) && (theStack.getItem().isDamageable()) ? 0 : theStack.getItemDamage();
  49.  
  50.   short obfusicatedItemId     = (short) (theStack.itemID ^ keyNbtTag.getShort(itemIdXorKey));
  51.   short obfusicatedItemDamage = (short) (itemDamage ^ keyNbtTag.getShort(itemDamageXorKey));
  52.  
  53.   int   itemIdentifier        = obfusicatedItemId * 32768 + obfusicatedItemDamage;
  54.  
  55.   int   idKey                 = keyNbtTag.getInteger(idKeyA) ^ keyNbtTag.getInteger(idKeyB) ^ keyNbtTag.getInteger(idKeyC);
  56.  
  57.   return itemIdentifier ^ idKey;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment