Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Liftu opened this issue Aug 7, 2022 · 3 comments
Closed

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

Liftu opened this issue Aug 7, 2022 · 3 comments

Comments

@Liftu
Copy link

Liftu commented Aug 7, 2022

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.

@KN4CK3R
Copy link
Member

KN4CK3R commented Aug 8, 2022

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
Copy link
Author

Liftu commented Aug 8, 2022

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.

@KN4CK3R
Copy link
Member

KN4CK3R commented Aug 8, 2022

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);

@KN4CK3R KN4CK3R closed this as completed Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants