ReClassNET/ReClass.NET

C++ code classes generated disordered "A uses undefined class B"

Liftu opened this issue · 3 comments

Liftu commented

Hello,

I'm trying to generate the C++ code from the structs I reversed but I get an error when I'm compiling the result.

ReClass.NET seems to generate the structs definitions in a random order.
So if a class A refers to a class B but the latter is defined after the struct A in the generated C++ code, I get the error "A uses undefined class B" from Visual Studio compiler.

I have more than 2000 lines of generated C++ code so I can't rearrange them manually.

It's the first time that kind of stuff happen to me using ReClass.NET and I wonder if someone else already encountered the same problem or not.

The class definitions are not in random order. ReClass checks which class depends on which other class and orders them for the compiler to be happy. Did you build a loop (A -> B -> C -> A)?

Otherwise I need a minimal example to have a deeper look.

Liftu commented

Ok, I think I managed to locate the issue.
This only occurs on classes that are used in unions.

I made a ReClass project example that I'll attach to this comment as a ZIP archive.

And here is the generated C++ code from ReClass.NET :

// Created with ReClass.NET 1.2 by KN4CK3R

class E
{
public:
	int32_t intE; //0x0000
}; //Size: 0x0004

class A
{
public:
	int32_t intA; //0x0000
	float floatA; //0x0004
	union //0x0008
	{
		class B b; //0x0000        <---- Class B in union
		class C c; //0x0000        <---- Class C in union
	};
	class E e; //0x0010                <---- Class E as is
}; //Size: 0x0014

class B
{
public:
	int32_t intB; //0x0000
}; //Size: 0x0004

class C
{
public:
	int32_t intC; //0x0000
	union //0x0004
	{
		class D d; //0x0000        <---- Class D in union
	};
}; //Size: 0x0008

class D
{
public:
	int32_t intD; //0x0000
}; //Size: 0x0004

As you can see, only the class E has been defined on top because it is the only class used as is in another one (in class A).
But classes B, C and D are used in unions and thus are not declared on the correct position.

For information I use the latest Github release from 2019/04/15 and I haven't tried it with latest commits.

Thank you for your time.

Thank you for the example. Fixed in 45696a7

// Created with ReClass.NET 1.2 by KN4CK3R

class B
{
public:
	int32_t intB; //0x0000
}; //Size: 0x0004
static_assert(sizeof(B) == 0x4);

class D
{
public:
	int32_t intD; //0x0000
}; //Size: 0x0004
static_assert(sizeof(D) == 0x4);

class C
{
public:
	int32_t intC; //0x0000
	union //0x0004
	{
		class D d; //0x0000
	};
}; //Size: 0x0008
static_assert(sizeof(C) == 0x8);

class E
{
public:
	int32_t intE; //0x0000
}; //Size: 0x0004
static_assert(sizeof(E) == 0x4);

class A
{
public:
	int32_t intA; //0x0000
	float floatA; //0x0004
	union //0x0008
	{
		class B b; //0x0000
		class C c; //0x0000
	};
	class E e; //0x0010
}; //Size: 0x0014
static_assert(sizeof(A) == 0x14);