Improve LagCompensation

This commit is contained in:
BotoX 2019-10-02 18:54:19 +02:00
parent 5f1e06177c
commit b15cb74b1c
2 changed files with 72 additions and 56 deletions

View File

@ -10,22 +10,16 @@
"linux" "@_ZN11CBaseEntity20PhysicsTouchTriggersEPK6Vector" "linux" "@_ZN11CBaseEntity20PhysicsTouchTriggersEPK6Vector"
} }
"SetLocalOrigin" "SetAbsOrigin"
{ {
"library" "server" "library" "server"
"linux" "@_ZN11CBaseEntity14SetLocalOriginERK6Vector" "linux" "@_ZN11CBaseEntity12SetAbsOriginERK6Vector"
} }
"SetLocalAngles" "SetAbsAngles"
{ {
"library" "server" "library" "server"
"linux" "@_ZN11CBaseEntity14SetLocalAnglesERK6QAngle" "linux" "@_ZN11CBaseEntity12SetAbsAnglesERK6QAngle"
}
"SetCollisionBounds"
{
"library" "server"
"linux" "@_ZN11CBaseEntity18SetCollisionBoundsERK6VectorS2_"
} }
} }

View File

@ -20,14 +20,13 @@ bool g_bLateLoad = false;
bool g_bBlockPhysics = false; bool g_bBlockPhysics = false;
bool g_bNoPhysics[2048]; bool g_bNoPhysics[2048];
#define MAX_RECORDS 64 #define MAX_RECORDS 32
#define MAX_ENTITIES 16 #define MAX_ENTITIES 16
enum struct LagRecord enum struct LagRecord
{ {
float vecOrigin[3]; float vecOrigin[3];
float vecAngles[3]; float vecAngles[3];
float flSimulationTime;
} }
enum struct EntityLagData enum struct EntityLagData
@ -36,6 +35,7 @@ enum struct EntityLagData
int iRecordIndex; int iRecordIndex;
int iNumRecords; int iNumRecords;
bool bRestore; bool bRestore;
bool bMoving;
LagRecord RestoreData; LagRecord RestoreData;
} }
@ -44,9 +44,8 @@ EntityLagData g_aEntityLagData[MAX_ENTITIES];
int g_iNumEntities = 0; int g_iNumEntities = 0;
Handle g_hPhysicsTouchTriggers; Handle g_hPhysicsTouchTriggers;
Handle g_hSetLocalOrigin; Handle g_hSetAbsOrigin;
Handle g_hSetLocalAngles; Handle g_hSetAbsAngles;
Handle g_hSetCollisionBounds;
public void OnPluginStart() public void OnPluginStart()
{ {
@ -54,36 +53,25 @@ public void OnPluginStart()
if(!hGameData) if(!hGameData)
SetFailState("Failed to load LagCompensation gamedata."); SetFailState("Failed to load LagCompensation gamedata.");
// CBaseEntity::SetLocalOrigin // CBaseEntity::SetAbsOrigin
StartPrepSDKCall(SDKCall_Entity); StartPrepSDKCall(SDKCall_Entity);
if(!PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, "SetLocalOrigin")) if(!PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, "SetAbsOrigin"))
{ {
delete hGameData; delete hGameData;
SetFailState("PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, \"SetLocalOrigin\") failed!"); SetFailState("PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, \"SetAbsOrigin\") failed!");
} }
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef); PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
g_hSetLocalOrigin = EndPrepSDKCall(); g_hSetAbsOrigin = EndPrepSDKCall();
// CBaseEntity::SetLocalAngles // CBaseEntity::SetAbsAngles
StartPrepSDKCall(SDKCall_Entity); StartPrepSDKCall(SDKCall_Entity);
if(!PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, "SetLocalAngles")) if(!PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, "SetAbsAngles"))
{ {
delete hGameData; delete hGameData;
SetFailState("PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, \"SetLocalAngles\") failed!"); SetFailState("PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, \"SetAbsAngles\") failed!");
} }
PrepSDKCall_AddParameter(SDKType_QAngle, SDKPass_ByRef); PrepSDKCall_AddParameter(SDKType_QAngle, SDKPass_ByRef);
g_hSetLocalAngles = EndPrepSDKCall(); g_hSetAbsAngles = EndPrepSDKCall();
// CBaseEntity::SetCollisionBounds
StartPrepSDKCall(SDKCall_Entity);
if(!PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, "SetCollisionBounds"))
{
delete hGameData;
SetFailState("PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, \"SetCollisionBounds\") failed!");
}
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
g_hSetCollisionBounds = EndPrepSDKCall();
g_hPhysicsTouchTriggers = DHookCreateFromConf(hGameData, "CBaseEntity__PhysicsTouchTriggers"); g_hPhysicsTouchTriggers = DHookCreateFromConf(hGameData, "CBaseEntity__PhysicsTouchTriggers");
@ -149,7 +137,7 @@ public void OnRunThinkFunctions(bool simulating)
{ {
for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++, j--) for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++, j--)
{ {
if(g_aEntityLagData[i].iEntity == 0) if(g_aEntityLagData[i].iEntity == 0 || !g_aEntityLagData[i].bMoving)
continue; continue;
if(!IsValidEntity(g_aEntityLagData[i].iEntity)) if(!IsValidEntity(g_aEntityLagData[i].iEntity))
@ -162,7 +150,7 @@ public void OnRunThinkFunctions(bool simulating)
RecordDataIntoRecord(g_aEntityLagData[i].iEntity, g_aEntityLagData[i].RestoreData); RecordDataIntoRecord(g_aEntityLagData[i].iEntity, g_aEntityLagData[i].RestoreData);
#if defined DEBUG #if defined DEBUG
LogMessage("[%d] index %d, RECORD entity %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity, g_aEntityLagData[i].iRecordIndex); LogMessage("1 [%d] [%d] index %d, RECORD entity %d", GetGameTickCount(), i, simulating, g_aEntityLagData[i].iEntity, g_aEntityLagData[i].iRecordIndex);
LogMessage("%f %f %f", LogMessage("%f %f %f",
g_aEntityLagData[i].RestoreData.vecOrigin[0], g_aEntityLagData[i].RestoreData.vecOrigin[0],
g_aEntityLagData[i].RestoreData.vecOrigin[1], g_aEntityLagData[i].RestoreData.vecOrigin[1],
@ -183,7 +171,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++, j--) for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++, j--)
{ {
if(g_aEntityLagData[i].iEntity == 0 || g_aEntityLagData[i].iNumRecords == 0) if(g_aEntityLagData[i].iEntity == 0 || !g_aEntityLagData[i].bMoving)
continue; continue;
if(!IsValidEntity(g_aEntityLagData[i].iEntity)) if(!IsValidEntity(g_aEntityLagData[i].iEntity))
@ -205,7 +193,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
g_aEntityLagData[i].bRestore = true; g_aEntityLagData[i].bRestore = true;
#if defined DEBUG #if defined DEBUG
LogMessage("[%d] index %d, Entity %d -> delta = %d | Record = %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity, delta, iRecordIndex); LogMessage("2 [%d] index %d, Entity %d -> delta = %d | Record = %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity, delta, iRecordIndex);
LogMessage("%f %f %f", LogMessage("%f %f %f",
g_aaLagRecords[i][iRecordIndex].vecOrigin[0], g_aaLagRecords[i][iRecordIndex].vecOrigin[0],
g_aaLagRecords[i][iRecordIndex].vecOrigin[1], g_aaLagRecords[i][iRecordIndex].vecOrigin[1],
@ -217,7 +205,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
return Plugin_Continue; return Plugin_Continue;
} }
public void OnPostPlayerThinkFunctionsPost() public void OnPostPlayerThinkFunctions()
{ {
for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++, j--) for(int i = 0, j = g_iNumEntities; i < MAX_ENTITIES, j; i++, j--)
{ {
@ -236,7 +224,7 @@ public void OnPostPlayerThinkFunctionsPost()
g_aEntityLagData[i].bRestore = false; g_aEntityLagData[i].bRestore = false;
#if defined DEBUG #if defined DEBUG
LogMessage("[%d] index %d, RESTORE entity %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity, g_aEntityLagData[i].iRecordIndex); LogMessage("3 [%d] index %d, RESTORE entity %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity, g_aEntityLagData[i].iRecordIndex);
LogMessage("%f %f %f", LogMessage("%f %f %f",
g_aEntityLagData[i].RestoreData.vecOrigin[0], g_aEntityLagData[i].RestoreData.vecOrigin[0],
g_aEntityLagData[i].RestoreData.vecOrigin[1], g_aEntityLagData[i].RestoreData.vecOrigin[1],
@ -263,6 +251,25 @@ public void OnRunThinkFunctionsPost(bool simulating)
continue; continue;
} }
if(g_aEntityLagData[i].iNumRecords)
{
if(!g_aEntityLagData[i].bMoving)
{
float vecOldOrigin[3];
vecOldOrigin[0] = g_aaLagRecords[i][0].vecOrigin[0];
vecOldOrigin[1] = g_aaLagRecords[i][0].vecOrigin[1];
vecOldOrigin[2] = g_aaLagRecords[i][0].vecOrigin[2];
float vecOrigin[3];
GetEntPropVector(g_aEntityLagData[i].iEntity, Prop_Data, "m_vecAbsOrigin", vecOrigin);
if(vecOldOrigin[0] == vecOrigin[0] && vecOldOrigin[1] == vecOrigin[1] && vecOldOrigin[2] == vecOrigin[2])
continue;
}
g_aEntityLagData[i].bMoving = true;
}
g_aEntityLagData[i].iRecordIndex++; g_aEntityLagData[i].iRecordIndex++;
if(g_aEntityLagData[i].iRecordIndex >= MAX_RECORDS) if(g_aEntityLagData[i].iRecordIndex >= MAX_RECORDS)
@ -274,7 +281,7 @@ public void OnRunThinkFunctionsPost(bool simulating)
RecordDataIntoRecord(g_aEntityLagData[i].iEntity, g_aaLagRecords[i][g_aEntityLagData[i].iRecordIndex]); RecordDataIntoRecord(g_aEntityLagData[i].iEntity, g_aaLagRecords[i][g_aEntityLagData[i].iRecordIndex]);
#if defined DEBUG #if defined DEBUG
LogMessage("[%d] index %d, RECORD entity %d into %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity, g_aEntityLagData[i].iRecordIndex); LogMessage("4 [%d] index %d, RECORD entity %d into %d", GetGameTickCount(), i, g_aEntityLagData[i].iEntity, g_aEntityLagData[i].iRecordIndex);
LogMessage("%f %f %f", LogMessage("%f %f %f",
g_aaLagRecords[i][g_aEntityLagData[i].iRecordIndex].vecOrigin[0], g_aaLagRecords[i][g_aEntityLagData[i].iRecordIndex].vecOrigin[0],
g_aaLagRecords[i][g_aEntityLagData[i].iRecordIndex].vecOrigin[1], g_aaLagRecords[i][g_aEntityLagData[i].iRecordIndex].vecOrigin[1],
@ -290,16 +297,14 @@ void RecordDataIntoRecord(int iEntity, LagRecord Record)
{ {
GetEntPropVector(iEntity, Prop_Data, "m_vecAbsOrigin", Record.vecOrigin); GetEntPropVector(iEntity, Prop_Data, "m_vecAbsOrigin", Record.vecOrigin);
GetEntPropVector(iEntity, Prop_Data, "m_angAbsRotation", Record.vecAngles); GetEntPropVector(iEntity, Prop_Data, "m_angAbsRotation", Record.vecAngles);
Record.flSimulationTime = GetEntPropFloat(iEntity, Prop_Data, "m_flSimulationTime");
} }
void RestoreEntityFromRecord(int iEntity, int iFilter, LagRecord Record) void RestoreEntityFromRecord(int iEntity, int iFilter, LagRecord Record)
{ {
FilterTriggerMoved(iFilter); FilterTriggerMoved(iFilter);
SetEntPropFloat(iEntity, Prop_Data, "m_flSimulationTime", Record.flSimulationTime); SDKCall(g_hSetAbsAngles, iEntity, Record.vecAngles);
SDKCall(g_hSetLocalAngles, iEntity, Record.vecAngles); SDKCall(g_hSetAbsOrigin, iEntity, Record.vecOrigin);
SDKCall(g_hSetLocalOrigin, iEntity, Record.vecOrigin);
FilterTriggerMoved(-1); FilterTriggerMoved(-1);
} }
@ -322,6 +327,7 @@ bool AddEntityForLagCompensation(int iEntity)
g_aEntityLagData[i].iEntity = iEntity; g_aEntityLagData[i].iEntity = iEntity;
g_aEntityLagData[i].iRecordIndex = -1; g_aEntityLagData[i].iRecordIndex = -1;
g_aEntityLagData[i].iNumRecords = 0; g_aEntityLagData[i].iNumRecords = 0;
g_aEntityLagData[i].bMoving = false;
LogMessage("[%d] added %d under index %d", GetGameTickCount(), iEntity, i); LogMessage("[%d] added %d under index %d", GetGameTickCount(), iEntity, i);
@ -345,29 +351,45 @@ public void OnEntitySpawned(int entity, const char[] classname)
if(!StrEqual(classname, "trigger_hurt")) if(!StrEqual(classname, "trigger_hurt"))
return; return;
int iParent = GetEntPropEnt(entity, Prop_Data, "m_pParent"); int iParent = entity;
char sParentClassname[64];
bool bGoodParents = false;
for(;;)
{
iParent = GetEntPropEnt(iParent, Prop_Data, "m_pParent");
if(iParent == -1)
break;
GetEntityClassname(iParent, sParentClassname, sizeof(sParentClassname));
if(StrEqual(sParentClassname, "func_movelinear") || StrEqual(sParentClassname, "func_door") || StrEqual(sParentClassname, "func_tracktrain"))
{
bGoodParents = true;
break;
}
}
if(iParent == -1) if(iParent == -1)
return; return;
char sParentClassname[64];
GetEntityClassname(iParent, sParentClassname, sizeof(sParentClassname));
char sTargetname[64]; char sTargetname[64];
GetEntPropString(entity, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname)); GetEntPropString(entity, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname));
char sParentTargetname[64]; char sParentTargetname[64];
GetEntPropString(iParent, Prop_Data, "m_iName", sParentTargetname, sizeof(sParentTargetname)); GetEntPropString(iParent, Prop_Data, "m_iName", sParentTargetname, sizeof(sParentTargetname));
if(StrEqual(sParentTargetname, "Airship_Ending_Killwall")) LogMessage("test: %s %s | parent: %s %s", classname, sTargetname, sParentClassname, sParentTargetname);
if(!bGoodParents)
return;
int SolidFlags = GetEntProp(iParent, Prop_Data, "m_usSolidFlags");
LogMessage("SolidFlags: %d", SolidFlags);
if(!(SolidFlags & 0x0004) && false) // FSOLID_NOT_SOLID
return; return;
bool result = false; if(!AddEntityForLagCompensation(entity))
if(StrEqual(sParentClassname, "func_movelinear") || StrEqual(sParentClassname, "func_door") || StrEqual(sParentClassname, "func_tracktrain"))
result = AddEntityForLagCompensation(iParent);
if(!result)
return; return;
g_bNoPhysics[entity] = true; g_bNoPhysics[entity] = true;