From 419d9fde321dd54eda601e90b0cc80fd9976ac72 Mon Sep 17 00:00:00 2001 From: The Conceptionist Date: Fri, 4 Mar 2022 06:22:35 -0600 Subject: [PATCH] Update game_masterduel.py Updated to add support for AssetBundle mods. --- games/game_masterduel.py | 65 +++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/games/game_masterduel.py b/games/game_masterduel.py index ca64090..5c65679 100644 --- a/games/game_masterduel.py +++ b/games/game_masterduel.py @@ -1,18 +1,19 @@ # -*- encoding: utf-8 -*- from PyQt5.QtCore import QFileInfo, QDir +from typing import List, Optional, cast +from os.path import join, exists import mobase from ..basic_game import BasicGame - -class MasterDuelGame(BasicGame): +class MasterDuelGame(BasicGame, mobase.IPluginFileMapper): Name = "Yu-Gi-Oh! Master Duel Support Plugin" Author = "The Conceptionist & uwx" - Version = "1.0.1" - Description = "Adds support for basic Yu-Gi-Oh! Master Duel mods.\nCurrently does not support any mods that require modifying the masterduel_Data/StreamingAssets folder." + Version = "1.0.2" + Description = "Adds support for basic Yu-Gi-Oh! Master Duel mods.\nEligible folders for mods are \"0000\" and \"AssetBundle\"." GameName = "Yu-Gi-Oh! Master Duel" GameShortName = "masterduel" @@ -21,6 +22,10 @@ class MasterDuelGame(BasicGame): GameSteamId = 1449850 GameBinary = "masterduel.exe" + def __init__(self): + BasicGame.__init__(self) + mobase.IPluginFileMapper.__init__(self) + def executables(self): return [ mobase.ExecutableInfo( @@ -28,8 +33,52 @@ class MasterDuelGame(BasicGame): QFileInfo(self.gameDirectory().absoluteFilePath(self.binaryName())), ).withArgument("-popupwindow"), ] - + + # dataDirectory returns the specific LocalData folder because this is where most mods will go to def dataDirectory(self) -> QDir: - localData = QDir(self.gameDirectory().absoluteFilePath('LocalData')) - subdirs = localData.entryList(filters=(QDir.Dirs | QDir.NoDotAndDotDot)) - return QDir(QDir.toNativeSeparators(localData.absoluteFilePath(subdirs[0]) + '/0000')) \ No newline at end of file + return QDir(self.userDataDir()) + + _userDataDirCached: Optional[str] = None + + # Gets the LocalData/xxxxxxxxx directory. This directory has a different, unique, 8-character hex name for each + # user. + def userDataDir(self) -> str: + if self._userDataDirCached is not None: + return self._userDataDirCached + + dir = self.gameDirectory() + dir.cd('LocalData') + + subdirs = dir.entryList(filters=cast(QDir.Filters, QDir.Dirs | QDir.NoDotAndDotDot)) + dir.cd(subdirs[0]) + + self._userDataDirCached = dir.absolutePath() + return self._userDataDirCached + + def mappings(self) -> List[mobase.Mapping]: + modsPath = self._organizer.modsPath() + unityMods = self.getUnityDataMods() + + mappings: List[mobase.Mapping] = [] + + for modName in unityMods: + m = mobase.Mapping() + m.createTarget = False + m.isDirectory = True + m.source = join(modsPath, modName, "AssetBundle") + m.destination = self.gameDirectory().filePath(join("masterduel_Data", "StreamingAssets", "AssetBundle")) + mappings.append(m) + + return mappings + + def getUnityDataMods(self): + modsPath = self._organizer.modsPath() + allMods = self._organizer.modList().allModsByProfilePriority() + + unityMods = [] + for modName in allMods: + if self._organizer.modList().state(modName) & mobase.ModState.ACTIVE != 0: + if exists(join(modsPath, modName, "AssetBundle")): + unityMods.append(modName) + + return unityMods