MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / GDREConfigSetting_LoadCustomBytecode

Class GDREConfigSetting_LoadCustomBytecode

utility/gdre_config.cpp:19–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19class GDREConfigSetting_LoadCustomBytecode : public GDREConfigSetting {
20 GDSOFTCLASS(GDREConfigSetting_LoadCustomBytecode, GDREConfigSetting);
21
22 String error_message;
23
24public:
25 GDREConfigSetting_LoadCustomBytecode() :
26 GDREConfigSetting(
27 "Bytecode/load_custom_bytecode",
28 "Load Custom Bytecode",
29 "Load a custom bytecode file.",
30 "",
31 false,
32 false) {
33 }
34
35 virtual bool is_filepicker() const override { return true; }
36 virtual bool is_virtual_setting() const override { return true; }
37 virtual String get_error_message() const override { return error_message; }
38 virtual void clear_error_message() override { error_message = ""; }
39 virtual Variant get_value() const override {
40 return "";
41 }
42 virtual void set_value(const Variant &p_value, bool p_force_ephemeral = false) override {
43 String path = p_value;
44 if (path.is_empty()) {
45 return;
46 }
47 if (!FileAccess::exists(path)) {
48 WARN_PRINT("Custom bytecode file does not exist: " + path);
49 error_message = "Custom bytecode file does not exist";
50 return;
51 }
52 String file_contents = FileAccess::get_file_as_string(path);
53 if (file_contents.is_empty()) {
54 WARN_PRINT("Custom bytecode file is empty: " + path);
55 error_message = "Custom bytecode file is empty";
56 return;
57 }
58 Dictionary json = JSON::parse_string(file_contents);
59 if (json.is_empty()) {
60 WARN_PRINT("Custom bytecode file is not valid JSON: " + path);
61 error_message = "Custom bytecode file is not valid JSON";
62 return;
63 }
64
65 // clears errors
66 GDRELogger::clear_error_queues();
67 int commit = GDScriptDecomp::register_decomp_version_custom(json);
68 if (commit == 0) {
69 WARN_PRINT("Failed to register custom bytecode file: " + path);
70 error_message = "Failed to register custom bytecode file: \n" + String("\n").join(GDRELogger::get_errors());
71 return;
72 }
73 GDREConfig::get_singleton()->set_setting("Bytecode/force_bytecode_revision", commit, true);
74 error_message = "";
75 }
76};

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected