2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/shock/shkchkcd.cpp,v 1.4 2000/02/19 12:36:41 toml Exp $
14 #include <dbmem.h> // must be last header!
17 // Shock CD and protection stuff.
19 // 1) We use DiscSafe copy protection, which wraps our executable in
20 // encrypted form. CD authentication occurs before our WinMain()
23 // 2) So, why this code? It's mostly here to locate the CD for runtime
24 // access. The cd_path config variable is only a default value to
25 // check. The user might have 2 CD drives, or a removable-medium
26 // drive which causes the CD to show up at a different letter.
30 #define CHKCD_SPEW(a) \
31 if (config_is_defined("chkcd_spew")) {mprintf a;}
32 #define CHKCD_BOOLSPEW(a,b,c)\
33 if (config_is_defined("chkcd_spew")) {if((a)){mprintf b;} else {mprintf c;}}
36 #define CHKCD_BOOLSPEW(a,b,c)
40 static char *path_configs
[]=
41 { "cd_path", "resname_base", "load_path", "script_module_path", "movie_path" };
43 // gonna replace " X:\" and "+X:\"
44 void _FixupCDConfigVars( char *drivePath
)
46 char try_paths
[MAX_PATH
], old_path
[MAX_PATH
];
49 if ( !config_get_raw( path_configs
[0], old_path
, sizeof( old_path
) ) )
50 strcpy( old_path
, "D:\\" );
53 for( i
= 0; i
< sizeof( path_configs
) / sizeof( path_configs
[0] ); i
++ )
55 if( config_get_raw( path_configs
[i
], try_paths
, sizeof( try_paths
) ) )
60 while( ( p
= strstr( p
, old_path
) ) != NULL
)
62 CHKCD_SPEW(( "CHKCD : Fixing up config var %s\n", path_configs
[i
] ));
63 CHKCD_SPEW(( "CHKCD : Was: \"%s\"\n", try_paths
));
64 memcpy( p
, drivePath
, strlen( drivePath
) );
65 CHKCD_SPEW(( "CHKCD : Now: \"%s\"\n", try_paths
));
66 p
++; // lets not fix ourselves up again
68 config_set_string( path_configs
[i
], try_paths
);
69 config_set_priority( path_configs
[i
], PRIORITY_TRANSIENT
);
74 static char* _GetNoCDString( char *fill_in
, char *type
, int fill_in_len
)
79 // Get language from config.
80 if ( !config_get_raw( "language", lang
, sizeof( lang
) ) )
81 strcpy( lang
, "english" ); // yes, gringo bastards, yes
83 // Use config variable of form no_cd_XXX_YYY, e.g. no_cd_title_english.
84 sprintf( cfg_var
, "no_cd_%s_%s", type
, lang
);
85 if ( !config_get_raw( cfg_var
, fill_in
, fill_in_len
) )
86 strcpy( fill_in
, "NO CD" );
91 static BOOL
_ShowCDMessage( BOOL copy_prot
)
96 _GetNoCDString( title
, "title", sizeof( title
) );
97 _GetNoCDString( message
, "msg", sizeof( message
) );
99 strcat( message
," ." );
100 if ( MessageBox( NULL
, message
, title
, MB_OKCANCEL
| MB_ICONEXCLAMATION
) == IDCANCEL
)
105 static BOOL
_CheckIsACD( char* drivePath
)
107 return GetDriveType( drivePath
) == DRIVE_CDROM
;
110 static BOOL
_CheckFile( char* drivePath
)
116 // Set up search path.
118 strcat( path
, drivePath
);
119 strcat( path
, "shock\\snd.crf" );
121 // Attempt to open known file.
122 fp
= fopen( path
, "rb" );
136 static BOOL
_CheckDrive( char* drivePath
)
138 return( _CheckIsACD( drivePath
) && _CheckFile( drivePath
) );
142 static BOOL
_CheckDrives( BOOL onlyCheckPath
)
145 BOOL wasFound
= FALSE
;
147 // Check config path setting.
148 if( config_get_raw( "cd_path", path
, sizeof( path
) ) )
150 wasFound
= _CheckDrive( path
);
151 CHKCD_SPEW(("CHKCD : Checking CD at cd_path (%s)... ", path
));
152 CHKCD_BOOLSPEW( wasFound
, ( "Found.\n" ), ( "Not found.\n") );
155 // We don't check other drives if onlyCheckPath is flagged or if
156 // we already found it.
157 if( !onlyCheckPath
&& !wasFound
)
159 CHKCD_SPEW(( "CHKCD : Checking other drives... " ));
160 strcpy( path
, "A:\\" );
161 while( !wasFound
&& path
[0] <= 'Z' )
163 CHKCD_SPEW(( "%c", path
[0] ));
164 wasFound
= _CheckDrive( path
);
169 CHKCD_BOOLSPEW( wasFound
, ( "\nCHKCD : Found CD at %s\n", path
), ("\nCHKCD : Not found.\n") );
172 _FixupCDConfigVars( path
);
185 // note that we are the default provider of this function
187 BOOL
CheckForCD(void)
189 BOOL wasFound
= FALSE
;
190 BOOL tryAgain
= TRUE
;
192 #ifndef COPY_PROTECTION
193 // Don't complain about copy protection.
194 if( !config_is_defined( "test_copy_protect" ) )
196 CHKCD_SPEW(( "CHKCD : Skipping copy protection.\n"));
197 // We still do _CheckDrives() so that any FixupConfigVars can happen.
198 wasFound
= _CheckDrives( config_is_defined( "only_check_path" ) );
199 // Force true result.
205 while ( !wasFound
&& tryAgain
)
207 // For testing purposes, we can check just one drive.
208 wasFound
= _CheckDrives( config_is_defined( "only_check_path" ) );
212 tryAgain
= _ShowCDMessage( TRUE
);