@@ -97,7 +97,8 @@ func reorder_autoloads() -> void:
9797			original_autoloads [name ] =  value 
9898
9999	ModLoaderSetupLog .info (
100- 		"Start reorder autoloads current state: %s "  %  JSON .stringify (original_autoloads , "\t " )
100+ 		"Start reorder autoloads current state: %s "  %  JSON .stringify (original_autoloads , "\t " ),
101+ 		LOG_NAME 
101102	)
102103
103104	for  autoload  in  original_autoloads .keys ():
@@ -123,7 +124,8 @@ func reorder_autoloads() -> void:
123124			new_autoloads [name ] =  value 
124125
125126	ModLoaderSetupLog .info (
126- 		"Reorder autoloads completed - new state: %s "  %  JSON .stringify (new_autoloads , "\t " )
127+ 		"Reorder autoloads completed - new state: %s "  %  JSON .stringify (new_autoloads , "\t " ),
128+ 		LOG_NAME 
127129	)
128130
129131
@@ -145,6 +147,10 @@ func handle_override_cfg() -> void:
145147
146148#  Creates the project.binary file, adds it to the pck and removes the no longer needed project.binary file.
147149func  handle_injection () ->  void :
150+ 	var  is_embedded : bool  =  not  FileAccess .file_exists (path .pck )
151+ 	var  injection_path : String  =  path .exe  if  is_embedded  else  path .pck 
152+ 	var  file_extension  :=  injection_path .get_extension ()
153+ 
148154	ModLoaderSetupLog .debug ("Start injection" , LOG_NAME )
149155	#  Create temp dir
150156	ModLoaderSetupLog .debug ('Creating temp dir at "%s "'  %  path .temp_dir_path , LOG_NAME )
@@ -167,83 +173,59 @@ func handle_injection() -> void:
167173	DirAccess .make_dir_recursive_absolute (path .temp_dir_path .path_join (".godot" ))
168174	#  Save the global class cache config file
169175	combined_global_script_class_cache_file .save (path .temp_global_script_class_cache_path )
170- 	get_pck_version ()
171- 	#  Check if .pck is embedded split it from the .exe
172- 	if  not  FileAccess .file_exists (path .pck ):
173- 		split_pck ()
174176
175- 	inject ()
177+ 	inject (injection_path ,  is_embedded )
176178
177179	#  Rename vanilla
178- 	DirAccess .rename_absolute (
179- 		path .pck ,
180- 		path .pck .trim_suffix ("%s .pck"  %  file_name .pck ).path_join ("%s -vanilla.pck"  %  file_name .pck )
181- 	)
182- 	ModLoaderSetupLog .debug (
183- 		(
184- 			'Renamed "%s " to "%s "' 
185- 			%  [
186- 				path .pck ,
187- 				path .pck .trim_suffix ("%s .pck"  %  file_name .pck ).path_join (
188- 					"%s -vanilla.pck"  %  file_name .pck 
189- 				)
190- 			]
191- 		),
192- 		LOG_NAME 
193- 	)
194- 	#  Rename modded
195- 	DirAccess .rename_absolute (
196- 		path .game_base_dir .path_join ("%s -modded.pck"  %  file_name .pck ),
197- 		"%s .pck"  %  path .game_base_dir .path_join (file_name .pck )
198- 	)
199- 	ModLoaderSetupLog .debug (
200- 		(
201- 			'Renamed "%s " to "%s "' 
202- 			%  [
203- 				path .game_base_dir .path_join ("%s -modded.pck"  %  file_name .pck ),
204- 				"%s .pck"  %  path .game_base_dir .path_join (file_name .pck )
205- 			]
206- 		),
207- 		LOG_NAME 
208- 	)
180+ 	var  modded_path  :=  "%s -modded.%s "  %  [injection_path .get_basename (), file_extension ]
181+ 	var  vanilla_path  :=  "%s -vanilla.%s "  %  [injection_path .get_basename (), file_extension ]
209182
210- 	clean_up ()
183+ 	DirAccess .rename_absolute (injection_path , vanilla_path )
184+ 	ModLoaderSetupLog .debug ('Renamed "%s " to "%s "'  %  [injection_path , vanilla_path ], LOG_NAME )
211185
186+ 	#  Rename modded
187+ 	DirAccess .rename_absolute (modded_path , injection_path )
188+ 	ModLoaderSetupLog .debug ('Renamed "%s " to "%s "'  %  [modded_path , injection_path ], LOG_NAME )
212189
213- func  get_pck_version () ->  String :
214- 	var  engine_version_info  :=  Engine .get_version_info ()
215- 	#  Godot 4 pck version always starts with a 2 (at least for now).
216- 	var  pck_version  :=  (
217- 		"2.%s .%s .%s " 
218- 		%  [engine_version_info .major , engine_version_info .minor , engine_version_info .patch ]
219- 	)
220- 	ModLoaderSetupLog .debug ("The pck version is: %s "  %  pck_version , LOG_NAME )
221- 	return  pck_version 
190+ 	clean_up ()
222191
223192
224193#  Add modified binary to the pck
225- func  inject (pck_version : String  =  get_pck_version ()) ->  void :
226- 	var  arguments  :=  [
227- 		"-pc" ,
228- 		path .pck ,
229- 		path .temp_dir_path ,
230- 		path .game_base_dir .path_join ("%s -modded.pck"  %  file_name .pck ),
231- 		pck_version 
232- 	]
233- 	ModLoaderSetupLog .debug (
234- 		"Injecting temp dir content into .pck: %s  %s " , [path .pck_explorer , arguments ], LOG_NAME 
194+ func  inject (injection_path : String , is_embedded  :=  false ) ->  void :
195+ 	var  arguments  :=  []
196+ 	arguments .push_back ("--headless" )
197+ 	arguments .push_back ("--pck-patch=%s "  %  injection_path )
198+ 	if  is_embedded :
199+ 		arguments .push_back ("--embed=%s "  %  injection_path )
200+ 	arguments .push_back (
201+ 		"--patch-file=%s =%s "  %  [path .temp_project_binary_path , path .project_binary_path_internal ]
235202	)
236- 	#  For unknown reasons the output only displays a single "[" - so only the executed arguments are logged.
237- 	var  _exit_code_inject  :=  OS .execute (path .pck_explorer , arguments )
238- 
239- 
240- func  split_pck () ->  void :
241- 	var  arguments  :=  ["-s" , path .exe ]
242- 	ModLoaderSetupLog .debug (
243- 		"Splitting .pck from .exe: %s  %s " , [path .pck_explorer , arguments ], LOG_NAME 
203+ 	arguments .push_back (
204+ 		(
205+ 			"--patch-file=%s =%s " 
206+ 			%  [
207+ 				path .temp_global_script_class_cache_path ,
208+ 				path .global_script_class_cache_path_internal 
209+ 			]
210+ 		)
211+ 	)
212+ 	arguments .push_back (
213+ 		(
214+ 			"--output=%s " 
215+ 			%  path .game_base_dir .path_join (
216+ 				(
217+ 					"%s -modded.%s " 
218+ 					%  [file_name [injection_path .get_extension ()], injection_path .get_extension ()]
219+ 				)
220+ 			)
221+ 		)
244222	)
223+ 
245224	#  For unknown reasons the output only displays a single "[" - so only the executed arguments are logged.
246- 	var  _exit_code_split_pck  :=  OS .execute (path .pck_explorer , arguments )
225+ 	ModLoaderSetupLog .debug ("Injection started: %s  %s "  %  [path .gdre , arguments ], LOG_NAME )
226+ 	var  output  :=  []
227+ 	var  _exit_code_inject  :=  OS .execute (path .gdre , arguments , output )
228+ 	ModLoaderSetupLog .debug ("Injection completed: %s "  %  output , LOG_NAME )
247229
248230
249231#  Removes the temp files
@@ -268,17 +250,15 @@ func setup_file_data() -> void:
268250	path .game_base_dir  =  ModLoaderSetupUtils .get_local_folder_dir ()
269251	#  C:/path/to/game/addons/mod_loader
270252	path .mod_loader_dir  =  path .game_base_dir  +  "addons/mod_loader/" 
271- 	path .pck_explorer  =  (
272- 		path .mod_loader_dir 
273- 		+  get_pck_explorer_path ()
274- 	)
275- 	#  ! pck explorer doesn't like trailing `/` in a path !
253+ 	path .gdre  =  path .mod_loader_dir  +  get_gdre_path ()
276254	path .temp_dir_path  =  path .mod_loader_dir  +  "setup/temp" 
277255	path .temp_project_binary_path  =  path .temp_dir_path  +  "/project.binary" 
278256	path .temp_global_script_class_cache_path  =  (
279257		path .temp_dir_path 
280258		+  "/.godot/global_script_class_cache.cfg" 
281259	)
260+ 	path .global_script_class_cache_path_internal  =  "res://.godot/global_script_class_cache.cfg" 
261+ 	path .project_binary_path_internal  =  "res://project.binary" 
282262	#  can be supplied to override the exe_name
283263	file_name .cli_arg_exe  =  ModLoaderSetupUtils .get_cmd_line_arg_value ("--exe-name" )
284264	#  can be supplied to override the pck_name
@@ -347,13 +327,11 @@ func get_combined_global_script_class_cache() -> ConfigFile:
347327	return  global_script_class_cache_combined 
348328
349329
350- func  get_pck_explorer_path () ->  String :
351- 	var  pck_explorer_path  :=  "vendor/GodotPCKExplorer/GodotPCKExplorer.Console" 
352- 
330+ func  get_gdre_path () ->  String :
353331	if  OS .get_name () ==  "Windows" :
354- 		return  "%s .exe"   %   pck_explorer_path 
332+ 		return  "vendor/GDRE/gdre_tools .exe" 
355333
356- 	return  pck_explorer_path 
334+ 	return  "" 
357335
358336
359337func  restart () ->  void :
0 commit comments