diff --git a/src/features/ref_fixes.cpp b/src/features/ref_fixes.cpp index 5cd2f03..2b00af8 100644 --- a/src/features/ref_fixes.cpp +++ b/src/features/ref_fixes.cpp @@ -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); } @@ -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); @@ -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) { diff --git a/src/features/scaled_font.cpp b/src/features/scaled_font.cpp index dec1d17..8b7328e 100644 --- a/src/features/scaled_font.cpp +++ b/src/features/scaled_font.cpp @@ -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; @@ -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); diff --git a/src/sof_buddy.cpp b/src/sof_buddy.cpp index d26531f..536bff7 100644 --- a/src/sof_buddy.cpp +++ b/src/sof_buddy.cpp @@ -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); @@ -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(); @@ -77,10 +85,29 @@ 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); @@ -88,7 +115,7 @@ void my_orig_Qcommon_Init(int argc, char **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) @@ -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; }