shit wont work

This commit is contained in:
nullifiedcat 2017-04-15 18:10:15 +03:00
parent a2e4219c30
commit 84341c6291
6 changed files with 157 additions and 40 deletions

View File

@ -24,8 +24,6 @@ CScreenSpaceEffectRegistration::CScreenSpaceEffectRegistration( const char *pNam
logging::Info("New head: 0x%08x", *g_ppScreenSpaceRegistrationHead);
}
static CTextureReference tr_cathook_rt;
/*IMaterial* GetRenderTarget() {
if (!tr_cathook_rt) {
tr_cathook_rt.InitRenderTarget(256, 256, RT_SIZE_FULL_FRAME_BUFFER, IMAGE_FORMAT_ARGB8888, MATERIAL_RT_DEPTH_NONE, false, "cathook_rt");
@ -35,48 +33,148 @@ static CTextureReference tr_cathook_rt;
IMaterial* GetGlowMaterial() {
return vfunc<IMaterial*(*)(IMaterialSystem*, const char*, const char*, bool, const char*)>(g_IMaterialSystem, 73)(g_IMaterialSystem, "dev/glow_color", TEXTURE_GROUP_OTHER, true, 0);
/*static IMaterial* material = nullptr;
if (!material) {
KeyValues* kv = new KeyValues("UnlitGeneric");
kv->SetString("$basetexture", "_rt_FullFrameFB");
kv->SetInt("$ignorez", 1);
material = g_IMaterialSystem->CreateMaterial("cathook/glow", kv);
}
return material;*/
}
static CatVar glow_experimental(CV_SWITCH, "glow_experimental", "0", "Experimental Glow");
void EffectGlow::Init() {
logging::Info("Init EffectGlow...");
if (!materials) materials = g_IMaterialSystem;
logging::Info("materials: 0x%08x", materials);
rt_A.InitRenderTarget(1920/2, 1080/2, RT_SIZE_DEFAULT, IMAGE_FORMAT_RGBA8888, MATERIAL_RT_DEPTH_SEPARATE, false, "__cathook_glow_rta");
rt_B.InitRenderTarget(1920/2, 1080/2, RT_SIZE_DEFAULT, IMAGE_FORMAT_RGBA8888, MATERIAL_RT_DEPTH_SEPARATE, false, "__cathook_glow_rtb");
logging::Info("Textures init!");
//rt_B.InitRenderTarget(256, 256, RT_SIZE_FULL_FRAME_BUFFER, IMAGE_FORMAT_ARGB8888, MATERIAL_RT_DEPTH_NONE, false, "__cathook_glow_rtB");
KeyValues *kv2 = new KeyValues( "VertexLitGeneric" );
kv2->SetString( "$basetexture", "vgui/white" );
kv2->SetInt( "$selfillum", 1 );
kv2->SetString( "$selfillummask", "vgui/white" );
kv2->SetInt( "$vertexalpha", 1 );
kv2->SetInt( "$model", 1 );
glow_material.Init( "__cathook_glow_mat_color", TEXTURE_GROUP_CLIENT_EFFECTS, kv2 );
glow_material->Refresh();
KeyValues* kv = new KeyValues("UnlitGeneric");
kv->SetString("$basetexture", "_rt_FullFrameFB");
kv->SetInt("$additive", 1);
result_material.Init("__cathook_glow_mat", TEXTURE_GROUP_CLIENT_EFFECTS, kv);
result_material->Refresh();
logging::Info("Material init!");
//dev_glow_color.Init(vfunc<IMaterial*(*)(IMaterialSystem*, const char*, const char*, bool, const char*)>(g_IMaterialSystem, 73)(g_IMaterialSystem, "dev/glow_color", TEXTURE_GROUP_OTHER, true, 0));
dev_bloomdadd.Init(vfunc<IMaterial*(*)(IMaterialSystem*, const char*, const char*, bool, const char*)>(g_IMaterialSystem, 73)(g_IMaterialSystem, "dev/bloomadd", TEXTURE_GROUP_OTHER, true, 0));
dev_blurfilterx.Init(vfunc<IMaterial*(*)(IMaterialSystem*, const char*, const char*, bool, const char*)>(g_IMaterialSystem, 73)(g_IMaterialSystem, "dev/blurfilterx", TEXTURE_GROUP_OTHER, true, 0));
dev_blurfiltery.Init(vfunc<IMaterial*(*)(IMaterialSystem*, const char*, const char*, bool, const char*)>(g_IMaterialSystem, 73)(g_IMaterialSystem, "dev/blurfiltery", TEXTURE_GROUP_OTHER, true, 0));
dev_halo_add_to_screen.Init(vfunc<IMaterial*(*)(IMaterialSystem*, const char*, const char*, bool, const char*)>(g_IMaterialSystem, 73)(g_IMaterialSystem, "dev/halo_add_to_screen", TEXTURE_GROUP_OTHER, true, 0));
logging::Info("Init done!");
init = true;
}
void EffectGlow::BeginRenderGlow() {
CMatRenderContextPtr ptr(vfunc<IMatRenderContext*(*)(IMaterialSystem*)>(g_IMaterialSystem, 100, 0)(g_IMaterialSystem));
ptr->PushRenderTargetAndViewport(rt_A);
g_IVModelRender->SuppressEngineLighting(true);
g_IVRenderView->GetColorModulation(orig_modulation);
static Vector red(1.0f, 0.1f, 0.1f);
g_IVRenderView->SetColorModulation(red.Base());
g_IStudioRender->ForcedMaterialOverride(glow_material);
g_IVRenderView->SetBlend(1.0f);
}
void EffectGlow::EndRenderGlow() {
CMatRenderContextPtr ptr(vfunc<IMatRenderContext*(*)(IMaterialSystem*)>(g_IMaterialSystem, 100, 0)(g_IMaterialSystem));
g_IVRenderView->SetColorModulation(orig_modulation);
g_IStudioRender->ForcedMaterialOverride(nullptr);
g_IVModelRender->SuppressEngineLighting(false);
ptr->PopRenderTargetAndViewport();
}
void EffectGlow::RenderGlow(int idx) {
CMatRenderContextPtr ptr(vfunc<IMatRenderContext*(*)(IMaterialSystem*)>(g_IMaterialSystem, 100, 0)(g_IMaterialSystem));
ptr->PushRenderTargetAndViewport( rt_A );
g_IVModelRender->SuppressEngineLighting( true );
// Set the glow tint since selfillum trumps color modulation
IMaterialVar *var = glow_material->FindVar( "$selfillumtint", NULL, false );
static float color[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
var->SetVecValue( color, 4 ); // Fixed compilation error
var = glow_material->FindVar( "$alpha", NULL, false );
var->SetFloatValue( color[3] ); // Fixed compilation error
g_IVModelRender->ForcedMaterialOverride( glow_material );
IClientEntity* ent = g_IEntityList->GetClientEntity(idx);
if (ent) ent->DrawModel(1);
g_IVModelRender->ForcedMaterialOverride( NULL );
g_IVModelRender->SuppressEngineLighting( false );
ptr->PopRenderTargetAndViewport();
/*IClientEntity* ent = g_IEntityList->GetClientEntity(idx);
if (ent) {
ent->DrawModel(1);
}*/
}
void EffectGlow::Render(int x, int y, int w, int h) {
if (!materials) materials = g_IMaterialSystem;
if (!init) Init();
if (!glow_experimental) return;
CMatRenderContextPtr ptr(vfunc<IMatRenderContext*(*)(IMaterialSystem*)>(g_IMaterialSystem, 100, 0)(g_IMaterialSystem));
//ITexture* rt_original = ptr->GetRenderTarget();
ITexture *pRtFullFrame = NULL;
pRtFullFrame = vfunc<ITexture*(*)(IMaterialSystem*, const char*, const char*, bool, int)>(g_IMaterialSystem, 81)(g_IMaterialSystem, "_rt_FullFrameFB", TEXTURE_GROUP_RENDER_TARGET, 1, 0);//materials->FindTexture( "_rt_FullFrameFB", TEXTURE_GROUP_RENDER_TARGET );
logging::Info("%s", pRtFullFrame->GetName());
ptr->SetRenderTarget(pRtFullFrame);
ptr->Viewport(0, 0, 1920, 1080);
ptr->PushRenderTargetAndViewport();
Vector orig_modulation;
g_IVRenderView->GetColorModulation(orig_modulation.Base());
Vector red(1.0f, 0.1f, 0.1f);
g_IVRenderView->SetColorModulation(red.Base());
g_IStudioRender->ForcedMaterialOverride(GetGlowMaterial());
g_IVRenderView->SetBlend(1.0f);
for (int i = 1; i < 8; i++) {
//ptr->Viewport(x, y, w, h);
ITexture* rt = ptr->GetRenderTarget();
IMaterialVar* var;
var = dev_blurfilterx->FindVar("$basetexture", nullptr);
var->SetTextureValue(rt_A);
var = dev_blurfiltery->FindVar("$basetexture", nullptr);
var->SetTextureValue(rt_B);
var = result_material->FindVar("$basetexture", nullptr);
var->SetTextureValue(rt_A);
//var = dev_blurfilterx->FindVar("$bloomamount", nullptr);
//var->SetFloatValue(10);
var = dev_blurfiltery->FindVar("$bloomamount", nullptr);
var->SetFloatValue(10);
ptr->ClearColor4ub(0, 0, 0, 255);
ptr->PushRenderTargetAndViewport(rt_A);
ptr->ClearBuffers(true, true);
ptr->PopRenderTargetAndViewport();
ptr->PushRenderTargetAndViewport(rt_B);
ptr->ClearBuffers(true, true);
ptr->PopRenderTargetAndViewport();
ptr->ClearStencilBufferRectangle( 0, 0, 1920, 1080, 0 );
BeginRenderGlow();
for (int i = 1; i < 32; i++) {
IClientEntity* ent = g_IEntityList->GetClientEntity(i);
if (!ent->IsDormant() && NET_BYTE(ent, netvar.iLifeState) == LIFE_ALIVE) {
logging::Info("Drawing %d", i);
ent->DrawModel(1);
if (ent && !ent->IsDormant() && NET_BYTE(ent, netvar.iLifeState) == LIFE_ALIVE) {
//BeginRenderGlow();
RenderGlow(i);
//EndRenderGlow();
}
}
logging::Info("Setting modulation");
g_IVRenderView->SetColorModulation(orig_modulation.Base());
logging::Info("z");
logging::Info("%i", g_IStudioRender->GetNumAmbientLightSamples());
g_IStudioRender->ForcedMaterialOverride(0);
logging::Info("x");
ptr->PushRenderTargetAndViewport( rt_B );
ptr->Viewport(x, y, w, h);
ptr->DrawScreenSpaceQuad( dev_blurfilterx );
ptr->PopRenderTargetAndViewport();
logging::Info("Done...?");
//ptr->SetRenderTarget(rt_original);
ptr->PushRenderTargetAndViewport( rt_A );
ptr->Viewport(x, y, w, h);
ptr->DrawScreenSpaceQuad( dev_blurfiltery );
ptr->PopRenderTargetAndViewport();
ptr->SetRenderTarget(rt);
ptr->Viewport(x, y, w, h);
ptr->DrawScreenSpaceQuad(result_material);
var = result_material->FindVar("$basetexture", nullptr);
//var->SetTextureValue(rt_B);
//ptr->DrawScreenSpaceQuad(result_material);
}
EffectGlow g_EffectGlow;

View File

@ -12,7 +12,7 @@
class EffectGlow : public IScreenSpaceEffect {
public:
inline virtual void Init( ) {};
virtual void Init( );
inline virtual void Shutdown( ) {};
inline virtual void SetParameters( KeyValues *params ) {};
@ -22,8 +22,21 @@ public:
inline virtual void Enable( bool bEnable ) { enabled = bEnable; };
inline virtual bool IsEnabled( ) { return enabled; };
void RenderGlow(int idx);
void BeginRenderGlow();
void EndRenderGlow();
public:
bool init { false };
bool enabled;
float orig_modulation[3];
CTextureReference rt_A;
CTextureReference rt_B;
CMaterialReference result_material;
CMaterialReference glow_material;
CMaterialReference dev_bloomdadd;
CMaterialReference dev_halo_add_to_screen;
CMaterialReference dev_blurfilterx;
CMaterialReference dev_blurfiltery;
};
extern EffectGlow g_EffectGlow;

View File

@ -188,6 +188,7 @@ void hack::Initialize() {
logging::Info("%s", reg->m_pEffectName);
}
g_pScreenSpaceEffects->EnableScreenSpaceEffect("_cathook_glow");
//g_EffectGlow.Init();
logging::Info("SSE enabled..");
}

View File

@ -95,8 +95,8 @@ void CreateInterfaces() {
g_IMaterialSystem = BruteforceInterface<IMaterialSystem>("VMaterialSystem", sharedobj::materialsystem, 81);
if (TF2) {
// FIXME static offset FIXME FIXME FIXME FIXME IMPORTANT!
g_pScreenSpaceEffects = *(IScreenSpaceEffectManager**)sharedobj::client->Pointer(0x01F73E74);
g_ppScreenSpaceRegistrationHead = (CScreenSpaceEffectRegistration**)sharedobj::client->Pointer(0x02018E30);
g_pScreenSpaceEffects = **(IScreenSpaceEffectManager***)(gSignatures.GetClientSignature("F3 0F 10 83 40 05 00 00 C7 44 24 04 ? ? ? ? 89 34 24 F3 0F 11 44 24 08 E8 ? ? ? ? A1 ? ? ? ? 8B 10 89 04 24 89 74 24 08 C7 44 24 04 ? ? ? ? FF 52 0C A1 ? ? ? ? 8B 10 C7 44 24 04 ? ? ? ? 89 04 24 FF 52 14") + 31);
g_ppScreenSpaceRegistrationHead = *(CScreenSpaceEffectRegistration***)(gSignatures.GetClientSignature("55 89 E5 53 83 EC 14 8B 1D ? ? ? ? 85 DB 74 25 8D B4 26 00 00 00 00 8B 43 04 85 C0 74 10") + 9);
}
if (TF2) g_IInput = **(reinterpret_cast<IInput***>((uintptr_t)1 + gSignatures.GetClientSignature("A1 ? ? ? ? C6 05 ? ? ? ? 01 8B 10 89 04 24 FF 92 B4 00 00 00 A1 ? ? ? ? 8B 10")));
else if (TF2C) g_IInput = **(reinterpret_cast<IInput***>((uintptr_t)1 + gSignatures.GetClientSignature("A1 ? ? ? ? C6 05 ? ? ? ? 01 8B 10 89 04 24 FF 92 A8 00 00 00 A1 ? ? ? ? 8B 10")));

View File

@ -20,6 +20,7 @@
#include <inetchannelinfo.h>
#include <gametrace.h>
#include <engine/IEngineTrace.h>
#include <materialsystem/imaterialvar.h>
#include <globalvars_base.h>
#include <materialsystem/itexture.h>
#include <engine/ivmodelinfo.h>

View File

@ -12,6 +12,8 @@
#include "materialsystem/imaterialsystem.h"
#include "tier1/KeyValues.h"
#include "../vfunc.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
@ -191,7 +193,9 @@ void CTextureReference::InitRenderTarget( int w, int h, RenderTargetSizeMode_t s
int renderTargetFlags = bHDR ? CREATERENDERTARGETFLAGS_HDR : 0;
// NOTE: Refcount returned by CreateRenderTargetTexture is 1
m_pTexture = materials->CreateNamedRenderTargetTextureEx( pStrOptionalName, w, h, sizeMode, fmt,
//m_pTexture = vfunc<ITexture*(*)(IMaterialSystem*, char const*,int,int,RenderTargetSizeMode_t,ImageFormat,MaterialRenderTargetDepth_t,uint,uint)>(materials, 87, 0)(materials, pStrOptionalName, w, h, sizeMode, fmt,
// depth, textureFlags, renderTargetFlags);
m_pTexture = materials->CreateNamedRenderTargetTextureEx( pStrOptionalName, w, h, sizeMode, fmt,
depth, textureFlags, renderTargetFlags );
Assert( m_pTexture );