Skip to content

Commit

Permalink
break down code to other scripts & add run gss button
Browse files Browse the repository at this point in the history
  • Loading branch information
nieboczek committed Sep 28, 2024
1 parent 9c925c7 commit 1af9033
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 143 deletions.
27 changes: 19 additions & 8 deletions mod_manager.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://c6570n2s1k1wv"]
[gd_scene load_steps=6 format=3 uid="uid://c6570n2s1k1wv"]

[ext_resource type="Theme" uid="uid://dged4041swr1" path="res://theme.tres" id="1_j4kl3"]
[ext_resource type="Script" path="res://scripts/mod_manager.gd" id="1_kosmn"]
[ext_resource type="Script" path="res://scripts/path_container.gd" id="3_2w3wq"]
[ext_resource type="Script" path="res://scripts/mod_loader_container.gd" id="4_66fcs"]
[ext_resource type="Script" path="res://scripts/mod_list_container.gd" id="5_7qwuo"]

[node name="ModManager" type="Control"]
layout_mode = 3
Expand All @@ -28,18 +31,24 @@ layout_mode = 2

[node name="PathContainer" type="HBoxContainer" parent="MarginContainer/MainContainer"]
layout_mode = 2
script = ExtResource("3_2w3wq")

[node name="PathLabel" type="Label" parent="MarginContainer/MainContainer/PathContainer"]
layout_mode = 2
theme_override_colors/font_color = Color(1, 0, 0, 1)
text = "GSS Path: C:/"

[node name="RunGameButton" type="Button" parent="MarginContainer/MainContainer/PathContainer"]
layout_mode = 2
text = "Run GSS"

[node name="ChangePathButton" type="Button" parent="MarginContainer/MainContainer/PathContainer"]
layout_mode = 2
text = "Change path"

[node name="ModLoaderContainer" type="HBoxContainer" parent="MarginContainer/MainContainer"]
layout_mode = 2
script = ExtResource("4_66fcs")

[node name="ModLoaderLabel" type="Label" parent="MarginContainer/MainContainer/ModLoaderContainer"]
layout_mode = 2
Expand All @@ -57,6 +66,7 @@ theme_override_constants/margin_bottom = 4

[node name="ModListContainer" type="HBoxContainer" parent="MarginContainer/MainContainer"]
layout_mode = 2
script = ExtResource("5_7qwuo")

[node name="ModListLabel" type="Label" parent="MarginContainer/MainContainer/ModListContainer"]
layout_mode = 2
Expand All @@ -83,7 +93,7 @@ layout_mode = 2

[node name="ModManagerLabel" type="Label" parent="MarginContainer/MainContainer/ModManagerContainer"]
layout_mode = 2
text = "GSS Mod Manager v0.2"
text = "GSS Mod Manager v0.3"

[node name="ConfigureButton" type="Button" parent="MarginContainer/MainContainer/ModManagerContainer"]
layout_mode = 2
Expand Down Expand Up @@ -131,10 +141,11 @@ access = 2
filters = PackedStringArray("*.zip,*.rar,*.7z;Archive Files")
use_native_dialog = true

[connection signal="pressed" from="MarginContainer/MainContainer/PathContainer/ChangePathButton" to="." method="_on_change_path_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/ModLoaderContainer/ModLoaderInstallButton" to="." method="_on_mod_loader_install_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/ModListContainer/RefreshButton" to="." method="_on_refresh_list_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/ModListContainer/InstallModButton" to="." method="_on_install_mod_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/PathContainer/RunGameButton" to="MarginContainer/MainContainer/PathContainer" method="_on_run_game_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/PathContainer/ChangePathButton" to="MarginContainer/MainContainer/PathContainer" method="_on_change_path_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/ModLoaderContainer/ModLoaderInstallButton" to="MarginContainer/MainContainer/ModLoaderContainer" method="_on_mod_loader_install_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/ModListContainer/RefreshButton" to="MarginContainer/MainContainer/ModListContainer" method="_on_refresh_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/ModListContainer/InstallModButton" to="MarginContainer/MainContainer/ModListContainer" method="_on_install_mod_button_pressed"]
[connection signal="pressed" from="MarginContainer/MainContainer/ModManagerContainer/ConfigureButton" to="." method="_on_configure_button_pressed"]
[connection signal="dir_selected" from="FileDialog" to="." method="_on_file_dialog_dir_selected"]
[connection signal="file_selected" from="FileDialog" to="." method="_on_file_dialog_file_selected"]
[connection signal="dir_selected" from="FileDialog" to="." method="_on_file_dialog_gss_path_selected"]
[connection signal="file_selected" from="FileDialog" to="MarginContainer/MainContainer/ModListContainer" method="_on_file_dialog_mod_selected"]
4 changes: 2 additions & 2 deletions scripts/files.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Node

## Copies from path to destination_path recursively, destination_path must exist
## Returns error code
static func copy_recursive(from: String, to: String, folder_name: String = "") -> int:
func copy_recursive(from: String, to: String, folder_name: String = "") -> int:
var err = DirAccess.make_dir_absolute("%s%s" % [to, folder_name])
if err != OK and err != ERR_ALREADY_EXISTS:
return err
Expand Down Expand Up @@ -30,7 +30,7 @@ static func copy_recursive(from: String, to: String, folder_name: String = "") -

## Deletes directories recursively
## Returns error code
static func remove_recursive(path: String) -> int:
func remove_recursive(path: String) -> int:
var dir = DirAccess.open(path)
if dir:
dir.list_dir_begin()
Expand Down
64 changes: 64 additions & 0 deletions scripts/mod_list_container.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class_name ModListContainer extends HBoxContainer

@onready var install_mod_button = $InstallModButton
@onready var mod_list_label = $ModListLabel

var mm: ModManager

func _on_refresh_button_pressed() -> void:
mm.update_mod_list()

func _on_install_mod_button_pressed() -> void:
mm.file_dialog.file_mode = FileDialog.FileMode.FILE_MODE_OPEN_FILE
mm.file_dialog.root_subfolder = "%s\\Downloads" % OS.get_environment("USERPROFILE")
mm.file_dialog.popup()

func set_install_disabled(disabled: bool) -> void:
install_mod_button.disabled = disabled

func set_count(count: int) -> void:
mod_list_label.text = "Mod list [%s]" % count

func _on_file_dialog_mod_selected(path: String) -> void:
# Use 7z to unzip the archive and copy it to GSS
var err = OS.execute("%s/7z.exe" % mm.root_path, ["x", path, "-o" + "%s/mod" % mm.root_path, "-y"])
if mm.os_error("Execute 7z", err): return

var names = DirAccess.get_directories_at("%s/mod" % mm.root_path)
var mod_name = names[0] # there can be more, only if the program crashes. sucks to suck

err = DirAccess.make_dir_absolute("%s/Simulatorita/Binaries/Win64/Mods/%s" % [mm.gss_path, mod_name])
if mm.error("Make directory for mod", err): return

err = Files.copy_recursive(
"%s/mod/%s" % [mm.root_path, mod_name],
"%s/Simulatorita/Binaries/Win64/Mods/%s" % [mm.gss_path, mod_name]
)
if mm.error("Copy from mod to mods folder", err): return
err = Files.remove_recursive("%s/mod/%s" % [mm.root_path, mod_name])
if mm.error("Remove mod", err): return

# Add "mod_name : 1" to mods.txt
var file = FileAccess.open("%s/Simulatorita/Binaries/Win64/Mods/mods.txt" % mm.gss_path, FileAccess.READ)
if file:
var lines = []
while not file.eof_reached():
lines.append(file.get_line())
file.close()
lines.append(mod_name + " : 1")

file = FileAccess.open("%s/Simulatorita/Binaries/Win64/Mods/mods.txt" % mm.gss_path, FileAccess.WRITE)
if file:
for i in range(len(lines)):
file.store_string(lines[i])
if i < len(lines) - 1:
file.store_string("\n")
file.close()
mm.update_mod_list()
print("Mod added successfully")
else:
err = FileAccess.get_open_error()
mm.error("Open mods.txt file", err)
else:
err = FileAccess.get_open_error()
mm.error("Open mods.txt file", err)
38 changes: 38 additions & 0 deletions scripts/mod_loader_container.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class_name ModLoaderContainer extends HBoxContainer

@onready var mod_loader_install_button = $ModLoaderInstallButton
@onready var mod_loader_label = $ModLoaderLabel

var is_installed := false
var mm: ModManager

func _on_mod_loader_install_button_pressed() -> void:
if is_installed:
Files.remove_recursive("%s/Simulatorita/Binaries/Win64/Mods" % mm.gss_path)
DirAccess.remove_absolute("%s/Simulatorita/Binaries/Win64/UE4SS.dll" % mm.gss_path)
DirAccess.remove_absolute("%s/Simulatorita/Binaries/Win64/UE4SS-settings.ini" % mm.gss_path)
DirAccess.remove_absolute("%s/Simulatorita/Binaries/Win64/dwmapi.dll" % mm.gss_path)
else:
Files.copy_recursive("%s/UE4SS" % mm.root_path, "%s/Simulatorita/Binaries/Win64" % mm.gss_path)
set_installed(!is_installed)
mm.update_mod_list()

func check_installed() -> void:
var installed = FileAccess.file_exists("%s/Simulatorita/Binaries/Win64/UE4SS.dll" % mm.gss_path)
set_installed(installed)

func set_install_disabled(disabled: bool) -> void:
mod_loader_install_button.disabled = disabled

func set_installed(installed: bool) -> void:
is_installed = installed
if installed:
mod_loader_label.text = "Mod loader installed"
mod_loader_label.add_theme_color_override("font_color", Color.GREEN)
mod_loader_install_button.text = "Uninstall mod loader"
mm.mod_list_container.set_install_disabled(false)
else:
mod_loader_label.text = "Mod loader not installed"
mod_loader_label.add_theme_color_override("font_color", Color.RED)
mod_loader_install_button.text = "Install mod loader"
mm.mod_list_container.set_install_disabled(false)
Loading

0 comments on commit 1af9033

Please sign in to comment.