Esempio n. 1
0
 private void CreateWriter()
 {
     if (_fileWriter == null && ProfileManager.Current != null && ProfileManager.Current.SaveJournalToFile)
     {
         try
         {
             string path = FileSystemHelper.CreateFolderIfNotExists(Path.Combine(CUOEnviroment.ExecutablePath, "Data"), "Client", "JournalLogs");
             _fileWriter = new StreamWriter(File.Open(Path.Combine(path, $"{DateTime.Now:yyyy_MM_dd_HH_mm_ss}_journal.txt"), FileMode.Create, FileAccess.Write, FileShare.Read))
             {
                 AutoFlush = true
             };
             try
             {
                 string[] files = Directory.GetFiles(path, "*_journal.txt");
                 Array.Sort <string>(files);
                 for (int i = files.Length - 1; i >= 100; --i)
                 {
                     File.Delete(files[i]);
                 }
             }
             catch { }
         }
         catch (Exception ex)
         {
             Log.Error(ex.ToString());
             // we don't want to wast time.
             _writerHasException = true;
         }
     }
 }
Esempio n. 2
0
        public static void Load(string language)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Language");


            string fileToLoad = Path.Combine(path, language);

            if (!File.Exists(fileToLoad))
            {
                Current = new Language();
            }
            else
            {
                Current = ConfigurationResolver.Load <Language>(fileToLoad,
                                                                new JsonSerializerSettings
                {
                    TypeNameHandling         = TypeNameHandling.All,
                    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
                });
                if (Current == null)
                {
                    Current = new Language();
                }
            }
        }
Esempio n. 3
0
        public void Save(List <Gump> gumps = null)
        {
            if (string.IsNullOrEmpty(ServerName))
            {
                throw new InvalidDataException();
            }

            if (string.IsNullOrEmpty(Username))
            {
                throw new InvalidDataException();
            }

            if (string.IsNullOrEmpty(CharacterName))
            {
                throw new InvalidDataException();
            }

            string path = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username, ServerName, CharacterName);

            Log.Message(LogTypes.Trace, $"Saving path:\t\t{path}");

            // save settings.json
            ConfigurationResolver.Save(this, Path.Combine(path, "profile.json"), new JsonSerializerSettings
            {
                TypeNameHandling         = TypeNameHandling.All,
                MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
            });

            // save gumps.bin
            SaveGumps(path, gumps);

            Log.Message(LogTypes.Trace, "Saving done!");
        }
Esempio n. 4
0
        public void Save(List <Gump> gumps = null)
        {
            if (string.IsNullOrEmpty(ServerName))
            {
                throw new InvalidDataException();
            }
            if (string.IsNullOrEmpty(Username))
            {
                throw new InvalidDataException();
            }
            if (string.IsNullOrEmpty(CharacterName))
            {
                throw new InvalidDataException();
            }

            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", Username, ServerName, CharacterName);

            Log.Message(LogTypes.Trace, $"Saving path:\t\t{path}");

            // save settings.json
            ConfigurationResolver.Save(this, Path.Combine(path, "settings.json"));

            // save gumps.bin
            SaveGumps(path, gumps);

            Log.Message(LogTypes.Trace, "Saving done!");
        }
Esempio n. 5
0
        public static void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Data", "Profiles", username, servername, charactername);



            string fileToLoad = Path.Combine(path, "profile.json");

            if (!File.Exists(fileToLoad))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(fileToLoad);
                if (Current == null)
                {
                    Current = new Profile(username, servername, charactername);
                }
                else
                {
                    Current.Username      = username;
                    Current.ServerName    = servername;
                    Current.CharacterName = charactername;
                }
            }

            ValidateFields(Current);

            ProfileLoaded?.Invoke();
        }
Esempio n. 6
0
        public static void Load(string servername, string username, string charactername)
        {
            string rootpath;

            if (string.IsNullOrWhiteSpace(Settings.GlobalSettings.ProfilesPath))
            {
                rootpath = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Profiles");
            }
            else
            {
                rootpath = Settings.GlobalSettings.ProfilesPath;
            }

            string path       = FileSystemHelper.CreateFolderIfNotExists(rootpath, username, servername, charactername);
            string fileToLoad = Path.Combine(path, "profile.json");

            ProfilePath    = path;
            CurrentProfile = ConfigurationResolver.Load <Profile>(fileToLoad) ?? new Profile();

            CurrentProfile.Username      = username;
            CurrentProfile.ServerName    = servername;
            CurrentProfile.CharacterName = charactername;

            ValidateFields(CurrentProfile);
        }
Esempio n. 7
0
        public void Save(List <Gump> gumps = null)
        {
            if (string.IsNullOrEmpty(ServerName))
            {
                throw new InvalidDataException();
            }

            if (string.IsNullOrEmpty(Username))
            {
                throw new InvalidDataException();
            }

            if (string.IsNullOrEmpty(CharacterName))
            {
                throw new InvalidDataException();
            }

            string path = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username.Trim(), ServerName.Trim(), CharacterName.Trim());

            Log.Trace($"Saving path:\t\t{path}");

            // Save profile settings
            ConfigurationResolver.Save(this, Path.Combine(path, "profile.json"));

            // Save opened gumps
            SaveGumps(path, gumps);

            Log.Trace("Saving done!");
        }
Esempio n. 8
0
        public static void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Data", "Profiles", username, servername, charactername);



            string fileToLoad = Path.Combine(path, "profile.json");

            if (!File.Exists(fileToLoad))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(fileToLoad,
                                                               new JsonSerializerSettings
                {
                    TypeNameHandling         = TypeNameHandling.All,
                    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
                });
                if (Current == null)
                {
                    Current = new Profile(username, servername, charactername);
                }
                else
                {
                    Current.Username      = username;
                    Current.ServerName    = servername;
                    Current.CharacterName = charactername;
                }
            }
        }
Esempio n. 9
0
        private void TakeScreenshot()
        {
            string screenshotsFolder = FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Data", "Client", "Screenshots");

            string path = Path.Combine(screenshotsFolder, $"screenshot_{DateTime.Now:yyyy-MM-dd_hh-mm-ss}.png");

            Color[] colors = new Color[GraphicManager.PreferredBackBufferWidth * GraphicManager.PreferredBackBufferHeight];

            GraphicsDevice.GetBackBufferData(colors);

            using (Texture2D texture = new Texture2D
                                       (
                       GraphicsDevice,
                       GraphicManager.PreferredBackBufferWidth,
                       GraphicManager.PreferredBackBufferHeight,
                       false,
                       SurfaceFormat.Color
                                       ))
                using (FileStream fileStream = File.Create(path))
                {
                    texture.SetData(colors);
                    texture.SaveAsPng(fileStream, texture.Width, texture.Height);
                    string message = string.Format(ResGeneral.ScreenshotStoredIn0, path);

                    if (ProfileManager.CurrentProfile == null || ProfileManager.CurrentProfile.HideScreenshotStoredInMessage)
                    {
                        Log.Info(message);
                    }
                    else
                    {
                        GameActions.Print(message, 0x44, MessageType.System);
                    }
                }
        }
Esempio n. 10
0
        public List <Gump> ReadGumps()
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", Username, ServerName, CharacterName);

            string binpath = Path.Combine(path, "gumps.bin");

            if (!File.Exists(binpath))
            {
                return(null);
            }

            List <Gump> gumps = new List <Gump>();

            using (BinaryReader reader = new BinaryReader(File.OpenRead(binpath)))
            {
                if (reader.BaseStream.Position + 12 < reader.BaseStream.Length)
                {
                    uint version = reader.ReadUInt32();
                    uint empty   = reader.ReadUInt32();

                    int count = reader.ReadInt32();

                    for (int i = 0; i < count; i++)
                    {
                        try
                        {
                            int    typeLen  = reader.ReadUInt16();
                            string typeName = reader.ReadUTF8String(typeLen);
                            int    x        = reader.ReadInt32();
                            int    y        = reader.ReadInt32();

                            Type type = Type.GetType(typeName, true);
                            Gump gump = (Gump)Activator.CreateInstance(type);
                            gump.Initialize();
                            gump.Restore(reader);
                            gump.X = x;
                            gump.Y = y;

                            if (gump.LocalSerial != 0)
                            {
                                Engine.UI.SavePosition(gump.LocalSerial, new Point(x, y));
                            }

                            if (!gump.IsDisposed)
                            {
                                gumps.Add(gump);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Message(LogTypes.Error, e.Message);
                        }
                    }
                }
            }

            return(gumps);
        }
Esempio n. 11
0
        public void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", username, servername, charactername);



            // FIXME: this is a temporary patch to change the profile settings name safety
            string fileToLoad = Path.Combine(path, "settings.json");
            string newPath    = Path.Combine(path, "profile.json");

            if (File.Exists(newPath))
            {
                if (File.Exists(fileToLoad))
                {
                    try
                    {
                        File.Delete(fileToLoad);
                    }
                    catch (Exception)
                    {
                        Log.Message(LogTypes.Warning, $"Failed to delete file: '{fileToLoad}'");
                    }
                }

                fileToLoad = newPath;
            }
            //



            if (!File.Exists(fileToLoad))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(fileToLoad,
                                                               new JsonSerializerSettings
                {
                    TypeNameHandling         = TypeNameHandling.All,
                    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
                });
                if (Current == null)
                {
                    Current = new Profile(username, servername, charactername);
                }
                else
                {
                    Current.Username      = username;
                    Current.ServerName    = servername;
                    Current.CharacterName = charactername;
                }
            }
        }
Esempio n. 12
0
        public void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", username, servername, charactername);

            if (!File.Exists(Path.Combine(path, "settings.json")))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(Path.Combine(path, "settings.json")) ?? new Profile(username, servername, charactername);
            }
        }
Esempio n. 13
0
        public void Load(string servername, string username, string charactername)
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(Engine.ExePath, "Data", "Profiles", username, servername, charactername);

            if (!File.Exists(Path.Combine(path, Engine.SettingsFile)))
            {
                Current = new Profile(username, servername, charactername);
            }
            else
            {
                Current = ConfigurationResolver.Load <Profile>(Path.Combine(path, Engine.SettingsFile),
                                                               new JsonSerializerSettings()
                {
                    TypeNameHandling         = TypeNameHandling.All,
                    MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
                }) ?? new Profile(username, servername, charactername);
            }
        }
Esempio n. 14
0
        private void CreateWriter()
        {
            if (_fileWriter == null && ProfileManager.Current.SaveJournalToFile)
            {
                try
                {
                    string path = FileSystemHelper.CreateFolderIfNotExists(Path.Combine(CUOEnviroment.ExecutablePath, "Data"), "Client", "JournalLogs");
                    path = Path.Combine(path, $"{DateTime.Now:yyyy_MM_dd_HH_mm_ss}_journal.txt");

                    _fileWriter = new StreamWriter(File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        AutoFlush = true
                    };
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                    // we don't want to wast time.
                    _writerHasException = true;
                }
            }
        }
Esempio n. 15
0
        private static void LogPacket(byte[] buffer, int length, bool toServer)
        {
            if (_logFile == null)
            {
                _logFile = new LogFile(FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Logs", "Network"), "packets.log");
            }

            Span <char>        span   = stackalloc char[256];
            ValueStringBuilder output = new ValueStringBuilder(span);
            {
                int off = sizeof(ulong) + 2;

                output.Append(' ', off);
                output.Append(string.Format("Ticks: {0} | {1} |  ID: {2:X2}   Length: {3}\n", Time.Ticks, (toServer ? "Client -> Server" : "Server -> Client"), buffer[0], length));

                if (buffer[0] == 0x80 || buffer[0] == 0x91)
                {
                    output.Append(' ', off);
                    output.Append("[ACCOUNT CREDENTIALS HIDDEN]\n");
                }
                else
                {
                    output.Append(' ', off);
                    output.Append("0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F\n");

                    output.Append(' ', off);
                    output.Append("-- -- -- -- -- -- -- --  -- -- -- -- -- -- -- --\n");

                    ulong address = 0;

                    for (int i = 0; i < length; i += 16, address += 16)
                    {
                        output.Append($"{address:X8}");

                        for (int j = 0; j < 16; ++j)
                        {
                            if ((j % 8) == 0)
                            {
                                output.Append(" ");
                            }

                            if (i + j < length)
                            {
                                output.Append($" {buffer[i + j]:X2}");
                            }
                            else
                            {
                                output.Append("   ");
                            }
                        }

                        output.Append("  ");

                        for (int j = 0; j < 16 && i + j < length; ++j)
                        {
                            byte c = buffer[i + j];

                            if (c >= 0x20 && c < 0x80)
                            {
                                output.Append((char)c);
                            }
                            else
                            {
                                output.Append('.');
                            }
                        }

                        output.Append('\n');
                    }
                }

                output.Append('\n');
                output.Append('\n');

                _logFile.Write(output.ToString());

                output.Dispose();
            }
        }
Esempio n. 16
0
        private unsafe int HandleSDLEvent(IntPtr userdata, IntPtr ptr)
        {
            SDL_Event *e = (SDL_Event *)ptr;

            switch (e->type)
            {
            case SDL.SDL_EventType.SDL_AUDIODEVICEADDED:
                Console.WriteLine("AUDIO ADDED: {0}", e->adevice.which);

                break;

            case SDL.SDL_EventType.SDL_AUDIODEVICEREMOVED:
                Console.WriteLine("AUDIO REMOVED: {0}", e->adevice.which);

                break;


            case SDL.SDL_EventType.SDL_WINDOWEVENT:

                switch (e->window.windowEvent)
                {
                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER:
                    Mouse.MouseInWindow = true;

                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE:
                    Mouse.MouseInWindow = false;

                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
                    Plugin.OnFocusGained();

                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
                    Plugin.OnFocusLost();

                    break;
                }

                break;

            case SDL.SDL_EventType.SDL_KEYDOWN:

                Keyboard.OnKeyDown(e->key);

                if (Plugin.ProcessHotkeys((int)e->key.keysym.sym, (int)e->key.keysym.mod, true))
                {
                    _ignoreNextTextInput = false;
                    UIManager.KeyboardFocusControl?.InvokeKeyDown(e->key.keysym.sym, e->key.keysym.mod);

                    _scene.OnKeyDown(e->key);
                }
                else
                {
                    _ignoreNextTextInput = true;
                }

                break;

            case SDL.SDL_EventType.SDL_KEYUP:

                Keyboard.OnKeyUp(e->key);
                UIManager.KeyboardFocusControl?.InvokeKeyUp(e->key.keysym.sym, e->key.keysym.mod);
                _scene.OnKeyUp(e->key);
                Plugin.ProcessHotkeys(0, 0, false);

                if (e->key.keysym.sym == SDL_Keycode.SDLK_PRINTSCREEN)
                {
                    string path = Path.Combine(FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Data", "Client", "Screenshots"), $"screenshot_{DateTime.Now:yyyy-MM-dd_hh-mm-ss}.png");

                    using (Stream stream = File.Create(path))
                    {
                        _buffer.SaveAsPng(stream, _buffer.Width, _buffer.Height);

                        GameActions.Print($"Screenshot stored in: {path}", 0x44, MessageType.System);
                    }
                }

                break;

            case SDL.SDL_EventType.SDL_TEXTINPUT:

                if (_ignoreNextTextInput)
                {
                    break;
                }

                string s = StringHelper.ReadUTF8(e->text.text);

                if (!string.IsNullOrEmpty(s))
                {
                    UIManager.KeyboardFocusControl?.InvokeTextInput(s);
                    _scene.OnTextInput(s);
                }
                break;

            case SDL.SDL_EventType.SDL_MOUSEMOTION:
                Mouse.Update();

                if (Mouse.IsDragging)
                {
                    UIManager.OnMouseDragging();
                    _scene.OnMouseDragging();
                }

                if (Mouse.IsDragging && !_dragStarted)
                {
                    _dragStarted = true;
                }

                break;

            case SDL.SDL_EventType.SDL_MOUSEWHEEL:
                Mouse.Update();
                bool isup = e->wheel.y > 0;

                Plugin.ProcessMouse(0, e->wheel.y);

                UIManager.OnMouseWheel(isup);
                _scene.OnMouseWheel(isup);

                break;

            case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
            case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                Mouse.Update();
                bool isDown = e->type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN;

                if (_dragStarted && !isDown)
                {
                    _dragStarted = false;
                }

                SDL.SDL_MouseButtonEvent mouse = e->button;

                switch ((uint)mouse.button)
                {
                case SDL_BUTTON_LEFT:

                    if (isDown)
                    {
                        Mouse.Begin();
                        Mouse.LButtonPressed    = true;
                        Mouse.LDropPosition     = Mouse.Position;
                        Mouse.CancelDoubleClick = false;
                        uint ticks = Time.Ticks;

                        if (Mouse.LastLeftButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks)
                        {
                            Mouse.LastLeftButtonClickTime = 0;

                            bool res = UIManager.ValidForDClick() ? UIManager.OnLeftMouseDoubleClick() : _scene.OnLeftMouseDoubleClick();

                            if (!res)
                            {
                                _scene.OnLeftMouseDown();
                                UIManager.OnLeftMouseButtonDown();
                            }
                            else
                            {
                                Mouse.LastLeftButtonClickTime = 0xFFFF_FFFF;
                            }

                            break;
                        }

                        _scene.OnLeftMouseDown();
                        UIManager.OnLeftMouseButtonDown();

                        Mouse.LastLeftButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks;
                    }
                    else
                    {
                        if (Mouse.LastLeftButtonClickTime != 0xFFFF_FFFF)
                        {
                            if (!UIManager.HadMouseDownOnGump(MouseButtonType.Left))
                            {
                                _scene.OnLeftMouseUp();
                            }
                            UIManager.OnLeftMouseButtonUp();
                        }
                        Mouse.LButtonPressed = false;
                        Mouse.End();
                    }

                    break;

                case SDL_BUTTON_MIDDLE:

                    if (isDown)
                    {
                        Mouse.Begin();
                        Mouse.MButtonPressed    = true;
                        Mouse.MDropPosition     = Mouse.Position;
                        Mouse.CancelDoubleClick = false;
                        uint ticks = Time.Ticks;

                        if (Mouse.LastMidButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks)
                        {
                            Mouse.LastMidButtonClickTime = 0;

                            if (!_scene.OnMiddleMouseDoubleClick())
                            {
                                _scene.OnMiddleMouseDown();
                                UIManager.OnMiddleMouseButtonDown();
                            }

                            break;
                        }

                        Plugin.ProcessMouse(e->button.button, 0);

                        _scene.OnMiddleMouseDown();
                        UIManager.OnMiddleMouseButtonDown();

                        Mouse.LastMidButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks;
                    }
                    else
                    {
                        if (Mouse.LastMidButtonClickTime != 0xFFFF_FFFF)
                        {
                            if (!UIManager.HadMouseDownOnGump(MouseButtonType.Middle))
                            {
                                _scene.OnMiddleMouseUp();
                            }
                            UIManager.OnMiddleMouseButtonUp();
                        }

                        Mouse.MButtonPressed = false;
                        Mouse.End();
                    }

                    break;

                case SDL_BUTTON_RIGHT:

                    if (isDown)
                    {
                        Mouse.Begin();
                        Mouse.RButtonPressed    = true;
                        Mouse.RDropPosition     = Mouse.Position;
                        Mouse.CancelDoubleClick = false;
                        uint ticks = Time.Ticks;

                        if (Mouse.LastRightButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks)
                        {
                            Mouse.LastRightButtonClickTime = 0;

                            bool res = _scene.OnRightMouseDoubleClick() || UIManager.OnRightMouseDoubleClick();

                            if (!res)
                            {
                                _scene.OnRightMouseDown();
                                UIManager.OnRightMouseButtonDown();
                            }
                            else
                            {
                                Mouse.LastRightButtonClickTime = 0xFFFF_FFFF;
                            }

                            break;
                        }

                        _scene.OnRightMouseDown();
                        UIManager.OnRightMouseButtonDown();

                        Mouse.LastRightButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks;
                    }
                    else
                    {
                        if (Mouse.LastRightButtonClickTime != 0xFFFF_FFFF)
                        {
                            if (!UIManager.HadMouseDownOnGump(MouseButtonType.Right))
                            {
                                _scene.OnRightMouseUp();
                            }
                            UIManager.OnRightMouseButtonUp();
                        }
                        Mouse.RButtonPressed = false;
                        Mouse.End();
                    }

                    break;

                case SDL_BUTTON_X1:
                case SDL_BUTTON_X2:
                    if (isDown)
                    {
                        Mouse.Begin();
                        Mouse.XButtonPressed    = true;
                        Mouse.CancelDoubleClick = false;
                        Plugin.ProcessMouse(e->button.button, 0);
                        _scene.OnExtraMouseDown(mouse.button - 1);
                        UIManager.OnExtraMouseButtonDown(mouse.button - 1);
                    }
                    else
                    {
                        if (!UIManager.HadMouseDownOnGump(MouseButtonType.XButton1) && !UIManager.HadMouseDownOnGump(MouseButtonType.XButton2))
                        {
                            _scene.OnExtraMouseUp(mouse.button - 1);
                        }
                        UIManager.OnExtraMouseButtonUp(mouse.button - 1);

                        Mouse.XButtonPressed = false;
                        Mouse.End();
                    }

                    break;
                }

                break;
            }

            return(0);
        }
Esempio n. 17
0
        public List <Gump> ReadGumps()
        {
            string      path  = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username.Trim(), ServerName.Trim(), CharacterName.Trim());
            List <Gump> gumps = new List <Gump>();



            // #########################################################
            // [FILE_FIX]
            // TODO: this code is a workaround to port old macros to the new xml system.
            string skillsGroupsPath = Path.Combine(path, "skillsgroups.bin");

            if (File.Exists(skillsGroupsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(skillsGroupsPath)))
                    {
                        int version = reader.ReadInt32();

                        int groupCount = reader.ReadInt32();

                        for (int i = 0; i < groupCount; i++)
                        {
                            int    entriesCount = reader.ReadInt32();
                            string groupName    = reader.ReadUTF8String(reader.ReadInt32());

                            SkillsGroup g = new SkillsGroup();
                            g.Name = groupName;

                            for (int j = 0; j < entriesCount; j++)
                            {
                                byte idx = (byte)reader.ReadInt32();
                                g.Add(idx);
                            }

                            g.Sort();

                            SkillsGroupManager.Add(g);
                        }
                    }
                }
                catch (Exception e)
                {
                    SkillsGroupManager.MakeDefault();
                    Log.Error(e.StackTrace);
                }


                SkillsGroupManager.Save();

                try
                {
                    File.Delete(skillsGroupsPath);
                }
                catch { }
            }

            string binpath = Path.Combine(path, "gumps.bin");

            if (File.Exists(binpath))
            {
                using (BinaryReader reader = new BinaryReader(File.OpenRead(binpath)))
                {
                    if (reader.BaseStream.Position + 12 < reader.BaseStream.Length)
                    {
                        GumpsVersion = reader.ReadUInt32();
                        uint empty = reader.ReadUInt32();

                        int count = reader.ReadInt32();

                        for (int i = 0; i < count; i++)
                        {
                            try
                            {
                                int    typeLen  = reader.ReadUInt16();
                                string typeName = reader.ReadUTF8String(typeLen);
                                int    x        = reader.ReadInt32();
                                int    y        = reader.ReadInt32();

                                Type type = Type.GetType(typeName, true);
                                Gump gump = (Gump)Activator.CreateInstance(type);
                                gump.Restore(reader);
                                gump.X = x;
                                gump.Y = y;

                                //gump.SetInScreen();

                                if (gump.LocalSerial != 0)
                                {
                                    UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                                }

                                if (!gump.IsDisposed)
                                {
                                    gumps.Add(gump);
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Error(e.StackTrace);
                            }
                        }
                    }
                }

                SaveGumps(path, gumps);

                gumps.Clear();

                try
                {
                    File.Delete(binpath);
                }
                catch
                {
                }
            }
            // #########################################################



            // load skillsgroup
            //SkillsGroupManager.Load();
            SkillsGroupManager.Load();

            // load gumps
            string gumpsXmlPath = Path.Combine(path, "gumps.xml");

            if (File.Exists(gumpsXmlPath))
            {
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(gumpsXmlPath);
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());

                    return(gumps);
                }

                XmlElement root = doc["gumps"];

                if (root != null)
                {
                    foreach (XmlElement xml in root.GetElementsByTagName("gump"))
                    {
                        try
                        {
                            GUMP_TYPE type   = (GUMP_TYPE)int.Parse(xml.GetAttribute("type"));
                            int       x      = int.Parse(xml.GetAttribute("x"));
                            int       y      = int.Parse(xml.GetAttribute("y"));
                            uint      serial = uint.Parse(xml.GetAttribute("serial"));

                            Gump gump = null;
                            switch (type)
                            {
                            case GUMP_TYPE.GT_BUFF:
                                gump = new BuffGump();
                                break;

                            case GUMP_TYPE.GT_CONTAINER:
                                gump = new ContainerGump();
                                break;

                            case GUMP_TYPE.GT_COUNTERBAR:
                                gump = new CounterBarGump();
                                break;

                            case GUMP_TYPE.GT_HEALTHBAR:
                                if (CustomBarsToggled)
                                {
                                    gump = new HealthBarGumpCustom();
                                }
                                else
                                {
                                    gump = new HealthBarGump();
                                }
                                break;

                            case GUMP_TYPE.GT_INFOBAR:
                                gump = new InfoBarGump();
                                break;

                            case GUMP_TYPE.GT_JOURNAL:
                                gump = new JournalGump();
                                break;

                            case GUMP_TYPE.GT_MACROBUTTON:
                                gump = new MacroButtonGump();
                                break;

                            case GUMP_TYPE.GT_MINIMAP:
                                gump = new MiniMapGump();
                                break;

                            case GUMP_TYPE.GT_PAPERDOLL:
                                gump = new PaperDollGump();
                                break;

                            case GUMP_TYPE.GT_SKILLMENU:
                                if (StandardSkillsGump)
                                {
                                    gump = new StandardSkillsGump();
                                }
                                else
                                {
                                    gump = new SkillGumpAdvanced();
                                }
                                break;

                            case GUMP_TYPE.GT_SPELLBOOK:
                                gump = new SpellbookGump();
                                break;

                            case GUMP_TYPE.GT_STATUSGUMP:
                                switch (Settings.GlobalSettings.ShardType)
                                {
                                default:
                                case 0:         // modern

                                    gump = new StatusGumpModern();

                                    break;

                                case 1:         // old

                                    gump = new StatusGumpOld();

                                    break;

                                case 2:         // outlands

                                    gump = new StatusGumpOutlands();

                                    break;
                                }
                                break;

                            //case GUMP_TYPE.GT_TIPNOTICE:
                            //    gump = new TipNoticeGump();
                            //    break;
                            case GUMP_TYPE.GT_ABILITYBUTTON:
                                gump = new UseAbilityButtonGump();
                                break;

                            case GUMP_TYPE.GT_SPELLBUTTON:
                                gump = new UseSpellButtonGump();
                                break;

                            case GUMP_TYPE.GT_SKILLBUTTON:
                                gump = new SkillButtonGump();
                                break;

                            case GUMP_TYPE.GT_RACIALBUTTON:
                                gump = new RacialAbilityButton();
                                break;

                            case GUMP_TYPE.GT_WORLDMAP:
                                gump = new WorldMapGump();
                                break;
                            }

                            if (gump == null)
                            {
                                continue;
                            }

                            gump.LocalSerial = serial;
                            gump.Restore(xml);
                            gump.X = x;
                            gump.Y = y;

                            if (gump.LocalSerial != 0)
                            {
                                UIManager.SavePosition(gump.LocalSerial, new Point(x, y));
                            }

                            if (!gump.IsDisposed)
                            {
                                gumps.Add(gump);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                        }
                    }
                }
            }


            // load anchors
            string anchorsPath = Path.Combine(path, "anchors.bin");

            if (File.Exists(anchorsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(anchorsPath)))
                        UIManager.AnchorManager.Restore(reader, gumps);
                }
                catch (Exception e)
                {
                    Log.Error(e.StackTrace);
                }
            }


            return(gumps);
        }
Esempio n. 18
0
        public List <Gump> ReadGumps()
        {
            string path = FileSystemHelper.CreateFolderIfNotExists(ProfilePath, Username, ServerName, CharacterName);

            string binpath = Path.Combine(path, "gumps.bin");

            if (!File.Exists(binpath))
            {
                return(null);
            }


            string skillsGroupsPath = Path.Combine(path, "skillsgroups.bin");

            if (File.Exists(skillsGroupsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(skillsGroupsPath)))
                        SkillsGroupManager.Load(reader);
                }
                catch (Exception e)
                {
                    SkillsGroupManager.LoadDefault();
                    Log.Message(LogTypes.Error, e.StackTrace);
                }
            }

            List <Gump> gumps = new List <Gump>();

            using (BinaryReader reader = new BinaryReader(File.OpenRead(binpath)))
            {
                if (reader.BaseStream.Position + 12 < reader.BaseStream.Length)
                {
                    GumpsVersion = reader.ReadUInt32();
                    uint empty = reader.ReadUInt32();

                    int count = reader.ReadInt32();

                    for (int i = 0; i < count; i++)
                    {
                        try
                        {
                            int    typeLen  = reader.ReadUInt16();
                            string typeName = reader.ReadUTF8String(typeLen);
                            int    x        = reader.ReadInt32();
                            int    y        = reader.ReadInt32();

                            Type type = Type.GetType(typeName, true);
                            Gump gump = (Gump)Activator.CreateInstance(type);
                            gump.Initialize();
                            gump.Restore(reader);
                            gump.X = x;
                            gump.Y = y;

                            //gump.SetInScreen();

                            if (gump.LocalSerial != 0)
                            {
                                Engine.UI.SavePosition(gump.LocalSerial, new Point(x, y));
                            }

                            if (!gump.IsDisposed)
                            {
                                gumps.Add(gump);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Message(LogTypes.Error, e.StackTrace);
                        }
                    }
                }
            }


            string anchorsPath = Path.Combine(path, "anchors.bin");

            if (File.Exists(anchorsPath))
            {
                try
                {
                    using (BinaryReader reader = new BinaryReader(File.OpenRead(anchorsPath)))
                        Engine.UI.AnchorManager.Restore(reader, gumps);
                }
                catch (Exception e)
                {
                    Log.Message(LogTypes.Error, e.StackTrace);
                }
            }


            return(gumps);
        }