Example #1
0
        private static void Main(string[] args)
        {
            try
            {
                Logger.GameIdentifier    = "Terraria";
                Logger.VersionIdentifier = "1.4";
                Logger.Log("Loading store...");
                Entry.Storage = new ModStorage(@"Creative");
                Entry.Store   = new ResourceStore <byte[]>(new StorageBackedResourceStore(Entry.Storage));

                Logger.Storage = Entry.Storage;
                Logger.Level   = LogLevel.Debug;

                Logger.Log("Start pre loading assemblies..");
                AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs sargs)
                {
                    bool   mono         = false;
                    string resourceName = new AssemblyName(sargs.Name).Name + ".dll";
                    string textx        = Array.Find <string>(typeof(Program).Assembly.GetManifestResourceNames(), (string element) => element.EndsWith(resourceName));
                    if (textx == null)
                    {
                        textx = Array.Find <string>(typeof(EntryPoint).Assembly.GetManifestResourceNames(), (string element) => element.EndsWith(resourceName));
                        if (textx == null)
                        {
                            return(null);
                        }

                        mono = true;
                    }
                    Assembly resultt;
                    if (!mono)
                    {
                        using (Stream manifestResourceStream = typeof(Program).Assembly.GetManifestResourceStream(textx))
                        {
                            byte[] array = new byte[manifestResourceStream.Length];
                            manifestResourceStream.Read(array, 0, array.Length);
                            resultt = Assembly.Load(array);
                        }
                    }
                    else
                    {
                        using (Stream manifestResourceStream = typeof(EntryPoint).Assembly.GetManifestResourceStream(textx))
                        {
                            byte[] array = new byte[manifestResourceStream.Length];
                            manifestResourceStream.Read(array, 0, array.Length);
                            resultt = Assembly.Load(array);
                        }
                    }
                    Logger.Log($"Loaded {resultt.FullName}");
                    return(resultt);
                };
                Logger.Log("Finished assemblies pre loading loading");


                //Force load Newtonsoft.Json to memory
                Logger.Log("Force loading Newtonsoft.Json...");
                string   text = Array.Find <string>(typeof(Program).Assembly.GetManifestResourceNames(), (string element) => element.EndsWith("Newtonsoft.Json.dll"));
                Assembly result;
                using (Stream manifestResourceStream = typeof(Program).Assembly.GetManifestResourceStream(text))
                {
                    byte[] array = new byte[manifestResourceStream.Length];
                    manifestResourceStream.Read(array, 0, array.Length);
                    result = AppDomain.CurrentDomain.Load(array);
                    //result = Assembly.Load(array);
                }
                //Newtonsoft.Json.JsonConvert.SerializeObject()
                var s = (string)Reflect.InvokeS(result, "Newtonsoft.Json.JsonConvert", "SerializeObject", new object[] { new List <string> {
                                                                                                                             "Terraria.ModKit", "v0.5"
                                                                                                                         } });
                Console.WriteLine(s);
                Logger.Log("Done! Registering initializer...");
                //Program.LaunchGame(args);
                Terraria.Main.OnEngineLoad += Entry.Initialise;
                Logger.Log("Running game...");
                Reflect.Invoke(typeof(WindowsLaunch), "Main", BindingFlags.Static | BindingFlags.NonPublic,
                               args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.ReadKey();
            }
        }
        //private static REPLTool tools;

        public override void OnInitialize()
        {
            mainPannel = new CheatPannel();
            mainPannel.Left.Set(-(310 / 2), 0.5f);
            mainPannel.Top.Set(-55, 1f);
            mainPannel.Width.Set(310, 0f);
            mainPannel.Height.Set(55f, 0f);
            mainPannel.BackgroundColor = Color.BlanchedAlmond.Opacity(0.3f);
            Append(mainPannel);
            //Main.Assets.Request<Texture2D>(@"Images\UI\Creative\Journey_Toggle");
            var texture = Main.Assets.Request <Texture2D>(@"Images\UI\Creative\Journey_Toggle");
            UIHoverImageButton journeyButton = cycleMode = new UIHoverImageButton(texture, texture.Frame(),
                                                                                  "Toggle journey mode",
                                                                                  () =>
            {
                Entry.CycleMode();

                cycleMode.Color = Main.GameMode == GameModeData.CreativeMode.Id ? Color.Gold : Color.White;
            });

            buttons.Add(journeyButton);
            mainPannel.Append(journeyButton);

            texture       = Main.Assets.Request <Texture2D>(@"Images\Item_493");
            journeyButton = flyMode = new UIHoverImageButton(texture, texture.Frame(), "Toggle Fly mode",
                                                             () =>
            {
                Entry.ChangeFly();
                flyMode.Color = Entry.fly ? Color.Gold : Color.White;
            });
            buttons.Add(journeyButton);
            mainPannel.Append(journeyButton);

            texture = Main.Assets.Request <Texture2D>(@"Images\UI\Creative\Infinite_Powers");
            Point p = CreativePowersHelper.CreativePowerIconLocations.Godmode;

            journeyButton = godMode = new UIHoverImageButton(texture, texture.Frame(21, 1, p.X, p.Y), "God Mode", () =>
            {
                Reflect.Invoke <object>(CreativePowerManager.Instance.GetPower <CreativePowers.GodmodePower>(),
                                        "RequestUse");
                Main.LocalPlayer.creativeGodMode = !Main.LocalPlayer.creativeGodMode;
                godMode.Color = Main.LocalPlayer.creativeGodMode ? Color.Gold : Color.White;
            });
            buttons.Add(journeyButton);
            mainPannel.Append(journeyButton);


            texture       = Main.Assets.Request <Texture2D>(@"Images\UI\WorldCreation\IconDifficultyMaster");
            journeyButton = changeDifficulty = new UIHoverImageButton(texture, texture.Frame(), "Change Difficulty",
                                                                      () =>
            {
                difficultyPannel.Visible = !difficultyPannel.Visible;
                changeDifficulty.Color   = difficultyPannel.Visible ? Color.Gold : Color.White;
            });
            buttons.Add(journeyButton);
            mainPannel.Append(journeyButton);

            texture       = Main.Assets.Request <Texture2D>(@"Images\Item_1315");
            journeyButton = lockOn = new UIHoverImageButton(texture, texture.Frame(), "Reveal map",
                                                            () =>
            {
                if (Main.netMode == 0)
                {
                    Entry.RevealWholeMap();
                }
                else
                {
                    Point center = Main.player[Main.myPlayer].Center.ToTileCoordinates();
                    Entry.RevealAroundPoint(center.X, center.Y);
                }
            });
            buttons.Add(journeyButton);
            mainPannel.Append(journeyButton);

            texture       = Main.Assets.Request <Texture2D>(@"Images\ui\Camera_2");
            journeyButton = copyTools = new UIHoverImageButton(texture, texture.Frame(), "Open Tile Copy Tool",
                                                               () =>
            {
                difficultyPannel.Visible = false;
                Copy.Visible             = !Copy.Visible;
                copyTools.Color          = Copy.Visible ? Color.Gold : Color.White;
            });
            buttons.Add(journeyButton);
            mainPannel.Append(journeyButton);


            texture       = Main.Assets.Request <Texture2D>(@"Images\ui\Settings_Inputs_2");
            journeyButton = new UIHoverImageButton(texture, texture.Frame(2, 2, 1, 0), "Open REPL",
                                                   () =>
            {
                Entry.tools.visible = !Entry.tools.visible;
            });
            buttons.Add(journeyButton);
            mainPannel.Append(journeyButton);


            //var tinker = new UITinker();
            //Append(tinker);


            difficultyPannel = new CheatPannel(65 * 2);
            difficultyPannel.Left.Set((float)Main.screenWidth / 2 - Width.Pixels, 0f);
            difficultyPannel.Top.Set(Main.screenHeight - 65 * 2, 0f);
            difficultyPannel.Width.Set(210, 0f);
            difficultyPannel.Height.Set(55f, 0f);
            difficultyPannel.BackgroundColor = Color.BlanchedAlmond.Opacity(0.3f);
            difficultyPannel.Visible         = false;
            Append(difficultyPannel);

            texture       = Main.Assets.Request <Texture2D>(@"Images\UI\WorldCreation\IconDifficultyCreative");
            journeyButton = new UIHoverImageButton(texture, texture.Frame(), "Journey",
                                                   () =>
            {
                Main.GameMode = GameModeData.CreativeMode.Id;
                Main.LocalPlayer.difficulty = 3;
            });
            journeyButton.Left.Set(0, 0);
            journeyButton.Top.Set(0, 0);
            difficultyPannel.Append(journeyButton);

            texture       = Main.Assets.Request <Texture2D>(@"Images\UI\WorldCreation\IconDifficultyNormal");
            journeyButton = new UIHoverImageButton(texture, texture.Frame(), "Classic",
                                                   () =>
            {
                Main.GameMode = GameModeData.NormalMode.Id;
                Main.LocalPlayer.difficulty = 0;
            });
            journeyButton.Left.Set(50, 0);
            journeyButton.Top.Set(0, 0);
            difficultyPannel.Append(journeyButton);

            texture       = Main.Assets.Request <Texture2D>(@"Images\UI\WorldCreation\IconDifficultyExpert");
            journeyButton = new UIHoverImageButton(texture, texture.Frame(), "Expert",
                                                   () =>
            {
                Main.GameMode = GameModeData.ExpertMode.Id;
                Main.LocalPlayer.difficulty = 0;
            });
            journeyButton.Left.Set(100, 0);
            journeyButton.Top.Set(0, 0);
            difficultyPannel.Append(journeyButton);

            texture       = Main.Assets.Request <Texture2D>(@"Images\UI\WorldCreation\IconDifficultyMaster");
            journeyButton = new UIHoverImageButton(texture, texture.Frame(), "Master",
                                                   () =>
            {
                Main.GameMode = GameModeData.MasterMode.Id;
                Main.LocalPlayer.difficulty = 0;
            });
            journeyButton.Left.Set(150, 0);
            journeyButton.Top.Set(0, 0);
            difficultyPannel.Append(journeyButton);


            int w = 10;

            foreach (var it in buttons)
            {
                it.Left.Set(w, 0f);
                w += 50;
            }
            mainPannel.Width.Set(w, 0f);
            mainPannel.Left.Set(-(w / 2), 0.5f);

            base.OnInitialize();
        }
Example #3
0
        private static void Update()
        {
            if (Main.gameMenu)
            {
                return;
            }

            if (installUI > 0) //Skip some frames before access layers
            {
                installUI--;
                if (installUI == 0)
                {
                    Logger.Log("Installing InterfaceLayer...");
                    var layers = Reflect.GetF <List <GameInterfaceLayer> >(Main.instance, "_gameInterfaceLayers");
                    layers?.Insert(36, new LegacyGameInterfaceLayer("Creative mod: Custom UI", () =>
                    {
                        if (Main.gameMenu)
                        {
                            return(false);
                        }
                        if (Copy.Visible)
                        {
                            ucopy.Draw(Main.spriteBatch, new GameTime());
                            copy.UIDraw();
                        }
                        if (CheatState.Visible)
                        {
                            inter.Draw(Main.spriteBatch, new GameTime());
                        }
                        if (tools.visible)
                        {
                            tools.UIDraw();
                        }

                        return(true);
                    }));
                    Logger.Log("Installing InterfaceLayer done!");
                }
            }

            if (controlsUI == null && Main.InGameUI.CurrentState != null)
            {
                if (Main.InGameUI.CurrentState is UIManageControls ui)
                {
                    Logger.Log("Hijack UIManageControls. Adding own input panel...");
                    controlsUI = ui;
                    try
                    {
                        Logger.Log("Getting \"CreateBindingGroup\" method...");
                        var pan = Reflect.Invoke <UISortableElement>(controlsUI, "CreateBindingGroup", 3,
                                                                     creativeControlsString, InputMode.Keyboard);
                        Logger.Log("Adding new panel to _bindKeyboard...");
                        Reflect.GetF <List <UIElement> >(controlsUI, "_bindsKeyboard").Add(pan);
                        Logger.Log("Adding new panel to _bindKeyboardUI...");
                        Reflect.GetF <List <UIElement> >(controlsUI, "_bindsKeyboardUI").Add(pan);

                        var KeyStatus = PlayerInput.CurrentProfile.InputModes[InputMode.Keyboard].KeyStatus;

                        Logger.Log("Registering new input bindings...");
                        if (!KeyStatus.ContainsKey("CycleMode"))
                        {
                            KeyStatus.Add("CycleMode", new List <string> {
                                CreativeInput[0].ToString()
                            });
                        }
                        if (!KeyStatus.ContainsKey("FlyMode"))
                        {
                            KeyStatus.Add("FlyMode", new List <string> {
                                CreativeInput[1].ToString()
                            });
                        }
                        if (!KeyStatus.ContainsKey("UnlockAllItems"))
                        {
                            KeyStatus.Add("UnlockAllItems", new List <string> {
                                CreativeInput[2].ToString()
                            });
                        }
                        if (!KeyStatus.ContainsKey("UnlockAllBestiary"))
                        {
                            KeyStatus.Add("UnlockAllBestiary", new List <string> {
                                CreativeInput[3].ToString()
                            });
                        }
                        if (!KeyStatus.ContainsKey("LockBestiary"))
                        {
                            KeyStatus.Add("LockBestiary", new List <string> {
                                CreativeInput[4].ToString()
                            });
                        }
                        if (!KeyStatus.ContainsKey("IncreaseFlySpeed"))
                        {
                            KeyStatus.Add("IncreaseFlySpeed", new List <string> {
                                CreativeInput[5].ToString()
                            });
                        }
                        if (!KeyStatus.ContainsKey("DecreaseFlySpeed"))
                        {
                            KeyStatus.Add("DecreaseFlySpeed", new List <string> {
                                CreativeInput[6].ToString()
                            });
                        }
                        if (!KeyStatus.ContainsKey("InstantRevive"))
                        {
                            KeyStatus.Add("InstantRevive", new List <string> {
                                CreativeInput[7].ToString()
                            });
                        }
                        if (!KeyStatus.ContainsKey("InstantRevive"))
                        {
                            KeyStatus.Add("InstantRevive", new List <string> {
                                CreativeInput[7].ToString()
                            });
                        }

                        PlayerInput.OnBindingChange += BindingChanged;

                        Logger.Log("Done! Getting \"FillList\" method...");
                        var method2 = controlsUI.GetType()
                                      .GetMethod("FillList", BindingFlags.NonPublic | BindingFlags.Instance);
                        //We use catch statement to notify if injection failed
                        // ReSharper disable once PossibleNullReferenceException
                        method2.Invoke(controlsUI, new object[] { });

                        Logger.Log("Successively added new panel!");
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e, "Error occured during adding new controls panel!");
                    }
                }
            }

            if (!firstUpdate)
            {
                firstUpdate = true;
                BindingChanged();
            }

            //All our ui get broken when UI Scale != 1
            //Main.UIScale = 1f;



            //NPC.NewNPC((int)Main.LocalPlayer.position.X, (int)Main.LocalPlayer.position.Y-300, 636);

            if (tools.visible)
            {
                tools.UIUpdate();
            }



            if (Main.LocalPlayer.creativeTracker.ItemSacrifices.SacrificesCountByItemIdCache.Count < 1000 &&
                Main.keyState.IsKeyDown(CreativeInput[2]) && Main.oldKeyState.IsKeyUp(CreativeInput[2]))
            {
                Logger.Log("Unlocking all items...");
                for (int i = 0; i < 5079; i++)
                {
                    try
                    {
                        Main.LocalPlayer.creativeTracker.ItemSacrifices.RegisterItemSacrifice(i, 999);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                Text("All items in journey mode unlocked");
            }

            if (Main.keyState.IsKeyDown(CreativeInput[0]) && Main.oldKeyState.IsKeyUp(CreativeInput[0]))
            {
                //CycleMode();
                CheatState.Visible = !CheatState.Visible;
            }

            if (Main.keyState.IsKeyDown(CreativeInput[3]) && Main.oldKeyState.IsKeyUp(CreativeInput[3]))
            {
                Logger.Log("Processing Bestiary...");
                try
                {
                    foreach (var it in ContentSamples.NpcBestiaryCreditIdsByNpcNetIds)
                    {
                        Console.WriteLine($"Registering NPCID: {it.Key} -> {it.Value}");
                        Main.BestiaryTracker.Kills.SetKillCountDirectly(it.Value, 9999);
                        Main.BestiaryTracker.Chats.SetWasChatWithDirectly(it.Value);
                        Main.BestiaryTracker.Sights.SetWasSeenDirectly(it.Value);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Error occured while processing bestiarry!");
                }
            }

            if (Main.keyState.IsKeyDown(CreativeInput[4]) && Main.oldKeyState.IsKeyUp(CreativeInput[4]))
            {
                Logger.Log("Clearing Bestiary...");
                try
                {
                    Main.BestiaryTracker.Kills.Reset();
                    Main.BestiaryTracker.Chats.Reset();
                    Main.BestiaryTracker.Sights.Reset();
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Error occured while processing bestiarry!");
                }
            }

            if (Main.keyState.IsKeyDown(CreativeInput[1]) && Main.oldKeyState.IsKeyUp(CreativeInput[1]))
            {
                ChangeFly();
            }

            if (Main.keyState.IsKeyDown(CreativeInput[5]) && Main.oldKeyState.IsKeyUp(CreativeInput[5]))
            {
                if (flyIndex < 10)
                {
                    flyIndex++;
                    SetupFlySpeed();
                }
            }

            if (Main.keyState.IsKeyDown(CreativeInput[6]) && Main.oldKeyState.IsKeyUp(CreativeInput[6]))
            {
                if (flyIndex > 1)
                {
                    flyIndex--;
                    SetupFlySpeed();
                }
            }

            if (Main.keyState.IsKeyDown(CreativeInput[7]) && Main.oldKeyState.IsKeyUp(CreativeInput[7]))
            {
                instantRevive = !instantRevive;
            }


            //Logic
            delta = Main.LocalPlayer.velocity - Main.LocalPlayer.oldVelocity;

            if (fly)
            {
                if (delta.Length() < 1)
                {
                    Main.LocalPlayer.velocity  = -delta;
                    Main.LocalPlayer.position += -delta;
                }
                else
                {
                    Main.LocalPlayer.velocity    = Vector2.Zero;
                    Main.LocalPlayer.oldVelocity = Vector2.Zero;
                }

                Main.LocalPlayer.fallStart = (int)(Main.LocalPlayer.position.Y / 16f);

                if (Main.keyState.IsKeyDown(FlyInput[0]))
                {
                    Main.LocalPlayer.position.Y -= flyDelta;
                }
                if (Main.keyState.IsKeyDown(FlyInput[1]))
                {
                    Main.LocalPlayer.position.Y += flyDelta;
                }
                if (Main.keyState.IsKeyDown(FlyInput[2]))
                {
                    Main.LocalPlayer.position.X += flyDelta;
                }
                if (Main.keyState.IsKeyDown(FlyInput[3]))
                {
                    Main.LocalPlayer.position.X -= flyDelta;
                }
            }

            if (instantRevive && Main.LocalPlayer.respawnTimer > 0)
            {
                fly = false;
                Main.LocalPlayer.respawnTimer = 0;
            }

            if (Main.mapFullscreen)
            {
                if (Main.mouseRight && Main.keyState.IsKeyUp(Keys.LeftControl))
                {
                    int     mapWidth       = Main.maxTilesX * 16;
                    int     mapHeight      = Main.maxTilesY * 16;
                    Vector2 cursorPosition = new Vector2(Main.mouseX, Main.mouseY);

                    cursorPosition.X -= Main.screenWidth / 2;
                    cursorPosition.Y -= Main.screenHeight / 2;

                    Vector2 mapPosition         = Main.mapFullscreenPos;
                    Vector2 cursorWorldPosition = mapPosition;

                    cursorPosition      /= 16;
                    cursorPosition      *= 16 / Main.mapFullscreenScale;
                    cursorWorldPosition += cursorPosition;
                    cursorWorldPosition *= 16;

                    Player player = Main.player[Main.myPlayer];
                    cursorWorldPosition.Y -= player.height;
                    if (cursorWorldPosition.X < 0)
                    {
                        cursorWorldPosition.X = 0;
                    }
                    else if (cursorWorldPosition.X + player.width > mapWidth)
                    {
                        cursorWorldPosition.X = mapWidth - player.width;
                    }
                    if (cursorWorldPosition.Y < 0)
                    {
                        cursorWorldPosition.Y = 0;
                    }
                    else if (cursorWorldPosition.Y + player.height > mapHeight)
                    {
                        cursorWorldPosition.Y = mapHeight - player.height;
                    }

                    if (Main.netMode == 0) // single
                    {
                        player.Teleport(cursorWorldPosition, 1);
                        player.position  = cursorWorldPosition;
                        player.velocity  = Vector2.Zero;
                        player.fallStart = (int)(player.position.Y / 16f);
                    }
                    else // 1, client
                    {
                        NetMessage.SendData(65, -1, -1, null, 0, player.whoAmI, cursorWorldPosition.X,
                                            cursorWorldPosition.Y, 1);
                        player.Teleport(cursorWorldPosition, 1);
                        player.position  = cursorWorldPosition;
                        player.velocity  = Vector2.Zero;
                        player.fallStart = (int)(player.position.Y / 16f);
                    }
                }
            }
            ucopy.Update(new GameTime());
            inter.Update(new GameTime());
        }