Skip to content

Commit e5eaf0f

Browse files
committed
tier1: rewrite Sys_LoadModule
1 parent 653e08b commit e5eaf0f

File tree

3 files changed

+71
-39
lines changed

3 files changed

+71
-39
lines changed

filesystem/basefilesystem.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5042,10 +5042,11 @@ CSysModule *CBaseFileSystem::LoadModule( const char *pFileName, const char *pPat
50425042

50435043
char tempPathID[ MAX_PATH ];
50445044
ParsePathID( pFileName, pPathID, tempPathID );
5045-
5045+
50465046
CUtlSymbol lookup = g_PathIDTable.AddString( pPathID );
50475047

50485048
// a pathID has been specified, find the first match in the path list
5049+
#ifndef ANDROID
50495050
int c = m_SearchPaths.Count();
50505051
for ( int i = 0; i < c; i++ )
50515052
{
@@ -5071,14 +5072,6 @@ CSysModule *CBaseFileSystem::LoadModule( const char *pFileName, const char *pPat
50715072
return pModule;
50725073
#endif
50735074
}
5074-
5075-
5076-
#ifdef POSIX
5077-
if( !pModule )
5078-
{
5079-
Q_snprintf( tempPathID, sizeof(tempPathID), "lib%s", pFileName );
5080-
pModule = Sys_LoadModule( tempPathID );
5081-
}
50825075
#endif
50835076

50845077
if( !pModule )

tier1/interface.cpp

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ HMODULE Sys_LoadLibrary( const char *pLibraryName, Sys_Flags flags )
258258
const char *pError = dlerror();
259259
if ( pError && ( strstr( pError, "No such file" ) == 0 ) && ( strstr( pError, "image not found" ) == 0 ) )
260260
{
261-
Msg( " failed to dlopen %s error=%s\n", str, pError );
261+
Msg( "failed to dlopen %s error=%s\n", str, pError );
262262
}
263263
}
264264

@@ -267,6 +267,36 @@ HMODULE Sys_LoadLibrary( const char *pLibraryName, Sys_Flags flags )
267267
}
268268
static bool s_bRunningWithDebugModules = false;
269269

270+
#ifdef POSIX
271+
272+
#ifdef ANDROID
273+
#define DEFAULT_LIB_PATH ""
274+
#else
275+
#define DEFAULT_LIB_PATH "bin/"
276+
#endif
277+
278+
bool foundLibraryWithPrefix( char *pModuleAbsolutePath, size_t AbsolutePathSize, const char *pPath, const char *pModuleName )
279+
{
280+
char str[1024];
281+
Q_strncpy( str, pModuleName, sizeof(str) );
282+
V_SetExtension( str, DLL_EXT_STRING, sizeof(str) );
283+
bool bFound = false;
284+
285+
struct stat statBuf;
286+
Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/" DEFAULT_LIB_PATH "lib%s", pPath, str);
287+
bFound |= stat(pModuleAbsolutePath, &statBuf) == 0;
288+
289+
if( !bFound )
290+
{
291+
Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/" DEFAULT_LIB_PATH "%s", pPath, str);
292+
bFound |= stat(pModuleAbsolutePath, &statBuf) == 0;
293+
}
294+
295+
return bFound;
296+
}
297+
298+
#endif
299+
270300
//-----------------------------------------------------------------------------
271301
// Purpose: Loads a DLL/component from disk and returns a handle to it
272302
// Input : *pModuleName - filename of the component
@@ -301,52 +331,61 @@ CSysModule *Sys_LoadModule( const char *pModuleName, Sys_Flags flags /* = SYS_NO
301331
szCwd[strlen(szCwd) - 1] = 0;
302332
}
303333

304-
char szAbsoluteModuleName[1024];
305-
bool bUseLibPrefix = false;
306-
334+
char szAbsoluteModuleName[2048];
307335
#ifdef ANDROID
308-
struct stat statBuf;
309336
char *libPath = getenv("APP_LIB_PATH");
310-
311337
char *modLibPath = getenv("APP_MOD_LIB");
338+
bool bFound;
339+
312340
if( modLibPath && *modLibPath ) // first load library from mod launcher
313341
{
314-
bool bFound = true;
315-
Q_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/lib%s", modLibPath, pModuleName);
316-
if( stat(szAbsoluteModuleName, &statBuf) != 0 )
317-
{
318-
Q_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", modLibPath, pModuleName);
319-
if( stat(szAbsoluteModuleName, &statBuf) != 0 )
320-
bFound = false;
321-
}
342+
bFound = foundLibraryWithPrefix( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), modLibPath, pModuleName );
322343

323-
hDLL = Sys_LoadLibrary(szAbsoluteModuleName, flags);
344+
if( bFound )
345+
hDLL = Sys_LoadLibrary( szAbsoluteModuleName, flags );
324346

325347
if( !hDLL && bFound )
326-
Error("Can't load mod library %s\n", szAbsoluteModuleName);
348+
Error("Can't find mod library %s\n", szAbsoluteModuleName);
349+
}
350+
351+
if( !foundLibraryWithPrefix( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), libPath, pModuleName ) )
352+
{
353+
Warning("Can't find module - %s\n", pModuleName);
354+
return reinterpret_cast<CSysModule *>(hDLL);
327355
}
328356

329-
Q_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/lib%s", libPath ,pModuleName);
330-
if( stat(szAbsoluteModuleName, &statBuf) != 0 )
331-
Q_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", libPath ,pModuleName);
357+
#elif defined( POSIX )
358+
if( !foundLibraryWithPrefix(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), szCwd, pModuleName) )
359+
{
360+
Warning("Can't find module - %s\n", pModuleName);
361+
return reinterpret_cast<CSysModule *>(hDLL);
362+
}
332363
#else
333-
#ifdef POSIX
334-
struct stat statBuf;
335-
Q_snprintf(szModuleName, sizeof(szModuleName), "bin/lib%s", pModuleName);
336-
bUseLibPrefix |= stat(szModuleName, &statBuf) == 0;
364+
Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/bin/%s", szCwd, pModuleName );
337365
#endif
338-
if( bUseLibPrefix )
339-
Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/bin/lib%s", szCwd, pModuleName );
340-
else
341-
Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/bin/%s", szCwd, pModuleName );
342-
#endif // ANDROID
343366
Msg("LoadLibrary: pModule: %s, path: %s\n", pModuleName, szAbsoluteModuleName);
344367

345368
if( !hDLL )
346369
hDLL = Sys_LoadLibrary( szAbsoluteModuleName, flags );
347370
}
348371
else
349-
Msg("LoadLibrary: path: %s\n", pModuleName);
372+
{
373+
#ifdef POSIX
374+
Q_strncpy( szModuleName, pModuleName, sizeof(szModuleName) );
375+
V_SetExtension( szModuleName, DLL_EXT_STRING, sizeof(szModuleName) );
376+
377+
struct stat statBuf;
378+
bool bFound = stat(szModuleName, &statBuf) == 0;
379+
380+
if( !bFound )
381+
{
382+
Warning("Can't find module - %s\n", pModuleName);
383+
return reinterpret_cast<CSysModule *>(hDLL);
384+
}
385+
386+
Msg("LoadLibrary: path: %s\n", szModuleName);
387+
#endif
388+
}
350389

351390

352391
if ( !hDLL )

vgui2/vgui_controls/HTML.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ m_HideTooltip( this, &HTML::BrowserHideToolTip )
155155
}
156156
else
157157
{
158-
Warning("Unable to access SteamHTMLSurface");
158+
Warning("Unable to access SteamHTMLSurface\n");
159159
}
160160
m_iScrollBorderX=m_iScrollBorderY=0;
161161
m_bScrollBarEnabled = true;

0 commit comments

Comments
 (0)