void CClientTools::StartRecording(wchar_t const * fileName) { EndRecording(); m_Recording = true; Dictionary_Clear(); m_File = 0; m_HiddenFileOffset = 0; m_Hidden.clear(); _wfopen_s(&m_File, fileName, L"wb"); if (m_File) { fputs("afxGameRecord", m_File); fputc('\0', m_File); int version = 4; fwrite(&version, sizeof(version), 1, m_File); } else Tier0_Warning("ERROR opening file \"%s\" for writing.\n", fileName); if (!EnableRecordingMode_get() && !SuppotsAutoEnableRecordingMode()) { Tier0_Warning( "WARNING: The recording needs to be enabled with [...] enabled 1 before loading the demo!\n" "(This is required, because this game leaks memory when recording mode is enabled.)\n" "Enabling the recording (but it might be too late already).\n" ); EnableRecordingMode_set(true); } }
WrpConVarRef::WrpConVarRef(char const * pName) : m_pConVar007(0) { ICvar_007 * iCvar007 = WrpConCommands::GetVEngineCvar007(); if(iCvar007) { m_pConVar007 = iCvar007->FindVar(pName); } if(!m_pConVar007) { Tier0_Warning("AfxError: WrpConVarRef::WrpConVarRef(%s): Could not get ConVar.\n", pName); } }
void touring_csgo__RecvProxy_m_flCycle(const csgo_CRecvProxyData_t *pData, void *pStruct, void *pOut) { volatile float * pValue = (float *)((char const *)pData + 0x8); float oldCycle = *(float *)pOut; float newCycle = *pValue; bool broken = 0.0f != newCycle && ( oldCycle > newCycle && 0.5f > oldCycle -newCycle || oldCycle < newCycle && 0.5f < newCycle -oldCycle ); if (g_csgo_PlayerAnimStateFix) { float orgValue; bool fixed = g_CsgoPlayerAnimStateFix.Fix((float *)pValue, (float *)pOut, orgValue); detoured_csgo_RecvProxy_m_flCycle(pData, pStruct, pOut); //Tier0_Msg("touring_csgo__RecvProxy_m_flCycle: %f\n", *pValue); if(fixed) *pValue = orgValue; //g_csgo_PlayerAnimStateFix_origValues.emplace_back(p_m_flPlaybackRate); // we want to get at m_flPlayBackRate later on :-) return; } static DWORD lastTickCount = 0; DWORD tickCount = GetTickCount(); if(broken && (lastTickCount +10000 <= tickCount || tickCount <= lastTickCount -10000)) { Tier0_Warning("touring_csgo__RecvProxy_m_flCycle: HLAE detected cycle inconsistency at 0x%08x: %f -> %f! You may want to use \"mirv_fix playerAnimState 1\"! (Supressing warnings for 10 seconds.)\n", pOut, oldCycle, newCycle); lastTickCount = tickCount; } detoured_csgo_RecvProxy_m_flCycle(pData, pStruct, pOut); }
void CCampathDrawer::OnPostRenderAllTools() { // Actually we are often called twice per frame due to an engine bug(?), once after 3d skybox // and once after world is drawn, maybe we will be even called more times, // but we can not care about that for now. if(!m_Draw) return; if(!m_VertexShader) { m_VertexShader = g_AfxShaders.GetVertexShader("afx_line_vs20.fxo"); } IDirect3DVertexShader9 * vertexShader = m_VertexShader->GetVertexShader(); if(!m_PixelShader) { m_PixelShader = g_AfxShaders.GetPixelShader("afx_line_ps20.fxo"); } IDirect3DPixelShader9 * pixelShader = m_PixelShader->GetPixelShader(); if(!(m_Device && vertexShader && m_PixelShader && g_VEngineClient)) { static bool firstError = true; if(firstError) { firstError = false; Tier0_Msg( "AFXERROR: CCampathDrawer::OnEndScene: Missing required dependencies:%s%s%s%s.\n", !m_Device ? " m_Device" : "", !vertexShader ? " vertexShader" : "", !pixelShader ? " pixelShader" : "", !g_VEngineClient ? " g_VEngineClient" : "" ); } return; } // Save device state: IDirect3DPixelShader9 * oldPixelShader = 0; m_Device->GetPixelShader(&oldPixelShader); if(oldPixelShader) oldPixelShader->AddRef(); IDirect3DVertexShader9 * oldVertexShader = 0; m_Device->GetVertexShader(&oldVertexShader); if(oldVertexShader) oldVertexShader->AddRef(); IDirect3DVertexBuffer9 * oldVertexBuffer = 0; UINT oldVertexBufferOffset; UINT oldVertexBufferStride; m_Device->GetStreamSource(0, &oldVertexBuffer, &oldVertexBufferOffset, &oldVertexBufferStride); // this is done already according to doc: // if(oldVertexBuffer) oldVertexBuffer->AddRef(); IDirect3DIndexBuffer9 * oldIndexBuffer = 0; m_Device->GetIndices(&oldIndexBuffer); // this is done already according to doc: // if(oldIndexBuffer) oldIndexBuffer->AddRef(); IDirect3DVertexDeclaration9 * oldDeclaration; m_Device->GetVertexDeclaration(&oldDeclaration); if(oldDeclaration) oldDeclaration->AddRef(); DWORD oldFVF; m_Device->GetFVF(&oldFVF); FLOAT oldCViewProj[4][4]; m_Device->GetVertexShaderConstantF(8, oldCViewProj[0], 4); FLOAT oldCScreenInfo[4]; m_Device->GetVertexShaderConstantF(48, oldCScreenInfo, 1); FLOAT oldCPlane0[4]; m_Device->GetVertexShaderConstantF(49, oldCPlane0, 1); FLOAT oldCPlaneN[4]; m_Device->GetVertexShaderConstantF(50, oldCPlaneN, 1); DWORD oldSrgbWriteEnable; m_Device->GetRenderState(D3DRS_SRGBWRITEENABLE, &oldSrgbWriteEnable); DWORD oldColorWriteEnable; m_Device->GetRenderState(D3DRS_COLORWRITEENABLE, &oldColorWriteEnable); DWORD oldZEnable; m_Device->GetRenderState(D3DRS_ZENABLE, &oldZEnable); DWORD oldZWriteEnable; m_Device->GetRenderState(D3DRS_ZWRITEENABLE, &oldZWriteEnable); DWORD oldZFunc; m_Device->GetRenderState(D3DRS_ZFUNC, &oldZFunc); DWORD oldAlphaTestEnable; m_Device->GetRenderState(D3DRS_ALPHATESTENABLE, &oldAlphaTestEnable); DWORD oldSeparateAlphaBlendEnable; m_Device->GetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, &oldSeparateAlphaBlendEnable); DWORD oldAlphaBlendEnable; m_Device->GetRenderState(D3DRS_ALPHABLENDENABLE, &oldAlphaBlendEnable); DWORD oldBlendOp; m_Device->GetRenderState(D3DRS_BLENDOP, &oldBlendOp); DWORD oldSrcBlend; m_Device->GetRenderState(D3DRS_SRCBLEND, &oldSrcBlend); DWORD oldDestBlend; m_Device->GetRenderState(D3DRS_DESTBLEND, &oldDestBlend); DWORD oldCullMode; m_Device->GetRenderState(D3DRS_CULLMODE, &oldCullMode); // Draw: { //Vector3 vvForward, vvUp, vvRight, vvPos; double curTime = g_Hook_VClient_RenderView.GetCurTime(); bool inCampath = 1 <= g_Hook_VClient_RenderView.m_CamPath.GetSize() && g_Hook_VClient_RenderView.m_CamPath.GetLowerBound() <= curTime && curTime <= g_Hook_VClient_RenderView.m_CamPath.GetUpperBound(); bool campathCanEval = g_Hook_VClient_RenderView.m_CamPath.CanEval(); bool campathEnabled = g_Hook_VClient_RenderView.m_CamPath.Enabled_get(); bool cameraMightBeSelected = false; m_Device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE); m_Device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA|D3DCOLORWRITEENABLE_BLUE|D3DCOLORWRITEENABLE_GREEN|D3DCOLORWRITEENABLE_RED); m_Device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); m_Device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); m_Device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL); m_Device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); m_Device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE); m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); m_Device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); m_Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); m_Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); m_Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); m_Device->SetVertexShader(vertexShader); m_WorldToScreenMatrix = g_VEngineClient->WorldToScreenMatrix(); m_Device->SetVertexShaderConstantF(8, m_WorldToScreenMatrix.m[0], 4); // Provide view plane info for line clipping: { double plane0[4]={0,0,0,1}; double planeN[4]={1,0,0,1}; //double planeR[4]={0,-1,0,1}; //double planeU[4]={0,0,1,1}; unsigned char P[4]; unsigned char Q[4]; double L[4][4]; double U[4][4]; double M[4][4] = { m_WorldToScreenMatrix.m[0][0], m_WorldToScreenMatrix.m[0][1], m_WorldToScreenMatrix.m[0][2], 0, m_WorldToScreenMatrix.m[1][0], m_WorldToScreenMatrix.m[1][1], m_WorldToScreenMatrix.m[1][2], 0, m_WorldToScreenMatrix.m[2][0], m_WorldToScreenMatrix.m[2][1], m_WorldToScreenMatrix.m[2][2], 0, m_WorldToScreenMatrix.m[3][0], m_WorldToScreenMatrix.m[3][1], m_WorldToScreenMatrix.m[3][2], -1, }; double b0[4] = { 0 -m_WorldToScreenMatrix.m[0][3], 0 -m_WorldToScreenMatrix.m[1][3], 0 -m_WorldToScreenMatrix.m[2][3], -m_WorldToScreenMatrix.m[3][3], }; double bN[4] = { 0 -m_WorldToScreenMatrix.m[0][3], 0 -m_WorldToScreenMatrix.m[1][3], 1 -m_WorldToScreenMatrix.m[2][3], -m_WorldToScreenMatrix.m[3][3], }; /* double bR[4] = { 1 -m_WorldToScreenMatrix.m[0][3], 0 -m_WorldToScreenMatrix.m[1][3], 0 -m_WorldToScreenMatrix.m[2][3], -m_WorldToScreenMatrix.m[3][3], }; double bU[4] = { 0 -m_WorldToScreenMatrix.m[0][3], 1 -m_WorldToScreenMatrix.m[1][3], 0 -m_WorldToScreenMatrix.m[2][3], -m_WorldToScreenMatrix.m[3][3], }; */ if(!LUdecomposition(M, P, Q, L, U)) { Tier0_Warning("AFXERROR in CCampathDrawer::OnPostRenderAllTools: LUdecomposition failed\n"); } else { SolveWithLU(L, U, P, Q, b0, plane0); SolveWithLU(L, U, P, Q, bN, planeN); //SolveWithLU(L, U, P, Q, bR, planeR); //SolveWithLU(L, U, P, Q, bU, planeU); } /* vvPos = Vector3(plane0[0], plane0[1], plane0[2]); vvForward = Vector3(planeN[0] -vvPos.X, planeN[1] -vvPos.Y, planeN[2]-vvPos.Z); vvForward.Normalize(); vvRight = Vector3(planeR[0] -vvPos.X, planeR[1] -vvPos.Y, planeR[2]-vvPos.Z); vvRight.Normalize(); vvUp = Vector3(planeU[0] -vvPos.X, planeU[1] -vvPos.Y, planeU[2]-vvPos.Z); vvUp.Normalize(); */ /* Tier0_Msg("CCampathDrawer::OnPostRenderAllTools: curTime = %f\n",curTime); Tier0_Msg("M[0]=%f %f %f %f\nM[1]=%f %f %f %f\nM[2]=%f %f %f %f\nM[3]=%f %f %f %f\n", M[0][0],M[0][1],M[0][2],M[0][3], M[1][0],M[1][1],M[1][2],M[1][3], M[2][0],M[2][1],M[2][2],M[2][3], M[3][0],M[3][1],M[3][2],M[3][3]); Tier0_Msg("b0[0]=%f %f %f %f\n", b0[0], b0[1], b0[2], b0[3]); Tier0_Msg("bN[0]=%f %f %f %f\n", bN[0], bN[1], bN[2], bN[3]); Tier0_Msg("plane0=%f %f %f %f\n", plane0[0], plane0[1], plane0[2], plane0[3]); Tier0_Msg("planeN=%f %f %f %f\n", planeN[0], planeN[1], planeN[2], planeN[3]); */ FLOAT vPlane0[4] = {(float)plane0[0], (float)plane0[1], (float)plane0[2], 0.0f}; Vector3 planeNormal(planeN[0] -plane0[0], planeN[1] -plane0[1], planeN[2] -plane0[2]); planeNormal.Normalize(); FLOAT vPlaneN[4] = {(float)planeNormal.X, (float)planeNormal.Y, (float)planeNormal.Z, 0.0f}; m_Device->SetVertexShaderConstantF(49, vPlane0, 1); m_Device->SetVertexShaderConstantF(50, vPlaneN, 1); } m_Device->SetPixelShader(pixelShader); m_Device->SetFVF(CCampathDrawer_VertexFVF); int screenWidth, screenHeight; g_VEngineClient->GetScreenSize(screenWidth, screenHeight); FLOAT newCScreenInfo[4] = { 0 != screenWidth ? 1.0f / screenWidth : 0.0f, 0 != screenHeight ? 1.0f / screenHeight : 0.0f, 0.0, 0.0f}; // Draw trajectory: if(2 <= g_Hook_VClient_RenderView.m_CamPath.GetSize() && campathCanEval) { if(m_RebuildDrawing) { // Rebuild trajectory points. // This operation can be quite expensive (up to O(N^2)), // so it should be done only when s.th. // changed (which is what we do here). m_TrajectoryPoints.clear(); CamPathIterator last = g_Hook_VClient_RenderView.m_CamPath.GetBegin(); CamPathIterator it = last; TempPoint * pts = new TempPoint[c_CameraTrajectoryMaxPointsPerInterval]; for(++it; it != g_Hook_VClient_RenderView.m_CamPath.GetEnd(); ++it) { double delta = it.GetTime() -last.GetTime(); for(size_t i = 0; i<c_CameraTrajectoryMaxPointsPerInterval; i++) { double t = last.GetTime() + delta*((double)i/(c_CameraTrajectoryMaxPointsPerInterval-1)); CamPathValue cpv = g_Hook_VClient_RenderView.m_CamPath.Eval(t); pts[i].t = t; pts[i].y = Vector3(cpv.X, cpv.Y, cpv.Z); pts[i].nextPt = i+1 <c_CameraTrajectoryMaxPointsPerInterval ? &(pts[i+1]) : 0; } RamerDouglasPeucker(&(pts[0]), &(pts[c_CameraTrajectoryMaxPointsPerInterval-1]), c_CameraTrajectoryEpsilon); // add all points except the last one (to avoid duplicates): for(TempPoint * pt = &(pts[0]); pt && pt->nextPt; pt = pt->nextPt) { m_TrajectoryPoints.push_back(pt->t); } last = it; } // add last point: m_TrajectoryPoints.push_back(pts[c_CameraTrajectoryMaxPointsPerInterval-1].t); delete pts; m_RebuildDrawing = false; } newCScreenInfo[2] = c_CameraTrajectoryPixelWidth; m_Device->SetVertexShaderConstantF(48, newCScreenInfo, 1); AutoPolyLineStart(); std::list<double>::iterator itPts = m_TrajectoryPoints.begin(); CamPathIterator itKeysLast = g_Hook_VClient_RenderView.m_CamPath.GetBegin(); CamPathIterator itKeysNext = itKeysLast; ++itKeysNext; bool hasLastPt = false; bool hasNextPt = false; bool hasCurPt = false; double lastPtTime; CamPathValue lastPtValue; double curPtTime; CamPathValue curPtValue; double nextPtTime; CamPathValue nextPtValue; do { if(hasNextPt) { hasLastPt = true; lastPtTime = curPtTime; lastPtValue = curPtValue; hasCurPt = true; curPtTime = nextPtTime; curPtValue = nextPtValue; hasNextPt = false; } else { hasCurPt = true; curPtTime = *itPts; curPtValue = g_Hook_VClient_RenderView.m_CamPath.Eval(curPtTime); ++itPts; } while(itKeysNext.GetTime() < curPtTime) { itKeysLast = itKeysNext; ++itKeysNext; } if(itPts != m_TrajectoryPoints.end()) { hasNextPt = true; nextPtTime = *itPts; nextPtValue = g_Hook_VClient_RenderView.m_CamPath.Eval(nextPtTime); ++itPts; } else { // current point is last point. hasNextPt = false; nextPtValue = curPtValue; } if(!hasLastPt) { // current point is first point. lastPtValue = curPtValue; } // emit current point: { double deltaTime = abs(curTime -curPtTime); DWORD colour; // determine colour: if(deltaTime < 1.0) { double t = (deltaTime -0.0)/1.0; colour = D3DCOLOR_RGBA( ValToUCCondInv(255.0*t, curPtValue.Selected), ValToUCCondInv(255, curPtValue.Selected), ValToUCCondInv(0, curPtValue.Selected), (unsigned char)(127*(1.0-t))+128 ); } else if(deltaTime < 2.0) { double t = (deltaTime -1.0)/1.0; colour = D3DCOLOR_RGBA( ValToUCCondInv(255, curPtValue.Selected), ValToUCCondInv(255.0*(1.0-t), curPtValue.Selected), ValToUCCondInv(0, curPtValue.Selected), (unsigned char)(64*(1.0-t))+64 ); } else { colour = D3DCOLOR_RGBA( ValToUCCondInv(255, curPtValue.Selected), ValToUCCondInv(0, curPtValue.Selected), ValToUCCondInv(0, curPtValue.Selected), 64 ); } AutoPolyLinePoint( Vector3(lastPtValue.X,lastPtValue.Y,lastPtValue.Z) , Vector3(curPtValue.X,curPtValue.Y,curPtValue.Z) , colour , Vector3(nextPtValue.X,nextPtValue.Y,nextPtValue.Z)); } } while(hasNextPt); AutoPolyLineFlush(); } // Draw keyframes: { newCScreenInfo[2] = c_CampathCrossPixelWidth; m_Device->SetVertexShaderConstantF(48, newCScreenInfo, 1); bool lpSelected = false; double lpTime; /*if(0 < g_Hook_VClient_RenderView.m_CamPath.GetSize()) { // Test for not too unlikely hard case: CamPathValue cpv = g_Hook_VClient_RenderView.m_CamPath.GetBegin().GetValue(); Vector3 current(cpv.X+76, cpv.Y+76, cpv.Z+76); Vector3 previous(current.X+76, current.Y-1*4, current.Z); Vector3 next(current.X+76, current.Y+1*4, current.Z); Vector3 next2(current.X, current.Y+2*4, current.Z); Vector3 next3(current.X+76, current.Y+3*4, current.Z); Vector3 next4(current.X, current.Y+4*4, current.Z); Vector3 next5(current.X+76, current.Y+5*4, current.Z); AutoPolyLineStart(); AutoPolyLinePoint(previous, previous, D3DCOLOR_RGBA(255,0,0,255), current); AutoPolyLinePoint(previous, current, D3DCOLOR_RGBA(255,0,0,255), next); AutoPolyLinePoint(current, next, D3DCOLOR_RGBA(255,0,0,255), next2); AutoPolyLinePoint(next, next2, D3DCOLOR_RGBA(255,0,0,255), next3); AutoPolyLinePoint(next2, next3, D3DCOLOR_RGBA(255,0,0,255), next4); AutoPolyLinePoint(next3, next4, D3DCOLOR_RGBA(255,0,0,255), next5); AutoPolyLinePoint(next4, next5, D3DCOLOR_RGBA(255,0,0,255), next5); AutoPolyLineFlush(); }*/ /*if(0 < g_Hook_VClient_RenderView.m_CamPath.GetSize()) { CamPathValue cpv = g_Hook_VClient_RenderView.m_CamPath.GetBegin().GetValue(); float x = cpv.X * m_WorldToScreenMatrix.m[0][0] + cpv.Y * m_WorldToScreenMatrix.m[0][1] + cpv.Z * m_WorldToScreenMatrix.m[0][2] +m_WorldToScreenMatrix.m[0][3]; float y = cpv.X * m_WorldToScreenMatrix.m[1][0] + cpv.Y * m_WorldToScreenMatrix.m[1][1] + cpv.Z * m_WorldToScreenMatrix.m[1][2] +m_WorldToScreenMatrix.m[1][3]; float z = cpv.X * m_WorldToScreenMatrix.m[2][0] + cpv.Y * m_WorldToScreenMatrix.m[2][1] + cpv.Z * m_WorldToScreenMatrix.m[2][2] +m_WorldToScreenMatrix.m[2][3]; float w = cpv.X * m_WorldToScreenMatrix.m[3][0] + cpv.Y * m_WorldToScreenMatrix.m[3][1] + cpv.Z * m_WorldToScreenMatrix.m[3][2] +m_WorldToScreenMatrix.m[3][3]; float iw = w ? 1/w : 0; Tier0_Msg("pt: %f %f %f %f -> %f %f %f %f\n",x,y,z,w,x*iw,y*iw,z*iw,w*iw); }*/ for(CamPathIterator it = g_Hook_VClient_RenderView.m_CamPath.GetBegin(); it != g_Hook_VClient_RenderView.m_CamPath.GetEnd(); ++it) { double cpT = it.GetTime(); CamPathValue cpv = it.GetValue(); cameraMightBeSelected = cameraMightBeSelected || lpSelected && cpv.Selected && lpTime <= curTime && curTime <= cpT; lpSelected = cpv.Selected; lpTime = cpT; double deltaTime = abs(curTime -cpT); bool selected = cpv.Selected; DWORD colour; // determine colour: if(deltaTime < 1.0) { double t = (deltaTime -0.0)/1.0; colour = D3DCOLOR_RGBA( ValToUCCondInv(255.0*t, selected), ValToUCCondInv(255, selected), ValToUCCondInv(0, selected), (unsigned char)(127*(1.0-t))+128 ); } else if(deltaTime < 2.0) { double t = (deltaTime -1.0)/1.0; colour = D3DCOLOR_RGBA( ValToUCCondInv(255, selected), ValToUCCondInv(255.0*(1.0-t), selected), ValToUCCondInv(0, selected), (unsigned char)(64*(1.0-t))+64 ); } else { colour = D3DCOLOR_RGBA( ValToUCCondInv(255, selected), ValToUCCondInv(0, selected), ValToUCCondInv(0, selected), 64 ); } // x / forward line: AutoSingleLine( Vector3(cpv.X -c_CampathCrossRadius, cpv.Y, cpv.Z), colour, Vector3(cpv.X +c_CampathCrossRadius, cpv.Y, cpv.Z), colour ); // y / left line: AutoSingleLine( Vector3(cpv.X, cpv.Y -c_CampathCrossRadius, cpv.Z), colour, Vector3(cpv.X, cpv.Y +c_CampathCrossRadius, cpv.Z), colour ); // z / up line: AutoSingleLine( Vector3(cpv.X, cpv.Y, cpv.Z -c_CampathCrossRadius), colour, Vector3(cpv.X, cpv.Y, cpv.Z +c_CampathCrossRadius), colour ); } AutoSingleLineFlush(); } // Draw wireframe camera: if(inCampath && campathCanEval) { newCScreenInfo[2] = c_CameraPixelWidth; m_Device->SetVertexShaderConstantF(48, newCScreenInfo, 1); DWORD colourCam = campathEnabled ? D3DCOLOR_RGBA( ValToUCCondInv(255,cameraMightBeSelected), ValToUCCondInv(0,cameraMightBeSelected), ValToUCCondInv(255,cameraMightBeSelected), 128) : D3DCOLOR_RGBA( ValToUCCondInv(255,cameraMightBeSelected), ValToUCCondInv(255,cameraMightBeSelected), ValToUCCondInv(255,cameraMightBeSelected), 128); DWORD colourCamUp = campathEnabled ? D3DCOLOR_RGBA( ValToUCCondInv(0,cameraMightBeSelected), ValToUCCondInv(255,cameraMightBeSelected), ValToUCCondInv(0,cameraMightBeSelected), 128) : D3DCOLOR_RGBA( ValToUCCondInv(0,cameraMightBeSelected), ValToUCCondInv(0,cameraMightBeSelected), ValToUCCondInv(0,cameraMightBeSelected), 128); CamPathValue cpv = g_Hook_VClient_RenderView.m_CamPath.Eval(curTime); // limit to values as RenderView hook: cpv.Fov = max(1,cpv.Fov); cpv.Fov = min(179,cpv.Fov); double forward[3], right[3], up[3]; QEulerAngles ang = cpv.R.ToQREulerAngles().ToQEulerAngles(); MakeVectors(ang.Roll, ang.Pitch, ang.Yaw, forward, right, up); Vector3 vCp(cpv.X, cpv.Y, cpv.Z); Vector3 vForward(forward); Vector3 vUp(up); Vector3 vRight(right); //Tier0_Msg("----------------",curTime); //Tier0_Msg("currenTime = %f",curTime); //Tier0_Msg("vCp = %f %f %f\n", vCp.X, vCp.Y, vCp.Z); double a = sin(cpv.Fov * M_PI / 360.0) * c_CameraRadius; double b = a; int screenWidth, screenHeight; g_VEngineClient->GetScreenSize(screenWidth, screenHeight); double aspectRatio = screenWidth ? (double)screenHeight / (double)screenWidth : 1.0; b *= aspectRatio; Vector3 vLU = vCp +(double)c_CameraRadius * vForward -a * vRight +b * vUp; Vector3 vRU = vCp +(double)c_CameraRadius * vForward +a * vRight +b * vUp; Vector3 vLD = vCp +(double)c_CameraRadius * vForward -a * vRight -b * vUp; Vector3 vRD = vCp +(double)c_CameraRadius * vForward +a * vRight -b * vUp; Vector3 vMU = vLU +(vRU -vLU)/2; Vector3 vMUU = vMU +(double)c_CameraRadius * vUp; AutoSingleLine(vCp, colourCam, vLD, colourCam); AutoSingleLine(vCp, colourCam, vRD, colourCam); AutoSingleLine(vCp, colourCam, vLU, colourCam); AutoSingleLine(vCp, colourCam, vRU, colourCam); AutoSingleLine(vLD, colourCam, vRD, colourCam); AutoSingleLine(vRD, colourCam, vRU, colourCam); AutoSingleLine(vRU, colourCam, vLU, colourCam); AutoSingleLine(vLU, colourCam, vLD, colourCam); AutoSingleLine(vMU, colourCam, vMUU, colourCamUp); AutoSingleLineFlush(); // /* colourCam = D3DCOLOR_RGBA(255, 0, 0, 255); colourCamUp = D3DCOLOR_RGBA(255, 255, 0, 255); vCp = vvPos; vForward = vvForward; vUp = vvUp; vRight = vvRight; //Tier0_Msg("vCp2 = %f %f %f\n", vCp.X, vCp.Y, vCp.Z); vLU = vCp +(double)c_CameraRadius * vForward -a * vRight +b * vUp; vRU = vCp +(double)c_CameraRadius * vForward +a * vRight +b * vUp; vLD = vCp +(double)c_CameraRadius * vForward -a * vRight -b * vUp; vRD = vCp +(double)c_CameraRadius * vForward +a * vRight -b * vUp; vMU = vLU +(vRU -vLU)/2; vMUU = vMU +(double)c_CameraRadius * vUp; AutoSingleLine(vCp, colourCam, vLD, colourCam); AutoSingleLine(vCp, colourCam, vRD, colourCam); AutoSingleLine(vCp, colourCam, vLU, colourCam); AutoSingleLine(vCp, colourCam, vRU, colourCam); AutoSingleLine(vLD, colourCam, vRD, colourCam); AutoSingleLine(vRD, colourCam, vRU, colourCam); AutoSingleLine(vRU, colourCam, vLU, colourCam); AutoSingleLine(vLU, colourCam, vLD, colourCam); AutoSingleLine(vMU, colourCam, vMUU, colourCamUp); AutoSingleLineFlush(); */ } } // Restore device state: m_Device->SetPixelShader(oldPixelShader); if(oldPixelShader) oldPixelShader->Release(); m_Device->SetVertexShader(oldVertexShader); if(oldVertexShader) oldVertexShader->Release(); m_Device->SetStreamSource(0, oldVertexBuffer, oldVertexBufferOffset, oldVertexBufferStride); if(oldVertexBuffer) oldVertexBuffer->Release(); m_Device->SetIndices(oldIndexBuffer); if(oldIndexBuffer) oldIndexBuffer->Release(); m_Device->SetFVF(oldFVF); m_Device->SetVertexDeclaration(oldDeclaration); if(oldDeclaration) oldDeclaration->Release(); m_Device->SetVertexShaderConstantF(8, oldCViewProj[0], 4); m_Device->SetVertexShaderConstantF(48, oldCScreenInfo, 1); m_Device->SetVertexShaderConstantF(49, oldCPlane0, 1); m_Device->SetVertexShaderConstantF(50, oldCPlaneN, 1); m_Device->SetRenderState(D3DRS_CULLMODE, oldCullMode); m_Device->SetRenderState(D3DRS_DESTBLEND, oldDestBlend); m_Device->SetRenderState(D3DRS_SRCBLEND, oldSrcBlend); m_Device->SetRenderState(D3DRS_BLENDOP, oldBlendOp); m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, oldAlphaBlendEnable); m_Device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, oldSeparateAlphaBlendEnable); m_Device->SetRenderState(D3DRS_ALPHATESTENABLE, oldAlphaTestEnable); m_Device->SetRenderState(D3DRS_ZFUNC, oldZFunc); m_Device->SetRenderState(D3DRS_ZWRITEENABLE, oldZWriteEnable); m_Device->SetRenderState(D3DRS_ZENABLE, oldZEnable); m_Device->SetRenderState(D3DRS_COLORWRITEENABLE, oldColorWriteEnable); m_Device->SetRenderState(D3DRS_SRGBWRITEENABLE, oldSrgbWriteEnable); }
/// <returns> If pValue was changed. </returns> bool Fix(float * pValue, float * pOut, float & outOrgValue) { outOrgValue = *pValue; float newNetValue = outOrgValue; float newEngineValue = *pOut; std::pair<std::map<float *, Entry>::iterator, bool> res = m_Map.insert(std::make_pair(pOut, Entry(newNetValue, newEngineValue, 0))); if (!res.second) { // Known. if (0.0f != newNetValue) { float oldNetValue = res.first->second.oldNet; res.first->second.oldNet = newNetValue; float oldEngineValue = res.first->second.oldEngine; res.first->second.oldEngine = newEngineValue; float deltaNet = newNetValue >= oldNetValue ? newNetValue - oldNetValue : newNetValue + 1.0f - oldNetValue; float net = oldNetValue; float engine = newEngineValue; float totalError; // I wish I was better at math, the correction values could need some numerical optimization! if (net >= engine) { if (0.5f >= net - engine) totalError = net - engine; else totalError = net -1.0f -engine; } else { if (0.5f >= net +1.0f -engine) totalError = net + 1.0f - engine; else totalError = net +1.0f - 1.0f - engine; } if (totalError < -0.5f) { // actually should never happen, just for readability. if (1 < g_csgo_PlayerAnimStateFix) Tier0_Warning("CCsgoPlayerAnimStateFix::Fix on m_flCycle at 0x%08x: Engine: %f | Net: %f -> %f (%f) | total error: %f, ERROR in HLAE code, limiting to -0.5!.\n", pOut, newEngineValue, oldNetValue, newNetValue, deltaNet, totalError); totalError = -0.5f; } else if (0.5f < totalError) { // actually should never happen, just for readability. if (1 < g_csgo_PlayerAnimStateFix) Tier0_Warning("CCsgoPlayerAnimStateFix::Fix on m_flCycle at 0x%08x: Engine: %f | Net: %f -> %f (%f) | total error: %f, ERROR in HLAE code, limiting to 0.5!.\n", pOut, newEngineValue, oldNetValue, newNetValue, deltaNet, totalError); totalError = 0.5f; } res.first->second.oldError = totalError; float targetVal; if (0.3f <= abs(totalError)) { targetVal = newNetValue; // give up if (1 < g_csgo_PlayerAnimStateFix) Tier0_Warning("CCsgoPlayerAnimStateFix::Fix on m_flCycle at 0x%08x: Engine: %f | Net: %f -> %f (%f) | total error: %f, GIVING UP, new target: %f.\n", pOut, newEngineValue, oldNetValue, newNetValue, deltaNet, totalError, targetVal); } else { float targetDelta = deltaNet +totalError; if (targetDelta < 0) targetDelta = 0; targetVal = mirv_cycle_mod(newEngineValue + targetDelta); //float targetDelta = 0; //targetVal = newEngineValue; if (1 < g_csgo_PlayerAnimStateFix) Tier0_Msg("CCsgoPlayerAnimStateFix::Fix on m_flCycle at 0x%08x: Engine: %f | Net: %f -> %f (%f) | total error: %f, new target: %f (%f).\n", pOut, newEngineValue, oldNetValue, newNetValue, deltaNet, totalError, targetVal, targetDelta); } *pValue = targetVal; float * p_m_flPrevCycle = (float *)((char *)pValue - 0x10); *p_m_flPrevCycle = newEngineValue; // fix up this shit as well. return true; } if (1 < g_csgo_PlayerAnimStateFix) Tier0_Msg("CCsgoPlayerAnimStateFix::Fix on m_flCycle at 0x%08x: Got %f, RE-STARTING.\n", pOut, newNetValue); return false; } if (1 < g_csgo_PlayerAnimStateFix) Tier0_Msg("CCsgoPlayerAnimStateFix::Fix on m_flCycle at 0x%08x: Got %f, STARTING.\n", pOut, newNetValue); return false; }
void Hook_VClient_RenderView::Console_CamIO(IWrpCommandArgs * args) { int argc = args->ArgC(); char const * cmd0 = args->ArgV(0); if (2 <= argc) { char const * cmd1 = args->ArgV(1); if (0 == _stricmp("export", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); if (0 == _stricmp("start", cmd2) && 5 <= argc) { if (0 != m_CamExport) { delete m_CamExport; m_CamExport = 0; } std::wstring fileName(L""); if (UTF8StringToWideString(args->ArgV(3), fileName)) { m_CamExport = new CamExport(fileName.c_str(), 0 == _stricmp("alienSwarm", args->ArgV(4)) ? CamExport::SF_AlienSwarm : CamExport::SF_None); } else Tier0_Warning("Error: Can not convert \"%s\" from UTF-8 to WideString.\n", args->ArgV(3)); return; } else if (0 == _stricmp("end", cmd2)) { if (0 != m_CamExport) { delete m_CamExport; m_CamExport = 0; } else Tier0_Warning("No cam export was active."); return; } } Tier0_Msg( "%s export start <fileName> <fovScaling> - Starts exporting to file <fileName>, <fovScaling> can be \"none\" for engine FOV or \"alienSwarm\" for scaling like Alien Swarm SDK (i.e. CS:GO).\n" "%s export end - Stops exporting.\n" , cmd0 , cmd0 ); return; } else if (0 == _stricmp("import", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); if (0 == _stricmp("start", cmd2) && 4 <= argc) { if (0 != m_CamImport) { delete m_CamImport; m_CamImport = 0; } m_CamImport = new CamImport(args->ArgV(3), g_MirvTime.GetTime()); if (m_CamImport->IsBad()) Tier0_Warning("Error importing CAM file \"%s\"\n", args->ArgV(3)); return; } else if (0 == _stricmp("end", cmd2)) { delete m_CamImport; m_CamImport = 0; return; } } Tier0_Msg( "%s import start <fileName> - Starts importing cam from file <fileName>.\n" "%s import end - Stops importing.\n" , cmd0 , cmd0 ); return; } } Tier0_Msg( "%s export [...] - Controls export of new camera motion data.\n" "%s import [...] - Controls import of new camera motion data.\n" , cmd0 , cmd0 ); }
void TrySetView(float Tx, float Ty, float Tz, float Rx, float Ry, float Rz, float fov, float * outOrgRz, float * outOrgFov) { static bool firstRun = true; static SOURCESDK::CSGO::IServerTools * serverTools = nullptr; if (firstRun) { firstRun = false; if (SourceSdkVer_CSGO == g_SourceSdkVer) { if (CClientToolsCsgo::Instance()) { if (HMODULE hServerModule = GetModuleHandleA("server")) { if (SOURCESDK::CreateInterfaceFn createInterfaceFn = (SOURCESDK::CreateInterfaceFn)GetProcAddress(hServerModule, "CreateInterface")) { int returnCode = 0; serverTools = (SOURCESDK::CSGO::IServerTools *)createInterfaceFn(SOURCESDK_CSGO_VSERVERTOOLS_INTERFACE_VERSION, &returnCode); } } } if (!serverTools) { Tier0_Warning( "AFXERROR: Could not get interfaces required for server view override.\n"); } } } if (serverTools) { if (SOURCESDK::C_BaseEntity_csgo * localPlayer = reinterpret_cast<SOURCESDK::C_BaseEntity_csgo *>(CClientToolsCsgo::Instance()->GetClientToolsInterface()->GetLocalPlayer())) { SOURCESDK::Vector origin; SOURCESDK::QAngle angles; if (outOrgRz) { serverTools->GetPlayerPosition(origin, angles, localPlayer); *outOrgRz = angles.z; } if (outOrgFov) { *outOrgFov = (float)serverTools->GetPlayerFOV(localPlayer); } origin.x = Tx; origin.y = Ty; origin.z = Tz; angles.x = Rx; angles.y = Ry; angles.z = Rz; serverTools->SnapPlayerToPosition(origin, angles, localPlayer); serverTools->SetPlayerFOV((int)fov, localPlayer); } } }
bool ClientTools_Console_Cfg(IWrpCommandArgs * args) { CClientTools * clientTools = CClientTools::Instance(); if (!clientTools) { //Tier0_Warning("Error: Feature not available!\n"); return false; } int argc = args->ArgC(); char const * prefix = args->ArgV(0); if (2 <= argc) { char const * cmd1 = args->ArgV(1); if (0 == _stricmp("recordCamera", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); clientTools->RecordCamera_set(0 != atoi(cmd2)); return true; } Tier0_Msg( "%s recordCamera 0|1 - Enable (1) / Disable (0) recording of main camera (includes FOV).\n" "Current value: %i.\n" , prefix , clientTools->RecordCamera_get() ? 1 : 0 ); return true; } else if (0 == _stricmp("recordPlayers", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); clientTools->RecordPlayers_set(0 != atoi(cmd2)); return true; } Tier0_Msg( "%s recordPlayers 0|1 - Enable (1) / Disable (0) recording of players.\n" "Current value: %i.\n" , prefix , clientTools->RecordPlayers_get() ? 1 : 0 ); return true; } else if (0 == _stricmp("recordWeapons", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); clientTools->RecordWeapons_set(0 != atoi(cmd2)); return true; } Tier0_Msg( "%s recordWeapons 0|1 - Enable (1) / Disable (0) recording of weapons.\n" "Current value: %i.\n" , prefix , clientTools->RecordWeapons_get() ? 1 : 0 ); return true; } else if (0 == _stricmp("recordProjectiles", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); clientTools->RecordProjectiles_set(0 != atoi(cmd2)); return true; } Tier0_Msg( "%s recordProjectiles 0|1 - Enable (1) / Disable (0) recording of Projectiles.\n" "Current value: %i.\n" , prefix , clientTools->RecordProjectiles_get() ? 1 : 0 ); return true; } else if (0 == _stricmp("recordViewModel", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); clientTools->RecordViewModel_set(0 != atoi(cmd2)); return true; } Tier0_Msg( "%s recordViewModel 0|1 - Enable (1) / Disable (0) recording of view models.\n" "Current value: %i.\n" , prefix , clientTools->RecordViewModel_get() ? 1 : 0 ); Tier0_Warning( "This feature is not fully supported, will only work in CSSV34 and CS:GO at the moment.\n" "It has the following general problems:\n" "- Most import plugins won't know how to handle the viewmodel FOV properly, meaning it will look different from in-game.\n" "In CS:GO it will have the following problems:\n" "- You'll need to set cl_custom_material_override 0.\n" "- There will be several trash viewmodels, not much we can do about." ); return true; } else if (0 == _stricmp("recordInvisible", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); clientTools->RecordInvisible_set(0 != atoi(cmd2)); return true; } Tier0_Msg( "%s recordInvisible 0|1 - Enable (1) / Disable (0) recording of invisible entities. (Enabling it can cause AGRs with trash data.)\n" "Current value: %i.\n" , prefix , clientTools->RecordInvisible_get() ? 1 : 0 ); return true; } else if (0 == _stricmp("debug", cmd1)) { if (3 <= argc) { char const * cmd2 = args->ArgV(2); clientTools->Debug_set(atoi(cmd2)); return true; } Tier0_Msg( "%s debug 0|1|2 - Debug level.\n" "Current value: %i.\n" , prefix , clientTools->Debug_get() ); return true; } } Tier0_Msg( "%s recordCamera [...]\n" "%s recordPlayers [...]\n" "%s recordWeapons [...]\n" "%s recordProjectiles [...]\n" "%s recordViewmodel [...] - (not recommended)\n" "%s recordInvisible [...] - (not recommended)\n" "%s debug [...]\n" , prefix , prefix , prefix , prefix , prefix , prefix , prefix ); return false; }