From 9e4dcc39af0aeacf47e1fb1cd8ec22635040d2ae Mon Sep 17 00:00:00 2001 From: xXJSONDeruloXx Date: Tue, 21 Jan 2025 22:51:09 -0500 Subject: trying script approach? --- assets/fgmod-uninstaller.sh | 39 +++++++++++++++ assets/fgmod.sh | 113 ++++++++++++++++++++++++++++++++++++++++++++ assets/prepare.sh | 83 ++++++++++++++++++++++++++++++++ main.py | 109 ++++++++++++++++++++++++++++++++++++++++-- src/index.tsx | 59 +++++++++++++---------- 5 files changed, 374 insertions(+), 29 deletions(-) create mode 100755 assets/fgmod-uninstaller.sh create mode 100755 assets/fgmod.sh create mode 100755 assets/prepare.sh diff --git a/assets/fgmod-uninstaller.sh b/assets/fgmod-uninstaller.sh new file mode 100755 index 0000000..a2ef7f6 --- /dev/null +++ b/assets/fgmod-uninstaller.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +mod_path="/usr/share/fgmod" + +if [[ $(pwd) == "$mod_path" ]]; then + rm -r $mod_path +else + rm "dlss-enabler.dll" + rm "dxgi.dll" + rm "nvngx-wrapper.dll" + rm "_nvngx.dll" + rm "dlssg_to_fsr3_amd_is_better.dll" + rm "dlssg_to_fsr3_amd_is_better-3.0.dll" + rm "dlss-enabler-upscaler.dll" + rm "nvngx.ini" + rm "libxess.dll" + rm "d3dcompiler_47.dll" + rm "amd_fidelityfx_dx12.dll" + rm "amd_fidelityfx_vk.dll" + + # Those files might not exist + rm "nvapi64.dll" 2>/dev/null + rm "fakenvapi.ini" 2>/dev/null + rm "OptiScaler.log" 2>/dev/null + rm "dlss-enabler.log" 2>/dev/null + rm "dlssg_to_fsr3.log" 2>/dev/null + rm "fakenvapi.log" 2>/dev/null + + # Restore files the game might've shipped with + mv -f "libxess.dll.b" "libxess.dll" 2>/dev/null + mv -f "d3dcompiler_47.dll.b" "d3dcompiler_47.dll" 2>/dev/null + mv -f "amd_fidelityfx_dx12.dll.b" "amd_fidelityfx_dx12.dll" 2>/dev/null + mv -f "amd_fidelityfx_vk.dll.b" "amd_fidelityfx_vk.dll" 2>/dev/null + + echo "fgmod removed from this game" + echo "Don't forget to remove /home/USERNAME/fgmod/fgmod from the launch options!" + + rm "$0" # remove the uninstaller itself +fi \ No newline at end of file diff --git a/assets/fgmod.sh b/assets/fgmod.sh new file mode 100755 index 0000000..dad2a41 --- /dev/null +++ b/assets/fgmod.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash + +error_exit() { + echo "$1" + if [[ -n $STEAM_ZENITY ]]; then + $STEAM_ZENITY --error --text "$1" + else + zenity --error --text "$1" + fi + exit 1 +} + +mod_path="/usr/share/fgmod" + +if [ "$#" -lt 1 ]; then + echo "Usage: $0 program [program_arguments...]" + exit 1 +fi + +# One arg means the command is ran standalone +if [[ $# -eq 1 ]]; then + if [[ "$1" == *.exe ]]; then + exe_folder_path=$(dirname "$1") + else + exe_folder_path=$1 + fi +else + for arg in "$@"; do + if [[ "$arg" == *.exe ]]; then + # Special cases, only FG-supported games + [[ "$arg" == *"Cyberpunk 2077"* ]] && arg=${arg//REDprelauncher.exe/bin/x64/Cyberpunk2077.exe} + [[ "$arg" == *"Witcher 3"* ]] && arg=${arg//REDprelauncher.exe/bin/x64_dx12/witcher3.exe} + [[ "$arg" == *"HITMAN 3"* ]] && arg=${arg//Launcher.exe/Retail/HITMAN3.exe} + [[ "$arg" == *"HITMAN World of Assassination"* ]] && arg=${arg//Launcher.exe/Retail/HITMAN3.exe} + [[ "$arg" == *"SYNCED"* ]] && arg=${arg//Launcher\/sop_launcher.exe/SYNCED.exe} # UE with a launcher + [[ "$arg" == *"2KLauncher"* ]] && arg=${arg//2KLauncher\/LauncherPatcher.exe/DoesntMatter.exe} # 2K launcher games + [[ "$arg" == *"Warhammer 40,000 DARKTIDE"* ]] && arg=${arg//launcher\/Launcher.exe/binaries/Darktide.exe} + [[ "$arg" == *"Warhammer Vermintide 2"* ]] && arg=${arg//launcher\/Launcher.exe/binaries_dx12/vermintide2_dx12.exe} + [[ "$arg" == *"Satisfactory"* ]] && arg=${arg//FactoryGameSteam.exe/Engine/Binaries/Win64/FactoryGameSteam-Win64-Shipping.exe} + exe_folder_path=$(dirname "$arg") + break + fi + done +fi + +# Fallback to STEAM_COMPAT_INSTALL_PATH when no path was found +if [[ ! -d $exe_folder_path ]] && [[ -n ${STEAM_COMPAT_INSTALL_PATH} ]]; then + echo "Trying the path from STEAM_COMPAT_INSTALL_PATH" + exe_folder_path=${STEAM_COMPAT_INSTALL_PATH} +fi + +# Check for UE games +if [[ -d "$exe_folder_path/Engine" ]]; then + ue_exe_path=$(find "$exe_folder_path" -maxdepth 4 -mindepth 4 -path "*Binaries/Win64/*.exe" -not -path "*/Engine/*" | head -1) + exe_folder_path=$(dirname "$ue_exe_path") +fi + +if [[ -d $exe_folder_path ]]; then + if [[ ! -w $exe_folder_path ]]; then + error_exit "No write permission to the game folder!" + fi + + original_dlls=("libxess.dll" "d3dcompiler_47.dll" "amd_fidelityfx_dx12.dll" "amd_fidelityfx_vk.dll") + + # Assume that the mod is not installed when dlss-enabler.dll is not present + if [[ ! -f "$exe_folder_path/dlss-enabler.dll" ]]; then + [[ -f "$exe_folder_path/dxgi.dll" ]] && error_exit 'dxgi.dll is already present in the game folder!\nThis script uses dxgi.dll to load required files.\nRemove the mod using dxgi.dll or install DLSS Enabler manually.' + for dll in "${original_dlls[@]}"; do + if [[ ! -f "$exe_folder_path/${dll}.b" ]]; then + mv -f "$exe_folder_path/$dll" "$exe_folder_path/${dll}.b" 2>/dev/null + fi + done + fi + + cp -f "$mod_path/fgmod-uninstaller.sh" "$exe_folder_path" || + error_exit "Couldn't copy the uninstaller!" + + cp -f "$mod_path/dlss-enabler.dll" "$exe_folder_path" && + cp -f "$mod_path/dxgi.dll" "$exe_folder_path" && + cp -f "$mod_path/nvngx-wrapper.dll" "$exe_folder_path" || + error_exit "Couldn't copy DLSS Enabler files!" + + # File is not preset on Nvidia installs so will fail on some setups on purpose + cp -f "$mod_path/nvapi64.dll" "$exe_folder_path" 2>/dev/null + + cp -f "$mod_path/_nvngx.dll" "$exe_folder_path" || + error_exit "Couldn't copy _nvngx.dll!" + + cp -f "$mod_path/dlssg_to_fsr3_amd_is_better.dll" "$exe_folder_path" && + cp -f "$mod_path/dlssg_to_fsr3_amd_is_better-3.0.dll" "$exe_folder_path" || + error_exit "Couldn't copy dlssg-to-fsr3!" + + cp -f "$mod_path/dlss-enabler-upscaler.dll" "$exe_folder_path" && + cp -f "$mod_path/amd_fidelityfx_dx12.dll" "$exe_folder_path" && + cp -f "$mod_path/amd_fidelityfx_vk.dll" "$exe_folder_path" && + cp -f "$mod_path/libxess.dll" "$exe_folder_path" && + cp -f "$mod_path/d3dcompiler_47.dll" "$exe_folder_path" || + error_exit "Couldn't copy Optiscaler files!" + + cp -n "$mod_path/nvngx.ini" "$exe_folder_path" + cp -n "$mod_path/fakenvapi.ini" "$exe_folder_path" +else + error_exit "Path doesn't exist!" +fi + +if [[ $# -gt 1 ]]; then + # Execute the original command + export SteamDeck=0 + export WINEDLLOVERRIDES="$WINEDLLOVERRIDES,dxgi=n,b" + "$@" +else + echo Done! +fi diff --git a/assets/prepare.sh b/assets/prepare.sh new file mode 100755 index 0000000..debfede --- /dev/null +++ b/assets/prepare.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +mod_path="$HOME/fgmod" +nvidiaver=555.52.04 +enablerver=3.02.000.0 +fakenvapiver=v1.2.0 +# standalone makes use of fgmod.sh and fgmod-uninstaller.sh from the working directory +# To make it fully standalone with files being installed to pwd, set standalone=1 and mod_path=. +standalone=1 + +if [[ -d "$mod_path" ]] && [[ ! $mod_path == . ]]; then + read -p "$mod_path already exists, override the old version? [y/N] " -n 1 -r /dev/null)" ]] && 7z -y x fakenvapi.7z +cp -f NVIDIA-Linux-x86_64-$nvidiaver/nvngx.dll _nvngx.dll +cp -f NVIDIA-Linux-x86_64-$nvidiaver/LICENSE "licenses/LICENSE (NVIDIA driver)" +chmod +r _nvngx.dll +rm -rf innoextract NVIDIA-Linux-x86_64-$nvidiaver dlss-enabler-setup-$enablerver.exe NVIDIA-Linux-x86_64-$nvidiaver.run fakenvapi.7z +rm -rf plugins nvapi64-proxy.dll dlss-enabler-fsr.dll dlss-enabler-xess.dll dbghelp.dll version.dll winmm.dll nvngx.dll dlss-finder.exe dlss-enabler.log dlssg_to_fsr3.log fakenvapi.log "LICENSE (DLSSG to FSR3 mod).txt" "Readme (DLSS enabler).txt" "READ ME (DLSSG to FSR3 mod).txt" "XESS LICENSE.pdf" +[[ -f "$(which nvidia-smi 2>/dev/null)" ]] && rm -rf nvapi64.dll fakenvapi.ini + +sed -i 's|mod_path="/usr/share/fgmod"|mod_path="'"$mod_path"'"|g' fgmod +chmod +x fgmod + +sed -i 's|mod_path="/usr/share/fgmod"|mod_path="'"$mod_path"'"|g' fgmod-uninstaller.sh +chmod +x fgmod-uninstaller.sh + +echo "" + +# Flatpak doesn't have access to home by default +if flatpak list | grep "com.valvesoftware.Steam" 1>/dev/null; then + echo Flatpak version of Steam detected, adding access to fgmod\'s folder + echo Please restart Steam! + flatpak override --user --filesystem="$mod_path" com.valvesoftware.Steam +fi + +echo All done! +echo For Steam, add this to the launch options: "$mod_path/fgmod" %COMMAND% +echo For Heroic, add this as a new wrapper: "$mod_path/fgmod" diff --git a/main.py b/main.py index bbe095b..64f416a 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,9 @@ -import json import os -import decky -import asyncio +import subprocess +import json +from decky_plugin import PluginBase -class Plugin: +class Plugin(PluginBase): async def get_installed_games(self) -> str: library_file = "/home/deck/.steam/steam/steamapps/libraryfolders.vdf" libraries = [] @@ -38,6 +38,107 @@ class Plugin: # Return games as JSON string for compatibility with TSX return json.dumps(games) + @callable + async def run_install_fgmod(self) -> dict: + script = """ +#!/usr/bin/env bash + +set -euo pipefail # Exit on error, undefined variable, or pipe failure +trap 'echo "An error occurred. Exiting."' ERR + +# Define paths +assets_path="$HOME/homebrew/plugins/Decky-Framegen/assets" +mod_path="$assets_path" +nvidiaver=555.52.04 +enablerver=3.02.000.0 +fakenvapiver=v1.2.0 + +# Ensure the assets directory exists +if [[ ! -d "$assets_path" ]]; then + echo "Error: Assets directory does not exist at $assets_path!" + exit 1 +fi + +# Clear existing mod files +echo "Preparing mod directory..." +rm -rf "$mod_path"/* +mkdir -p "$mod_path" + +# Copy fgmod scripts from assets +echo "Copying fgmod scripts..." +cp "$assets_path/fgmod.sh" "$mod_path/fgmod" || { echo "Error: fgmod.sh not found in assets!"; exit 1; } +cp "$assets_path/fgmod-uninstaller.sh" "$mod_path/fgmod-uninstaller.sh" || { echo "Error: fgmod-uninstaller.sh not found in assets!"; exit 1; } + +# Navigate to mod_path +cd "$mod_path" + +# Download required files +echo "Downloading required files..." +curl -OLf "https://github.com/artur-graniszewski/DLSS-Enabler/releases/download/$enablerver/dlss-enabler-setup-$enablerver.exe" +curl -OLf "https://download.nvidia.com/XFree86/Linux-x86_64/$nvidiaver/NVIDIA-Linux-x86_64-$nvidiaver.run" +curl -OLf "https://raw.githubusercontent.com/mozilla/fxc2/master/dll/d3dcompiler_47.dll" +curl -OLf "https://github.com/FakeMichau/innoextract/releases/download/6.3.0/innoextract" +curl -OLf "https://github.com/FakeMichau/fakenvapi/releases/download/$fakenvapiver/fakenvapi.7z" + +# Validate downloads +echo "Validating downloaded files..." +required_files=( + "dlss-enabler-setup-$enablerver.exe" + "NVIDIA-Linux-x86_64-$nvidiaver.run" + "d3dcompiler_47.dll" + "innoextract" + "fakenvapi.7z" +) + +for file in "${required_files[@]}"; do + if [[ ! -f $file ]]; then + echo "Error: Missing required file: $file" + exit 1 + fi +done + +# Extract and prepare files +echo "Extracting and preparing files..." +chmod +x NVIDIA-Linux-x86_64-$nvidiaver.run innoextract +./NVIDIA-Linux-x86_64-$nvidiaver.run -x +./innoextract dlss-enabler-setup-$enablerver.exe + +mv app/* . || true +rm -r app || true +if command -v 7z &>/dev/null; then + 7z -y x fakenvapi.7z +fi + +cp -f NVIDIA-Linux-x86_64-$nvidiaver/nvngx.dll _nvngx.dll +cp -f NVIDIA-Linux-x86_64-$nvidiaver/LICENSE "licenses/LICENSE (NVIDIA driver)" +chmod +r _nvngx.dll + +# Cleanup unnecessary files +echo "Cleaning up temporary files..." +rm -rf innoextract NVIDIA-Linux-x86_64-$nvidiaver dlss-enabler-setup-$enablerver.exe \ + NVIDIA-Linux-x86_64-$nvidiaver.run fakenvapi.7z + +# Update script paths +sed -i "s|mod_path=\"/usr/share/fgmod\"|mod_path=\"$mod_path\"|g" "$mod_path/fgmod" "$mod_path/fgmod-uninstaller.sh" +chmod +x "$mod_path/fgmod" "$mod_path/fgmod-uninstaller.sh" + +# Handle Flatpak Steam +if flatpak list | grep -q "com.valvesoftware.Steam"; then + echo "Flatpak version of Steam detected. Granting access to $mod_path." + flatpak override --user --filesystem="$mod_path" com.valvesoftware.Steam + echo "Please restart Steam for changes to take effect." +fi + +echo "All done!" +echo "For Steam, add this to the launch options: \"$mod_path/fgmod\" %COMMAND%" +echo "For Heroic, add this as a new wrapper: \"$mod_path/fgmod\"" +""" + try: + process = subprocess.run(script, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + return {"status": "success", "output": process.stdout} + except subprocess.CalledProcessError as e: + return {"status": "error", "message": e.stderr} + async def _main(self): decky.logger.info("Plugin loaded.") diff --git a/src/index.tsx b/src/index.tsx index e8db057..011ce22 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,37 +1,46 @@ -import { useState, useEffect } from "react"; -import { PanelSection, PanelSectionRow, Dropdown, DropdownOption } from "@decky/ui"; +import { useState } from "react"; +import { PanelSection, PanelSectionRow, ButtonItem } from "@decky/ui"; import { callable, definePlugin } from "@decky/api"; import { FaShip } from "react-icons/fa"; -const fetchInstalledGames = callable<[], string>("get_installed_games"); +const runInstallFGMod = callable<[], { status: string; message?: string; output?: string }>("run_install_fgmod"); function Content() { - const [games, setGames] = useState([]); - const [selectedGame, setSelectedGame] = useState(null); - - useEffect(() => { - const loadGames = async () => { - const result = await fetchInstalledGames(); - const gameList = JSON.parse(result) as { appid: string; name: string }[]; - setGames(gameList.map(game => ({ data: game.appid, label: game.name }))); - }; + const [installing, setInstalling] = useState(false); + const [installResult, setInstallResult] = useState<{ status: string; output?: string; message?: string } | null>( + null + ); - loadGames(); - }, []); + const handleInstallClick = async () => { + setInstalling(true); + const result = await runInstallFGMod(); + setInstalling(false); + setInstallResult(result); + }; return ( - + - setSelectedGame(option)} - strDefaultLabel="Select a game" // Placeholder equivalent - /> + + {installing ? "Installing..." : "Install FG Mod"} + - {selectedGame && ( + {installResult && ( -
You selected: {selectedGame.label}
+
+ Status: {installResult.status === "success" ? "Success" : "Error"}
+ {installResult.output && ( + <> + Output: +
{installResult.output}
+ + )} + {installResult.message && ( + <> + Error: {installResult.message} + + )} +
)}
@@ -39,8 +48,8 @@ function Content() { } export default definePlugin(() => ({ - name: "Game Selector Plugin", - titleView:
Game Selector Plugin
, + name: "FG Mod Installer", + titleView:
FG Mod Installer
, content: , icon: , onDismount() { -- cgit v1.2.3