diff options
Diffstat (limited to 'modules/gdscript/gd_script.cpp')
-rw-r--r-- | modules/gdscript/gd_script.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index d183782864..2885b754be 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -31,6 +31,7 @@ #include "global_constants.h" #include "gd_compiler.h" #include "os/file_access.h" +#include "io/file_access_encrypted.h" /* TODO: @@ -1591,7 +1592,28 @@ void GDScript::_bind_methods() { Error GDScript::load_byte_code(const String& p_path) { - Vector<uint8_t> bytecode = FileAccess::get_file_as_array(p_path); + Vector<uint8_t> bytecode; + + if (p_path.ends_with("gde")) { + + FileAccess *fa = FileAccess::open(p_path,FileAccess::READ); + ERR_FAIL_COND_V(!fa,ERR_CANT_OPEN); + FileAccessEncrypted *fae = memnew( FileAccessEncrypted ); + ERR_FAIL_COND_V(!fae,ERR_CANT_OPEN); + Vector<uint8_t> key; + key.resize(32); + for(int i=0;i<key.size();i++) { + key[i]=script_encryption_key[i]; + } + Error err = fae->open_and_parse(fa,key,FileAccessEncrypted::MODE_READ); + ERR_FAIL_COND_V(err,err); + bytecode.resize(fae->get_len()); + fae->get_buffer(bytecode.ptr(),bytecode.size()); + memdelete(fae); + } else { + + bytecode = FileAccess::get_file_as_array(p_path); + } ERR_FAIL_COND_V(bytecode.size()==0,ERR_PARSE_ERROR); path=p_path; @@ -2225,7 +2247,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path,const String& p_orig Ref<GDScript> scriptres(script); - if (p_path.ends_with(".gdc")) { + if (p_path.ends_with(".gde") || p_path.ends_with(".gdc")) { script->set_script_path(p_original_path); // script needs this. script->set_path(p_original_path); @@ -2258,6 +2280,7 @@ void ResourceFormatLoaderGDScript::get_recognized_extensions(List<String> *p_ext p_extensions->push_back("gd"); p_extensions->push_back("gdc"); + p_extensions->push_back("gde"); } bool ResourceFormatLoaderGDScript::handles_type(const String& p_type) const { @@ -2268,7 +2291,7 @@ bool ResourceFormatLoaderGDScript::handles_type(const String& p_type) const { String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) const { String el = p_path.extension().to_lower(); - if (el=="gd" || el=="gdc") + if (el=="gd" || el=="gdc" || el=="gde") return "GDScript"; return ""; } |