Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //RPC Вызов
- case RPC_ShowDialog:
- {
- BitStream bsData(rpcParams->input, rpcParams->numberOfBitsOfData / 8, false);
- unsigned short DialogID;
- BYTE style, caplen, button1_len, button2_len;
- char caption[255], button1[25], button2[25], info[0x1000];
- bsData.ResetReadPointer();
- bsData.Read(DialogID);
- bsData.Read(style);
- bsData.Read(caplen);
- bsData.Read(caption, caplen);
- caption[caplen] = '\0';
- bsData.Read(button1_len);
- bsData.Read(button1, button1_len);
- button1[button1_len] = '\0';
- bsData.Read(button2_len);
- bsData.Read(button2, button2_len);
- button2[button2_len] = '\0';
- SAMP->DecodeString(info, 0x1000, &bsData);
- SAMP->getChat()->addMessageToChat(-1, "Info :%s Caption ; %s", info, caption);
- break;
- }
- // САМ DECODE STRING.
- typedef uint32_t BitSize_t;
- struct HuffmanEncodingTreeNode
- {
- unsigned char value;
- unsigned weight;
- HuffmanEncodingTreeNode *left;
- HuffmanEncodingTreeNode *right;
- HuffmanEncodingTreeNode *parent;
- };
- HuffmanEncodingTreeNode *root;
- unsigned DecodeArray(BitStream * input, BitSize_t sizeInBits, size_t maxCharsToWrite, unsigned char *output)
- {
- HuffmanEncodingTreeNode * currentNode;
- unsigned outputWriteIndex;
- outputWriteIndex = 0;
- currentNode = root;
- // 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
- for (unsigned counter = 0; counter < sizeInBits; counter++)
- {
- if (input->ReadBit() == false) // left!
- currentNode = currentNode->left;
- else
- currentNode = currentNode->right;
- if (currentNode->left == 0 && currentNode->right == 0) // Leaf
- {
- if (outputWriteIndex < maxCharsToWrite)
- output[outputWriteIndex] = currentNode->value;
- outputWriteIndex++;
- currentNode = root;
- }
- }
- return outputWriteIndex;
- }
- bool DecodeString(char *output, int maxCharsToWrite, BitStream *input)
- {
- if (maxCharsToWrite <= 0)
- return false;
- uint32_t stringBitLength;
- int bytesInStream;
- output[0] = 0;
- if (input->ReadCompressed(stringBitLength) == false)
- return false;
- if ((unsigned)input->GetNumberOfUnreadBits() < stringBitLength)
- return false;
- bytesInStream = DecodeArray(input, stringBitLength, maxCharsToWrite, (unsigned char*)output);
- if (bytesInStream < maxCharsToWrite)
- output[bytesInStream] = 0;
- else
- output[maxCharsToWrite - 1] = 0;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement