I reversing game packets , Everything is good, but how do I save these values in the array or Vector [ValueFromRecv,id,x,y]
Note that it is not possible to know the size of the array ,
Because when the player hits the monster in the game, a lot of items are on the ground and randomly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
constexprauto ValueFromRecvOffset = 0x8;
auto lpReadAddress = reinterpret_cast<LPVOID>((DWORD)lpPacket + ValueFromRecvOffset);
auto ValueFromRecv = memory.Read<uint32_t>(lpReadAddress);
constexprauto IDOffset = 0xC;
auto lpReadAddress = reinterpret_cast<LPVOID>((DWORD)lpPacket + IDOffset);
auto ID = memory.Read<uint32_t>(lpReadAddress);
constexprauto XOffset = 0x10;
auto lpReadAddress = reinterpret_cast<LPVOID>((DWORD)lpPacket + XOffset);
auto X = memory.Read<uint16_t>(lpReadAddress);
constexprauto YOffset = 0x12;
auto lpReadAddress = reinterpret_cast<LPVOID>((DWORD)lpPacket + YOffset);
auto Y = memory.Read<uint16_t>(lpReadAddress);
You could use a struct for the values (ValueFromRecv, id, x, y) with each element of the appropriate type. Then have a std::vector of the struct. To add items to the vector, you just insert at the end. Unlike a std::array, the size of a std::vector can change at run-time when you insert/erase elements. Consider for a simple example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <vector>
#include <iostream>
struct Data {
int ValueFromRecv {};
int id {};
int x {};
int y {};
};
int main() {
std::vector<Data> packets;
packets.emplace_back(1, 2, 3, 4);
packets.emplace_back(3, 4, 5, 6);
for (constauto& [vfr, i, x, y] : packets)
std::cout << vfr << " " << i << " " << x << " " << y << '\n';
}
#include <vector>
#include <iostream>
struct Data {
int ValueFromRecv {};
int id {};
int x {};
int y {};
Data(int v, int i, int x_, int y_) : ValueFromRecv(v), id(i), x(x_), y(y_) {}
};
int main() {
std::vector<Data> packets;
packets.emplace_back(1, 2, 3, 4);
packets.emplace_back(3, 4, 5, 6);
for (constauto& pack : packets)
std::cout << pack.ValueFromRecv << " " << pack.id << " " << pack.x << " " << pack.y << '\n';
}
What os/compiler are you using? For some compilers you need to explicitly specify the C++ version to use (eg MS VS defaults to C++14 unless changed). C++20 is the current standard with C++23 due later this year. If your current C++ complier doesn't support C++20 then I'd advise you really consider updating it.
VS2019 and VS2022 default the C++ language standard to C++14. C++20 should be your minimum default standard unless you have specific reasons not to.
C++23 is now the current approved standard, but no compilers are 100% compliant yet. VS can be set for the language standard to c++:latest that include what C++23 features have be added.
VS2019 is at "end of life" support now that VS2022 is available, newer language support isn't likely to happen. VS2019 has issues with some C++20 features. Consider upgrading to VS2022 if you can.