Skip to content

Commit 22f88eb

Browse files
committed
Fix CyberpunkModDataChecker not accepting extra files
1 parent cf2a700 commit 22f88eb

1 file changed

Lines changed: 30 additions & 64 deletions

File tree

games/game_cyberpunk2077.py

Lines changed: 30 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class CyberpunkModDataChecker(BasicModDataChecker):
2424
def __init__(self):
2525
super().__init__(
2626
GlobPatterns(
27+
move={
28+
# archive and ArchiveXL
29+
"*.archive": "archive/pc/mod/",
30+
"*.xl": "archive/pc/mod/",
31+
},
2732
valid=[
2833
"archive",
2934
# redscript
@@ -34,11 +39,6 @@ def __init__(self):
3439
"bin", # CET etc. gets handled below
3540
"root", # RootBuilder: hardlink / copy to game root
3641
],
37-
move={
38-
# archive and ArchiveXL
39-
"*.archive": "archive/pc/mod/",
40-
"*.xl": "archive/pc/mod/",
41-
},
4242
)
4343
)
4444

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

5956
def dataLooksValid(
@@ -63,69 +60,37 @@ def dataLooksValid(
6360
parent = filetree.parent()
6461
if parent is not None and self.dataLooksValid(parent) is self.FIXABLE:
6562
return self.FIXABLE
66-
if (status := super().dataLooksValid(filetree)) is self.INVALID:
67-
# Archive with REDmod folders, not in mods/
68-
if all(self._valid_redmod(e) for e in filetree):
69-
return self.CheckReturn.FIXABLE
70-
else:
71-
match self._check_bin_folder(filetree):
72-
case self.INVALID:
73-
return self.INVALID
74-
case self.FIXABLE:
75-
status = self.FIXABLE
76-
case _:
77-
pass # valid = keep status
78-
# Check extra fixes
79-
if any(filetree.exists(p) for p in self._extra_files_to_move):
80-
status = self.FIXABLE
63+
status = mobase.ModDataChecker.INVALID
64+
# Check extra fixes
65+
if any(filetree.exists(p) for p in self._extra_files_to_move):
66+
return mobase.ModDataChecker.FIXABLE
67+
rp = self._regex_patterns
68+
for entry in filetree:
69+
name = entry.name().casefold()
70+
if rp.move_match(name) is not None:
71+
status = mobase.ModDataChecker.FIXABLE
72+
elif rp.valid.match(name):
73+
if status is mobase.ModDataChecker.INVALID:
74+
status = mobase.ModDataChecker.VALID
75+
elif self._valid_redmod(entry):
76+
# Archive with REDmod folders, not in mods/
77+
status = mobase.ModDataChecker.FIXABLE
78+
# Accept any other entry
8179
return status
8280

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

88-
def _check_bin_folder(
89-
self, filetree: mobase.IFileTree
90-
) -> mobase.ModDataChecker.CheckReturn:
91-
"""Only Red4ext and CET are supported in bin folder."""
92-
bin_folder = filetree.find("bin/x64")
93-
if not bin_folder:
94-
return self.VALID
95-
elif not is_directory(bin_folder):
96-
return self.INVALID
97-
status = self.VALID
98-
cet_path = self._cet_path.rstrip("/\\")
99-
for entry in bin_folder:
100-
entry_name = entry.name()
101-
if self._ignore_pattern.match(entry_name):
102-
continue
103-
elif f"bin/x64/{entry_name}" in self._extra_files_to_move:
104-
status = self.FIXABLE
105-
elif entry_name == "plugins" and is_directory(entry):
106-
for plugin in entry:
107-
plugin_path = f"bin/x64/plugins/{plugin.name()}"
108-
if plugin_path == cet_path:
109-
if not is_directory(plugin):
110-
return self.INVALID
111-
if not (len(plugin) == 1 and plugin.exists("mods")):
112-
status = self.FIXABLE # CET framework: fix
113-
elif plugin_path in self._extra_files_to_move:
114-
status = self.FIXABLE
115-
else:
116-
return self.INVALID # unknown plugin
117-
else:
118-
return self.INVALID # unknown entry
119-
return status
120-
12186
def fix(self, filetree: mobase.IFileTree) -> mobase.IFileTree:
87+
for source, target in self._extra_files_to_move.items():
88+
if file := filetree.find(source):
89+
parent = file.parent()
90+
filetree.move(file, target)
91+
clear_empty_folder(parent)
12292
if filetree := super().fix(filetree):
123-
for source, target in self._extra_files_to_move.items():
124-
if file := filetree.find(source):
125-
parent = file.parent()
126-
filetree.move(file, target)
127-
clear_empty_folder(parent)
128-
self._fix_cet_framework(filetree)
93+
filetree = self._fix_cet_framework(filetree)
12994
# REDmod
13095
for entry in list(filetree):
13196
if not self._regex_patterns.valid.match(
@@ -134,7 +99,7 @@ def fix(self, filetree: mobase.IFileTree) -> mobase.IFileTree:
13499
filetree.move(entry, "mods/")
135100
return filetree
136101

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

158124

159125
def clear_empty_folder(filetree: mobase.IFileTree | None):
@@ -314,7 +280,7 @@ def apply(self) -> bool:
314280
class Cyberpunk2077Game(BasicGame):
315281
Name = "Cyberpunk 2077 Support Plugin"
316282
Author = "6788, Zash"
317-
Version = "2.2.1"
283+
Version = "2.2.2"
318284

319285
GameName = "Cyberpunk 2077"
320286
GameShortName = "cyberpunk2077"

0 commit comments

Comments
 (0)