mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-22 23:48:11 +00:00
added the game
This commit is contained in:
69
addons/mod_tool/scripts/build_zip.gd
Normal file
69
addons/mod_tool/scripts/build_zip.gd
Normal file
@@ -0,0 +1,69 @@
|
||||
extends Node
|
||||
class_name ModToolZipBuilder
|
||||
|
||||
|
||||
func build_zip(mod_tool_store: ModToolStore) -> void:
|
||||
var writer := ZIPPacker.new()
|
||||
var err := writer.open(mod_tool_store.path_global_final_zip)
|
||||
if not err == OK:
|
||||
return
|
||||
|
||||
# Get all file paths inside the mod folder
|
||||
mod_tool_store.path_mod_files = ModToolUtils.get_flat_view_dict(mod_tool_store.path_mod_dir)
|
||||
|
||||
# Loop over each file path
|
||||
for i in mod_tool_store.path_mod_files.size():
|
||||
var path_mod_file := mod_tool_store.path_mod_files[i] as String
|
||||
# Check for excluded file extensions
|
||||
if ModToolUtils.is_file_extension(path_mod_file, mod_tool_store.excluded_file_extensions):
|
||||
# Dont add files with unwanted extensions to the zip
|
||||
mod_tool_store.path_mod_files.remove_at(i)
|
||||
continue
|
||||
|
||||
# If it's a .import file
|
||||
if path_mod_file.get_extension() == "import":
|
||||
# Get the path to the imported file
|
||||
var path_imported_file := _get_imported_file_path(path_mod_file)
|
||||
# And add it to the mod file paths
|
||||
if not path_imported_file == "":
|
||||
mod_tool_store.path_mod_files.append(path_imported_file)
|
||||
|
||||
# Add each file to the mod zip
|
||||
for i in mod_tool_store.path_mod_files.size():
|
||||
var path_mod_file: String = mod_tool_store.path_mod_files[i]
|
||||
var path_mod_file_data := FileAccess.open(path_mod_file, FileAccess.READ)
|
||||
var path_mod_file_length := path_mod_file_data.get_length()
|
||||
var path_mod_file_buffer := path_mod_file_data.get_buffer(path_mod_file_length)
|
||||
var path_zip_file: String = path_mod_file.trim_prefix("res://")
|
||||
|
||||
writer.start_file(path_zip_file) # path inside the zip file
|
||||
writer.write_file(path_mod_file_buffer)
|
||||
writer.close_file()
|
||||
|
||||
writer.close()
|
||||
|
||||
# Open the export dir
|
||||
var file_manager_path: String = mod_tool_store.path_global_export_dir
|
||||
if OS.has_feature("macos"):
|
||||
file_manager_path = "file://" + file_manager_path
|
||||
OS.shell_open(file_manager_path)
|
||||
|
||||
|
||||
func _get_imported_file_path(import_file_path: String) -> String:
|
||||
var config := ConfigFile.new()
|
||||
|
||||
# Open file
|
||||
var error := config.load(import_file_path)
|
||||
if error != OK:
|
||||
ModToolUtils.output_error("Failed to load import file -> " + str(error))
|
||||
|
||||
# Get the path to the imported file
|
||||
# Imported file example path:
|
||||
# res://.godot/imported/ImportedPNG.png-eddc81c8e2d2fc90950be5862656c2b5.stex
|
||||
var imported_file_path := config.get_value('remap', 'path', '') as String
|
||||
|
||||
if imported_file_path == '':
|
||||
ModToolUtils.output_error("No remap path found in import file -> " + import_file_path)
|
||||
return ''
|
||||
|
||||
return imported_file_path
|
1
addons/mod_tool/scripts/build_zip.gd.uid
Normal file
1
addons/mod_tool/scripts/build_zip.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b36ubk26m45e4
|
1
addons/mod_tool/scripts/file_system_link.gd.uid
Normal file
1
addons/mod_tool/scripts/file_system_link.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bdeotl8om6vp
|
60
addons/mod_tool/scripts/hook_gen.gd
Normal file
60
addons/mod_tool/scripts/hook_gen.gd
Normal file
@@ -0,0 +1,60 @@
|
||||
@tool
|
||||
class_name ModToolHookGen
|
||||
extends RefCounted
|
||||
|
||||
|
||||
static func transform_one(path: String, mod_tool_store: ModToolStore) -> Error:
|
||||
var source_code_processed := mod_tool_store.mod_hook_preprocessor.process_script(path, true)
|
||||
var backup_path := "%s/%s" % [mod_tool_store.path_script_backup_dir, path.trim_prefix("res://")]
|
||||
|
||||
# Create a backup of the vanilla script files
|
||||
if not FileAccess.file_exists(backup_path):
|
||||
ModToolUtils.file_copy(path, backup_path)
|
||||
|
||||
var file := FileAccess.open(path, FileAccess.WRITE)
|
||||
|
||||
if not file:
|
||||
var error := file.get_error()
|
||||
return error
|
||||
|
||||
# Write processed source_code to file
|
||||
file.store_string(source_code_processed)
|
||||
file.close()
|
||||
|
||||
mod_tool_store.hooked_scripts[path] = true
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
static func restore(path: String, mod_tool_store: ModToolStore) -> Error:
|
||||
var backup_path := "%s/%s" % [mod_tool_store.path_script_backup_dir, path.trim_prefix("res://")]
|
||||
var backup_file := FileAccess.open(backup_path, FileAccess.READ)
|
||||
|
||||
if not backup_file:
|
||||
mod_tool_store.hooked_scripts.erase(path)
|
||||
clear_mod_hook_preprocessor_hashmap(path, mod_tool_store)
|
||||
return FileAccess.get_open_error()
|
||||
|
||||
var restored_source := backup_file.get_as_text()
|
||||
|
||||
var file := FileAccess.open(path, FileAccess.WRITE)
|
||||
|
||||
if not file:
|
||||
return FileAccess.get_open_error()
|
||||
|
||||
# Write processed source_code to file
|
||||
file.store_string(restored_source)
|
||||
file.close()
|
||||
|
||||
mod_tool_store.hooked_scripts.erase(path)
|
||||
|
||||
clear_mod_hook_preprocessor_hashmap(path, mod_tool_store)
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
static func clear_mod_hook_preprocessor_hashmap(path: String, mod_tool_store: ModToolStore) -> void:
|
||||
var script: GDScript = load(path)
|
||||
|
||||
for method in script.get_script_method_list():
|
||||
mod_tool_store.mod_hook_preprocessor.hashmap.erase(_ModLoaderHooks.get_hook_hash(path, method.name))
|
1
addons/mod_tool/scripts/hook_gen.gd.uid
Normal file
1
addons/mod_tool/scripts/hook_gen.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://w36kem24kso0
|
Reference in New Issue
Block a user