WPF代码洞穴与定时器循环

时间:2013-11-15 14:26:31

标签: c# wpf timer codecave

我遇到了代码洞穴代码的问题,试图使用计时器而不是“while”进行循环。 它只写一次值,然后只写0值。 我想要的是基于定时器和读取其他值后每秒写入一个地址。就像刷新读取值一样。 我有另一个代码正常工作,但这个代码洞穴不是:

using System.Timers;

public static System.Timers.Timer aTimer;
public MainWindow()
{
    InitializeComponent();
    aTimer = new System.Timers.Timer(1000);
    aTimer.Elapsed += new ElapsedEventHandler(Timer);
    aTimer.AutoReset = true;
    GC.KeepAlive(aTimer);
}
public static void Start()
{
    OpenProcess(); Allocate(out vMemory, 0x1024);
}
public static void Timer(object source, ElapsedEventArgs e)
{
    aTimer.Enabled = true;

    int[] wepOffsets = { 0x70, 0x10, 0x20, 0x368, 0x36c };
    byte[] readMemory = PointerRead((IntPtr)weapBase, 4, wepOffsets, out bytesToRead);
    int final = BitConverter.ToInt32(readMemory, 0);
    //MessageBox.Show("value :  " + final);

    if (final == 5) // at first start it is writing this value then 0
    {
        byte[] swByte = { 0xC7,0x83,0x22,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x8B,0x74,0x24,0x40,
            0x48,0x8B,0x6C,0x24,0x48,0x48,0x8B,0x5C,0x24,0x50,0x48,0x83,0xC4,0x58,0xC3 };

        for (int i = 6; i < 10; ++i) { swByte[i] = (byte)(swSpd & 0xFF); swSpd = swSpd >> 8; }

        write(vMemory + 8, swByte, 30);
        write(vMemory, BitConverter.GetBytes((vMemory + 8)), 8);
        write(gameBase, new byte[] { 0xFF, 0x24, 0x25 }, 3);
        write(gameBase + 3, BitConverter.GetBytes((vMemory)), 4);
    }

    if (final == 14) // doesn't reach this part
    {
        byte[] gsByte = { 0xC7,0x83,0x22,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x48,0x8B,0x74,0x24,0x40,
            0x48,0x8B,0x6C,0x24,0x48,0x48,0x8B,0x5C,0x24,0x50,0x48,0x83,0xC4,0x58,0xC3 };

        for (int i = 6; i < 10; ++i) { gsByte[i] = (byte)(gsSpd & 0xFF); gsSpd = gsSpd >> 8; }

        write(vMemory + 8, gsByte, 30);
        write(vMemory, BitConverter.GetBytes((vMemory + 8)), 8);
        write(gameBase, new byte[] { 0xFF, 0x24, 0x25 }, 3);
        write(gameBase + 3, BitConverter.GetBytes((vMemory)), 4);
    }
}

好吧,我需要根据读取地址每秒写入2个值...如果已经改变,则立即写入新值。 我怎么能减少这个代码...我认为可以做一些修改:)。

非常感谢您的支持,想法。

0 个答案:

没有答案