Skip to content

Commit

Permalink
fixed crash attempt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
d3nd3 committed May 20, 2024
1 parent ecffb2f commit ed1103c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
39 changes: 21 additions & 18 deletions src/features/ref_fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ void refFixes_apply(void)
_sofbuddy_lightblend_src = orig_Cvar_Get("_sofbuddy_lightblend_src","GL_DST_COLOR",CVAR_ARCHIVE,&lightblend_change);
_sofbuddy_lightblend_dst = orig_Cvar_Get("_sofbuddy_lightblend_dst","GL_SRC_COLOR",CVAR_ARCHIVE,&lightblend_change);
#endif




//These textures don't have mipmaps, so GL_NEAREST or GL_LINEAR. (sky prob looks good with GL_LINEAR)
_sofbuddy_minfilter_unmipped = orig_Cvar_Get("_sofbuddy_minfilter_unmipped","GL_LINEAR",CVAR_ARCHIVE,&minfilter_change);
_sofbuddy_magfilter_unmipped = orig_Cvar_Get("_sofbuddy_magfilter_unmipped","GL_LINEAR",CVAR_ARCHIVE,&magfilter_change);

_sofbuddy_minfilter_mipped = orig_Cvar_Get("_sofbuddy_minfilter_mipped","GL_LINEAR_MIPMAP_LINEAR",CVAR_ARCHIVE,&minfilter_change);
//I like GL_NEAREST here, the detail textures look crisper? debateable.
_sofbuddy_magfilter_mipped = orig_Cvar_Get("_sofbuddy_magfilter_mipped","GL_NEAREST",CVAR_ARCHIVE,&magfilter_change);

// I don't see a reason to have this set to anything but GL_NEAREST
_sofbuddy_minfilter_ui = orig_Cvar_Get("_sofbuddy_minfilter_ui","GL_NEAREST",CVAR_ARCHIVE,&minfilter_change);
//required for the font upscaling.
_sofbuddy_magfilter_ui = orig_Cvar_Get("_sofbuddy_magfilter_ui","GL_NEAREST",CVAR_ARCHIVE,&magfilter_change);

}

Expand Down Expand Up @@ -428,6 +444,7 @@ void lighting_fix_init(void) {
#endif

void setup_minmag_filters(void) {
static bool first_run = true;

_gl_texturemode = orig_Cvar_Get("gl_texturemode","GL_NEAREST",NULL,NULL);

Expand All @@ -454,26 +471,12 @@ void setup_minmag_filters(void) {
WriteE8Call(0x300065B1 ,&orig_glTexParameterf_mag_ui);
WriteByte(0x300065B6,0x90);



//These textures don't have mipmaps, so GL_NEAREST or GL_LINEAR. (sky prob looks good with GL_LINEAR)
_sofbuddy_minfilter_unmipped = orig_Cvar_Get("_sofbuddy_minfilter_unmipped","GL_LINEAR",CVAR_ARCHIVE,&minfilter_change);
minfilter_change(_sofbuddy_minfilter_unmipped);
_sofbuddy_magfilter_unmipped = orig_Cvar_Get("_sofbuddy_magfilter_unmipped","GL_LINEAR",CVAR_ARCHIVE,&magfilter_change);
magfilter_change(_sofbuddy_magfilter_unmipped);
//R_Init->GL_SetDefaultState() is handling texturemode for us, yet we are after that.
//Thus we want to call it again, from R_beginFrame()

_sofbuddy_minfilter_mipped = orig_Cvar_Get("_sofbuddy_minfilter_mipped","GL_LINEAR_MIPMAP_LINEAR",CVAR_ARCHIVE,&minfilter_change);
minfilter_change(_sofbuddy_minfilter_mipped);
//I like GL_NEAREST here, the detail textures look crisper? debateable.
_sofbuddy_magfilter_mipped = orig_Cvar_Get("_sofbuddy_magfilter_mipped","GL_NEAREST",CVAR_ARCHIVE,&magfilter_change);
magfilter_change(_sofbuddy_magfilter_mipped);
//Trigger re-apply of texturemode
if (_gl_texturemode) _gl_texturemode->modified = true;

// I don't see a reason to have this set to anything but GL_NEAREST
_sofbuddy_minfilter_ui = orig_Cvar_Get("_sofbuddy_minfilter_ui","GL_NEAREST",CVAR_ARCHIVE,&minfilter_change);
minfilter_change(_sofbuddy_minfilter_ui);
//required for the font upscaling.
_sofbuddy_magfilter_ui = orig_Cvar_Get("_sofbuddy_magfilter_ui","GL_NEAREST",CVAR_ARCHIVE,&magfilter_change);
magfilter_change(_sofbuddy_magfilter_ui);
}

int my_R_SetMode(void * deviceMode) {
Expand Down
8 changes: 6 additions & 2 deletions src/features/scaled_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ void fontscale_change(cvar_t * cvar) {
consolesize_change(_sofbuddy_console_size);

// Clear console.
if ( !first_run ) {
if ( !first_run && orig_Con_CheckResize ) {
//Cannot call this before Con_Init, cos references a cvar from Con_Init.
orig_Con_Initialize();
}
first_run = false;
Expand Down Expand Up @@ -189,8 +190,11 @@ void my_Con_Init(void) {

//Called at end of QCommon_Init()
void scaledFont_apply(void) {
_sofbuddy_font_scale = orig_Cvar_Get("_sofbuddy_font_scale","1",CVAR_ARCHIVE,&fontscale_change);

_sofbuddy_console_size = orig_Cvar_Get("_sofbuddy_console_size","0.35",CVAR_ARCHIVE,&consolesize_change);
//fontscale_change references a cvar, so order matters.
_sofbuddy_font_scale = orig_Cvar_Get("_sofbuddy_font_scale","1",CVAR_ARCHIVE,&fontscale_change);

orig_Con_DrawNotify = DetourCreate((void*)0x20020D70 , (void*)&my_Con_DrawNotify,DETOUR_TYPE_JMP,5);
orig_Con_DrawConsole = DetourCreate((void*)0x20020F90,(void*)&my_Con_DrawConsole,DETOUR_TYPE_JMP,5);

Expand Down
34 changes: 29 additions & 5 deletions src/sof_buddy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "sof_compat.h"
#include "./DetourXS/detourxs.h"


//__ioinit
void (*orig_FS_InitFilesystem)(void) = NULL;
void my_FS_InitFilesystem(void);
void my_orig_Qcommon_Init(int argc, char **argv);
qboolean my_Cbuf_AddLateCommands(void);

Expand Down Expand Up @@ -61,6 +65,10 @@ qboolean my_Cbuf_AddLateCommands(void);
*/
void afterWsockInit(void)
{
/*
This is called by our DllMain(), thus before SoF.exe CRTmain().
Cvars etc not allowed here.
*/
#ifdef FEATURE_MEDIA_TIMERS
//my_Sys_Milliseconds hook
mediaTimers_early();
Expand All @@ -77,18 +85,37 @@ void afterWsockInit(void)
}

//orig_Qcommon_Init = DetourCreate(orig_Qcommon_Init,&my_orig_Qcommon_Init,DETOUR_TYPE_JMP,5);
orig_FS_InitFilesystem = DetourCreate(0x20026980, &my_FS_InitFilesystem,DETOUR_TYPE_JMP,6);
orig_Cbuf_AddLateCommands = DetourCreate(0x20018740,&my_Cbuf_AddLateCommands,DETOUR_TYPE_JMP,5);

}

//Every cvar here would trigger its modified, because no cvars exist prior.
//But its loaded with its default value.
/*
This is earlier than Cbuf_AddLateCommands(), just before exec default.cfg and exec config.cfg IN Qcommon_Init()
*/
void my_FS_InitFilesystem(void) {
orig_FS_InitFilesystem();

//Best place for cvars if you want config.cfg induced triggering of modified events.
refFixes_apply();
#ifdef FEATURE_FONT_SCALING
scaledFont_apply();
#endif
}
/*
A long standing bug, was related to the order of initializing cvars, which behaved different for a user without
a config.cfg than one with one. If getting crashes, always remember this!.
*/
void my_orig_Qcommon_Init(int argc, char **argv)
{
orig_Qcommon_Init(argc,argv);
}


/*
Safest Init Location
Safest Init Location for wanting to check command line values.
*/
//this is called inside Qcommon_Init()
qboolean my_Cbuf_AddLateCommands(void)
Expand All @@ -97,10 +124,7 @@ qboolean my_Cbuf_AddLateCommands(void)
#ifdef FEATURE_MEDIA_TIMERS
mediaTimers_apply();
#endif
refFixes_apply();
#ifdef FEATURE_FONT_SCALING
scaledFont_apply();
#endif

return ret;
}

Expand Down

0 comments on commit ed1103c

Please sign in to comment.