1

I'm porting my program to C++, but I'm having a little bit of trouble. I have this code in C# creating a byte[] :

writer.New(0x484700C0);
    {
        writer += Functions.PadString("PTEmu", 0x10);
        writer += new byte[] { 0xC9, 0x32, 0xE0, 0x4D, 0xEB, 0x01 };
        writer.SkipBytes(6);
        writer += 1;
        writer += channels.Count; // sub count


        for (int i = 0; i < channels.Count; i++)
        {
            writer += Functions.PadString(channels[i].Item4, 0x20); // len = 0x20
            writer += Functions.PadString(channels[i].Item2, 0x14);
            writer += Functions.PadString(channels[i].Item2, 0x14);
            writer += Functions.PadString(channels[i].Item2, 0x14);


            writer += channels[i].Item3; // int, size = 4
            writer += channels[i].Item3;
            writer += channels[i].Item3;
            writer += 0;
        }


        writer += Functions.PadString("Clan", 32);
        writer += Functions.PadString("127.0.0.1", 0x14);
        writer += Functions.PadString("127.0.0.1", 0x14);
        writer += Functions.PadString("127.0.0.1", 0x14);
        writer += 80;
        writer += 80;
        writer += 80;
        writer.SkipBytes(12);
    }

I thought about doing something like:

struct PT_ServerList{
    int size;
    int opcode;
    char server[0x10];
    char bla[6];
    int reserved1;
    short reserved2;
    int unknow;
    int serverCount;
    ServerInfo servers[];
};

But after the servers[] I'd need to add more variables, but then the compiler doesnt accept the struct. What can I do to solve this?

2 Answers 2

2

Use a vector:

struct PT_ServerList {
    ...
    std::vector<ServerInfo> servers;
    ...
};
Sign up to request clarification or add additional context in comments.

Comments

1

You probably want to use either:

ServerInfo *servers;

(in which case you'd need to allocate the array using "new[]" and deallocate it using "delete[]"); or:

std::vector<ServerInfo> servers;

(In which case you should consult the std::vector documentation for information about how to use it, if you haven't used std::vector before.

2 Comments

it still not working, I wrote the contents to a .dat file and it is not showing the contents of servers
I saw in olly, that the contents of servers is being added in another location of memory, not inside the PT_ServerList structure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.