Mzzzj / CS2_DMA_Radar

CS2 DMA 雷达
141 stars 53 forks source link

我自己遇到了一个问题 #18

Closed IDhammaI closed 4 months ago

IDhammaI commented 8 months ago

当我想在此项目上添加玩家武器信息时遇到了一些困难,我不会使用相关库进行dma读取。如果大佬愿意帮助我的话,我愿意赞助100元,下面是使用C sharp读取玩家相关武器的代码(目的只要local player的武器)

using HelloWorldCS;
using Swed64;

// 实例化Swed类,用于读取和操作内存
Swed swed = new Swed("cs2");

// 获取client.dll模块的基址
IntPtr client = swed.GetModuleBase("client.dll");

// 定义游戏实体列表的地址偏移量
int dwEntityList = 0x18B3FA8;

// 定义游戏中与玩家和武器相关的偏移量
int m_hPlayerPawn = 0x7E4;
int m_pClippingWeapon = 0x1308;
int m_iItemDefinitionIndex = 0x1BA;

int m_AttributeManager = 0x1098;
int m_Item = 0x50;

// 无限循环,用于持续读取数据
while (true)
{
    // 读取实体列表的指针
    IntPtr entityList = swed.ReadPointer(client, dwEntityList);

    // 读取列表中的第一个条目
    IntPtr listEntry = swed.ReadPointer(entityList, 0x10);

    // 读取当前控制的实体
    IntPtr currentController = swed.ReadPointer(listEntry, 1 * 0x78);
    if (currentController == IntPtr.Zero)
    {
        continue; // 如果没有控制的实体,继续下一次循环
    }
    // 读取玩家实体句柄
    int pawnHandle = swed.ReadInt(currentController, m_hPlayerPawn);
    if (pawnHandle == 0)
    {
        continue; // 如果句柄为0,继续下一次循环
    }
    // 根据句柄计算实体的位置并读取
    IntPtr listEntry2 = swed.ReadPointer(entityList, 0x8 * ((pawnHandle & 0x7FFF) >> 9) + 0x10);

    IntPtr currentPawn = swed.ReadPointer(listEntry2, 0x78 * (pawnHandle & 0x1FF));

    if (currentPawn == IntPtr.Zero)
    {
        continue; // 如果没有当前实体,继续下一次循环
    }

    // 读取当前武器的指针
    IntPtr currentWeapon = swed.ReadPointer(currentPawn, m_pClippingWeapon);

    // 读取当前武器的定义索引
    short weaponDefinitionIndex = swed.ReadShort(currentWeapon, m_AttributeManager + m_Item + m_iItemDefinitionIndex);

    if (weaponDefinitionIndex == -1) continue; // 如果武器定义索引为-1,继续下一次循环

    // 根据武器定义索引获取武器名称
    string currentWeaponName = Enum.GetName(typeof(Weapon), weaponDefinitionIndex);

    // 输出当前武器名称
    Console.WriteLine($"ent:{currentWeaponName}");

    // 暂停500毫秒
    Thread.Sleep(500);

    // 清除控制台输出
    Console.Clear();
}
IDhammaI commented 8 months ago

qq 1518470138 希望作者能帮助我,我自己已经折腾了好久没实现。。。

IDhammaI commented 8 months ago

下面是配套的枚举类

namespace HelloWorldCS
{

    public enum Weapon {
        Deagle = 1,
        Elite = 2,
        Fiveseven = 3,
        Glock = 4,
        Ak47 = 7,
        Aug = 8,
        Awp = 9,
        Famas = 10,
        G3Sg1 = 11,

        GalilAR = 13,

        M249 = 14,

        Mac10 = 17,

        P90 = 19,

        mp5 = 23,
        Ump45 = 24,
        Xm1014 = 25,
        Bizon = 26,
        Mag7 = 27,
        Negev = 28,
        Sawedoff = 29,
        Tec9 = 30,
        Zeus = 31,
        P2000 = 32,
        Mp7 = 33,
        Mp9 = 34,
        Nova = 35,
        P250 = 36,
        Scar20 = 38,
        Sg556 = 39,
        Ssg08 = 40,
        CtKnife = 42,
        Flashbang = 43,
        Hegrenade = 44,
        Smokegrenade = 45,
        Molotov = 46,
        Decoy = 47,
        Incgrenade = 48,
        C4 = 49,
        M4A4 = 16,
        UspS = 61,
        M4A1Silencer = 60,
        Cz75A = 63,
        Revolver = 64,
        TKnife = 59
    }
}