The database-packed file (DBPF) is a format used to store data for pretty much all Maxis games after The Sims, including The Sims Online (the first appearance of this format), SimCity 4, The Sims 2, Spore, The Sims 3, and SimCity 2013.
Inheritance: IDisposable
Example #1
0
        public static DBPFFile LoadResource(string file, bool isDownload = false)
        {
            var res = new DBPFFile();

            res.fname = file;
            var stream = File.OpenRead(file);

            res.Read(stream, true, isDownload);
            return(res);
        }
Example #2
0
        /// <summary>
        /// Gets a Hitlist from a DBPF using its InstanceID.
        /// </summary>
        /// <param name="InstanceID">The InstanceID of the Hitlist.</param>
        /// <param name="dbpf">The DBPF to search.</param>
        /// <returns>A Hitlist instance.</returns>
        private Hitlist GetHitlistFrom(uint InstanceID, DBPFFile dbpf)
        {
            var hit = dbpf.GetItemByID((ulong)DBPFTypeID.HIT + (((ulong)InstanceID) << 32));
            if (hit != null) return new Hitlist(hit);

            return null;
        }
Example #3
0
        /// <summary>
        /// Gets a audio file from a DBPF using its InstanceID.
        /// </summary>
        /// <param name="InstanceID">The InstanceID of the audio.</param>
        /// <param name="dbpf">The DBPF to search.</param>
        /// <returns>The audio as a stream of bytes.</returns>
        private byte[] GetAudioFrom(uint InstanceID, DBPFFile dbpf)
        {
            if (InstanceID == 0)
                return null;

            //all game sfx has type id 0x2026960B
            byte[] dat = dbpf.GetItemByID((ulong)DBPFTypeID.SoundFX + (((ulong)InstanceID)<<32));

            if (dat != null)
            {
                string head = new string(new char[] { (char)dat[0], (char)dat[1], (char)dat[2], (char)dat[3] });
                if (head.StartsWith("XA"))
                    return new XAFile(dat).DecompressedData;
                else if (head.StartsWith("UTM0"))
                {
                    var utk = new UTKFile2(dat);
                    utk.UTKDecode();
                    return utk.DecompressedWav;
                }
                else
                    return dat; //either wav or mp3.
            }
            else
                Debug.WriteLine("Couldn't find sound!");
            return null;
        }
Example #4
0
 /// <summary>
 /// Gets a track from a DBPF using its InstanceID.
 /// </summary>
 /// <param name="dbpf">The DBPF to search.</param>
 private void AddTracksFrom(DBPFFile dbpf)
 {
     var tracks = dbpf.GetItemsByType(DBPFTypeID.TRK);
     for (var i=0; i<tracks.Count; i++)
     {
         TracksById.Add(tracks[i].Key, new Track(tracks[i].Value));
     }
 }
Example #5
0
        /// <summary>
        /// Initializes the audio manager.
        /// </summary>
        public void Init()
        {
            this.Stations = new List<AudioReference>();
            this.StationsById = new Dictionary<uint, AudioReference>();
            this.Modes = new List<AudioReference>();

            var stationsRegEx = new Regex(@"music/stations/.*\.mp3");

            foreach (var file in ContentManager.AllFiles)
            {
                if (stationsRegEx.IsMatch(file))
                {
                    var reference = new AudioReference { Type = AudioType.RADIO_STATION, FilePath = ContentManager.GetPath(file) };
                    Stations.Add(reference);
                    var idString = Path.GetFileNameWithoutExtension(file);
                    idString = idString.Substring(idString.LastIndexOf("_") + 1);
                    var id = Convert.ToUInt32(idString, 16);
                    reference.ID = id;
                    StationsById.Add(id, reference);
                }
            }

            TSOAudio = new DBPFFile(ContentManager.GetPath("TSOAudio.dat"));
            tsov2 = new DBPFFile(ContentManager.GetPath("tsov2.dat"));
            Stings = new DBPFFile(ContentManager.GetPath("Stings.dat"));
            EP5Samps = new DBPFFile(ContentManager.GetPath("EP5Samps.dat"));
            EP2 = new DBPFFile(ContentManager.GetPath("EP2.dat"));
            Hitlists = new DBPFFile(ContentManager.GetPath("HitListsTemp.dat"));

            SFXCache = new Dictionary<uint, SoundEffect>();
            TracksById = new Dictionary<uint, Track>();
            HitlistsById = new Dictionary<uint, Hitlist>();

            AddTracksFrom(TSOAudio);
        }
Example #6
0
 public DBPFReference(byte[] bytes, DBPFFile file)
 {
     this.fileBytes = bytes;
     this.file      = file;
 }