Skip to content

Commit

Permalink
Merge pull request #124 from ZashIn/cyberpunk
Browse files Browse the repository at this point in the history
Fix CyberpunkModDataChecker not accepting extra files
  • Loading branch information
Silarn authored Oct 18, 2023
2 parents cf2a700 + 22f88eb commit b99c053
Showing 1 changed file with 30 additions and 64 deletions.
94 changes: 30 additions & 64 deletions games/game_cyberpunk2077.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class CyberpunkModDataChecker(BasicModDataChecker):
def __init__(self):
super().__init__(
GlobPatterns(
move={
# archive and ArchiveXL
"*.archive": "archive/pc/mod/",
"*.xl": "archive/pc/mod/",
},
valid=[
"archive",
# redscript
Expand All @@ -34,11 +39,6 @@ def __init__(self):
"bin", # CET etc. gets handled below
"root", # RootBuilder: hardlink / copy to game root
],
move={
# archive and ArchiveXL
"*.archive": "archive/pc/mod/",
"*.xl": "archive/pc/mod/",
},
)
)

Expand All @@ -51,9 +51,6 @@ def __init__(self):
"bin/x64/global.ini": "root/bin/x64/",
"bin/x64/plugins/cyber_engine_tweaks.asi": "root/bin/x64/plugins/",
}
"""Some frameworks need to be copied or hard linked to root. Use / as sep!"""
_ignore_pattern = re.compile(r"licenses?$", re.I)

_cet_path = "bin/x64/plugins/cyber_engine_tweaks/"

def dataLooksValid(
Expand All @@ -63,69 +60,37 @@ def dataLooksValid(
parent = filetree.parent()
if parent is not None and self.dataLooksValid(parent) is self.FIXABLE:
return self.FIXABLE
if (status := super().dataLooksValid(filetree)) is self.INVALID:
# Archive with REDmod folders, not in mods/
if all(self._valid_redmod(e) for e in filetree):
return self.CheckReturn.FIXABLE
else:
match self._check_bin_folder(filetree):
case self.INVALID:
return self.INVALID
case self.FIXABLE:
status = self.FIXABLE
case _:
pass # valid = keep status
# Check extra fixes
if any(filetree.exists(p) for p in self._extra_files_to_move):
status = self.FIXABLE
status = mobase.ModDataChecker.INVALID
# Check extra fixes
if any(filetree.exists(p) for p in self._extra_files_to_move):
return mobase.ModDataChecker.FIXABLE
rp = self._regex_patterns
for entry in filetree:
name = entry.name().casefold()
if rp.move_match(name) is not None:
status = mobase.ModDataChecker.FIXABLE
elif rp.valid.match(name):
if status is mobase.ModDataChecker.INVALID:
status = mobase.ModDataChecker.VALID
elif self._valid_redmod(entry):
# Archive with REDmod folders, not in mods/
status = mobase.ModDataChecker.FIXABLE
# Accept any other entry
return status

def _valid_redmod(self, filetree: mobase.IFileTree | mobase.FileTreeEntry) -> bool:
return isinstance(filetree, mobase.IFileTree) and bool(
filetree and filetree.find("info.json")
)

def _check_bin_folder(
self, filetree: mobase.IFileTree
) -> mobase.ModDataChecker.CheckReturn:
"""Only Red4ext and CET are supported in bin folder."""
bin_folder = filetree.find("bin/x64")
if not bin_folder:
return self.VALID
elif not is_directory(bin_folder):
return self.INVALID
status = self.VALID
cet_path = self._cet_path.rstrip("/\\")
for entry in bin_folder:
entry_name = entry.name()
if self._ignore_pattern.match(entry_name):
continue
elif f"bin/x64/{entry_name}" in self._extra_files_to_move:
status = self.FIXABLE
elif entry_name == "plugins" and is_directory(entry):
for plugin in entry:
plugin_path = f"bin/x64/plugins/{plugin.name()}"
if plugin_path == cet_path:
if not is_directory(plugin):
return self.INVALID
if not (len(plugin) == 1 and plugin.exists("mods")):
status = self.FIXABLE # CET framework: fix
elif plugin_path in self._extra_files_to_move:
status = self.FIXABLE
else:
return self.INVALID # unknown plugin
else:
return self.INVALID # unknown entry
return status

def fix(self, filetree: mobase.IFileTree) -> mobase.IFileTree:
for source, target in self._extra_files_to_move.items():
if file := filetree.find(source):
parent = file.parent()
filetree.move(file, target)
clear_empty_folder(parent)
if filetree := super().fix(filetree):
for source, target in self._extra_files_to_move.items():
if file := filetree.find(source):
parent = file.parent()
filetree.move(file, target)
clear_empty_folder(parent)
self._fix_cet_framework(filetree)
filetree = self._fix_cet_framework(filetree)
# REDmod
for entry in list(filetree):
if not self._regex_patterns.valid.match(
Expand All @@ -134,7 +99,7 @@ def fix(self, filetree: mobase.IFileTree) -> mobase.IFileTree:
filetree.move(entry, "mods/")
return filetree

def _fix_cet_framework(self, filetree: mobase.IFileTree):
def _fix_cet_framework(self, filetree: mobase.IFileTree) -> mobase.IFileTree:
"""Move CET framework to `root/`, except for `mods`.
Only CET >= v1.27.0 (Patch 2.01) works with USVFS.
Expand All @@ -154,6 +119,7 @@ def _fix_cet_framework(self, filetree: mobase.IFileTree):
if entry.name() != "mods":
filetree.move(entry, root_cet_path)
clear_empty_folder(parent)
return filetree


def clear_empty_folder(filetree: mobase.IFileTree | None):
Expand Down Expand Up @@ -314,7 +280,7 @@ def apply(self) -> bool:
class Cyberpunk2077Game(BasicGame):
Name = "Cyberpunk 2077 Support Plugin"
Author = "6788, Zash"
Version = "2.2.1"
Version = "2.2.2"

GameName = "Cyberpunk 2077"
GameShortName = "cyberpunk2077"
Expand Down

0 comments on commit b99c053

Please sign in to comment.