Repository navigation
Implement GDPatch modloader installers #2303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ethangreen-dev
wants to merge
3
commits into
develop
Choose a base branch
from
gdpatch
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import { InstallArgs, PackageInstaller } from "./PackageInstaller"; | ||
| import FileNotFoundError from "../model/errors/FileNotFoundError"; | ||
| import FileWriteError from "../model/errors/FileWriteError"; | ||
| import FsProvider from "../providers/generic/file/FsProvider"; | ||
| import path from "../providers/node/path/path"; | ||
| import FileUtils from "../utils/FileUtils"; | ||
|
|
||
| export class GDPatchInstaller implements PackageInstaller { | ||
| async install(args: InstallArgs) { | ||
| const { | ||
| packagePath, | ||
| profile, | ||
| } = args; | ||
|
|
||
| const fs = FsProvider.instance; | ||
|
|
||
| const windowsLoaderSrc = path.join(packagePath, "winmm.dll"); | ||
| const windowsLoaderDest = profile.joinToProfilePath("winmm.dll"); | ||
| await fs.copyFile(windowsLoaderSrc, windowsLoaderDest); | ||
|
|
||
| const linuxLoaderSrc = path.join(packagePath, "libgdpatch_loader.so"); | ||
| const linuxLoaderDest = profile.joinToProfilePath("libgdpatch_loader.so"); | ||
| await fs.copyFile(linuxLoaderSrc, linuxLoaderDest); | ||
|
|
||
| const macosLoaderSrc = path.join(packagePath, "libgdpatch_loader.dylib"); | ||
| const macosLoaderDest = profile.joinToProfilePath("libgdpatch_loader.dylib"); | ||
| await fs.copyFile(macosLoaderSrc, macosLoaderDest); | ||
| } | ||
|
|
||
| async uninstall(args: InstallArgs) { | ||
| const { profile } = args; | ||
| const fs = FsProvider.instance; | ||
|
|
||
| const loaderPaths = [ | ||
| profile.joinToProfilePath("winmm.dll"), | ||
| profile.joinToProfilePath("libgdpatch_loader.so"), | ||
| profile.joinToProfilePath("libgdpatch_loader.dylib"), | ||
| ]; | ||
|
|
||
| try { | ||
| for (const loaderPath of loaderPaths) { | ||
| if (await fs.exists(loaderPath)) { | ||
| await fs.unlink(loaderPath); | ||
| } | ||
| } | ||
| } catch (e) { | ||
| const name = "Failed to delete GDPatch loader files from profile"; | ||
| const solution = "Is the game still running?"; | ||
| throw FileWriteError.fromThrownValue(e, name, solution); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function findFolderContainingModToml(folder: string): Promise<string | undefined> { | ||
| const fs = FsProvider.instance; | ||
|
|
||
| if (await fs.exists(path.join(folder, "gdpatch_mod.toml"))) { | ||
| return folder; | ||
| } | ||
|
|
||
| for (const entry of await fs.readdir(folder)) { | ||
| const entryPath = path.join(folder, entry); | ||
| if ((await fs.lstat(entryPath)).isFile()) { | ||
| continue; | ||
| } | ||
|
|
||
| const modFolder = await findFolderContainingModToml(entryPath); | ||
| if (modFolder) { | ||
| return modFolder; | ||
| } | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| export class GDPatchPluginInstaller implements PackageInstaller { | ||
| private getModFolderInProfile(args: InstallArgs) { | ||
| return args.profile.joinToProfilePath("GDPatch", "mods", args.mod.getName()); | ||
| } | ||
|
|
||
| async install(args: InstallArgs) { | ||
| const modFolderInCache = await findFolderContainingModToml(args.packagePath); | ||
| if (modFolderInCache === undefined) { | ||
| throw new FileNotFoundError( | ||
| `Failed to find gdpatch_mod.toml in ${args.mod.getName()}`, | ||
| "Either the mod package is malformed, or the files extracted to cache are corrupted" | ||
| ); | ||
| } | ||
|
|
||
| const modFolderInProfile = this.getModFolderInProfile(args); | ||
| await FileUtils.ensureDirectory(modFolderInProfile); | ||
| await FsProvider.instance.copyFolder(modFolderInCache, modFolderInProfile); | ||
| } | ||
|
|
||
| async uninstall(args: InstallArgs) { | ||
| try { | ||
| await FileUtils.recursiveRemoveDirectoryIfExists(this.getModFolderInProfile(args)); | ||
| } catch (e) { | ||
| const name = `Failed to delete ${args.mod.getName()} from profile`; | ||
| const solution = "Is the game still running?"; | ||
| throw FileWriteError.fromThrownValue(e, name, solution); | ||
| } | ||
| } | ||
|
|
||
| async enable(args: InstallArgs) { | ||
| const fs = FsProvider.instance; | ||
|
|
||
| try { | ||
| const disabledMarkerPath = path.join(this.getModFolderInProfile(args), "gdpatch_disabled"); | ||
| if (await fs.exists(disabledMarkerPath)) { | ||
| await fs.unlink(disabledMarkerPath); | ||
| } | ||
| } catch (e) { | ||
| const name = `Failed to enable ${args.mod.getName()}`; | ||
| const solution = "Is the game still running?"; | ||
| throw FileWriteError.fromThrownValue(e, name, solution); | ||
| } | ||
| } | ||
|
|
||
| async disable(args: InstallArgs) { | ||
| const fs = FsProvider.instance; | ||
|
|
||
| try { | ||
| const disabledMarkerPath = path.join(this.getModFolderInProfile(args), "gdpatch_disabled"); | ||
| await fs.writeFile(disabledMarkerPath, ""); | ||
| } catch (e) { | ||
| const name = `Failed to disable ${args.mod.getName()}`; | ||
| const solution = "Is the game still running?"; | ||
| throw FileWriteError.fromThrownValue(e, name, solution); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/r2mm/launching/instructions/instructions/loader/GDPatchGameInstructions.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import GameInstructionGenerator from '../GameInstructionGenerator'; | ||
| import { GameInstruction } from '../../GameInstructions'; | ||
| import Game from '../../../../../model/game/Game'; | ||
| import Profile from '../../../../../model/Profile'; | ||
| import { DynamicGameInstruction } from '../../DynamicGameInstruction'; | ||
|
|
||
| export default class GDPatchGameInstructions extends GameInstructionGenerator { | ||
| public async generate(game: Game, profile: Profile): Promise<GameInstruction> { | ||
| return { | ||
| moddedParameterList: [`--gdpatch-root-directory=${DynamicGameInstruction.GDPATCH_FOLDER}`], | ||
| vanillaParameterList: ["--gdpatch-disable"] | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.