예제 #1
0
 public Field(FieldDescriptor fd, Dictionary<uint, string> unhash, long pos, DbxFile tmpdbx)
 {
     this.descriptor = fd;
     this.name = unhash[fd.hash];
     this.absPos = pos;
     this.dbx = tmpdbx;
 }
예제 #2
0
 public CasCat(string catPath, Main handle)
 {
     this.mainForm = handle;
     this.casPath  = Path.GetDirectoryName(catPath) + "\\";
     this.modName  = Path.GetFileName(catPath);
     this.setUserDefaultDirectory();
     this.casWriterNumber = 0;
     this.guidTable       = new Dictionary <byte[], string>(new ByteArrayComparer());
     this.casReaders      = new Dictionary <int, BinaryReader>();
     this.catEntries      = new List <CatEntry>();
     using (BinaryReader binaryReader = new BinaryReader(File.Open(catPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
     {
         if (new string(binaryReader.ReadChars(16)) != "NyanNyanNyanNyan")
         {
             throw new Exception("No Nyan found. Invalid cat file header.");
         }
         while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length / 1L)
         {
             CatEntry catEntry = new CatEntry(binaryReader);
             this.catEntries.Add(catEntry);
             BinaryReader binaryReader2 = this.getBinaryReader((int)catEntry.archiveNumber);
             binaryReader2.BaseStream.Position = (long)((ulong)catEntry.offset);
             uint num = binaryReader2.ReadUInt32();
             if (num == 263377358u)
             {
                 DbxFile dbxFile = new DbxFile(binaryReader2, catEntry, this);
                 dbxFile.InitializeFilename(binaryReader2);
                 this.guidTable[dbxFile.dbxHeader.fileGuid] = dbxFile.filename;
                 this.addToTreeView(dbxFile);
             }
         }
     }
 }
예제 #3
0
 public CasCat(string catPath, Main handle)
 {
     this.mainForm = handle;
     this.casPath = Path.GetDirectoryName(catPath) + "\\";
     this.modName = Path.GetFileName(catPath);
     this.setUserDefaultDirectory();
     this.casWriterNumber = 0;
     this.guidTable = new Dictionary<byte[], string>(new ByteArrayComparer());
     this.casReaders = new Dictionary<int, BinaryReader>();
     this.catEntries = new List<CatEntry>();
     using (BinaryReader binaryReader = new BinaryReader(File.Open(catPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
     {
         if (new string(binaryReader.ReadChars(16)) != "NyanNyanNyanNyan")
         {
             throw new Exception("No Nyan found. Invalid cat file header.");
         }
         while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length / 1L)
         {
             CatEntry catEntry = new CatEntry(binaryReader);
             this.catEntries.Add(catEntry);
             BinaryReader binaryReader2 = this.getBinaryReader((int)catEntry.archiveNumber);
             binaryReader2.BaseStream.Position = (long)((ulong)catEntry.offset);
             uint num = binaryReader2.ReadUInt32();
             if (num == 263377358u)
             {
                 DbxFile dbxFile = new DbxFile(binaryReader2, catEntry, this);
                 dbxFile.InitializeFilename(binaryReader2);
                 this.guidTable[dbxFile.dbxHeader.fileGuid] = dbxFile.filename;
                 this.addToTreeView(dbxFile);
             }
         }
     }
 }
예제 #4
0
 public Field(FieldDescriptor fd, Dictionary <uint, string> unhash, long pos, DbxFile tmpdbx)
 {
     this.descriptor = fd;
     this.name       = unhash[fd.hash];
     this.absPos     = pos;
     this.dbx        = tmpdbx;
 }
예제 #5
0
        public void InitializeFilename(BinaryReader fCas)
        {
            fCas.BaseStream.Position = (long)((ulong)this.payloadSectionStart);
            foreach (InstanceRepeater current in this.instanceRepeaters)
            {
                int num = 0;
                while ((long)num < (long)((ulong)current.repetitions))
                {
                    byte[] first = fCas.ReadBytes(16);
                    if (first.SequenceEqual(this.dbxHeader.primaryInstanceGuid))
                    {
                        ComplexDescriptor complexDescriptor  = this.complexDescriptors[(int)current.complexIndex];
                        FieldDescriptor   fieldDescriptor    = this.fieldDescriptors[(int)complexDescriptor.fieldStartIndex];
                        ComplexDescriptor complexDescriptor2 = this.complexDescriptors[(int)fieldDescriptor.reference];
                        while (true)
                        {
                            if (complexDescriptor2.numField > 1)
                            {
                                for (int i = 0; i < (int)complexDescriptor2.numField; i++)
                                {
                                    fieldDescriptor = this.fieldDescriptors[(int)(complexDescriptor2.fieldStartIndex + (uint)i)];
                                    if (!(this.unhash[fieldDescriptor.hash] != "Name"))
                                    {
                                        goto IL_199;
                                    }
                                }
                            }
                            if (complexDescriptor2.numField == 0)
                            {
                                break;
                            }
                            complexDescriptor2 = this.complexDescriptors[(int)this.fieldDescriptors[(int)complexDescriptor2.fieldStartIndex].reference];
                        }
                        for (int j = 0; j < (int)complexDescriptor.numField; j++)
                        {
                            fieldDescriptor = this.fieldDescriptors[(int)(complexDescriptor.fieldStartIndex + (uint)j)];
                            if (!(this.unhash[fieldDescriptor.hash] != "Name"))
                            {
                                goto IL_199;
                            }
                        }
                        throw new Exception("No Name found.");
IL_199:
                        fCas.BaseStream.Position += (long)((ulong)fieldDescriptor.offset);
                        fCas.BaseStream.Position  = (long)((ulong)(this.stringSectionStart + fCas.ReadUInt32()));
                        this.filename             = DbxFile.readNullTerminatedString(fCas);
                        return;
                    }
                    fCas.BaseStream.Position += (long)((ulong)this.complexDescriptors[(int)current.complexIndex].size);
                    num++;
                }
            }
        }
예제 #6
0
 public void addSubNode(DbxFile dbxfile, int index, List<string> elems, TreeNode tn)
 {
     string text = elems[index];
     if (!tn.Nodes.ContainsKey(text))
     {
         tn.Nodes.Add(text, text);
     }
     if (elems.Count - 1 == index)
     {
         tn.Nodes[text].Tag = dbxfile;
         return;
     }
     this.addSubNode(dbxfile, index + 1, elems.ToList<string>(), tn.Nodes[text]);
 }
예제 #7
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            DbxFile dbxFile = e.Node.Tag as DbxFile;

            if (dbxFile == null)
            {
                this.propertyGrid1.SelectedObject = null;
                return;
            }
            if (dbxFile.instances == null)
            {
                dbxFile.InitializePayload();
            }
            this.propertyGrid1.SelectedObject = dbxFile;
        }
예제 #8
0
        public void addSubNode(DbxFile dbxfile, int index, List <string> elems, TreeNode tn)
        {
            string text = elems[index];

            if (!tn.Nodes.ContainsKey(text))
            {
                tn.Nodes.Add(text, text);
            }
            if (elems.Count - 1 == index)
            {
                tn.Nodes[text].Tag = dbxfile;
                return;
            }
            this.addSubNode(dbxfile, index + 1, elems.ToList <string>(), tn.Nodes[text]);
        }
예제 #9
0
 public void addToTreeView(DbxFile dbxfile)
 {
     string[] array = dbxfile.filename.Split(new char[]
     {
         '/'
     });
     if (!this.mainForm.treeView1.Nodes.ContainsKey(array[0]))
     {
         this.mainForm.treeView1.Nodes.Add(array[0], array[0]);
     }
     if (array.Count <string>() == 1)
     {
         this.mainForm.treeView1.Nodes[array[0]].Tag = dbxfile;
         return;
     }
     this.addSubNode(dbxfile, 1, array.ToList <string>(), this.mainForm.treeView1.Nodes[array[0]]);
 }
예제 #10
0
        public BinaryWriter getWriter(DbxFile dbx)
        {
            if (dbx.catEntry.archiveNumber >= 50u)
            {
                try
                {
                    this.casWriter = new BinaryWriter(File.Open(string.Concat(new object[]
                    {
                        this.casPath,
                        "cas_",
                        dbx.catEntry.archiveNumber,
                        ".cas"
                    }), FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
                }
                catch (Exception)
                {
                }
                return(this.casWriter);
            }
            uint num  = 4294967295u;
            uint num2 = 4294967295u;

            if (this.casWriterNumber >= 50)
            {
                try
                {
                    this.casWriter = new BinaryWriter(File.Open(string.Concat(new object[]
                    {
                        this.casPath,
                        "cas_",
                        this.casWriterNumber,
                        ".cas"
                    }), FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
                }
                catch (Exception)
                {
                }
                this.casWriter.Seek(0, SeekOrigin.End);
                num  = (uint)this.casWriterNumber;
                num2 = (uint)this.casWriter.BaseStream.Position + 32u;
            }
            else
            {
                for (int i = 50; i < 100; i++)
                {
                    if (!File.Exists(string.Concat(new object[]
                    {
                        this.casPath,
                        "cas_",
                        i,
                        ".cas"
                    })))
                    {
                        this.casWriterNumber = i;
                        this.casWriter       = new BinaryWriter(File.Open(string.Concat(new object[]
                        {
                            this.casPath,
                            "cas_",
                            i,
                            ".cas"
                        }), FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
                        num  = (uint)i;
                        num2 = 32u;
                        break;
                    }
                }
            }
            if (this.casWriter == null || num == 4294967295u)
            {
                throw new Exception("Cannot create new cas file in the range 50-99");
            }
            BinaryReader binaryReader = this.casReaders[(int)dbx.catEntry.archiveNumber];
            uint         offset       = dbx.catEntry.offset;
            BinaryWriter binaryWriter = new BinaryWriter(File.Open(this.casPath + this.modName, FileMode.Open, FileAccess.Write, FileShare.ReadWrite));

            binaryReader.BaseStream.Position = (long)((ulong)(offset - 32u));
            this.casWriter.Write(binaryReader.ReadBytes((int)(dbx.catEntry.size + 32u)));
            for (int j = 0; j < this.catEntries.Count <CatEntry>(); j++)
            {
                if (this.catEntries[j].sha1.SequenceEqual(dbx.catEntry.sha1))
                {
                    int num3 = 16 + j * 32;
                    this.catEntries[j].archiveNumber = num;
                    this.catEntries[j].offset        = num2;
                    binaryWriter.Seek(num3 + 20, SeekOrigin.Begin);
                    binaryWriter.Write(num2);
                    binaryWriter.Seek(4, SeekOrigin.Current);
                    binaryWriter.Write(num);
                    binaryWriter.Close();
                    break;
                }
            }
            return(this.casWriter);
        }
예제 #11
0
 public void addToTreeView(DbxFile dbxfile)
 {
     string[] array = dbxfile.filename.Split(new char[]
     {
         '/'
     });
     if (!this.mainForm.treeView1.Nodes.ContainsKey(array[0]))
     {
         this.mainForm.treeView1.Nodes.Add(array[0], array[0]);
     }
     if (array.Count<string>() == 1)
     {
         this.mainForm.treeView1.Nodes[array[0]].Tag = dbxfile;
         return;
     }
     this.addSubNode(dbxfile, 1, array.ToList<string>(), this.mainForm.treeView1.Nodes[array[0]]);
 }
예제 #12
0
 public BinaryWriter getWriter(DbxFile dbx)
 {
     if (dbx.catEntry.archiveNumber >= 50u)
     {
         try
         {
             this.casWriter = new BinaryWriter(File.Open(string.Concat(new object[]
             {
                 this.casPath,
                 "cas_",
                 dbx.catEntry.archiveNumber,
                 ".cas"
             }), FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
         }
         catch (Exception)
         {
         }
         return this.casWriter;
     }
     uint num = 4294967295u;
     uint num2 = 4294967295u;
     if (this.casWriterNumber >= 50)
     {
         try
         {
             this.casWriter = new BinaryWriter(File.Open(string.Concat(new object[]
             {
                 this.casPath,
                 "cas_",
                 this.casWriterNumber,
                 ".cas"
             }), FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
         }
         catch (Exception)
         {
         }
         this.casWriter.Seek(0, SeekOrigin.End);
         num = (uint)this.casWriterNumber;
         num2 = (uint)this.casWriter.BaseStream.Position + 32u;
     }
     else
     {
         for (int i = 50; i < 100; i++)
         {
             if (!File.Exists(string.Concat(new object[]
             {
                 this.casPath,
                 "cas_",
                 i,
                 ".cas"
             })))
             {
                 this.casWriterNumber = i;
                 this.casWriter = new BinaryWriter(File.Open(string.Concat(new object[]
                 {
                     this.casPath,
                     "cas_",
                     i,
                     ".cas"
                 }), FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
                 num = (uint)i;
                 num2 = 32u;
                 break;
             }
         }
     }
     if (this.casWriter == null || num == 4294967295u)
     {
         throw new Exception("Cannot create new cas file in the range 50-99");
     }
     BinaryReader binaryReader = this.casReaders[(int)dbx.catEntry.archiveNumber];
     uint offset = dbx.catEntry.offset;
     BinaryWriter binaryWriter = new BinaryWriter(File.Open(this.casPath + this.modName, FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
     binaryReader.BaseStream.Position = (long)((ulong)(offset - 32u));
     this.casWriter.Write(binaryReader.ReadBytes((int)(dbx.catEntry.size + 32u)));
     for (int j = 0; j < this.catEntries.Count<CatEntry>(); j++)
     {
         if (this.catEntries[j].sha1.SequenceEqual(dbx.catEntry.sha1))
         {
             int num3 = 16 + j * 32;
             this.catEntries[j].archiveNumber = num;
             this.catEntries[j].offset = num2;
             binaryWriter.Seek(num3 + 20, SeekOrigin.Begin);
             binaryWriter.Write(num2);
             binaryWriter.Seek(4, SeekOrigin.Current);
             binaryWriter.Write(num);
             binaryWriter.Close();
             break;
         }
     }
     return this.casWriter;
 }
예제 #13
0
 public DbxPropertyDescriptor(string name, Complex elem, DbxFile dbxa) : base(name, null)
 {
     this.complex = elem;
 }
 public DbxPropertyDescriptor(string name, Complex elem, DbxFile dbxa)
     : base(name, null)
 {
     this.complex = elem;
 }
예제 #15
0
        public void InitializeMetaData(BinaryReader fCas)
        {
            this.dbxHeader           = new DbxHeader(fCas);
            this.arraySectionStart   = this.catEntry.offset + this.dbxHeader.stringOffset + this.dbxHeader.lenString + this.dbxHeader.lenPayload;
            this.stringSectionStart  = this.catEntry.offset + this.dbxHeader.stringOffset;
            this.payloadSectionStart = this.catEntry.offset + this.dbxHeader.stringOffset + this.dbxHeader.lenString;
            this.externalGuids       = new List <Tuple <byte[], byte[]> >((int)this.dbxHeader.numExternalGuid);
            int num = 0;

            while ((long)num < (long)((ulong)this.dbxHeader.numExternalGuid))
            {
                this.externalGuids.Add(new Tuple <byte[], byte[]>(fCas.ReadBytes(16), fCas.ReadBytes(16)));
                num++;
            }
            this.unhash = new Dictionary <uint, string>();
            byte[] array = new byte[this.dbxHeader.lenKeyword];
            fCas.BaseStream.Read(array, 0, (int)this.dbxHeader.lenKeyword);
            int num2 = 0;
            int num3 = 0;

            while ((long)num3 < (long)((ulong)this.dbxHeader.lenKeyword))
            {
                if (array[num3] == 0)
                {
                    string @string = Encoding.ASCII.GetString(array, num2, num3 - num2);
                    if (@string != "")
                    {
                        this.unhash.Add(DbxFile.hasher(@string), @string);
                    }
                    num2 = num3 + 1;
                }
                num3++;
            }
            this.fieldDescriptors = new List <FieldDescriptor>((int)this.dbxHeader.numField);
            int num4 = 0;

            while ((long)num4 < (long)((ulong)this.dbxHeader.numField))
            {
                FieldDescriptor item = new FieldDescriptor(fCas);
                this.fieldDescriptors.Add(item);
                num4++;
            }
            this.complexDescriptors = new List <ComplexDescriptor>((int)this.dbxHeader.numComplex);
            int num5 = 0;

            while ((long)num5 < (long)((ulong)this.dbxHeader.numComplex))
            {
                ComplexDescriptor item2 = new ComplexDescriptor(fCas);
                this.complexDescriptors.Add(item2);
                num5++;
            }
            this.instanceRepeaters = new List <InstanceRepeater>();
            int num6 = 0;

            while ((long)num6 < (long)((ulong)this.dbxHeader.numInstanceRepeater))
            {
                this.instanceRepeaters.Add(new InstanceRepeater(fCas));
                num6++;
            }
            long num7 = 16L - (fCas.BaseStream.Position - (long)((ulong)this.catEntry.offset)) % 16L;

            if (num7 != 16L)
            {
                fCas.ReadBytes((int)num7);
            }
            this.arrayRepeaters = new List <ArrayRepeater>();
            int num8 = 0;

            while ((long)num8 < (long)((ulong)this.dbxHeader.numArrayRepeater))
            {
                this.arrayRepeaters.Add(new ArrayRepeater(fCas));
                num8++;
            }
        }
예제 #16
0
        private Field parseField(FieldDescriptor fieldDesc, BinaryReader b)
        {
            Field     field = new Field(fieldDesc, this.unhash, b.BaseStream.Position - (long)((ulong)this.catEntry.offset), this);
            FieldType type  = fieldDesc.type;

            if (type <= FieldType.Int8)
            {
                if (type <= FieldType.Array)
                {
                    if (type <= FieldType.Complex)
                    {
                        if (type != FieldType.Inheritance && type != FieldType.Complex)
                        {
                            return(field);
                        }
                    }
                    else
                    {
                        if (type == FieldType.Guid)
                        {
                            field.value = b.ReadUInt32();
                            return(field);
                        }
                        if (type != FieldType.Array)
                        {
                            return(field);
                        }
                        ArrayRepeater     arrayRepeater = this.arrayRepeaters[b.ReadInt32()];
                        ComplexDescriptor cd            = this.complexDescriptors[(int)fieldDesc.reference];
                        FieldDescriptor   fieldDesc2    = this.fieldDescriptors[(int)cd.fieldStartIndex];
                        if (arrayRepeater.repetitions == 0u)
                        {
                            field.value = "*nullArray*";
                            return(field);
                        }
                        b.BaseStream.Position = (long)((ulong)(this.arraySectionStart + arrayRepeater.offset));
                        Complex complex = new Complex(cd, this.unhash);
                        int     num     = 0;
                        while ((long)num < (long)((ulong)arrayRepeater.repetitions))
                        {
                            complex.fields.Add(this.parseField(fieldDesc2, b));
                            num++;
                        }
                        field.value = complex;
                        return(field);
                    }
                }
                else
                {
                    if (type <= FieldType.String)
                    {
                        if (type == FieldType.Enum)
                        {
                            Enum @enum = new Enum();
                            @enum.selection = b.ReadUInt32();
                            ComplexDescriptor complexDescriptor = this.complexDescriptors[(int)fieldDesc.reference];
                            for (int i = 0; i < (int)complexDescriptor.numField; i++)
                            {
                                Field field2 = new Field(this.fieldDescriptors[(int)(complexDescriptor.fieldStartIndex + (uint)i)], this.unhash, b.BaseStream.Position, this);
                                @enum.choices.Add(new Tuple <uint, string>(field2.descriptor.offset, field2.name));
                            }
                            field.value = @enum;
                            return(field);
                        }
                        if (type != FieldType.String)
                        {
                            return(field);
                        }
                        long position = b.BaseStream.Position;
                        b.BaseStream.Position = (long)((ulong)(this.stringSectionStart + b.ReadUInt32()));
                        field.value           = DbxFile.readNullTerminatedString(b);
                        b.BaseStream.Position = position + 4L;
                        return(field);
                    }
                    else
                    {
                        if (type == FieldType.Bool)
                        {
                            field.value = (b.ReadByte() != 0);
                            return(field);
                        }
                        if (type != FieldType.Int8)
                        {
                            return(field);
                        }
                        field.value = b.ReadByte();
                        return(field);
                    }
                }
            }
            else
            {
                if (type <= FieldType.UInt32)
                {
                    if (type <= FieldType.Int16)
                    {
                        if (type == FieldType.UInt16)
                        {
                            field.value = b.ReadUInt16();
                            return(field);
                        }
                        if (type != FieldType.Int16)
                        {
                            return(field);
                        }
                        field.value = b.ReadInt16();
                        return(field);
                    }
                    else
                    {
                        if (type == FieldType.Int32)
                        {
                            field.value = b.ReadInt32();
                            return(field);
                        }
                        if (type != FieldType.UInt32)
                        {
                            return(field);
                        }
                        field.value = b.ReadUInt32();
                        return(field);
                    }
                }
                else
                {
                    if (type <= FieldType.Double)
                    {
                        if (type == FieldType.Single)
                        {
                            field.value = b.ReadSingle();
                            return(field);
                        }
                        if (type != FieldType.Double)
                        {
                            return(field);
                        }
                        field.value = b.ReadDouble();
                        return(field);
                    }
                    else
                    {
                        if (type == FieldType.RawGuid)
                        {
                            field.value = b.ReadBytes(16);
                            return(field);
                        }
                        if (type != FieldType.Complex2)
                        {
                            return(field);
                        }
                    }
                }
            }
            field.value = this.parseComplex((int)fieldDesc.reference, b);
            return(field);
        }