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

Wrong code generated #248

Closed
qtbar opened this issue Dec 31, 2022 · 2 comments
Closed

Wrong code generated #248

qtbar opened this issue Dec 31, 2022 · 2 comments

Comments

@qtbar
Copy link

qtbar commented Dec 31, 2022

When I try to generate code I get wrong output (Vector3 missing in c++ version):

// Created with ReClass.NET 1.2 by KN4CK3R

class ent
{
public:
	char pad_0000[4]; //0x0000
headpos; //0x0004
	char pad_0010[36]; //0x0010
position; //0x0034
angles; //0x0040
	char pad_004C[172]; //0x004C
	int32_t health; //0x00F8
	char pad_00FC[296]; //0x00FC
	int8_t attack; //0x0224
	char pad_0225[263]; //0x0225
	int32_t team; //0x032C
	char pad_0330[68]; //0x0330
	class weapon *currentWeapon; //0x0374
	char pad_0378[1244]; //0x0378
}; //Size: 0x0854
static_assert(sizeof(ent) == 0x854);

class weapon
{
public:
	char pad_0000[4]; //0x0000
	int32_t weaponId; //0x0004
	class ent *owner; //0x0008
	char pad_000C[4]; //0x000C
	class ammoPtr *ammoReserve; //0x0010
	class ammoPtr *ammoMag; //0x0014
	char pad_0018[44]; //0x0018
}; //Size: 0x0044
static_assert(sizeof(weapon) == 0x44);

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

C# output:

// Created with ReClass.NET 1.2 by KN4CK3R

// Warning: The C# code generator doesn't support all node types!

using System.Runtime.InteropServices;
// optional namespace, only for vectors
using System.Numerics;

[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
public struct ent
{
	[FieldOffset(0x4)]
	public readonly Vector3 headpos;
	[FieldOffset(0x34)]
	public readonly Vector3 position;
	[FieldOffset(0x40)]
	public readonly Vector3 angles;
	[FieldOffset(0xF8)]
	public readonly int health;
	[FieldOffset(0x224)]
	public readonly sbyte attack;
	[FieldOffset(0x32C)]
	public readonly int team;
	[FieldOffset(0x374)]
	public readonly IntPtr currentWeapon;
}

[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
public struct weapon
{
	[FieldOffset(0x4)]
	public readonly int weaponId;
	[FieldOffset(0x8)]
	public readonly IntPtr owner;
	[FieldOffset(0x10)]
	public readonly IntPtr ammoReserve;
	[FieldOffset(0x14)]
	public readonly IntPtr ammoMag;
}

[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
public struct ammoPtr
{
	[FieldOffset(0x0)]
	public readonly int ammo;
}

What could be the problem?

@DrP3pp3r
Copy link
Contributor

DrP3pp3r commented Jun 2, 2023

This is a problem caused by the code colorizer, i am having a similar issue.

Workaround - comment out code coloring in CodeForm.cs:

		public CodeForm(ICodeGenerator generator, IReadOnlyList<ClassNode> classes, IReadOnlyList<EnumDescription> enums, ILogger logger)
		{
			Contract.Requires(generator != null);
			Contract.Requires(classes != null);
			Contract.Requires(enums != null);

			InitializeComponent();

			codeRichTextBox.SetInnerMargin(5, 5, 5, 5);

			var code = generator.GenerateCode(classes, enums, logger);

			/*
			var buffer = new StringBuilder(code.Length * 2);
			using (var writer = new StringWriter(buffer))
			{
				new CodeColorizer().Colorize(
					code,
					generator.Language == Language.Cpp ? Languages.Cpp : Languages.CSharp,
					new RtfFormatter(),
					StyleSheets.Default,
					writer
				);
			}

			codeRichTextBox.Rtf = buffer.ToString();
			*/

			codeRichTextBox.Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericMonospace, 9);
			codeRichTextBox.ReadOnly = true;
			codeRichTextBox.Text = code;
		}

@KN4CK3R
Copy link
Member

KN4CK3R commented Jun 5, 2023

Thank you for the report. Fixed with 8dc64c8.

@KN4CK3R KN4CK3R closed this as completed Jun 5, 2023
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

3 participants