using System;
using QCRPG.Framework;

namespace QCRPG.TSL.BT.Packets;

public class DumpInformationVseInfo : PacketInfoBase
{
	public override string Name => "Dump Information Vse";

	public override string DisplayGroup => "Vendor Specific";

	public DumpInformationVseInfo(DumpInformationVse packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		DumpInformationVse dumpInformationVse = (DumpInformationVse)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("Vendor Event Class", "HCI_VS_DATALOG_OPCODE", 8, FormatValue(dumpInformationVse.UserFields.VendorEventClass, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Message Type", "PF_DBG_LogMSGTYPE_CRASH_INFO", 8, FormatValue(dumpInformationVse.UserFields.MessageType, 8), "", "", "", settable: false, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Build Version", "Firmware Build Version Information", 32, FormatValue(dumpInformationVse.UserFields.BuildVersion, 32), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Dump Reason", "Dump Reason\r\n\r\n" + DumpInformationVse.UserFieldsWrapper.DumpReasonInfo.DumpReasonToDescription(), 16, FormatValue(dumpInformationVse.UserFields.DumpReason, 16), DumpInformationVse.UserFieldsWrapper.DumpReasonInfo.DumpReasonToString(DumpInformationVse.UserFieldsWrapper.DumpReasonInfo.ValueToDumpReason(dumpInformationVse.UserFields.DumpReason)), "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ARM Registers Size", "ARM Registers Size, Current M0 ARM is 76. The size can be changed when different ARM CPU is being used later", 8, FormatValue(dumpInformationVse.UserFields.ArmRegistersSize, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("ARM Registers", "ARM Register Value", dumpInformationVse.UserFields.ArmRegistersList.Count * 8, FormatValue(dumpInformationVse.UserFields.ArmRegistersList, dumpInformationVse.UserFields.ArmRegistersList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Call Stack Size", "Call Stack Size. Maximum call stack size is 0x80", 8, FormatValue(dumpInformationVse.UserFields.CallStackSize, 8), "", "", "80", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("Call Stack", "Call Stack Frame", dumpInformationVse.UserFields.CallStackList.Count * 8, FormatValue(dumpInformationVse.UserFields.CallStackList, dumpInformationVse.UserFields.CallStackList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		DumpInformationVse dumpInformationVse = (DumpInformationVse)packet;
		int num = -1;
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field VendorEventClass");
		}
		if (index == ++num)
		{
			throw new Exception("Tried to set non-settable field MessageType");
		}
		if (index == ++num)
		{
			dumpInformationVse.UserFields.BuildVersion = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			dumpInformationVse.UserFields.DumpReason = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			dumpInformationVse.UserFields.ArmRegistersSize = Convert.ToUInt32(value, 16);
			return;
		}
		if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, dumpInformationVse.UserFields.ArmRegistersList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				dumpInformationVse.UserFields.ArmRegistersList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
		if (index == ++num)
		{
			dumpInformationVse.UserFields.CallStackSize = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, dumpInformationVse.UserFields.CallStackList.Count);
			int num3 = 0;
			while (value.Length > 0)
			{
				string value3 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				dumpInformationVse.UserFields.CallStackList[num3] = Convert.ToUInt32(value3, 16);
				num3++;
			}
		}
	}
}
