@@ -59,6 +59,31 @@ int fclose_hook(FILE *stream) {
5959 return fclose (stream );
6060}
6161
62+ char_t * default_boot_config_path = NULL ;
63+ #if !defined(__APPLE__ )
64+ FILE * fopen64_hook (char * filename , char * mode ) {
65+ char * actual_file_name = filename ;
66+
67+ if (strcmp (filename , default_boot_config_path ) == 0 ) {
68+ actual_file_name = config .boot_config_override ;
69+ LOG ("Overriding boot.config to %s" , actual_file_name );
70+ }
71+
72+ return fopen64 (actual_file_name , mode );
73+ }
74+ #endif
75+
76+ FILE * fopen_hook (char * filename , char * mode ) {
77+ char * actual_file_name = filename ;
78+
79+ if (strcmp (filename , default_boot_config_path ) == 0 ) {
80+ actual_file_name = config .boot_config_override ;
81+ LOG ("Overriding boot.config to %s" , actual_file_name );
82+ }
83+
84+ return fopen (actual_file_name , mode );
85+ }
86+
6287int dup2_hook (int od , int nd ) {
6388 // Newer versions of Unity redirect stdout to player.log, we don't want
6489 // that
@@ -80,7 +105,8 @@ __attribute__((constructor)) void doorstop_ctor() {
80105
81106 void * unity_player = plthook_handle_by_name ("UnityPlayer" );
82107
83- if (unity_player && PLTHOOK_OPEN_BY_HANDLE_OR_ADDRESS (& hook , unity_player ) == 0 ) {
108+ if (unity_player &&
109+ PLTHOOK_OPEN_BY_HANDLE_OR_ADDRESS (& hook , unity_player ) == 0 ) {
84110 LOG ("Found UnityPlayer, hooking into it instead" );
85111 } else if (plthook_open (& hook , NULL ) != 0 ) {
86112 LOG ("Failed to open current process PLT! Cannot run Doorstop! "
@@ -94,6 +120,31 @@ __attribute__((constructor)) void doorstop_ctor() {
94120 printf ("Failed to hook dlsym, ignoring it. Error: %s\n" ,
95121 plthook_error ());
96122
123+ if (config .boot_config_override ) {
124+ if (file_exists (config .boot_config_override )) {
125+ default_boot_config_path = calloc (MAX_PATH , sizeof (char_t ));
126+ memset (default_boot_config_path , 0 , MAX_PATH * sizeof (char_t ));
127+ strcat (default_boot_config_path , get_working_dir ());
128+ strcat (default_boot_config_path , TEXT ("/" ));
129+ strcat (default_boot_config_path ,
130+ get_file_name (program_path (), FALSE));
131+ strcat (default_boot_config_path , TEXT ("_Data/boot.config" ));
132+
133+ #if !defined(__APPLE__ )
134+ if (plthook_replace (hook , "fopen64" , & fopen64_hook , NULL ) != 0 )
135+ printf ("Failed to hook fopen64, ignoring it. Error: %s\n" ,
136+ plthook_error ());
137+ #endif
138+ if (plthook_replace (hook , "fopen" , & fopen_hook , NULL ) != 0 )
139+ printf ("Failed to hook fopen, ignoring it. Error: %s\n" ,
140+ plthook_error ());
141+ } else {
142+ LOG ("The boot.config file won't be overriden because the provided "
143+ "one does not exist: %s" ,
144+ config .boot_config_override );
145+ }
146+ }
147+
97148 if (plthook_replace (hook , "fclose" , & fclose_hook , NULL ) != 0 )
98149 printf ("Failed to hook fclose, ignoring it. Error: %s\n" ,
99150 plthook_error ());
0 commit comments