ReClassNET/ReClass.NET

Wrong code generated

qtbar opened this issue · 2 comments

qtbar commented

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?

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

Thank you for the report. Fixed with 8dc64c8.