SHARE
TWEET

Untitled

a guest Feb 12th, 2018 506 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //RPC Вызов
  2. case RPC_ShowDialog:
  3.         {
  4.             BitStream       bsData(rpcParams->input, rpcParams->numberOfBitsOfData / 8, false);
  5.             unsigned short DialogID;
  6.             BYTE style, caplen, button1_len, button2_len;
  7.             char caption[255], button1[25], button2[25], info[0x1000];
  8.             bsData.ResetReadPointer();
  9.             bsData.Read(DialogID);
  10.             bsData.Read(style);
  11.             bsData.Read(caplen);
  12.             bsData.Read(caption, caplen);
  13.             caption[caplen] = '\0';
  14.             bsData.Read(button1_len);
  15.             bsData.Read(button1, button1_len);
  16.             button1[button1_len] = '\0';
  17.             bsData.Read(button2_len);
  18.             bsData.Read(button2, button2_len);
  19.             button2[button2_len] = '\0';
  20.                 SAMP->DecodeString(info, 0x1000, &bsData);
  21.             SAMP->getChat()->addMessageToChat(-1, "Info :%s Caption ; %s", info, caption);
  22.  
  23.             break;
  24.         }
  25.  
  26. // САМ DECODE STRING.
  27.  
  28. typedef uint32_t BitSize_t;
  29.     struct HuffmanEncodingTreeNode
  30.     {
  31.         unsigned char value;
  32.         unsigned weight;
  33.         HuffmanEncodingTreeNode *left;
  34.         HuffmanEncodingTreeNode *right;
  35.         HuffmanEncodingTreeNode *parent;
  36.     };
  37.     HuffmanEncodingTreeNode *root;
  38.     unsigned DecodeArray(BitStream * input, BitSize_t sizeInBits, size_t maxCharsToWrite, unsigned char *output)
  39.     {
  40.         HuffmanEncodingTreeNode * currentNode;
  41.  
  42.         unsigned outputWriteIndex;
  43.         outputWriteIndex = 0;
  44.         currentNode = root;
  45.  
  46.         // For each bit, go left if it is a 0 and right if it is a 1.  When we reach a leaf, that gives us the desired value and we restart from the root
  47.  
  48.         for (unsigned counter = 0; counter < sizeInBits; counter++)
  49.         {
  50.             if (input->ReadBit() == false)   // left!
  51.                 currentNode = currentNode->left;
  52.             else
  53.                 currentNode = currentNode->right;
  54.  
  55.             if (currentNode->left == 0 && currentNode->right == 0)   // Leaf
  56.             {
  57.  
  58.                 if (outputWriteIndex < maxCharsToWrite)
  59.                     output[outputWriteIndex] = currentNode->value;
  60.  
  61.                 outputWriteIndex++;
  62.  
  63.                 currentNode = root;
  64.             }
  65.         }
  66.  
  67.         return outputWriteIndex;
  68.     }
  69.  
  70.     bool DecodeString(char *output, int maxCharsToWrite, BitStream *input)
  71.     {
  72.         if (maxCharsToWrite <= 0)
  73.             return false;
  74.  
  75.         uint32_t stringBitLength;
  76.         int bytesInStream;
  77.  
  78.         output[0] = 0;
  79.  
  80.         if (input->ReadCompressed(stringBitLength) == false)
  81.             return false;
  82.  
  83.         if ((unsigned)input->GetNumberOfUnreadBits() < stringBitLength)
  84.             return false;
  85.  
  86.         bytesInStream = DecodeArray(input, stringBitLength, maxCharsToWrite, (unsigned char*)output);
  87.  
  88.         if (bytesInStream < maxCharsToWrite)
  89.             output[bytesInStream] = 0;
  90.         else
  91.             output[maxCharsToWrite - 1] = 0;
  92.  
  93.         return true;
  94.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top