Example #1
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);
        }
Example #2
0
    public override void Enable(GameContext ctx)
    {
        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.FromCode(
                        new AssemblyCode[] {
            (Instruction)"mov edx, [esp+4]",
            (Instruction)"push [esp]",
            (Instruction)"push 255",
            AssemblySnippet.FromClrCall(
                ctx.GameModuleHelper.GetFunctionAddress("Terraria.Map.WorldMap", "UpdateLighting"), false, ctx.Map.BaseAddress, null, null,
                Array.Empty <object>())
        }),
                    ctx.MaxTilesY, false),
                ctx.MaxTilesX, false));
        asm.Content.Add(Instruction.Create("pop edx"));
        asm.Content.Add(Instruction.Create("pop ecx"));

        ctx.RunByHookOnUpdate(asm);
        ctx.RefreshMap = true;
    }
Example #3
0
        public void Emit(GameContext context, MPointF Location)
        {
            using MemoryAllocation alloc = new(context.HContext, 32 * (uint)Projs.Count + 64);
            RemoteMemoryStream stream = new(context.HContext, alloc.AllocationBase, 0);

            stream.Write <long>(Projs.Count);           //8 bytes

            byte[] bs = new byte[12];
            for (int i = 0; i < Projs.Count; i++)
            {
                stream.Write(Projs[i].ProjType);                //4
                stream.Write(Location.X + Projs[i].Location.X); //4
                stream.Write(Location.Y + Projs[i].Location.Y); //4
                stream.Write(Projs[i].Speed.X);                 //4
                stream.Write(Projs[i].Speed.Y);                 //4

                stream.Write(bs, (uint)bs.Length);
            }
            AssemblySnippet snippet = AssemblySnippet.FromCode(
                new AssemblyCode[] {
                (Instruction)$"pushad",
                (Instruction)$"mov ebx,{alloc.AllocationBase}",
            });

            snippet.Content.Add(AssemblySnippet.Loop(
                                    AssemblySnippet.FromCode(
                                        new AssemblyCode[] {
                (Instruction)$"mov eax,[esp]",                                                  //i
                (Instruction)$"shl eax,5",                                                      //*32
                (Instruction)$"lea eax,[ebx+8+eax]",

                (Instruction)$"xor ecx,ecx",                                            //SpawnSource:IProjectileSource
                (Instruction)$"push [eax+4]",                                           //X:float
                (Instruction)$"push [eax+8]",                                           //Y:float
                (Instruction)$"push [eax+12]",                                          //SpeedX:float
                (Instruction)$"push [eax+16]",                                          //SpeedY:float
                (Instruction)$"mov edx,[eax]",                                          //Type:int
                (Instruction)$"push 0",                                                 //Damage:int
                (Instruction)$"push 0",                                                 //KnockBack:float
                (Instruction)$"push {context.MyPlayerIndex}",                           //Owner:int
                (Instruction)$"push 0",                                                 //ai0:float
                (Instruction)$"push 0",                                                 //ai1:float
                (Instruction)$"call {context.GameModuleHelper.GetClrMethodBySignature("Terraria.Projectile", "Terraria.Projectile.NewProjectile(Terraria.DataStructures.IEntitySource, Single, Single, Single, Single, Int32, Int32, Single, Int32, Single, Single)").NativeCode}",
            }),
                                    Projs.Count, true));
            snippet.Content.Add((Instruction)"popad");
            context.RunByHookOnUpdate(snippet);
        }
Example #4
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;
        }