Skip to content

Commit

Permalink
Goofy fullscreen hack + bloom
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueNightHawk committed Dec 26, 2022
1 parent 2f0fb71 commit f00f5df
Show file tree
Hide file tree
Showing 3 changed files with 422 additions and 7 deletions.
20 changes: 19 additions & 1 deletion cl_dll/cdll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "vgui_TeamFortressViewport.h"
#include "filesystem_utils.h"

#include "SDL2/SDL_opengl.h"

cl_enginefunc_t gEngfuncs;
CHud gHUD;
TeamFortressViewport* gViewPort = NULL;
Expand All @@ -44,6 +46,10 @@ TeamFortressViewport* gViewPort = NULL;
#include "particleman.h"
IParticleMan* g_pParticleMan = nullptr;

bool InitScreenGlow(void);
bool VidInitScreenGlow();
void RenderScreenGlow(void);

void CL_LoadParticleMan();
void CL_UnloadParticleMan();

Expand All @@ -54,6 +60,8 @@ void IN_Commands();
void R_StudioVidInit();

void HL_ImGUI_Init();

extern bool bQueueRestart;
/*
================================
HUD_GetHullBounds
Expand Down Expand Up @@ -133,6 +141,7 @@ int DLLEXPORT Initialize(cl_enginefunc_t* pEnginefuncs, int iVersion)
}

HL_ImGUI_Init();
InitScreenGlow();

// get tracker interface, if any
return 1;
Expand All @@ -157,6 +166,8 @@ int DLLEXPORT HUD_VidInit()
VGui_Startup();

R_StudioVidInit();

VidInitScreenGlow();

return 1;
}
Expand Down Expand Up @@ -193,8 +204,12 @@ int DLLEXPORT HUD_Redraw(float time, int intermission)
{
// RecClHudRedraw(time, intermission);

gHUD.Redraw(time, 0 != intermission);
RenderScreenGlow();


glDepthRange(0.f, 0.f);
gHUD.Redraw(time, 0 != intermission);
glDepthRange(0.f, 1.f);
return 1;
}

Expand Down Expand Up @@ -247,6 +262,9 @@ Called by engine every frame that client .dll is loaded
void DLLEXPORT HUD_Frame(double time)
{
// RecClHudFrame(time);
if (bQueueRestart)
gEngfuncs.pfnClientCmd("_restart");


GetClientVoiceMgr()->Frame(time);
}
Expand Down
197 changes: 191 additions & 6 deletions cl_dll/hl_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
#include "cl_dll.h"
#include "PlatformHeaders.h"
#include <Psapi.h>
#include "cvardef.h"
#include "cl_util.h"

#include "SDL2/SDL.h"
#include "SDL2/SDL_video.h"
#include "SDL2/SDL_opengl.h"

#include <string>

extern cl_enginefunc_t gEngfuncs;
SDL_Window* firstwindow = NULL;
SDL_Window* window = NULL;
Expand All @@ -16,9 +20,47 @@ SDL_GLContext gl_context;
void HL_ImGUI_Draw();
int HL_ImGUI_ProcessEvent(void* data, SDL_Event* event);

int RegRead(const char* valuename);
bool RegWrite(const char* valuename, int value);
bool RegCreate(const char* subkey);

bool bQueueRestart = false;
bool bFullscreen = false;
int iVidMode = 0;

float flFullscreenDelay = 0.0f;

// To draw imgui on top of Half-Life, we take a detour from certain engine's function into HL_ImGUI_Draw function
void HL_ImGUI_Init()
{
int iWindowed = RegRead("ScreenWindowed");
int iSDLFullscreen = RegRead("SDL_FullScreen");
iVidMode = RegRead("vid_level");
if (iVidMode == 0)
{
if (iWindowed == 1 && iSDLFullscreen == 0)
{
bFullscreen = false;
}
else if (iWindowed == 0)
{
RegCreate("SDL_FullScreen");
RegWrite("SDL_FullScreen", 1);
RegWrite("ScreenWindowed", 1);

bQueueRestart = true;
return;
}
else
{
if (RegRead("SDL_FullScreen") != 0)
{
flFullscreenDelay = gEngfuncs.GetAbsoluteTime() + 0.5f;
bFullscreen = true;
}
RegWrite("SDL_FullScreen", 0);
}
}
// One of the final steps before drawing a frame is calling SDL_GL_SwapWindow function
// It must be prevented, so imgui could be drawn before calling SDL_GL_SwapWindow

Expand Down Expand Up @@ -85,21 +127,24 @@ void HL_ImGUI_Init()
// Notice the 1 byte offset from the origin
WriteProcessMemory(GetCurrentProcess(), (void*)(origin + 1), offsetBytes, 4, NULL);

//window = SDL_GetWindowFromID(1);
firstwindow = SDL_GetWindowFromID(1);

int iWidth, iHeight;

SDL_GetWindowSize(firstwindow, &iWidth, &iHeight);
int iWidth = 0, iHeight = 0;
iWidth = RegRead("ScreenWidth");
iHeight = RegRead("ScreenHeight");

// Setup window
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_GetWindowFlags(firstwindow));

window = SDL_CreateWindow(SDL_GetWindowTitle(firstwindow), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, iWidth, iHeight, window_flags);

gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_HideWindow(firstwindow);
Expand All @@ -123,10 +168,37 @@ void HL_ImGUI_Deinit()
SDL_DestroyWindow(firstwindow);

SDL_DelEventWatch(HL_ImGUI_ProcessEvent, NULL);

if (RegRead("ScreenWindowed") == 0 && bFullscreen)
{
RegWrite("ScreenWindowed", 1);
}
else if (bFullscreen)
{
RegWrite("ScreenWindowed", 0);
}
}

void HL_ImGUI_Draw()
{
static cvar_s* rawinput = nullptr;

if (!rawinput)
rawinput = gEngfuncs.pfnGetCvarPointer("m_rawinput");

if (bFullscreen && iVidMode == 0)
{
if (rawinput && rawinput->value < 1.0f)
{
gEngfuncs.Cvar_SetValue("m_rawinput", 1);
}

if (flFullscreenDelay != 0.0f && flFullscreenDelay < gEngfuncs.GetAbsoluteTime())
{
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
flFullscreenDelay = 0.0f;
}
}
SDL_GL_SwapWindow(window);
}

Expand All @@ -147,4 +219,117 @@ int HL_ImGUI_ProcessEvent(void* data, SDL_Event* event)
break;
}
return 1;
}
}

// Read data from registry
BOOL readDwordValueRegistry(HKEY hKeyParent, LPCSTR subkey, LPCSTR valueName, DWORD* readData)
{
HKEY hKey;
DWORD Ret;
// Check if the registry exists
Ret = RegOpenKeyEx(
hKeyParent,
subkey,
0,
KEY_READ,
&hKey);
if (Ret == ERROR_SUCCESS)
{
DWORD data;
DWORD len = sizeof(DWORD); // size of data
Ret = RegQueryValueEx(
hKey,
valueName,
NULL,
NULL,
(LPBYTE)(&data),
&len);
if (Ret == ERROR_SUCCESS)
{
RegCloseKey(hKey);
(*readData) = data;
return TRUE;
}
RegCloseKey(hKey);
return TRUE;
}
else
{
return FALSE;
}
}

int RegRead(const char* valuename)
{
DWORD outvalue = 0;
readDwordValueRegistry(HKEY_CURRENT_USER, "Software\\Valve\\Half-Life\\Settings", valuename, &outvalue);
return (int)outvalue;
}

BOOL WriteInRegistry(HKEY hKeyParent, LPCSTR subkey, LPCSTR valueName, DWORD data)
{
DWORD Ret; // use to check status
HKEY hKey; // key
// Open the key
Ret = RegOpenKeyEx(
hKeyParent,
subkey,
0,
KEY_WRITE,
&hKey);
if (Ret == ERROR_SUCCESS)
{
// Set the value in key
if (ERROR_SUCCESS !=
RegSetValueEx(
hKey,
valueName,
0,
REG_DWORD,
reinterpret_cast<BYTE*>(&data),
sizeof(data)))
{
RegCloseKey(hKey);
return FALSE;
}
// close the key
RegCloseKey(hKey);
return TRUE;
}
return FALSE;
}

bool RegWrite(const char* valuename, int value)
{
return WriteInRegistry(HKEY_CURRENT_USER, "Software\\Valve\\Half-Life\\Settings", valuename, (DWORD)value);
}

BOOL CreateRegistryKey(HKEY hKeyParent, LPCSTR subkey)
{
DWORD dwDisposition; // It verify new key is created or open existing key
HKEY hKey;
DWORD Ret;
Ret =
RegCreateKeyEx(
hKeyParent,
subkey,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&dwDisposition);
if (Ret != ERROR_SUCCESS)
{
printf("Error opening or creating new key\n");
return FALSE;
}
RegCloseKey(hKey); // close the key
return TRUE;
}

bool RegCreate(const char*subkey)
{
return CreateRegistryKey(HKEY_CURRENT_USER, ((std::string)("Software\\Valve\\Half-Life\\Settings\\") + subkey).c_str());
}
Loading

0 comments on commit f00f5df

Please sign in to comment.