using System; using System.Collections.Generic; using System.Globalization; namespace NHSE.Core { public static class ItemCheatCode { public static byte[] ReadCode(string paste) { var lines = paste.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); return ReadCode(lines); } public static byte[] ReadCode(IEnumerable lines) { var result = new List(); foreach (var l in lines) { var lastSpace = l.LastIndexOf(' '); if (lastSpace < 0) continue; var lastChunk = l.Substring(lastSpace + 1); if (!uint.TryParse(lastChunk, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out var hex)) continue; var bytes = BitConverter.GetBytes(hex); result.AddRange(bytes); } return result.ToArray(); } public static IEnumerable WriteCode(IEnumerable items, uint offset) { int ctr = 0; foreach (var item in items) { var bytes = item.ToBytesClass(); var lower = BitConverter.ToUInt32(bytes, 0); var upper = BitConverter.ToUInt32(bytes, 4); yield return $"04100000 {offset + (ctr++*4):X8} {lower:X8}"; yield return $"04100000 {offset + (ctr++*4):X8} {upper:X8}"; } } } }