Exemplo n.º 1
0
        public static void SendChat(GameContext Context, string Text)
        {
            byte[] bs     = Encoding.Unicode.GetBytes(Text);
            int    strEnd = 0;
            int    strMem = NativeFunctions.VirtualAllocEx(Context.HContext.Handle, 0, Text.Length + 10,
                                                           NativeFunctions.AllocationType.Commit, NativeFunctions.MemoryProtection.ExecuteReadWrite);

            NativeFunctions.WriteProcessMemory(Context.HContext.Handle, strMem, bs, bs.Length, 0);
            NativeFunctions.WriteProcessMemory(Context.HContext.Handle, strMem + bs.Length, ref strEnd, 4, 0);

            var             mscorlib_AddrHelper = Context.HContext.GetAddressHelper("mscorlib.dll");
            int             ctor = mscorlib_AddrHelper.GetFunctionAddress("System.String", "CtorCharPtr");
            AssemblySnippet asm  = AssemblySnippet.FromCode(
                new AssemblyCode[] {
                (Instruction)"push ecx",
                (Instruction)"push edx",
                AssemblySnippet.ConstructString(Context.HContext, strMem, Context.HContext.MainAddressHelper.GetStaticFieldAddress("Terraria.Main", "chatText")),
                (Instruction)$"mov byte ptr [{Context.HContext.MainAddressHelper.GetStaticFieldAddress("Terraria.Main", "drawingPlayerChat")}],1",
                (Instruction)$"mov byte ptr [{Context.HContext.MainAddressHelper.GetStaticFieldAddress("Terraria.Main", "inputTextEnter")}],1",
                (Instruction)$"mov byte ptr [{Context.HContext.MainAddressHelper.GetStaticFieldAddress("Terraria.Main", "chatRelease")}],1",
                (Instruction)"pop edx",
                (Instruction)"pop ecx"
            });

            InlineHook.InjectAndWait(Context.HContext, asm, Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Main", "DoUpdate"), true);
            NativeFunctions.VirtualFreeEx(Context.HContext.Handle, strMem, 0);
        }
Exemplo n.º 2
0
        public void Emit(GameContext context, float X, float Y)
        {
            int data = NativeFunctions.VirtualAllocEx(context.HContext.Handle, 0, (int)(32 * Projs.Count), NativeFunctions.AllocationType.Commit, NativeFunctions.MemoryProtection.ExecuteReadWrite);

            NativeFunctions.WriteProcessMemory(context.HContext.Handle, data, BitConverter.GetBytes(Projs.Count), 4, 0);
            for (int i = 0; i < Projs.Count; i++)
            {
                int t = data + 8 + i * 32;
                NativeFunctions.WriteProcessMemory(context.HContext.Handle, t, BitConverter.GetBytes(Projs[i].ProjType), 4, 0);
                NativeFunctions.WriteProcessMemory(context.HContext.Handle, t + 4, BitConverter.GetBytes(context.MyPlayer.X + Projs[i].Location.X), 4, 0);
                NativeFunctions.WriteProcessMemory(context.HContext.Handle, t + 8, BitConverter.GetBytes(context.MyPlayer.Y + Projs[i].Location.Y), 4, 0);
                NativeFunctions.WriteProcessMemory(context.HContext.Handle, t + 12, BitConverter.GetBytes(Projs[i].Speed.X), 4, 0);
                NativeFunctions.WriteProcessMemory(context.HContext.Handle, t + 16, BitConverter.GetBytes(Projs[i].Speed.Y), 4, 0);
            }
            AssemblySnippet snippet = AssemblySnippet.FromCode(
                new AssemblyCode[] {
                (Instruction)$"pushad",
                (Instruction)$"mov ebx,{data}",
            });

            snippet.Content.Add(AssemblySnippet.Loop(
                                    AssemblySnippet.FromCode(
                                        new AssemblyCode[] {
                (Instruction)$"mov eax,[esp]",                                        //i
                (Instruction)$"shl eax,5",
                (Instruction)$"lea eax,[ebx+8+eax]",
                Projectile.GetSnippet_Call_NewProjectile(context, null, false,
                                                         "[eax+4]", "[eax+8]", "[eax+12]", "[eax+16]", "[eax]", 0, 0f, context.MyPlayerIndex, 0f, 0f),
            }),
                                    (int)Projs.Count, true));
            snippet.Content.Add((Instruction)"popad");
            InlineHook.InjectAndWait(context.HContext, snippet,
                                     context.HContext.MainAddressHelper["Terraria.Main", "Update"], true);
            NativeFunctions.VirtualFreeEx(context.HContext.Handle, data, 0);
        }
Exemplo n.º 3
0
        public static void RevealMap(GameContext Context)
        {
            AssemblySnippet asm = AssemblySnippet.FromClrCall(
                Context.HContext.GetAddressHelper("TRInjections.dll").GetFunctionAddress("TRInjections.Utils", "RevealMap"), null, true);

            InlineHook.InjectAndWait(Context.HContext, asm,
                                     Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Main", "DoUpdate"), true);
        }
Exemplo n.º 4
0
        public static void SendWater(GameContext Context, int x, int y)
        {
            AssemblySnippet snippet = AssemblySnippet.FromDotNetCall(
                Context.HContext.AddressHelper.GetFunctionAddress("Terraria.NetMessage", "sendWater"),
                null,
                true,
                x, y);

            InlineHook.InjectAndWait(Context.HContext, snippet, Context.HContext.AddressHelper.GetFunctionAddress("Terraria.Main", "Update"), true);
        }
Exemplo n.º 5
0
        public static void SquareTileFrame(GameContext Context, int i, int j, bool resetFrame = true)
        {
            AssemblySnippet snippet = AssemblySnippet.FromClrCall(
                Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.WorldGen", "SquareTileFrame"),
                null,
                true,
                i, j, true);

            InlineHook.InjectAndWait(Context.HContext, snippet, Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Main", "DoUpdate"), true);
        }
Exemplo n.º 6
0
        public void AddBuff(int type, int time, bool quiet = false)
        {
            AssemblySnippet snippet = AssemblySnippet.FromDotNetCall(
                Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.NPC", "AddBuff"),
                null,
                true,
                BaseAddress, type, time, quiet);

            InlineHook.InjectAndWait(Context.HContext, snippet, Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Main", "Update"), true);
        }
Exemplo n.º 7
0
        public static void NewNPC(GameContext Context, int x, int y, int type, int start = 0, float ai0 = 0f, float ai1 = 0f, float ai2 = 0f, float ai3 = 0f, int target = 255)
        {
            AssemblySnippet snippet = AssemblySnippet.FromDotNetCall(
                Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.NPC", "NewNPC"),
                null,
                true,
                x, y, type, start, ai0, ai1, ai2, ai3, target);

            InlineHook.InjectAndWait(Context.HContext, snippet, Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Main", "Update"), true);
        }
Exemplo n.º 8
0
        public static void SendData(GameContext Context, int msgType, int remoteClient = -1, int ignoreClient = -1,
                                    int text    = 0, int number  = 0, float number2 = 0f, float number3 = 0f, float number4 = 0f,
                                    int number5 = 0, int number6 = 0, int number7   = 0)
        {
            AssemblySnippet snippet = AssemblySnippet.FromDotNetCall(
                Context.HContext.AddressHelper.GetFunctionAddress("Terraria.NetMessage", "SendData"),
                null,
                true,
                msgType, remoteClient, ignoreClient, text, number, number2, number3, number4, number5, number6, number7);

            InlineHook.InjectAndWait(Context.HContext, snippet, Context.HContext.AddressHelper.GetFunctionAddress("Terraria.Main", "Update"), true);
        }
Exemplo n.º 9
0
        public static int NewProjectile(GameContext Context, float X, float Y, float SpeedX, float SpeedY, int Type, int Damage, float KnockBack, int Owner = 255, float ai0 = 0f, float ai1 = 0f)
        {
            int ret = NativeFunctions.VirtualAllocEx(Context.HContext.Handle, 0, 4, NativeFunctions.AllocationType.Commit, NativeFunctions.MemoryProtection.ExecuteReadWrite);

            AssemblySnippet snippet = GetSnippet_Call_NewProjectile(
                Context,
                ret,
                true,
                X, Y, SpeedX, SpeedY, Type, Damage, KnockBack, Owner, ai0, ai1);

            InlineHook.InjectAndWait(Context.HContext, snippet, Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Main", "Update"), true);
            NativeFunctions.ReadProcessMemory(Context.HContext.Handle, ret, ref ret, 4, 0);
            NativeFunctions.VirtualFreeEx(Context.HContext.Handle, ret, 0);
            return(ret);
        }
Exemplo n.º 10
0
        public bool UpdateLighting(int x, int y, byte light)
        {
            int             ret     = NativeFunctions.VirtualAllocEx(Context.HContext.Handle, 0, 4, NativeFunctions.AllocationType.Commit, NativeFunctions.MemoryProtection.ExecuteReadWrite);
            AssemblySnippet snippet = AssemblySnippet.FromDotNetCall(
                Context.HContext.AddressHelper.GetFunctionAddress("Terraria.Map.WorldMap", "UpdateLighting"),
                ret,
                true,
                BaseAddress, x, y, light);

            InlineHook.InjectAndWait(Context.HContext, snippet, Context.HContext.AddressHelper.GetFunctionAddress("Terraria.Main", "Update"), true);
            bool rv = false;

            NativeFunctions.ReadProcessMemory(Context.HContext.Handle, ret, ref rv, 1, 0);
            NativeFunctions.VirtualFreeEx(Context.HContext.Handle, ret, 0);
            return(rv);
        }
Exemplo n.º 11
0
        public static void RevealMap(GameContext Context)
        {
            AssemblySnippet asm = AssemblySnippet.FromEmpty();

            asm.Content.Add(Instruction.Create("push ecx"));
            asm.Content.Add(Instruction.Create("push edx"));
            asm.Content.Add(
                AssemblySnippet.Loop(
                    AssemblySnippet.Loop(
                        AssemblySnippet.FromClrCall(
                            Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Map.WorldMap", "UpdateLighting"), null, false,
                            Context.Map.BaseAddress, "[esp+4]", "[esp]", 255),
                        Context.MaxTilesY, false),
                    Context.MaxTilesX, false));
            asm.Content.Add(Instruction.Create("pop edx"));
            asm.Content.Add(Instruction.Create("pop ecx"));

            InlineHook.InjectAndWait(Context.HContext, asm,
                                     Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Main", "DoUpdate"), true);
            Context.RefreshMap = true;
        }
Exemplo n.º 12
0
        public static void Call(GameContext Context, int targetAddr, int hookAddress, params object[] args)
        {
            Dictionary <int, int> strAddrs = new Dictionary <int, int>();

            object[] trueArgs = args.Select(t =>
            {
                if (!(t is string) || !(t as string).TrimStart().StartsWith("@"))
                {
                    return(t);
                }
                string str     = t as string;
                string trueStr = str.Substring(str.IndexOf("@") + 1);
                int strEnd     = 0;
                byte[] bs      = Encoding.Unicode.GetBytes(trueStr);
                int maddr      = NativeFunctions.VirtualAllocEx(Context.HContext.Handle, 0, bs.Length + 4, NativeFunctions.AllocationType.Commit, NativeFunctions.MemoryProtection.ExecuteReadWrite);
                int taddr      = NativeFunctions.VirtualAllocEx(Context.HContext.Handle, 0, 4, NativeFunctions.AllocationType.Commit, NativeFunctions.MemoryProtection.ExecuteReadWrite);
                NativeFunctions.WriteProcessMemory(Context.HContext.Handle, maddr, bs, bs.Length, 0);
                NativeFunctions.WriteProcessMemory(Context.HContext.Handle, maddr + bs.Length, ref strEnd, 4, 0);
                strAddrs[taddr] = maddr;
                return(taddr);
            }).ToArray();
            for (int i = 0; i < args.Length; i++)
            {
                var t = args[i];
                if (!(t is string) || !(t as string).TrimStart().StartsWith("@"))
                {
                    trueArgs[i] = args[i];
                    continue;
                }
                string str     = t as string;
                string trueStr = str.Substring(str.IndexOf("@") + 1);
                int    strEnd  = 0;
                byte[] bs      = Encoding.Unicode.GetBytes(trueStr);
                int    maddr   = NativeFunctions.VirtualAllocEx(Context.HContext.Handle, 0, bs.Length + 4, NativeFunctions.AllocationType.Commit, NativeFunctions.MemoryProtection.ExecuteReadWrite);
                int    taddr   = NativeFunctions.VirtualAllocEx(Context.HContext.Handle, 0, 4, NativeFunctions.AllocationType.Commit, NativeFunctions.MemoryProtection.ExecuteReadWrite);
                NativeFunctions.WriteProcessMemory(Context.HContext.Handle, maddr, bs, bs.Length, 0);
                NativeFunctions.WriteProcessMemory(Context.HContext.Handle, maddr + bs.Length, ref strEnd, 4, 0);
                strAddrs[taddr] = maddr;
                trueArgs[i]     = $"dword ptr [{taddr}]";
            }


            AssemblySnippet snippet = AssemblySnippet.FromCode(
                new AssemblyCode[] {
                (Instruction)"pushad",
                AssemblySnippet.FromCode(
                    strAddrs.Select(t => AssemblySnippet.ConstructString(
                                        Context.HContext, t.Value, t.Key
                                        ))),
                AssemblySnippet.FromClrCall(
                    targetAddr, null, false,
                    trueArgs),
                (Instruction)"popad"
            });

            InlineHook.InjectAndWait(Context.HContext, snippet, hookAddress, true);

            //Console.WriteLine(snippet.GetCode());
            foreach (var addrs in strAddrs)
            {
                NativeFunctions.VirtualFreeEx(Context.HContext.Handle, addrs.Key, 0);
                NativeFunctions.VirtualFreeEx(Context.HContext.Handle, addrs.Value, 0);
            }
        }