0

我目前正在编写自己的 C# 内存编辑库。

我正在尝试As在 C# 中从下面的 C++ 类中复制该函数。

class globalHandle
{
private:
    void* _handle;
public:

    globalHandle(int index)
        : _handle(&m_globalPtr[index >> 18 & 0x3F][index & 0x3FFFF])
    { }

    globalHandle(void* p)
        : _handle(p)
    { }

    globalHandle(const globalHandle& copy)
        : _handle(copy._handle)
    { }

    globalHandle At(int index)
    {
        return globalHandle(reinterpret_cast<void**>(this->_handle) + (index));
    }

    globalHandle At(int index, int size)
    {
        // Position 0 = Array Size
        return this->At(1 + (index * size));
    }

    template <typename T>
    T* Get()
    {
        return reinterpret_cast<T*>(this->_handle);
    }

    template <typename T>
    T& As()
    {
        return *this->Get<T>();
    }
};

它如下所示:

globalHandle(1573972).As<int>() = 123;

我想在 C# 中归档一个函数,如下所示:

m.memory(pointer, offset).Set<int>() = 123;

我的记忆功能如下所示:

long address;
public Memory(long pointer, long offset)
{
    byte[] buffer_temp = new byte[16];

    ReadProcessMemory(procHandle, (long)BaseAddress + pointer, buffer_temp, buffer_temp.Length, IntPtr.Zero);
    address = BitConverter.ToInt64(buffer_temp, 0) + offset;
}

我尝试了泛型和动态,但无法使其正常工作。

你们有什么想法我可以存档我想要的吗?

4

0 回答 0