예제 #1
0
 public void AddResource(TGI_Key Key1, TGI_Key Key2)
 {
     //if (Key1 != Key2)
     //{
     //    Console.WriteLine("{0} <--> {1}", Key1, Key2);
     //}
     Resources.Add(Key1);
 }
 public int Priority { get; set; }  // used by GameLibrary code
 #endregion
 
 #region Constructor
 public ResourceEntry(Stream Datastore, TGI_Key Key, long ChunkOffset, int ChunkLength, int ResourceLength, bool IsCompressed, bool IsEncrypted)
 {
     this.DataStore = Datastore;
     this.Key = Key;
     _ChunkOffset = ChunkOffset;
     _ChunkLength = ChunkLength;
     _ResourceLength = ResourceLength;
     this.IsCompressed = IsCompressed;
     _IsEncrypted = IsEncrypted;
 }
 public ResourceEntry(Stream DataStore, TGI_Key Key)
 {
     this.DataStore = DataStore;
     this.Key = Key;
     _ChunkOffset = 0;
     _ChunkLength = (int)DataStore.Length;
     _ResourceLength = (int)DataStore.Length;
     this.IsCompressed = false;
     _IsEncrypted = false;
 }
예제 #4
0
 public ResourceEntry GetResource(TGI_Key Key)
 {
     return Index.GetResource(Key);
 }
예제 #5
0
        /// <summary>
        /// returns the first composition resource for the package
        /// </summary>
        /// <returns></returns>
        public TGI_Key GetCompositionResource()
        {
            var Keys = GetCompositionResources();

            TGI_Key Result = new TGI_Key(0,0,0);
            int Priority = -1;

            foreach (var Item in Keys)
            {
                if (Item.Value > Priority)
                {
                    Priority = Item.Value;
                    Result = Item.Key;
                }
            }

            return Result;
        }
예제 #6
0
        public ResourceEntry GetResource(TGI_Key Key)
        {
            var Result = from Item in Resources
                         where Item.Key == Key
                         select Item;

            foreach (ResourceEntry Entry in Result)
            {
                return Entry;  // get the first match only
            }

            return null;
        }
예제 #7
0
        private void Import()
        {
            BinaryReader Reader;
            byte[] buffer;            

            // Start by getting the Header :  0x60 bytes at the beginning of the file
            DataStore.Seek (0,SeekOrigin .Begin);

            buffer = new byte[0x60];
            DataStore.Read (buffer,0,0x60);

            
            // Check the Magic
            string Magic = Encoding.ASCII.GetString(buffer, 0, 4);

            if ((Magic != "DBPF") & (Magic != "DBPP"))
            {
                throw new InvalidDataException("Unknown Magic Number: " + Magic);
            }

            if (Magic == "DBPP")
            {
                _IsEncrypted = true;
                throw new InvalidDataException("DBPP Not Supported");
            }

            Reader = new BinaryReader(new MemoryStream(buffer, false));
            Reader.BaseStream.Position = 4;
            
            // Next verify the Major, Minor Versions
            // Major, Minor == 2,0

            uint Major = Reader.ReadUInt32();
            uint Minor = Reader.ReadUInt32();
            uint UMajor = Reader.ReadUInt32();
            uint UMinor = Reader.ReadUInt32();
            uint Flags = Reader.ReadUInt32();
            uint CDate = Reader.ReadUInt32();
            uint MDate = Reader.ReadUInt32();
            uint IMajor = Reader.ReadUInt32();
            uint IndexCount = Reader.ReadUInt32();
            uint IOffset = Reader.ReadUInt32();
            uint IndexLength = Reader.ReadUInt32();
            uint HCount = Reader.ReadUInt32();
            uint HOffset = Reader.ReadUInt32();
            uint HLength = Reader.ReadUInt32();
            uint IMinor = Reader.ReadUInt32();
            uint IndexOffset = Reader.ReadUInt32();

            // Verify Header Values
            if ((Major != 2) | (Minor != 0))
            {
                log.Warn(string.Format("Unknown DBPF Version {0}.{1}, Expected 2.0 -- {2}", Major, Minor,this.FileName));
                throw new InvalidDataException(string.Format("Unknown File Version: {0}.{1}, Expected 2.0", Major, Minor));
            }

            if (((IMajor != 0) & (IMajor != 7)) | (IMinor != 3))
            {
                log.Warn(string.Format("Unknown Index Version {0}.{1}, Expected 0.3 -- {2}", IMajor, IMinor,this.FileName));
                //throw new InvalidDataException(string.Format("Unknown Index Version: {0}.{1}, Expected 0.3", IMajor, IMinor));
            }

            if ((UMajor != 0) | (UMinor != 0) | (Flags != 0) | (CDate != 0) | (MDate != 0) | (HCount != 0) | (HLength != 0))
            {
                log.Warn(string.Format("Unused Header Value not set to 0 -- {0}", this.FileName));
            //    throw new InvalidDataException("Unused header value not 0");
            }

            if ((IOffset != 0) & (IOffset != IndexOffset))
            {
                log.Warn(string.Format("Header Offset mismatch -- Not loadable by Game! -- {0}", this.FileName));
            }
            
            // Now we need to get a new buffer, BinaryReader, etc and read in the Index
            buffer = new byte[IndexLength];
            DataStore.Position = IndexOffset;

            DataStore.Read(buffer, 0, (int)IndexLength);
            Reader = new BinaryReader(new MemoryStream(buffer, false));

            // Vars to hold the info
            UInt32 Type =0;
            UInt32 Group=0;
            UInt64 Instance=0;

            TGI_Key Key;
            ResourceEntry Entry;

            UInt32 ILow = 0xffffffffu;
            UInt32 IHigh = 0xffffffffu;

            UInt32 ChunkOffset;
            UInt32 ChunkLength;
            UInt32 ResourceLength;
            UInt16 ResourceCompression;
            UInt16 ResourceFlag;

            // if we don't have any index entries, just exit
            if (IndexCount == 0)
            {
                log.Info("Empty Package -- No Index Entries");
                return;
            }

            // Now we get the index type
            uint IndexBits = Reader.ReadUInt32();

            // Test Package Index Type :::
            //
            int CommonCount = 0;
            if ((IndexBits & 0x0001) == 0x0001)
            {
                CommonCount += 4;
            }
            if ((IndexBits & 0x0002) == 0x0002)
            {
                CommonCount += 4;
            }
            if ((IndexBits & 0x0004) == 0x0004)
            {
                CommonCount += 4;
            }
            if ((IndexBits & 0x0008) == 0x0008)
            {
                CommonCount += 4;
            }

            

            int BlockLength = CommonCount + 4;
            BlockLength += (32 - CommonCount) * (int)IndexCount;

            if (BlockLength != IndexLength)
            {
                log.Warn(string.Format("DBPF Format Error, IndexType vs IndexSize mismatch: Actual Size {0}, Calculated Size {1}, IndexType {2} -- {3}", IndexLength, BlockLength,IndexBits,this.FileName));
                throw new InvalidDataException("DBPF Format Error, IndexType vs IndexSize mismatch");          
            }



            if ((IndexBits | 0x000f) != 0x000f )
            {
                log.Fatal("Import not implemented");
                throw new NotImplementedException();           
            }

            if ((IndexBits & 0x00000001) == 0x00000001)
            {
                Type = Reader.ReadUInt32();
            }

            if ((IndexBits & 0x00000002) == 0x00000002)
            {
                Group = Reader.ReadUInt32();
            }

            if ((IndexBits & 0x00000004) == 0x00000004)
            {
                ILow = Reader.ReadUInt32();
            }

            if ((IndexBits & 0x00000008) == 0x00000008)
            {
                IHigh = Reader.ReadUInt32();             


            }

            // now we cycle through each of the entries
            for (int i = 0; i < IndexCount; i++)
            {
                // Get the Variable Portion
                if ((IndexBits & 0x00000001) == 0x00000000)
                {
                    Type = Reader.ReadUInt32();
                }

                if ((IndexBits & 0x00000002) == 0x00000000)
                {
                    Group = Reader.ReadUInt32();
                }

                if ((IndexBits & 0x00000004) == 0x00000000)
                {
                    ILow = Reader.ReadUInt32();
                }
                if ((IndexBits & 0x000000008) == 0x00000000)
                {
                    IHigh = Reader.ReadUInt32();
                }

                Instance = (UInt64)IHigh | ((UInt64)ILow << 32);

                // Get the static part
                ChunkOffset = Reader.ReadUInt32();
                ChunkLength = Reader.ReadUInt32() & 0x7fffffff;
                ResourceLength = Reader.ReadUInt32();
                ResourceCompression = Reader.ReadUInt16();
                ResourceFlag = Reader.ReadUInt16();

                // Build the Key and the Entry
                Key = new TGI_Key(Type, Group, Instance);

                Entry = new ResourceEntry(DataStore, Key, (long)ChunkOffset, (int)ChunkLength, (int)ResourceLength, ResourceCompression == 0xffff, IsEncrypted);

                Resources.Add(Entry);
            }
        }
예제 #8
0
        public bool ContainsKey(TGI_Key Key)
        {
            return Keys.Contains(Key);

            //foreach (SimIndexEntry Entry in Entries)
            //{
            //    if (Entry.SIME == Key)
            //    {
            //        return true;
            //    }
            //}
            //return false;
        }
예제 #9
0
 private void WriteKey(TGI_Key Key, BinaryWriter Writer)
 {
     Writer.Write(Key.Type);
     Writer.Write(Key.Group);
     Writer.Write(Key.Instance);
 }
예제 #10
0
 public ResourceList(TGI_Key Key)
 {
     List = new Dictionary<int, ResourceEntry>();
     Duplicates = new List<ResourceEntry>();
     this.Key = Key;
 }
예제 #11
0
        void Import(Stream Source)
        {
            Traits = new List<UInt64>();
            // Setup the exportable reader
            TGITable = new List<TGI_Key>();
            BinaryReader Reader = new BinaryReader(Source);

            UInt16 Version = Reader.ReadUInt16();
            UInt16 TGICount = Reader.ReadUInt16();

            for (int i = 0; i < TGICount; i++)
            {
                UInt64 Instance = Reader.ReadUInt64();
                UInt32 Group = Reader.ReadUInt32();
                UInt32 Type = Reader.ReadUInt32();
                TGI_Key temp = new TGI_Key(Type, Group, Instance);

                TGITable.Add(temp);
            }

            UInt16 Unknown1 = Reader.ReadUInt16();
            UInt32 ExportableSize = Reader.ReadUInt32();

            ExportableReader EReader = new ExportableReader(Reader.ReadBytes((int)ExportableSize));

            byte[] Unknown2 = Reader.ReadBytes(5);

            // now get the values
            SimFlags = EReader.ReadUint32(0x68cdf632);
            DefaultOutfitKey = EReader.ReadInt32(0xf93356ee);
            FirstName = EReader.ReadString(0xeb5173a0);
            LastName = EReader.ReadString(0x7047cb14);
            FavoriteColor = EReader.ReadUint32(0x90254f2f);
            FavoriteFood = EReader.ReadUint32(0x35f0b67e);
            FavoriteMusic = EReader.ReadUint32(0x1672cf33);
            try { ZodiacSign = EReader.ReadUint32(0xa84edf4); }
            catch (KeyNotFoundException) { ZodiacSign = 0xff; }

            LifeTimeWish = EReader.ReadUint32(0x84205551);

            UInt32 TraitCount;
            try
            {
                TraitCount = EReader.ReadUint32(0x5b6a3bbd);
                UInt64[] TraitTemp = EReader.ReadUInt64List(0x6979b0fb);

                foreach (UInt64 Trait in TraitTemp)
                {
                    Traits.Add(Trait);
                }
            }
            catch (KeyNotFoundException) { TraitCount = 0; }


            if (Biography == "")
            {
                Biography = "Test Bio";
            }
       
        }
예제 #12
0
        private void Import(Stream Source)
        {
            BinaryReader Reader = new BinaryReader(Source);
            // Read the DepList from the Stream and create the appropriate DepListEntries...

            // Get the Count
            UInt32 Count = Reader.ReadUInt32().Swap();

            DepListEntry Entry;

            for (int i = 0; i < Count; i++)
            {
                // Read the Signature

                byte[] sig = Reader.ReadBytes(5);

                // Next get DependencyCount and ResourceCount
                UInt32 DependencyCount = Reader.ReadUInt32().Swap();
                UInt32 ResourceCount = Reader.ReadUInt32().Swap();

                TS3GUID PackageID = new TS3GUID(Reader.ReadBytes(16));

                Entry = new DepListEntry(PackageID);

                // Now read the Dependencies
                for (int j = 0; j < DependencyCount; j++)
                {
                    Entry.AddDependency(new TS3GUID(Reader.ReadBytes(16)));
                }

                // Now read the Entry Type and Sub Type
                Entry.SetPackageType(Reader.ReadUInt32().Swap(), Reader.ReadUInt32().Swap());
                UInt16 unknown01 = Reader.ReadUInt16();


                UInt32 Type;
                UInt32 Group;
                UInt32 InstLo;
                UInt32 InstHi;
                UInt64 Inst;

                // Now read the Resource Keys
                for (int j = 0; j < ResourceCount; j++)
                {
                    Type = Reader.ReadUInt32().Swap();
                    Group = Reader.ReadUInt32().Swap();
                    InstLo = Reader.ReadUInt32().Swap();
                    InstHi = Reader.ReadUInt32().Swap();
                    Inst = (UInt64)(InstLo + ((UInt64)InstHi << 32));

                    TGI_Key Key1 = new TGI_Key(Type, Group, Inst);


                    Type = Reader.ReadUInt32().Swap();
                    Group = Reader.ReadUInt32().Swap();
                    InstLo = Reader.ReadUInt32().Swap();
                    InstHi = Reader.ReadUInt32().Swap();
                    Inst = (UInt64)(InstLo + ((UInt64)InstHi << 32));
                    TGI_Key Key2 = new TGI_Key(Type, Group, Inst);

                    Entry.AddResource(Key1, Key2);
                }

                // Next, read the String Length and the String
                int NameCount = (int)Reader.ReadUInt32().Swap();
                                
                Entry.Name = Encoding.BigEndianUnicode.GetString(Reader.ReadBytes(NameCount * 2));

                Reader.ReadBytes(4);  // skip the gap at the end of the String

                Type = Reader.ReadUInt32().Swap();
                Group = Reader.ReadUInt32().Swap();
                InstLo = Reader.ReadUInt32().Swap();
                InstHi = Reader.ReadUInt32().Swap();
                Inst = (UInt64)(InstLo + ((UInt64)InstHi << 32));
                Entry.Thumbnail = new TGI_Key(Type, Group, Inst);
                Console.WriteLine(Entry.Thumbnail);

                UInt32 ExtraLen;
                byte Flags = Reader.ReadByte();
                // Get the flag

                do
                {
                    
                    ExtraLen = Reader.ReadUInt32().Swap();

                    if (ExtraLen != 0)
                    {
                        Entry.AddExtraData (Encoding.ASCII.GetString(Reader.ReadBytes((int)ExtraLen)));
                    }
                }
                while (ExtraLen != 0);
                Entries.Add(Entry.PackageID, Entry);
            }

        }
예제 #13
0
        public ResourceEntry GetResource(TGI_Key Key)
        {
            if (!ResourceData.ContainsKey (Key))
                throw new ArgumentException ();

            return ResourceData[Key].Value;
        }
예제 #14
0
 public void SetThumbnail (TGI_Key Thumbnail)
 {
     this.Thumbnail = Thumbnail;
 }
예제 #15
0
 public SimIndexEntry(TS3GUID GUID, TGI_Key SIME)
 {
     this.GUID = GUID;
     this.SIME = SIME;
 }