diff options
author | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2018-12-23 20:28:29 +0200 |
---|---|---|
committer | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2018-12-24 17:16:14 +0200 |
commit | ba13a2bc059f97200871fcebdd47dfd756e82981 (patch) | |
tree | 1609852be85833a618d86795f55b69cd3708fadf /modules | |
parent | 10e9221c49eddc05cb36c0b582060cac9e4c8cef (diff) |
Bring back script encryption in export preset
Retrieved working implementation from 2.1 branch and adapted to
existing export preset system.
Added Script tab in export preset to export script as raw text,
compiled, or encrypted (same as in 2.1). The script encryption key is
visually validated. The script export mode and the key is saved per
per preset in `export_presets.cfg`, so it makes sense to ignore this
file in version control system.
Each custom exporting procedure can retrieve an export preset set
during project exporting. Refactored project export dialog a bit to
allow easier code comprehension.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/register_types.cpp | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 9c4dc0c926..3faff4873d 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -54,20 +54,74 @@ class EditorExportGDScript : public EditorExportPlugin { public: virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features) { - if (!p_path.ends_with(".gd")) + int script_mode = EditorExportPreset::MODE_SCRIPT_COMPILED; + String script_key; + + const Ref<EditorExportPreset> &preset = get_export_preset(); + + if (preset.is_valid()) { + script_mode = preset->get_script_export_mode(); + script_key = preset->get_script_encryption_key().to_lower(); + } + + if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) return; Vector<uint8_t> file = FileAccess::get_file_as_array(p_path); if (file.empty()) return; + String txt; txt.parse_utf8((const char *)file.ptr(), file.size()); file = GDScriptTokenizerBuffer::parse_code_string(txt); - if (file.empty()) - return; - - add_file(p_path.get_basename() + ".gdc", file, true); + if (!file.empty()) { + + if (script_mode == EditorExportPreset::MODE_SCRIPT_ENCRYPTED) { + + String tmp_path = EditorSettings::get_singleton()->get_settings_dir().plus_file("tmp/script.gde"); + FileAccess *fa = FileAccess::open(tmp_path, FileAccess::WRITE); + + Vector<uint8_t> key; + key.resize(32); + for (int i = 0; i < 32; i++) { + int v = 0; + if (i * 2 < script_key.length()) { + CharType ct = script_key[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 < script_key.length()) { + CharType ct = script_key[i * 2 + 1]; + if (ct >= '0' && ct <= '9') + ct = ct - '0'; + else if (ct >= 'a' && ct <= 'f') + ct = 10 + ct - 'a'; + v |= ct; + } + key.write[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()); + } + + memdelete(fae); + + file = FileAccess::get_file_as_array(tmp_path); + add_file(p_path.get_basename() + ".gde", file, true); + + } else { + + add_file(p_path.get_basename() + ".gdc", file, true); + } + } } }; |