From 27225439d717627d20e6470b561723f77de8b001 Mon Sep 17 00:00:00 2001 From: Huoji's <1296564236@qq.com> Date: Sun, 8 Oct 2023 10:59:59 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dm=5Fglow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- csgo2/native_sdk.h | 49 ++++++++++++++++++++++++++++++++++++++++++- csgo2/script_apis.cpp | 18 +++++----------- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/csgo2/native_sdk.h b/csgo2/native_sdk.h index 8edae3e..d5c9c68 100644 --- a/csgo2/native_sdk.h +++ b/csgo2/native_sdk.h @@ -78,7 +78,53 @@ extern auto SetStateChanged(Z_CBaseEntity* pEntity, int offset) -> void; (uintptr_t)(this) + m_key.offset + extra_offset) = val; \ } +#define SCHEMA_FIELD_OFFSET_EX(type, datatableName, varName, extra_offset) \ + std::add_lvalue_reference_t varName() { \ + static constexpr auto datatable_hash = \ + hash_32_fnv1a_const(datatableName); \ + static constexpr auto prop_hash = hash_32_fnv1a_const(#varName); \ + \ + static const auto m_key = \ + schema::GetOffset(ThisClass, datatable_hash, #varName, prop_hash); \ + \ + return *reinterpret_cast>( \ + (uintptr_t)(this) + m_key.offset + extra_offset); \ + } \ + void varName(type val) { \ + static constexpr auto datatable_hash = \ + hash_32_fnv1a_const(datatableName); \ + static constexpr auto prop_hash = hash_32_fnv1a_const(#varName); \ + \ + static const auto m_key = \ + schema::GetOffset(ThisClass, datatable_hash, #varName, prop_hash); \ + \ + static const auto m_chain = schema::FindChainOffset(ThisClass); \ + \ + if (m_chain != 0 && m_key.networked) { \ + LOG("Found chain offset %d for %s::%s\n", m_chain, ThisClass, \ + #varName); \ + Offset::FnNetworkStateChanged((uintptr_t)(this) + m_chain, \ + m_key.offset + extra_offset, \ + 0xFFFFFFFF); \ + } else if (m_key.networked) { \ + /* WIP: Works fine for most props, but inlined classes in the \ + middle of a class will need to have their this pointer \ + corrected by the offset .*/ \ + LOG("Attempting to call SetStateChanged on on %s::%s\n", \ + ThisClass, #varName); \ + if (!OffsetIsStruct) \ + SetStateChanged((Z_CBaseEntity*)this, \ + m_key.offset + extra_offset); \ + else \ + CALL_VIRTUAL(void, 1, this, m_key.offset + extra_offset, \ + 0xFFFFFFFF, 0xFFFF); \ + } \ + *reinterpret_cast>( \ + (uintptr_t)(this) + m_key.offset + extra_offset) = val; \ + } #define SCHEMA_FIELD(type, varName) SCHEMA_FIELD_OFFSET(type, varName, 0) +#define SCHEMA_FIELD_EX(type, dataTableName, varName) \ + SCHEMA_FIELD_OFFSET_EX(type, dataTableName, varName, 0) #define PSCHEMA_FIELD_OFFSET(type, varName, extra_offset) \ auto varName() { \ @@ -323,7 +369,7 @@ class CEntityInstance { SCHEMA_FIELD(CEntityIdentity*, m_pEntity); SCHEMA_FIELD(const char*, m_designerName); }; - +class CGlowProperty; class CBaseEntity : public CEntityInstance { public: DECLARE_CLASS(CBaseEntity); @@ -333,6 +379,7 @@ class CBaseEntity : public CEntityInstance { // SCHEMA_FIELD(Vector, m_vecBaseVelocity) SCHEMA_FIELD(CCollisionProperty*, m_pCollision) SCHEMA_FIELD(Vector, m_vecBaseVelocity) + SCHEMA_FIELD_EX(CGlowProperty, "CBaseModelEntity", m_Glow); auto IsBasePlayerController() -> bool; auto SpawnClientEntity() -> void; }; diff --git a/csgo2/script_apis.cpp b/csgo2/script_apis.cpp index 6d72e4d..2d63416 100644 --- a/csgo2/script_apis.cpp +++ b/csgo2/script_apis.cpp @@ -660,11 +660,7 @@ auto luaApi_SetPlayerGlowColor(lua_State* luaVm) -> int { const auto b = lua_tonumber(luaVm, 4); ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) { playerController->m_hPawn() - .Get() - ->m_Glow() - .m_fGlowColor(Vector(r, g, b)); - playerController->m_hPawn() - .Get() + .Get() ->m_Glow() .m_glowColorOverride(Color(r, g, b, 230)); }); @@ -676,14 +672,10 @@ auto luaApi_SetPlayerGlowEnable(lua_State* luaVm) -> int { const auto playerIndex = lua_tointeger(luaVm, 1); const auto isEnable = lua_toboolean(luaVm, 2); ExcutePlayerAction(playerIndex, [&](CCSPlayerController* playerController) { - playerController->m_hPawn() - .Get() - ->m_Glow() - .m_bGlowing(isEnable); - playerController->m_hPawn() - .Get() - ->m_Glow() - .m_iGlowType(3); + playerController->m_hPawn().Get()->m_Glow().m_bGlowing( + isEnable); + playerController->m_hPawn().Get()->m_Glow().m_iGlowType( + 3); }); lua_pop(luaVm, 2); return 0;