Исходник [CS2] Netvar Manager

  • 681
  • 318
credits: GitHub - bruhmoment21/cs2-sdk & GitHub - neverlosecc/source2gen: Source2 games SDK generator & GitHub - MissedShot/wok-csgo-2.1: simple csgo sdk/base

I spent a little time and made a parser of all netvars, it in "wok-csgo" style, but you can edit it.

Netvars Dump

netvars.hpp
C++:
#pragma once

namespace fw {
namespace sdk {
class c_netvars {
public:
  c_netvars();

  template <typename t> t get(std::uint32_t hash) {
    return m_data.m_list[hash];
  }

private:
  struct {
    std::unordered_map<std::uint32_t, std::int16_t> m_list;
  } m_data;
};
inline std::unique_ptr<c_netvars> netvars;
} // namespace sdk
} // namespace fw

#define NETVAR(type, func, name)                                               \
  ALWAYS_INLINE type &func {                                                   \
    static const auto offset =                                                 \
        fw::sdk::netvars->get<std::uintptr_t>(FNV1A(name));                    \
    return *reinterpret_cast<type *>(reinterpret_cast<std::uintptr_t>(this) +  \
                                     offset);                                  \
  }

#define ANETVAR(type, size, func, name)                                        \
  ALWAYS_INLINE type &func {                                                   \
    static const auto offset =                                                 \
        fw::sdk::netvars->get<std::uintptr_t>(FNV1A(name));                    \
    return *reinterpret_cast<std::array<type, size> *>(                        \
        reinterpret_cast<std::uintptr_t>(this) + offset);                      \
  }

#define PNETVAR(type, func, name)                                              \
  ALWAYS_INLINE type &func {                                                   \
    static const auto offset =                                                 \
        fw::sdk::netvars->get<std::uintptr_t>(FNV1A(name));                    \
    return reinterpret_cast<type *>(reinterpret_cast<std::uintptr_t>(this) +   \
                                    offset);                                   \
  }

#define NETVAR_OFFSET(type, func, name, add)                                   \
  ALWAYS_INLINE type &func {                                                   \
    static const auto offset =                                                 \
        fw::sdk::netvars->get<std::uintptr_t>(FNV1A(name));                    \
    return *reinterpret_cast<type *>(reinterpret_cast<std::uintptr_t>(this) +  \
                                     offset + add);                            \
  }

#define ANETVAR_OFFSET(type, size, func, name, add)                            \
  ALWAYS_INLINE type &func {                                                   \
    static const auto offset =                                                 \
        fw::sdk::netvars->get<std::uintptr_t>(FNV1A(name));                    \
    return *reinterpret_cast<std::array<type, size> *>(                        \
        reinterpret_cast<std::uintptr_t>(this) + offset + add);                \
  }

#define PNETVAR_OFFSET(type, func, name, add)                                  \
  ALWAYS_INLINE type &func {                                                   \
    static const auto offset =                                                 \
        fw::sdk::netvars->get<std::uintptr_t>(FNV1A(name));                    \
    return reinterpret_cast<type *>(reinterpret_cast<std::uintptr_t>(this) +   \
                                    offset + add);                             \
  }

#define OFFSET(type, func, offset)                                             \
  ALWAYS_INLINE type &func {                                                   \
    return *reinterpret_cast<type *>(reinterpret_cast<std::uintptr_t>(this) +  \
                                     offset);                                  \
  }

#define POFFSET(type, func, offset)                                            \
  ALWAYS_INLINE type &func {                                                   \
    return reinterpret_cast<type *>(reinterpret_cast<std::uintptr_t>(this) +   \
                                    offset);                                   \
  }

#define PPOFFSET(type, func, offset)                                           \
  ALWAYS_INLINE type &func {                                                   \
    return **reinterpret_cast<type **>(                                        \
        reinterpret_cast<std::uintptr_t>(this) + offset);                      \
  }

#define MPOFFSET(type, func, offset, modifier)                                 \
  ALWAYS_INLINE type &func {                                                   \
    return **reinterpret_cast<type **>(                                        \
        reinterpret_cast<std::uintptr_t>(this) + offset * modifier);           \
  }

netvars.cpp
C++:
#include "../../../framework.hpp"

namespace fw {
namespace sdk {
c_netvars::c_netvars() {
  const auto type_scopes = interfaces::m_schema_system->get_type_scopes();

  for (auto i = 0; i < type_scopes.Count(); ++i) {
    const auto current = type_scopes.m_pElements[i];

    for (const auto schema_class_binding :
         current->get_classes().GetElements()) {
      const auto class_info =
          current->find_declared_class(schema_class_binding->m_binary_name);

      const auto field_size = class_info->get_field_size();
      const auto fields = class_info->get_fields();

      for (int i = 0; i < field_size; ++i) {
        auto &field = fields[i];

        char name[260];

        strcpy_s(name, schema_class_binding->m_binary_name);
        strcat_s(name, "->");
        strcat_s(name, field.m_name);

        m_data.m_list[FNV1A_RT(name)] = field.m_offset;

        fw::console->print("Found netvar {}", name);
      }
    }
  }
}
} // namespace sdk
} // namespace fw

example:
// init
fw::sdk::netvars = std::make_unique<fw::sdk::c_netvars>();
// use
NETVAR(std::uint8_t, m_iTeamNum(), "C_BaseEntity->m_iTeamNum");

 
Последнее редактирование:

Похожие темы

Ответы
0
Просмотры
1K
Сверху Снизу