From 0c729c609cd052f4e720ce885c1d5322b63c9edd Mon Sep 17 00:00:00 2001 From: BobTheBob9 Date: Fri, 21 Oct 2022 00:17:48 +0100 Subject: fix up squirrel sq_getentity defs --- NorthstarDLL/miscserverscript.cpp | 4 ++-- NorthstarDLL/r2server.h | 11 +++++++++-- NorthstarDLL/serverchathooks.cpp | 10 +++++----- NorthstarDLL/squirrel.cpp | 16 +++++++++++++--- NorthstarDLL/squirrel.h | 17 ++++++++++++++--- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/NorthstarDLL/miscserverscript.cpp b/NorthstarDLL/miscserverscript.cpp index ca2a5b61..758323ef 100644 --- a/NorthstarDLL/miscserverscript.cpp +++ b/NorthstarDLL/miscserverscript.cpp @@ -20,7 +20,7 @@ SQRESULT SQ_EarlyWritePlayerPersistenceForLeave(HSquirrelVM* sqvm) return SQRESULT_NOTNULL; } - R2::CBaseClient* pClient = &R2::g_pClientArray[pPlayer->m_nPlayerIndex]; + R2::CBaseClient* pClient = &R2::g_pClientArray[pPlayer->m_nPlayerIndex - 1]; if (g_pServerAuthentication->m_PlayerAuthenticationData.find(pClient) == g_pServerAuthentication->m_PlayerAuthenticationData.end()) { g_pSquirrel->pushbool(sqvm, false); @@ -51,7 +51,7 @@ SQRESULT SQ_IsPlayerLocalPlayer(HSquirrelVM* sqvm) return SQRESULT_NOTNULL; } - R2::CBaseClient* pClient = &R2::g_pClientArray[pPlayer->m_nPlayerIndex]; + R2::CBaseClient* pClient = &R2::g_pClientArray[pPlayer->m_nPlayerIndex - 1]; g_pSquirrel->pushbool(sqvm, !strcmp(R2::g_pLocalPlayerUserID, pClient->m_UID)); return SQRESULT_NOTNULL; } diff --git a/NorthstarDLL/r2server.h b/NorthstarDLL/r2server.h index 1abe822d..235dde7f 100644 --- a/NorthstarDLL/r2server.h +++ b/NorthstarDLL/r2server.h @@ -1,5 +1,7 @@ #pragma once +#include "vector.h" + // use the R2 namespace for game funcs namespace R2 { @@ -14,8 +16,13 @@ namespace R2 uint32_t m_nPlayerIndex; // +0x5C - char pad1[0x1C75]; - char m_communityClanTag[16]; + char pad1[0x1C34]; + bool m_hasBadReputation; // 0x1C90 + char m_communityName[64]; // 0x1C91 + char m_communityClanTag[16]; // 0x1CD1 + char m_factionName[16]; // 0x1CE1 + char m_hardwareIcon[16]; // 0x1CF1 + bool m_happyHourActive; // 0x1D01 }; #pragma pack(pop) diff --git a/NorthstarDLL/serverchathooks.cpp b/NorthstarDLL/serverchathooks.cpp index 1dd05830..31844c67 100644 --- a/NorthstarDLL/serverchathooks.cpp +++ b/NorthstarDLL/serverchathooks.cpp @@ -37,7 +37,7 @@ void(__fastcall* MessageWriteBool)(bool bValue); bool bShouldCallSayTextHook = false; // clang-format off AUTOHOOK(_CServerGameDLL__OnReceivedSayTextMessage, server.dll + 0x1595C0, -void, __fastcall, (CServerGameDLL* self, unsigned int senderPlayerId, const char* text, bool isTeam)) +void, __fastcall, (CServerGameDLL* self, unsigned int nSenderPlayerIndex, const char* text, bool isTeam)) // clang-format on { // MiniHook doesn't allow calling the base function outside of anywhere but the hook function. @@ -45,23 +45,23 @@ void, __fastcall, (CServerGameDLL* self, unsigned int senderPlayerId, const char if (bShouldCallSayTextHook) { bShouldCallSayTextHook = false; - _CServerGameDLL__OnReceivedSayTextMessage(self, senderPlayerId, text, isTeam); + _CServerGameDLL__OnReceivedSayTextMessage(self, nSenderPlayerIndex, text, isTeam); return; } // check chat ratelimits - if (!g_pServerLimits->CheckChatLimits(&R2::g_pClientArray[senderPlayerId - 1])) + if (!g_pServerLimits->CheckChatLimits(&R2::g_pClientArray[nSenderPlayerIndex - 1])) return; if (g_pSquirrel->setupfunc("CServerGameDLL_ProcessMessageStartThread") != SQRESULT_ERROR) { - g_pSquirrel->pushinteger(g_pSquirrel->m_pSQVM->sqvm, (int)senderPlayerId - 1); + g_pSquirrel->pushinteger(g_pSquirrel->m_pSQVM->sqvm, (int)nSenderPlayerIndex - 1); g_pSquirrel->pushstring(g_pSquirrel->m_pSQVM->sqvm, text); g_pSquirrel->pushbool(g_pSquirrel->m_pSQVM->sqvm, isTeam); g_pSquirrel->call(g_pSquirrel->m_pSQVM->sqvm, 3); } else - _CServerGameDLL__OnReceivedSayTextMessage(self, senderPlayerId, text, isTeam); + _CServerGameDLL__OnReceivedSayTextMessage(self, nSenderPlayerIndex, text, isTeam); } void ChatSendMessage(unsigned int playerIndex, const char* text, bool isTeam) diff --git a/NorthstarDLL/squirrel.cpp b/NorthstarDLL/squirrel.cpp index 23935827..d130aed7 100644 --- a/NorthstarDLL/squirrel.cpp +++ b/NorthstarDLL/squirrel.cpp @@ -489,7 +489,7 @@ ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (CModule module)) g_pSquirrel->__sq_getuserdata = module.Offset(0x63D0).As(); g_pSquirrel->__sq_getvector = module.Offset(0x6140).As(); g_pSquirrel->__sq_getthisentity = module.Offset(0x12F80).As(); - g_pSquirrel->__sq_getentity = module.Offset(0x6140).As(); + g_pSquirrel->__sq_getobject = module.Offset(0x6160).As(); g_pSquirrel->__sq_getstring = g_pSquirrel->__sq_getstring; g_pSquirrel->__sq_getinteger = g_pSquirrel->__sq_getinteger; g_pSquirrel->__sq_getfloat = g_pSquirrel->__sq_getfloat; @@ -499,13 +499,20 @@ ON_DLL_LOAD_RELIESON("client.dll", ClientSquirrel, ConCommand, (CModule module)) g_pSquirrel->__sq_getuserdata = g_pSquirrel->__sq_getuserdata; g_pSquirrel->__sq_getvector = g_pSquirrel->__sq_getvector; g_pSquirrel->__sq_getthisentity = g_pSquirrel->__sq_getthisentity; - g_pSquirrel->__sq_getentity = g_pSquirrel->__sq_getentity; + g_pSquirrel->__sq_getobject = g_pSquirrel->__sq_getobject; g_pSquirrel->__sq_createuserdata = module.Offset(0x38D0).As(); g_pSquirrel->__sq_setuserdatatypeid = module.Offset(0x6490).As(); g_pSquirrel->__sq_createuserdata = g_pSquirrel->__sq_createuserdata; g_pSquirrel->__sq_setuserdatatypeid = g_pSquirrel->__sq_setuserdatatypeid; + g_pSquirrel->__sq_GetEntityConstant_CBaseEntity = module.Offset(0x3E49B0).As(); + g_pSquirrel->__sq_getentityfrominstance = module.Offset(0x114F0).As(); + g_pSquirrel->__sq_GetEntityConstant_CBaseEntity = + g_pSquirrel->__sq_GetEntityConstant_CBaseEntity; + g_pSquirrel->__sq_getentityfrominstance = g_pSquirrel->__sq_getentityfrominstance; + + MAKEHOOK( module.Offset(0x108E0), &RegisterSquirrelFunctionHook, @@ -568,11 +575,14 @@ ON_DLL_LOAD_RELIESON("server.dll", ServerSquirrel, ConCommand, (CModule module)) g_pSquirrel->__sq_getvector = module.Offset(0x6120).As(); g_pSquirrel->__sq_get = module.Offset(0x7C00).As(); g_pSquirrel->__sq_getthisentity = module.Offset(0x203B0).As(); - g_pSquirrel->__sq_getentity = module.Offset(0x6120).As(); + g_pSquirrel->__sq_getobject = module.Offset(0x6140).As(); g_pSquirrel->__sq_createuserdata = module.Offset(0x38D0).As(); g_pSquirrel->__sq_setuserdatatypeid = module.Offset(0x6470).As(); + g_pSquirrel->__sq_GetEntityConstant_CBaseEntity = module.Offset(0x418AF0).As(); + g_pSquirrel->__sq_getentityfrominstance = module.Offset(0x1E920).As(); + MAKEHOOK( module.Offset(0x1DD10), &RegisterSquirrelFunctionHook, diff --git a/NorthstarDLL/squirrel.h b/NorthstarDLL/squirrel.h index de99b9d0..bc738428 100644 --- a/NorthstarDLL/squirrel.h +++ b/NorthstarDLL/squirrel.h @@ -122,12 +122,16 @@ typedef SQRESULT (*sq_getassetType)(HSquirrelVM* sqvm, SQInteger iStackpos, cons typedef SQRESULT (*sq_getuserdataType)(HSquirrelVM* sqvm, SQInteger iStackpos, void** pData, uint64_t* pTypeId); typedef SQFloat* (*sq_getvectorType)(HSquirrelVM* sqvm, SQInteger iStackpos); typedef SQBool (*sq_getthisentityType)(HSquirrelVM*, void** ppEntity); -typedef void* (*sq_getentityType)(HSquirrelVM*, SQInteger iStackPos); +typedef void (*sq_getobjectType)(HSquirrelVM*, SQInteger iStackPos, SQObject* pOutObj); // sq stack userpointer funcs typedef void* (*sq_createuserdataType)(HSquirrelVM* sqvm, SQInteger iSize); typedef SQRESULT (*sq_setuserdatatypeidType)(HSquirrelVM* sqvm, SQInteger iStackpos, uint64_t iTypeId); +// sq misc entity funcs +typedef void* (*sq_getentityfrominstanceType)(CSquirrelVM* sqvm, SQObject* pInstance, char** ppEntityConstant); +typedef char** (*sq_GetEntityConstantType)(); + template class SquirrelManager { private: @@ -171,10 +175,13 @@ template class SquirrelManager sq_getuserdataType __sq_getuserdata; sq_getvectorType __sq_getvector; sq_getthisentityType __sq_getthisentity; - sq_getentityType __sq_getentity; + sq_getobjectType __sq_getobject; sq_createuserdataType __sq_createuserdata; sq_setuserdatatypeidType __sq_setuserdatatypeid; + + sq_getentityfrominstanceType __sq_getentityfrominstance; + sq_GetEntityConstantType __sq_GetEntityConstant_CBaseEntity; #pragma endregion public: @@ -324,7 +331,11 @@ template class SquirrelManager template inline T* getentity(HSquirrelVM* sqvm, SQInteger iStackPos) { - return (T*)__sq_getentity(sqvm, iStackPos); + SQObject obj; + __sq_getobject(sqvm, iStackPos, &obj); + + // there are entity constants for other types, but seemingly CBaseEntity's is the only one needed + return (T*) __sq_getentityfrominstance(m_pSQVM, &obj, __sq_GetEntityConstant_CBaseEntity()); } #pragma endregion }; -- cgit v1.2.3