From 03c1690b97555333c10a4ef5c611e745d43ed391 Mon Sep 17 00:00:00 2001 From: hzqst <113660872@qq.com> Date: Tue, 10 Jan 2023 14:20:48 +0800 Subject: [PATCH] Fix a typo in R_StudioDrawPlayer hook handler which was causing crash in Opposing Force. #224 --- Plugins/BulletPhysics/exportfuncs.cpp | 4 +- Plugins/BulletPhysics/mathlib.cpp | 1 - Plugins/BulletPhysics/physics.cpp | 80 ++++----------------------- Plugins/BulletPhysics/physics.h | 1 - Plugins/BulletPhysics/privatehook.cpp | 2 - 5 files changed, 13 insertions(+), 75 deletions(-) diff --git a/Plugins/BulletPhysics/exportfuncs.cpp b/Plugins/BulletPhysics/exportfuncs.cpp index 2302fb28..baf67455 100644 --- a/Plugins/BulletPhysics/exportfuncs.cpp +++ b/Plugins/BulletPhysics/exportfuncs.cpp @@ -436,7 +436,7 @@ int __fastcall GameStudioRenderer_StudioDrawModel(void *pthis, int dummy, int fl //EngineDrawPlayer -int __fastcall R_StudioDrawPlayer(int flags, struct entity_state_s *pplayer) +int R_StudioDrawPlayer(int flags, struct entity_state_s *pplayer) { int playerindex = pplayer->number; @@ -1137,7 +1137,7 @@ void HUD_Init(void) bv_debug = gEngfuncs.pfnRegisterVariable("bv_debug", "0", FCVAR_CLIENTDLL); bv_simrate = gEngfuncs.pfnRegisterVariable("bv_simrate", "64", FCVAR_CLIENTDLL | FCVAR_ARCHIVE); - bv_scale = gEngfuncs.pfnRegisterVariable("bv_scale", "0.5", FCVAR_CLIENTDLL | FCVAR_ARCHIVE); + bv_scale = gEngfuncs.pfnRegisterVariable("bv_scale", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE); bv_enable = gEngfuncs.pfnRegisterVariable("bv_enable", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE); bv_syncview = gEngfuncs.pfnRegisterVariable("bv_syncview", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE); diff --git a/Plugins/BulletPhysics/mathlib.cpp b/Plugins/BulletPhysics/mathlib.cpp index 2298473a..51201bf2 100644 --- a/Plugins/BulletPhysics/mathlib.cpp +++ b/Plugins/BulletPhysics/mathlib.cpp @@ -890,7 +890,6 @@ void Matrix4x4_Transpose(float out[4][4], float in1[4][4]) out[3][3] = in1[3][3]; } - void Matrix4x4_CreateFromEntity(float out[4][4], const vec3_t angles, const vec3_t origin, float scale) { float angle, sr, sp, sy, cr, cp, cy; diff --git a/Plugins/BulletPhysics/physics.cpp b/Plugins/BulletPhysics/physics.cpp index 7c106278..bc6771a3 100644 --- a/Plugins/BulletPhysics/physics.cpp +++ b/Plugins/BulletPhysics/physics.cpp @@ -431,56 +431,6 @@ CStaticBody *CPhysicsManager::CreateStaticBody(cl_entity_t *ent, vertexarray_t * return staticbody; } -void CPhysicsManager::RotateForEntity(cl_entity_t *e, float matrix[4][4]) -{ - int i; - vec3_t angles; - vec3_t modelpos; - - VectorCopy(e->origin, modelpos); - VectorCopy(e->angles, angles); - - if (e->curstate.movetype != MOVETYPE_NONE) - { - float f; - float d; - - if (e->curstate.animtime + 0.2f > gEngfuncs.GetClientTime() && e->curstate.animtime != e->latched.prevanimtime) - { - f = (gEngfuncs.GetClientTime() - e->curstate.animtime) / (e->curstate.animtime - e->latched.prevanimtime); - } - else - { - f = 0; - } - - for (i = 0; i < 3; i++) - { - modelpos[i] -= (e->latched.prevorigin[i] - e->origin[i]) * f; - } - - if (f != 0.0f && f < 1.5f) - { - f = 1.0f - f; - - for (i = 0; i < 3; i++) - { - d = e->latched.prevangles[i] - e->angles[i]; - - if (d > 180.0) - d -= 360.0; - else if (d < -180.0) - d += 360.0; - - angles[i] += d * f; - } - } - } - - memcpy(matrix, r_identity_matrix, sizeof(r_identity_matrix)); - Matrix4x4_CreateFromEntity(matrix, angles, modelpos, 1); -} - void CPhysicsManager::CreateBarnacle(cl_entity_t *ent) { auto itor = m_staticMap.find(ent->index); @@ -2263,11 +2213,11 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con shape->calculateLocalInertia(mass, localInertia); btRigidBody::btRigidBodyConstructionInfo cInfo(mass, motionState, shape, localInertia); - cInfo.m_friction = 0.5f; + cInfo.m_friction = 1.0f; cInfo.m_rollingFriction = 1.0; cInfo.m_restitution = 0; - cInfo.m_linearSleepingThreshold = 50.0f; - cInfo.m_angularSleepingThreshold = 12.0f; + cInfo.m_linearSleepingThreshold = 10.0f; + cInfo.m_angularSleepingThreshold = 4.5f; cInfo.m_linearDamping = 0.25f; cInfo.m_angularDamping = 0.25f; FloatGoldSrcToBullet(&cInfo.m_linearSleepingThreshold); @@ -2282,8 +2232,8 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con rig->rigbody->setUserPointer(rig); - float ccdThreshould = 50.0f; - float ccdRadius = rigsize; + float ccdThreshould = 1.0f; + float ccdRadius = rigsize * 0.5; FloatGoldSrcToBullet(&ccdThreshould); @@ -2319,13 +2269,14 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con shape->calculateLocalInertia(mass, localInertia); btRigidBody::btRigidBodyConstructionInfo cInfo(mass, motionState, shape, localInertia); - cInfo.m_friction = 0.5f; + cInfo.m_friction = 1.0f; cInfo.m_rollingFriction = 1.0f; cInfo.m_restitution = 0; - cInfo.m_linearSleepingThreshold = 50.0f; - cInfo.m_angularSleepingThreshold = 12.0f; + cInfo.m_linearSleepingThreshold = 10.0f; + cInfo.m_angularSleepingThreshold = 3 * SIMD_RADS_PER_DEG; cInfo.m_linearDamping = 0.25f; cInfo.m_angularDamping = 0.25f; + cInfo.m_additionalDamping = true; FloatGoldSrcToBullet(&cInfo.m_linearSleepingThreshold); @@ -2339,8 +2290,8 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con rig->rigbody->setUserPointer(rig); - float ccdThreshould = 50.0f; - float ccdRadius = max(rigsize, rigsize2); + float ccdThreshould = 1.0f; + float ccdRadius = max(rigsize, rigsize2) * 0.5; FloatGoldSrcToBullet(&ccdThreshould); @@ -2395,15 +2346,6 @@ CRigBody *CPhysicsManager::CreateRigBody(studiohdr_t *studiohdr, ragdoll_rig_con rig->rigbody->setUserPointer(rig); - float ccdThreshould = 2.5; - float ccdRadius = 1.25; - - FloatGoldSrcToBullet(&ccdThreshould); - FloatGoldSrcToBullet(&ccdRadius); - - rig->rigbody->setCcdMotionThreshold(ccdThreshould); - rig->rigbody->setCcdSweptSphereRadius(ccdRadius); - m_dynamicsWorld->addRigidBody(rig->rigbody, rig->group, rig->mask); return rig; diff --git a/Plugins/BulletPhysics/physics.h b/Plugins/BulletPhysics/physics.h index 25ad67f1..73049d40 100644 --- a/Plugins/BulletPhysics/physics.h +++ b/Plugins/BulletPhysics/physics.h @@ -574,7 +574,6 @@ class CPhysicsManager void CreateBrushModel(cl_entity_t *ent); void CreateBarnacle(cl_entity_t *ent); void CreateGargantua(cl_entity_t *ent); - void RotateForEntity(cl_entity_t *ent, float matrix[4][4]); void ReleaseRagdollFromBarnacle(CRagdollBody *ragdoll); void ReleaseRagdollFromGargantua(CRagdollBody *ragdoll); bool GetRagdollOrigin(CRagdollBody *ragdoll, float *origin); diff --git a/Plugins/BulletPhysics/privatehook.cpp b/Plugins/BulletPhysics/privatehook.cpp index d0126b4d..9e3017e3 100644 --- a/Plugins/BulletPhysics/privatehook.cpp +++ b/Plugins/BulletPhysics/privatehook.cpp @@ -323,8 +323,6 @@ void Client_FillAddress(void) g_iUser2 = (decltype(g_iUser2))ctx.Candidates[ctx.iNumCandidates - 1]; } } - - } void R_NewMap(void)