Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions bytecode/bytecode_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "compat/variant_decoder_compat.h"
#include "compat/variant_writer_compat.h"
#include "utility/common.h"
#include "utility/gdre_config.h"
#include "utility/gdre_settings.h"
#include "utility/godotver.h"

Expand Down Expand Up @@ -623,24 +624,6 @@ Error GDScriptDecomp::decompile_buffer(Vector<uint8_t> p_buffer) {
Error err = get_script_state(p_buffer, s);
ERR_FAIL_COND_V(err != OK, err);

int tab_size = 4;

if (s.columns.size() > 0) {
Vector<int> diffs;
int prev_column = 1;
for (auto &[key, value] : s.columns) {
int curr_column = value;
if (curr_column > prev_column) {
diffs.push_back(curr_column - prev_column);
}
prev_column = curr_column;
}
tab_size = gdre::get_most_popular_value(diffs);
if (tab_size <= 1) {
tab_size = 4;
}
}

Ref<GDScriptTokenizerCompat> tokenizer = GDScriptTokenizerCompat::create_buffer_tokenizer(this, p_buffer);
if (tokenizer.is_null()) {
return ERR_INVALID_DATA;
Expand All @@ -655,7 +638,8 @@ Error GDScriptDecomp::decompile_buffer(Vector<uint8_t> p_buffer) {
current = tokenizer->scan();
}

bool use_spaces = false;
bool use_spaces = (IndentType)GDREConfig::get_singleton()->get_setting("Script/Indent/type", 0) == INDENT_TYPE_SPACES;
int tab_size = GDREConfig::get_singleton()->get_setting("Script/Indent/size", 4).operator int();
bool first_line = true;
int version = s.bytecode_version;
int bytecode_version = get_bytecode_version();
Expand Down
6 changes: 6 additions & 0 deletions bytecode/bytecode_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ class GDScriptDecomp : public RefCounted {
TOKEN_LINE_MASK = (1 << TOKEN_LINE_BITS) - 1,
};

enum IndentType {
INDENT_TYPE_TABS,
INDENT_TYPE_SPACES,
INDENT_TYPE_MAX,
};

// bytecode_version, ids, constants, tokens, lines, columns
struct ScriptState {
int bytecode_version = -1;
Expand Down
14 changes: 9 additions & 5 deletions standalone/gdre_config_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extends GDREWindow

@export var show_ephemeral_settings: bool = false

signal config_changed(changed_settings: Dictionary[String, Variant])
signal config_changed(changed_settings: Dictionary[String, Array])

func create_section_settings() -> LabelSettings:
var label_settings: LabelSettings = LabelSettings.new()
Expand Down Expand Up @@ -238,15 +238,19 @@ func create_setting_button(setting: GDREConfigSetting) -> Control:
elif setting.get_type() == TYPE_INT:
button = SpinBox.new()
button.value = value
button.step = 1
button.min_value = setting.get_min_value()
button.max_value = setting.get_max_value()
button.step = setting.get_step_value()
var label: Label = make_button_label(setting.get_brief_description())
label.tooltip_text = setting.get_description()
control = make_button_hbox(setting, button, label)
button.value_changed.connect(func(val): setting_callback(setting, val, control))
elif setting.get_type() == TYPE_FLOAT:
button = SpinBox.new()
button.value = value
button.step = 0.1
button.min_value = setting.get_min_value()
button.max_value = setting.get_max_value()
button.step = setting.get_step_value()
var label: Label = make_button_label(setting.get_brief_description())
label.tooltip_text = setting.get_description()
control = make_button_hbox(setting, button, label)
Expand Down Expand Up @@ -325,10 +329,10 @@ func _render_settings():


func save_settings():
var changed_settings: Dictionary[String, Variant] = {}
var changed_settings: Dictionary[String, Array] = {}
for setting: GDREConfigSetting in setting_value_map.keys():
if setting.get_value() != setting_value_map[setting]:
changed_settings[setting.get_full_name()] = setting_value_map[setting]
changed_settings[setting.get_full_name()] = [setting.get_value(), setting_value_map[setting]]
setting.set_value(setting_value_map[setting])
GDREConfig.save_config()
if changed_settings.size() != 0 or force_change:
Expand Down
3 changes: 2 additions & 1 deletion standalone/gdre_recover.gd
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,9 @@ func _on_export_settings_button_pressed() -> void:
%GDREConfigDialog.show()


func _on_gdre_config_dialog_config_changed(changed_settings: Dictionary[String, Variant]) -> void:
func _on_gdre_config_dialog_config_changed(changed_settings: Dictionary[String, Array]) -> void:
GDRESettings.update_from_ephemeral_settings()
RESOURCE_PREVIEW.refresh()


func _on_add_pcks_dialog_files_selected(paths: PackedStringArray) -> void:
Expand Down
6 changes: 6 additions & 0 deletions standalone/gdre_resource_preview.gd
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ func load_resource(path: String) -> void:
if (%ResourceInfo.text == ""):
pop_resource_info(path, info)

func refresh():
var current_view = get_currently_visible_view()
if current_view == %TextView and current_resource_path != "":
%TextView.reload_from_disk()
# TODO: handle other views? Not currently necessary, config settings only affect the text view currently


func try_text_preview(path, type, res_type):
if type == -1:
Expand Down
50 changes: 31 additions & 19 deletions standalone/gdre_text_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ enum HighlightType {
XML
}

var current_type: HighlightType = HighlightType.UNKNOWN

func _add_regions_to_gdscript_highlighter():
# Not working, if it ends in a newline, the color wraps to the next line
gdscript_highlighter.add_color_region("@", " ", Color("#ffb373"))
Expand Down Expand Up @@ -112,13 +114,6 @@ func _add_regions_to_gdscript_highlighter():
get:
return xml_highlighter

@export var default_highlighter: HighlightType = HighlightType.GDSCRIPT:
set(val):
set_highlight_type(val)
default_highlighter = val
get:
return default_highlighter

@onready var font_size = get_theme_font_size("TextEdit")

var code_opts_panel_button_icon = preload("res://gdre_icons/gdre_GuiTabMenuHl.svg")
Expand Down Expand Up @@ -204,17 +199,30 @@ func _init():
code_opts_box.add_child(code_opts_panel_button)
code_opts_box.add_child(CODE_VIWER_OPTIONS)
add_child(code_opts_box)
set_highlight_type(default_highlighter)
set_text_viewer_props()

func _ready():
set_highlight_type(default_highlighter)
set_highlight_type(HighlightType.UNKNOWN)

func reset():
current_path = ""
set_viewer_text("")
set_text_viewer_props()
set_highlight_type(HighlightType.UNKNOWN)
pass

func reload_from_disk():
if current_path.is_empty():
return
var h_scroll = CODE_VIEWER.scroll_horizontal
var v_scroll = CODE_VIEWER.scroll_vertical
var caret_line = CODE_VIEWER.get_caret_line()
var caret_column = CODE_VIEWER.get_caret_column()
load_path(current_path, current_type)
CODE_VIEWER.scroll_horizontal = h_scroll
CODE_VIEWER.scroll_vertical = v_scroll
CODE_VIEWER.set_caret_line(caret_line, false)
CODE_VIEWER.set_caret_column(caret_column, false)

func set_viewer_text(text: String):
# This is a workaround for a bug in CodeEdit where setting the text property throws errors when wrapping is enabled
if CODE_VIEWER.wrap_mode == TextEdit.LINE_WRAPPING_BOUNDARY:
Expand Down Expand Up @@ -271,39 +279,39 @@ func load_code(path, override_bytecode_revision: int = 0) -> bool:
if GDRESettings.has_loaded_dotnet_assembly():
var decompiler = GDRESettings.get_dotnet_decompiler()
code_text = decompiler.decompile_individual_file(path)
set_csharp_viewer_props()
set_highlight_type(HighlightType.CSHARP)
else:
code_text = "Error loading script:\nNo .NET assembly loaded"
set_text_viewer_props()
set_highlight_type(HighlightType.TEXT)
else:
set_csharp_viewer_props()
set_highlight_type(HighlightType.CSHARP)
elif ext == "gde" or ext == "gdc":
var script: FakeGDScript = FakeGDScript.new()
if (override_bytecode_revision != 0):
script.set_override_bytecode_revision(override_bytecode_revision)
script.load_source_code(path)
if not script.get_error_message().is_empty():
code_text = "Error loading script:\n" + script.get_error_message()
set_text_viewer_props()
set_highlight_type(HighlightType.TEXT)
else:
code_text = script.get_source_code()
set_code_viewer_props()
set_highlight_type(HighlightType.GDSCRIPT)
else: # ext == "gd"
code_text = FileAccess.get_file_as_string(path)
set_code_viewer_props()
set_highlight_type(HighlightType.GDSCRIPT)

set_viewer_text(code_text)
return true

func load_text_resource(path):
current_path = path
set_resource_viewer_props()
set_highlight_type(HighlightType.GDRESOURCE)
set_viewer_text(ResourceCompatLoader.resource_to_string(path))
return true

func load_text_string(text):
current_path = ""
set_text_viewer_props()
set_highlight_type(HighlightType.TEXT)
set_viewer_text(text)
return true

Expand Down Expand Up @@ -377,7 +385,10 @@ func recognize(path):
return HighlightType.UNKNOWN

func set_highlight_type(type: HighlightType):
match type:
if current_type == type:
return
current_type = type
match current_type:
HighlightType.GDSHADER:
set_shader_viewer_props()
HighlightType.GDSCRIPT:
Expand Down Expand Up @@ -419,6 +430,7 @@ func set_common_code_viewer_props(is_code: bool):
CODE_VIEWER.gutters_draw_fold_gutter = is_code
CODE_VIEWER.gutters_draw_line_numbers = is_code
CODE_VIEWER.auto_brace_completion_highlight_matching = is_code
CODE_VIEWER.set_tab_size(GDREConfig.get_setting("Script/Indent/size"))


func set_shader_viewer_props():
Expand Down
121 changes: 121 additions & 0 deletions utility/gdre_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@
"Add imports to git repo",
"Add .godot/imported/ (or .import/ for Godot 3) to the git repo.",
false)),
memnew(GDREConfigSettingEnum(
"Script/Indent/type",
"Indent type",
"The type of indentation to use when decompiling and displaying scripts.",
0,
"Tabs,Spaces",
false,
false)),
memnew(GDREConfigSettingRange(
"Script/Indent/size",
"Tab size",
"The number of spaces to use when decompiling and displaying scripts.",
4,
"1,64,1",
false,
false)),
memnew(GDREConfigSetting_BytecodeForceBytecodeRevision()),
memnew(GDREConfigSetting_LoadCustomBytecode()),
#if !GODOT_MONO_DECOMP_DISABLED
Expand Down Expand Up @@ -428,7 +444,7 @@
}

TypedArray<GDREConfigSetting> GDREConfig::get_all_settings() const {
TypedArray<GDREConfigSetting> settings;

Check warning on line 447 in utility/gdre_config.cpp

View workflow job for this annotation

GitHub Actions / Windows Template Release

declaration of 'settings' hides class member

Check warning on line 447 in utility/gdre_config.cpp

View workflow job for this annotation

GitHub Actions / Windows Editor

declaration of 'settings' hides class member
settings.resize(default_settings.size());
int i = 0;
for (const auto &[key, setting] : default_settings) {
Expand Down Expand Up @@ -594,6 +610,45 @@
GDREConfig::get_singleton()->set_setting(full_name, p_value, p_force_ephemeral || ephemeral);
}

Variant GDREConfigSetting::get_min_value() const {
switch (get_type()) {
case Variant::Type::INT:
return 0;
case Variant::Type::FLOAT:
return 0.0f;
case Variant::Type::BOOL:
return false;
default:
return Variant();
}
}

Variant GDREConfigSetting::get_max_value() const {
switch (get_type()) {
case Variant::Type::INT:
return INT_MAX;
case Variant::Type::FLOAT:
return 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
case Variant::Type::BOOL:
return true;
default:
return Variant();
}
}

Variant GDREConfigSetting::get_step_value() const {
switch (get_type()) {
case Variant::Type::INT:
return 1;
case Variant::Type::FLOAT:
return 0.01f;
case Variant::Type::BOOL:
return 1;
default:
return Variant();
}
}

bool GDREConfigSetting::is_hidden() const {
return hidden;
}
Expand All @@ -602,6 +657,68 @@
return ephemeral;
}

GDREConfigSettingEnum::GDREConfigSettingEnum(
const String &p_full_name,
const String &p_brief,
const String &p_description,
const Variant &p_default_value,
const String &p_enum_values,
bool p_hidden,
bool p_ephemeral) :
GDREConfigSetting(p_full_name, p_brief, p_description, p_default_value, p_hidden, p_ephemeral) {
enum_values = p_enum_values.split(",");
}

bool GDREConfigSettingEnum::has_special_value() const {
return true;
}

Dictionary GDREConfigSettingEnum::get_list_of_possible_values() const {
Dictionary ret;
for (int i = 0; i < enum_values.size(); i++) {
ret[i] = enum_values[i];
}
return ret;
}

GDREConfigSettingRange::GDREConfigSettingRange(
const String &p_full_name,
const String &p_brief,
const String &p_description,
const Variant &p_default_value,
const String &p_range_string, bool p_hidden, bool p_ephemeral) :
GDREConfigSetting(p_full_name, p_brief, p_description, p_default_value, p_hidden, p_ephemeral) {
auto parts = p_range_string.split(",");
ERR_FAIL_COND_MSG(parts.size() != 3, "Invalid range string: " + p_range_string);
if (p_default_value.get_type() == Variant::Type::INT) {
min_value = parts[0].to_int();
max_value = parts[1].to_int();
step_value = parts[2].to_int();
} else if (p_default_value.get_type() == Variant::Type::FLOAT) {
min_value = parts[0].to_float();
max_value = parts[1].to_float();
step_value = parts[2].to_float();
} else {
ERR_FAIL_MSG("Invalid range string: " + p_range_string);
}
}

Variant GDREConfigSettingRange::get_min_value() const {
return min_value;
}

Variant GDREConfigSettingRange::get_max_value() const {
return max_value;
}

Variant GDREConfigSettingRange::get_step_value() const {
return step_value;
}

bool GDREConfigSettingRange::is_range_setting() const {
return true;
}

void GDREConfigSetting::_bind_methods() {
ClassDB::bind_method(D_METHOD("reset"), &GDREConfigSetting::reset);
ClassDB::bind_method(D_METHOD("set_value", "value", "force_ephemeral"), &GDREConfigSetting::set_value, DEFVAL(false));
Expand All @@ -617,6 +734,10 @@
ClassDB::bind_method(D_METHOD("is_filepicker"), &GDREConfigSetting::is_filepicker);
ClassDB::bind_method(D_METHOD("is_dirpicker"), &GDREConfigSetting::is_dirpicker);
ClassDB::bind_method(D_METHOD("is_virtual_setting"), &GDREConfigSetting::is_virtual_setting);
ClassDB::bind_method(D_METHOD("is_range_setting"), &GDREConfigSetting::is_range_setting);
ClassDB::bind_method(D_METHOD("get_min_value"), &GDREConfigSetting::get_min_value);
ClassDB::bind_method(D_METHOD("get_max_value"), &GDREConfigSetting::get_max_value);
ClassDB::bind_method(D_METHOD("get_step_value"), &GDREConfigSetting::get_step_value);
ClassDB::bind_method(D_METHOD("get_error_message"), &GDREConfigSetting::get_error_message);
ClassDB::bind_method(D_METHOD("clear_error_message"), &GDREConfigSetting::clear_error_message);
ClassDB::bind_method(D_METHOD("has_special_value"), &GDREConfigSetting::has_special_value);
Expand Down
Loading
Loading