diff --git a/bytecode/bytecode_015d36d.h b/bytecode/bytecode_015d36d.h index 6aa1fa2a..25ecf9bf 100644 --- a/bytecode/bytecode_015d36d.h +++ b/bytecode/bytecode_015d36d.h @@ -26,6 +26,7 @@ class GDScriptDecomp_015d36d : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_015d36d() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_054a2ac.h b/bytecode/bytecode_054a2ac.h index 613f201e..6557f64e 100644 --- a/bytecode/bytecode_054a2ac.h +++ b/bytecode/bytecode_054a2ac.h @@ -26,6 +26,7 @@ class GDScriptDecomp_054a2ac : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_054a2ac() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_0b806ee.h b/bytecode/bytecode_0b806ee.h index 35808546..f962c7b1 100644 --- a/bytecode/bytecode_0b806ee.h +++ b/bytecode/bytecode_0b806ee.h @@ -26,6 +26,7 @@ class GDScriptDecomp_0b806ee : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_0b806ee() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_1a36141.h b/bytecode/bytecode_1a36141.h index 5c5f0a04..14d6a81f 100644 --- a/bytecode/bytecode_1a36141.h +++ b/bytecode/bytecode_1a36141.h @@ -26,6 +26,7 @@ class GDScriptDecomp_1a36141 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_1a36141() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_1add52b.h b/bytecode/bytecode_1add52b.h index f98a5aaf..8c01cc50 100644 --- a/bytecode/bytecode_1add52b.h +++ b/bytecode/bytecode_1add52b.h @@ -26,6 +26,7 @@ class GDScriptDecomp_1add52b : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_1add52b() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_1ca61a3.h b/bytecode/bytecode_1ca61a3.h index bb848a22..dafcb1d0 100644 --- a/bytecode/bytecode_1ca61a3.h +++ b/bytecode/bytecode_1ca61a3.h @@ -26,6 +26,7 @@ class GDScriptDecomp_1ca61a3 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_1ca61a3() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_216a8aa.h b/bytecode/bytecode_216a8aa.h index 393f0a53..25ae4fcb 100644 --- a/bytecode/bytecode_216a8aa.h +++ b/bytecode/bytecode_216a8aa.h @@ -26,6 +26,7 @@ class GDScriptDecomp_216a8aa : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_216a8aa() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_2185c01.h b/bytecode/bytecode_2185c01.h index ec822c80..b8093b26 100644 --- a/bytecode/bytecode_2185c01.h +++ b/bytecode/bytecode_2185c01.h @@ -26,6 +26,7 @@ class GDScriptDecomp_2185c01 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_2185c01() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_23381a5.h b/bytecode/bytecode_23381a5.h index 129d9b0d..2d375ecc 100644 --- a/bytecode/bytecode_23381a5.h +++ b/bytecode/bytecode_23381a5.h @@ -26,6 +26,7 @@ class GDScriptDecomp_23381a5 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_23381a5() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_23441ec.h b/bytecode/bytecode_23441ec.h index 2a9aa8d5..b03253cf 100644 --- a/bytecode/bytecode_23441ec.h +++ b/bytecode/bytecode_23441ec.h @@ -26,6 +26,7 @@ class GDScriptDecomp_23441ec : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_23441ec() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_30c1229.h b/bytecode/bytecode_30c1229.h index 64414b2d..d16fdbad 100644 --- a/bytecode/bytecode_30c1229.h +++ b/bytecode/bytecode_30c1229.h @@ -26,6 +26,7 @@ class GDScriptDecomp_30c1229 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_30c1229() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_31ce3c5.h b/bytecode/bytecode_31ce3c5.h index 9862f68e..65bddbcc 100644 --- a/bytecode/bytecode_31ce3c5.h +++ b/bytecode/bytecode_31ce3c5.h @@ -26,6 +26,7 @@ class GDScriptDecomp_31ce3c5 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_31ce3c5() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_3ea6d9f.h b/bytecode/bytecode_3ea6d9f.h index 66c4edbc..495a19d8 100644 --- a/bytecode/bytecode_3ea6d9f.h +++ b/bytecode/bytecode_3ea6d9f.h @@ -26,6 +26,7 @@ class GDScriptDecomp_3ea6d9f : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_3ea6d9f() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_48f1d02.h b/bytecode/bytecode_48f1d02.h index cbd963af..ebc46d13 100644 --- a/bytecode/bytecode_48f1d02.h +++ b/bytecode/bytecode_48f1d02.h @@ -26,6 +26,7 @@ class GDScriptDecomp_48f1d02 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_48f1d02() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_4ee82a2.h b/bytecode/bytecode_4ee82a2.h index 84717923..7f457311 100644 --- a/bytecode/bytecode_4ee82a2.h +++ b/bytecode/bytecode_4ee82a2.h @@ -26,6 +26,7 @@ class GDScriptDecomp_4ee82a2 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_4ee82a2() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_506df14.h b/bytecode/bytecode_506df14.h index 5d8af28d..73e53284 100644 --- a/bytecode/bytecode_506df14.h +++ b/bytecode/bytecode_506df14.h @@ -25,6 +25,7 @@ class GDScriptDecomp_506df14 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_506df14() { engine_ver_major = 4; } }; #endif diff --git a/bytecode/bytecode_513c026.h b/bytecode/bytecode_513c026.h index 6ce3c86b..ab62115a 100644 --- a/bytecode/bytecode_513c026.h +++ b/bytecode/bytecode_513c026.h @@ -26,6 +26,7 @@ class GDScriptDecomp_513c026 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_513c026() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_514a3fb.h b/bytecode/bytecode_514a3fb.h index 9a872929..131f85b5 100644 --- a/bytecode/bytecode_514a3fb.h +++ b/bytecode/bytecode_514a3fb.h @@ -25,6 +25,7 @@ class GDScriptDecomp_514a3fb : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_514a3fb() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_5565f55.h b/bytecode/bytecode_5565f55.h index 9d0afc29..04a3622e 100644 --- a/bytecode/bytecode_5565f55.h +++ b/bytecode/bytecode_5565f55.h @@ -25,6 +25,7 @@ class GDScriptDecomp_5565f55 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_5565f55() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_5e938f0.h b/bytecode/bytecode_5e938f0.h index af2250ca..55a105ff 100644 --- a/bytecode/bytecode_5e938f0.h +++ b/bytecode/bytecode_5e938f0.h @@ -26,6 +26,7 @@ class GDScriptDecomp_5e938f0 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_5e938f0() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_6174585.h b/bytecode/bytecode_6174585.h index f9df7431..d8420d1c 100644 --- a/bytecode/bytecode_6174585.h +++ b/bytecode/bytecode_6174585.h @@ -26,6 +26,7 @@ class GDScriptDecomp_6174585 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_6174585() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_620ec47.h b/bytecode/bytecode_620ec47.h index 28a6d450..f0a3c6cd 100644 --- a/bytecode/bytecode_620ec47.h +++ b/bytecode/bytecode_620ec47.h @@ -25,6 +25,7 @@ class GDScriptDecomp_620ec47 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_620ec47() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_62273e5.h b/bytecode/bytecode_62273e5.h index 121936e9..a7ee83f1 100644 --- a/bytecode/bytecode_62273e5.h +++ b/bytecode/bytecode_62273e5.h @@ -26,6 +26,7 @@ class GDScriptDecomp_62273e5 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_62273e5() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_64872ca.h b/bytecode/bytecode_64872ca.h index d041b36f..44a5d57c 100644 --- a/bytecode/bytecode_64872ca.h +++ b/bytecode/bytecode_64872ca.h @@ -26,6 +26,7 @@ class GDScriptDecomp_64872ca : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_64872ca() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_65d48d6.h b/bytecode/bytecode_65d48d6.h index 4ac672bb..856eb7b8 100644 --- a/bytecode/bytecode_65d48d6.h +++ b/bytecode/bytecode_65d48d6.h @@ -26,6 +26,7 @@ class GDScriptDecomp_65d48d6 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_65d48d6() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_6694c11.h b/bytecode/bytecode_6694c11.h index 03f19b3c..e45b3a59 100644 --- a/bytecode/bytecode_6694c11.h +++ b/bytecode/bytecode_6694c11.h @@ -25,6 +25,7 @@ class GDScriptDecomp_6694c11 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_6694c11() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_703004f.h b/bytecode/bytecode_703004f.h index 1e24931f..4c277757 100644 --- a/bytecode/bytecode_703004f.h +++ b/bytecode/bytecode_703004f.h @@ -26,6 +26,7 @@ class GDScriptDecomp_703004f : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_703004f() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_7124599.h b/bytecode/bytecode_7124599.h index b2333826..2c095e92 100644 --- a/bytecode/bytecode_7124599.h +++ b/bytecode/bytecode_7124599.h @@ -26,6 +26,7 @@ class GDScriptDecomp_7124599 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_7124599() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_7d2d144.h b/bytecode/bytecode_7d2d144.h index ed3bc1d1..acdad9d5 100644 --- a/bytecode/bytecode_7d2d144.h +++ b/bytecode/bytecode_7d2d144.h @@ -26,6 +26,7 @@ class GDScriptDecomp_7d2d144 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_7d2d144() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_7f7d97f.h b/bytecode/bytecode_7f7d97f.h index 75d5fbeb..0b4dc9e8 100644 --- a/bytecode/bytecode_7f7d97f.h +++ b/bytecode/bytecode_7f7d97f.h @@ -25,6 +25,7 @@ class GDScriptDecomp_7f7d97f : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_7f7d97f() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_85585c7.h b/bytecode/bytecode_85585c7.h index 66e1f718..b549c30f 100644 --- a/bytecode/bytecode_85585c7.h +++ b/bytecode/bytecode_85585c7.h @@ -26,6 +26,7 @@ class GDScriptDecomp_85585c7 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_85585c7() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_8aab9a0.h b/bytecode/bytecode_8aab9a0.h index a3d2fd8d..4beb8eb0 100644 --- a/bytecode/bytecode_8aab9a0.h +++ b/bytecode/bytecode_8aab9a0.h @@ -26,6 +26,7 @@ class GDScriptDecomp_8aab9a0 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_8aab9a0() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_8b912d1.h b/bytecode/bytecode_8b912d1.h index 260d014c..4c1e077a 100644 --- a/bytecode/bytecode_8b912d1.h +++ b/bytecode/bytecode_8b912d1.h @@ -26,6 +26,7 @@ class GDScriptDecomp_8b912d1 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_8b912d1() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_8c1731b.h b/bytecode/bytecode_8c1731b.h index b1e4d0f9..3770c99d 100644 --- a/bytecode/bytecode_8c1731b.h +++ b/bytecode/bytecode_8c1731b.h @@ -26,6 +26,7 @@ class GDScriptDecomp_8c1731b : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_8c1731b() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_8cab401.h b/bytecode/bytecode_8cab401.h index 455b8927..77110909 100644 --- a/bytecode/bytecode_8cab401.h +++ b/bytecode/bytecode_8cab401.h @@ -26,6 +26,7 @@ class GDScriptDecomp_8cab401 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_8cab401() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_8e35d93.h b/bytecode/bytecode_8e35d93.h index b22587b1..c6532763 100644 --- a/bytecode/bytecode_8e35d93.h +++ b/bytecode/bytecode_8e35d93.h @@ -26,6 +26,7 @@ class GDScriptDecomp_8e35d93 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_8e35d93() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_91ca725.h b/bytecode/bytecode_91ca725.h index ab4eeb4f..02229dfd 100644 --- a/bytecode/bytecode_91ca725.h +++ b/bytecode/bytecode_91ca725.h @@ -26,6 +26,7 @@ class GDScriptDecomp_91ca725 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_91ca725() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_97f34a1.h b/bytecode/bytecode_97f34a1.h index e6f382ae..37d7fc19 100644 --- a/bytecode/bytecode_97f34a1.h +++ b/bytecode/bytecode_97f34a1.h @@ -26,6 +26,7 @@ class GDScriptDecomp_97f34a1 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_97f34a1() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_a3f1ee5.h b/bytecode/bytecode_a3f1ee5.h index b259ca79..e61169e4 100644 --- a/bytecode/bytecode_a3f1ee5.h +++ b/bytecode/bytecode_a3f1ee5.h @@ -26,6 +26,7 @@ class GDScriptDecomp_a3f1ee5 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_a3f1ee5() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_a56d6ff.h b/bytecode/bytecode_a56d6ff.h index f464f4b3..3cbc016f 100644 --- a/bytecode/bytecode_a56d6ff.h +++ b/bytecode/bytecode_a56d6ff.h @@ -26,6 +26,7 @@ class GDScriptDecomp_a56d6ff : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_a56d6ff() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_a60f242.h b/bytecode/bytecode_a60f242.h index 369e3cda..16c165ea 100644 --- a/bytecode/bytecode_a60f242.h +++ b/bytecode/bytecode_a60f242.h @@ -25,6 +25,7 @@ class GDScriptDecomp_a60f242 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_a60f242() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_base.cpp b/bytecode/bytecode_base.cpp index 1e45829d..8e85e97d 100644 --- a/bytecode/bytecode_base.cpp +++ b/bytecode/bytecode_base.cpp @@ -4,6 +4,7 @@ #include "bytecode_base.h" #include "compat/file_access_encrypted_v3.h" +#include "compat/variant_writer_compat.h" #include "core/config/engine.h" #include "core/io/file_access.h" @@ -86,7 +87,8 @@ String GDScriptDecomp::get_error_message() { } String GDScriptDecomp::get_constant_string(Vector &constants, uint32_t constId) { - String constString = constants[constId].get_construct_string(); + String constString; + Error err = VariantWriterCompat::write_to_string(constants[constId], constString, engine_ver_major); if (constants[constId].get_type() == Variant::Type::STRING) { constString = constString.replace("\n", "\\n"); } diff --git a/bytecode/bytecode_base.h b/bytecode/bytecode_base.h index 54ed8189..81da7735 100644 --- a/bytecode/bytecode_base.h +++ b/bytecode/bytecode_base.h @@ -20,6 +20,7 @@ class GDScriptDecomp : public Object { String script_text; String error_message; + int engine_ver_major; public: virtual Error decompile_buffer(Vector p_buffer) = 0; diff --git a/bytecode/bytecode_be46be7.h b/bytecode/bytecode_be46be7.h index 87dce899..e64e0837 100644 --- a/bytecode/bytecode_be46be7.h +++ b/bytecode/bytecode_be46be7.h @@ -26,6 +26,7 @@ class GDScriptDecomp_be46be7 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_be46be7() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_c00427a.h b/bytecode/bytecode_c00427a.h index e145f64d..41a20bd0 100644 --- a/bytecode/bytecode_c00427a.h +++ b/bytecode/bytecode_c00427a.h @@ -25,6 +25,7 @@ class GDScriptDecomp_c00427a : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_c00427a() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_c24c739.h b/bytecode/bytecode_c24c739.h index c6bf058d..2cf335cd 100644 --- a/bytecode/bytecode_c24c739.h +++ b/bytecode/bytecode_c24c739.h @@ -26,6 +26,7 @@ class GDScriptDecomp_c24c739 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_c24c739() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_c6120e7.h b/bytecode/bytecode_c6120e7.h index a4506b34..4391756e 100644 --- a/bytecode/bytecode_c6120e7.h +++ b/bytecode/bytecode_c6120e7.h @@ -26,6 +26,7 @@ class GDScriptDecomp_c6120e7 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_c6120e7() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_d28da86.h b/bytecode/bytecode_d28da86.h index b41f9226..833502b2 100644 --- a/bytecode/bytecode_d28da86.h +++ b/bytecode/bytecode_d28da86.h @@ -26,6 +26,7 @@ class GDScriptDecomp_d28da86 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_d28da86() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_d6b31da.h b/bytecode/bytecode_d6b31da.h index 5d223f3a..80cdbaf4 100644 --- a/bytecode/bytecode_d6b31da.h +++ b/bytecode/bytecode_d6b31da.h @@ -26,6 +26,7 @@ class GDScriptDecomp_d6b31da : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_d6b31da() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_e82dc40.h b/bytecode/bytecode_e82dc40.h index 9e355ec9..be3b422c 100644 --- a/bytecode/bytecode_e82dc40.h +++ b/bytecode/bytecode_e82dc40.h @@ -26,6 +26,7 @@ class GDScriptDecomp_e82dc40 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_e82dc40() { engine_ver_major = 1; } }; #endif diff --git a/bytecode/bytecode_ed80f45.h b/bytecode/bytecode_ed80f45.h index 05adcf6d..5a427f9c 100644 --- a/bytecode/bytecode_ed80f45.h +++ b/bytecode/bytecode_ed80f45.h @@ -26,6 +26,7 @@ class GDScriptDecomp_ed80f45 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_ed80f45() { engine_ver_major = 2; } }; #endif diff --git a/bytecode/bytecode_f3f05dc.h b/bytecode/bytecode_f3f05dc.h index 76cbe055..e7cb9522 100644 --- a/bytecode/bytecode_f3f05dc.h +++ b/bytecode/bytecode_f3f05dc.h @@ -25,6 +25,7 @@ class GDScriptDecomp_f3f05dc : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_f3f05dc() { engine_ver_major = 4; } }; #endif diff --git a/bytecode/bytecode_f8a7c46.h b/bytecode/bytecode_f8a7c46.h index 0c4dc6c8..8eb6dcca 100644 --- a/bytecode/bytecode_f8a7c46.h +++ b/bytecode/bytecode_f8a7c46.h @@ -26,6 +26,7 @@ class GDScriptDecomp_f8a7c46 : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_f8a7c46() { engine_ver_major = 3; } }; #endif diff --git a/bytecode/bytecode_ff1e7cf.h b/bytecode/bytecode_ff1e7cf.h index 06ca673f..ba134b11 100644 --- a/bytecode/bytecode_ff1e7cf.h +++ b/bytecode/bytecode_ff1e7cf.h @@ -26,6 +26,7 @@ class GDScriptDecomp_ff1e7cf : public GDScriptDecomp { public: virtual Error decompile_buffer(Vector p_buffer) override; + GDScriptDecomp_ff1e7cf() { engine_ver_major = 3; } }; #endif diff --git a/compat/variant_decoder_compat.cpp b/compat/variant_decoder_compat.cpp index 72a503ad..b5b57416 100644 --- a/compat/variant_decoder_compat.cpp +++ b/compat/variant_decoder_compat.cpp @@ -267,7 +267,7 @@ Error VariantDecoderCompat::decode_variant_3(Variant &r_variant, const uint8_t * uint32_t type = decode_uint32(buf); - ERR_FAIL_COND_V((type & ENCODE_MASK) >= 27, ERR_INVALID_DATA); + ERR_FAIL_COND_V((type & ENCODE_MASK) >= V3Type::VARIANT_MAX, ERR_INVALID_DATA); buf += 4; len -= 4; @@ -570,7 +570,7 @@ Error VariantDecoderCompat::decode_variant_3(Variant &r_variant, const uint8_t * r_variant = (Object *)nullptr; } else { Object *obj = ClassDB::instantiate(str); - + bool is_input_event_key = str == "InputEventKey"; ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE); ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); @@ -600,7 +600,15 @@ Error VariantDecoderCompat::decode_variant_3(Variant &r_variant, const uint8_t * if (r_len) { (*r_len) += used; } - + // Hack for v3 Input Events, which will be the only Objects we encounter encoded into the project.binary + // scancode was renamed to keycode in v4 + if (is_input_event_key) { + if (str == "scancode") { + str = "keycode"; + } else if (str == "physical_scancode") { + str = "physical_keycode"; + } + } obj->set(str, value); } @@ -912,7 +920,7 @@ Error VariantDecoderCompat::decode_variant_2(Variant &r_variant, const uint8_t * uint32_t type = decode_uint32(buf); - ERR_FAIL_COND_V((type & ENCODE_MASK) >= 29, ERR_INVALID_DATA); + ERR_FAIL_COND_V((type & ENCODE_MASK) >= V2Type::VARIANT_MAX, ERR_INVALID_DATA); buf += 4; len -= 4; diff --git a/compat/variant_writer_compat.cpp b/compat/variant_writer_compat.cpp index a8910537..a34155cd 100644 --- a/compat/variant_writer_compat.cpp +++ b/compat/variant_writer_compat.cpp @@ -9,10 +9,253 @@ static String rtosfix(double p_value) { return rtoss(p_value); } -// Don't think this is necessary at the moment? The only objects that get stored inline in text resources are Position3D objects and those are unchanged from Godot 2.x -Error VariantParserCompat::fake_parse_object(VariantParser::Token &token, Variant &r_value, VariantParser::Stream *p_stream, int &line, String &r_err_str, VariantParser::ResourceParser *p_res_parser) { - return parse_value(token, r_value, p_stream, line, r_err_str, p_res_parser); +Error VariantParserCompat::_parse_array(Array &array, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) { + Token token; + bool need_comma = false; + + while (true) { + if (p_stream->is_eof()) { + r_err_str = "Unexpected End of File while parsing array"; + return ERR_FILE_CORRUPT; + } + + Error err = get_token(p_stream, token, line, r_err_str); + if (err != OK) { + return err; + } + + if (token.type == TK_BRACKET_CLOSE) { + return OK; + } + + if (need_comma) { + if (token.type != TK_COMMA) { + r_err_str = "Expected ','"; + return ERR_PARSE_ERROR; + } else { + need_comma = false; + continue; + } + } + + Variant v; + err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser); + if (err) { + return err; + } + + array.push_back(v); + need_comma = true; + } +} + +Error VariantParserCompat::_parse_dictionary(Dictionary &object, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser) { + bool at_key = true; + Variant key; + Token token; + bool need_comma = false; + + while (true) { + if (p_stream->is_eof()) { + r_err_str = "Unexpected End of File while parsing dictionary"; + return ERR_FILE_CORRUPT; + } + + if (at_key) { + Error err = get_token(p_stream, token, line, r_err_str); + if (err != OK) { + return err; + } + + if (token.type == TK_CURLY_BRACKET_CLOSE) { + return OK; + } + + if (need_comma) { + if (token.type != TK_COMMA) { + r_err_str = "Expected '}' or ','"; + return ERR_PARSE_ERROR; + } else { + need_comma = false; + continue; + } + } + + err = parse_value(token, key, p_stream, line, r_err_str, p_res_parser); + + if (err) { + return err; + } + + err = get_token(p_stream, token, line, r_err_str); + + if (err != OK) { + return err; + } + if (token.type != TK_COLON) { + r_err_str = "Expected ':'"; + return ERR_PARSE_ERROR; + } + at_key = false; + } else { + Error err = get_token(p_stream, token, line, r_err_str); + if (err != OK) { + return err; + } + + Variant v; + err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser); + if (err) { + return err; + } + object[key] = v; + need_comma = true; + at_key = true; + } + } } + +// Primarily for parsing V3 input event objects stored in project.godot +// The only other Objects that get stored inline in text resources that we know of are Position3D objects, +// and those are unchanged from Godot 2.x +Error VariantParserCompat::parse_value(VariantParser::Token &token, Variant &r_value, VariantParser::Stream *p_stream, int &line, String &r_err_str, VariantParser::ResourceParser *p_res_parser) { + // Since Arrays and Dictionaries can have Objects inside of them... + if (token.type == TK_CURLY_BRACKET_OPEN) { + Dictionary d; + Error err = _parse_dictionary(d, p_stream, line, r_err_str, p_res_parser); + if (err) { + return err; + } + r_value = d; + return OK; + } else if (token.type == TK_BRACKET_OPEN) { + Array a; + Error err = _parse_array(a, p_stream, line, r_err_str, p_res_parser); + if (err) { + return err; + } + r_value = a; + return OK; + } else if (token.type == TK_IDENTIFIER) { + String id = token.value; + if (id == "Object") { + get_token(p_stream, token, line, r_err_str); + if (token.type != TK_PARENTHESIS_OPEN) { + r_err_str = "Expected '('"; + return ERR_PARSE_ERROR; + } + + get_token(p_stream, token, line, r_err_str); + + if (token.type != TK_IDENTIFIER) { + r_err_str = "Expected identifier with type of object"; + return ERR_PARSE_ERROR; + } + + String type = token.value; + // hacks for v3 input_event + bool v3_input_key_hacks = type == "InputEventKey"; + Object *obj = ClassDB::instantiate(type); + + if (!obj) { + r_err_str = "Can't instantiate Object() of type: " + type; + return ERR_PARSE_ERROR; + } + + Ref ref = Ref(Object::cast_to(obj)); + + get_token(p_stream, token, line, r_err_str); + if (token.type != TK_COMMA) { + r_err_str = "Expected ',' after object type"; + return ERR_PARSE_ERROR; + } + + bool at_key = true; + String key; + Token token2; + bool need_comma = false; + + while (true) { + if (p_stream->is_eof()) { + r_err_str = "Unexpected End of File while parsing Object()"; + return ERR_FILE_CORRUPT; + } + + if (at_key) { + Error err = get_token(p_stream, token2, line, r_err_str); + if (err != OK) { + return err; + } + + if (token2.type == TK_PARENTHESIS_CLOSE) { + r_value = ref.is_valid() ? Variant(ref) : Variant(obj); + return OK; + } + + if (need_comma) { + if (token2.type != TK_COMMA) { + r_err_str = "Expected '}' or ','"; + return ERR_PARSE_ERROR; + } else { + need_comma = false; + continue; + } + } + + if (token2.type != TK_STRING) { + r_err_str = "Expected property name as string"; + return ERR_PARSE_ERROR; + } + + key = token2.value; + + err = get_token(p_stream, token2, line, r_err_str); + + if (err != OK) { + return err; + } + if (token2.type != TK_COLON) { + r_err_str = "Expected ':'"; + return ERR_PARSE_ERROR; + } + at_key = false; + } else { + Error err = get_token(p_stream, token2, line, r_err_str); + if (err != OK) { + return err; + } + + Variant v; + err = parse_value(token2, v, p_stream, line, r_err_str, p_res_parser); + + if (err) { + return err; + } + + // Hacks for v3 input events + // "scancode" was renamed to "keycode" + // We don't check for engine version + // If this is a v4 input_event, it won't have these + // v2 input_events were variants and are handled below + if (v3_input_key_hacks) { + if (key == "scancode") { + key = "keycode"; + } else if (key == "physical_scancode") { + key = "physical_keycode"; + } + } + obj->set(key, v); + need_comma = true; + at_key = true; + } + } + } + // If it's an Object, the above will eventually call return + } + // If this wasn't an Object or a Variant that can have objects stored inside them... + return VariantParser::parse_value(token, r_value, p_stream, line, r_err_str, p_res_parser); +} + Error VariantParserCompat::parse_tag(VariantParser::Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, VariantParser::ResourceParser *p_res_parser, bool p_simple_tag) { return VariantParser::parse_tag(p_stream, line, r_err_str, r_tag, p_res_parser, p_simple_tag); } @@ -87,9 +330,8 @@ Error VariantParserCompat::parse_tag_assign_eof(VariantParser::Stream *p_stream, err = InputEventParserV2::parse_input_event_construct_v2(p_stream, r_value, line, r_err_str); } else if (id == "mbutton" || id == "key" || id == "jbutton" || id == "jaxis") { // Old V2 InputEvent in project.cfg err = InputEventParserV2::parse_input_event_construct_v2(p_stream, r_value, line, r_err_str, id); - } else if (id == "Object") { - err = fake_parse_object(token, r_value, p_stream, line, r_err_str, p_res_parser); } else { + // Our own compat parse_value err = parse_value(token, r_value, p_stream, line, r_err_str, p_res_parser); } return err; @@ -232,7 +474,7 @@ Error VariantWriterCompat::write_compat(const Variant &p_variant, const uint32_t p_store_string_func(p_store_string_ud, "null"); break; // don't save it } - + bool v3_input_key_hacks = false; Ref res = p_variant; if (res.is_valid()) { // is resource @@ -246,15 +488,19 @@ Error VariantWriterCompat::write_compat(const Variant &p_variant, const uint32_t // try external function res_text = p_encode_res_func(p_encode_res_ud, res); } - // try path because it's a file - if (res_text == String() && res->get_path().is_resource_file()) { - // external resource - String path = res->get_path(); - res_text = "Resource( \"" + path + "\")"; + if (res_text.is_empty()) { + if (ver_major == 3 && res->is_class("InputEventKey") && is_pcfg) { + // Hacks for v3 InputEventKeys stored inline in project.godot + v3_input_key_hacks = true; + } else if (res->get_path().is_resource_file()) { + // external resource + String path = res->get_path(); + res_text = "Resource( \"" + path + "\")"; + } } // could come up with some sort of text - if (res_text != String()) { + if (!res_text.is_empty()) { p_store_string_func(p_store_string_ud, res_text); break; } @@ -276,8 +522,16 @@ Error VariantWriterCompat::write_compat(const Variant &p_variant, const uint32_t } else { p_store_string_func(p_store_string_ud, ","); } - - p_store_string_func(p_store_string_ud, "\"" + E->get().name + "\":"); + // v3 InputEventKey hacks + String compat_name = E->get().name; + if (v3_input_key_hacks) { + if (compat_name == "keycode") { + compat_name = "scancode"; + } else if (compat_name == "physical_keycode") { + compat_name = "physical_scancode"; + } + } + p_store_string_func(p_store_string_ud, "\"" + compat_name + "\":"); write_compat(obj->get(E->get().name), ver_major, p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, is_pcfg); } } diff --git a/compat/variant_writer_compat.h b/compat/variant_writer_compat.h index 6242b584..37587598 100644 --- a/compat/variant_writer_compat.h +++ b/compat/variant_writer_compat.h @@ -7,9 +7,11 @@ #include "core/variant/variant_parser.h" class VariantParserCompat : VariantParser { - static Error fake_parse_object(VariantParser::Token &token, Variant &value, VariantParser::Stream *p_stream, int &line, String &r_err_str, VariantParser::ResourceParser *p_res_parser); + static Error _parse_dictionary(Dictionary &object, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser = nullptr); + static Error _parse_array(Array &array, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser = nullptr); public: + static Error parse_value(VariantParser::Token &token, Variant &value, VariantParser::Stream *p_stream, int &line, String &r_err_str, VariantParser::ResourceParser *p_res_parser); static Error parse_tag(VariantParser::Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, VariantParser::ResourceParser *p_res_parser = nullptr, bool p_simple_tag = false); static Error parse_tag_assign_eof(VariantParser::Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, String &r_assign, Variant &r_value, VariantParser::ResourceParser *p_res_parser = nullptr, bool p_simple_tag = false); };