forked from Nekojimi/JackIt
35 lines
1.3 KiB
GDScript
35 lines
1.3 KiB
GDScript
@tool
|
|
extends EditorExportPlugin
|
|
|
|
var export_path: String = ""
|
|
|
|
func _get_name() -> String:
|
|
return "tnhujftdbnhkjdftrgh"
|
|
|
|
func _export_begin(features: PackedStringArray, is_debug: bool, path: String, flags: int) -> void:
|
|
export_path = path.left(path.rfind("/"))
|
|
print("Project is being exported to %s" % export_path)
|
|
|
|
func _export_end() -> void:
|
|
var dir: DirAccess = DirAccess.open(export_path)
|
|
if dir:
|
|
for file in dir.get_files():
|
|
print("Exported file: %s" % file)
|
|
if file.ends_with(".js"):
|
|
hack_js_file(export_path + "/" + file)
|
|
|
|
func hack_js_file(file: String) -> void:
|
|
print("Checking exported JS file %s" % file)
|
|
var file_access: FileAccess = FileAccess.open(file,FileAccess.READ_WRITE)
|
|
if file_access == null:
|
|
printerr("Failed to open file %s, code: %s" % [file, FileAccess.get_open_error()])
|
|
return
|
|
var contents: String = file_access.get_as_text()
|
|
var regex: RegEx = RegEx.create_from_string("if \\(!Features.isSecureContext\\(\\)\\) \\{(\n[^\n]*){2}")
|
|
var match: RegExMatch = regex.search(contents)
|
|
if match and match.get_start() != -1:
|
|
print("Found target string! Modifying...")
|
|
contents = regex.sub(contents, "/* I fucked this file to enable HTTP support, look at me */")
|
|
file_access.resize(0)
|
|
file_access.store_string(contents)
|