public static void InjectAndWait(Context Context, AssemblySnippet snippet, int targetAddr, bool once) { var t = Inject(Context, snippet, targetAddr, once); System.Threading.Thread.Sleep(10); while (true) { int y = 0; NativeFunctions.ReadProcessMemory(Context.Handle, t.Item3, ref y, 4, 0); if (y == 0) { if (t.Item2 == 0) { NativeFunctions.WriteProcessMemory(Context.Handle, targetAddr, t.Item4, t.Item4.Length, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.Item1, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.Item3, 0); return; } else { NativeFunctions.ReadProcessMemory(Context.Handle, t.Item2, ref y, 4, 0); if (y == 0) { NativeFunctions.WriteProcessMemory(Context.Handle, targetAddr, t.Item4, t.Item4.Length, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.Item1, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.Item2, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.Item3, 0); return; } } } } }
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; }
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); }
public static void HarpToTP_E(GameContext Context) { int a = AobscanHelper.Aobscan( Context.HContext.Handle, "8B 8D E4 F9 FF FF FF 15") - 5; byte[] j = new byte[1]; NativeFunctions.ReadProcessMemory(Context.HContext.Handle, a, j, 1, 0); if (j[0] != 0xE9) { var player = Context.MyPlayer; InlineHook.Inject(Context.HContext, AssemblySnippet.FromCode( new AssemblyCode[] { (Instruction)$"pushad", AssemblySnippet.FromClrCall( Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Main", "get_LocalPlayer"), null, false), (Instruction)$"mov ebx,eax", (Instruction)$"push 16", (Instruction)$"fild dword ptr [{Context.TileTargetX_Address}]", (Instruction)$"fild dword ptr [esp]", (Instruction)$"fmul", (Instruction)$"fstp dword ptr [ebx+{Entity.OFFSET_Position}]", (Instruction)$"fild dword ptr [{Context.TileTargetY_Address}]", (Instruction)$"fild dword ptr [esp]", (Instruction)$"fmul", (Instruction)$"fstp dword ptr [ebx+{Entity.OFFSET_Position + 0x4}]", (Instruction)$"add esp,4", (Instruction)$"popad", }), a, false); } }
public static void InjectAndWait(Context Context, AssemblySnippet snippet, int targetAddr, bool once) { var t = Inject(Context, snippet, targetAddr, once); System.Threading.Thread.Sleep(10); while (true) { int y = 0; NativeFunctions.ReadProcessMemory(Context.Handle, t.ComparisonInstructionAddress, ref y, 4, 0); if (y == 0) { if (t.ComparisonFlagAddress == 0) { NativeFunctions.WriteProcessMemory(Context.Handle, targetAddr, t.RawCodeBytes, t.RawCodeBytes.Length, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.CodeAddress, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.ComparisonInstructionAddress, 0); return; } else { NativeFunctions.ReadProcessMemory(Context.Handle, t.ComparisonFlagAddress, ref y, 4, 0); if (y == 0) { NativeFunctions.WriteProcessMemory(Context.Handle, targetAddr, t.RawCodeBytes, t.RawCodeBytes.Length, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.CodeAddress, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.ComparisonFlagAddress, 0); NativeFunctions.VirtualFreeEx(Context.Handle, t.ComparisonInstructionAddress, 0); return; } } } } }
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); }
public static void HighLight_E(GameContext Context) { int a = AobscanHelper.AobscanASM( Context.HContext.Handle, @"mov [ebp-0x48],edx fld dword ptr [esi+0x8] fld dword ptr [ebp-0x3c] fcomip st(1) fstp st(0)") + 3; if (a <= 0) { return; } InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( @"mov dword ptr [esi+0x8],0x3f800000 mov dword ptr [esi+0x10],0x3f800000 mov dword ptr [esi+0x18],0x3f800000 fld dword ptr [esi+0x8] fld dword ptr [ebp-0x3c]" ), a, false ); }
public static AssemblySnippet GetSnippet_Call_NewProjectile(GameContext Context, int?ret, bool regProtection, object X, object Y, object SpeedX, object SpeedY, object Type, object Damage, object KnockBack, object Owner, object ai0, object ai1) { return(AssemblySnippet.FromDotNetCall( Context.HContext.MainAddressHelper.GetFunctionAddress("Terraria.Projectile", "NewProjectile"), ret, regProtection, Type, Damage, Y, X, SpeedY, SpeedX, KnockBack, Owner, ai0, ai1)); }
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); }
public static void LowGravity_E(GameContext Context) { int a = AobscanHelper.AobscanASM( Context.HContext.Handle, "mov [esi+0x414],edx\ncmp dword ptr [esi+0x370],0"); InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode("mov dword ptr [esi+0x410],0x41200000"), a, false); }
public override void Enable(GameContext ctx) { int off = GetOffset(ctx, "Terraria.Entity", "position"); var ass = AssemblySnippet.FromCode( new AssemblyCode[] { Instruction.Create("pushad"), Instruction.Create($"cmp byte ptr [{ctx.MapFullScreen_Address}],0"), Instruction.Create("je _rwualfna"), Instruction.Create($"cmp byte ptr [{ctx.MouseRight_Address}],0"), Instruction.Create("je _rwualfna"), Instruction.Create($"cmp byte ptr [{ctx.MouseRightRelease_Address}],0"), Instruction.Create("je _rwualfna"), AssemblySnippet.FromCode( new AssemblyCode[] { Instruction.Create($"mov byte ptr [{ctx.MapFullScreen_Address}],0"), Instruction.Create($"mov byte ptr [{ctx.MouseRightRelease_Address}],0"), AssemblySnippet.FromClrCall( ctx.GameModuleHelper.GetFunctionAddress("Terraria.Main", "get_LocalPlayer"), false, null, null, null, Array.Empty <object>()), Instruction.Create("mov ebx,eax"), Instruction.Create("push eax"), Instruction.Create("mov dword ptr [esp],2"), Instruction.Create($"fild dword ptr [{ctx.ScreenWidth_Address}]"), Instruction.Create("fild dword ptr [esp]"), Instruction.Create("fdivp"), Instruction.Create($"fild dword ptr [{ctx.MouseX_Address}]"), Instruction.Create("fsubp"), Instruction.Create($"fld dword ptr [{ctx.MapFullScreenScale_Address}]"), Instruction.Create("fdivp"), Instruction.Create($"fld dword ptr [{ctx.MapFullscreenPos_Address + 4}]"), Instruction.Create("fsubrp"), Instruction.Create("mov dword ptr [esp],16"), Instruction.Create("fild dword ptr [esp]"), Instruction.Create("fmulp"), Instruction.Create($"fstp dword ptr [ebx+{off}]"), Instruction.Create("mov dword ptr [esp],2"), Instruction.Create($"fild dword ptr [{ctx.ScreenHeight_Address}]"), Instruction.Create("fild dword ptr [esp]"), Instruction.Create("fdivp"), Instruction.Create($"fild dword ptr [{ctx.MouseY_Address}]"), Instruction.Create("fsubp"), Instruction.Create($"fld dword ptr [{ctx.MapFullScreenScale_Address}]"), Instruction.Create("fdivp"), Instruction.Create($"fld dword ptr [{ctx.MapFullscreenPos_Address + 8}]"), Instruction.Create("fsubrp"), Instruction.Create("mov dword ptr [esp],16"), Instruction.Create("fild dword ptr [esp]"), Instruction.Create("fmulp"), Instruction.Create($"fstp dword ptr [ebx+{off + 0x4}]"), Instruction.Create("pop eax"), }), Instruction.Create("_rwualfna:"), Instruction.Create("popad") }); HookParameters ps = new HookParameters(ctx.GameModuleHelper.GetFunctionAddress("Terraria.Main", "Update") + 5, 4096); InlineHook.Hook(ctx.HContext, ass, ps); }
public static void FastTileSpeed_E(GameContext Context) { int a = AobscanHelper.Aobscan( Context.HContext.Handle, "d9 98 c8 03 00 00 8b 85 30 f0 ff ff d9"); InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( "mov dword ptr [eax+0x3c8],0x3e800000"), a, false, false); }
public static void ShadowDodge_E(GameContext Context) { int a = AobscanHelper.Aobscan( Context.HContext.Handle, "00 00 88 96 33 05 00 00 88 96 A9 05 00 00") - 4; InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( "mov byte ptr [esi+0x532],0x1"), a, false, false); }
public static void ShowCircuit_E(GameContext Context) { int a = AobscanHelper.Aobscan( Context.HContext.Handle, "88 96 1D 06 00 00 88 96 1E 06 00 00") - 6; InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( "mov byte ptr [esi+0x62a],0x1"), a, false, false); }
public static void RulerEffect_E(GameContext Context) { int a = AobscanHelper.Aobscan( Context.HContext.Handle, "88 96 F8 05 00 00 88 96 F9 05 00 00") - 6; InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( "mov byte ptr [esi+0x5f7],0x1"), a, false, false); }
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); }
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); }
public static void FastSpeed_E(GameContext Context) { int a = AobscanHelper.AobscanASM( Context.HContext.Handle, "fstp dword ptr [esi+0x3bc]\nmov [esi+0x54b],dl"); InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( "mov dword ptr [esi+0x3bc],0x464b2000\nmov dword ptr [esi+0x3e4],0x464b2000"), a, false, false); }
public static void SlimeGunBurn_E(GameContext Context) { int a = AobscanHelper.Aobscan( Context.HContext.Handle, "8b 85 b8 f3 ff ff 89 45 cc 8b 45 cc 40") - 0x1a; InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( "mov dword ptr [esp+8],216000\nmov edx,0x99"), a, false, false); }
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); }
public static void FastWallSpeed_E(GameContext Context) { int a = (int)Context.HContext.MainAddressHelper.GetFunctionInstruction("Terraria.Player", "Update", 0x2D07).EndAddress - 6; int off = 0; NativeFunctions.ReadProcessMemory(Context.HContext.Handle, a + 2, ref off, 4, 0); InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( $"mov dword ptr [eax+{off}],0x3e800000"), a, false, false); }
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); }
public static void MachinicalRulerEffect_E(GameContext Context) { int a = AobscanHelper.Aobscan( Context.HContext.Handle, "d9 9e c0 03 00 00 88 96 f0 05 00 00") + 12; InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( "mov byte ptr [esi+0x5f6],0x1"), a, false, false); }
private static AssemblyCode Imp_AddI2F() { return(AssemblySnippet.FromCode(new AssemblyCode[] { (Instruction)"fild dword ptr [esp+4]", (Instruction)"fild dword ptr [esp+8]", (Instruction)"fadd", (Instruction)"fstp dword ptr [esp-4]", (Instruction)"mov eax,[esp-4]", (Instruction)"ret 8", })); }
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); }
public static void DisableInvisibility_E(GameContext Context) { int a = (int)Context.HContext.MainAddressHelper["Terraria.Player", "UpdateBuffs", 0x21B].StartAddress; int s = 0; NativeFunctions.ReadProcessMemory(Context.HContext.Handle, a + 4, ref s, 4, 0); var code = AssemblySnippet.FromCode(new AssemblyCode[] { (Instruction)"mov byte ptr [esi+0x651],0", }); InlineHook.Inject(Context.HContext, code, a, false, false); }
/// <summary> /// Calling this is much more effective than calling the two functions separately. /// </summary> /// <param name="type"></param> /// <param name="prefix"></param> public void SetDefaultsAndPrefix(int type, int prefix) { Context.RunByHookOnUpdate(AssemblySnippet.FromCode( new AssemblyCode[] { Instruction.Create("push ecx"), Instruction.Create("push edx"), TypedInternalObject.GetMethodCall("Terraria.Item.SetDefaults(Int32)").Call(false, null, null, new object[] { type }), TypedInternalObject.GetMethodCall("Terraria.Item.Prefix(Int32)").Call(false, null, null, new object[] { prefix }), Instruction.Create("pop edx"), Instruction.Create("pop ecx") })); }
public static void BonusTwoSlots_E(GameContext Context) { int a = AobscanHelper.AobscanASM( Context.HContext.Handle, "mov byte ptr [esi+0x5c0],0\nmov byte ptr [esi+0x514],0\nmov byte ptr [esi+0x5aa],0") - 6; InlineHook.Inject(Context.HContext, AssemblySnippet.FromASMCode( "mov dword ptr [esi+0x140],2"), a, false, false); byte[] bs = { 0x90, 0x90 }; NativeFunctions.WriteProcessMemory(Context.HContext.Handle, a - 0x10, bs, bs.Length, 0); }
public static void Call(GameContext Context, nuint targetAddr, params object[] args) { AssemblySnippet snippet = AssemblySnippet.FromCode( new AssemblyCode[] { (Instruction)"pushad", AssemblySnippet.FromClrCall( targetAddr, false, null, null, null, args), (Instruction)"popad" }); Context.RunByHookOnUpdate(snippet); }
public override void Enable(GameContext ctx) { nuint a = ctx.GameModuleHelper["Terraria.Player", "GetItemGrabRange"]; if (Read <byte>(ctx, a) == 0xE9) { return; } InlineHook.Hook(ctx.HContext, AssemblySnippet.FromASMCode( "mov eax,1000\nret"), new HookParameters(a, 4096, false, false)); this.IsEnabled = true; }