1

我遇到了代码洞穴代码尝试使用计时器而不是“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 个值……如果已经更改,则立即写入新值。以及如何减少此代码...我认为可以进行一些修改:)。

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

4

0 回答 0