public static int detectStart(PCCPackage pcc, byte[] raw, uint flags) { if ((flags & 0x02000000) != 0) { return(30); } var result = 8; var test1 = BitConverter.ToInt32(raw, 4); var test2 = BitConverter.ToInt32(raw, 8); if (pcc.IsName(test1) && test2 == 0) { result = 4; } if (pcc.IsName(test1) && pcc.IsName(test2) && test2 != 0) { result = 8; } return(result); }
public static int detectStart(PCCPackage pcc, byte[] raw) { var result = 8; var test1 = BitConverter.ToInt32(raw, 4); if (test1 < 0) { result = 30; } else { var test2 = BitConverter.ToInt32(raw, 8); if (pcc.IsName(test1) && test2 == 0) { result = 4; } if (pcc.IsName(test1) && pcc.IsName(test2) && test2 != 0) { result = 8; } } return(result); }
public static List <Property> ReadProp(PCCPackage pcc, byte[] raw, int start) { Property p; PropertyValue v; int sname; var result = new List <Property>(); var pos = start; if (raw.Length - pos < 8) { return(result); } var name = (int)BitConverter.ToInt64(raw, pos); if (!pcc.IsName(name)) { return(result); } var t = pcc.Names[name]; if (pcc.Names[name] == "None") { p = new Property(); p.Name = name; p.TypeVal = Type.None; p.i = 0; p.offsetval = pos; p.Size = 8; p.Value = new PropertyValue(); p.raw = BitConverter.GetBytes((Int64)name); p.offend = pos + 8; result.Add(p); return(result); } var type = (int)BitConverter.ToInt64(raw, pos + 8); var size = BitConverter.ToInt32(raw, pos + 16); var idx = BitConverter.ToInt32(raw, pos + 20); if (!pcc.IsName(type) || size < 0 || size >= raw.Length) { return(result); } var tp = pcc.Names[type]; switch (tp) { case "DelegateProperty": p = new Property(); p.Name = name; p.TypeVal = Type.DelegateProperty; p.i = 0; p.offsetval = pos + 24; v = new PropertyValue(); v.IntValue = BitConverter.ToInt32(raw, pos + 28); v.len = size; v.Array = new List <PropertyValue>(); pos += 24; for (var i = 0; i < size; i++) { var v2 = new PropertyValue(); if (pos < raw.Length) { v2.IntValue = raw[pos]; } v.Array.Add(v2); pos++; } p.Value = v; break; case "ArrayProperty": var count = (int)BitConverter.ToInt64(raw, pos + 24); p = new Property(); p.Name = name; p.TypeVal = Type.ArrayProperty; p.i = 0; p.offsetval = pos + 24; v = new PropertyValue(); v.IntValue = type; v.len = size - 4; count = v.len; //TODO can be other objects too v.Array = new List <PropertyValue>(); pos += 28; for (var i = 0; i < count; i++) { var v2 = new PropertyValue(); if (pos < raw.Length) { v2.IntValue = raw[pos]; } v.Array.Add(v2); pos++; } p.Value = v; break; case "StrProperty": count = (int)BitConverter.ToInt64(raw, pos + 24); p = new Property(); p.Name = name; p.TypeVal = Type.StrProperty; p.i = 0; p.offsetval = pos + 24; count *= -1; v = new PropertyValue(); v.IntValue = type; v.len = count; pos += 28; var s = ""; for (var i = 0; i < count; i++) { s += (char)raw[pos]; pos += 2; } v.StringValue = s; p.Value = v; break; case "StructProperty": sname = (int)BitConverter.ToInt64(raw, pos + 24); p = new Property(); p.Name = name; p.TypeVal = Type.StructProperty; p.i = 0; p.offsetval = pos + 24; v = new PropertyValue(); v.IntValue = sname; v.len = size; v.Array = new List <PropertyValue>(); pos += 32; for (var i = 0; i < size; i++) { var v2 = new PropertyValue(); if (pos < raw.Length) { v2.IntValue = raw[pos]; } v.Array.Add(v2); pos++; } p.Value = v; break; case "ByteProperty": sname = (int)BitConverter.ToInt64(raw, pos + 24); p = new Property(); p.Name = name; p.TypeVal = Type.ByteProperty; p.i = 0; p.offsetval = pos + 32; v = new PropertyValue(); v.StringValue = pcc.GetName(sname); v.len = size; pos += 32; v.IntValue = (int)BitConverter.ToInt64(raw, pos); pos += size; p.Value = v; break; default: p = new Property(); p.Name = name; p.TypeVal = getType(pcc, type); p.i = 0; p.offsetval = pos + 24; p.Value = ReadValue(pcc, raw, pos + 24, type); pos += p.Value.len + 24; break; } p.raw = new byte[pos - start]; p.offend = pos; if (pos < raw.Length) { for (var i = 0; i < pos - start; i++) { p.raw[i] = raw[start + i]; } } result.Add(p); if (pos != start) { result.AddRange(ReadProp(pcc, raw, pos)); } return(result); }