public static int detectStart(IPCCObject pcc, byte[] raw, long flags)
        {
            if ((flags & (long)UnrealFlags.EObjectFlags.HasStack) != 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(IPCCObject 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(IPCCObject 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;
                    v = new PropertyValue();
                    v.IntValue = type;
                    v.len = count;
                    pos += 28;
                    string s = "";
                    for (int i = 0; i < count; i++)
                        s += (char)raw[pos++];
                    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":
                    p = new Property();
                    p.Name = name;
                    p.TypeVal = Type.ByteProperty;
                    p.i = idx;
                    p.offsetval = pos + 24;
                    v = new PropertyValue();
                    v.IntValue = raw[pos + 24];
                    v.len = size;
                    pos += 24 + size;
                    p.Value = v;
                    break;
                case "BoolProperty":
                    p = new Property();
                    p.Name = name;
                    p.TypeVal = Type.BoolProperty;
                    p.i = idx;
                    p.offsetval = pos + 24;
                    v = new PropertyValue();
                    v.IntValue = raw[pos + 24];
                    v.len = 4;
                    pos += 28;
                    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 static int detectStart(IPCCObject 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(IPCCObject 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;

            int MEtype = Methods.GetMEType();
            string t = pcc.GetName(name);
            bool test = t == "None";
            if (MEtype == 3)
            {
                t = pcc.Names[name];
                test = pcc.Names[name] == "None";
            }
            else if (MEtype != 1 && MEtype != 2)
            {
                DebugOutput.PrintLn("Failed to get ME Game Type.");
                return new List<Property>();
            }

            if (test)
            {
                p = new Property();
                p.Name = t;
                p.TypeVal = Type.None;
                p.i = 0;
                p.offsetval = pos;
                p.Size = (MEtype == 3) ? 8 : 20;
                p.Value = new PropertyValue();
                p.raw = BitConverter.GetBytes((Int64)name);
                p.offend = pos + ((MEtype == 3) ? 8 : 20);
                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); //Unused
            if (!pcc.isName(type) || size < 0 || size >= raw.Length)
                return result;
            string tp = (MEtype == 3) ? pcc.Names[type] : pcc.GetName(type);
            switch (tp)
            {
                case "BoolProperty":
                    p = new Property();
                    p.TypeVal = Type.BoolProperty;
                    p.Name = t;
                    p.Size = size;
                    v = new PropertyValue();
                    if (MEtype == 3)
                    {
                        p.offsetval = pos + 24;
                        pos += 25;
                        byte temp = raw[p.offsetval];
                        v.IntValue = (int)temp;
                        v.Boolereno = temp == 1;
                    }
                    else
                    {
                        p.i = 0;
                        v.IntValue = BitConverter.ToInt32(raw, pos + ((MEtype == 2) ? 24 : 16)); //Guess. I haven't seen a true boolproperty yet
                        pos += 28;
                    }
                    p.Value = v;
                    break;
                case "NameProperty":
                    p = new Property();
                    p.TypeVal = Type.NameProperty;
                    p.Name = t;
                    p.Size = size;
                    v = new PropertyValue();
                    if (MEtype == 3)
                    {
                        pos += 24;
                        v.IntValue = (int)BitConverter.ToInt64(raw, pos);
                        v.StringValue = pcc.Names[v.IntValue];
                        pos += size;
                    }
                    else
                    {
                        //pos += 32;
                        //int tempInt = BitConverter.ToInt32(raw, pos + 24);
                        p.i = 0;
                        v.StringValue = pcc.GetName(BitConverter.ToInt32(raw, pos + 24));
                        pos += 32;
                    }
                    p.Value = v;
                    break;
                case "IntProperty":
                    p = new Property();
                    p.TypeVal = Type.IntProperty;
                    v = new PropertyValue();
                    p.Name = t;
                    p.Size = size;
                    if (MEtype == 3)
                    {
                        pos += 24;
                        v.IntValue = (int)BitConverter.ToInt64(raw, pos);
                        pos += size;
                    }
                    else
                    {
                        v.IntValue = BitConverter.ToInt32(raw, pos + 24);
                        p.i = 0;
                        p.offsetval = pos + 24;
                        pos += 28;
                    }
                    p.Value = v;
                    break;
                case "DelegateProperty":
                    p = new Property();
                    p.Name = t;
                    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>();
                    if (MEtype != 3)
                        p.Size = size;
                    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 = t;
                    if (MEtype != 3)
                        p.Size = size;
                    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":
                    if (MEtype == 2)
                        count = (int)BitConverter.ToInt32(raw, pos + 24);
                    else
                        count = (int)BitConverter.ToInt64(raw, pos + 24);
                    p = new Property();
                    p.Name = t;
                    if (MEtype != 3)
                        p.Size = size;
                    p.TypeVal = Type.StrProperty;
                    p.i = 0;
                    p.offsetval = pos + 24;
                    if (MEtype == 3)
                        count *= -1;
                    v = new PropertyValue();
                    v.IntValue = type;
                    v.len = count;
                    pos += 28;
                    string s = "";
                    for (int i = 0; i < ((MEtype == 3) ? count : count - 1); i++)
                    {
                        s += (char)raw[pos];
                        if (MEtype == 3)
                            pos += 2;
                        else
                            pos++;
                    }
                    if (MEtype != 3)
                        pos++;
                    v.StringValue = s;
                    p.Value = v;
                    break;
                case "StructProperty":
                    sname = (int)BitConverter.ToInt64(raw, pos + 24);
                    p = new Property();
                    p.Name = t;
                    p.Size = size;
                    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>();
                    if (MEtype == 3)
                        v.StringValue = pcc.Names[sname];
                    else if (MEtype == 3)
                        v.StringValue = pcc.GetName(sname);
                    pos += 32;
                    for (int i = 0; i < size; i += ((MEtype == 3) ? 1 : 4))
                    {
                        PropertyValue v2 = new PropertyValue();
                        //if (pos < raw.Length)
                        //    v2.IntValue = raw[pos];
                        //v.Array.Add(v2);
                        //pos++;
                        if (pos < raw.Length)
                            v2.IntValue = (MEtype == 3) ? raw[pos] : BitConverter.ToInt32(raw, pos);
                        v.Array.Add(v2);
                        pos += (MEtype == 3) ? 1 : 4;
                    }
                    p.Value = v;
                    break;
                case "ByteProperty":
                    if (MEtype == 3)
                        sname = (int)BitConverter.ToInt64(raw, pos + 24);
                    else
                        sname = BitConverter.ToInt32(raw, pos + 24);
                    p = new Property();
                    p.Name = t;
                    p.Size = size;
                    p.TypeVal = Type.ByteProperty;
                    p.i = 0;
                    p.offsetval = pos + 32;
                    v = new PropertyValue();
                    v.StringValue = (MEtype == 3) ? pcc.getNameEntry(sname) : pcc.GetName(sname);
                    v.len = size;
                    if (MEtype == 3)
                    {
                        pos += 32;
                        v.IntValue = BitConverter.ToInt32(raw, pos);
                        v.String2 = pcc.Names[v.IntValue];
                        pos += size;
                    }
                    else
                    {
                        v.IntValue = BitConverter.ToInt32(raw, pos + 28);
                        if (MEtype == 2)
                            v.String2 = pcc.GetName(v.IntValue);
                        pos += 32;
                    }

                    //v.IntValue = (int)BitConverter.ToInt64(raw, pos);
                    //pos += size;
                    p.Value = v;
                    break;
                case "FloatProperty":
                    if (MEtype == 1)
                        sname = (int)BitConverter.ToInt64(raw, pos + 24);
                    else if (MEtype == 2)
                        sname = BitConverter.ToInt32(raw, pos + 24);
                    p = new Property();
                    p.Name = t;
                    p.Size = size;
                    p.TypeVal = Type.FloatProperty;
                    p.i = 0;
                    p.offsetval = (MEtype != 3) ? pos + 24 : 24;
                    v = new PropertyValue();
                    v.FloatValue = BitConverter.ToSingle(raw, pos + 24);
                    v.len = size;
                    pos += 28;
                    p.Value = v;
                    break;
                default:
                    p = new Property();
                    p.Name = t;
                    p.TypeVal = getType(pcc, type);
                    p.i = 0;
                    if (MEtype != 3)
                        p.Size = size;
                    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 static int detectStart(IPCCObject pcc, byte[] raw, long flags)
 {
     if ((flags & (long)UnrealFlags.EObjectFlags.HasStack) != 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 List <Property> ReadProp(IPCCObject 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);
            }

            int    MEtype = Methods.GetMEType();
            string t      = pcc.GetName(name);
            bool   test   = t == "None";

            if (MEtype == 3)
            {
                t    = pcc.Names[name];
                test = pcc.Names[name] == "None";
            }
            else if (MEtype != 1 && MEtype != 2)
            {
                DebugOutput.PrintLn("Failed to get ME Game Type.");
                return(new List <Property>());
            }

            if (test)
            {
                p           = new Property();
                p.Name      = t;
                p.TypeVal   = Type.None;
                p.i         = 0;
                p.offsetval = pos;
                p.Size      = (MEtype == 3) ? 8 : 20;
                p.Value     = new PropertyValue();
                p.raw       = BitConverter.GetBytes((Int64)name);
                p.offend    = pos + ((MEtype == 3) ? 8 : 20);
                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); //Unused

            if (!pcc.isName(type) || size < 0 || size >= raw.Length)
            {
                return(result);
            }
            string tp = (MEtype == 3) ? pcc.Names[type] : pcc.GetName(type);

            switch (tp)
            {
            case "BoolProperty":
                p         = new Property();
                p.TypeVal = Type.BoolProperty;
                p.Name    = t;
                p.Size    = size;
                v         = new PropertyValue();
                if (MEtype == 3)
                {
                    p.offsetval = pos + 24;
                    pos        += 25;
                    byte temp = raw[p.offsetval];
                    v.IntValue  = (int)temp;
                    v.Boolereno = temp == 1;
                }
                else
                {
                    p.i        = 0;
                    v.IntValue = BitConverter.ToInt32(raw, pos + ((MEtype == 2) ? 24 : 16));     //Guess. I haven't seen a true boolproperty yet
                    pos       += 28;
                }
                p.Value = v;
                break;

            case "NameProperty":
                p         = new Property();
                p.TypeVal = Type.NameProperty;
                p.Name    = t;
                p.Size    = size;
                v         = new PropertyValue();
                if (MEtype == 3)
                {
                    pos          += 24;
                    v.IntValue    = BitConverter.ToInt32(raw, pos);
                    v.StringValue = pcc.GetName(v.IntValue);
                    // Heff: Temporary modification to handle name refs properly, until we can rewrite the whole property system accross all tools
                    var nameRef = new NameReference();
                    nameRef.index = v.IntValue;
                    nameRef.count = BitConverter.ToInt32(raw, pos + 4);
                    nameRef.Name  = pcc.getNameEntry(nameRef.index);
                    if (nameRef.count > 0)
                    {
                        nameRef.Name += "_" + (nameRef.count - 1);
                    }
                    v.NameValue = nameRef;
                    pos        += size;
                }
                else
                {
                    //pos += 32;
                    //int tempInt = BitConverter.ToInt32(raw, pos + 24);
                    p.i           = 0;
                    v.IntValue    = BitConverter.ToInt32(raw, pos + 24);
                    v.StringValue = pcc.GetName(v.IntValue);
                    // Heff: Temporary modification to handle name refs properly, until we can rewrite the whole property system accross all tools
                    var nameRef = new NameReference();
                    nameRef.index = v.IntValue;
                    nameRef.count = BitConverter.ToInt32(raw, pos + 4);
                    nameRef.Name  = pcc.getNameEntry(nameRef.index);
                    if (nameRef.count > 0)
                    {
                        nameRef.Name += "_" + (nameRef.count - 1);
                    }
                    v.NameValue = nameRef;
                    pos        += 32;
                }
                p.Value = v;
                break;

            case "IntProperty":
                p         = new Property();
                p.TypeVal = Type.IntProperty;
                v         = new PropertyValue();
                p.Name    = t;
                p.Size    = size;
                if (MEtype == 3)
                {
                    pos       += 24;
                    v.IntValue = (int)BitConverter.ToInt64(raw, pos);
                    pos       += size;
                }
                else
                {
                    v.IntValue  = BitConverter.ToInt32(raw, pos + 24);
                    p.i         = 0;
                    p.offsetval = pos + 24;
                    pos        += 28;
                }
                p.Value = v;
                break;

            case "DelegateProperty":
                p           = new Property();
                p.Name      = t;
                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>();
                if (MEtype != 3)
                {
                    p.Size = size;
                }
                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 = t;
                if (MEtype != 3)
                {
                    p.Size = size;
                }
                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":
                if (MEtype == 2)
                {
                    count = (int)BitConverter.ToInt32(raw, pos + 24);
                }
                else
                {
                    count = (int)BitConverter.ToInt64(raw, pos + 24);
                }
                p      = new Property();
                p.Name = t;
                if (MEtype != 3)
                {
                    p.Size = size;
                }
                p.TypeVal   = Type.StrProperty;
                p.i         = 0;
                p.offsetval = pos + 24;
                if (MEtype == 3)
                {
                    count *= -1;
                }
                v          = new PropertyValue();
                v.IntValue = type;
                v.len      = count;
                pos       += 28;
                string s = "";
                for (int i = 0; i < ((MEtype == 3) ? count : count - 1); i++)
                {
                    s += (char)raw[pos];
                    if (MEtype == 3)
                    {
                        pos += 2;
                    }
                    else
                    {
                        pos++;
                    }
                }
                if (MEtype != 3)
                {
                    pos++;
                }
                v.StringValue = s;
                p.Value       = v;
                break;

            case "StructProperty":
                sname       = (int)BitConverter.ToInt64(raw, pos + 24);
                p           = new Property();
                p.Name      = t;
                p.Size      = size;
                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>();
                if (MEtype == 3)
                {
                    v.StringValue = pcc.Names[sname];
                }
                else if (MEtype == 3)
                {
                    v.StringValue = pcc.GetName(sname);
                }
                pos += 32;
                for (int i = 0; i < size; i += ((MEtype == 3) ? 1 : 4))
                {
                    PropertyValue v2 = new PropertyValue();
                    //if (pos < raw.Length)
                    //    v2.IntValue = raw[pos];
                    //v.Array.Add(v2);
                    //pos++;
                    if (pos < raw.Length)
                    {
                        v2.IntValue = (MEtype == 3) ? raw[pos] : BitConverter.ToInt32(raw, pos);
                    }
                    v.Array.Add(v2);
                    pos += (MEtype == 3) ? 1 : 4;
                }
                p.Value = v;
                break;

            case "ByteProperty":
                if (MEtype == 3)
                {
                    sname = (int)BitConverter.ToInt64(raw, pos + 24);
                }
                else
                {
                    sname = BitConverter.ToInt32(raw, pos + 24);
                }
                p             = new Property();
                p.Name        = t;
                p.Size        = size;
                p.TypeVal     = Type.ByteProperty;
                p.i           = 0;
                p.offsetval   = pos + 32;
                v             = new PropertyValue();
                v.StringValue = (MEtype == 3) ? pcc.getNameEntry(sname) : pcc.GetName(sname);
                v.len         = size;
                if (MEtype == 3)
                {
                    pos       += 32;
                    v.IntValue = BitConverter.ToInt32(raw, pos);
                    v.String2  = pcc.Names[v.IntValue];
                    // Heff: Temporary modification to handle name refs properly, until we can rewrite the whole property system accross all tools
                    // This is stupid for enum properties, but as the enum itself will probably never be a name with index it works..
                    var nameRef = new NameReference();
                    nameRef.index = v.IntValue;
                    nameRef.count = BitConverter.ToInt32(raw, pos + 4);
                    nameRef.Name  = pcc.getNameEntry(nameRef.index);
                    if (nameRef.count > 0)
                    {
                        nameRef.Name += "_" + (nameRef.count - 1);
                    }
                    v.NameValue = nameRef;
                    pos        += size;
                }
                else
                {
                    v.IntValue = BitConverter.ToInt32(raw, pos + 28);
                    if (MEtype == 2)
                    {
                        v.String2 = pcc.GetName(v.IntValue);
                    }
                    pos += 32;
                }

                //v.IntValue = (int)BitConverter.ToInt64(raw, pos);
                //pos += size;
                p.Value = v;
                break;

            case "FloatProperty":
                if (MEtype == 1)
                {
                    sname = (int)BitConverter.ToInt64(raw, pos + 24);
                }
                else if (MEtype == 2)
                {
                    sname = BitConverter.ToInt32(raw, pos + 24);
                }
                p            = new Property();
                p.Name       = t;
                p.Size       = size;
                p.TypeVal    = Type.FloatProperty;
                p.i          = 0;
                p.offsetval  = (MEtype != 3) ? pos + 24 : 24;
                v            = new PropertyValue();
                v.FloatValue = BitConverter.ToSingle(raw, pos + 24);
                v.len        = size;
                pos         += 28;
                p.Value      = v;
                break;

            default:
                p         = new Property();
                p.Name    = t;
                p.TypeVal = getType(pcc, type);
                p.i       = 0;
                if (MEtype != 3)
                {
                    p.Size = size;
                }
                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 static List <Property> ReadProp(IPCCObject 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;
                v           = new PropertyValue();
                v.IntValue  = type;
                v.len       = count;
                pos        += 28;
                string s = "";
                for (int i = 0; i < count; i++)
                {
                    s += (char)raw[pos++];
                }
                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":
                p           = new Property();
                p.Name      = name;
                p.TypeVal   = Type.ByteProperty;
                p.i         = idx;
                p.offsetval = pos + 24;
                v           = new PropertyValue();
                v.IntValue  = raw[pos + 24];
                v.len       = size;
                pos        += 24 + size;
                p.Value     = v;
                break;

            case "BoolProperty":
                p           = new Property();
                p.Name      = name;
                p.TypeVal   = Type.BoolProperty;
                p.i         = idx;
                p.offsetval = pos + 24;
                v           = new PropertyValue();
                v.IntValue  = raw[pos + 24];
                v.len       = 4;
                pos        += 28;
                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);
        }
Example #9
0
        public List <PropHeader> ReadHeadersTillNone()
        {
            List <PropHeader> ret = new List <PropHeader>();
            bool run = true;

            while (run)
            {
                PropHeader p = new PropHeader();
                p.name = BitConverter.ToInt32(memory, readerpos);
                if (!pcc.isName(p.name))
                {
                    run = false;
                }
                else
                {
                    if (pcc.getNameEntry(p.name) != "None")
                    {
                        p.type = BitConverter.ToInt32(memory, readerpos + 8);
                        if (!pcc.isName(p.type) || isType(pcc.getNameEntry(p.type)) == -1)
                        {
                            run = false;
                        }
                        else
                        {
                            p.size   = BitConverter.ToInt32(memory, readerpos + 16);
                            p.index  = BitConverter.ToInt32(memory, readerpos + 20);
                            p.offset = readerpos;
                            ret.Add(p);
                            readerpos += p.size + 24;
                            if (isType(pcc.getNameEntry(p.type)) == 5)//Boolbyte
                            {
                                if (GameVersion == 3)
                                {
                                    readerpos++;
                                }
                                else
                                {
                                    readerpos += 4;
                                }
                            }

                            if (isType(pcc.getNameEntry(p.type)) == 0 ||                     //StructName
                                (GameVersion == 3 && isType(pcc.getNameEntry(p.type)) == 6)) //byteprop
                            {
                                readerpos += 8;
                            }
                        }
                    }
                    else
                    {
                        p.type   = p.name;
                        p.size   = 0;
                        p.index  = 0;
                        p.offset = readerpos;
                        ret.Add(p);
                        readerpos += 8;
                        run        = false;
                    }
                }
            }
            return(ret);
        }