public UIMessageBox(float X, float Y, string Message, UIScreen Screen, string StrID)
            : base(Screen, StrID, DrawLevel.AlwaysOnTop)
        {
            m_Archive = new FAR3Archive(GlobalSettings.Default.StartupPath + "uigraphics\\dialogs\\dialogs.dat");

            m_X = X;
            m_Y = Y;

            MemoryStream TexStream = new MemoryStream(m_Archive.GetItemByID(0xE5));
            m_DiagBackgrnd = Texture2D.FromFile(Screen.ScreenMgr.GraphicsDevice, TexStream);

            TexStream = new MemoryStream(m_Archive.GetItemByID(0x185));
            m_DiagCorner = Texture2D.FromFile(Screen.ScreenMgr.GraphicsDevice, TexStream);

            TexStream = new MemoryStream(m_Archive.GetItemByID(0x892));
            Texture2D BtnTex = Texture2D.FromFile(Screen.ScreenMgr.GraphicsDevice, TexStream);
            ManualTextureMask(ref BtnTex, new Color(255, 0, 255));

            float Scale = GlobalSettings.Default.ScaleFactor;

            m_OkBtn = new UIButton(((m_X + (m_DiagBackgrnd.Width * Scale) + 94) - (m_DiagCorner.Width * Scale)) * Scale,
                ((m_Y + (m_DiagBackgrnd.Height * Scale) + 37) - (m_DiagCorner.Height * Scale)) * Scale, .15f, .4f, BtnTex, "BtnOK", Screen);
            m_OkBtn.OnButtonClick += new ButtonClickDelegate(m_OkBtn_OnButtonClick);

            m_Message = Message;
        }
        /// <summary>
        /// Constructor for the UITextbox class.
        /// </summary>
        /// <param name="BackgrdID">The ID of the background's texture.</param>
        /// <param name="X">The x-coordinate on the screen of where to draw the textbox.</param>
        /// <param name="Y">The y-coordinate on the screen of where to draw the textbox.</param>
        /// <param name="Width">The width of the textbox in pixels. Should be greater than 39.</param>
        /// <param name="DrawTransparent">Whether or not to draw this textbox transparently.</param>
        /// <param name="Screen">A UIScreen instance.</param>
        /// <param name="StrID">The the string ID of this textbox.</param>
        public UITextbox(uint BackgrdID, int X, int Y, int Width, int Transparency, 
            UIScreen Screen, string StrID)
            : base(Screen, StrID, DrawLevel.DontGiveAFuck)
        {
            m_Archive = new FAR3Archive(GlobalSettings.Default.StartupPath + "uigraphics\\dialogs\\dialogs.dat");

            MemoryStream TexStream = new MemoryStream(m_Archive.GetItemByID(BackgrdID));
            m_BackgroundTex = Texture2D.FromFile(Screen.ScreenMgr.GraphicsDevice, TexStream);

            m_Transparency = Transparency;

            m_X = X;
            m_Y = Y;
            m_CursorDrawX = (m_X + 3);

            //The Width parameter will hopefully always be greater than 39, as the
            //'dialog_textboxbackground.bmp' image is 39x39 pixels.
            if (Width > m_BackgroundTex.Width)
            {
                m_NumTiles = (int)(Width / (m_BackgroundTex.Width + 3));
                //The background consist of one half tile + one third of a tile as many times as m_NumTiles,
                //then another half tile. Therefore the total width equals the calculation below.
                m_Width = (m_NumTiles * 13) + m_BackgroundTex.Width;
                m_Height = m_BackgroundTex.Height;
            }
            else
            {
                //Originally I set m_NumTiles to m_BackgroundTex.Width here, but realized
                //that that would cause f*****g ENDLESS textboxes (39 tiles!!)
                m_NumTiles = Width;
                m_Width = m_BackgroundTex.Width;
                m_Height = m_BackgroundTex.Height;
            }
        }
        static ContentManager()
        {
            m_Archives = new Dictionary<string, FAR3Archive>();
            m_Rand = new Random(0);
            FAR3Archive packingSlips = new FAR3Archive(GlobalSettings.Default.StartupPath + "packingslips\\packingslips.dat");

            List<KeyValuePair<uint, byte[]>> entries = packingSlips.GetAllEntries();

            m_Resources = new Dictionary<ulong, string>();
            foreach (KeyValuePair<uint, byte[]> kvp in entries)
            {
                BinaryReader br = new BinaryReader(new MemoryStream(kvp.Value));
                br.BaseStream.Position = 50;
                string path = br.ReadString();
                br.BaseStream.Position += 8;
                ulong id = Endian.SwapUInt64(br.ReadUInt64());
                m_Resources.Add(id, path);
            }
            initComplete = true;
        }
        public static byte[] GetResourceFromLongID(ulong id)
        {
            while (!initComplete) ;
            if (m_Resources.ContainsKey(id))
            {
                string path = m_Resources[id].Replace("./", "");
                if (!File.Exists(path))
                {
                    string[] pathSections = path.Split(new char[] { '/' });
                    int directoryIdx = 0;
                    if (path.Contains("/heads/") || path.Contains("/hands/") || path.Contains("/bodies/") || path.Contains("/accessories/"))
                        directoryIdx = Array.FindLastIndex<string>(pathSections, delegate(string it) { if (it.CompareTo("avatardata") == 0) { return true; } return false; }) + 2;
                    else
                        directoryIdx = Array.FindLastIndex<string>(pathSections, delegate(string it) { if (it.CompareTo("TSOClient") == 0) { return true; } return false; }) + 2;
                    string directoryName = pathSections[directoryIdx];
                    path = path.Remove(path.LastIndexOf('/'));
                    string archivePath = GlobalSettings.Default.StartupPath + '/' + path.Remove((path.LastIndexOf(pathSections[directoryIdx]))) + directoryName + '/' + directoryName + ".dat";

                    if (!m_Archives.ContainsKey(archivePath))
                    {
                        FAR3Archive archive = new FAR3Archive(archivePath);
                        m_Archives.Add(archivePath, archive);
                        return archive[pathSections[pathSections.Length - 1]];
                    }
                    else
                    {
                        return m_Archives[archivePath].GetItemByID((uint)(id >> 32));
                    }
                }
                else
                {
                    return File.ReadAllBytes(GlobalSettings.Default.StartupPath + path);
                }
            }
            return new byte[0];
        }
        public byte[] this[ulong id]
        {
            get
            {
                if (m_Resources.ContainsKey(id))
                {
                    string path = m_Resources[id].Replace("./", "");
                    if (!File.Exists(path))
                    {
                        string[] pathSections = path.Split(new char[] { '/' });
                        string directoryName = pathSections[pathSections.Length - 2];
                        string archivePath = GlobalSettings.Default.StartupPath + path.Remove(path.LastIndexOf('/') + 1) + directoryName + ".dat";

                        FAR3Archive archive = new FAR3Archive(archivePath);
                        return archive[pathSections[pathSections.Length - 1]];
                    }
                    else
                    {
                        return File.ReadAllBytes(GlobalSettings.Default.StartupPath + path);
                    }
                }
                return new byte[0];
            }
        }
        public byte[] this[ulong FileID]
        {
            get
            {
                byte[] Resource;

                //Resource hasn't already been loaded...
                if (!m_LoadedResources.TryGetValue(FileID, out Resource))
                {
                    string path = m_Resources[FileID].Replace("./", "");
                    if (!File.Exists(path))
                    {
                        string[] pathSections = path.Split(new char[] { '/' });
                        string directoryName = pathSections[pathSections.Length - 2];
                        string archivePath = GlobalSettings.Default.StartupPath + path.Remove(path.LastIndexOf('/') + 1) + directoryName + ".dat";

                        FAR3Archive archive = new FAR3Archive(archivePath);
                        return archive[pathSections[pathSections.Length - 1]];
                    }
                    else
                    {
                        Resource = File.ReadAllBytes(GlobalSettings.Default.StartupPath + path);
                        return Resource;
                    }
                }
                else
                    return Resource;
            }
        }
        public static byte[] GetResourceFromLongID(ulong ID)
        {
            byte[] Resource;

            while (!initComplete) ;
            //Resource hasn't already been loaded...
            if (!m_LoadedResources.TryGetValue(ID, out Resource))
            {
                string path = m_Resources[ID];

                FAR3Archive Archive = new FAR3Archive(path);

                Resource = Archive.GetItemByID(ID);
                return Resource;
            }
            else
                return m_LoadedResources[ID];
        }
        public static ContentResource GetResourceInfo(ulong ID)
        {
            /** Busy wait until we are ready **/
            while (!initComplete) ;

            ContentResource result = null;

            if (!m_LoadedResources.TryGetValue(ID, out result))
            {
                result = new ContentResource
                {
                    ID = ID
                };

                string path = m_Resources[ID];
                result.FilePath = path;
                result.FileExtension = Path.GetExtension(path).ToLower();

                if (!path.EndsWith(".dat"))
                {
                    /** Isnt an archive **/
                    result.Data = File.ReadAllBytes(path);
                    return result;
                }

                if (!m_Archives.ContainsKey(path))
                {
                    FAR3Archive Archive = new FAR3Archive(path);
                    m_Archives.Add(path, Archive);
                }

                result.Data = m_Archives[path].GetItemByID(ID);

                return result;
            }
            else
            {
                return result;
            }
        }
        /// <summary>
        /// Adds files from a specified directory to a dictionary of entries.
        /// </summary>
        /// <param name="EntryDir">The directory to scan for entries.</param>
        /// <param name="Filetype">A fully qualified lowercase filetype to scan for (can be empty).</param>
        /// <param name="Entries">The Dictionary to add entries to.</param>
        private static void AddFilesFromDir(string EntryDir, string Filetype, ref Dictionary<Far3Entry, string> Entries)
        {
            string[] Dirs = Directory.GetDirectories(EntryDir);

            foreach(string Dir in Dirs)
            {
                if (Filetype != "")
                {
                    if (Dir.Contains(Filetype))
                    {
                        string[] Files = Directory.GetFiles(Dir);
                        string[] SubDirs = Directory.GetDirectories(Dir);
                        foreach (string Fle in Files)
                        {
                            if (Fle.Contains(".dat"))
                            {
                                FAR3Archive Archive = new FAR3Archive(Fle);

                                foreach (Far3Entry Entry in Archive.GetAllFAR3Entries())
                                    Entries.Add(Entry, Fle.Replace(GlobalSettings.Default.StartupPath, ""));
                            }
                            else
                            {
                                Far3Entry Entry = new Far3Entry();
                                Entry.Filename = Fle.Replace(GlobalSettings.Default.StartupPath, "");
                                Entry.FileID = HelperFuncs.GetFileID(Entry);
                                Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(Fle));

                                HelperFuncs.CheckCollision(Entry.FileID, Entries);

                                //Ignore fonts to minimize the risk of ID collisions.
                                if (!Entry.Filename.Contains(".ttf"))
                                {
                                    if (!Entry.Filename.Contains(".ffn"))
                                        Entries.Add(Entry, Entry.Filename);
                                }
                            }
                        }

                        foreach (string SubDir in SubDirs)
                        {
                            Files = Directory.GetFiles(SubDir);
                            foreach (string SubFle in Files)
                            {
                                if (SubFle.Contains(".dat"))
                                {
                                    FAR3Archive Archive = new FAR3Archive(SubFle);

                                    foreach (Far3Entry Entry in Archive.GetAllFAR3Entries())
                                        Entries.Add(Entry, SubFle.Replace(GlobalSettings.Default.StartupPath, ""));
                                }
                                else
                                {
                                    Far3Entry Entry = new Far3Entry();
                                    Entry.Filename = SubFle.Replace(GlobalSettings.Default.StartupPath, "");
                                    Entry.FileID = HelperFuncs.GetFileID(Entry);
                                    Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(SubFle));

                                    HelperFuncs.CheckCollision(Entry.FileID, Entries);

                                    //Ignore fonts to minimize the risk of ID collisions.
                                    if (!Entry.Filename.Contains(".ttf"))
                                    {
                                        if (!Entry.Filename.Contains(".ffn"))
                                            Entries.Add(Entry, Entry.Filename);
                                    }
                                }
                            }
                        }
                    }
                }
                else //Filetype was empty, so just add all filetypes found...
                {
                    string[] Files = Directory.GetFiles(Dir);
                    string[] SubDirs = Directory.GetDirectories(Dir);
                    foreach (string Fle in Files)
                    {
                        if (Fle.Contains(".dat"))
                        {
                            FAR3Archive Archive = new FAR3Archive(Fle);

                            foreach (Far3Entry Entry in Archive.GetAllFAR3Entries())
                                Entries.Add(Entry, Fle.Replace(GlobalSettings.Default.StartupPath, ""));
                        }
                        else
                        {
                            Far3Entry Entry = new Far3Entry();
                            Entry.Filename = Fle.Replace(GlobalSettings.Default.StartupPath, "");
                            Entry.FileID = HelperFuncs.GetFileID(Entry);
                            Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(Fle));

                            HelperFuncs.CheckCollision((ulong)(((ulong)Entry.FileID) << 32 | ((ulong)(Entry.TypeID >> 32))), Entries);

                            //Ignore fonts to minimize the risk of ID collisions.
                            if (!Entry.Filename.Contains(".ttf"))
                            {
                                if(!Entry.Filename.Contains(".ffn"))
                                    Entries.Add(Entry, Entry.Filename);
                            }
                        }
                    }

                    foreach (string SubDir in SubDirs)
                    {
                        Files = Directory.GetFiles(SubDir);
                        foreach (string SubFle in Files)
                        {
                            if (SubFle.Contains(".dat"))
                            {
                                FAR3Archive Archive = new FAR3Archive(SubFle);

                                foreach (Far3Entry Entry in Archive.GetAllFAR3Entries())
                                    Entries.Add(Entry, SubFle.Replace(GlobalSettings.Default.StartupPath, ""));
                            }
                            else
                            {
                                Far3Entry Entry = new Far3Entry();
                                Entry.Filename = SubFle.Replace(GlobalSettings.Default.StartupPath, "");
                                Entry.FileID = HelperFuncs.GetFileID(Entry);
                                Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(SubFle));

                                HelperFuncs.CheckCollision((ulong)(((ulong)Entry.FileID) << 32 | ((ulong)(Entry.TypeID >> 32))), Entries);

                                //Ignore fonts to minimize the risk of ID collisions.
                                if (!Entry.Filename.Contains(".ttf"))
                                {
                                    if (!Entry.Filename.Contains(".ffn"))
                                        Entries.Add(Entry, Entry.Filename);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
        public Stream GetResource(string path, ulong assetID)
        {
            if (path.EndsWith(".dat"))
            {
                /** Archive **/
                if (!Archives.ContainsKey(path))
                {
                    FAR3Archive newArchive = new FAR3Archive(GetPath(path));
                    Archives.Add(path, newArchive);
                }

                var archive = Archives[path];
                var bytes = archive.GetItemByID(assetID);
                return new MemoryStream(bytes, false);
            }

            return File.OpenRead(GetPath(path));
        }