[0.3DL] My game crashes when resolving RPC_ShowDialog

IamSpawN

Member
Joined
Feb 25, 2020
Messages
22
Reaction score
1
Location
Turkey
Code:
unsigned DecodeArray(BitStream* input, unsigned sizeInBits, unsigned maxCharsToWrite, unsigned char* output)
{
    struct HuffmanEncodingTreeNode
    {
        unsigned char value;
        unsigned weight;
        HuffmanEncodingTreeNode* left;
        HuffmanEncodingTreeNode* right;
        HuffmanEncodingTreeNode* parent;
    };
    HuffmanEncodingTreeNode* currentNode;
    HuffmanEncodingTreeNode* root;

    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)
{
    
    unsigned short stringBitLength;
    int bytesInStream;

    output[0] = 0;

    if (input->ReadCompressed(stringBitLength) == false)
        return false;

    if (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;
}

RPC
Code:
case RPC_ShowDialog:
        {
            struct SAMPDialog
            {
                int iIsActive;
                BYTE bDialogStyle;
                WORD wDialogID;
                BYTE bTitleLength;
                char szTitle[257];
                BYTE bButton1Len;
                char szButton1[257];
                BYTE bButton2Len;
                char szButton2[257];
                char szInfo[1024];
            };


            SAMPDialog    house;

            PCHAR Data = reinterpret_cast<PCHAR>(rpcParams->input);
            int iBitLength = rpcParams->numberOfBitsOfData;
            BitStream bsData((unsigned char*)Data, (iBitLength / 8) + 1, false);

            bsData.Read(house.wDialogID);
            bsData.Read(house.bDialogStyle);

            bsData.Read(house.bTitleLength);
            bsData.Read(house.szTitle, house.bTitleLength);
            house.szTitle[house.bTitleLength] = '\0';

            bsData.Read(house.bButton1Len);
            bsData.Read(house.szButton1, house.bButton1Len);
            house.szButton1[house.bButton1Len] = '\0';

            bsData.Read(house.bButton2Len);
            bsData.Read(house.szButton2, house.bButton2Len);
            house.szButton2[house.bButton2Len] = '\0';

            DecodeString(house.szInfo, 256, &bsData);

            
        }
 

SobFoX

Expert
Joined
Jul 14, 2015
Messages
1,386
Solutions
4
Reaction score
893
Location
Israel
Your question basically "why would it even work for me because I'm just copying things randoms"
 

IamSpawN

Member
Joined
Feb 25, 2020
Messages
22
Reaction score
1
Location
Turkey
Your question basically "why would it even work for me because I'm just copying things randoms"
You didn't know anything about your Sobfox 0.0.0.1 project, stop stealing here instead of swearing at people.
 

SobFoX

Expert
Joined
Jul 14, 2015
Messages
1,386
Solutions
4
Reaction score
893
Location
Israel
In the meantime you got the most correct answer from me, raknet does not like you. Understand for yourself that the problem is with raknet

Do a deeper hook to raknet and then the code will work for you =)
 

SobFoX

Expert
Joined
Jul 14, 2015
Messages
1,386
Solutions
4
Reaction score
893
Location
Israel
Ask the person who built version 0.0.0.1 with the addition of life he knows =)
 
Top