From 07ba3ff2c11e9d1a487d9bddabec95a3893bc507 Mon Sep 17 00:00:00 2001 From: Steven Franklin Date: Sat, 27 Jul 2024 04:53:21 -0500 Subject: [PATCH] BPSI (pack set?) - implemented parse/build for bpsi on dread and SR --- README.md | 2 +- .../formats/__init__.py | 2 ++ .../formats/bpsi.py | 25 +++++++++++++++++++ tests/formats/test_bpsi.py | 14 +++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/mercury_engine_data_structures/formats/bpsi.py create mode 100644 tests/formats/test_bpsi.py diff --git a/README.md b/README.md index 65e66a14..73274802 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Construct type definitions for Mercury Engine | BMTRE | ✗ | ✗ | ✓ | ✓ | | BMTUN | ✓ | ✓ | Missing | Missing | | BNVIB | Missing | Missing | ✓ | ✓ | -| BPSI | ✗ | ✗ | ✗ | ✗ | +| BPSI | ✓ | ✓ | ✓ | ✓ | | BPTDAT | Missing | Missing | ✗ | ✗ | | BPTDEF | Missing | Missing | ✗ | ✗ | | BREM | Missing | Missing | ✓ | ✓ | diff --git a/src/mercury_engine_data_structures/formats/__init__.py b/src/mercury_engine_data_structures/formats/__init__.py index e7ac1a9f..69a072fb 100644 --- a/src/mercury_engine_data_structures/formats/__init__.py +++ b/src/mercury_engine_data_structures/formats/__init__.py @@ -31,6 +31,7 @@ from mercury_engine_data_structures.formats.bmtre import Bmtre from mercury_engine_data_structures.formats.bmtun import Bmtun from mercury_engine_data_structures.formats.bnvib import Bnvib +from mercury_engine_data_structures.formats.bpsi import Bpsi from mercury_engine_data_structures.formats.brem import Brem from mercury_engine_data_structures.formats.bres import Bres from mercury_engine_data_structures.formats.brev import Brev @@ -80,6 +81,7 @@ "BMSLGROUP": Bmslgroup, "BMSLINK": Bmslink, "BMSMD": Bmsmd, + "BPSI": Bpsi, "BMTRE": Bmtre, "BNVIB": Bnvib, "BRSA": Brsa, diff --git a/src/mercury_engine_data_structures/formats/bpsi.py b/src/mercury_engine_data_structures/formats/bpsi.py new file mode 100644 index 00000000..06adf11f --- /dev/null +++ b/src/mercury_engine_data_structures/formats/bpsi.py @@ -0,0 +1,25 @@ +from construct.core import Const, Construct, IfThenElse, Int32ul, PrefixedArray, Struct, Terminated + +from mercury_engine_data_structures import game_check +from mercury_engine_data_structures.common_types import VersionAdapter +from mercury_engine_data_structures.construct_extensions.strings import PascalStringRobust +from mercury_engine_data_structures.formats.base_resource import BaseResource + +BPSI = Struct( + _magic = Const(b"MPSI"), + version = IfThenElse( + game_check.current_game_at_most(game_check.Game.SAMUS_RETURNS), + VersionAdapter("1.2.0"), + VersionAdapter("1.3.0") + ), + files = PrefixedArray(Int32ul, Struct( + file = PascalStringRobust(Int32ul, "utf-8"), + in_packages = PrefixedArray(Int32ul, PascalStringRobust(Int32ul, "utf-8")) + )), + _eof=Terminated +) + +class Bpsi(BaseResource): + @classmethod + def construct_class(cls, target_game: game_check.Game) -> Construct: + return BPSI diff --git a/tests/formats/test_bpsi.py b/tests/formats/test_bpsi.py new file mode 100644 index 00000000..2facd042 --- /dev/null +++ b/tests/formats/test_bpsi.py @@ -0,0 +1,14 @@ +import pytest +from tests.test_lib import parse_build_compare_editor + +from mercury_engine_data_structures import dread_data, samus_returns_data +from mercury_engine_data_structures.formats.bpsi import Bpsi + + +@pytest.mark.parametrize("bpsi_path", dread_data.all_files_ending_with(".bpsi")) +def test_bmtre_dread(dread_file_tree, bpsi_path): + parse_build_compare_editor(Bpsi, dread_file_tree, bpsi_path) + +@pytest.mark.parametrize("bpsi_path", samus_returns_data.all_files_ending_with(".bpsi")) +def test_bmtre_sr(dread_file_tree, bpsi_path): + parse_build_compare_editor(Bpsi, dread_file_tree, bpsi_path)