public static int detectStart(PCCPackage pcc, byte[] raw, uint flags) { if ((flags & 0x02000000) != 0) { return(30); } int result = 8; int test1 = BitConverter.ToInt32(raw, 4); int 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) { int result = 8; int test1 = BitConverter.ToInt32(raw, 4); if (test1 < 0) { result = 30; } else { int 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, uint flags) { //has stack if ((flags & 0x02000000) != 0) { return 30; } int result = 8; int test1 = BitConverter.ToInt32(raw, 4); int 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) { int result = 8; int test1 = BitConverter.ToInt32(raw, 4); if (test1 < 0) result = 30; else { int 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; List<Property> result = new List<Property>(); int pos = start; if(raw.Length - pos < 8) return result; int name = (int)BitConverter.ToInt64(raw, pos); if (!pcc.isName(name)) return result; string 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; } int type = (int)BitConverter.ToInt64(raw, pos + 8); int size = BitConverter.ToInt32(raw, pos + 16); int idx = BitConverter.ToInt32(raw, pos + 20); if (!pcc.isName(type) || size < 0 || size >= raw.Length) return result; string 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 (int i = 0; i < size; i++) { PropertyValue v2 = new PropertyValue(); if(pos < raw.Length) v2.IntValue = raw[pos]; v.Array.Add(v2); pos ++; } p.Value = v; break; case "ArrayProperty": int 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 (int i = 0; i < count; i++) { PropertyValue 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; string s = ""; for (int 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 (int i = 0; i < size; i++) { PropertyValue 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; if (size == 8) { v.IntValue = BitConverter.ToInt32(raw, pos); } else { v.IntValue = 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.Size = size; p.raw = new byte[pos - start]; p.offend = pos; if(pos < raw.Length) for (int 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; }
public static List <Property> ReadProp(PCCPackage pcc, byte[] raw, int start) { Property p; PropertyValue v; int sname; List <Property> result = new List <Property>(); int pos = start; if (raw.Length - pos < 8) { return(result); } int name = (int)BitConverter.ToInt64(raw, pos); if (!pcc.isName(name)) { return(result); } string 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); } int type = (int)BitConverter.ToInt64(raw, pos + 8); int size = BitConverter.ToInt32(raw, pos + 16); int idx = BitConverter.ToInt32(raw, pos + 20); if (!pcc.isName(type) || size < 0 || size >= raw.Length) { return(result); } string 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 (int i = 0; i < size; i++) { PropertyValue v2 = new PropertyValue(); if (pos < raw.Length) { v2.IntValue = raw[pos]; } v.Array.Add(v2); pos++; } p.Value = v; break; case "ArrayProperty": int 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 (int i = 0; i < count; i++) { PropertyValue 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; string s = ""; for (int 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 (int i = 0; i < size; i++) { PropertyValue 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 (int 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); }
public void ImportProperty(PCCPackage pcc, PCCPackage importpcc, PropertyReader.Property p, MemoryStream m) { string name = importpcc.GetName(p.Name); int idxname = pcc.FindNameOrAdd(name); m.Write(BitConverter.GetBytes(idxname), 0, 4); m.Write(new byte[4], 0, 4); if (name == "None") return; string type = importpcc.GetName(BitConverter.ToInt32(p.raw, 8)); int idxtype = pcc.FindNameOrAdd(type); m.Write(BitConverter.GetBytes(idxtype), 0, 4); m.Write(new byte[4], 0, 4); string name2; int idxname2; int size, count, pos; List<PropertyReader.Property> Props; switch (type) { case "IntProperty": case "FloatProperty": case "ObjectProperty": case "StringRefProperty": m.Write(BitConverter.GetBytes(4), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4); break; case "NameProperty": m.Write(BitConverter.GetBytes(8), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4); m.Write(new byte[4], 0, 4); break; case "BoolProperty": m.Write(new byte[8], 0, 8); m.WriteByte((byte)p.Value.IntValue); break; case "ByteProperty": name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 24)); idxname2 = pcc.FindNameOrAdd(name2); m.Write(BitConverter.GetBytes(8), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(idxname2), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4); m.Write(new byte[4], 0, 4); break; case "DelegateProperty": size = BitConverter.ToInt32(p.raw, 16); if (size == 0xC) { name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 28)); idxname2 = pcc.FindNameOrAdd(name2); m.Write(BitConverter.GetBytes(0xC), 0, 4); m.Write(new byte[4], 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(idxname2), 0, 4); m.Write(new byte[4], 0, 4); } else { m.Write(BitConverter.GetBytes(size), 0, 4); m.Write(new byte[4], 0, 4); for (int i = 0; i < size; i++) m.WriteByte(p.raw[24 + i]); } break; case "StrProperty": name2 = p.Value.StringValue; m.Write(BitConverter.GetBytes(4 + name2.Length * 2), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(-name2.Length), 0, 4); foreach (char c in name2) { m.WriteByte((byte)c); m.WriteByte(0); } break; case "StructProperty": size = BitConverter.ToInt32(p.raw, 16); name2 = importpcc.GetName(BitConverter.ToInt32(p.raw, 24)); idxname2 = pcc.FindNameOrAdd(name2); pos = 32; Props = new List<PropertyReader.Property>(); try { Props = PropertyReader.ReadProp(importpcc, p.raw, pos); } catch (Exception) { } m.Write(BitConverter.GetBytes(size), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(idxname2), 0, 4); m.Write(new byte[4], 0, 4); if (Props.Count == 0) { for (int i = 0; i < size; i++) m.WriteByte(p.raw[32 + i]); } else if (Props[0].TypeVal == PropertyReader.Type.Unknown) { for (int i = 0; i < size; i++) m.WriteByte(p.raw[32 + i]); } else { foreach (PropertyReader.Property pp in Props) ImportProperty(pcc, importpcc, pp, m); } break; case "ArrayProperty": size = BitConverter.ToInt32(p.raw, 16); count = BitConverter.ToInt32(p.raw, 24); pos = 28; List<PropertyReader.Property> AllProps = new List<PropertyReader.Property>(); for (int i = 0; i < count; i++) { Props = new List<PropertyReader.Property>(); int test1 = BitConverter.ToInt32(p.raw, pos); int test2 = BitConverter.ToInt32(p.raw, pos + 4); if (!importpcc.isName(test1) || test2 != 0) break; if (importpcc.GetName(test1) != "None") if (BitConverter.ToInt32(p.raw, pos + 12) != 0) break; try { Props = PropertyReader.ReadProp(importpcc, p.raw, pos); } catch (Exception) { } AllProps.AddRange(Props); if (Props.Count != 0) { pos = Props[Props.Count - 1].offend; } } m.Write(BitConverter.GetBytes(size), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(count), 0, 4); if (AllProps.Count != 0) foreach (PropertyReader.Property pp in AllProps) ImportProperty(pcc, importpcc, pp, m); else m.Write(p.raw, 28, size - 4); break; default: throw new Exception(type); } }