Skip to content

stalker 2 support with a pak tab #185

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
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d78cf05
stalker 2 support with a pak tab
MK-HATERS Jun 22, 2025
ab91432
[pre-commit.ci] Auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] Jun 22, 2025
109daf6
updated some comments and redudencies
MK-HATERS Jun 22, 2025
79e10f4
updated some comments and adjusted redundencies
MK-HATERS Jun 22, 2025
d24e955
[pre-commit.ci] Auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] Jun 22, 2025
060b3ff
fixing lint for stalker 2 pak tab game support
MK-HATERS Jun 22, 2025
3730421
Merge branch 'master' of https://github.com/MK-HATERS/modorganizer-ba…
MK-HATERS Jun 22, 2025
6008acb
[pre-commit.ci] Auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] Jun 22, 2025
e980eea
Update game_stalker2heartofchornobyl.py
MK-HATERS Jun 22, 2025
2bb45d2
Merge branch 'master' of https://github.com/MK-HATERS/modorganizer-ba…
MK-HATERS Jun 22, 2025
8c68398
lint adjustments s2hoc pak tab
MK-HATERS Jun 22, 2025
358924f
[pre-commit.ci] Auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] Jun 22, 2025
2e357d6
adjusted widget for s2hoc pak tab game support
MK-HATERS Jun 22, 2025
5ab9cc8
[pre-commit.ci] Auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] Jun 22, 2025
cf91ef3
Update game_stalker2heartofchornobyl.py
MK-HATERS Jun 22, 2025
1f2a02f
Merge branch 'master' of https://github.com/MK-HATERS/modorganizer-ba…
MK-HATERS Jun 22, 2025
1b1f066
Update game_stalker2heartofchornobyl.py
MK-HATERS Jun 22, 2025
baad9af
Update game_stalker2heartofchornobyl.py
MK-HATERS Jun 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 271 additions & 0 deletions games/game_stalker2heartofchornobyl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
import os
from enum import IntEnum, auto

from PyQt6.QtCore import QDir
from PyQt6.QtWidgets import QMainWindow, QTabWidget, QWidget

import mobase

from ..basic_features import BasicLocalSavegames, BasicModDataChecker, GlobPatterns
from ..basic_game import BasicGame


class Problems(IntEnum):
"""
Enums for IPluginDiagnose.
"""

MISPLACED_PAK_FILES = auto()
MISSING_MOD_DIRECTORIES = auto()


class S2HoCGame(BasicGame, mobase.IPluginFileMapper, mobase.IPluginDiagnose):
Name = "Stalker 2: Heart of Chornobyl Plugin"
Author = "MkHaters"
Version = "1.1.0"

GameName = "Stalker 2: Heart of Chornobyl"
GameShortName = "stalker2heartofchornobyl"
GameNexusName = "stalker2heartofchornobyl"
GameDocumentsDirectory = "%USERPROFILE%/AppData/Local/Stalker2"
GameSavesDirectory = "%GAME_DOCUMENTS%/Saved/Steam/SaveGames/Data"
GameSaveExtension = "sav"
GameNexusId = 6944
GameSteamId = 1643320
GameGogId = 1529799785
GameBinary = "Stalker2.exe"
GameDataPath = "Stalker2"
GameIniFiles = [
"%GAME_DOCUMENTS%/Saved/Config/Windows/Game.ini",
"%GAME_DOCUMENTS%/Saved/Config/Windows/GameUserSettings.ini",
"%GAME_DOCUMENTS%/Saved/Config/Windows/Engine.ini",
]

_main_window: QMainWindow
_paks_tab: QWidget

def __init__(self):
BasicGame.__init__(self)
mobase.IPluginFileMapper.__init__(self)
mobase.IPluginDiagnose.__init__(self)

def resolve_path(self, path: str) -> str:
path = path.replace("%USERPROFILE%", os.environ.get("USERPROFILE", ""))

if "%GAME_DOCUMENTS%" in path:
game_docs = self.GameDocumentsDirectory.replace(
"%USERPROFILE%", os.environ.get("USERPROFILE", "")
)
path = path.replace("%GAME_DOCUMENTS%", game_docs)

if "%GAME_PATH%" in path:
game_path = self._gamePath if hasattr(self, "_gamePath") else ""
path = path.replace("%GAME_PATH%", game_path)

return path

def init(self, organizer: mobase.IOrganizer) -> bool:
super().init(organizer)
self._register_feature(S2HoCModDataChecker())
self._register_feature(
BasicLocalSavegames(QDir(self.resolve_path(self.GameSavesDirectory)))
)

if (
self._organizer.managedGame()
and self._organizer.managedGame().gameName() == self.gameName()
):
mod_path = self.paksModsDirectory().absolutePath()
try:
os.makedirs(mod_path, exist_ok=True)
if not os.path.exists(mod_path):
print(f"Failed to create directory: {mod_path}")
except OSError as e:
print(f"OS error creating mod directory: {e}")
except Exception as e:
print(f"Unexpected error creating mod directory: {e}")

organizer.onUserInterfaceInitialized(self.init_tab)
return True

def init_tab(self, main_window: QMainWindow):
"""
Initializes the PAK management tab for Stalker 2.
"""
try:
if self._organizer.managedGame() != self:
return

self._main_window = main_window
tab_widget: QTabWidget = main_window.findChild(QTabWidget, "tabWidget")
if not tab_widget:
print("No main tab widget found!")
return

from .stalker2heartofchornobyl.paks import S2HoCPaksTabWidget

self._paks_tab = S2HoCPaksTabWidget(main_window, self._organizer)

tab_widget.addTab(self._paks_tab, "PAK Files")
print("PAK Files tab added!")
except ImportError as e:
print(f"Failed to import PAK tab widget: {e}")
except Exception as e:
print(f"Error initializing PAK tab: {e}")
import traceback

traceback.print_exc()

def mappings(self) -> list[mobase.Mapping]:
pak_extensions = ["*.pak", "*.utoc", "*.ucas"]
target_dir = "Content/Paks/~mods/"

mappings = []

for ext in pak_extensions:
mappings.append(mobase.Mapping(ext, target_dir, False))

source_dirs = ["Paks/", "~mods/", "Content/Paks/~mods/"]
for source_dir in source_dirs:
for ext in pak_extensions:
mappings.append(mobase.Mapping(f"{source_dir}{ext}", target_dir, False))

return mappings

def gameDirectory(self) -> QDir:
return QDir(self._gamePath)

def paksDirectory(self) -> QDir:
path = os.path.join(
self.gameDirectory().absolutePath(), self.GameDataPath, "Content", "Paks"
)
return QDir(path)

def paksModsDirectory(self) -> QDir:
try:
path = os.path.join(self.paksDirectory().absolutePath(), "~mods")
return QDir(path)
except Exception:
fallback = os.path.join(
self.gameDirectory().absolutePath(),
self.GameDataPath,
"Content",
"Paks",
"~mods",
)
return QDir(fallback)

def logicModsDirectory(self) -> QDir:
path = os.path.join(
self.gameDirectory().absolutePath(),
self.GameDataPath,
"Content",
"Paks",
"LogicMods",
)
return QDir(path)

def binariesDirectory(self) -> QDir:
path = os.path.join(
self.gameDirectory().absolutePath(),
self.GameDataPath,
"Binaries",
"Win64",
)
return QDir(path)

def getModMappings(self) -> dict[str, list[str]]:
return {
"Content/Paks/~mods": [self.paksModsDirectory().absolutePath()],
}

def activeProblems(self) -> list[int]:
problems = set()
if self._organizer.managedGame() == self:
mod_path = self.paksModsDirectory().absolutePath()
if not os.path.isdir(mod_path):
problems.add(Problems.MISSING_MOD_DIRECTORIES)
print(f"Missing mod directory: {mod_path}")

for mod in self._organizer.modList().allMods():
mod_info = self._organizer.modList().getMod(mod)
filetree = mod_info.fileTree()

for entry in filetree:
if entry.name().endswith((".pak", ".utoc", ".ucas")) and not any(
entry.path().startswith(p)
for p in ["Content/Paks/~mods", "Paks", "~mods"]
):
problems.add(Problems.MISPLACED_PAK_FILES)
break

return list(problems)

def fullDescription(self, key: int) -> str:
match key:
case Problems.MISPLACED_PAK_FILES:
return (
"Some mod packages contain PAK files that are not placed in "
"the correct directory structure.\n\n"
"PAK files should be placed in one of the following "
"locations within the mod:\n"
"- Content/Paks/~mods/\n"
"- Paks/\n"
"- ~mods/\n\n"
"Please restructure your mods to follow this directory "
"layout."
)
case Problems.MISSING_MOD_DIRECTORIES:
return (
"Required mod directory is missing in the game folder.\n\n"
"The following directory should exist:\n"
"- Stalker2/Content/Paks/~mods\n\n"
"This will be created automatically when you restart "
"Mod Organizer 2."
)
case _:
return ""

def hasGuidedFix(self, key: int) -> bool:
match key:
case Problems.MISSING_MOD_DIRECTORIES:
return True
case _:
return False

def shortDescription(self, key: int) -> str:
match key:
case Problems.MISPLACED_PAK_FILES:
return "Some mods have PAK files in incorrect locations."
case Problems.MISSING_MOD_DIRECTORIES:
return "Required mod directories are missing."
case _:
return ""

def startGuidedFix(self, key: int) -> None:
match key:
case Problems.MISSING_MOD_DIRECTORIES:
try:
os.makedirs(self.paksModsDirectory().absolutePath(), exist_ok=True)
print("Created missing mod directories")
except Exception as e:
print(f"Failed to create mod directories: {e}")
case _:
pass


class S2HoCModDataChecker(BasicModDataChecker):
def __init__(self, patterns: GlobPatterns = GlobPatterns()):
move_patterns = {
"*.pak": "Content/Paks/~mods/",
"*.utoc": "Content/Paks/~mods/",
"*.ucas": "Content/Paks/~mods/",
}
valid_roots = ["Content", "Paks", "~mods"]
base_patterns = GlobPatterns(valid=valid_roots, move=move_patterns)
merged_patterns = base_patterns.merge(patterns)
super().__init__(merged_patterns)


def createPlugin():
return S2HoCGame()
3 changes: 3 additions & 0 deletions games/stalker2heartofchornobyl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .paks import S2HoCPaksModel, S2HoCPaksTabWidget, S2HoCPaksView

__all__ = ["S2HoCPaksTabWidget", "S2HoCPaksModel", "S2HoCPaksView"]
5 changes: 5 additions & 0 deletions games/stalker2heartofchornobyl/paks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .model import S2HoCPaksModel
from .view import S2HoCPaksView
from .widget import S2HoCPaksTabWidget

__all__ = ["S2HoCPaksTabWidget", "S2HoCPaksModel", "S2HoCPaksView"]
Loading
Loading