Beispiel #1
0
        /// <summary>
        /// Xna PreUpdate event callback.
        /// </summary>
        /// <param name="e"></param>
        public static void OnXnaPreUpdate(XnaUpdateEventArgs e)
        {
            // Force the mouse to render..
            Terraria.MainGame.IsMouseVisible = true;

            // Clear current chat text..
            Terraria.SetMainField("chatText", string.Empty);

            // Update the input handler..
            InputHandler.Update();

            // Update the hotkey manager..
            HotkeyManager.ProcessHotkeys();

            // Update the UI manager..
            Detox.GuiManager.Update(e.GameTime);

            // Handle the enter key..
            if (InputHandler.CurrentKeyboard.IsKeyDown(Keys.Enter) && !InputHandler.PreviousKeyboard.IsKeyDown(Keys.Enter) &&
                !Terraria.GetMainField <bool>("editSign"))
            {
                if (Detox.DetoxConsole.Visible && !Detox.DetoxConsole.HasInputFocus)
                {
                    Detox.DetoxConsole.HasInputFocus = true;
                }
                else
                {
                    Detox.DetoxChatWindow.HasInputFocus = !Detox.DetoxChatWindow.HasInputFocus;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Terraria.Main.SetTitle hook callback.
        /// </summary>
        public static void TerrariaSetTitle()
        {
            // Set the new window title..
            var version = Terraria.GetMainField <string>("versionNumber");

            Terraria.MainGame.Window.Title = version;
        }
Beispiel #3
0
        /// <summary>
        /// Xna PostUpdate event callback.
        /// </summary>
        /// <param name="e"></param>
        public static void OnXnaPostUpdate(XnaUpdateEventArgs e)
        {
            // Force the mouse to render..
            Terraria.MainGame.IsMouseVisible = true;

            // Clear the chat text and mode..
            Terraria.SetMainField("chatText", string.Empty);
            Terraria.SetMainField("chatMode", false);

            // Update the UI manager..
            Detox.GuiManager.PostUpdate(e.GameTime);
        }
Beispiel #4
0
        /// <summary>
        /// Xna PostInitialize event callback.
        /// </summary>
        /// <param name="e"></param>
        public static void OnXnaPostInitialize(System.EventArgs e)
        {
            Logging.Instance.Log("[Detox:Xna] OnXnaPostInitialize was called!");

            // Adjust the game resolution per-configurations..
            Terraria.MainGraphics.PreferredBackBufferWidth  = Configurations.Instance.Current.Graphics.StartupWindowWidth;
            Terraria.MainGraphics.PreferredBackBufferHeight = Configurations.Instance.Current.Graphics.StartupWindowHeight;
            Terraria.MainGraphics.ApplyChanges();

            // Prepare the UI manager..
            Detox.GuiManager = new Manager(Terraria.MainGame, Configurations.Instance.Current.Graphics.Skin)
            {
                AutoCreateRenderTarget = true,
                SkinDirectory          = Path.Combine(Detox.DetoxBasePath, "DetoxContent\\Skins\\")
            };
            Detox.GuiManager.Initialize();

            // Prepare the console window..
            Detox.DetoxConsole = new DetoxConsole(Detox.GuiManager);
            Detox.DetoxConsole.Init();
            Detox.DetoxConsole.Visible = false;

            // Prepare the chat window..
            Detox.DetoxChatWindow              = new DetoxChatWindow(Detox.GuiManager);
            Detox.DetoxChatWindow.MessageSent += (sender, args) =>
            {
                Terraria.SetMainField("chatText", string.Empty);
                Terraria.SendMessage(args.Message.Message);
            };
            Detox.DetoxChatWindow.Init();
            Detox.DetoxChatWindow.Visible = true;

            // Register hotkey for toggling the console..
            HotkeyManager.Register("consoleWindowToggle", new List <Keys> {
                Keys.OemTilde
            }, hargs =>
            {
                // Toggle the console if chat does not have focus..
                if (!Detox.DetoxChatWindow.HasInputFocus)
                {
                    Detox.DetoxConsole.Visible = !Detox.DetoxConsole.Visible;
                }

                // Toggle the focus of the console..
                if (!Detox.DetoxConsole.Visible)
                {
                    Detox.DetoxConsole.Focused = false;
                }
            });

            Logging.Instance.Log("[Detox:Xna] OnXnaPostInitialize completed!");
        }
Beispiel #5
0
        /// <summary>
        /// Terraria.Main.Ctor hook callback.
        /// </summary>
        /// <param name="game"></param>
        public static void TerrariaConstructor(Game game)
        {
            Logging.Instance.Log("[Detox:Terraria] Terraria.ctor() was called!");

            // Store the game object..
            Terraria.MainGame = game;

            // Obtain the main graphics object..
            Terraria.MainGraphics = Terraria.GetMainField <GraphicsDeviceManager>("graphics", true);

            // Skip the main splash screen if requested..
            // TODO: Add config option here..
            Terraria.SetMainField("showSplash", false);

            // Adjust the version strings..
            var version = Terraria.GetMainField <string>("versionNumber");

            Terraria.SetMainField("versionNumber", string.Format("Detox Client Mod :: by atom0s -- v{0} :: Terraria {1}", Assembly.GetExecutingAssembly().GetName().Version, version));
            Terraria.SetMainField("versionNumber2", string.Format("Detox Client Mod :: by atom0s -- v{0} :: Terraria {1}", Assembly.GetExecutingAssembly().GetName().Version, version));

            Logging.Instance.Log("[Detox:Terraria] Terraria.ctor() completed!");
        }
Beispiel #6
0
        /// <summary>
        /// Terraria.Main.Update hook callback to block input handling.
        /// </summary>
        public static void TerrariaUpdateBlockInput()
        {
            // Ensure a control is focused..
            if (Detox.GuiManager.FocusedControl == null)
            {
                return;
            }

            // Disable the current mouse state..
            Terraria.SetMainField("mouseState", new MouseState(0, 0, InputHandler.CurrentMouse.ScrollWheelValue, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released));
            Terraria.SetMainField("oldMouseState", new MouseState(0, 0, InputHandler.CurrentMouse.ScrollWheelValue, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released));

            // Disable the mouse data..
            Terraria.SetMainField("mouseLeft", false);
            Terraria.SetMainField("mouseRight", false);
            Terraria.SetMainField("mouseHC", false);
            Terraria.SetMainField("mouseLeftRelease", false);
            Terraria.SetMainField("mouseRightRelease", false);

            // Disable player mouse events..
            DetoxPlayers.LocalPlayer["mouseInterface"] = false;
            DetoxPlayers.LocalPlayer["showItemIcon"]   = false;
            DetoxPlayers.LocalPlayer["showItemIcon2"]  = 0;
        }
Beispiel #7
0
        /// <summary>
        /// Xna PostLoadContent event callback.
        /// </summary>
        /// <param name="e"></param>
        public static void OnXnaPostLoadContent(XnaLoadContentEventArgs e)
        {
            Logging.Instance.Log("[Detox:Xna] OnXnaPostLoadContent was called!");

            // Store the sprite batch object..
            Terraria.MainSpriteBatch = Terraria.GetMainField <SpriteBatch>("spriteBatch", true);

            // Load tiny font for chat..
            Detox.TinyFont = e.Content.Load <SpriteFont>(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\Fonts\\tiny"));

            // Override fonts per-configrations..
            if (Configurations.Instance.Current.CustomObjects.UseCustomFonts)
            {
                // Load ou custom fonts..
                var small  = e.Content.Load <SpriteFont>(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\Fonts\\small"));
                var medium = e.Content.Load <SpriteFont>(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\Fonts\\medium"));
                var large  = e.Content.Load <SpriteFont>(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\Fonts\\large"));
                var huge   = e.Content.Load <SpriteFont>(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\Fonts\\huge"));

                // Set the Terraria fonts..
                Terraria.SetMainField("fontCombatText", new[] { medium, large });
                Terraria.SetMainField("fontDeathText", huge);
                Terraria.SetMainField("fontItemStack", small);
                Terraria.SetMainField("fontMouseText", small);
            }

            // Override hp/mp icons per-configurations..
            if (Configurations.Instance.Current.CustomObjects.UseCustomHpMpIcons)
            {
                using (var hpStream = new FileStream(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\hp.png"), FileMode.Open, FileAccess.Read))
                {
                    var hpTexture = Texture2D.FromStream(Terraria.MainGame.GraphicsDevice, hpStream);
                    Terraria.SetMainField("heartTexture", hpTexture);
                }

                using (var hpStream = new FileStream(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\hp2.png"), FileMode.Open, FileAccess.Read))
                {
                    var hpTexture = Texture2D.FromStream(Terraria.MainGame.GraphicsDevice, hpStream);
                    Terraria.SetMainField("heart2Texture", hpTexture);
                }

                using (var mpStream = new FileStream(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\mp.png"), FileMode.Open, FileAccess.Read))
                {
                    var mpTexture = Texture2D.FromStream(Terraria.MainGame.GraphicsDevice, mpStream);
                    Terraria.SetMainField("manaTexture", mpTexture);
                }
            }

            // Override background textures per-configurations..
            if (Configurations.Instance.Current.CustomObjects.UseCustomBackgrounds)
            {
                // Set the inventory background textures..
                using (var bgStream = new FileStream(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\bg.png"), FileMode.Open, FileAccess.Read))
                {
                    var bg = Texture2D.FromStream(Terraria.MainGame.GraphicsDevice, bgStream);
                    Terraria.SetMainField("inventoryBackTexture", bg);
                    for (var x = 2; x <= 12; x++)
                    {
                        Terraria.SetMainField(string.Format("inventoryBack{0}Texture", x), bg);
                    }
                }

                // Set the npc chat background texture..
                using (var chatBackgroundStream = new FileStream(Path.Combine(Detox.DetoxBasePath, "DetoxContent\\chat_bg.png"), FileMode.Open, FileAccess.Read))
                {
                    var chatBackgroundTexture = Texture2D.FromStream(Terraria.MainGame.GraphicsDevice, chatBackgroundStream);
                    Terraria.SetMainField("chatBackTexture", chatBackgroundTexture);
                }
            }

            // Delete the original Terraria mouse texture..
            var cursorTexture = new Texture2D(Terraria.MainGame.GraphicsDevice, 1, 1);

            cursorTexture.SetData(new[] { Color.Transparent });
            Terraria.SetMainField("cursorTexture", cursorTexture);

            Logging.Instance.Log("[Detox:Xna] OnXnaPostLoadContent completed!");
        }
Beispiel #8
0
 /// <summary>
 /// Sends a chat packet to the server.
 /// </summary>
 /// <param name="text"></param>
 public static void SendMessage(string text)
 {
     Terraria.SendData(PacketTypes.Chat, -1, -1, text);
 }