Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带计时器的WPF代码循环_C#_Wpf_Timer_Codecave - Fatal编程技术网

C# 带计时器的WPF代码循环

C# 带计时器的WPF代码循环,c#,wpf,timer,codecave,C#,Wpf,Timer,Codecave,我遇到了一个问题,代码洞代码试图使用计时器而不是“while”来执行循环。 它只写一次值,然后只写0个值。 我想要的是基于计时器和读取其他值后,每秒写入一个地址。就像刷新读取值一样。 我有另一个工作正常的代码,但这个代码不是: using System.Timers; public static System.Timers.Timer aTimer; public MainWindow() { InitializeComponent(); aTimer = new System

我遇到了一个问题,代码洞代码试图使用计时器而不是“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);
    }
}
使用系统定时器;
公共静态系统定时器定时器定时器;
公共主窗口()
{
初始化组件();
aTimer=新系统计时器计时器(1000);
aTimer.Appead+=新的ElapsedEventHandler(计时器);
aTimer.AutoReset=true;
GC.KeepAlive(aTimer);
}
公共静态void Start()
{
OpenProcess();分配(out vMemory,0x1024);
}
公共静态无效计时器(对象源,ElapsedEventArgs e)
{
aTimer.Enabled=true;
int[]wepOffsets={0x70、0x10、0x20、0x368、0x36c};
字节[]readMemory=PointerRead((IntPtr)weapBase,4,wepoffset,out bytesToRead);
int final=BitConverter.ToInt32(readMemory,0);
//MessageBox.Show(“值:+final”);
如果(final==5)//在第一次开始时,它正在写入这个值,那么0
{
字节[]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};
对于(inti=6;i<10;++i){swByte[i]=(byte)(swSpd&0xFF);swSpd=swSpd>>8;}
写入(vMemory+8,swByte,30);
写入(vMemory,BitConverter.GetBytes((vMemory+8)),8);
写入(gameBase,新字节[]{0xFF,0x24,0x25},3);
写入(gameBase+3,BitConverter.GetBytes((vMemory)),4);
}
如果(final==14)//未到达此部分
{
字节[]gsByte={0xC7,0x83,0x22,0x05,0x00,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};
对于(inti=6;i<10;++i){gsByte[i]=(byte)(gsSpd&0xFF);gsSpd=gsSpd>>8;}
写入(vMemory+8,gsByte,30);
写入(vMemory,BitConverter.GetBytes((vMemory+8)),8);
写入(gameBase,新字节[]{0xFF,0x24,0x25},3);
写入(gameBase+3,BitConverter.GetBytes((vMemory)),4);
}
}
嗯,我需要根据读取地址每秒写入2个值…如果已经更改,则立即写入新值。 我如何减少这段代码…我认为可以做一些修改:)

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