diff options
| author | Juan Linietsky | 2014-06-11 10:41:03 -0300 |
|---|---|---|
| committer | Juan Linietsky | 2014-06-11 10:41:03 -0300 |
| commit | 9b8696d3dd92e2ed6f310ad0f0bf3c2182c9c6ae (patch) | |
| tree | b2ed0515196bb774504b54aab0bf242992ac3d9f /modules/gdscript/register_types.cpp | |
| parent | 6f0b4678e26c04abfc88c0226c803e78a108de98 (diff) | |
| download | godot-9b8696d3dd92e2ed6f310ad0f0bf3c2182c9c6ae.tar.gz godot-9b8696d3dd92e2ed6f310ad0f0bf3c2182c9c6ae.tar.zst godot-9b8696d3dd92e2ed6f310ad0f0bf3c2182c9c6ae.zip | |
Diffstat (limited to 'modules/gdscript/register_types.cpp')
| -rw-r--r-- | modules/gdscript/register_types.cpp | 78 |
1 files changed, 65 insertions, 13 deletions
diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 6bcd12857..abb3d5a94 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -14,6 +14,8 @@ #include "gd_script.h" #include "io/resource_loader.h" #include "os/file_access.h" +#include "io/file_access_encrypted.h" + GDScriptLanguage *script_language_gd=NULL; @@ -25,6 +27,7 @@ ResourceFormatSaverGDScript *resource_saver_gd=NULL; #include "tools/editor/editor_import_export.h" #include "gd_tokenizer.h" #include "tools/editor/editor_node.h" +#include "tools/editor/editor_settings.h" class EditorExportGDScript : public EditorExportPlugin { @@ -34,20 +37,69 @@ public: virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) { //compile gdscript to bytecode - if (p_path.ends_with(".gd")) { - Vector<uint8_t> file = FileAccess::get_file_as_array(p_path); - if (file.empty()) - return file; - String txt; - txt.parse_utf8((const char*)file.ptr(),file.size()); - file = GDTokenizerBuffer::parse_code_string(txt); - if (!file.empty()) { - print_line("PREV: "+p_path); - p_path=p_path.basename()+".gdc"; - print_line("NOW: "+p_path); - return file; - } + if (EditorImportExport::get_singleton()->script_get_action()!=EditorImportExport::SCRIPT_ACTION_NONE) { + + if (p_path.ends_with(".gd")) { + Vector<uint8_t> file = FileAccess::get_file_as_array(p_path); + if (file.empty()) + return file; + String txt; + txt.parse_utf8((const char*)file.ptr(),file.size()); + file = GDTokenizerBuffer::parse_code_string(txt); + + if (!file.empty()) { + + if (EditorImportExport::get_singleton()->script_get_action()==EditorImportExport::SCRIPT_ACTION_ENCRYPT) { + + String tmp_path=EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/script.gde"); + FileAccess *fa = FileAccess::open(tmp_path,FileAccess::WRITE); + String skey=EditorImportExport::get_singleton()->script_get_encryption_key().to_lower(); + Vector<uint8_t> key; + key.resize(32); + for(int i=0;i<32;i++) { + int v=0; + if (i*2<skey.length()) { + CharType ct = skey[i*2]; + if (ct>='0' && ct<='9') + ct=ct-'0'; + else if (ct>='a' && ct<='f') + ct=10+ct-'a'; + v|=ct<<4; + } + + if (i*2+1<skey.length()) { + CharType ct = skey[i*2+1]; + if (ct>='0' && ct<='9') + ct=ct-'0'; + else if (ct>='a' && ct<='f') + ct=10+ct-'a'; + v|=ct; + } + key[i]=v; + } + FileAccessEncrypted *fae=memnew(FileAccessEncrypted); + Error err = fae->open_and_parse(fa,key,FileAccessEncrypted::MODE_WRITE_AES256); + if (err==OK) { + + fae->store_buffer(file.ptr(),file.size()); + p_path=p_path.basename()+".gde"; + } + + memdelete(fae); + + file=FileAccess::get_file_as_array(tmp_path); + return file; + + + } else { + + p_path=p_path.basename()+".gdc"; + return file; + } + } + + } } return Vector<uint8_t>(); |
