Advertisement
Brick

Burnout Paradise 64-bit ID Encode/Decode

Sep 27th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.54 KB | None | 0 0
  1. static constexpr const uint8_t BurnoutID_EncodeTable[256] =
  2. {
  3.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  4.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02,
  6.     0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12,
  7.     0x13, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B,
  8.     0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x00, 0x00, 0x00, 0x27,
  9.     0x00, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B,
  10.     0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x00, 0x00, 0x00, 0x00,
  11.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  13.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  15.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  16.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  17.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19. };
  20.  
  21. uint64_t EncodeBurnoutID(const char* string)
  22. {
  23.     uint64_t result = 0;
  24.  
  25.     size_t i = 0;
  26.  
  27.     for (; i < 12; ++i)
  28.     {
  29.         const uint8_t c = static_cast<uint8_t>(string[i]);
  30.  
  31.         if (!c)
  32.         {
  33.             break;
  34.         }
  35.  
  36.         result *= 40;
  37.         result += BurnoutID_EncodeTable[c];
  38.     }
  39.  
  40.     for (; i < 12; ++i)
  41.     {
  42.         result *= 40;
  43.     }
  44.  
  45.     return result;
  46. }
  47.  
  48. static constexpr const char BurnoutID_DecodeTable[40 + 1] = " -/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  49.  
  50. void DecodeBurnoutID(char (&buffer)[13], uint64_t id)
  51. {
  52.     for (size_t i = 12; i--;)
  53.     {
  54.         buffer[i] = BurnoutID_DecodeTable[id % 40];
  55.         id /= 40;
  56.     }
  57.  
  58.     buffer[12] = 0;
  59.  
  60.     for (size_t i = 12; i--;)
  61.     {
  62.         if (buffer[i] == ' ')
  63.         {
  64.             buffer[i] = '\0';
  65.         }
  66.         else
  67.         {
  68.             break;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement