summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gd_script.cpp29
-rw-r--r--modules/gdscript/gd_tokenizer.cpp1
-rw-r--r--modules/gdscript/register_types.cpp78
3 files changed, 92 insertions, 16 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 "";
}
diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp
index aeee1f6667..a92e2f22ea 100644
--- a/modules/gdscript/gd_tokenizer.cpp
+++ b/modules/gdscript/gd_tokenizer.cpp
@@ -757,6 +757,7 @@ void GDTokenizerText::_advance() {
{Variant::_RID,"RID"},
{Variant::OBJECT,"Object"},
{Variant::INPUT_EVENT,"InputEvent"},
+ {Variant::NODE_PATH,"NodePath"},
{Variant::DICTIONARY,"dict"},
{Variant::DICTIONARY,"Dictionary"},
{Variant::ARRAY,"Array"},
diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp
index 6bcd12857b..abb3d5a946 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>();