public string Name; // Name of node public SockHintInfo(SockHint hint, string value, string name = "Unknown") { Hint = hint; StringValue = value == "0" ? "" : value; Name = name; ByteValue = 0; ShortValue = 0; IntValue = 0; LongValue = 0; if (byte.TryParse(value, out byte byteValue)) { ByteValue = byteValue; } if (short.TryParse(value, out short shortValue)) { ShortValue = shortValue; } if (int.TryParse(value, out int intValue)) { IntValue = intValue; } if (long.TryParse(value, out long longValue)) { LongValue = longValue; } }
// resolve opcode (offset,type,value) (offset2,type2,value2) ... // Example: resolve 1500 (4,Decode8,100) public static PacketStructureResolver Parse(string input) { Regex overrideRegex = new Regex(@"\((\d+),(\w+),(-?\w+)(?:,(\w+))?\)"); string[] args = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); // TODO: fix this opcode parsing (it's backwards for 2 bytes...) ushort opCode = args[0].Length == 2 ? args[0].ToByte() : BitConverter.ToUInt16(args[0].ToByteArray()); PacketStructureResolver resolver = new PacketStructureResolver(opCode); for (int i = 1; i < args.Length; i++) { Match match = overrideRegex.Match(args[i]); if (!match.Success) { Console.WriteLine($"Invalid override:{args[i]} skipped."); } else { uint offset = uint.Parse(match.Groups[1].Value); SockHint type = match.Groups[2].Value.ToSockHint(); string value = match.Groups[3].Value; string name = "Override"; if (match.Groups.Count > 4 && !string.IsNullOrEmpty(match.Groups[4].Value)) { name = match.Groups[4].Value; } resolver.overrides.Add(offset, new SockHintInfo(type, value, name)); } } return(resolver); }
// resolve opcode (offset,type,value) (offset2,type2,value2) ... // Example: resolve 0015 (8,Decode8,100) public static PacketStructureResolver Parse(string input) { Regex overrideRegex = new Regex(@"\((\d+),(\w+),(-?\w+)(?:,(\w+))?\)"); string[] args = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); // Parse opCode: 81 0081 0x81 0x0081 ushort opCode = 0; if (args[0].ToLower().StartsWith("0x")) { opCode = Convert.ToUInt16(args[0], 16); } else { if (args[0].Length == 2) { opCode = args[0].ToByte(); } else if (args[0].Length == 4) { // Reverse bytes byte[] bytes = args[0].ToByteArray(); Array.Reverse(bytes); opCode = BitConverter.ToUInt16(bytes); } else { Console.WriteLine("Invalid opcode."); return(null); } } PacketStructureResolver resolver = new PacketStructureResolver(opCode); for (int i = 1; i < args.Length; i++) { Match match = overrideRegex.Match(args[i]); if (!match.Success) { Console.WriteLine($"Invalid override:{args[i]} skipped."); } else { uint offset = uint.Parse(match.Groups[1].Value); SockHint type = match.Groups[2].Value.ToSockHint(); string value = match.Groups[3].Value; string name = "Override"; if (match.Groups.Count > 4 && !string.IsNullOrEmpty(match.Groups[4].Value)) { name = match.Groups[4].Value; } resolver.overrides.Add(offset, new SockHintInfo(type, value, name)); } } return(resolver); }
public string Name; // Name of node public SockHintInfo(SockHint hint, string value, string name = "Unknown") { this.Hint = hint; byte.TryParse(value, out ByteValue); short.TryParse(value, out ShortValue); int.TryParse(value, out IntValue); long.TryParse(value, out LongValue); StringValue = value == "0" ? "" : value; Name = name; }
// MapleShark Script Code public static string GetScript(this SockHint hint, string name = "Unknown") { return(hint switch { SockHint.Decode1 => $"AddByte(\"{name}\");", SockHint.Decode2 => $"AddShort(\"{name}\");", SockHint.Decode4 => $"AddInt(\"{name}\");", SockHint.Decodef => $"AddFloat(\"{name}\");", SockHint.Decode8 => $"AddLong(\"{name}\");", SockHint.DecodeStr => $"AddUnicodeString(\"{name.Replace("Unknown", "UnknownStr")}\");", SockHint.DecodeStrA => $"AddString(\"{name.Replace("Unknown", "UnknownStr")}\");", _ => throw new ArgumentException($"Unexpected hint: {hint}") });
// MapleShark Script Code public static string GetScript(this SockHint hint, string name = "Unknown") => hint switch {