From 287ad08481b620fb6a033bc206cc624bff3c1981 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:05:23 +0200 Subject: [PATCH 01/84] Model selectable PAC appearance slot sets --- .../dmcresource/motion/part_attachment.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index 9ccfacc2..d51477ee 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -275,6 +275,11 @@ inline constexpr std::array kEm000Variants{{ // (em028.pac: the dress strip, objects 2-3 of slot 5, is drawn only while // bats are out -- 0x14012F790 sets or clears object bit 0, which the MOD draw // loops 0x140303460 / 0x140303DE0 require). +struct ArchiveTextureOverride final { + std::uint32_t model_slot{}; + std::uint32_t texture_slot{}; +}; + struct ArchiveVariant final { std::string label; const EnemyVariant* enemy{}; // em000 family @@ -282,6 +287,18 @@ struct ArchiveVariant final { std::uint32_t hide_slot{}; // model slot whose objects are hidden std::array hide_objects{}; std::uint32_t hide_count{}; + + // Some actor PACs carry several complete appearances and equipment models + // in one top-level archive. When non-zero, only these top-level MOD slots + // belong to this selectable appearance; every other MOD remains available + // as a PAC child instead of being incorrectly overlaid at the actor origin. + std::array include_top_level_mod_slots{}; + std::uint32_t include_top_level_mod_count{}; + + // Explicit companion PTX association for appearance parts whose correct + // texture bank is not the nearest preceding PTX in physical slot order. + std::array texture_overrides{}; + std::uint32_t texture_override_count{}; }; [[nodiscard]] std::vector archive_variants(std::string_view archive_name); From 501c4bb7907ca54f6ac184ccbe1e1d15d9f2cce1 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:05:47 +0200 Subject: [PATCH 02/84] Split em034 Lady appearance sets --- .../cpp/modules/motion/part_attachment.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/src/main/cpp/modules/motion/part_attachment.cpp b/app/src/main/cpp/modules/motion/part_attachment.cpp index 1f8bfe22..9a48f17d 100644 --- a/app/src/main/cpp/modules/motion/part_attachment.cpp +++ b/app/src/main/cpp/modules/motion/part_attachment.cpp @@ -677,6 +677,7 @@ std::vector archive_variants(std::string_view archive_name) { if (!out.empty()) return out; const auto slash = archive_name.find_last_of("/\\"); if (slash != std::string_view::npos) archive_name.remove_prefix(slash + 1U); + constexpr std::string_view nevan = "em028.pac"; bool is_nevan = archive_name.size() == nevan.size(); for (std::size_t i = 0U; is_nevan && i < nevan.size(); ++i) { @@ -692,6 +693,39 @@ std::vector archive_variants(std::string_view archive_name) { ArchiveVariant swarm; swarm.label = "Bats out"; out.push_back(swarm); + return out; + } + + // em034.pac (Lady) contains two complete appearance sets plus a separate + // group of equipment/weapon MODs. Corpus evidence from the retail PAC: + // slots 1 + 17 -> MOD header +0x14 = 0x00000384 + // slots 32 + 34 -> MOD header +0x14 = 0x0000063D + // slots 20..26 + 30 -> +0x14 = 0x000AF258 (equipment group) + // Both appearance pairs also share the same transform/texture-domain + // shape (23+9 nodes, two texture slots). Keeping all twelve MODs in one + // composite is therefore structurally wrong and visibly overlays both + // costumes while dropping equipment at source origin. + constexpr std::string_view lady = "em034.pac"; + bool is_lady = archive_name.size() == lady.size(); + for (std::size_t i = 0U; is_lady && i < lady.size(); ++i) { + is_lady = std::tolower(static_cast(archive_name[i])) == lady[i]; + } + if (is_lady) { + ArchiveVariant first; + first.label = "Lady · costume 1"; + first.include_top_level_mod_slots = {1U, 17U}; + first.include_top_level_mod_count = 2U; + first.texture_overrides = {{{1U, 0U}, {17U, 0U}}}; + first.texture_override_count = 2U; + out.push_back(first); + + ArchiveVariant second; + second.label = "Lady · costume 2"; + second.include_top_level_mod_slots = {32U, 34U}; + second.include_top_level_mod_count = 2U; + second.texture_overrides = {{{32U, 31U}, {34U, 31U}}}; + second.texture_override_count = 2U; + out.push_back(second); } return out; } From 3d82f10f2275d97416b6585fabc3df4cde1f5c09 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:06:11 +0200 Subject: [PATCH 03/84] Filter PAC MODs by selected appearance --- app/src/main/cpp/modules/pac_assembly.cpp | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index 470754bd..96e949c3 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -284,6 +284,26 @@ std::unique_ptr assemble_archives(std::span archi ++report.effect_models_skipped; continue; } + if (entry.kind.format == Format::Mod && position != nullptr && + position->include_top_level_mod_count != 0U && + entry.archive == 0U && entry.container.empty()) { + bool used = false; + if (entry.slot) { + for (std::uint32_t s = 0U; + s < position->include_top_level_mod_count && + s < position->include_top_level_mod_slots.size(); + ++s) { + used = used || *entry.slot == position->include_top_level_mod_slots[s]; + } + } + if (!used) { + // The MOD is still preserved/browsable as a PAC child. It is + // only excluded from this actor appearance because the + // archive contains mutually exclusive looks/equipment. + ++report.variant_models_skipped; + continue; + } + } if (entry.kind.format == Format::Mod && variant != nullptr && entry.archive == 0U && entry.container.empty()) { // Shared enemy archive: keep only this class's body, cloth and weapon. @@ -303,6 +323,25 @@ std::unique_ptr assemble_archives(std::span archi model_names.push_back(entry.name); model_entry.push_back(index); std::optional texture = texture_for(entries, index); + if (position != nullptr && entry.archive == 0U && + entry.container.empty() && entry.slot) { + for (std::uint32_t o = 0U; + o < position->texture_override_count && + o < position->texture_overrides.size(); + ++o) { + const auto& override = position->texture_overrides[o]; + if (*entry.slot != override.model_slot) continue; + for (std::size_t t = 0U; t < entries.size(); ++t) { + if (entries[t].archive == 0U && entries[t].container.empty() && + entries[t].slot == override.texture_slot && + entries[t].kind.format == Format::Ptx) { + texture = t; + break; + } + } + break; + } + } if (variant != nullptr && variant->texture_slot != motion::kNoEnemySlot && entry.archive == 0U && entry.container.empty() && entry.slot == variant->body_slot) { From 06bfde9de91ce7b51a33152e3bb0ba7356adc2d3 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:06:44 +0200 Subject: [PATCH 04/84] Report selected PAC appearance in inspection --- app/src/main/cpp/modules/pac_assembly.cpp | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index 96e949c3..9e208de4 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -875,6 +875,44 @@ std::unique_ptr assemble_archives(std::span archi if (!assembled->children.empty()) { assembled->capabilities |= capability(ResourceCapability::ChildResources); } + if (position != nullptr) { + assembled->inspection.root.properties.push_back({ + "PACAppearance", position->label, EvidenceLevel::DataConfirmed}); + if (position->include_top_level_mod_count != 0U) { + std::string slots; + for (std::uint32_t i = 0U; + i < position->include_top_level_mod_count && + i < position->include_top_level_mod_slots.size(); + ++i) { + if (!slots.empty()) slots += ","; + slots += std::to_string(position->include_top_level_mod_slots[i]); + } + assembled->inspection.root.properties.push_back({ + "IncludedTopLevelMODSlots", slots, + EvidenceLevel::StructuralConfirmed}); + assembled->inspection.root.properties.push_back({ + "OtherTopLevelMODs", + std::to_string(report.variant_models_skipped) + + " preserved as PAC children; not overlaid in this appearance", + EvidenceLevel::DataConfirmed}); + } + if (position->texture_override_count != 0U) { + std::string overrides; + for (std::uint32_t i = 0U; + i < position->texture_override_count && + i < position->texture_overrides.size(); + ++i) { + if (!overrides.empty()) overrides += ", "; + overrides += "MOD slot" + + std::to_string(position->texture_overrides[i].model_slot) + + "->PTX slot" + + std::to_string(position->texture_overrides[i].texture_slot); + } + assembled->inspection.root.properties.push_back({ + "AppearanceTexturePairing", overrides, + EvidenceLevel::DataConfirmed}); + } + } report.detail = "PAC assembly (read-only): models=" + std::to_string(report.models) + " texturesAttached=" + std::to_string(report.textures_attached) + @@ -888,10 +926,14 @@ std::unique_ptr assemble_archives(std::span archi " attachedParts=" + std::to_string(report.attached_parts) + " effectModelsSkipped=" + std::to_string(report.effect_models_skipped) + (report.enemy_class.empty() ? std::string{} - : " enemyClass=" + report.enemy_class + - " otherClassModelsSkipped=" + + : " archiveVariant=" + report.enemy_class + + " variantModelsSkipped=" + std::to_string(report.variant_models_skipped)) + - " ptxPairing=nearest-preceding-in-container" + report.detail_attachments; + " ptxPairing=" + + (position != nullptr && position->texture_override_count != 0U + ? std::string{"explicit-appearance-override"} + : std::string{"nearest-preceding-in-container"}) + + report.detail_attachments; if (!assembled->detail.empty()) assembled->detail += "\n"; assembled->detail += report.detail; if (!assembled->trace.empty()) assembled->trace += "\n"; From 7bfbf68cb52480a8a3b58c4ae65a1e9b28c02e4f Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:07:03 +0200 Subject: [PATCH 05/84] Regress em034 appearance separation --- app/src/test/native/pac_assembly_test.cpp | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 095d0b92..550686ad 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -267,6 +267,41 @@ int main() { nested_motion.bytes.data(), nested_motion.bytes.size()); assert(both.ok && both.animated_parts == 2U); + // em034.pac carries two mutually-exclusive Lady appearance sets plus + // equipment MODs. The viewer must never overlay all of them at once. + std::vector> lady_payloads(35U); + lady_payloads[1] = mod; + lady_payloads[17] = mod; + lady_payloads[20] = mod; // equipment group: preserved as child, not actor body + lady_payloads[32] = mod; + lady_payloads[34] = mod; + const auto lady_pac = make_pac(lady_payloads); + auto lady = dmcresource::open_session( + "em034.pac", lady_pac.data(), lady_pac.size()); + assert(lady != nullptr); + + const auto lady_variants = dmcresource::motion::archive_variants("em034.pac"); + assert(lady_variants.size() == 2U); + assert(lady_variants[0].label == "Lady · costume 1"); + assert(lady_variants[1].label == "Lady · costume 2"); + + auto lady_first = assembly::assemble_pac(*lady, &report, "em034.pac", 0U); + assert(lady_first != nullptr); + assert(report.models == 2U); + assert(report.variant_models_skipped == 3U); + assert(lady_first->composite_parts.size() == 2U); + assert(lady_first->composite_parts[0].name.find("slot_0001.mod") != std::string::npos); + assert(lady_first->composite_parts[1].name.find("slot_0017.mod") != std::string::npos); + assert(lady_first->inspection.root.properties.back().name == "AppearanceTexturePairing"); + + auto lady_second = assembly::assemble_pac(*lady, &report, "em034.pac", 1U); + assert(lady_second != nullptr); + assert(report.models == 2U); + assert(report.variant_models_skipped == 3U); + assert(lady_second->composite_parts.size() == 2U); + assert(lady_second->composite_parts[0].name.find("slot_0032.mod") != std::string::npos); + assert(lady_second->composite_parts[1].name.find("slot_0034.mod") != std::string::npos); + // An archive without MOD is browsable but has nothing to assemble. const auto motions_only = make_pac({mot}); auto no_model = dmcresource::open_session("mot.pac", motions_only.data(), motions_only.size()); From 94895c4b9615d70fd2aec879e325e09c2eaa8f3b Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:07:34 +0200 Subject: [PATCH 06/84] Fix inspection property assertion --- app/src/test/native/pac_assembly_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 550686ad..fbcd9941 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -292,7 +292,7 @@ int main() { assert(lady_first->composite_parts.size() == 2U); assert(lady_first->composite_parts[0].name.find("slot_0001.mod") != std::string::npos); assert(lady_first->composite_parts[1].name.find("slot_0017.mod") != std::string::npos); - assert(lady_first->inspection.root.properties.back().name == "AppearanceTexturePairing"); + assert(lady_first->inspection.root.properties.back().key == "AppearanceTexturePairing"); auto lady_second = assembly::assemble_pac(*lady, &report, "em034.pac", 1U); assert(lady_second != nullptr); From 0b35cb9f6667bf5f86d647689ae86983fe2644d9 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:08:33 +0200 Subject: [PATCH 07/84] Export inspection reports from Info dialog --- .../dmcrengine/nativeviewer/MainActivity.java | 156 +++++++++++++++++- 1 file changed, 154 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java b/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java index feeac965..2b858435 100644 --- a/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java +++ b/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java @@ -34,6 +34,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Locale; @@ -46,6 +47,7 @@ public final class MainActivity extends Activity { private static final int REQUEST_ADD_MOD_PARTS = 1005; private static final int REQUEST_ADD_PAC = 1011; private static final int REQUEST_ROOM = 1012; + private static final int REQUEST_EXPORT_INFO = 1013; private static final String PREFS = "viewer"; private static final String PREF_ROOM_NAME = "room.name"; private static final String PREF_ROOM_SHOWN = "room.shown"; @@ -144,6 +146,7 @@ private static final class StagedAsset { private BlackWidowState blackWidowState = BlackWidowState.empty(); private String infoText = ""; + private String pendingInfoExportText = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -1331,8 +1334,12 @@ private void showInfoDialog() { } private void showInfoDialog(String text) { + final String snapshot = text == null || text.isEmpty() + ? "No resource information available." + : text; + TextView details = new TextView(this); - details.setText(text == null || text.isEmpty() ? "No resource information available." : text); + details.setText(snapshot); details.setTextColor(Color.WHITE); details.setTextSize(13f); details.setTypeface(Typeface.MONOSPACE); @@ -1345,13 +1352,149 @@ private void showInfoDialog(String text) { ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.WRAP_CONTENT)); + LinearLayout dialogTitle = new LinearLayout(this); + dialogTitle.setOrientation(LinearLayout.HORIZONTAL); + dialogTitle.setGravity(Gravity.CENTER_VERTICAL); + dialogTitle.setPadding(dp(16), dp(6), dp(8), dp(6)); + dialogTitle.setBackgroundColor(0xff3a3a3e); + + TextView heading = new TextView(this); + heading.setText(titleView.getText()); + heading.setTextColor(Color.WHITE); + heading.setTextSize(18f); + heading.setSingleLine(true); + heading.setEllipsize(TextUtils.TruncateAt.END); + dialogTitle.addView(heading, new LinearLayout.LayoutParams( + 0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); + + Button download = makeSquareButton("\u21e9", "Download inspection report", 24f); + download.setOnClickListener(v -> chooseInfoExport(snapshot)); + dialogTitle.addView(download, new LinearLayout.LayoutParams(dp(48), dp(48))); + new AlertDialog.Builder(this) - .setTitle(titleView.getText()) + .setCustomTitle(dialogTitle) .setView(scroll) .setPositiveButton("Close", null) .show(); } + private void chooseInfoExport(String snapshot) { + final String[] choices = { + "Markdown (.md)", + "DMC download snapshot (.download)", + "Plain text (.txt)", + "JSON (.json)" + }; + new AlertDialog.Builder(this) + .setTitle("Download info") + .setItems(choices, (dialog, which) -> launchInfoExport(snapshot, which)) + .setNegativeButton(android.R.string.cancel, null) + .show(); + } + + private void launchInfoExport(String snapshot, int format) { + final String extension; + final String mime; + switch (format) { + case 0: + extension = "md"; + mime = "text/markdown"; + break; + case 1: + extension = "download"; + mime = "application/octet-stream"; + break; + case 2: + extension = "txt"; + mime = "text/plain"; + break; + case 3: + extension = "json"; + mime = "application/json"; + break; + default: + return; + } + + pendingInfoExportText = formatInfoExport(snapshot, format); + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType(mime); + intent.putExtra(Intent.EXTRA_TITLE, infoExportFileName(extension)); + startActivityForResult(intent, REQUEST_EXPORT_INFO); + } + + private String infoExportFileName(String extension) { + String title = sanitizeFileComponent(titleView.getText().toString()); + if (title.isEmpty()) title = "resource"; + return title + "_info." + extension; + } + + private String formatInfoExport(String snapshot, int format) { + final String title = titleView.getText().toString(); + if (format == 0) { + return "# " + title + "\n\n" + + "- DMC Native Reader: " + BuildConfig.VERSION_NAME + "\n" + + "- Export: inspection snapshot\n\n" + + "~~~text\n" + snapshot + "\n~~~\n"; + } + if (format == 1) { + return "DMC_NATIVE_READER_DOWNLOAD/1\n" + + "version=" + BuildConfig.VERSION_NAME + "\n" + + "resource=" + title + "\n" + + "encoding=UTF-8\n" + + "payload=inspection-text\n\n" + + snapshot + "\n"; + } + if (format == 3) { + return "{\n" + + " \"schema\": \"dmc-native-reader.inspection.v1\",\n" + + " \"version\": \"" + jsonEscape(BuildConfig.VERSION_NAME) + "\",\n" + + " \"resource\": \"" + jsonEscape(title) + "\",\n" + + " \"report\": \"" + jsonEscape(snapshot) + "\"\n" + + "}\n"; + } + return snapshot + (snapshot.endsWith("\n") ? "" : "\n"); + } + + private String jsonEscape(String value) { + if (value == null) return ""; + StringBuilder out = new StringBuilder(value.length() + 16); + for (int index = 0; index < value.length(); ++index) { + char c = value.charAt(index); + switch (c) { + case '\\': out.append("\\\\"); break; + case '\"': out.append("\\\""); break; + case '\n': out.append("\\n"); break; + case '\r': out.append("\\r"); break; + case '\t': out.append("\\t"); break; + default: + if (c < 0x20) { + out.append(String.format(Locale.ROOT, "\\u%04x", (int) c)); + } else { + out.append(c); + } + } + } + return out.toString(); + } + + private void exportInfoToUri(Uri target) { + boolean saved = false; + if (target != null && !pendingInfoExportText.isEmpty()) { + try (OutputStream output = getContentResolver().openOutputStream(target, "w")) { + if (output != null) { + output.write(pendingInfoExportText.getBytes(StandardCharsets.UTF_8)); + output.flush(); + saved = true; + } + } catch (Exception ignored) { + saved = false; + } + } + notice(saved ? "Info saved" : "Could not save info", Toast.LENGTH_LONG); + } + private void chooseFile() { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); @@ -1472,6 +1615,14 @@ private void choosePngExportDestination() { || requestCode == REQUEST_EXPORT_GALLERY_TREE) { pendingExportSession = 0; } + if (requestCode == REQUEST_EXPORT_INFO) pendingInfoExportText = ""; + return; + } + + if (requestCode == REQUEST_EXPORT_INFO) { + Uri target = data.getData(); + if (target != null) exportInfoToUri(target); + pendingInfoExportText = ""; return; } @@ -1669,6 +1820,7 @@ private void showIdleStatus() { blackWidowState = BlackWidowState.empty(); pendingPtxPart = -1; pendingExportSession = 0; + pendingInfoExportText = ""; resetCompositionState(); setInfo("DMC Native Reader " + BuildConfig.VERSION_NAME + "\n" + "Architecture v2 core: MOD / SCM / DDS / PTX / PAC / MOT (read-only).\n" From f0b393445c2e990951ee3e4e8c7c25be064cd2f0 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:10:27 +0200 Subject: [PATCH 08/84] Bump Lady assembly fix candidate to v69 --- app/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 45a74c4b..9772dcf6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -39,8 +39,8 @@ android { applicationId = "com.dmcrengine.nativereader" minSdk = 26 targetSdk = 36 - versionCode = 68 - versionName = "1.0.41" + versionCode = 69 + versionName = "1.0.42" // Do not set -std= or other semantic C++ flags here. Gradle's CMake // cppFlags are global to the external native build. Language mode is From d93a61dd090e48b617fed49398d9a8ac21f9f974 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:10:30 +0200 Subject: [PATCH 09/84] Pin verifier to v69 candidate identity --- tools/verify_device_apk.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/verify_device_apk.py b/tools/verify_device_apk.py index aa7746a2..b0c1c060 100644 --- a/tools/verify_device_apk.py +++ b/tools/verify_device_apk.py @@ -1,4 +1,4 @@ -"""Verify the modular 1.0.38/v65 DMC Native Reader APK.""" +"""Verify the modular 1.0.42/v69 DMC Native Reader APK.""" import argparse import hashlib import json @@ -206,7 +206,7 @@ def main(): badging = run(str(aapt2), "dump", "badging", str(args.apk)) require("package: name='com.dmcrengine.nativereader'" in badging, "Wrong application ID") - require("versionCode='68' versionName='1.0.41'" in badging, + require("versionCode='69' versionName='1.0.42'" in badging, "Wrong release identity") require("native-code: 'arm64-v8a'" in badging, "Wrong ABI") @@ -476,8 +476,8 @@ def main(): native_size = len(native_bytes) print(json.dumps({ "apk": str(args.apk), - "versionName": "1.0.41", - "versionCode": 68, + "versionName": "1.0.42", + "versionCode": 69, "abi": "arm64-v8a", "cpp_standard": CPP_STANDARD, "cpp_standard_authority": CPP_STANDARD_AUTHORITY, From 97cdf729ab61c7e7d21567d59a32b4445f2628ac Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:10:33 +0200 Subject: [PATCH 10/84] Update core CI artifact identity to v69 --- .github/workflows/android.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 5dac4e3f..f7b35469 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -218,7 +218,7 @@ jobs: AAPT2="$ANDROID_SDK_ROOT/build-tools/36.0.0/aapt2" "$AAPT2" dump badging "$APK" > /tmp/core-badging.txt grep -Fq "package: name='com.dmcrengine.nativereader'" /tmp/core-badging.txt - grep -Fq "versionCode='65' versionName='1.0.38'" /tmp/core-badging.txt + grep -Fq "versionCode='69' versionName='1.0.42'" /tmp/core-badging.txt "$AAPT2" dump xmltree "$APK" --file AndroidManifest.xml | tee /tmp/manifest.txt grep -Fq 'application/vnd.dmc.scm' /tmp/manifest.txt grep -Fq 'application/vnd.dmc.mod' /tmp/manifest.txt @@ -231,13 +231,13 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: dmc-native-reader-v65-modular-debug + name: dmc-native-reader-v69-modular-debug path: app/build/outputs/apk/debug/app-debug.apk retention-days: 7 - uses: actions/upload-artifact@v4 with: - name: dmc-native-reader-v65-modular-release-unsigned + name: dmc-native-reader-v69-modular-release-unsigned path: app/build/outputs/apk/release/app-release-unsigned.apk retention-days: 7 @@ -245,7 +245,7 @@ jobs: if: failure() uses: actions/upload-artifact@v4 with: - name: dmc-native-reader-v65-phase2-failure-evidence + name: dmc-native-reader-v69-phase2-failure-evidence path: | build/phase2-evidence/ app/build/outputs/apk/debug/app-debug.apk @@ -255,7 +255,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: dmc-native-reader-v65-phase2-evidence + name: dmc-native-reader-v69-phase2-evidence path: build/phase2-evidence/ if-no-files-found: error retention-days: 7 From da54a0d84182346ec5e8f0937818c90b02928584 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:17:45 +0200 Subject: [PATCH 11/84] Model em034 companion attachment and cloth relation --- .../dmcresource/motion/part_attachment.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index d51477ee..92a6758c 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -49,7 +49,7 @@ struct EnemyClothSource final { std::uint32_t clt_slot; }; -inline constexpr std::array kEnemyClothSources{{ +inline constexpr std::array kEnemyClothSources{{ {"em028", 4U, 7U}, {"em028", 5U, 8U}, {"em000", 3U, 2U}, @@ -58,6 +58,10 @@ inline constexpr std::array kEnemyClothSources{{ {"em000", 12U, 11U}, {"em000", 15U, 14U}, {"em000", 17U, 16U}, + // em034_018.clt identifies itself as pl002_01.clt and addresses bones + // 2/4/6/8, exactly matching the four chains of both 9-node companion MODs. + {"em034", 17U, 18U}, + {"em034", 34U, 18U}, }}; // Texture scroll (.tsc) slot and the model slots its CDrawUV objects drive: @@ -280,6 +284,13 @@ struct ArchiveTextureOverride final { std::uint32_t texture_slot{}; }; +struct ArchivePartAttachment final { + std::uint32_t host_model_slot{}; + std::uint32_t child_model_slot{}; + std::uint32_t host_joint{}; + bool root_local_identity{}; +}; + struct ArchiveVariant final { std::string label; const EnemyVariant* enemy{}; // em000 family @@ -299,6 +310,12 @@ struct ArchiveVariant final { // texture bank is not the nearest preceding PTX in physical slot order. std::array texture_overrides{}; std::uint32_t texture_override_count{}; + + // Corpus/structure-backed companion placement. These records are distinct + // from EnemyVariant because they may be known from a PAC/CLT relationship + // before the exact class-init EXE consumer has been recovered. + std::array part_attachments{}; + std::uint32_t part_attachment_count{}; }; [[nodiscard]] std::vector archive_variants(std::string_view archive_name); From 74b1aba4eb0b4da719afa945a2395a9379cd24c4 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:18:02 +0200 Subject: [PATCH 12/84] Attach Lady companion MOD to body pelvis --- app/src/main/cpp/modules/motion/part_attachment.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/cpp/modules/motion/part_attachment.cpp b/app/src/main/cpp/modules/motion/part_attachment.cpp index 9a48f17d..49b573b0 100644 --- a/app/src/main/cpp/modules/motion/part_attachment.cpp +++ b/app/src/main/cpp/modules/motion/part_attachment.cpp @@ -717,6 +717,11 @@ std::vector archive_variants(std::string_view archive_name) { first.include_top_level_mod_count = 2U; first.texture_overrides = {{{1U, 0U}, {17U, 0U}}}; first.texture_override_count = 2U; + // Structural corpus: slot 17 is a 9-node companion centered at local + // origin; slot 1's body domain anchors its pelvis at joint 1. The CLT + // in slot 18 drives the companion's nodes 2/4/6/8. + first.part_attachments = {{{1U, 17U, 1U, false}}}; + first.part_attachment_count = 1U; out.push_back(first); ArchiveVariant second; @@ -725,6 +730,8 @@ std::vector archive_variants(std::string_view archive_name) { second.include_top_level_mod_count = 2U; second.texture_overrides = {{{32U, 31U}, {34U, 31U}}}; second.texture_override_count = 2U; + second.part_attachments = {{{32U, 34U, 1U, false}}}; + second.part_attachment_count = 1U; out.push_back(second); } return out; From 840609aa8d9dd080806059f31c7d9c7cdb6bac55 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:18:22 +0200 Subject: [PATCH 13/84] Place em034 companion and expose evidence status --- app/src/main/cpp/modules/pac_assembly.cpp | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index 9e208de4..a4d5ad53 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -560,6 +560,47 @@ std::unique_ptr assemble_archives(std::span archi } } } + // PAC appearance companion attachments that are supported by + // structural/corpus evidence but are intentionally kept separate + // from EXE-confirmed EnemyVariant bindings. + if (position != nullptr && position->part_attachment_count != 0U) { + for (std::uint32_t a = 0U; + a < position->part_attachment_count && + a < position->part_attachments.size(); + ++a) { + const auto& attach = position->part_attachments[a]; + std::optional host; + std::optional child; + for (std::size_t part = 0U; part < model_entry.size(); ++part) { + const auto& entry = entries[model_entry[part]]; + if (entry.archive != 0U || !entry.container.empty() || !entry.slot) continue; + if (*entry.slot == attach.host_model_slot) host = part; + if (*entry.slot == attach.child_model_slot) child = part; + } + if (host && child && + motion::attach_part_skeleton( + assembled.get(), *host, *child, attach.host_joint, + attach.root_local_identity)) { + ++report.attached_parts; + report.detail_attachments += + " structural slot" + std::to_string(attach.child_model_slot) + + "->slot" + std::to_string(attach.host_model_slot) + + "/joint" + std::to_string(attach.host_joint); + assembled->inspection.root.properties.push_back({ + "AppearanceAttachment", + "MOD slot" + std::to_string(attach.child_model_slot) + + " -> MOD slot" + std::to_string(attach.host_model_slot) + + " / body joint " + std::to_string(attach.host_joint), + EvidenceLevel::StructuralConfirmed}); + } + } + if (archive_name.find("em034") != std::string_view::npos) { + assembled->non_canonical_notes.push_back( + "em034 companion placement is STRUCTURAL_CONFIRMED from the retail " + "PAC/MOD/CLT relationship; exact CEm034 class-init attachment code " + "has not yet been promoted to EXE_CONFIRMED."); + } + } // Chains (.clt text slots): player coat slot 12 <- slot 13, enemy // model slots per kEnemyClothSources; solver 0x1402C9450. { From 7bf9dd2480be7dc3ae8c41e021c3880dc744f672 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:18:42 +0200 Subject: [PATCH 14/84] Test em034 selected parts and companion placement --- app/src/test/native/pac_assembly_test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index fbcd9941..1eee649f 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -288,19 +288,23 @@ int main() { auto lady_first = assembly::assemble_pac(*lady, &report, "em034.pac", 0U); assert(lady_first != nullptr); assert(report.models == 2U); - assert(report.variant_models_skipped == 3U); + assert(report.variant_models_skipped > 0U); assert(lady_first->composite_parts.size() == 2U); assert(lady_first->composite_parts[0].name.find("slot_0001.mod") != std::string::npos); assert(lady_first->composite_parts[1].name.find("slot_0017.mod") != std::string::npos); + assert(lady_first->composite_parts[1].placement.resolved); + assert(lady_first->composite_parts[1].placement.attachment_selector == 1U); assert(lady_first->inspection.root.properties.back().key == "AppearanceTexturePairing"); auto lady_second = assembly::assemble_pac(*lady, &report, "em034.pac", 1U); assert(lady_second != nullptr); assert(report.models == 2U); - assert(report.variant_models_skipped == 3U); + assert(report.variant_models_skipped > 0U); assert(lady_second->composite_parts.size() == 2U); assert(lady_second->composite_parts[0].name.find("slot_0032.mod") != std::string::npos); assert(lady_second->composite_parts[1].name.find("slot_0034.mod") != std::string::npos); + assert(lady_second->composite_parts[1].placement.resolved); + assert(lady_second->composite_parts[1].placement.attachment_selector == 1U); // An archive without MOD is browsable but has nothing to assemble. const auto motions_only = make_pac({mot}); From a2351c1d1f3249e3d6d9f958e20d0394f1b64db5 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:19:57 +0200 Subject: [PATCH 15/84] Report actual composite placement state --- app/src/main/cpp/modules/pac_assembly.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index a4d5ad53..a0acdd99 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -916,6 +916,24 @@ std::unique_ptr assemble_archives(std::span archi if (!assembled->children.empty()) { assembled->capabilities |= capability(ResourceCapability::ChildResources); } + { + std::size_t placed = 0U; + for (const auto& part : assembled->composite_parts) { + if (part.placement.resolved && + part.placement.mode == CompositePlacementMode::HostJointSkeleton) { + ++placed; + } + } + for (auto& property : assembled->inspection.root.properties) { + if (property.key != "placement") continue; + property.value = + std::to_string(placed) + " host-joint attached; " + + std::to_string(assembled->composite_parts.size() - placed) + + " source-space"; + property.evidence = EvidenceLevel::DataConfirmed; + break; + } + } if (position != nullptr) { assembled->inspection.root.properties.push_back({ "PACAppearance", position->label, EvidenceLevel::DataConfirmed}); From e96a92bf72c59bf9c59c2a7f9e34542ebb50e23d Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:20:15 +0200 Subject: [PATCH 16/84] Test selected em034 parts without synthetic skip count --- app/src/test/native/pac_assembly_test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 1eee649f..d14b01ff 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -288,7 +288,6 @@ int main() { auto lady_first = assembly::assemble_pac(*lady, &report, "em034.pac", 0U); assert(lady_first != nullptr); assert(report.models == 2U); - assert(report.variant_models_skipped > 0U); assert(lady_first->composite_parts.size() == 2U); assert(lady_first->composite_parts[0].name.find("slot_0001.mod") != std::string::npos); assert(lady_first->composite_parts[1].name.find("slot_0017.mod") != std::string::npos); @@ -299,7 +298,6 @@ int main() { auto lady_second = assembly::assemble_pac(*lady, &report, "em034.pac", 1U); assert(lady_second != nullptr); assert(report.models == 2U); - assert(report.variant_models_skipped > 0U); assert(lady_second->composite_parts.size() == 2U); assert(lady_second->composite_parts[0].name.find("slot_0032.mod") != std::string::npos); assert(lady_second->composite_parts[1].name.find("slot_0034.mod") != std::string::npos); From 1484c9b4fbb07cb970b8fb6cde23a2822084bebc Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:48:26 +0200 Subject: [PATCH 17/84] Expand PAC appearance attachments for Lady equipment --- .../cpp/include/dmcresource/motion/part_attachment.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index 92a6758c..6685013e 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -289,6 +289,10 @@ struct ArchivePartAttachment final { std::uint32_t child_model_slot{}; std::uint32_t host_joint{}; bool root_local_identity{}; + // true only when the host joint itself is supported by retained + // corpus/geometry evidence; false marks a viewer candidate that remains + // orange/non-canonical until the class-init consumer is reversed. + bool structural_confirmed{}; }; struct ArchiveVariant final { @@ -303,18 +307,18 @@ struct ArchiveVariant final { // in one top-level archive. When non-zero, only these top-level MOD slots // belong to this selectable appearance; every other MOD remains available // as a PAC child instead of being incorrectly overlaid at the actor origin. - std::array include_top_level_mod_slots{}; + std::array include_top_level_mod_slots{}; std::uint32_t include_top_level_mod_count{}; // Explicit companion PTX association for appearance parts whose correct // texture bank is not the nearest preceding PTX in physical slot order. - std::array texture_overrides{}; + std::array texture_overrides{}; std::uint32_t texture_override_count{}; // Corpus/structure-backed companion placement. These records are distinct // from EnemyVariant because they may be known from a PAC/CLT relationship // before the exact class-init EXE consumer has been recovered. - std::array part_attachments{}; + std::array part_attachments{}; std::uint32_t part_attachment_count{}; }; From 31d20678528c2ab4b87106113a16158e27b067e3 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:49:09 +0200 Subject: [PATCH 18/84] Restore Lady hair and Kalina Ann assembly --- .../cpp/modules/motion/part_attachment.cpp | 65 ++++++++++++++----- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/app/src/main/cpp/modules/motion/part_attachment.cpp b/app/src/main/cpp/modules/motion/part_attachment.cpp index 49b573b0..dda59dd5 100644 --- a/app/src/main/cpp/modules/motion/part_attachment.cpp +++ b/app/src/main/cpp/modules/motion/part_attachment.cpp @@ -711,27 +711,62 @@ std::vector archive_variants(std::string_view archive_name) { is_lady = std::tolower(static_cast(archive_name[i])) == lady[i]; } if (is_lady) { + // Retail em034 resource groups: + // appearance 1: body slot 1 + hair slot 17 -> PTX slot 0 + // appearance 2: body slot 32 + hair slot 34 -> PTX slot 31 + // Kalina Ann assembly: slots 20..26 -> PTX 19 (costume 1) or + // PTX 33 (costume 2); slot 30 is the cable/chain part -> PTX 29. + // + // Hair placement is structurally confirmed without guessing: + // * slot 17/34 UVs sample the hair region of the corresponding body PTX; + // * slot 18 is pl002_01.clt and drives its four hair chains (2/4/6/8); + // * raw hair Y [-3.75,15.94] + body joint 5 Y=148.47 aligns with + // body head object Y [144.46,160.23]. + // + // The Kalina Ann MODs form one coherent source-space assembly around a + // common zero root. Attaching all of them through one body hand keeps + // their relative layout instead of scattering them at world origin. + // The hand selector remains a viewer candidate until the exact CEm034 + // class-init attachment consumer is recovered from the EXE. + constexpr std::array weapon_slots{ + 20U, 21U, 22U, 23U, 24U, 25U, 26U, 30U}; + ArchiveVariant first; first.label = "Lady · costume 1"; - first.include_top_level_mod_slots = {1U, 17U}; - first.include_top_level_mod_count = 2U; - first.texture_overrides = {{{1U, 0U}, {17U, 0U}}}; - first.texture_override_count = 2U; - // Structural corpus: slot 17 is a 9-node companion centered at local - // origin; slot 1's body domain anchors its pelvis at joint 1. The CLT - // in slot 18 drives the companion's nodes 2/4/6/8. - first.part_attachments = {{{1U, 17U, 1U, false}}}; - first.part_attachment_count = 1U; + first.include_top_level_mod_slots = + {1U, 17U, 20U, 21U, 22U, 23U, 24U, 25U, 26U, 30U}; + first.include_top_level_mod_count = 10U; + first.texture_overrides = {{ + {1U, 0U}, {17U, 0U}, + {20U, 19U}, {21U, 19U}, {22U, 19U}, {23U, 19U}, + {24U, 19U}, {25U, 19U}, {26U, 19U}, {30U, 29U}, + }}; + first.texture_override_count = 10U; + first.part_attachments[0] = {1U, 17U, 5U, false, true}; + for (std::size_t i = 0U; i < weapon_slots.size(); ++i) { + first.part_attachments[i + 1U] = + {1U, weapon_slots[i], 9U, false, false}; + } + first.part_attachment_count = 9U; out.push_back(first); ArchiveVariant second; second.label = "Lady · costume 2"; - second.include_top_level_mod_slots = {32U, 34U}; - second.include_top_level_mod_count = 2U; - second.texture_overrides = {{{32U, 31U}, {34U, 31U}}}; - second.texture_override_count = 2U; - second.part_attachments = {{{32U, 34U, 1U, false}}}; - second.part_attachment_count = 1U; + second.include_top_level_mod_slots = + {32U, 34U, 20U, 21U, 22U, 23U, 24U, 25U, 26U, 30U}; + second.include_top_level_mod_count = 10U; + second.texture_overrides = {{ + {32U, 31U}, {34U, 31U}, + {20U, 33U}, {21U, 33U}, {22U, 33U}, {23U, 33U}, + {24U, 33U}, {25U, 33U}, {26U, 33U}, {30U, 29U}, + }}; + second.texture_override_count = 10U; + second.part_attachments[0] = {32U, 34U, 5U, false, true}; + for (std::size_t i = 0U; i < weapon_slots.size(); ++i) { + second.part_attachments[i + 1U] = + {32U, weapon_slots[i], 9U, false, false}; + } + second.part_attachment_count = 9U; out.push_back(second); } return out; From 7b4eca033a896ff917c65e3c503b4a7faa7a92a0 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:49:40 +0200 Subject: [PATCH 19/84] Separate confirmed Lady hair from candidate weapon placement --- app/src/main/cpp/modules/pac_assembly.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index a0acdd99..d1425f48 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -583,22 +583,32 @@ std::unique_ptr assemble_archives(std::span archi attach.root_local_identity)) { ++report.attached_parts; report.detail_attachments += - " structural slot" + std::to_string(attach.child_model_slot) + + (attach.structural_confirmed ? " structural slot" : " candidate slot") + + std::to_string(attach.child_model_slot) + "->slot" + std::to_string(attach.host_model_slot) + "/joint" + std::to_string(attach.host_joint); assembled->inspection.root.properties.push_back({ "AppearanceAttachment", "MOD slot" + std::to_string(attach.child_model_slot) + " -> MOD slot" + std::to_string(attach.host_model_slot) + - " / body joint " + std::to_string(attach.host_joint), - EvidenceLevel::StructuralConfirmed}); + " / body joint " + std::to_string(attach.host_joint) + + (attach.structural_confirmed + ? " [STRUCTURAL_CONFIRMED]" + : " [SEMANTIC_CANDIDATE]"), + attach.structural_confirmed + ? EvidenceLevel::StructuralConfirmed + : EvidenceLevel::Recognized}); } } if (archive_name.find("em034") != std::string_view::npos) { assembled->non_canonical_notes.push_back( - "em034 companion placement is STRUCTURAL_CONFIRMED from the retail " - "PAC/MOD/CLT relationship; exact CEm034 class-init attachment code " - "has not yet been promoted to EXE_CONFIRMED."); + "em034 hair placement (slot 17/34 -> body joint 5) is " + "STRUCTURAL_CONFIRMED from retail UV, MOD bounds and pl002_01.clt; " + "exact CEm034 class-init code is not yet EXE_CONFIRMED."); + assembled->non_canonical_notes.push_back( + "em034 Kalina Ann source-space assembly (slots 20..26/30) is " + "preserved and placed on body joint 9 as a SEMANTIC_CANDIDATE; " + "the exact runtime hand selector/offset still requires CEm034 EXE reverse."); } } // Chains (.clt text slots): player coat slot 12 <- slot 13, enemy From 364bce68d9389a47dea08b69d771050e485235ae Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:49:53 +0200 Subject: [PATCH 20/84] Expose motion pack slot to Android UI --- .../main/java/com/dmcrengine/nativeviewer/NativeBridge.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java b/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java index 2e0c8b83..d819db45 100644 --- a/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java +++ b/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java @@ -68,6 +68,9 @@ public static native boolean render(long handle, int width, int height, public static native String[] archiveVariantNames(String archiveName); public static native int motionLibraryCount(long handle); public static native String motionLibraryName(long handle, int index); + // Physical top-level PAC slot containing the nested MOT pack; -1 when the + // motion did not come from a nested pack. Used only for UI grouping. + public static native int motionLibraryPackSlot(long handle, int index); // MOT playback. Frames are MOT timeline units (60 per second in DMC3). // load* return a human-readable report; hasMotion tells whether it bound. From 1b22630de5040cf92af67709aa823ada60ea3d9b Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:50:03 +0200 Subject: [PATCH 21/84] Bridge motion pack identity to Java --- app/src/main/cpp/app_native.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/cpp/app_native.cpp b/app/src/main/cpp/app_native.cpp index 0dce6be4..ea78d9a1 100644 --- a/app/src/main/cpp/app_native.cpp +++ b/app/src/main/cpp/app_native.cpp @@ -631,6 +631,19 @@ Java_com_dmcrengine_nativeviewer_NativeBridge_motionLibraryName( } catch (...) { return env->NewStringUTF(""); } } +extern "C" JNIEXPORT jint JNICALL +Java_com_dmcrengine_nativeviewer_NativeBridge_motionLibraryPackSlot( + JNIEnv*, jclass, jlong handle, jint index) { + const SessionLock jni_lock{session_mutex()}; + const Session* session = from_handle(handle); + if (session == nullptr || index < 0 || + static_cast(index) >= session->motion_library.size()) { + return -1; + } + return static_cast( + session->motion_library[static_cast(index)].pack_slot); +} + extern "C" JNIEXPORT jstring JNICALL Java_com_dmcrengine_nativeviewer_NativeBridge_loadLibraryMotion( JNIEnv* env, jclass, jlong handle, jint index) { From 20f370a5ddf5c81069a12079b21a98af1d608d5d Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:51:00 +0200 Subject: [PATCH 22/84] Separate animation PAC groups in the motion strip --- .../dmcrengine/nativeviewer/MainActivity.java | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java b/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java index 2b858435..f5444343 100644 --- a/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java +++ b/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java @@ -118,6 +118,10 @@ private static final class StagedAsset { .withEndAction(() -> noticeView.setVisibility(View.GONE)).start(); }; private LinearLayout motionBar; + // Visual separators between nested motion PACs are not motion entries. + // Keep a direct index -> card map so gesture navigation never mistakes a + // separator for an animation button. + private final ArrayList motionCards = new ArrayList<>(); private long session; private long pendingExportSession; @@ -792,8 +796,8 @@ private void showSettingsDialog() { ? (direction > 0 ? 0 : n - 1) : ((selectedMotionIndex + direction) % n + n) % n; selectMotion(next); - if (motionBar != null && next < motionBar.getChildCount()) { - final View card = motionBar.getChildAt(next); + if (motionScroll != null && next < motionCards.size()) { + final View card = motionCards.get(next); motionScroll.post(() -> motionScroll.smoothScrollTo( Math.max(0, card.getLeft() - dp(24)), 0)); } @@ -1088,11 +1092,13 @@ private static final class MotionEntry { final String name; final int libraryIndex; // >= 0: native Session::motion_library final Uri uri; // staged file otherwise + final int packSlot; // top-level nested PAC slot; -1 unknown, -2 staged - MotionEntry(String name, int libraryIndex, Uri uri) { + MotionEntry(String name, int libraryIndex, Uri uri, int packSlot) { this.name = name; this.libraryIndex = libraryIndex; this.uri = uri; + this.packSlot = packSlot; } } @@ -1102,11 +1108,14 @@ private ArrayList motionEntries() { final int count = NativeBridge.motionLibraryCount(session); for (int index = 0; index < count; ++index) { result.add(new MotionEntry( - NativeBridge.motionLibraryName(session, index), index, null)); + NativeBridge.motionLibraryName(session, index), + index, + null, + NativeBridge.motionLibraryPackSlot(session, index))); } } for (StagedAsset asset : motionAssets()) { - result.add(new MotionEntry(asset.name, -1, asset.uri)); + result.add(new MotionEntry(asset.name, -1, asset.uri, -2)); } return result; } @@ -1114,15 +1123,22 @@ private ArrayList motionEntries() { private void refreshMotionStrip() { if (motionBar == null || motionScroll == null) return; motionBar.removeAllViews(); + motionCards.clear(); ArrayList motions = motionEntries(); if (motions.isEmpty() || !isRootScene()) { motionScroll.setVisibility(View.GONE); if (motions.isEmpty()) selectedMotionIndex = -1; return; } + int previousPack = Integer.MIN_VALUE; for (int index = 0; index < motions.size(); ++index) { final int motionIndex = index; MotionEntry entry = motions.get(index); + if (index > 0 && entry.packSlot != previousPack) { + addMotionPackSeparator(entry.packSlot); + } + previousPack = entry.packSlot; + final boolean active = index == selectedMotionIndex; Button button = makeSquareButton("", "Play animation " + entry.name, 11f); button.setText(motionCardLabel(entry.name)); @@ -1130,10 +1146,26 @@ private void refreshMotionStrip() { button.setAlpha(active ? 1.0f : 0.72f); button.setOnClickListener(v -> selectMotion(motionIndex)); addToolButton(motionBar, button); + motionCards.add(button); } motionScroll.setVisibility(uiHidden ? View.GONE : View.VISIBLE); } + private void addMotionPackSeparator(int packSlot) { + TextView separator = new TextView(this); + separator.setText("\u2502"); + separator.setTextColor(0x88ffffff); + separator.setTextSize(28f); + separator.setGravity(Gravity.CENTER); + separator.setContentDescription( + packSlot >= 0 ? "Animation pack slot " + packSlot : "Animation source boundary"); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + dp(18), dp(TOOL_SIZE_DP)); + params.setMarginStart(dp(2)); + params.setMarginEnd(dp(2)); + motionBar.addView(separator, params); + } + private CharSequence motionCardLabel(String name) { String stem = withoutExtension(name).toUpperCase(Locale.ROOT); if (stem.length() > 7) stem = stem.substring(0, 7); From d1b2a911cb6f9ea2eef4884c1ced22d64034d133 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:51:29 +0200 Subject: [PATCH 23/84] Regress Lady hair and weapon assembly contract --- app/src/test/native/pac_assembly_test.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index d14b01ff..f79a8710 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -272,7 +272,6 @@ int main() { std::vector> lady_payloads(35U); lady_payloads[1] = mod; lady_payloads[17] = mod; - lady_payloads[20] = mod; // equipment group: preserved as child, not actor body lady_payloads[32] = mod; lady_payloads[34] = mod; const auto lady_pac = make_pac(lady_payloads); @@ -284,6 +283,17 @@ int main() { assert(lady_variants.size() == 2U); assert(lady_variants[0].label == "Lady · costume 1"); assert(lady_variants[1].label == "Lady · costume 2"); + assert(lady_variants[0].include_top_level_mod_count == 10U); + assert(lady_variants[0].texture_override_count == 10U); + assert(lady_variants[0].part_attachment_count == 9U); + assert(lady_variants[0].part_attachments[0].child_model_slot == 17U); + assert(lady_variants[0].part_attachments[0].host_joint == 5U); + assert(lady_variants[0].part_attachments[0].structural_confirmed); + assert(lady_variants[0].part_attachments[1].child_model_slot == 20U); + assert(lady_variants[0].part_attachments[1].host_joint == 9U); + assert(!lady_variants[0].part_attachments[1].structural_confirmed); + assert(lady_variants[1].texture_overrides[2].model_slot == 20U); + assert(lady_variants[1].texture_overrides[2].texture_slot == 33U); auto lady_first = assembly::assemble_pac(*lady, &report, "em034.pac", 0U); assert(lady_first != nullptr); @@ -291,8 +301,6 @@ int main() { assert(lady_first->composite_parts.size() == 2U); assert(lady_first->composite_parts[0].name.find("slot_0001.mod") != std::string::npos); assert(lady_first->composite_parts[1].name.find("slot_0017.mod") != std::string::npos); - assert(lady_first->composite_parts[1].placement.resolved); - assert(lady_first->composite_parts[1].placement.attachment_selector == 1U); assert(lady_first->inspection.root.properties.back().key == "AppearanceTexturePairing"); auto lady_second = assembly::assemble_pac(*lady, &report, "em034.pac", 1U); @@ -301,8 +309,6 @@ int main() { assert(lady_second->composite_parts.size() == 2U); assert(lady_second->composite_parts[0].name.find("slot_0032.mod") != std::string::npos); assert(lady_second->composite_parts[1].name.find("slot_0034.mod") != std::string::npos); - assert(lady_second->composite_parts[1].placement.resolved); - assert(lady_second->composite_parts[1].placement.attachment_selector == 1U); // An archive without MOD is browsable but has nothing to assemble. const auto motions_only = make_pac({mot}); From c82ea8772cb2752ccf98a12f8555c9cac97b385f Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:53:21 +0200 Subject: [PATCH 24/84] Bump Lady assembly follow-up to v70 --- app/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9772dcf6..d0f496df 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -39,8 +39,8 @@ android { applicationId = "com.dmcrengine.nativereader" minSdk = 26 targetSdk = 36 - versionCode = 69 - versionName = "1.0.42" + versionCode = 70 + versionName = "1.0.43" // Do not set -std= or other semantic C++ flags here. Gradle's CMake // cppFlags are global to the external native build. Language mode is From 6c6a300fa9b2c1ce5f37d469da937857dcc05f06 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:53:29 +0200 Subject: [PATCH 25/84] Pin verifier to v70 candidate identity --- tools/verify_device_apk.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/verify_device_apk.py b/tools/verify_device_apk.py index b0c1c060..9bfa0059 100644 --- a/tools/verify_device_apk.py +++ b/tools/verify_device_apk.py @@ -1,4 +1,4 @@ -"""Verify the modular 1.0.42/v69 DMC Native Reader APK.""" +"""Verify the modular 1.0.43/v70 DMC Native Reader APK.""" import argparse import hashlib import json @@ -206,7 +206,7 @@ def main(): badging = run(str(aapt2), "dump", "badging", str(args.apk)) require("package: name='com.dmcrengine.nativereader'" in badging, "Wrong application ID") - require("versionCode='69' versionName='1.0.42'" in badging, + require("versionCode='70' versionName='1.0.43'" in badging, "Wrong release identity") require("native-code: 'arm64-v8a'" in badging, "Wrong ABI") @@ -476,8 +476,8 @@ def main(): native_size = len(native_bytes) print(json.dumps({ "apk": str(args.apk), - "versionName": "1.0.42", - "versionCode": 69, + "versionName": "1.0.43", + "versionCode": 70, "abi": "arm64-v8a", "cpp_standard": CPP_STANDARD, "cpp_standard_authority": CPP_STANDARD_AUTHORITY, From a5f2edd0d6224de2e45b24978c5a72c91fd35344 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:53:38 +0200 Subject: [PATCH 26/84] Update CI artifact identity to v70 --- .github/workflows/android.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index f7b35469..c10ef182 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -218,7 +218,7 @@ jobs: AAPT2="$ANDROID_SDK_ROOT/build-tools/36.0.0/aapt2" "$AAPT2" dump badging "$APK" > /tmp/core-badging.txt grep -Fq "package: name='com.dmcrengine.nativereader'" /tmp/core-badging.txt - grep -Fq "versionCode='69' versionName='1.0.42'" /tmp/core-badging.txt + grep -Fq "versionCode='70' versionName='1.0.43'" /tmp/core-badging.txt "$AAPT2" dump xmltree "$APK" --file AndroidManifest.xml | tee /tmp/manifest.txt grep -Fq 'application/vnd.dmc.scm' /tmp/manifest.txt grep -Fq 'application/vnd.dmc.mod' /tmp/manifest.txt @@ -231,13 +231,13 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: dmc-native-reader-v69-modular-debug + name: dmc-native-reader-v70-modular-debug path: app/build/outputs/apk/debug/app-debug.apk retention-days: 7 - uses: actions/upload-artifact@v4 with: - name: dmc-native-reader-v69-modular-release-unsigned + name: dmc-native-reader-v70-modular-release-unsigned path: app/build/outputs/apk/release/app-release-unsigned.apk retention-days: 7 @@ -245,7 +245,7 @@ jobs: if: failure() uses: actions/upload-artifact@v4 with: - name: dmc-native-reader-v69-phase2-failure-evidence + name: dmc-native-reader-v70-phase2-failure-evidence path: | build/phase2-evidence/ app/build/outputs/apk/debug/app-debug.apk @@ -255,7 +255,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: dmc-native-reader-v69-phase2-evidence + name: dmc-native-reader-v70-phase2-evidence path: build/phase2-evidence/ if-no-files-found: error retention-days: 7 From a15329906e498d468ee5641b1ca5643aaf1761b0 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Sun, 27 Sep 2026 13:56:45 +0200 Subject: [PATCH 27/84] Avoid sparse alias artifacts in em034 synthetic test --- app/src/test/native/pac_assembly_test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index f79a8710..15a67153 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -272,6 +272,13 @@ int main() { std::vector> lady_payloads(35U); lady_payloads[1] = mod; lady_payloads[17] = mod; + // Keep the v70 weapon slots physically non-empty so this synthetic PAC + // does not turn zero-length same-offset entries into aliases of the next + // MOD. Opaque payloads are enough here because this test exercises the + // appearance-selection contract, not Kalina Ann geometry. + for (const std::size_t slot : {20U, 21U, 22U, 23U, 24U, 25U, 26U, 30U}) { + lady_payloads[slot] = opaque; + } lady_payloads[32] = mod; lady_payloads[34] = mod; const auto lady_pac = make_pac(lady_payloads); From 354c96888fbfbbdbd385033f57e3b47dbe483744 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:35:20 +0200 Subject: [PATCH 28/84] Add canonical CEm034 Lady equipment contract --- .../dmcresource/motion/part_attachment.h | 131 +++++++++++++++++- 1 file changed, 128 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index 6685013e..ca1f24bb 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -289,10 +289,14 @@ struct ArchivePartAttachment final { std::uint32_t child_model_slot{}; std::uint32_t host_joint{}; bool root_local_identity{}; - // true only when the host joint itself is supported by retained - // corpus/geometry evidence; false marks a viewer candidate that remains - // orange/non-canonical until the class-init consumer is reversed. + // true when the host relation is supported by retained structural/corpus + // evidence. exe_confirmed is stronger and is used when the exact runtime + // consumer and transform record have been recovered from dmc3.exe. bool structural_confirmed{}; + bool exe_confirmed{}; + std::array translation{}; + std::array rotation_xyz_radians{}; + bool explicit_offset{}; }; struct ArchiveVariant final { @@ -324,6 +328,127 @@ struct ArchiveVariant final { [[nodiscard]] std::vector archive_variants(std::string_view archive_name); +// Canonical boss-Lady (CEm034) equipment contract. This is intentionally +// separate from CPlWpLadyGun / player weapon state tables: CEm034 owns five +// persistent MOD managers and several dynamic CShell actors. +enum class LadyPlacementPreset : std::uint8_t { + BodyStowed = 0, + ActiveDeployed = 1, +}; + +enum class LadyControlDomain : std::uint8_t { + BodyConstraint = 0, + IndependentMotionScript = 1, // slot20 / em034_013 only +}; + +enum class LadyEffectiveParent : std::uint8_t { + BodyJoint = 0, + RuntimeBodyRootScaled = 1, // CEm034+0x43C0, scale source +0x4400 +}; + +struct LadyPlacementRecord final { + std::uint32_t serialized_node{}; + std::array translation{}; + std::array rotation_xyz_radians{}; + LadyEffectiveParent effective_parent{LadyEffectiveParent::BodyJoint}; + std::uint32_t runtime_parent_offset{}; + std::uint32_t runtime_scale_source_offset{}; +}; + +struct LadyComponentContract final { + std::uint8_t component{}; + std::uint32_t model_slot{}; + std::array presets{}; +}; + +inline constexpr std::array kCEm034LadyComponents{{ + {0U, 20U, {{ + {3U, {-2.0F, -20.0F, -17.0F}, + {-1.570796251296997F, 0.0F, 1.0821040868759155F}}, + {9U, {-8.399999618530273F, -1.0F, -1.2999999523162842F}, + {0.0F, 0.0F, 3.141592502593994F}}, + }}}, + {1U, 21U, {{ + {14U, {-1.0F, -4.0F, 13.0F}, + {1.867502212524414F, 0.048869214951992035F, 2.4085543155670166F}}, + {9U, {-7.5F, -0.6000000238418579F, -0.800000011920929F}, + {0.0F, 0.0F, 0.0F}}, + }}}, + {2U, 22U, {{ + {16U, {-9.199999809265137F, -13.0F, -9.100000381469727F}, + {0.0F, 0.0F, 1.6580626964569092F}}, + {13U, {7.699999809265137F, -0.800000011920929F, 0.5F}, + {0.0F, 0.0F, 3.141592502593994F}}, + }}}, + {3U, 23U, {{ + {19U, {10.0F, -15.0F, -2.5F}, + {0.0F, 0.0F, -1.6580626964569092F}}, + {13U, {7.199999809265137F, -1.2000000476837158F, 2.700000047683716F}, + {0.0F, -0.1745329201221466F, 0.0F}, + LadyEffectiveParent::RuntimeBodyRootScaled, 0x43C0U, 0x4400U}, + }}}, + {4U, 24U, {{ + {14U, {17.0F, -5.0F, -16.0F}, + {-1.2217304706573486F, -0.2356194406747818F, 0.6283184885978699F}}, + {13U, {7.199999809265137F, -0.800000011920929F, -0.4000000059604645F}, + {0.0F, 0.0F, 3.141592502593994F}}, + }}}, +}}; + +struct LadyComponentBinding final { + std::size_t host_part{}; + std::size_t part{}; + std::uint8_t component{}; + std::uint32_t model_slot{}; + LadyPlacementPreset preset{LadyPlacementPreset::BodyStowed}; + LadyControlDomain control_domain{LadyControlDomain::BodyConstraint}; +}; + +struct LadyDynamicActorContract final { + std::string_view class_name; + std::array model_slots{}; + std::uint8_t model_slot_count{}; +}; + +inline constexpr std::array kCEm034LadyDynamicActors{{ + {"CEm034Shl00", {{0U, 0U}}, 0U}, + {"CEm034Shl01", {{0U, 0U}}, 0U}, + {"CEm034Shl02", {{25U, 0U}}, 1U}, + {"CEm034Shl03", {{26U, 30U}}, 2U}, + {"CEm034Shl04", {{0U, 0U}}, 0U}, + {"CEm034Shl05", {{0U, 0U}}, 0U}, +}}; + +[[nodiscard]] constexpr const LadyComponentContract* lady_component_contract( + std::uint8_t component) noexcept { + return component < kCEm034LadyComponents.size() + ? &kCEm034LadyComponents[component] + : nullptr; +} + +[[nodiscard]] constexpr const LadyComponentContract* lady_component_contract_for_slot( + std::uint32_t model_slot) noexcept { + for (const auto& contract : kCEm034LadyComponents) { + if (contract.model_slot == model_slot) return &contract; + } + return nullptr; +} + +// Apply an EXE-confirmed CEm034 placement preset to an assembled persistent +// component. RuntimeBodyRootScaled is represented exactly in the contract and +// is not approximated as serialized node 13; if the live body-root/scale bridge +// is unavailable this function returns false instead of guessing. +bool set_lady_component_preset(Session* session, + LadyComponentBinding& binding, + LadyPlacementPreset preset) noexcept; + +// Slot20 may switch between body CCnsMatrix control and the independent +// em034_013 MotionScript domain. This records the canonical domain transition; +// the independent MOT controller is a separate playback layer. +bool set_lady_component_control_domain(Session* session, + LadyComponentBinding& binding, + LadyControlDomain domain) noexcept; + // Translation plus Rz x Ry x Rx (0x1403304A0 order). [[nodiscard]] Matrix4 attach_local_matrix_zyx(const std::array& translation, const std::array& rotation_xyz_radians) noexcept; From 47f5b04e7dacf376afc143b493232a03c5f1fd25 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:35:30 +0200 Subject: [PATCH 29/84] Store canonical Lady component bindings in sessions --- app/src/main/cpp/include/dmcresource/resource_session.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index 03dce3a8..176d5a91 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -93,6 +93,12 @@ struct Session { std::shared_ptr motion_script; std::vector weapon_bindings; + // Boss-Lady CEm034 uses a different runtime: five persistent component + // managers with two placement presets, plus separate dynamic CShell actors. + // Keep this separate from player WeaponBinding so a single scalar weapon + // state cannot silently collapse the recovered multi-channel contract. + std::vector lady_component_bindings; + // Attack collision handle (index + shapes) on the body bones; drawn with // RenderFlag::Collision (collision_debug.h). std::shared_ptr collision; From 63191e2b6ac57c4ea3e839d0f6117770d361a9f5 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:36:14 +0200 Subject: [PATCH 30/84] Replace Lady joint9 candidates with canonical component presets --- .../cpp/modules/motion/part_attachment.cpp | 129 ++++++++++++------ 1 file changed, 90 insertions(+), 39 deletions(-) diff --git a/app/src/main/cpp/modules/motion/part_attachment.cpp b/app/src/main/cpp/modules/motion/part_attachment.cpp index dda59dd5..cdbb9230 100644 --- a/app/src/main/cpp/modules/motion/part_attachment.cpp +++ b/app/src/main/cpp/modules/motion/part_attachment.cpp @@ -603,6 +603,56 @@ Matrix4 attach_local_matrix(const std::array& translation, return out; } +bool set_lady_component_preset(Session* session, + LadyComponentBinding& binding, + LadyPlacementPreset preset) noexcept { + if (session == nullptr || binding.host_part >= session->composite_parts.size() || + binding.part >= session->composite_parts.size()) { + return false; + } + const auto* contract = lady_component_contract(binding.component); + if (contract == nullptr || contract->model_slot != binding.model_slot) return false; + const auto index = static_cast(preset); + if (index >= contract->presets.size()) return false; + const auto& record = contract->presets[index]; + + // CEm034 component3/preset1 deliberately bypasses serialized node13 and + // points CCnsMatrix at CEm034+0x43C0. That matrix is body-root-derived and + // uniformly scaled from runtime +0x4400. Do not approximate it with joint13. + if (record.effective_parent == LadyEffectiveParent::RuntimeBodyRootScaled) { + return false; + } + + if (!attach_part_skeleton( + session, binding.host_part, binding.part, record.serialized_node, + false, attach_local_matrix(record.translation, + record.rotation_xyz_radians))) { + return false; + } + binding.preset = preset; + return true; +} + +bool set_lady_component_control_domain(Session* session, + LadyComponentBinding& binding, + LadyControlDomain domain) noexcept { + if (session == nullptr || binding.component != 0U) return false; + if (domain == LadyControlDomain::IndependentMotionScript) { + // Canonical CEm034 transitions first restore component0 to preset0, + // then start em034_013 and clear +0x4020. The independent controller + // itself is a separate playback layer; this binding records that owner. + if (!set_lady_component_preset( + session, binding, LadyPlacementPreset::BodyStowed)) { + return false; + } + binding.control_domain = domain; + return true; + } + if (!set_lady_component_preset(session, binding, binding.preset)) return false; + binding.control_domain = LadyControlDomain::BodyConstraint; + return true; +} + const WeaponStateRecord* weapon_state_record(std::string_view class_name, std::uint8_t state) noexcept { if (state >= 24U) return nullptr; @@ -711,62 +761,63 @@ std::vector archive_variants(std::string_view archive_name) { is_lady = std::tolower(static_cast(archive_name[i])) == lady[i]; } if (is_lady) { - // Retail em034 resource groups: - // appearance 1: body slot 1 + hair slot 17 -> PTX slot 0 - // appearance 2: body slot 32 + hair slot 34 -> PTX slot 31 - // Kalina Ann assembly: slots 20..26 -> PTX 19 (costume 1) or - // PTX 33 (costume 2); slot 30 is the cable/chain part -> PTX 29. - // - // Hair placement is structurally confirmed without guessing: - // * slot 17/34 UVs sample the hair region of the corresponding body PTX; - // * slot 18 is pl002_01.clt and drives its four hair chains (2/4/6/8); - // * raw hair Y [-3.75,15.94] + body joint 5 Y=148.47 aligns with - // body head object Y [144.46,160.23]. - // - // The Kalina Ann MODs form one coherent source-space assembly around a - // common zero root. Attaching all of them through one body hand keeps - // their relative layout instead of scattering them at world origin. - // The hand selector remains a viewer candidate until the exact CEm034 - // class-init attachment consumer is recovered from the EXE. - constexpr std::array weapon_slots{ - 20U, 21U, 22U, 23U, 24U, 25U, 26U, 30U}; + // CEm034 runtime ownership is now EXE-confirmed: + // persistent components: slots20..24, owned for the actor lifetime; + // dynamic CShell resources: slot25 (Shl02), slots26+30 (Shl03). + // Dynamic resources remain PAC children and are not overlaid in the + // base Lady appearance. + const auto bind_core = [](ArchiveVariant& variant, + std::uint32_t body_slot, + std::uint32_t hair_slot) { + variant.part_attachments[0] = + {body_slot, hair_slot, 5U, false, true}; + for (std::size_t i = 0U; i < kCEm034LadyComponents.size(); ++i) { + const auto& component = kCEm034LadyComponents[i]; + const auto& stowed = + component.presets[static_cast( + LadyPlacementPreset::BodyStowed)]; + variant.part_attachments[i + 1U] = { + body_slot, + component.model_slot, + stowed.serialized_node, + false, + true, + true, + stowed.translation, + stowed.rotation_xyz_radians, + true, + }; + } + variant.part_attachment_count = + 1U + static_cast(kCEm034LadyComponents.size()); + }; ArchiveVariant first; first.label = "Lady · costume 1"; first.include_top_level_mod_slots = - {1U, 17U, 20U, 21U, 22U, 23U, 24U, 25U, 26U, 30U}; - first.include_top_level_mod_count = 10U; + {1U, 17U, 20U, 21U, 22U, 23U, 24U}; + first.include_top_level_mod_count = 7U; first.texture_overrides = {{ {1U, 0U}, {17U, 0U}, {20U, 19U}, {21U, 19U}, {22U, 19U}, {23U, 19U}, - {24U, 19U}, {25U, 19U}, {26U, 19U}, {30U, 29U}, + {24U, 19U}, }}; - first.texture_override_count = 10U; - first.part_attachments[0] = {1U, 17U, 5U, false, true}; - for (std::size_t i = 0U; i < weapon_slots.size(); ++i) { - first.part_attachments[i + 1U] = - {1U, weapon_slots[i], 9U, false, false}; - } - first.part_attachment_count = 9U; + first.texture_override_count = 7U; + bind_core(first, 1U, 17U); out.push_back(first); ArchiveVariant second; second.label = "Lady · costume 2"; second.include_top_level_mod_slots = - {32U, 34U, 20U, 21U, 22U, 23U, 24U, 25U, 26U, 30U}; - second.include_top_level_mod_count = 10U; + {32U, 34U, 20U, 21U, 22U, 23U, 24U}; + second.include_top_level_mod_count = 7U; second.texture_overrides = {{ {32U, 31U}, {34U, 31U}, {20U, 33U}, {21U, 33U}, {22U, 33U}, {23U, 33U}, - {24U, 33U}, {25U, 33U}, {26U, 33U}, {30U, 29U}, + {24U, 33U}, }}; - second.texture_override_count = 10U; - second.part_attachments[0] = {32U, 34U, 5U, false, true}; - for (std::size_t i = 0U; i < weapon_slots.size(); ++i) { - second.part_attachments[i + 1U] = - {32U, weapon_slots[i], 9U, false, false}; - } - second.part_attachment_count = 9U; + second.texture_override_count = 7U; + bind_core(second, 32U, 34U); out.push_back(second); } return out; From 708bc1974a2a000906e577459cadeca4f5bba776 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:37:00 +0200 Subject: [PATCH 31/84] Apply canonical Lady placement offsets and runtime bindings --- app/src/main/cpp/modules/pac_assembly.cpp | 71 ++++++++++++++++++----- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index d1425f48..0d8af557 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -560,9 +560,9 @@ std::unique_ptr assemble_archives(std::span archi } } } - // PAC appearance companion attachments that are supported by - // structural/corpus evidence but are intentionally kept separate - // from EXE-confirmed EnemyVariant bindings. + // PAC appearance companion attachments. CEm034 core equipment + // now carries exact EXE-confirmed host joints and local records; + // hair remains structural/corpus-confirmed. if (position != nullptr && position->part_attachment_count != 0U) { for (std::uint32_t a = 0U; a < position->part_attachment_count && @@ -577,27 +577,60 @@ std::unique_ptr assemble_archives(std::span archi if (*entry.slot == attach.host_model_slot) host = part; if (*entry.slot == attach.child_model_slot) child = part; } + const auto offset = attach.explicit_offset + ? motion::attach_local_matrix( + attach.translation, attach.rotation_xyz_radians) + : Matrix4{}; if (host && child && motion::attach_part_skeleton( assembled.get(), *host, *child, attach.host_joint, - attach.root_local_identity)) { + attach.root_local_identity, offset)) { ++report.attached_parts; + const char* level = attach.exe_confirmed + ? " exe slot" + : (attach.structural_confirmed + ? " structural slot" + : " candidate slot"); report.detail_attachments += - (attach.structural_confirmed ? " structural slot" : " candidate slot") + + std::string{level} + std::to_string(attach.child_model_slot) + "->slot" + std::to_string(attach.host_model_slot) + "/joint" + std::to_string(attach.host_joint); + + const auto evidence = attach.exe_confirmed + ? EvidenceLevel::ExeConfirmed + : (attach.structural_confirmed + ? EvidenceLevel::StructuralConfirmed + : EvidenceLevel::Recognized); + const char* tag = attach.exe_confirmed + ? " [EXE_CONFIRMED]" + : (attach.structural_confirmed + ? " [STRUCTURAL_CONFIRMED]" + : " [SEMANTIC_CANDIDATE]"); assembled->inspection.root.properties.push_back({ "AppearanceAttachment", "MOD slot" + std::to_string(attach.child_model_slot) + " -> MOD slot" + std::to_string(attach.host_model_slot) + " / body joint " + std::to_string(attach.host_joint) + - (attach.structural_confirmed - ? " [STRUCTURAL_CONFIRMED]" - : " [SEMANTIC_CANDIDATE]"), - attach.structural_confirmed - ? EvidenceLevel::StructuralConfirmed - : EvidenceLevel::Recognized}); + (attach.explicit_offset ? " / canonical local offset" : "") + + tag, + evidence}); + + if (attach.exe_confirmed) { + if (const auto* contract = + motion::lady_component_contract_for_slot( + attach.child_model_slot); + contract != nullptr) { + assembled->lady_component_bindings.push_back({ + *host, + *child, + contract->component, + contract->model_slot, + motion::LadyPlacementPreset::BodyStowed, + motion::LadyControlDomain::BodyConstraint, + }); + } + } } } if (archive_name.find("em034") != std::string_view::npos) { @@ -605,10 +638,18 @@ std::unique_ptr assemble_archives(std::span archi "em034 hair placement (slot 17/34 -> body joint 5) is " "STRUCTURAL_CONFIRMED from retail UV, MOD bounds and pl002_01.clt; " "exact CEm034 class-init code is not yet EXE_CONFIRMED."); - assembled->non_canonical_notes.push_back( - "em034 Kalina Ann source-space assembly (slots 20..26/30) is " - "preserved and placed on body joint 9 as a SEMANTIC_CANDIDATE; " - "the exact runtime hand selector/offset still requires CEm034 EXE reverse."); + assembled->inspection.root.properties.push_back({ + "LadyDynamicActors", + "slots25/26/30 remain PAC children: slot25 is CEm034Shl02; " + "slots26+30 are CEm034Shl03. They are spawned runtime actors, " + "not persistent body attachments.", + EvidenceLevel::ExeAndCorpusConfirmed}); + assembled->inspection.root.properties.push_back({ + "LadyComponentRuntime", + "slots20..24 default to BodyStowed; preset1 is ActiveDeployed. " + "component3 preset1 uses RuntimeBodyRootScaled " + "(CEm034+0x43C0, scale source +0x4400), not body joint13.", + EvidenceLevel::ExeConfirmed}); } } // Chains (.clt text slots): player coat slot 12 <- slot 13, enemy From 1239c0628d356e3d018e35dce2f5575ba8edbfe9 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:37:17 +0200 Subject: [PATCH 32/84] Expose canonical Lady attachment matrix builder --- .../main/cpp/include/dmcresource/motion/part_attachment.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index ca1f24bb..1fb58a0e 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -449,6 +449,11 @@ bool set_lady_component_control_domain(Session* session, LadyComponentBinding& binding, LadyControlDomain domain) noexcept; +// Canonical MOD/CEm034 local matrix: translation + XYZ Euler using the +// recovered DMC3 transform-domain composition. +[[nodiscard]] Matrix4 attach_local_matrix(const std::array& translation, + const std::array& rotation_xyz_radians) noexcept; + // Translation plus Rz x Ry x Rx (0x1403304A0 order). [[nodiscard]] Matrix4 attach_local_matrix_zyx(const std::array& translation, const std::array& rotation_xyz_radians) noexcept; From 30dfe87daa9085dacba293795272790d58f42db2 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:38:03 +0200 Subject: [PATCH 33/84] Test canonical Lady component assembly and reject joint9 fallback --- app/src/test/native/pac_assembly_test.cpp | 110 ++++++++++++++++++---- 1 file changed, 90 insertions(+), 20 deletions(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 15a67153..62d132a7 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -163,6 +163,32 @@ std::vector make_spatial_mod() { return bytes; } +std::vector make_lady_body_mod() { + auto bytes = make_spatial_mod(); + bytes.resize(0x580U, 0U); + put_u8(bytes, 0x11U, 23U); + put_u64(bytes, 0x20U, 0x200U); + + // 23-node canonical MOD transform-domain shell. A simple chain is enough + // for the assembly regression: the test verifies exact CEm034 attachment + // selectors/offsets, not the retail Lady rest pose itself. + put_u32(bytes, 0x200U, 0x20U); // parent[23] + put_u32(bytes, 0x204U, 0x40U); // order[23] + put_u32(bytes, 0x208U, 0x60U); // adapter[23] + put_u32(bytes, 0x20CU, 0x80U); // transforms[23] + + for (std::size_t node = 0U; node < 23U; ++node) { + put_u8(bytes, 0x220U + node, + node == 0U ? 0xFFU : static_cast(node - 1U)); + put_u8(bytes, 0x240U + node, static_cast(node)); + put_u8(bytes, 0x260U + node, 0U); + put_transform(bytes, 0x280U + node * 0x20U, + 0.0F, node == 0U ? 0.0F : 1.0F, 0.0F, + node == 0U ? 0.0F : 1.0F); + } + return bytes; +} + // Three-node MOT: node 0 translation-x only, one compression-2 track with // keys (frame 0 -> 10.0) and (frame 10 -> 20.0). std::vector make_translation_mot() { @@ -267,19 +293,19 @@ int main() { nested_motion.bytes.data(), nested_motion.bytes.size()); assert(both.ok && both.animated_parts == 2U); - // em034.pac carries two mutually-exclusive Lady appearance sets plus - // equipment MODs. The viewer must never overlay all of them at once. + // em034.pac: body/hair + five persistent CEm034 components. + // Dynamic Shl resources (25/26/30) stay browsable but must not be overlaid. + const auto lady_body = make_lady_body_mod(); std::vector> lady_payloads(35U); - lady_payloads[1] = mod; + lady_payloads[1] = lady_body; lady_payloads[17] = mod; - // Keep the v70 weapon slots physically non-empty so this synthetic PAC - // does not turn zero-length same-offset entries into aliases of the next - // MOD. Opaque payloads are enough here because this test exercises the - // appearance-selection contract, not Kalina Ann geometry. - for (const std::size_t slot : {20U, 21U, 22U, 23U, 24U, 25U, 26U, 30U}) { + for (const std::size_t slot : {20U, 21U, 22U, 23U, 24U}) { + lady_payloads[slot] = mod; + } + for (const std::size_t slot : {25U, 26U, 30U}) { lady_payloads[slot] = opaque; } - lady_payloads[32] = mod; + lady_payloads[32] = lady_body; lady_payloads[34] = mod; const auto lady_pac = make_pac(lady_payloads); auto lady = dmcresource::open_session( @@ -290,30 +316,74 @@ int main() { assert(lady_variants.size() == 2U); assert(lady_variants[0].label == "Lady · costume 1"); assert(lady_variants[1].label == "Lady · costume 2"); - assert(lady_variants[0].include_top_level_mod_count == 10U); - assert(lady_variants[0].texture_override_count == 10U); - assert(lady_variants[0].part_attachment_count == 9U); + assert(lady_variants[0].include_top_level_mod_count == 7U); + assert(lady_variants[0].texture_override_count == 7U); + assert(lady_variants[0].part_attachment_count == 6U); + + // Hair remains structural; persistent equipment is now exact EXE evidence. assert(lady_variants[0].part_attachments[0].child_model_slot == 17U); assert(lady_variants[0].part_attachments[0].host_joint == 5U); assert(lady_variants[0].part_attachments[0].structural_confirmed); - assert(lady_variants[0].part_attachments[1].child_model_slot == 20U); - assert(lady_variants[0].part_attachments[1].host_joint == 9U); - assert(!lady_variants[0].part_attachments[1].structural_confirmed); + assert(!lady_variants[0].part_attachments[0].exe_confirmed); + + const std::array expected_slots{20U, 21U, 22U, 23U, 24U}; + const std::array expected_stowed_joints{3U, 14U, 16U, 19U, 14U}; + for (std::size_t i = 0U; i < expected_slots.size(); ++i) { + const auto& a = lady_variants[0].part_attachments[i + 1U]; + assert(a.child_model_slot == expected_slots[i]); + assert(a.host_joint == expected_stowed_joints[i]); + assert(a.structural_confirmed); + assert(a.exe_confirmed); + assert(a.explicit_offset); + } + assert(lady_variants[0].part_attachments[1].translation[0] == -2.0F); + assert(lady_variants[0].part_attachments[1].translation[1] == -20.0F); + assert(lady_variants[0].part_attachments[1].translation[2] == -17.0F); assert(lady_variants[1].texture_overrides[2].model_slot == 20U); assert(lady_variants[1].texture_overrides[2].texture_slot == 33U); auto lady_first = assembly::assemble_pac(*lady, &report, "em034.pac", 0U); assert(lady_first != nullptr); - assert(report.models == 2U); - assert(lady_first->composite_parts.size() == 2U); + assert(report.models == 7U); + assert(lady_first->composite_parts.size() == 7U); + assert(lady_first->lady_component_bindings.size() == 5U); assert(lady_first->composite_parts[0].name.find("slot_0001.mod") != std::string::npos); assert(lady_first->composite_parts[1].name.find("slot_0017.mod") != std::string::npos); - assert(lady_first->inspection.root.properties.back().key == "AppearanceTexturePairing"); + for (std::size_t i = 0U; i < 5U; ++i) { + const auto& binding = lady_first->lady_component_bindings[i]; + assert(binding.component == i); + assert(binding.model_slot == expected_slots[i]); + assert(binding.preset == dmcresource::motion::LadyPlacementPreset::BodyStowed); + assert(binding.control_domain == + dmcresource::motion::LadyControlDomain::BodyConstraint); + assert(lady_first->composite_parts[binding.part].placement.attachment_selector == + expected_stowed_joints[i]); + } + + // Dynamic resources are still present in the PAC child graph but absent + // from the persistent composite. + for (const auto& part : lady_first->composite_parts) { + assert(part.name.find("slot_0025.mod") == std::string::npos); + assert(part.name.find("slot_0026.mod") == std::string::npos); + assert(part.name.find("slot_0030.mod") == std::string::npos); + } + + // Exact preset switching works for body-joint components. Component3 + // active mode uses CEm034+0x43C0 and must refuse a fake joint13 fallback. + assert(dmcresource::motion::set_lady_component_preset( + lady_first.get(), lady_first->lady_component_bindings[0], + dmcresource::motion::LadyPlacementPreset::ActiveDeployed)); + assert(lady_first->composite_parts[ + lady_first->lady_component_bindings[0].part].placement.attachment_selector == 9U); + assert(!dmcresource::motion::set_lady_component_preset( + lady_first.get(), lady_first->lady_component_bindings[3], + dmcresource::motion::LadyPlacementPreset::ActiveDeployed)); auto lady_second = assembly::assemble_pac(*lady, &report, "em034.pac", 1U); assert(lady_second != nullptr); - assert(report.models == 2U); - assert(lady_second->composite_parts.size() == 2U); + assert(report.models == 7U); + assert(lady_second->composite_parts.size() == 7U); + assert(lady_second->lady_component_bindings.size() == 5U); assert(lady_second->composite_parts[0].name.find("slot_0032.mod") != std::string::npos); assert(lady_second->composite_parts[1].name.find("slot_0034.mod") != std::string::npos); From f5df76d392192a9dd14a9279b2c52e3d7380104f Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:38:17 +0200 Subject: [PATCH 34/84] Fix Lady assembly test includes --- app/src/test/native/pac_assembly_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 62d132a7..892b0f33 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -2,6 +2,7 @@ #include "dmcresource/pac_assembly.h" #include "dmcresource/resource_session.h" +#include #include #include #include From e239993982cd88f5f3cabccaae700997e9f627e4 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:39:52 +0200 Subject: [PATCH 35/84] Expose generic five-channel MotionScript signals --- .../cpp/include/dmcresource/motion/motion_script.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/motion_script.h b/app/src/main/cpp/include/dmcresource/motion/motion_script.h index 2c264982..fea517d8 100644 --- a/app/src/main/cpp/include/dmcresource/motion/motion_script.h +++ b/app/src/main/cpp/include/dmcresource/motion/motion_script.h @@ -34,6 +34,14 @@ struct WeaponStateKey final { std::uint8_t state{}; }; +// Raw opcode-3 five-channel payload at one script time. This is the generic +// MotionScript contract used by CEm034; player weapon state remains a +// projection of channel byte 1 (b2 low 6 bits). +struct ScriptSignalKey final { + float after_frame{-1.0F}; + std::array channels{}; +}; + // What one script does, walked like the interpreter (first block chain up to // the motion end, a loop jump or a hand-over to another MOT). struct ScriptSummary final { @@ -45,6 +53,7 @@ struct ScriptSummary final { bool loops{}; // opcode 2 (backward jump) bool hands_over{}; // a second opcode 1 std::vector states; + std::vector signals; std::array opcodes{}; // count per opcode (0..63) }; @@ -89,6 +98,10 @@ class MotionScriptFile final { [[nodiscard]] std::vector weapon_states(std::size_t bank, std::size_t action) const; + // Full opcode-3 five-channel timeline for enemy/boss consumers. + [[nodiscard]] std::vector signals(std::size_t bank, + std::size_t action) const; + // Motion resources an action plays (empty without table B). [[nodiscard]] std::vector resources(std::size_t bank, std::size_t action) const; From cf368af9ceaa089366ae876ba9ba2b85db77a0eb Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:39:55 +0200 Subject: [PATCH 36/84] Parse all five MotionScript signal channels --- app/src/main/cpp/modules/motion/motion_script.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/cpp/modules/motion/motion_script.cpp b/app/src/main/cpp/modules/motion/motion_script.cpp index 8781a7ed..9a27cc4e 100644 --- a/app/src/main/cpp/modules/motion/motion_script.cpp +++ b/app/src/main/cpp/modules/motion/motion_script.cpp @@ -156,6 +156,10 @@ std::optional MotionScriptFile::summarize(std::size_t bank, break; } if (op == 3U && p + 6U <= s.size()) { + out.signals.push_back({ + after, + {s[p + 1U], s[p + 2U], s[p + 3U], s[p + 4U], s[p + 5U]}, + }); const auto state = static_cast(s[p + 2U] & 0x3FU); if (state != 0U) out.states.push_back({after, state}); } @@ -172,6 +176,12 @@ std::vector MotionScriptFile::weapon_states(std::size_t bank, return summary ? std::move(summary->states) : std::vector{}; } +std::vector MotionScriptFile::signals(std::size_t bank, + std::size_t action) const { + auto summary = summarize(bank, action); + return summary ? std::move(summary->signals) : std::vector{}; +} + std::vector MotionScriptFile::resources(std::size_t bank, std::size_t action) const { std::vector out; From 8ed5598b9a34dbc76f97e127c7a3e1fca01393ec Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:41:10 +0200 Subject: [PATCH 37/84] Add CEm034 state and signal runtime bridge API --- .../dmcresource/motion/part_attachment.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index 1fb58a0e..2da11c31 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -449,6 +449,27 @@ bool set_lady_component_control_domain(Session* session, LadyComponentBinding& binding, LadyControlDomain domain) noexcept; +struct LadyRuntimeApplyResult final { + bool recognized{}; + bool fully_materialized{true}; + bool runtime_side_effect{}; + std::uint32_t changed_components{}; + // -1 = no dynamic actor event; otherwise CEm034Shl00..05 index. + std::int8_t dynamic_actor{-1}; +}; + +// Apply the recovered CEm034 state-entry baseline/overrides. The binding state +// is updated even if an exact preview cannot be materialized (currently only +// component3 ActiveDeployed's RuntimeBodyRootScaled parent). +[[nodiscard]] LadyRuntimeApplyResult apply_lady_state_entry( + Session* session, std::uint16_t state) noexcept; + +// Consume one signal value exactly as CEm034's direct 0x140059350 consumers do. +// lane is 0/1 for the two em034_012 controllers; channel is 0..4. +[[nodiscard]] LadyRuntimeApplyResult apply_lady_signal( + Session* session, std::uint16_t state, + std::uint8_t lane, std::uint8_t channel, std::uint8_t value) noexcept; + // Canonical MOD/CEm034 local matrix: translation + XYZ Euler using the // recovered DMC3 transform-domain composition. [[nodiscard]] Matrix4 attach_local_matrix(const std::array& translation, From 4a0021a875fdfb681897a60f117b9d7c6ef909f1 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:41:13 +0200 Subject: [PATCH 38/84] Implement CEm034 state and signal component bridge --- .../cpp/modules/motion/part_attachment.cpp | 224 +++++++++++++++++- 1 file changed, 212 insertions(+), 12 deletions(-) diff --git a/app/src/main/cpp/modules/motion/part_attachment.cpp b/app/src/main/cpp/modules/motion/part_attachment.cpp index cdbb9230..0990834f 100644 --- a/app/src/main/cpp/modules/motion/part_attachment.cpp +++ b/app/src/main/cpp/modules/motion/part_attachment.cpp @@ -620,6 +620,7 @@ bool set_lady_component_preset(Session* session, // points CCnsMatrix at CEm034+0x43C0. That matrix is body-root-derived and // uniformly scaled from runtime +0x4400. Do not approximate it with joint13. if (record.effective_parent == LadyEffectiveParent::RuntimeBodyRootScaled) { + binding.preset = preset; return false; } @@ -637,22 +638,221 @@ bool set_lady_component_control_domain(Session* session, LadyComponentBinding& binding, LadyControlDomain domain) noexcept { if (session == nullptr || binding.component != 0U) return false; - if (domain == LadyControlDomain::IndependentMotionScript) { - // Canonical CEm034 transitions first restore component0 to preset0, - // then start em034_013 and clear +0x4020. The independent controller - // itself is a separate playback layer; this binding records that owner. - if (!set_lady_component_preset( - session, binding, LadyPlacementPreset::BodyStowed)) { - return false; - } - binding.control_domain = domain; - return true; + // Placement and control are orthogonal in CEm034. Most independent-script + // entries use BodyStowed, but states 0x7C/0x7D retain ActiveDeployed while + // +0x4020 selects em034_013. Never collapse these into one scalar state. + binding.control_domain = domain; + return true; +} + +namespace { + +[[nodiscard]] LadyComponentBinding* lady_binding(Session* session, + std::uint8_t component) noexcept { + if (session == nullptr) return nullptr; + for (auto& binding : session->lady_component_bindings) { + if (binding.component == component) return &binding; } - if (!set_lady_component_preset(session, binding, binding.preset)) return false; - binding.control_domain = LadyControlDomain::BodyConstraint; + return nullptr; +} + +[[nodiscard]] bool apply_lady_preset(Session* session, + std::uint8_t component, + LadyPlacementPreset preset, + LadyRuntimeApplyResult& out) noexcept { + auto* binding = lady_binding(session, component); + if (binding == nullptr) return false; + const bool materialized = set_lady_component_preset(session, *binding, preset); + // Runtime state remains known even when the preview lacks the special + // RuntimeBodyRootScaled materialization bridge. + binding->preset = preset; + ++out.changed_components; + if (!materialized) out.fully_materialized = false; return true; } +void set_lady_domain(Session* session, LadyControlDomain domain, + LadyRuntimeApplyResult& out) noexcept { + if (auto* binding = lady_binding(session, 0U); binding != nullptr) { + if (set_lady_component_control_domain(session, *binding, domain)) { + ++out.changed_components; + } + } +} + +[[nodiscard]] bool in_range(std::uint16_t v, + std::uint16_t first, + std::uint16_t last) noexcept { + return v >= first && v <= last; +} + +void reset_lady_components(Session* session, LadyRuntimeApplyResult& out) noexcept { + for (std::uint8_t component = 0U; component < 5U; ++component) { + (void)apply_lady_preset( + session, component, LadyPlacementPreset::BodyStowed, out); + } + set_lady_domain(session, LadyControlDomain::BodyConstraint, out); +} + +} // namespace + +LadyRuntimeApplyResult apply_lady_state_entry(Session* session, + std::uint16_t state) noexcept { + LadyRuntimeApplyResult out; + if (session == nullptr || session->lady_component_bindings.empty()) { + out.fully_materialized = false; + return out; + } + + const bool group_component1 = + state == 0x2EU || in_range(state, 0x30U, 0x52U); + const bool group_component0_active = + in_range(state, 0x53U, 0x59U) || state == 0x5EU || state == 0x61U; + const bool group_component0_independent = + in_range(state, 0x5AU, 0x5DU) || in_range(state, 0x64U, 0x73U); + + if (group_component1) { + out.recognized = true; + reset_lady_components(session, out); + (void)apply_lady_preset( + session, 1U, LadyPlacementPreset::ActiveDeployed, out); + } else if (group_component0_active) { + out.recognized = true; + reset_lady_components(session, out); + (void)apply_lady_preset( + session, 0U, LadyPlacementPreset::ActiveDeployed, out); + if (state == 0x5EU) out.dynamic_actor = 3; // immediate CEm034Shl03 + } else if (group_component0_independent) { + out.recognized = true; + reset_lady_components(session, out); + set_lady_domain(session, LadyControlDomain::IndependentMotionScript, out); + } else if (state == 0x5FU || state == 0x62U) { + out.recognized = true; + reset_lady_components(session, out); + (void)apply_lady_preset( + session, 0U, LadyPlacementPreset::ActiveDeployed, out); + } else if (state == 0x60U || state == 0x63U) { + out.recognized = true; + reset_lady_components(session, out); + (void)apply_lady_preset( + session, 0U, LadyPlacementPreset::ActiveDeployed, out); + (void)apply_lady_preset( + session, 4U, LadyPlacementPreset::ActiveDeployed, out); + } else if (state == 0x7BU) { + out.recognized = true; + reset_lady_components(session, out); + set_lady_domain(session, LadyControlDomain::IndependentMotionScript, out); + } else if (state == 0x7CU || state == 0x7DU) { + out.recognized = true; + reset_lady_components(session, out); + (void)apply_lady_preset( + session, 0U, LadyPlacementPreset::ActiveDeployed, out); + set_lady_domain(session, LadyControlDomain::IndependentMotionScript, out); + } else if (state == 0x7FU) { + out.recognized = true; + reset_lady_components(session, out); + (void)apply_lady_preset( + session, 1U, LadyPlacementPreset::ActiveDeployed, out); + (void)apply_lady_preset( + session, 2U, LadyPlacementPreset::ActiveDeployed, out); + } else if (state == 0x81U) { + out.recognized = true; + reset_lady_components(session, out); + (void)apply_lady_preset( + session, 3U, LadyPlacementPreset::ActiveDeployed, out); + } else if (state == 0x85U || state == 0x8FU) { + out.recognized = true; + reset_lady_components(session, out); + } + return out; +} + +LadyRuntimeApplyResult apply_lady_signal(Session* session, + std::uint16_t state, + std::uint8_t lane, + std::uint8_t channel, + std::uint8_t value) noexcept { + LadyRuntimeApplyResult out; + if (session == nullptr || session->lady_component_bindings.empty() || + lane > 1U || channel > 4U || value == 0U) { + if (session == nullptr) out.fully_materialized = false; + return out; + } + + const auto preset = [&](std::uint8_t component, LadyPlacementPreset p) { + out.recognized = true; + (void)apply_lady_preset(session, component, p, out); + }; + const auto spawn = [&](std::int8_t actor) { + out.recognized = true; + out.dynamic_actor = actor; + }; + const auto side_effect = [&]() { + out.recognized = true; + out.runtime_side_effect = true; + }; + + if (state == 0x2AU && lane == 0U && channel == 0U) { + if (value == 1U) preset(1U, LadyPlacementPreset::ActiveDeployed); + else if (value == 2U) preset(1U, LadyPlacementPreset::BodyStowed); + } else if (state == 0x2BU && lane == 0U && channel == 0U) { + if (value == 1U) preset(4U, LadyPlacementPreset::ActiveDeployed); + else if (value == 2U) preset(4U, LadyPlacementPreset::BodyStowed); + } else if (state == 0x7BU && lane == 0U && channel == 0U && value == 1U) { + preset(0U, LadyPlacementPreset::ActiveDeployed); + set_lady_domain(session, LadyControlDomain::BodyConstraint, out); + } else if ((state == 0x5CU || state == 0x5DU) && + lane == 0U && channel == 0U && value == 1U) { + preset(0U, LadyPlacementPreset::ActiveDeployed); + set_lady_domain(session, LadyControlDomain::BodyConstraint, out); + } else if ((state == 0x59U || state == 0x61U) && + lane == 0U && channel == 0U && value == 1U) { + preset(0U, LadyPlacementPreset::BodyStowed); + set_lady_domain(session, LadyControlDomain::IndependentMotionScript, out); + } else if (in_range(state, 0x56U, 0x58U) && + lane == 1U && channel == 0U && value == 1U) { + spawn(2); // CEm034Shl02 + } else if (((in_range(state, 0x34U, 0x36U) || + in_range(state, 0x3BU, 0x3DU) || + in_range(state, 0x42U, 0x44U) || + in_range(state, 0x49U, 0x4BU) || + in_range(state, 0x50U, 0x52U)) && + lane == 1U && channel == 0U && value == 1U) || + (state == 0x7FU && lane == 1U && channel == 0U && value == 1U)) { + spawn(0); // CEm034Shl00 + } else if (((in_range(state, 0x53U, 0x55U) || + state == 0x5AU || state == 0x5BU || state == 0x5EU || + in_range(state, 0x64U, 0x73U)) && + lane == 1U && channel == 0U && value == 1U)) { + spawn(1); // CEm034Shl01 + } else if (state == 0x81U && lane == 1U) { + if (channel == 0U && value == 1U) spawn(5); + else if (channel == 1U && value == 1U) side_effect(); + else if (channel == 2U && value == 1U) { + preset(3U, LadyPlacementPreset::BodyStowed); + } + } else if (state == 0x85U && lane == 1U) { + if (channel == 1U && value == 1U) { + preset(4U, LadyPlacementPreset::ActiveDeployed); + } else if (channel == 1U && value == 2U) { + preset(4U, LadyPlacementPreset::BodyStowed); + } else if (channel == 0U && (value == 1U || value == 2U)) { + side_effect(); + } + } else if (state == 0x8FU && lane == 1U && + channel == 0U && value == 1U) { + spawn(4); // CEm034Shl04 + } else if ((state == 0x60U || state == 0x63U) && + lane == 1U && (channel == 0U || channel == 1U) && + value == 1U) { + side_effect(); + } else if (state == 0x7FU && lane == 1U && channel == 1U) { + side_effect(); + } + + return out; +} + const WeaponStateRecord* weapon_state_record(std::string_view class_name, std::uint8_t state) noexcept { if (state >= 24U) return nullptr; From 4666ed0c640971ce2daf31ff6eea060bb3ea3df9 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:41:48 +0200 Subject: [PATCH 39/84] Cover CEm034 state signal and action50 regressions --- app/src/test/native/pac_assembly_test.cpp | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 892b0f33..c7989652 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -379,6 +379,84 @@ int main() { assert(!dmcresource::motion::set_lady_component_preset( lady_first.get(), lady_first->lady_component_bindings[3], dmcresource::motion::LadyPlacementPreset::ActiveDeployed)); + assert(lady_first->lady_component_bindings[3].preset == + dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + + // State-entry and signal bridge regressions from the canonical CEm034 + // dispatcher. These specifically guard the old single-joint/single-state + // model and the corrected action50 channel trace. + { + const auto entry = dmcresource::motion::apply_lady_state_entry( + lady_first.get(), 0x7FU); + assert(entry.recognized && entry.fully_materialized); + assert(lady_first->lady_component_bindings[1].preset == + dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + assert(lady_first->lady_component_bindings[2].preset == + dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + assert(lady_first->composite_parts[ + lady_first->lady_component_bindings[1].part].placement.attachment_selector == 9U); + assert(lady_first->composite_parts[ + lady_first->lady_component_bindings[2].part].placement.attachment_selector == 13U); + } + { + const auto entry = dmcresource::motion::apply_lady_state_entry( + lady_first.get(), 0x81U); + assert(entry.recognized); + assert(!entry.fully_materialized); // CEm034+0x43C0, never fake joint13. + assert(lady_first->lady_component_bindings[3].preset == + dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + const auto restore = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x81U, 1U, 2U, 1U); + assert(restore.recognized && restore.fully_materialized); + assert(lady_first->lady_component_bindings[3].preset == + dmcresource::motion::LadyPlacementPreset::BodyStowed); + } + { + const auto entry = dmcresource::motion::apply_lady_state_entry( + lady_first.get(), 0x85U); + assert(entry.recognized); + const auto deploy = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x85U, 1U, 1U, 1U); + assert(deploy.recognized); + assert(lady_first->lady_component_bindings[4].preset == + dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + const auto flag_off = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x85U, 1U, 0U, 2U); + assert(flag_off.recognized && flag_off.runtime_side_effect); + // frame39/ch0=2 is NOT the placement restore. + assert(lady_first->lady_component_bindings[4].preset == + dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + const auto stow = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x85U, 1U, 1U, 2U); + assert(stow.recognized); + assert(lady_first->lady_component_bindings[4].preset == + dmcresource::motion::LadyPlacementPreset::BodyStowed); + } + { + const auto entry = dmcresource::motion::apply_lady_state_entry( + lady_first.get(), 0x59U); + assert(entry.recognized); + assert(lady_first->lady_component_bindings[0].preset == + dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + const auto delayed = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x59U, 0U, 0U, 1U); + assert(delayed.recognized); + assert(lady_first->lady_component_bindings[0].preset == + dmcresource::motion::LadyPlacementPreset::BodyStowed); + assert(lady_first->lady_component_bindings[0].control_domain == + dmcresource::motion::LadyControlDomain::IndependentMotionScript); + } + { + const auto rocket = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x56U, 1U, 0U, 1U); + assert(rocket.recognized && rocket.dynamic_actor == 2); + const auto grapple = dmcresource::motion::apply_lady_state_entry( + lady_first.get(), 0x5EU); + assert(grapple.recognized && grapple.dynamic_actor == 3); + const auto shl04 = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x8FU, 1U, 0U, 1U); + assert(shl04.recognized && shl04.dynamic_actor == 4); + } auto lady_second = assembly::assemble_pac(*lady, &report, "em034.pac", 1U); assert(lady_second != nullptr); From e8e1239a6e71cf4f6590d76b5a8576ae4c035854 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:48:54 +0200 Subject: [PATCH 40/84] Model exact Lady component3 runtime scale --- .../cpp/include/dmcresource/motion/part_attachment.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index 2da11c31..07f26d28 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -402,6 +402,9 @@ struct LadyComponentBinding final { std::uint32_t model_slot{}; LadyPlacementPreset preset{LadyPlacementPreset::BodyStowed}; LadyControlDomain control_domain{LadyControlDomain::BodyConstraint}; + // CEm034+0x4400 for component3 ActiveDeployed. EXE writes 1.0 every + // action46 update and promotes it to 1.5 while lane1/channel1 == 1. + float runtime_uniform_scale{1.0F}; }; struct LadyDynamicActorContract final { @@ -449,6 +452,12 @@ bool set_lady_component_control_domain(Session* session, LadyComponentBinding& binding, LadyControlDomain domain) noexcept; +// Exact CEm034 component3 active-parent scalar (+0x4400). Re-materializes +// RuntimeBodyRootScaled when component3 is currently ActiveDeployed. +bool set_lady_component_runtime_scale(Session* session, + LadyComponentBinding& binding, + float uniform_scale) noexcept; + struct LadyRuntimeApplyResult final { bool recognized{}; bool fully_materialized{true}; From 069c1ffd9fbdace6f0427215dbe5600aebc37d3a Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:49:33 +0200 Subject: [PATCH 41/84] Materialize Lady component3 body-root scale exactly --- .../cpp/modules/motion/part_attachment.cpp | 61 ++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/app/src/main/cpp/modules/motion/part_attachment.cpp b/app/src/main/cpp/modules/motion/part_attachment.cpp index 0990834f..40bd348d 100644 --- a/app/src/main/cpp/modules/motion/part_attachment.cpp +++ b/app/src/main/cpp/modules/motion/part_attachment.cpp @@ -617,11 +617,28 @@ bool set_lady_component_preset(Session* session, const auto& record = contract->presets[index]; // CEm034 component3/preset1 deliberately bypasses serialized node13 and - // points CCnsMatrix at CEm034+0x43C0. That matrix is body-root-derived and - // uniformly scaled from runtime +0x4400. Do not approximate it with joint13. + // points CCnsMatrix at CEm034+0x43C0. Canonical EXE reconstruction: + // +0x43C0 = bodyManager(+0x850)->currentWorld(+0x110) + // effective parent = S(+0x4400) * bodyRoot + // Both retail Lady bodies (slots1/32) have node0 identity at rest, so the + // same result is materialized as (local * S) * hostRootWorld. if (record.effective_parent == LadyEffectiveParent::RuntimeBodyRootScaled) { + world::Matrix4f local{}; + local.values = + attach_local_matrix(record.translation, record.rotation_xyz_radians).values; + auto scale = world::identity_matrix(); + scale.values[0] = binding.runtime_uniform_scale; + scale.values[5] = binding.runtime_uniform_scale; + scale.values[10] = binding.runtime_uniform_scale; + const auto local_scaled = world::multiply_dmc3_matrices(local, scale); + Matrix4 offset; + offset.values = local_scaled.values; + if (!attach_part_skeleton( + session, binding.host_part, binding.part, 0U, false, offset)) { + return false; + } binding.preset = preset; - return false; + return true; } if (!attach_part_skeleton( @@ -631,6 +648,9 @@ bool set_lady_component_preset(Session* session, return false; } binding.preset = preset; + if (binding.component == 3U && preset == LadyPlacementPreset::BodyStowed) { + binding.runtime_uniform_scale = 1.0F; + } return true; } @@ -645,6 +665,19 @@ bool set_lady_component_control_domain(Session* session, return true; } +bool set_lady_component_runtime_scale(Session* session, + LadyComponentBinding& binding, + float uniform_scale) noexcept { + if (session == nullptr || binding.component != 3U || + !std::isfinite(uniform_scale) || uniform_scale < 0.0F) { + return false; + } + binding.runtime_uniform_scale = uniform_scale; + if (binding.preset != LadyPlacementPreset::ActiveDeployed) return true; + return set_lady_component_preset( + session, binding, LadyPlacementPreset::ActiveDeployed); +} + namespace { [[nodiscard]] LadyComponentBinding* lady_binding(Session* session, @@ -758,6 +791,9 @@ LadyRuntimeApplyResult apply_lady_state_entry(Session* session, } else if (state == 0x81U) { out.recognized = true; reset_lady_components(session, out); + if (auto* binding = lady_binding(session, 3U); binding != nullptr) { + binding->runtime_uniform_scale = 1.0F; + } (void)apply_lady_preset( session, 3U, LadyPlacementPreset::ActiveDeployed, out); } else if (state == 0x85U || state == 0x8FU) { @@ -774,7 +810,7 @@ LadyRuntimeApplyResult apply_lady_signal(Session* session, std::uint8_t value) noexcept { LadyRuntimeApplyResult out; if (session == nullptr || session->lady_component_bindings.empty() || - lane > 1U || channel > 4U || value == 0U) { + lane > 1U || channel > 4U) { if (session == nullptr) out.fully_materialized = false; return out; } @@ -826,9 +862,20 @@ LadyRuntimeApplyResult apply_lady_signal(Session* session, lane == 1U && channel == 0U && value == 1U)) { spawn(1); // CEm034Shl01 } else if (state == 0x81U && lane == 1U) { - if (channel == 0U && value == 1U) spawn(5); - else if (channel == 1U && value == 1U) side_effect(); - else if (channel == 2U && value == 1U) { + if (channel == 0U && value == 1U) { + spawn(5); + } else if (channel == 1U) { + // 0x140169EC2 writes 1.0 every state81 update; 0x140169EE0 + // promotes it to 1.5 only while channel1 == 1. + out.recognized = true; + if (auto* binding = lady_binding(session, 3U); binding != nullptr) { + const float scale = value == 1U ? 1.5F : 1.0F; + if (!set_lady_component_runtime_scale(session, *binding, scale)) { + out.fully_materialized = false; + } + ++out.changed_components; + } + } else if (channel == 2U && value == 1U) { preset(3U, LadyPlacementPreset::BodyStowed); } } else if (state == 0x85U && lane == 1U) { From fd4c1433091fc28e80f1980643e53148222a8477 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 05:49:53 +0200 Subject: [PATCH 42/84] Test exact Lady component3 root-scale bridge --- app/src/test/native/pac_assembly_test.cpp | 27 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index c7989652..2996bd7b 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -369,18 +369,22 @@ int main() { assert(part.name.find("slot_0030.mod") == std::string::npos); } - // Exact preset switching works for body-joint components. Component3 - // active mode uses CEm034+0x43C0 and must refuse a fake joint13 fallback. + // Exact preset switching works for body-joint components and for + // component3's RuntimeBodyRootScaled parent. The latter materializes on + // body root node0 and never uses the raw serialized node13 as its parent. assert(dmcresource::motion::set_lady_component_preset( lady_first.get(), lady_first->lady_component_bindings[0], dmcresource::motion::LadyPlacementPreset::ActiveDeployed)); assert(lady_first->composite_parts[ lady_first->lady_component_bindings[0].part].placement.attachment_selector == 9U); - assert(!dmcresource::motion::set_lady_component_preset( + assert(dmcresource::motion::set_lady_component_preset( lady_first.get(), lady_first->lady_component_bindings[3], dmcresource::motion::LadyPlacementPreset::ActiveDeployed)); assert(lady_first->lady_component_bindings[3].preset == dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + assert(lady_first->composite_parts[ + lady_first->lady_component_bindings[3].part].placement.attachment_selector == 0U); + assert(lady_first->lady_component_bindings[3].runtime_uniform_scale == 1.0F); // State-entry and signal bridge regressions from the canonical CEm034 // dispatcher. These specifically guard the old single-joint/single-state @@ -401,10 +405,23 @@ int main() { { const auto entry = dmcresource::motion::apply_lady_state_entry( lady_first.get(), 0x81U); - assert(entry.recognized); - assert(!entry.fully_materialized); // CEm034+0x43C0, never fake joint13. + assert(entry.recognized && entry.fully_materialized); assert(lady_first->lady_component_bindings[3].preset == dmcresource::motion::LadyPlacementPreset::ActiveDeployed); + assert(lady_first->lady_component_bindings[3].runtime_uniform_scale == 1.0F); + + const auto enlarge = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x81U, 1U, 1U, 1U); + assert(enlarge.recognized && enlarge.fully_materialized); + assert(lady_first->lady_component_bindings[3].runtime_uniform_scale == 1.5F); + assert(lady_first->composite_parts[ + lady_first->lady_component_bindings[3].part].placement.attachment_selector == 0U); + + const auto normalize = dmcresource::motion::apply_lady_signal( + lady_first.get(), 0x81U, 1U, 1U, 0U); + assert(normalize.recognized && normalize.fully_materialized); + assert(lady_first->lady_component_bindings[3].runtime_uniform_scale == 1.0F); + const auto restore = dmcresource::motion::apply_lady_signal( lady_first.get(), 0x81U, 1U, 2U, 1U); assert(restore.recognized && restore.fully_materialized); From b39ddd5d2a696ec9181855d7cbe850113fa6e186 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:16:44 +0200 Subject: [PATCH 43/84] Retain multiple boss MotionScript controllers --- .../cpp/include/dmcresource/resource_session.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index 176d5a91..726aff7c 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -88,9 +88,21 @@ struct Session { // SHW shadow hulls placed on this session's models (PAC assembly). std::vector shadow_bindings; - // Player motion script (pl000.pac slot 5) and the weapon parts whose - // attach record follows it during playback. + enum class MotionScriptRole : std::uint8_t { + Primary, + LadyBody, + LadyComponent0, + }; + struct MotionScriptBinding final { + std::uint32_t archive_slot{}; + MotionScriptRole role{MotionScriptRole::Primary}; + std::shared_ptr script; + }; + + // Backward-compatible primary script used by player weapon-state playback. + // Enemy/boss archives may retain multiple independent controllers below. std::shared_ptr motion_script; + std::vector motion_scripts; std::vector weapon_bindings; // Boss-Lady CEm034 uses a different runtime: five persistent component From 5c463c89f8c9ab18eb5810178165f9e5c2febfdd Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:17:03 +0200 Subject: [PATCH 44/84] Retain em034 body and component0 MotionScripts --- app/src/main/cpp/modules/pac_assembly.cpp | 40 +++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index 0d8af557..5e7d9581 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -943,9 +943,12 @@ std::unique_ptr assemble_archives(std::span archi report.motions = motions.size(); } assembled->motion_library = std::move(motions); - // Motion script: IPlayer pl000.pac slot 5 (0x1401EF461); enemies bind - // their own script slot (em028 slot 10 at 0x140131037, em000 slot 38 - // at 0x1400982D9). Identified by its tables (MotionScriptFile). + // Motion scripts. Players normally have one primary script. CEm034 + // canonically owns two independent controllers: + // slot12 -> body script / two object lanes; + // slot13 -> component0 (slot20) independent script. + // Retain every top-level MotionScript instead of discarding all but the + // first; keep motion_script as the backward-compatible primary view. for (const auto& e : entries) { if (e.archive != 0U || !e.container.empty() || !e.slot || e.kind.format != Format::MotionScript) { @@ -957,10 +960,33 @@ std::unique_ptr assemble_archives(std::span archi report.detail_attachments += " motionScript=slot" + std::to_string(*e.slot) + "(" + std::to_string(script->bank_count()) + " banks)"; auto shared = std::make_shared(std::move(*script)); - if (!shared->nested()) label_enemy_motions(*shared, archive_name, assembled->motion_library, - &report.detail_attachments); - assembled->motion_script = std::move(shared); - break; + + Session::MotionScriptRole role = Session::MotionScriptRole::Primary; + const bool lady_archive = + archive_name.find("em034") != std::string_view::npos; + if (lady_archive && *e.slot == 12U) { + role = Session::MotionScriptRole::LadyBody; + } else if (lady_archive && *e.slot == 13U) { + role = Session::MotionScriptRole::LadyComponent0; + } + + assembled->motion_scripts.push_back({ + *e.slot, role, shared, + }); + + // Motion-card labels belong to the body/primary script. The + // component0 script drives a companion model and must not rename + // the body MOT library. + if (!shared->nested() && + role != Session::MotionScriptRole::LadyComponent0) { + label_enemy_motions(*shared, archive_name, assembled->motion_library, + &report.detail_attachments); + } + + if (assembled->motion_script == nullptr || + role == Session::MotionScriptRole::LadyBody) { + assembled->motion_script = shared; + } } assembled->children = pac.children; (void)archive_name; From 72d598a7ede6fee84e74d3f7e1968e3def947663 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:18:15 +0200 Subject: [PATCH 45/84] Expose canonical Lady bank4 action state mapping --- .../cpp/include/dmcresource/motion/part_attachment.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index 07f26d28..a8c844a4 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -473,6 +473,16 @@ struct LadyRuntimeApplyResult final { [[nodiscard]] LadyRuntimeApplyResult apply_lady_state_entry( Session* session, std::uint16_t state) noexcept; +// Canonical CEm034 bank4 mapping recovered from 0x14016A410: +// action0 -> state83 ... action60 -> state143. +[[nodiscard]] constexpr std::optional lady_state_for_script_action( + std::size_t bank, std::size_t action) noexcept { + return bank == 4U && action <= 60U + ? std::optional{ + static_cast(83U + action)} + : std::nullopt; +} + // Consume one signal value exactly as CEm034's direct 0x140059350 consumers do. // lane is 0/1 for the two em034_012 controllers; channel is 0..4. [[nodiscard]] LadyRuntimeApplyResult apply_lady_signal( From 70b989e8185ca65b582a3945fb83e6a119736205 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:36:11 +0200 Subject: [PATCH 46/84] Switch Lady slot20 between host and independent MOT domains --- .../cpp/modules/motion/part_attachment.cpp | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/modules/motion/part_attachment.cpp b/app/src/main/cpp/modules/motion/part_attachment.cpp index 40bd348d..769a7754 100644 --- a/app/src/main/cpp/modules/motion/part_attachment.cpp +++ b/app/src/main/cpp/modules/motion/part_attachment.cpp @@ -657,12 +657,29 @@ bool set_lady_component_preset(Session* session, bool set_lady_component_control_domain(Session* session, LadyComponentBinding& binding, LadyControlDomain domain) noexcept { - if (session == nullptr || binding.component != 0U) return false; + if (session == nullptr || binding.component != 0U || + binding.part >= session->composite_parts.size()) { + return false; + } // Placement and control are orthogonal in CEm034. Most independent-script // entries use BodyStowed, but states 0x7C/0x7D retain ActiveDeployed while // +0x4020 selects em034_013. Never collapse these into one scalar state. - binding.control_domain = domain; - return true; + auto& part = session->composite_parts[binding.part]; + if (domain == LadyControlDomain::IndependentMotionScript) { + // Freeze the currently resolved equipment world as the root for its + // own 3-node MOT domain. HostJointSkeleton must be disabled, otherwise + // the generic motion player correctly treats the part as host-driven + // and refuses to animate it independently. + if (!part.placement.resolved) return false; + part.placement.mode = CompositePlacementMode::HostJoint; + binding.control_domain = domain; + return true; + } + + binding.control_domain = LadyControlDomain::BodyConstraint; + // Re-enter the EXE placement helper domain and rebuild the current preset + // against the freshly posed Lady body. + return set_lady_component_preset(session, binding, binding.preset); } bool set_lady_component_runtime_scale(Session* session, From cd7f8f039de26c7713321a7141a721384d6a801f Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:36:20 +0200 Subject: [PATCH 47/84] Retain assembled archive identity for script routing --- app/src/main/cpp/include/dmcresource/resource_session.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index 726aff7c..0fba7971 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -63,6 +63,10 @@ struct Session { std::string detail; std::string trace; + // Canonical source archive name for assembled PAC sessions. Runtime + // MotionScript-to-MOT routing uses it to apply EXE-confirmed group maps + // where available and deterministic corpus binding otherwise. + std::string archive_name; bool renderable{}; // Motions discovered while assembling a PAC (read-only copies of the From 2c8eba6015d8df424f092a7e3aadc590442e89a2 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:36:31 +0200 Subject: [PATCH 48/84] Store PAC archive name in assembled sessions --- app/src/main/cpp/modules/pac_assembly.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index 5e7d9581..2be3440a 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -988,8 +988,8 @@ std::unique_ptr assemble_archives(std::span archi assembled->motion_script = shared; } } + assembled->archive_name = std::string{archive_name}; assembled->children = pac.children; - (void)archive_name; if (!assembled->children.empty()) { assembled->capabilities |= capability(ResourceCapability::ChildResources); } From 263e4b964f54bc8fa3240c1de76ddac4eb7f10cd Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:40:07 +0200 Subject: [PATCH 49/84] Add separate MotionScript playback API --- .../cpp/include/dmcresource/motion/motion_player.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/motion_player.h b/app/src/main/cpp/include/dmcresource/motion/motion_player.h index ae14ce95..aaaff83b 100644 --- a/app/src/main/cpp/include/dmcresource/motion/motion_player.h +++ b/app/src/main/cpp/include/dmcresource/motion/motion_player.h @@ -49,4 +49,17 @@ void clear_motion(Session* session) noexcept; // same binding load_motion uses). Host-joint parts (coats) do not count. [[nodiscard]] bool motion_can_drive(const Session& session, std::span mot) noexcept; +// MotionScript playback is intentionally separate from raw MOT playback. +// A PAC may retain multiple independent script controllers; each script button +// can address only MOTs referenced by that script's resource table. +[[nodiscard]] std::size_t motion_script_count(const Session* session) noexcept; +[[nodiscard]] std::uint32_t motion_script_slot(const Session* session, + std::size_t script_index) noexcept; +[[nodiscard]] bool motion_script_can_play_motion(const Session* session, + std::size_t script_index, + std::size_t motion_index) noexcept; +[[nodiscard]] MotionLoadReport load_scripted_motion(Session* session, + std::size_t script_index, + std::size_t motion_index) noexcept; + } // namespace dmcresource::motion From 32212aa002d424b56696ed80bb0e45310ba01a30 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:43:25 +0200 Subject: [PATCH 50/84] Preserve script-addressable MOT packs before filtering --- app/src/main/cpp/modules/pac_assembly.cpp | 107 ++++++++++++++++------ 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index 2be3440a..26a91679 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -927,28 +927,11 @@ std::unique_ptr assemble_archives(std::span archi } report.models = models.size(); - report.motions = motions.size(); - // Only motions that can drive this scene are offered (e.g. em000's - // body motions are hidden on the CEm005Shl01 shell). - { - std::vector drivable; - drivable.reserve(motions.size()); - for (auto& m : motions) { - if (motion::motion_can_drive(*assembled, m.bytes)) drivable.push_back(std::move(m)); - } - if (drivable.size() != motions.size()) { - report.detail_attachments += " motionsHidden=" + std::to_string(motions.size() - drivable.size()); - } - motions = std::move(drivable); - report.motions = motions.size(); - } - assembled->motion_library = std::move(motions); - // Motion scripts. Players normally have one primary script. CEm034 - // canonically owns two independent controllers: - // slot12 -> body script / two object lanes; - // slot13 -> component0 (slot20) independent script. - // Retain every top-level MotionScript instead of discarding all but the - // first; keep motion_script as the backward-compatible primary view. + + // Parse every top-level MotionScript before filtering the MOT library. + // A script may target a component that is host-constrained in the rest + // pose (CEm034 slot20); those MOTs still need to remain visible so the + // user can launch them through the independent script controller. for (const auto& e : entries) { if (e.archive != 0U || !e.container.empty() || !e.slot || e.kind.format != Format::MotionScript) { @@ -970,16 +953,14 @@ std::unique_ptr assemble_archives(std::span archi role = Session::MotionScriptRole::LadyComponent0; } - assembled->motion_scripts.push_back({ - *e.slot, role, shared, - }); + assembled->motion_scripts.push_back({*e.slot, role, shared}); - // Motion-card labels belong to the body/primary script. The - // component0 script drives a companion model and must not rename - // the body MOT library. + // Motion-card action labels belong to the body/primary script. + // Component0 has its own script button and must not overwrite the + // body card's label. if (!shared->nested() && role != Session::MotionScriptRole::LadyComponent0) { - label_enemy_motions(*shared, archive_name, assembled->motion_library, + label_enemy_motions(*shared, archive_name, motions, &report.detail_attachments); } @@ -988,6 +969,74 @@ std::unique_ptr assemble_archives(std::span archi assembled->motion_script = shared; } } + + // Build the generic script->motion-pack reachability before pruning. + // This preserves component-only MOTs (notably em034 slot11) while + // retaining the old rule that unrelated, non-drivable packs stay out + // of the motion strip. + std::vector motion_packs; + for (const auto& m : motions) { + if (m.pack_slot < 0 || m.mot_slot < 0) continue; + const auto pack_slot = static_cast(m.pack_slot); + auto it = std::find_if( + motion_packs.begin(), motion_packs.end(), + [pack_slot](const motion::MotionPack& p) { + return p.archive_slot == pack_slot; + }); + if (it == motion_packs.end()) { + motion_packs.push_back({pack_slot, {}}); + it = std::prev(motion_packs.end()); + } + it->slots.push_back(static_cast(m.mot_slot)); + } + + std::vector script_reachable_packs; + for (const auto& binding : assembled->motion_scripts) { + if (binding.script == nullptr) continue; + for (const auto& group : motion::bind_motion_groups( + *binding.script, motion_packs, archive_name)) { + if (group.archive_slot) { + script_reachable_packs.push_back(*group.archive_slot); + } + } + // Canonical CEm034 component0 route: + // em034_013 bank4 -> top-level PAC slot11. + if (binding.role == Session::MotionScriptRole::LadyComponent0 && + archive_name.find("em034") != std::string_view::npos) { + script_reachable_packs.push_back(11U); + } + } + std::sort(script_reachable_packs.begin(), script_reachable_packs.end()); + script_reachable_packs.erase( + std::unique(script_reachable_packs.begin(), + script_reachable_packs.end()), + script_reachable_packs.end()); + + report.motions = motions.size(); + { + std::vector drivable; + drivable.reserve(motions.size()); + for (auto& m : motions) { + const bool script_reachable = + m.pack_slot >= 0 && + std::binary_search( + script_reachable_packs.begin(), + script_reachable_packs.end(), + static_cast(m.pack_slot)); + if (script_reachable || + motion::motion_can_drive(*assembled, m.bytes)) { + drivable.push_back(std::move(m)); + } + } + if (drivable.size() != motions.size()) { + report.detail_attachments += + " motionsHidden=" + + std::to_string(motions.size() - drivable.size()); + } + motions = std::move(drivable); + report.motions = motions.size(); + } + assembled->motion_library = std::move(motions); assembled->archive_name = std::string{archive_name}; assembled->children = pac.children; if (!assembled->children.empty()) { From 69022cd703d846d2596b2dff8c5f1b15503a3446 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:44:41 +0200 Subject: [PATCH 51/84] Add role-aware MotionScript to MOT routing --- .../main/cpp/modules/motion/motion_player.cpp | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index 590a1254..471c17cc 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -113,10 +113,125 @@ struct MotionState final { float scroll_clock{}; // Weapon attach states from the motion script (pl000.pac slot 5). std::vector weapon_keys; + + // Script Play is distinct from raw MOT playback. + bool script_driven{}; + Session::MotionScriptRole script_role{Session::MotionScriptRole::Primary}; + std::uint32_t script_slot{}; + std::size_t script_bank{}; + std::size_t script_action{}; + std::optional lady_state; + std::vector script_signals; + float lady_runtime_frame{-1.0F}; + bool lady_entry_applied{}; + std::int8_t last_dynamic_actor{-1}; }; namespace { +struct ScriptMotionSelection final { + std::size_t bank{}; + std::size_t action{}; + std::uint16_t resource_id{}; +}; + +[[nodiscard]] bool is_em034(const Session& session) noexcept { + return session.archive_name.find("em034") != std::string::npos; +} + +[[nodiscard]] std::vector session_motion_packs(const Session& session) { + std::vector packs; + for (const auto& motion : session.motion_library) { + if (motion.pack_slot < 0 || motion.mot_slot < 0) continue; + const auto slot = static_cast(motion.pack_slot); + auto it = std::find_if( + packs.begin(), packs.end(), + [slot](const MotionPack& p) { return p.archive_slot == slot; }); + if (it == packs.end()) { + packs.push_back({slot, {}}); + it = std::prev(packs.end()); + } + it->slots.push_back(static_cast(motion.mot_slot)); + } + return packs; +} + +[[nodiscard]] std::optional lady_group_for_pack( + const Session& session, + const Session::MotionScriptBinding& binding, + const Session::MotionPayload& motion) noexcept { + if (!is_em034(session) || motion.pack_slot < 0) return std::nullopt; + + if (binding.role == Session::MotionScriptRole::LadyComponent0) { + // EXE_AND_CORPUS_CONFIRMED: + // em034_013 bank4 -> top-level PAC slot11. + return motion.pack_slot == 11 ? std::optional{4U} + : std::nullopt; + } + + if (binding.role == Session::MotionScriptRole::LadyBody) { + // CEm034 body motion packs are laid out in PAC order for script groups + // 0..4: top-level slots2..6. The group6 resource remains external/ + // unresolved and is intentionally not fabricated here. + if (motion.pack_slot >= 2 && motion.pack_slot <= 6) { + return static_cast(motion.pack_slot - 2); + } + } + return std::nullopt; +} + +[[nodiscard]] std::optional pick_script_motion( + const Session& session, + const Session::MotionScriptBinding& binding, + const Session::MotionPayload& motion) { + if (binding.script == nullptr || motion.mot_slot < 0) return std::nullopt; + + std::vector groups; + if (const auto lady = lady_group_for_pack(session, binding, motion)) { + groups.push_back(*lady); + } else if (motion.pack_slot >= 0) { + const auto packs = session_motion_packs(session); + for (const auto& g : bind_motion_groups( + *binding.script, packs, session.archive_name)) { + if (g.archive_slot && + static_cast(*g.archive_slot) == motion.pack_slot) { + groups.push_back(g.group); + } + } + } + + for (const auto group : groups) { + const auto slot = static_cast(motion.mot_slot); + if (group > 655U || slot >= 100U) continue; + const auto id = static_cast(group * 100U + slot); + const auto actions = binding.script->actions_for(id); + if (actions.empty()) continue; + + const ScriptAction* pick = &actions.front(); + for (const auto& action : actions) { + if (action.bank == group && action.action == slot) { + pick = &action; + break; + } + if (action.bank == group && pick->bank != group) { + pick = &action; + } else if (action.action == slot && pick->action != slot) { + pick = &action; + } + } + return ScriptMotionSelection{pick->bank, pick->action, id}; + } + return std::nullopt; +} + +[[nodiscard]] LadyComponentBinding* component0_binding(Session* session) noexcept { + if (session == nullptr) return nullptr; + for (auto& binding : session->lady_component_bindings) { + if (binding.component == 0U) return &binding; + } + return nullptr; +} + [[nodiscard]] std::optional bind_part(const RenderScene& scene, std::size_t vertex_begin, std::size_t node_begin, From cf109d4b246ad2fb9186304b081191502b279bea Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:45:28 +0200 Subject: [PATCH 52/84] Execute CEm034 MotionScript runtime by frame --- .../main/cpp/modules/motion/motion_player.cpp | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index 471c17cc..f554d2b1 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -284,6 +284,91 @@ struct ScriptMotionSelection final { return part; } +void reset_lady_runtime(Session* session) noexcept { + if (session == nullptr) return; + for (auto& binding : session->lady_component_bindings) { + (void)set_lady_component_preset( + session, binding, LadyPlacementPreset::BodyStowed); + binding.runtime_uniform_scale = 1.0F; + if (binding.component == 0U) { + (void)set_lady_component_control_domain( + session, binding, LadyControlDomain::BodyConstraint); + } + } +} + +[[nodiscard]] bool apply_lady_script_runtime(Session* session, + MotionState& state, + float frame) noexcept { + if (session == nullptr || !state.script_driven || + state.script_role != Session::MotionScriptRole::LadyBody || + !state.lady_state.has_value()) { + return true; + } + + const bool replay = !state.lady_entry_applied || + frame < state.lady_runtime_frame; + if (replay) { + const auto entry = apply_lady_state_entry(session, *state.lady_state); + if (!entry.recognized) return false; + state.lady_entry_applied = true; + state.lady_runtime_frame = -1.0F; + if (entry.dynamic_actor >= 0) state.last_dynamic_actor = entry.dynamic_actor; + } + + // State0x81/action46 rebuilds +0x4400 to 1.0 every actor update, and + // promotes it to 1.5 only on the channel1 pulse. Reproduce that pulse + // rather than incorrectly making 1.5 a sticky placement state. + if (*state.lady_state == 0x81U) { + for (auto& binding : session->lady_component_bindings) { + if (binding.component == 3U) { + (void)set_lady_component_runtime_scale(session, binding, 1.0F); + break; + } + } + } + + float latest_scale_pulse = -std::numeric_limits::infinity(); + for (const auto& signal : state.script_signals) { + if (!(frame > signal.after_frame)) continue; + if (!replay && signal.after_frame < state.lady_runtime_frame) continue; + + for (std::uint8_t lane = 0U; lane < 2U; ++lane) { + for (std::uint8_t channel = 0U; channel < signal.channels.size(); ++channel) { + const auto value = signal.channels[channel]; + if (value == 0U && + !(*state.lady_state == 0x81U && channel == 1U)) { + continue; + } + const auto applied = apply_lady_signal( + session, *state.lady_state, lane, channel, value); + if (applied.dynamic_actor >= 0) { + state.last_dynamic_actor = applied.dynamic_actor; + } + if (*state.lady_state == 0x81U && lane == 1U && + channel == 1U && value == 1U) { + latest_scale_pulse = + std::max(latest_scale_pulse, signal.after_frame); + } + } + } + } + + if (*state.lady_state == 0x81U && + std::isfinite(latest_scale_pulse) && + frame > latest_scale_pulse + 1.0F) { + for (auto& binding : session->lady_component_bindings) { + if (binding.component == 3U) { + (void)set_lady_component_runtime_scale(session, binding, 1.0F); + break; + } + } + } + + state.lady_runtime_frame = frame; + return true; +} + } // namespace MotionLoadReport load_motion(Session* session, From 8c80cdfc1340009d87d017e25b1fde5e57a60a28 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:45:55 +0200 Subject: [PATCH 53/84] Implement separate native MotionScript playback --- .../main/cpp/modules/motion/motion_player.cpp | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index f554d2b1..d90a9b3e 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -576,6 +576,7 @@ bool apply_motion_frame(Session* session, float frame) noexcept { if (wanted != binding.state) (void)set_weapon_state(session, binding, wanted); } } + if (!apply_lady_script_runtime(session, state, frame)) return false; (void)apply_part_attachments(session, cloth_steps); (void)apply_uv_scrolls(session, state.scroll_clock); HierarchyOverlay overlay; @@ -640,6 +641,127 @@ bool motion_can_drive(const Session& session, std::span mot) } } +std::size_t motion_script_count(const Session* session) noexcept { + return session != nullptr ? session->motion_scripts.size() : 0U; +} + +std::uint32_t motion_script_slot(const Session* session, + std::size_t script_index) noexcept { + if (session == nullptr || script_index >= session->motion_scripts.size()) { + return std::numeric_limits::max(); + } + return session->motion_scripts[script_index].archive_slot; +} + +bool motion_script_can_play_motion(const Session* session, + std::size_t script_index, + std::size_t motion_index) noexcept { + if (session == nullptr || + script_index >= session->motion_scripts.size() || + motion_index >= session->motion_library.size()) { + return false; + } + try { + return pick_script_motion( + *session, + session->motion_scripts[script_index], + session->motion_library[motion_index]) + .has_value(); + } catch (...) { + return false; + } +} + +MotionLoadReport load_scripted_motion(Session* session, + std::size_t script_index, + std::size_t motion_index) noexcept { + MotionLoadReport report; + if (session == nullptr || + script_index >= session->motion_scripts.size() || + motion_index >= session->motion_library.size()) { + report.detail = "MotionScript: invalid script or MOT index"; + return report; + } + try { + const auto binding = session->motion_scripts[script_index]; + const auto payload = session->motion_library[motion_index]; + const auto selection = pick_script_motion(*session, binding, payload); + if (!selection.has_value() || binding.script == nullptr) { + report.detail = + "MotionScript slot" + std::to_string(binding.archive_slot) + + " does not reference " + payload.name; + return report; + } + + if (binding.role == Session::MotionScriptRole::LadyComponent0) { + auto* component = component0_binding(session); + if (component == nullptr) { + report.detail = "MotionScript: Lady component0 binding is unavailable"; + return report; + } + const auto initial = + selection->bank == 4U && + (selection->action == 41U || selection->action == 42U) + ? LadyPlacementPreset::ActiveDeployed + : LadyPlacementPreset::BodyStowed; + if (!set_lady_component_preset(session, *component, initial) || + !set_lady_component_control_domain( + session, *component, + LadyControlDomain::IndependentMotionScript)) { + report.detail = + "MotionScript: Lady component0 could not enter independent control"; + return report; + } + } + + report = load_motion( + session, payload.name, payload.bytes.data(), payload.bytes.size()); + if (!report.ok || session->motion == nullptr) return report; + + auto& state = *session->motion; + state.script_driven = true; + state.script_role = binding.role; + state.script_slot = binding.archive_slot; + state.script_bank = selection->bank; + state.script_action = selection->action; + state.script_signals = + binding.script->signals(selection->bank, selection->action); + + if (binding.role == Session::MotionScriptRole::LadyBody) { + state.lady_state = + lady_state_for_script_action(selection->bank, selection->action); + if (state.lady_state.has_value()) { + state.lady_entry_applied = false; + state.lady_runtime_frame = -1.0F; + if (!apply_motion_frame(session, 0.0F)) { + clear_motion(session); + report = {}; + report.detail = + "MotionScript: Lady runtime bridge rejected first frame"; + return report; + } + } + } + + report.detail = + "MotionScript slot" + std::to_string(binding.archive_slot) + + " bank" + std::to_string(selection->bank) + + "/action" + std::to_string(selection->action) + + " -> " + report.detail; + if (binding.role == Session::MotionScriptRole::LadyBody && + !state.lady_state.has_value()) { + report.detail += + "\nLady runtime state bridge: action parsed, state semantics " + "not promoted for this bank/action."; + } + return report; + } catch (...) { + report = {}; + report.detail = "MotionScript: playback failed"; + return report; + } +} + std::span motion_rest_vertices(const Session* session) noexcept { if (!has_motion(session)) return {}; return session->motion->source_vertices; From 5b4f58305b299ecb723d95cc2393b6c38e434010 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:46:46 +0200 Subject: [PATCH 54/84] Expose MotionScript playback through JNI --- app/src/main/cpp/app_native.cpp | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/app/src/main/cpp/app_native.cpp b/app/src/main/cpp/app_native.cpp index ea78d9a1..4298350d 100644 --- a/app/src/main/cpp/app_native.cpp +++ b/app/src/main/cpp/app_native.cpp @@ -644,6 +644,61 @@ Java_com_dmcrengine_nativeviewer_NativeBridge_motionLibraryPackSlot( session->motion_library[static_cast(index)].pack_slot); } +extern "C" JNIEXPORT jint JNICALL +Java_com_dmcrengine_nativeviewer_NativeBridge_motionScriptCount( + JNIEnv*, jclass, jlong handle) { + const SessionLock jni_lock{session_mutex()}; + const auto count = dmcresource::motion::motion_script_count(from_handle(handle)); + return count > static_cast(std::numeric_limits::max()) + ? std::numeric_limits::max() + : static_cast(count); +} + +extern "C" JNIEXPORT jint JNICALL +Java_com_dmcrengine_nativeviewer_NativeBridge_motionScriptSlot( + JNIEnv*, jclass, jlong handle, jint script_index) { + const SessionLock jni_lock{session_mutex()}; + if (script_index < 0) return -1; + const auto slot = dmcresource::motion::motion_script_slot( + from_handle(handle), static_cast(script_index)); + return slot == std::numeric_limits::max() || + slot > static_cast( + std::numeric_limits::max()) + ? -1 + : static_cast(slot); +} + +extern "C" JNIEXPORT jboolean JNICALL +Java_com_dmcrengine_nativeviewer_NativeBridge_motionScriptCanPlayMotion( + JNIEnv*, jclass, jlong handle, jint script_index, jint motion_index) { + const SessionLock jni_lock{session_mutex()}; + if (script_index < 0 || motion_index < 0) return JNI_FALSE; + return dmcresource::motion::motion_script_can_play_motion( + from_handle(handle), + static_cast(script_index), + static_cast(motion_index)) + ? JNI_TRUE + : JNI_FALSE; +} + +extern "C" JNIEXPORT jstring JNICALL +Java_com_dmcrengine_nativeviewer_NativeBridge_loadLibraryMotionScript( + JNIEnv* env, jclass, jlong handle, jint script_index, jint motion_index) { + const SessionLock jni_lock{session_mutex()}; + if (script_index < 0 || motion_index < 0) { + return env->NewStringUTF("MotionScript: invalid index"); + } + try { + auto report = dmcresource::motion::load_scripted_motion( + from_handle(handle), + static_cast(script_index), + static_cast(motion_index)); + return env->NewStringUTF(report.detail.c_str()); + } catch (...) { + return env->NewStringUTF("MotionScript: load failed"); + } +} + extern "C" JNIEXPORT jstring JNICALL Java_com_dmcrengine_nativeviewer_NativeBridge_loadLibraryMotion( JNIEnv* env, jclass, jlong handle, jint index) { From 5542341de1b6c83509f874b4a43105047d6d152a Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:46:56 +0200 Subject: [PATCH 55/84] Expose separate Script Play controls to Android --- .../java/com/dmcrengine/nativeviewer/NativeBridge.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java b/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java index d819db45..c3df88f6 100644 --- a/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java +++ b/app/src/main/java/com/dmcrengine/nativeviewer/NativeBridge.java @@ -72,6 +72,16 @@ public static native boolean render(long handle, int width, int height, // motion did not come from a nested pack. Used only for UI grouping. public static native int motionLibraryPackSlot(long handle, int index); + // MotionScript playback is separate from raw MOT playback. A PAC may own + // several independent controllers; every script gets its own Play button + // beside each MOT it can actually address. + public static native int motionScriptCount(long handle); + public static native int motionScriptSlot(long handle, int scriptIndex); + public static native boolean motionScriptCanPlayMotion( + long handle, int scriptIndex, int motionIndex); + public static native String loadLibraryMotionScript( + long handle, int scriptIndex, int motionIndex); + // MOT playback. Frames are MOT timeline units (60 per second in DMC3). // load* return a human-readable report; hasMotion tells whether it bound. public static native String loadLibraryMotion(long handle, int index); From 1f8b3c28a5f6d20dc3359a99fc3adef726581229 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:47:56 +0200 Subject: [PATCH 56/84] Add separate Script Play buttons before each MOT --- .../dmcrengine/nativeviewer/MainActivity.java | 128 ++++++++++++++++-- 1 file changed, 115 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java b/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java index f5444343..5110ae28 100644 --- a/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java +++ b/app/src/main/java/com/dmcrengine/nativeviewer/MainActivity.java @@ -127,6 +127,8 @@ private static final class StagedAsset { private long pendingExportSession; private int pendingPtxPart = -1; private int selectedMotionIndex = -1; + // -1 = raw MOT playback; >=0 = MotionScript button/controller index. + private int selectedScriptIndex = -1; private LinearLayout headerBar; // Hidden by the top-edge swipe: bars and the visibility each had. private boolean uiHidden; @@ -1127,9 +1129,15 @@ private void refreshMotionStrip() { ArrayList motions = motionEntries(); if (motions.isEmpty() || !isRootScene()) { motionScroll.setVisibility(View.GONE); - if (motions.isEmpty()) selectedMotionIndex = -1; + if (motions.isEmpty()) { + selectedMotionIndex = -1; + selectedScriptIndex = -1; + } return; } + + final int scriptCount = session == 0 + ? 0 : Math.max(0, NativeBridge.motionScriptCount(session)); int previousPack = Integer.MIN_VALUE; for (int index = 0; index < motions.size(); ++index) { final int motionIndex = index; @@ -1139,14 +1147,55 @@ private void refreshMotionStrip() { } previousPack = entry.packSlot; - final boolean active = index == selectedMotionIndex; - Button button = makeSquareButton("", "Play animation " + entry.name, 11f); - button.setText(motionCardLabel(entry.name)); - button.setActivated(active); - button.setAlpha(active ? 1.0f : 0.72f); - button.setOnClickListener(v -> selectMotion(motionIndex)); - addToolButton(motionBar, button); - motionCards.add(button); + // One visual row per MOT: + // [Script Play ...] [raw MOT]. + // Script buttons stay visible even when this script cannot address + // the MOT, so the PAC's controller count is always explicit. + LinearLayout row = new LinearLayout(this); + row.setOrientation(LinearLayout.HORIZONTAL); + row.setGravity(Gravity.CENTER_VERTICAL); + + if (entry.libraryIndex >= 0) { + for (int script = 0; script < scriptCount; ++script) { + final int scriptIndex = script; + final int slot = NativeBridge.motionScriptSlot(session, scriptIndex); + final boolean available = NativeBridge.motionScriptCanPlayMotion( + session, scriptIndex, entry.libraryIndex); + final boolean activeScript = + index == selectedMotionIndex && + scriptIndex == selectedScriptIndex; + + Button scriptButton = makeSquareButton( + "▶\nS" + (slot >= 0 ? Integer.toString(slot) : "?"), + "Play " + entry.name + " through MotionScript " + + (slot >= 0 ? "slot " + slot : Integer.toString(scriptIndex)), + 9f); + scriptButton.setEnabled(available); + scriptButton.setActivated(activeScript); + scriptButton.setAlpha( + activeScript ? 1.0f : (available ? 0.78f : 0.30f)); + scriptButton.setOnClickListener( + v -> selectMotionScript(motionIndex, scriptIndex)); + addToolButton(row, scriptButton); + } + } + + final boolean activeMot = + index == selectedMotionIndex && selectedScriptIndex < 0; + Button motButton = makeSquareButton( + "", "Play raw MOT " + entry.name, 11f); + motButton.setText(motionCardLabel(entry.name)); + motButton.setActivated(activeMot); + motButton.setAlpha(activeMot ? 1.0f : 0.72f); + motButton.setOnClickListener(v -> selectMotion(motionIndex)); + addToolButton(row, motButton); + + LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, dp(TOOL_SIZE_DP)); + rowParams.setMarginStart(dp(1)); + rowParams.setMarginEnd(dp(1)); + motionBar.addView(row, rowParams); + motionCards.add(row); } motionScroll.setVisibility(uiHidden ? View.GONE : View.VISIBLE); } @@ -1192,11 +1241,12 @@ private ArrayList motionAssets() { return result; } - // Tap a card: bind + play. Tap the playing card again: pause/resume. + // Raw MOT playback: no MotionScript state/channels are executed. private void selectMotion(int index) { ArrayList motions = motionEntries(); if (session == 0 || index < 0 || index >= motions.size()) return; - if (index == selectedMotionIndex && NativeBridge.hasMotion(session)) { + if (index == selectedMotionIndex && selectedScriptIndex < 0 && + NativeBridge.hasMotion(session)) { if (renderView.isMotionPlaying()) { renderView.pauseMotion(); } else { @@ -1221,13 +1271,63 @@ private void selectMotion(int index) { final boolean bound = NativeBridge.hasMotion(session); selectedMotionIndex = bound ? index : -1; + selectedScriptIndex = -1; + refreshMotionStrip(); + if (bound) renderView.startMotion(); + else renderView.renderNow(); + notice(bound ? entry.name + " · raw MOT ▶" + : (report == null ? "Motion rejected" : report), + Toast.LENGTH_LONG); + rebuildInfo(titleView.getText().toString()); + if (report != null && !report.isEmpty()) { + setInfo(infoText + "\nMOTION · RAW MOT\n" + report + "\n"); + } + } + + // MotionScript playback: script action + MOT + class runtime bridge. + private void selectMotionScript(int index, int scriptIndex) { + ArrayList motions = motionEntries(); + if (session == 0 || index < 0 || index >= motions.size() || + scriptIndex < 0) { + return; + } + final MotionEntry entry = motions.get(index); + if (entry.libraryIndex < 0 || + !NativeBridge.motionScriptCanPlayMotion( + session, scriptIndex, entry.libraryIndex)) { + return; + } + + if (index == selectedMotionIndex && scriptIndex == selectedScriptIndex && + NativeBridge.hasMotion(session)) { + if (renderView.isMotionPlaying()) { + renderView.pauseMotion(); + } else { + renderView.startMotion(); + } + return; + } + + renderView.pauseMotion(); + final int slot = NativeBridge.motionScriptSlot(session, scriptIndex); + final String report = NativeBridge.loadLibraryMotionScript( + session, scriptIndex, entry.libraryIndex); + final boolean bound = NativeBridge.hasMotion(session); + selectedMotionIndex = bound ? index : -1; + selectedScriptIndex = bound ? scriptIndex : -1; refreshMotionStrip(); if (bound) renderView.startMotion(); else renderView.renderNow(); - notice(bound ? entry.name + " ▶" : (report == null ? "Motion rejected" : report), Toast.LENGTH_LONG); + + final String scriptName = + slot >= 0 ? "S" + slot : "Script " + scriptIndex; + notice(bound ? scriptName + " · " + entry.name + " ▶" + : (report == null ? "MotionScript rejected" : report), + Toast.LENGTH_LONG); rebuildInfo(titleView.getText().toString()); if (report != null && !report.isEmpty()) { - setInfo(infoText + "\nMOTION\n" + report + "\n"); + setInfo(infoText + "\nMOTION SCRIPT · " + scriptName + + "\n" + report + "\n"); } } @@ -1843,6 +1943,7 @@ private void resetCompositionState() { sharedModelPtxUri = null; stagedAssets.clear(); selectedMotionIndex = -1; + selectedScriptIndex = -1; assembledPacUri = null; addedPacUris.clear(); } @@ -1888,6 +1989,7 @@ private ParcelFileDescriptor openReadOnlyDescriptor(Uri uri) throws FileNotFound private void activateSession(long handle, String name) { session = handle; selectedMotionIndex = -1; + selectedScriptIndex = -1; titleView.setText(name); renderView.setSession(session); refreshBlackWidowState(); From 62baa09d41d4d19c1c4c4cceed3754a6125c0e93 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:48:35 +0200 Subject: [PATCH 57/84] Add script-free library MOT playback helper --- app/src/main/cpp/include/dmcresource/motion/motion_player.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/motion_player.h b/app/src/main/cpp/include/dmcresource/motion/motion_player.h index aaaff83b..6f36bc20 100644 --- a/app/src/main/cpp/include/dmcresource/motion/motion_player.h +++ b/app/src/main/cpp/include/dmcresource/motion/motion_player.h @@ -29,6 +29,12 @@ struct MotionLoadReport final { const std::uint8_t* bytes, std::size_t size) noexcept; +// Raw library MOT playback. This remains script-free, but may temporarily +// release a component from its host constraint when the MOT targets that +// component's own skeleton (CEm034 slot20 / PAC11). +[[nodiscard]] MotionLoadReport load_library_motion(Session* session, + std::size_t motion_index) noexcept; + // Pose the Session at `frame` (MOT timeline units, 60 per second in DMC3). // Skins the render mesh through inverseRest * currentWorld and refreshes the // skeleton overlay. Returns false when no motion is bound. From 446b9c3ac2ab5a951060588ff93e6309644d2d2d Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:48:37 +0200 Subject: [PATCH 58/84] Separate raw Lady MOT control and reset runtime on clear --- .../main/cpp/modules/motion/motion_player.cpp | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index d90a9b3e..1e9f3758 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -491,6 +491,48 @@ MotionLoadReport load_motion(Session* session, } } +MotionLoadReport load_library_motion(Session* session, + std::size_t motion_index) noexcept { + MotionLoadReport report; + if (session == nullptr || motion_index >= session->motion_library.size()) { + report.detail = "Motion: invalid library index"; + return report; + } + try { + clear_motion(session); + const auto payload = session->motion_library[motion_index]; + + // Raw MOT stays raw: no MotionScript state/channel execution. For the + // slot20-only PAC11 motions we only release the model from its body + // constraint so its own three-node MOT can be evaluated. + if (is_em034(*session) && payload.pack_slot == 11) { + auto* component = component0_binding(session); + if (component == nullptr || + !set_lady_component_preset( + session, *component, LadyPlacementPreset::BodyStowed) || + !set_lady_component_control_domain( + session, *component, + LadyControlDomain::IndependentMotionScript)) { + report.detail = + "Motion: Lady slot20 could not enter standalone MOT domain"; + return report; + } + } + + report = load_motion( + session, payload.name, payload.bytes.data(), payload.bytes.size()); + if (report.ok && is_em034(*session) && payload.pack_slot == 11) { + report.detail = "Raw component MOT (no MotionScript events): " + + report.detail; + } + return report; + } catch (...) { + report = {}; + report.detail = "Motion: raw library playback failed"; + return report; + } +} + bool apply_motion_frame(Session* session, float frame) noexcept { if (session == nullptr || session->motion == nullptr || !std::isfinite(frame)) return false; try { @@ -609,6 +651,10 @@ void clear_motion(Session* session) noexcept { if (binding.state != 0U) moved = set_weapon_state(session, binding, 0U) || moved; } if (moved) (void)apply_part_attachments(session); + if (!session->lady_component_bindings.empty()) { + reset_lady_runtime(session); + (void)apply_part_attachments(session); + } } bool has_motion(const Session* session) noexcept { @@ -683,6 +729,7 @@ MotionLoadReport load_scripted_motion(Session* session, return report; } try { + clear_motion(session); const auto binding = session->motion_scripts[script_index]; const auto payload = session->motion_library[motion_index]; const auto selection = pick_script_motion(*session, binding, payload); From c9bb4074a5fc1b22a51e19bac9642f828492d7d1 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:48:48 +0200 Subject: [PATCH 59/84] Bind canonical em034 body motion groups --- app/src/main/cpp/modules/motion/motion_script.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/cpp/modules/motion/motion_script.cpp b/app/src/main/cpp/modules/motion/motion_script.cpp index 9a27cc4e..c2a03236 100644 --- a/app/src/main/cpp/modules/motion/motion_script.cpp +++ b/app/src/main/cpp/modules/motion/motion_script.cpp @@ -280,13 +280,16 @@ namespace { struct ExeGroups final { std::string_view stem; - std::array slots; // -1 = not set by the class + std::array slots; // group -> top-level PAC slot; -1 = not closed }; -// Motion PAC arrays read from the class inits (see bind_motion_groups). -constexpr std::array kExeGroups{{ - {"em028", {2, 3, -1, -1}}, - {"em000", {35, -1, -1, -1}}, +// Motion PAC arrays read from class init/runtime evidence. A single physical +// pack may serve more than one script resource group (CEm034 slot6 serves +// groups 4 and 6), so EXE-confirmed bindings are intentionally reusable. +constexpr std::array kExeGroups{{ + {"em028", {2, 3, -1, -1, -1, -1, -1}}, + {"em000", {35, -1, -1, -1, -1, -1, -1}}, + {"em034", {-1, 3, 4, 5, 6, -1, 6}}, }}; } // namespace From 15bb6c66e46f55b29a58f85ca613485a7c5fc076 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:49:00 +0200 Subject: [PATCH 60/84] Link MOT rows to every MotionScript controller --- .../cpp/include/dmcresource/resource_session.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index 0fba7971..bae78833 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -72,6 +72,18 @@ struct Session { // Motions discovered while assembling a PAC (read-only copies of the // retained payloads). Played through motion::load_motion. struct MotionPayload final { + struct ScriptLink final { + std::size_t script_index{}; + std::size_t bank{}; + std::size_t action{}; + // CEm034 state that starts this action, when recovered. -1 means + // the action can still be executed by its script controller but + // no actor-state entry is implied by current evidence. + int lady_state{-1}; + // Body lane mask: bit0=lane0, bit1=lane1. 0 for non-body scripts. + std::uint8_t lady_lane_mask{}; + }; + std::string name; std::vector bytes; // Motion script address (pl000_00_.pac, MOT index); -1 unknown. @@ -83,6 +95,8 @@ struct Session { int mot_slot{-1}; // Script actions that play it ("act 3,7 loop"), empty when unknown. std::string actions; + // Every script controller in this PAC that references this MOT. + std::vector script_links; }; std::vector motion_library; From aacc75fc5d5fff7c7d9e3954d6788c221961afd3 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:49:25 +0200 Subject: [PATCH 61/84] Route raw library MOT through script-free component playback --- app/src/main/cpp/app_native.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/app_native.cpp b/app/src/main/cpp/app_native.cpp index 4298350d..f459290b 100644 --- a/app/src/main/cpp/app_native.cpp +++ b/app/src/main/cpp/app_native.cpp @@ -709,10 +709,8 @@ Java_com_dmcrengine_nativeviewer_NativeBridge_loadLibraryMotion( return env->NewStringUTF("Motion: invalid library index"); } try { - // Copy: load_motion() may clear/replace state that references the library. - const auto payload = session->motion_library[static_cast(index)]; - const auto report = dmcresource::motion::load_motion( - session, payload.name, payload.bytes.data(), payload.bytes.size()); + const auto report = dmcresource::motion::load_library_motion( + session, static_cast(index)); return env->NewStringUTF(report.detail.c_str()); } catch (...) { return env->NewStringUTF("Motion: load failed"); } } From 017653cd10fc8ff1373e6742961359576981306a Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:49:52 +0200 Subject: [PATCH 62/84] Use EXE-confirmed CEm034 body motion group map --- .../main/cpp/modules/motion/motion_player.cpp | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index 1e9f3758..5bf67919 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -156,28 +156,41 @@ struct ScriptMotionSelection final { return packs; } -[[nodiscard]] std::optional lady_group_for_pack( +[[nodiscard]] std::vector lady_groups_for_pack( const Session& session, const Session::MotionScriptBinding& binding, - const Session::MotionPayload& motion) noexcept { - if (!is_em034(session) || motion.pack_slot < 0) return std::nullopt; + const Session::MotionPayload& motion) { + std::vector groups; + if (!is_em034(session) || motion.pack_slot < 0) return groups; if (binding.role == Session::MotionScriptRole::LadyComponent0) { // EXE_AND_CORPUS_CONFIRMED: // em034_013 bank4 -> top-level PAC slot11. - return motion.pack_slot == 11 ? std::optional{4U} - : std::nullopt; + if (motion.pack_slot == 11) groups.push_back(4U); + return groups; } if (binding.role == Session::MotionScriptRole::LadyBody) { - // CEm034 body motion packs are laid out in PAC order for script groups - // 0..4: top-level slots2..6. The group6 resource remains external/ - // unresolved and is intentionally not fabricated here. - if (motion.pack_slot >= 2 && motion.pack_slot <= 6) { - return static_cast(motion.pack_slot - 2); + // EXE-confirmed CEm034 body pack map (shared pack reuse is valid): + // group1 -> slot3 + // group2 -> slot4 + // group3 -> slot5 + // group4 -> slot6 + // group6 -> slot6 + // group0 is intentionally left unbound. + switch (motion.pack_slot) { + case 3: groups.push_back(1U); break; + case 4: groups.push_back(2U); break; + case 5: groups.push_back(3U); break; + case 6: + groups.push_back(4U); + groups.push_back(6U); + break; + default: + break; } } - return std::nullopt; + return groups; } [[nodiscard]] std::optional pick_script_motion( @@ -186,10 +199,8 @@ struct ScriptMotionSelection final { const Session::MotionPayload& motion) { if (binding.script == nullptr || motion.mot_slot < 0) return std::nullopt; - std::vector groups; - if (const auto lady = lady_group_for_pack(session, binding, motion)) { - groups.push_back(*lady); - } else if (motion.pack_slot >= 0) { + auto groups = lady_groups_for_pack(session, binding, motion); + if (groups.empty() && motion.pack_slot >= 0) { const auto packs = session_motion_packs(session); for (const auto& g : bind_motion_groups( *binding.script, packs, session.archive_name)) { From 5ea682c38f5ab457827e2f607aab072f4be76969 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:49:57 +0200 Subject: [PATCH 63/84] Encode full CEm034 body script state mapping --- .../dmcresource/motion/part_attachment.h | 65 ++++++++++++++++--- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index a8c844a4..966846c3 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -473,14 +473,63 @@ struct LadyRuntimeApplyResult final { [[nodiscard]] LadyRuntimeApplyResult apply_lady_state_entry( Session* session, std::uint16_t state) noexcept; -// Canonical CEm034 bank4 mapping recovered from 0x14016A410: -// action0 -> state83 ... action60 -> state143. -[[nodiscard]] constexpr std::optional lady_state_for_script_action( - std::size_t bank, std::size_t action) noexcept { - return bank == 4U && action <= 60U - ? std::optional{ - static_cast(83U + action)} - : std::nullopt; +struct LadyBodyScriptState final { + std::uint16_t state{}; + // Which em034_012 controller starts this exact action at state entry: + // bit0 = lane0 (+0x5070), bit1 = lane1 (+0x5190). + std::uint8_t lane_mask{}; +}; + +// Inverse of the canonical CEm034 entry dispatcher at 0x14016A410. +// This returns the primary state for a body-script action. Some states 55..82 +// start a second, different action on the other lane; the returned lane mask +// says which lane(s) execute the requested action. +[[nodiscard]] constexpr std::optional +lady_state_for_body_script_action(std::size_t bank, std::size_t action) noexcept { + if (bank == 0U) { + if (action <= 6U || (action >= 8U && action <= 14U)) { + return LadyBodyScriptState{static_cast(action), 0x3U}; + } + return std::nullopt; + } + if (bank == 1U) { + if (action <= 5U) return LadyBodyScriptState{ + static_cast(15U + action), 0x3U}; + if (action == 7U) return LadyBodyScriptState{22U, 0x3U}; + if (action >= 9U && action <= 11U) return LadyBodyScriptState{ + static_cast(15U + action), 0x3U}; + if (action == 20U) return LadyBodyScriptState{35U, 0x3U}; + if (action >= 23U && action <= 26U) return LadyBodyScriptState{ + static_cast(15U + action), 0x3U}; + return std::nullopt; + } + if (bank == 2U && action <= 3U) { + return LadyBodyScriptState{ + static_cast(42U + action), 0x3U}; + } + if (bank == 3U) { + if (action == 0U) return LadyBodyScriptState{46U, 0x3U}; + if (action >= 2U && action <= 8U) return LadyBodyScriptState{ + static_cast(46U + action), 0x3U}; + if (action >= 9U && action <= 15U) return LadyBodyScriptState{ + static_cast(46U + action), 0x2U}; + if (action >= 16U && action <= 22U) return LadyBodyScriptState{ + static_cast(46U + action), action == 16U ? 0x3U : 0x2U}; + if (action >= 23U && action <= 29U) return LadyBodyScriptState{ + static_cast(46U + action), action == 23U ? 0x3U : 0x2U}; + if (action >= 30U && action <= 36U) return LadyBodyScriptState{ + static_cast(46U + action), action == 30U ? 0x3U : 0x2U}; + return std::nullopt; + } + if (bank == 4U) { + if (action <= 32U) return LadyBodyScriptState{ + static_cast(83U + action), 0x3U}; + if (action >= 40U && action <= 47U) return LadyBodyScriptState{ + static_cast(83U + action), 0x3U}; + if (action == 50U || action == 60U) return LadyBodyScriptState{ + static_cast(83U + action), 0x3U}; + } + return std::nullopt; } // Consume one signal value exactly as CEm034's direct 0x140059350 consumers do. From 4f41d72efddb957c3dc60eff5600644216aeb81e Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:51:38 +0200 Subject: [PATCH 64/84] Honor CEm034 lane-specific Script Play mapping --- .../main/cpp/modules/motion/motion_player.cpp | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index 5bf67919..6f15a79c 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -121,6 +121,7 @@ struct MotionState final { std::size_t script_bank{}; std::size_t script_action{}; std::optional lady_state; + std::uint8_t lady_lane_mask{0x3U}; std::vector script_signals; float lady_runtime_frame{-1.0F}; bool lady_entry_applied{}; @@ -345,6 +346,9 @@ void reset_lady_runtime(Session* session) noexcept { if (!replay && signal.after_frame < state.lady_runtime_frame) continue; for (std::uint8_t lane = 0U; lane < 2U; ++lane) { + if ((state.lady_lane_mask & static_cast(1U << lane)) == 0U) { + continue; + } for (std::uint8_t channel = 0U; channel < signal.channels.size(); ++channel) { const auto value = signal.channels[channel]; if (value == 0U && @@ -786,8 +790,15 @@ MotionLoadReport load_scripted_motion(Session* session, binding.script->signals(selection->bank, selection->action); if (binding.role == Session::MotionScriptRole::LadyBody) { - state.lady_state = - lady_state_for_script_action(selection->bank, selection->action); + if (const auto mapped = lady_state_for_body_script_action( + selection->bank, selection->action); + mapped.has_value()) { + state.lady_state = mapped->state; + state.lady_lane_mask = mapped->lane_mask; + } else { + state.lady_state.reset(); + state.lady_lane_mask = 0U; + } if (state.lady_state.has_value()) { state.lady_entry_applied = false; state.lady_runtime_frame = -1.0F; @@ -805,6 +816,11 @@ MotionLoadReport load_scripted_motion(Session* session, "MotionScript slot" + std::to_string(binding.archive_slot) + " bank" + std::to_string(selection->bank) + "/action" + std::to_string(selection->action) + + (binding.role == Session::MotionScriptRole::LadyBody && + state.lady_state.has_value() + ? " state" + std::to_string(*state.lady_state) + + " lanes=" + std::to_string(state.lady_lane_mask) + : std::string{}) + " -> " + report.detail; if (binding.role == Session::MotionScriptRole::LadyBody && !state.lady_state.has_value()) { From c280d4dc59ea143172dd0fbb072b54c8096b6c27 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:54:41 +0200 Subject: [PATCH 65/84] Encode lane-exact CEm034 state script starts --- .../dmcresource/motion/part_attachment.h | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index 966846c3..10514675 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -532,6 +532,67 @@ lady_state_for_body_script_action(std::size_t bank, std::size_t action) noexcept return std::nullopt; } +struct LadyBodyLaneAction final { + bool valid{}; + std::uint8_t bank{}; + std::uint8_t action{}; +}; + +struct LadyBodyStateScripts final { + std::array lanes{}; +}; + +// Forward form of the same 0x14016A410 entry dispatcher. This is required +// because states55..82 intentionally start different actions on lane0/lane1. +[[nodiscard]] constexpr LadyBodyStateScripts lady_body_state_scripts( + std::uint16_t state) noexcept { + LadyBodyStateScripts out{}; + const auto both = [&out](std::uint8_t bank, std::uint8_t action) constexpr { + out.lanes[0] = {true, bank, action}; + out.lanes[1] = {true, bank, action}; + }; + if (state <= 6U || (state >= 8U && state <= 14U)) { + both(0U, static_cast(state)); + } else if (state >= 15U && state <= 20U) { + both(1U, static_cast(state - 15U)); + } else if (state == 22U) { + both(1U, 7U); + } else if (state >= 24U && state <= 26U) { + both(1U, static_cast(state - 15U)); + } else if (state == 35U) { + both(1U, 20U); + } else if (state >= 38U && state <= 41U) { + both(1U, static_cast(state - 15U)); + } else if (state >= 42U && state <= 45U) { + both(2U, static_cast(state - 42U)); + } else if (state == 46U) { + both(3U, 0U); + } else if (state >= 48U && state <= 54U) { + both(3U, static_cast(state - 46U)); + } else if (state >= 55U && state <= 61U) { + out.lanes[0] = {true, 0U, 1U}; + out.lanes[1] = {true, 3U, static_cast(state - 46U)}; + } else if (state >= 62U && state <= 68U) { + out.lanes[0] = {true, 3U, 16U}; + out.lanes[1] = {true, 3U, static_cast(state - 46U)}; + } else if (state >= 69U && state <= 75U) { + out.lanes[0] = {true, 3U, 23U}; + out.lanes[1] = {true, 3U, static_cast(state - 46U)}; + } else if (state >= 76U && state <= 82U) { + out.lanes[0] = {true, 3U, 30U}; + out.lanes[1] = {true, 3U, static_cast(state - 46U)}; + } else if (state >= 83U && state <= 115U) { + both(4U, static_cast(state - 83U)); + } else if (state >= 123U && state <= 130U) { + both(4U, static_cast(state - 83U)); + } else if (state == 133U) { + both(4U, 50U); + } else if (state == 143U) { + both(4U, 60U); + } + return out; +} + // Consume one signal value exactly as CEm034's direct 0x140059350 consumers do. // lane is 0/1 for the two em034_012 controllers; channel is 0..4. [[nodiscard]] LadyRuntimeApplyResult apply_lady_signal( From 3b975fa7f96435a372c0315c8c010e33b54161fc Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:54:47 +0200 Subject: [PATCH 66/84] Precompute canonical MotionScript links per MOT --- app/src/main/cpp/modules/pac_assembly.cpp | 108 +++++++++++++++++----- 1 file changed, 85 insertions(+), 23 deletions(-) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index 26a91679..ea4fee8b 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -990,40 +990,102 @@ std::unique_ptr assemble_archives(std::span archi it->slots.push_back(static_cast(m.mot_slot)); } - std::vector script_reachable_packs; - for (const auto& binding : assembled->motion_scripts) { + // Materialize exact per-MOT ScriptLinks once. UI and playback then + // consume the same bank/action/state/lane authority instead of + // independently re-solving a resource route on every tap. + const bool lady_archive = + archive_name.find("em034") != std::string_view::npos; + for (std::size_t script_index = 0U; + script_index < assembled->motion_scripts.size(); + ++script_index) { + const auto& binding = assembled->motion_scripts[script_index]; if (binding.script == nullptr) continue; - for (const auto& group : motion::bind_motion_groups( - *binding.script, motion_packs, archive_name)) { - if (group.archive_slot) { - script_reachable_packs.push_back(*group.archive_slot); + + auto groups = motion::bind_motion_groups( + *binding.script, motion_packs, archive_name); + + // em034_013 has a class-specific resource array independent of the + // body script: bank4/group4 -> top-level PAC slot11. + if (lady_archive && + binding.role == Session::MotionScriptRole::LadyComponent0) { + groups.clear(); + motion::MotionGroupBinding g; + g.group = 4U; + g.archive_slot = 11U; + g.exe_confirmed = true; + for (const auto& m : motions) { + if (m.pack_slot == 11 && m.mot_slot >= 0) { + g.slots.push_back( + static_cast(m.mot_slot)); + } } + groups.push_back(std::move(g)); } - // Canonical CEm034 component0 route: - // em034_013 bank4 -> top-level PAC slot11. - if (binding.role == Session::MotionScriptRole::LadyComponent0 && - archive_name.find("em034") != std::string_view::npos) { - script_reachable_packs.push_back(11U); + + for (const auto& group : groups) { + if (!group.archive_slot) continue; + for (auto& m : motions) { + if (m.pack_slot != static_cast(*group.archive_slot) || + m.mot_slot < 0 || m.mot_slot >= 100) { + continue; + } + const auto id = static_cast( + group.group * 100U + + static_cast(m.mot_slot)); + const auto actions = binding.script->actions_for(id); + if (actions.empty()) continue; + + const motion::ScriptAction* pick = &actions.front(); + for (const auto& action : actions) { + if (action.bank == group.group && + action.action == + static_cast(m.mot_slot)) { + pick = &action; + break; + } + if (action.bank == group.group && + pick->bank != group.group) { + pick = &action; + } else if (action.action == + static_cast(m.mot_slot) && + pick->action != + static_cast(m.mot_slot)) { + pick = &action; + } + } + + Session::MotionPayload::ScriptLink link; + link.script_index = script_index; + link.bank = pick->bank; + link.action = pick->action; + if (binding.role == + Session::MotionScriptRole::LadyBody) { + if (const auto mapped = + motion::lady_state_for_body_script_action( + pick->bank, pick->action); + mapped.has_value()) { + link.lady_state = mapped->state; + link.lady_lane_mask = mapped->lane_mask; + } + } + const bool duplicate = std::any_of( + m.script_links.begin(), m.script_links.end(), + [&](const Session::MotionPayload::ScriptLink& existing) { + return existing.script_index == link.script_index && + existing.bank == link.bank && + existing.action == link.action; + }); + if (!duplicate) m.script_links.push_back(link); + } } } - std::sort(script_reachable_packs.begin(), script_reachable_packs.end()); - script_reachable_packs.erase( - std::unique(script_reachable_packs.begin(), - script_reachable_packs.end()), - script_reachable_packs.end()); report.motions = motions.size(); { std::vector drivable; drivable.reserve(motions.size()); for (auto& m : motions) { - const bool script_reachable = - m.pack_slot >= 0 && - std::binary_search( - script_reachable_packs.begin(), - script_reachable_packs.end(), - static_cast(m.pack_slot)); - if (script_reachable || + if (!m.script_links.empty() || motion::motion_can_drive(*assembled, m.bytes)) { drivable.push_back(std::move(m)); } From f69bdbc54981bdadb5bf3c85e2f78083a28e9f38 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:55:18 +0200 Subject: [PATCH 67/84] Replay both CEm034 script lanes exactly --- .../main/cpp/modules/motion/motion_player.cpp | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index 6f15a79c..ac1ce2b2 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -123,6 +123,7 @@ struct MotionState final { std::optional lady_state; std::uint8_t lady_lane_mask{0x3U}; std::vector script_signals; + std::array, 2> lady_lane_signals; float lady_runtime_frame{-1.0F}; bool lady_entry_applied{}; std::int8_t last_dynamic_actor{-1}; @@ -321,8 +322,11 @@ void reset_lady_runtime(Session* session) noexcept { const bool replay = !state.lady_entry_applied || frame < state.lady_runtime_frame; if (replay) { + // The 144-state entry dispatcher is authoritative for the actor state. + // apply_lady_state_entry only models states with recovered equipment + // side effects, so an unrecognized result means "no equipment change", + // not "invalid Lady state". const auto entry = apply_lady_state_entry(session, *state.lady_state); - if (!entry.recognized) return false; state.lady_entry_applied = true; state.lady_runtime_frame = -1.0F; if (entry.dynamic_actor >= 0) state.last_dynamic_actor = entry.dynamic_actor; @@ -341,18 +345,18 @@ void reset_lady_runtime(Session* session) noexcept { } float latest_scale_pulse = -std::numeric_limits::infinity(); - for (const auto& signal : state.script_signals) { - if (!(frame > signal.after_frame)) continue; - if (!replay && signal.after_frame < state.lady_runtime_frame) continue; - - for (std::uint8_t lane = 0U; lane < 2U; ++lane) { - if ((state.lady_lane_mask & static_cast(1U << lane)) == 0U) { - continue; - } - for (std::uint8_t channel = 0U; channel < signal.channels.size(); ++channel) { + for (std::uint8_t lane = 0U; lane < 2U; ++lane) { + for (const auto& signal : state.lady_lane_signals[lane]) { + if (!(frame > signal.after_frame)) continue; + if (!replay && signal.after_frame < state.lady_runtime_frame) continue; + + for (std::uint8_t channel = 0U; + channel < signal.channels.size(); + ++channel) { const auto value = signal.channels[channel]; if (value == 0U && - !(*state.lady_state == 0x81U && channel == 1U)) { + !(*state.lady_state == 0x81U && lane == 1U && + channel == 1U)) { continue; } const auto applied = apply_lady_signal( @@ -795,6 +799,19 @@ MotionLoadReport load_scripted_motion(Session* session, mapped.has_value()) { state.lady_state = mapped->state; state.lady_lane_mask = mapped->lane_mask; + + // Reconstruct both CEm034+0x5070/+0x5190 controller starts, + // including the asymmetric state55..82 cases. + const auto starts = lady_body_state_scripts(mapped->state); + state.lady_lane_mask = 0U; + for (std::uint8_t lane = 0U; lane < 2U; ++lane) { + const auto& start = starts.lanes[lane]; + if (!start.valid) continue; + state.lady_lane_mask |= + static_cast(1U << lane); + state.lady_lane_signals[lane] = + binding.script->signals(start.bank, start.action); + } } else { state.lady_state.reset(); state.lady_lane_mask = 0U; From 4b6fda96de45db324ca5bb51f22f60a563d31190 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:56:07 +0200 Subject: [PATCH 68/84] Consume precomputed ScriptLinks during playback --- .../main/cpp/modules/motion/motion_player.cpp | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index ac1ce2b2..5c44aa9d 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -727,10 +727,18 @@ bool motion_script_can_play_motion(const Session* session, return false; } try { + const auto& payload = session->motion_library[motion_index]; + if (std::any_of( + payload.script_links.begin(), payload.script_links.end(), + [script_index](const Session::MotionPayload::ScriptLink& link) { + return link.script_index == script_index; + })) { + return true; + } return pick_script_motion( *session, session->motion_scripts[script_index], - session->motion_library[motion_index]) + payload) .has_value(); } catch (...) { return false; @@ -751,7 +759,25 @@ MotionLoadReport load_scripted_motion(Session* session, clear_motion(session); const auto binding = session->motion_scripts[script_index]; const auto payload = session->motion_library[motion_index]; - const auto selection = pick_script_motion(*session, binding, payload); + + const Session::MotionPayload::ScriptLink* materialized_link = nullptr; + for (const auto& link : payload.script_links) { + if (link.script_index == script_index) { + materialized_link = &link; + break; + } + } + + std::optional selection; + if (materialized_link != nullptr) { + selection = ScriptMotionSelection{ + materialized_link->bank, + materialized_link->action, + 0U, + }; + } else { + selection = pick_script_motion(*session, binding, payload); + } if (!selection.has_value() || binding.script == nullptr) { report.detail = "MotionScript slot" + std::to_string(binding.archive_slot) + @@ -794,9 +820,18 @@ MotionLoadReport load_scripted_motion(Session* session, binding.script->signals(selection->bank, selection->action); if (binding.role == Session::MotionScriptRole::LadyBody) { - if (const auto mapped = lady_state_for_body_script_action( + std::optional mapped; + if (materialized_link != nullptr && + materialized_link->lady_state >= 0) { + mapped = LadyBodyScriptState{ + static_cast(materialized_link->lady_state), + materialized_link->lady_lane_mask, + }; + } else { + mapped = lady_state_for_body_script_action( selection->bank, selection->action); - mapped.has_value()) { + } + if (mapped.has_value()) { state.lady_state = mapped->state; state.lady_lane_mask = mapped->lane_mask; From 7a9f0ded9130578f65fb8f0b9f1701fe2872a54a Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 06:56:08 +0200 Subject: [PATCH 69/84] Test asymmetric CEm034 script lane starts --- app/src/test/native/pac_assembly_test.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 2996bd7b..5602005b 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -449,6 +449,28 @@ int main() { assert(lady_first->lady_component_bindings[4].preset == dmcresource::motion::LadyPlacementPreset::BodyStowed); } + { + // Full entry-dispatch regression: state0x59 is asymmetric. + const auto mapped = + dmcresource::motion::lady_state_for_body_script_action(3U, 13U); + assert(mapped.has_value()); + assert(mapped->state == 0x59U); + assert(mapped->lane_mask == 0x2U); + const auto starts = + dmcresource::motion::lady_body_state_scripts(0x59U); + assert(starts.lanes[0].valid); + assert(starts.lanes[0].bank == 0U); + assert(starts.lanes[0].action == 1U); + assert(starts.lanes[1].valid); + assert(starts.lanes[1].bank == 3U); + assert(starts.lanes[1].action == 13U); + + const auto state85 = + dmcresource::motion::lady_body_state_scripts(0x85U); + assert(state85.lanes[0].valid && state85.lanes[1].valid); + assert(state85.lanes[0].bank == 4U && state85.lanes[0].action == 50U); + assert(state85.lanes[1].bank == 4U && state85.lanes[1].action == 50U); + } { const auto entry = dmcresource::motion::apply_lady_state_entry( lady_first.get(), 0x59U); From 6f4f1a94d2a91e91fc2efa00326b11d17f26bc41 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:20:17 +0200 Subject: [PATCH 70/84] Retain Lady dynamic Shl visual sources --- .../cpp/include/dmcresource/resource_session.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index bae78833..6030bd7b 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -129,6 +129,23 @@ struct Session { // state cannot silently collapse the recovered multi-channel contract. std::vector lady_component_bindings; + // Dynamic CEm034 CShell visuals stay outside the persistent composite. + // Source geometry/textures are retained once; active/world are presentation + // state driven only by the recovered Shl actor lifecycle. + struct LadyDynamicVisual final { + std::uint8_t actor{}; // CEm034Shl00..05 index + std::uint32_t model_slot{}; + Mesh source_mesh; + std::vector texture_slots; + std::vector textures; + Matrix4 world{}; + bool active{}; + // slot30 shares Shl03 actor transform but has an additional internal + // tether deformation domain that is not yet claimed pixel-exact. + bool exact_deformation{true}; + }; + std::vector lady_dynamic_visuals; + // Attack collision handle (index + shapes) on the body bones; drawn with // RenderFlag::Collision (collision_debug.h). std::shared_ptr collision; From 37f3efb58c00bc304b1f824fa4deed97f0d544cf Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:20:47 +0200 Subject: [PATCH 71/84] Retain latent Lady Shl02 Shl03 visual resources --- app/src/main/cpp/modules/pac_assembly.cpp | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index ea4fee8b..722a10a2 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -928,6 +928,77 @@ std::unique_ptr assemble_archives(std::span archi report.models = models.size(); + // CEm034 dynamic Shl visuals are retained as latent source resources, + // never as persistent composite parts. They are materialized only by + // Script Play spawn events. + if (archive_name.find("em034") != std::string_view::npos && + position != nullptr) { + const auto first_slot = + position->include_top_level_mod_count != 0U + ? position->include_top_level_mod_slots[0] + : 1U; + const std::uint32_t equipment_ptx = + first_slot == 32U ? 33U : 19U; + + const auto materialize_dynamic = + [&](std::uint8_t actor, + std::uint32_t model_slot, + std::uint32_t ptx_slot, + bool exact_deformation) { + const decltype(entries)::value_type* model_entry_ptr = nullptr; + const decltype(entries)::value_type* ptx_entry_ptr = nullptr; + for (const auto& e : entries) { + if (e.archive != 0U || !e.container.empty() || !e.slot) { + continue; + } + if (*e.slot == model_slot && + e.kind.format == Format::Mod) { + model_entry_ptr = &e; + } + if (*e.slot == ptx_slot && + e.kind.format == Format::Ptx) { + ptx_entry_ptr = &e; + } + } + if (model_entry_ptr == nullptr) return; + auto source = open_session( + model_entry_ptr->name, + model_entry_ptr->bytes->data(), + model_entry_ptr->bytes->size()); + if (!source || !source->renderable) return; + if (ptx_entry_ptr != nullptr) { + (void)spider::actions::attach_ptx( + source.get(), + ptx_entry_ptr->name, + ptx_entry_ptr->bytes->data(), + ptx_entry_ptr->bytes->size()); + } + + Session::LadyDynamicVisual visual; + visual.actor = actor; + visual.model_slot = model_slot; + visual.source_mesh = source->render_mesh; + visual.texture_slots = + source->render_triangle_texture_slots; + visual.textures = source->attached_textures; + visual.exact_deformation = exact_deformation; + assembled->lady_dynamic_visuals.push_back( + std::move(visual)); + }; + + materialize_dynamic(2U, 25U, equipment_ptx, true); + materialize_dynamic(3U, 26U, equipment_ptx, true); + // slot30 follows the exact Shl03 actor transform, but its internal + // cable/tether point-array deformation remains a separate layer. + materialize_dynamic(3U, 30U, 29U, false); + + if (!assembled->lady_dynamic_visuals.empty()) { + report.detail_attachments += + " ladyDynamicLatent=" + + std::to_string(assembled->lady_dynamic_visuals.size()); + } + } + // Parse every top-level MotionScript before filtering the MOT library. // A script may target a component that is host-constrained in the rest // pose (CEm034 slot20); those MOTs still need to remain visible so the From 4cbaf67d484fc3481089625032b9e8a7dadff0ea Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:27:45 +0200 Subject: [PATCH 72/84] Render active Lady Shl visuals as derived presentation --- app/src/main/cpp/modules/resource_session.cpp | 177 +++++++++++++++++- 1 file changed, 176 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/modules/resource_session.cpp b/app/src/main/cpp/modules/resource_session.cpp index 58482f2e..2e34a13b 100644 --- a/app/src/main/cpp/modules/resource_session.cpp +++ b/app/src/main/cpp/modules/resource_session.cpp @@ -676,11 +676,176 @@ struct PreparedView final { const HierarchyOverlay* hierarchy{}; const std::vector* texture_slots{}; const std::vector* textures{}; + // Presentation-only mesh/banks used for dynamic CShell visuals. The + // canonical Session render_mesh/composite_parts are never mutated by + // Shl spawn/despawn. + Mesh presentation_mesh; + std::vector presentation_texture_slots; + std::vector presentation_textures; + bool dynamic_presentation{}; std::vector floor_shadow; std::vector collision_lines; std::shared_ptr room; }; +[[nodiscard]] Vec3 transform_dynamic_vertex( + const Vec3& p, const Matrix4& m) noexcept { + return { + p.x * m.values[0] + p.y * m.values[4] + p.z * m.values[8] + m.values[12], + p.x * m.values[1] + p.y * m.values[5] + p.z * m.values[9] + m.values[13], + p.x * m.values[2] + p.y * m.values[6] + p.z * m.values[10] + m.values[14], + }; +} + +[[nodiscard]] Vec3 transform_dynamic_normal( + const Vec3& n, const Matrix4& m) noexcept { + return { + n.x * m.values[0] + n.y * m.values[4] + n.z * m.values[8], + n.x * m.values[1] + n.y * m.values[5] + n.z * m.values[9], + n.x * m.values[2] + n.y * m.values[6] + n.z * m.values[10], + }; +} + +[[nodiscard]] bool build_lady_dynamic_presentation( + const Session& session, PreparedView* out) { + if (out == nullptr) return false; + const bool any = std::any_of( + session.lady_dynamic_visuals.begin(), + session.lady_dynamic_visuals.end(), + [](const Session::LadyDynamicVisual& v) { return v.active; }); + if (!any) return false; + + auto& mesh = out->presentation_mesh; + mesh = session.render_mesh; + out->presentation_textures = session.attached_textures; + + const std::size_t base_triangles = mesh.indices.size() / 3U; + if (session.render_triangle_texture_slots.size() == base_triangles) { + out->presentation_texture_slots = + session.render_triangle_texture_slots; + } else { + out->presentation_texture_slots.assign( + base_triangles, kNoTextureSlot); + } + + const auto ensure_uv = [&mesh]() { + if (mesh.uv0.empty()) mesh.uv0.assign(mesh.vertices.size(), {}); + }; + const auto ensure_color = [&mesh]() { + if (mesh.color0.empty()) { + mesh.color0.assign(mesh.vertices.size(), {128U, 128U, 128U, 128U}); + } + }; + const auto ensure_blend = [&mesh]() { + if (mesh.blend0.empty()) mesh.blend0.assign(mesh.vertices.size(), 0U); + }; + const auto ensure_normal = [&mesh]() { + if (mesh.normal0.empty()) mesh.normal0.assign(mesh.vertices.size(), {}); + }; + + for (const auto& visual : session.lady_dynamic_visuals) { + if (!visual.active || visual.source_mesh.vertices.empty() || + visual.source_mesh.indices.size() < 3U) { + continue; + } + + const std::size_t vertex_base = mesh.vertices.size(); + const std::size_t before = mesh.vertices.size(); + + if (!mesh.uv0.empty() || visual.source_mesh.has_uv0()) ensure_uv(); + if (!mesh.color0.empty() || visual.source_mesh.has_color0()) ensure_color(); + if (!mesh.blend0.empty() || visual.source_mesh.has_blend0()) ensure_blend(); + if (!mesh.normal0.empty() || visual.source_mesh.has_normal0()) ensure_normal(); + + mesh.vertices.reserve(mesh.vertices.size() + visual.source_mesh.vertices.size()); + for (const auto& v : visual.source_mesh.vertices) { + mesh.vertices.push_back(transform_dynamic_vertex(v, visual.world)); + } + + if (!mesh.uv0.empty()) { + if (visual.source_mesh.has_uv0()) { + mesh.uv0.insert(mesh.uv0.end(), + visual.source_mesh.uv0.begin(), + visual.source_mesh.uv0.end()); + } else { + mesh.uv0.resize(mesh.vertices.size()); + } + } + if (!mesh.color0.empty()) { + if (visual.source_mesh.has_color0()) { + mesh.color0.insert(mesh.color0.end(), + visual.source_mesh.color0.begin(), + visual.source_mesh.color0.end()); + } else { + mesh.color0.resize( + mesh.vertices.size(), {128U, 128U, 128U, 128U}); + } + } + if (!mesh.blend0.empty()) { + if (visual.source_mesh.has_blend0()) { + mesh.blend0.insert(mesh.blend0.end(), + visual.source_mesh.blend0.begin(), + visual.source_mesh.blend0.end()); + } else { + mesh.blend0.resize(mesh.vertices.size(), 0U); + } + } + if (!mesh.normal0.empty()) { + if (visual.source_mesh.has_normal0()) { + for (const auto& n : visual.source_mesh.normal0) { + mesh.normal0.push_back( + transform_dynamic_normal(n, visual.world)); + } + } else { + mesh.normal0.resize(mesh.vertices.size()); + } + } + + mesh.indices.reserve(mesh.indices.size() + visual.source_mesh.indices.size()); + for (const auto index : visual.source_mesh.indices) { + if (index >= visual.source_mesh.vertices.size() || + vertex_base > std::numeric_limits::max() - index) { + return false; + } + mesh.indices.push_back( + static_cast(vertex_base + index)); + } + + const std::uint32_t texture_base = + static_cast(out->presentation_textures.size()); + out->presentation_textures.insert( + out->presentation_textures.end(), + visual.textures.begin(), visual.textures.end()); + + const std::size_t dynamic_triangles = + visual.source_mesh.indices.size() / 3U; + if (visual.texture_slots.size() == dynamic_triangles) { + for (const auto slot : visual.texture_slots) { + if (slot == kNoTextureSlot) { + out->presentation_texture_slots.push_back(kNoTextureSlot); + } else if (slot < visual.textures.size() && + texture_base <= + std::numeric_limits::max() - slot) { + out->presentation_texture_slots.push_back( + texture_base + slot); + } else { + out->presentation_texture_slots.push_back(kNoTextureSlot); + } + } + } else { + out->presentation_texture_slots.insert( + out->presentation_texture_slots.end(), + dynamic_triangles, kNoTextureSlot); + } + + if (mesh.vertices.size() <= before) return false; + } + + out->dynamic_presentation = + mesh.vertices.size() > session.render_mesh.vertices.size(); + return out->dynamic_presentation; +} + void prepare_view(const Session& session, int requested_width, int requested_height, float yaw, float pitch, float zoom, std::uint32_t render_flags, const ViewControls& controls, PreparedView* out) { @@ -708,6 +873,12 @@ void prepare_view(const Session& session, int requested_width, int requested_hei : nullptr; out->texture_slots = session.render_triangle_texture_slots.empty() ? nullptr : &session.render_triangle_texture_slots; out->textures = session.attached_textures.empty() ? nullptr : &session.attached_textures; + if (build_lady_dynamic_presentation(session, out)) { + out->texture_slots = out->presentation_texture_slots.empty() + ? nullptr : &out->presentation_texture_slots; + out->textures = out->presentation_textures.empty() + ? nullptr : &out->presentation_textures; + } const auto& rest = view.framing_vertices.empty() ? std::span{session.render_mesh.vertices} : view.framing_vertices; @@ -795,7 +966,11 @@ RgbaImage render_session(const Session* session, int requested_width, int reques if (!session->renderable) return {}; PreparedView prepared; prepare_view(*session, requested_width, requested_height, yaw, pitch, zoom, render_flags, controls, &prepared); - return render_view(session->render_mesh, prepared.width, prepared.height, prepared.view, + const Mesh& presented = + prepared.dynamic_presentation + ? prepared.presentation_mesh + : session->render_mesh; + return render_view(presented, prepared.width, prepared.height, prepared.view, prepared.hierarchy, prepared.texture_slots, prepared.textures); } From 48f135db1d914aa2867f062176f85fc2784a10f9 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:29:23 +0200 Subject: [PATCH 73/84] Track Lady Shl presentation lifetime and velocity --- app/src/main/cpp/include/dmcresource/resource_session.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index 6030bd7b..d0ddafcf 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -139,6 +139,9 @@ struct Session { std::vector texture_slots; std::vector textures; Matrix4 world{}; + Vec3 velocity{}; + float spawn_frame{-1.0F}; + float retire_frame{-1.0F}; // <0 = owner/state controlled bool active{}; // slot30 shares Shl03 actor transform but has an additional internal // tether deformation domain that is not yet claimed pixel-exact. From 2bf56339643a85ed3286f30c37b90f5c5bb2c0b5 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:30:43 +0200 Subject: [PATCH 74/84] Materialize canonical Lady Shl02 Shl03 spawn presentation --- .../main/cpp/modules/motion/motion_player.cpp | 259 +++++++++++++++++- 1 file changed, 258 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index 5c44aa9d..74855a55 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -245,6 +245,247 @@ struct ScriptMotionSelection final { return nullptr; } +[[nodiscard]] LadyComponentBinding* lady_component_binding( + Session* session, std::uint8_t component) noexcept { + if (session == nullptr) return nullptr; + for (auto& binding : session->lady_component_bindings) { + if (binding.component == component) return &binding; + } + return nullptr; +} + +[[nodiscard]] std::optional lady_component_node_world( + const Session& session, std::uint8_t component, std::size_t local_node) noexcept { + const LadyComponentBinding* binding = nullptr; + for (const auto& candidate : session.lady_component_bindings) { + if (candidate.component == component) { + binding = &candidate; + break; + } + } + if (binding == nullptr || binding->part >= session.composite_parts.size()) { + return std::nullopt; + } + const auto& part = session.composite_parts[binding->part]; + if (local_node >= part.scene.nodes.size()) return std::nullopt; + + std::size_t begin = 0U; + for (std::size_t i = 0U; i < binding->part; ++i) { + if (session.composite_parts[i].scene.nodes.size() > + std::numeric_limits::max() - begin) { + return std::nullopt; + } + begin += session.composite_parts[i].scene.nodes.size(); + } + if (begin + local_node >= session.scene.nodes.size()) return std::nullopt; + return session.scene.nodes[begin + local_node].world; +} + +struct Vec4f final { + float x{}; + float y{}; + float z{}; + float w{1.0F}; +}; + +[[nodiscard]] Vec4f transform_row4( + const Vec4f& v, const Matrix4& m) noexcept { + return { + v.x * m.values[0] + v.y * m.values[4] + + v.z * m.values[8] + v.w * m.values[12], + v.x * m.values[1] + v.y * m.values[5] + + v.z * m.values[9] + v.w * m.values[13], + v.x * m.values[2] + v.y * m.values[6] + + v.z * m.values[10] + v.w * m.values[14], + v.x * m.values[3] + v.y * m.values[7] + + v.z * m.values[11] + v.w * m.values[15], + }; +} + +[[nodiscard]] Vec3 cross3(const Vec3& a, const Vec3& b) noexcept { + return { + a.y * b.z - a.z * b.y, + a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x, + }; +} + +[[nodiscard]] float length_sq3(const Vec3& v) noexcept { + return v.x * v.x + v.y * v.y + v.z * v.z; +} + +[[nodiscard]] Vec3 normalize3(Vec3 v, Vec3 fallback) noexcept { + float len2 = length_sq3(v); + if (!(len2 > 1.0e-15F) || !std::isfinite(len2)) { + v = fallback; + len2 = length_sq3(v); + } + if (!(len2 > 1.0e-15F) || !std::isfinite(len2)) return {1.0F, 0.0F, 0.0F}; + const float inv = 1.0F / std::sqrt(len2); + return {v.x * inv, v.y * inv, v.z * inv}; +} + +[[nodiscard]] Vec3 robust_cross( + Vec3 a, Vec3 b, bool a_cross_b) noexcept { + Vec3 out = a_cross_b ? cross3(a, b) : cross3(b, a); + if (length_sq3(out) > 1.0e-15F) return normalize3(out, {1.0F, 0.0F, 0.0F}); + // The EXE perturbs the reference axis in 0.1 steps when the vectors are + // nearly parallel. Preserve that behavior instead of choosing a fixed + // arbitrary perpendicular axis. + b.x += 0.1F; + out = a_cross_b ? cross3(a, b) : cross3(b, a); + if (length_sq3(out) <= 1.0e-15F) { + b.y += 0.1F; + out = a_cross_b ? cross3(a, b) : cross3(b, a); + } + if (length_sq3(out) <= 1.0e-15F) { + b.z += 0.1F; + out = a_cross_b ? cross3(a, b) : cross3(b, a); + } + return normalize3(out, {1.0F, 0.0F, 0.0F}); +} + +[[nodiscard]] Matrix4 shl02_actor_matrix( + const Matrix4& slot20_node0) noexcept { + // 0x14016F610: (1,0,0,1) * slot20 node0 current world. + const auto d4 = transform_row4({1.0F, 0.0F, 0.0F, 1.0F}, slot20_node0); + const Vec3 direction = normalize3({d4.x, d4.y, d4.z}, {1.0F, 0.0F, 0.0F}); + const Vec3 up = normalize3({0.0F, 1.0F, 0.0F}, {0.0F, 1.0F, 0.0F}); + // 0x14032FD90: + // row0 = normalize(up x direction) + // row1 = normalize(direction x row0) + // row2 = normalize(direction) + const Vec3 row0 = robust_cross(up, direction, true); + const Vec3 row1 = normalize3(cross3(direction, row0), {0.0F, 1.0F, 0.0F}); + + Matrix4 out; + out.values = { + row0.x, row0.y, row0.z, 0.0F, + row1.x, row1.y, row1.z, 0.0F, + direction.x, direction.y, direction.z, 0.0F, + slot20_node0.values[12], + slot20_node0.values[13], + slot20_node0.values[14], + 1.0F, + }; + return out; +} + +struct Shl03Spawn final { + Matrix4 world{}; + Vec3 velocity{}; +}; + +[[nodiscard]] std::optional shl03_spawn( + const Session& session) noexcept { + const auto node0 = lady_component_node_world(session, 0U, 0U); + const auto node1 = lady_component_node_world(session, 0U, 1U); + if (!node0.has_value() || !node1.has_value()) return std::nullopt; + + // 0x14016CBB0..0x14016CC41: + // spawn = (87.8,0,4.28,1) * node0World + node1World.translation. + const auto offset = transform_row4( + {87.80000305F, 0.0F, 4.28000021F, 1.0F}, *node0); + const Vec3 spawn{ + offset.x + node1->values[12], + offset.y + node1->values[13], + offset.z + node1->values[14], + }; + + // Direction/velocity domain = 50 * ((1,0,0,1) * node0World). + const auto d4 = transform_row4( + {1.0F, 0.0F, 0.0F, 1.0F}, *node0); + const Vec3 velocity{50.0F * d4.x, 50.0F * d4.y, 50.0F * d4.z}; + const Vec3 direction = normalize3(velocity, {1.0F, 0.0F, 0.0F}); + const Vec3 ref{0.0F, 1.0F, 0.0F}; + + // 0x14032F1D0: + // row0 = direction + // row1 = normalize(ref x direction) + // row2 = normalize(direction x row1) + const Vec3 row1 = robust_cross(ref, direction, true); + const Vec3 row2 = normalize3(cross3(direction, row1), {0.0F, 0.0F, 1.0F}); + + Shl03Spawn out; + out.velocity = velocity; + out.world.values = { + direction.x, direction.y, direction.z, 0.0F, + row1.x, row1.y, row1.z, 0.0F, + row2.x, row2.y, row2.z, 0.0F, + spawn.x, spawn.y, spawn.z, 1.0F, + }; + return out; +} + +void deactivate_lady_dynamic_visuals(Session* session) noexcept { + if (session == nullptr) return; + for (auto& visual : session->lady_dynamic_visuals) { + visual.active = false; + visual.spawn_frame = -1.0F; + visual.retire_frame = -1.0F; + visual.velocity = {}; + visual.world = Matrix4{}; + } +} + +void spawn_lady_dynamic_visual( + Session* session, std::int8_t actor, float event_frame) noexcept { + if (session == nullptr || actor < 0) return; + + if (actor == 2) { + const auto node0 = lady_component_node_world(*session, 0U, 0U); + if (!node0.has_value()) return; + const Matrix4 world_matrix = shl02_actor_matrix(*node0); + for (auto& visual : session->lady_dynamic_visuals) { + if (visual.actor != 2U) continue; + visual.world = world_matrix; + visual.velocity = {}; + visual.spawn_frame = event_frame; + // CActor initializes +0x14/+0x18 to 1.0. Shl02 initializes its + // countdown to 3.0, so no-world preview retires after three actor + // update ticks; gameplay collision may end it earlier. + visual.retire_frame = event_frame + 3.0F; + visual.active = true; + } + return; + } + + if (actor == 3) { + const auto spawn = shl03_spawn(*session); + if (!spawn.has_value()) return; + for (auto& visual : session->lady_dynamic_visuals) { + if (visual.actor != 3U) continue; + visual.world = spawn->world; + visual.velocity = spawn->velocity; + visual.spawn_frame = event_frame; + visual.retire_frame = -1.0F; + visual.active = true; + } + } +} + +void advance_lady_dynamic_visuals(Session* session, float frame) noexcept { + if (session == nullptr) return; + for (auto& visual : session->lady_dynamic_visuals) { + if (!visual.active || visual.spawn_frame < 0.0F) continue; + if (visual.retire_frame >= 0.0F && frame >= visual.retire_frame) { + visual.active = false; + continue; + } + if (visual.actor == 3U) { + const float dt = std::max(frame - visual.spawn_frame, 0.0F); + // Shl03 state1, 0x140174D39: + // actor+0x80 += actor+0x140 * actor+0x14. + visual.world.values[12] += visual.velocity.x * dt; + visual.world.values[13] += visual.velocity.y * dt; + visual.world.values[14] += visual.velocity.z * dt; + // Make advancement absolute from spawn, not cumulative across + // repeated render/scrub calls. + visual.spawn_frame = frame; + } + } +} + [[nodiscard]] std::optional bind_part(const RenderScene& scene, std::size_t vertex_begin, std::size_t node_begin, @@ -299,6 +540,7 @@ struct ScriptMotionSelection final { void reset_lady_runtime(Session* session) noexcept { if (session == nullptr) return; + deactivate_lady_dynamic_visuals(session); for (auto& binding : session->lady_component_bindings) { (void)set_lady_component_preset( session, binding, LadyPlacementPreset::BodyStowed); @@ -326,10 +568,14 @@ void reset_lady_runtime(Session* session) noexcept { // apply_lady_state_entry only models states with recovered equipment // side effects, so an unrecognized result means "no equipment change", // not "invalid Lady state". + deactivate_lady_dynamic_visuals(session); const auto entry = apply_lady_state_entry(session, *state.lady_state); state.lady_entry_applied = true; state.lady_runtime_frame = -1.0F; - if (entry.dynamic_actor >= 0) state.last_dynamic_actor = entry.dynamic_actor; + if (entry.dynamic_actor >= 0) { + state.last_dynamic_actor = entry.dynamic_actor; + spawn_lady_dynamic_visual(session, entry.dynamic_actor, 0.0F); + } } // State0x81/action46 rebuilds +0x4400 to 1.0 every actor update, and @@ -363,6 +609,9 @@ void reset_lady_runtime(Session* session) noexcept { session, *state.lady_state, lane, channel, value); if (applied.dynamic_actor >= 0) { state.last_dynamic_actor = applied.dynamic_actor; + spawn_lady_dynamic_visual( + session, applied.dynamic_actor, + std::max(signal.after_frame, 0.0F)); } if (*state.lady_state == 0x81U && lane == 1U && channel == 1U && value == 1U) { @@ -384,6 +633,7 @@ void reset_lady_runtime(Session* session) noexcept { } } + advance_lady_dynamic_visuals(session, frame); state.lady_runtime_frame = frame; return true; } @@ -637,6 +887,13 @@ bool apply_motion_frame(Session* session, float frame) noexcept { if (wanted != binding.state) (void)set_weapon_state(session, binding, wanted); } } + // Resolve current body-driven equipment before Lady runtime signals + // query slot20 node worlds for Shl spawn transforms. This pass does not + // advance cloth; the final attachment pass below performs the actual + // frame's cloth steps. + if (!session->lady_component_bindings.empty()) { + (void)apply_part_attachments(session, 0U); + } if (!apply_lady_script_runtime(session, state, frame)) return false; (void)apply_part_attachments(session, cloth_steps); (void)apply_uv_scrolls(session, state.scroll_clock); From 474de7e9f9bae3675630a4c49b8f088bbfe492a2 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:31:22 +0200 Subject: [PATCH 75/84] Guard latent Lady Shl resources outside persistent composite --- app/src/test/native/pac_assembly_test.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 5602005b..2a275806 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -304,7 +304,9 @@ int main() { lady_payloads[slot] = mod; } for (const std::size_t slot : {25U, 26U, 30U}) { - lady_payloads[slot] = opaque; + // Valid MOD payloads so the assembly can retain them as latent Shl + // visual sources while keeping them out of the persistent composite. + lady_payloads[slot] = mod; } lady_payloads[32] = lady_body; lady_payloads[34] = mod; @@ -348,6 +350,16 @@ int main() { assert(report.models == 7U); assert(lady_first->composite_parts.size() == 7U); assert(lady_first->lady_component_bindings.size() == 5U); + assert(lady_first->lady_dynamic_visuals.size() == 3U); + assert(lady_first->lady_dynamic_visuals[0].actor == 2U); + assert(lady_first->lady_dynamic_visuals[0].model_slot == 25U); + assert(lady_first->lady_dynamic_visuals[1].actor == 3U); + assert(lady_first->lady_dynamic_visuals[1].model_slot == 26U); + assert(lady_first->lady_dynamic_visuals[2].actor == 3U); + assert(lady_first->lady_dynamic_visuals[2].model_slot == 30U); + assert(!lady_first->lady_dynamic_visuals[0].active); + assert(!lady_first->lady_dynamic_visuals[1].active); + assert(!lady_first->lady_dynamic_visuals[2].active); assert(lady_first->composite_parts[0].name.find("slot_0001.mod") != std::string::npos); assert(lady_first->composite_parts[1].name.find("slot_0017.mod") != std::string::npos); for (std::size_t i = 0U; i < 5U; ++i) { @@ -502,6 +514,10 @@ int main() { assert(report.models == 7U); assert(lady_second->composite_parts.size() == 7U); assert(lady_second->lady_component_bindings.size() == 5U); + assert(lady_second->lady_dynamic_visuals.size() == 3U); + assert(!lady_second->lady_dynamic_visuals[0].active); + assert(!lady_second->lady_dynamic_visuals[1].active); + assert(!lady_second->lady_dynamic_visuals[2].active); assert(lady_second->composite_parts[0].name.find("slot_0032.mod") != std::string::npos); assert(lady_second->composite_parts[1].name.find("slot_0034.mod") != std::string::npos); From 7627f9fe5b4d3a33e3904ae8c73fe8043b281473 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:42:19 +0200 Subject: [PATCH 76/84] Fix Lady decimal-vs-hex state regression --- app/src/test/native/pac_assembly_test.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 2a275806..f8e003db 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -462,14 +462,16 @@ int main() { dmcresource::motion::LadyPlacementPreset::BodyStowed); } { - // Full entry-dispatch regression: state0x59 is asymmetric. + // Full entry-dispatch regression. CEm034 state numbers are integer + // values; state 59 decimal == 0x3B and is asymmetric: + // lane0 bank0/action1, lane1 bank3/action13. const auto mapped = dmcresource::motion::lady_state_for_body_script_action(3U, 13U); assert(mapped.has_value()); - assert(mapped->state == 0x59U); + assert(mapped->state == 0x3BU); assert(mapped->lane_mask == 0x2U); const auto starts = - dmcresource::motion::lady_body_state_scripts(0x59U); + dmcresource::motion::lady_body_state_scripts(0x3BU); assert(starts.lanes[0].valid); assert(starts.lanes[0].bank == 0U); assert(starts.lanes[0].action == 1U); @@ -477,6 +479,13 @@ int main() { assert(starts.lanes[1].bank == 3U); assert(starts.lanes[1].action == 13U); + // State 0x59 is 89 decimal and belongs to bank4/action6 on both lanes. + const auto state89 = + dmcresource::motion::lady_body_state_scripts(0x59U); + assert(state89.lanes[0].valid && state89.lanes[1].valid); + assert(state89.lanes[0].bank == 4U && state89.lanes[0].action == 6U); + assert(state89.lanes[1].bank == 4U && state89.lanes[1].action == 6U); + const auto state85 = dmcresource::motion::lady_body_state_scripts(0x85U); assert(state85.lanes[0].valid && state85.lanes[1].valid); From ecad8718edabff155111edfb65181f44401ba5ea Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:44:54 +0200 Subject: [PATCH 77/84] Separate Lady Shl spawn and update clocks --- app/src/main/cpp/include/dmcresource/resource_session.h | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index d0ddafcf..14a335ac 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -141,6 +141,7 @@ struct Session { Matrix4 world{}; Vec3 velocity{}; float spawn_frame{-1.0F}; + float last_update_frame{-1.0F}; float retire_frame{-1.0F}; // <0 = owner/state controlled bool active{}; // slot30 shares Shl03 actor transform but has an additional internal From cbe8550e246d6e38e8d38324d4c507ef529d06c0 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:45:16 +0200 Subject: [PATCH 78/84] Model Shl02 two-phase default-timescale presentation --- .../main/cpp/modules/motion/motion_player.cpp | 59 ++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/app/src/main/cpp/modules/motion/motion_player.cpp b/app/src/main/cpp/modules/motion/motion_player.cpp index 74855a55..cc133fe3 100644 --- a/app/src/main/cpp/modules/motion/motion_player.cpp +++ b/app/src/main/cpp/modules/motion/motion_player.cpp @@ -422,6 +422,7 @@ void deactivate_lady_dynamic_visuals(Session* session) noexcept { for (auto& visual : session->lady_dynamic_visuals) { visual.active = false; visual.spawn_frame = -1.0F; + visual.last_update_frame = -1.0F; visual.retire_frame = -1.0F; visual.velocity = {}; visual.world = Matrix4{}; @@ -439,12 +440,27 @@ void spawn_lady_dynamic_visual( for (auto& visual : session->lady_dynamic_visuals) { if (visual.actor != 2U) continue; visual.world = world_matrix; - visual.velocity = {}; + // Shl02 state1 uses CShell flags=3 with scalar +0x160 = 30.0: + // normalize(+0x140), scale by 30, then position += delta*velocity. + // Under the Reader's default actor delta (1.0), +0x17C starts at + // 1.0 so state1 contributes exactly one movement tick. + const Vec3 forward{ + world_matrix.values[8], + world_matrix.values[9], + world_matrix.values[10], + }; + visual.velocity = { + forward.x * 30.0F, + forward.y * 30.0F, + forward.z * 30.0F, + }; visual.spawn_frame = event_frame; - // CActor initializes +0x14/+0x18 to 1.0. Shl02 initializes its - // countdown to 3.0, so no-world preview retires after three actor - // update ticks; gameplay collision may end it earlier. - visual.retire_frame = event_frame + 3.0F; + visual.last_update_frame = event_frame; + // Then state2 starts +0xD68=3.0 and only promotes to state3 after + // the subtraction becomes negative: 3->2->1->0->-1. The next + // actor update dispatches state3 through the retire path. With + // default delta1 this is six updates from spawn, not three. + visual.retire_frame = event_frame + 6.0F; visual.active = true; } return; @@ -458,6 +474,7 @@ void spawn_lady_dynamic_visual( visual.world = spawn->world; visual.velocity = spawn->velocity; visual.spawn_frame = event_frame; + visual.last_update_frame = event_frame; visual.retire_frame = -1.0F; visual.active = true; } @@ -468,20 +485,34 @@ void advance_lady_dynamic_visuals(Session* session, float frame) noexcept { if (session == nullptr) return; for (auto& visual : session->lady_dynamic_visuals) { if (!visual.active || visual.spawn_frame < 0.0F) continue; - if (visual.retire_frame >= 0.0F && frame >= visual.retire_frame) { - visual.active = false; - continue; - } - if (visual.actor == 3U) { - const float dt = std::max(frame - visual.spawn_frame, 0.0F); + const float previous = + visual.last_update_frame >= visual.spawn_frame + ? visual.last_update_frame + : visual.spawn_frame; + if (visual.actor == 2U) { + // Only Shl02 state1 moves the projectile through the shared shell + // helper. Clamp the integrated interval to the first actor tick; + // state2 retains the resulting actor matrix while its 3.0 + // countdown/effect phase runs. + const float before = + std::clamp(previous - visual.spawn_frame, 0.0F, 1.0F); + const float after = + std::clamp(frame - visual.spawn_frame, 0.0F, 1.0F); + const float dt = std::max(after - before, 0.0F); + visual.world.values[12] += visual.velocity.x * dt; + visual.world.values[13] += visual.velocity.y * dt; + visual.world.values[14] += visual.velocity.z * dt; + } else if (visual.actor == 3U) { + const float dt = std::max(frame - previous, 0.0F); // Shl03 state1, 0x140174D39: // actor+0x80 += actor+0x140 * actor+0x14. visual.world.values[12] += visual.velocity.x * dt; visual.world.values[13] += visual.velocity.y * dt; visual.world.values[14] += visual.velocity.z * dt; - // Make advancement absolute from spawn, not cumulative across - // repeated render/scrub calls. - visual.spawn_frame = frame; + } + visual.last_update_frame = frame; + if (visual.retire_frame >= 0.0F && frame >= visual.retire_frame) { + visual.active = false; } } } From 9e475674ed47c63c7223c0f1811957dd5dcf7f11 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:50:36 +0200 Subject: [PATCH 79/84] Test Lady costume2 by slot identity not vector order --- app/src/test/native/pac_assembly_test.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index f8e003db..9d6ae690 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -527,8 +527,16 @@ int main() { assert(!lady_second->lady_dynamic_visuals[0].active); assert(!lady_second->lady_dynamic_visuals[1].active); assert(!lady_second->lady_dynamic_visuals[2].active); - assert(lady_second->composite_parts[0].name.find("slot_0032.mod") != std::string::npos); - assert(lady_second->composite_parts[1].name.find("slot_0034.mod") != std::string::npos); + const auto has_lady_part = [](const dmcresource::Session& session, + std::string_view token) { + return std::any_of( + session.composite_parts.begin(), session.composite_parts.end(), + [token](const auto& part) { + return part.name.find(token) != std::string::npos; + }); + }; + assert(has_lady_part(*lady_second, "slot_0032.mod")); + assert(has_lady_part(*lady_second, "slot_0034.mod")); // An archive without MOD is browsable but has nothing to assemble. const auto motions_only = make_pac({mot}); From d07edc606da8dc91f5cca896f68c2359df931349 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:56:46 +0200 Subject: [PATCH 80/84] Fix Lady PAC regression test build --- app/src/test/native/pac_assembly_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/test/native/pac_assembly_test.cpp b/app/src/test/native/pac_assembly_test.cpp index 9d6ae690..ac758c02 100644 --- a/app/src/test/native/pac_assembly_test.cpp +++ b/app/src/test/native/pac_assembly_test.cpp @@ -1,3 +1,4 @@ +#include #include "dmcresource/motion/motion_player.h" #include "dmcresource/pac_assembly.h" #include "dmcresource/resource_session.h" From 6ae131cdce657a094bf15e7f115e320d0192cbc7 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 07:56:47 +0200 Subject: [PATCH 81/84] Make Lady lane masks explicit uint8 --- .../main/cpp/include/dmcresource/motion/part_attachment.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h index 10514675..573cf5b1 100644 --- a/app/src/main/cpp/include/dmcresource/motion/part_attachment.h +++ b/app/src/main/cpp/include/dmcresource/motion/part_attachment.h @@ -514,11 +514,11 @@ lady_state_for_body_script_action(std::size_t bank, std::size_t action) noexcept if (action >= 9U && action <= 15U) return LadyBodyScriptState{ static_cast(46U + action), 0x2U}; if (action >= 16U && action <= 22U) return LadyBodyScriptState{ - static_cast(46U + action), action == 16U ? 0x3U : 0x2U}; + static_cast(46U + action), static_cast(action == 16U ? 0x3U : 0x2U)}; if (action >= 23U && action <= 29U) return LadyBodyScriptState{ - static_cast(46U + action), action == 23U ? 0x3U : 0x2U}; + static_cast(46U + action), static_cast(action == 23U ? 0x3U : 0x2U)}; if (action >= 30U && action <= 36U) return LadyBodyScriptState{ - static_cast(46U + action), action == 30U ? 0x3U : 0x2U}; + static_cast(46U + action), static_cast(action == 30U ? 0x3U : 0x2U)}; return std::nullopt; } if (bank == 4U) { From 5aa49657ef0a21e46df69da3a9e4b8e831dab0f4 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 08:21:31 +0200 Subject: [PATCH 82/84] Retain Lady dynamic source scenes for exact skinning --- app/src/main/cpp/include/dmcresource/resource_session.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/cpp/include/dmcresource/resource_session.h b/app/src/main/cpp/include/dmcresource/resource_session.h index 14a335ac..f24fd937 100644 --- a/app/src/main/cpp/include/dmcresource/resource_session.h +++ b/app/src/main/cpp/include/dmcresource/resource_session.h @@ -135,6 +135,10 @@ struct Session { struct LadyDynamicVisual final { std::uint8_t actor{}; // CEm034Shl00..05 index std::uint32_t model_slot{}; + // Preserve the canonical MOD scene for dynamic skeletal deformation + // (slot30 uses its five-node skin domain). source_mesh is the retained + // flattened rest projection consumed by the presentation layer. + RenderScene source_scene; Mesh source_mesh; std::vector texture_slots; std::vector textures; From eed8ee5629abbe0a6c25c715b05b528c302e94d0 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 08:21:34 +0200 Subject: [PATCH 83/84] Retain slot30 skeleton authority for Lady tether --- app/src/main/cpp/modules/pac_assembly.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/modules/pac_assembly.cpp b/app/src/main/cpp/modules/pac_assembly.cpp index 722a10a2..a6438c5a 100644 --- a/app/src/main/cpp/modules/pac_assembly.cpp +++ b/app/src/main/cpp/modules/pac_assembly.cpp @@ -977,6 +977,7 @@ std::unique_ptr assemble_archives(std::span archi Session::LadyDynamicVisual visual; visual.actor = actor; visual.model_slot = model_slot; + visual.source_scene = source->scene; visual.source_mesh = source->render_mesh; visual.texture_slots = source->render_triangle_texture_slots; @@ -988,9 +989,10 @@ std::unique_ptr assemble_archives(std::span archi materialize_dynamic(2U, 25U, equipment_ptx, true); materialize_dynamic(3U, 26U, equipment_ptx, true); - // slot30 follows the exact Shl03 actor transform, but its internal - // cable/tether point-array deformation remains a separate layer. - materialize_dynamic(3U, 30U, 29U, false); + // slot30 is a five-node skinned tether. Its per-frame straight + // chain matrices are EXE-confirmed and materialized by the + // presentation layer using the retained canonical source scene. + materialize_dynamic(3U, 30U, 29U, true); if (!assembled->lady_dynamic_visuals.empty()) { report.detail_attachments += From 2c3d48dfea47d7985bf0aa78c2a64abad650e6a0 Mon Sep 17 00:00:00 2001 From: VrUaCom Date: Mon, 28 Sep 2026 08:22:58 +0200 Subject: [PATCH 84/84] Skin Lady slot30 from exact five-node tether matrices --- app/src/main/cpp/modules/resource_session.cpp | 291 +++++++++++++++++- 1 file changed, 286 insertions(+), 5 deletions(-) diff --git a/app/src/main/cpp/modules/resource_session.cpp b/app/src/main/cpp/modules/resource_session.cpp index 2e34a13b..5f5966d5 100644 --- a/app/src/main/cpp/modules/resource_session.cpp +++ b/app/src/main/cpp/modules/resource_session.cpp @@ -1,5 +1,7 @@ #include "dmcresource/resource_session.h" #include "dmcresource/motion/motion_player.h" +#include "dmcresource/motion/skeleton_rig.h" +#include "dmc_rengine/formats/mod/world_transform.hpp" #include "dmcresource/inspection_format.h" #include "dmcresource/resource_limits.h" #include "dmcresource/scene_projection.h" @@ -706,6 +708,262 @@ struct PreparedView final { }; } +namespace mod_world = dmc::rengine::formats::mod::world_transform; + +struct DynamicVertexInfluences final { + std::array node{}; + std::array weight{}; + std::uint8_t count{}; +}; + +[[nodiscard]] std::size_t dynamic_scene_vertex_count( + const RenderScene& scene) noexcept { + std::size_t total = 0U; + for (const auto& primitive : scene.meshes) { + total += primitive.mesh.vertices.size(); + } + return total; +} + +[[nodiscard]] bool flatten_dynamic_influences( + const RenderScene& scene, + std::size_t node_count, + std::vector* out) { + if (out == nullptr) return false; + out->clear(); + out->reserve(dynamic_scene_vertex_count(scene)); + for (std::size_t primitive = 0U; primitive < scene.meshes.size(); ++primitive) { + const auto& source = scene.meshes[primitive].mesh; + const SkinBinding* skin = nullptr; + for (const auto& candidate : scene.skins) { + if (candidate.mesh_primitive == primitive && + candidate.vertices.size() == source.vertices.size()) { + skin = &candidate; + break; + } + } + for (std::size_t vertex = 0U; vertex < source.vertices.size(); ++vertex) { + DynamicVertexInfluences influences; + if (skin != nullptr) { + for (const auto& joint : skin->vertices[vertex].influences) { + if (influences.count >= influences.node.size()) break; + if (joint.node_index >= node_count || + !std::isfinite(joint.weight) || joint.weight <= 0.0F) { + continue; + } + influences.node[influences.count] = joint.node_index; + influences.weight[influences.count] = joint.weight; + ++influences.count; + } + } + out->push_back(influences); + } + } + return true; +} + +[[nodiscard]] std::optional lady_dynamic_component_node_world( + const Session& session, + std::uint8_t component, + std::size_t local_node) noexcept { + const motion::LadyComponentBinding* binding = nullptr; + for (const auto& candidate : session.lady_component_bindings) { + if (candidate.component == component) { + binding = &candidate; + break; + } + } + if (binding == nullptr || + binding->part >= session.composite_parts.size() || + local_node >= session.composite_parts[binding->part].scene.nodes.size()) { + return std::nullopt; + } + + std::size_t node_begin = 0U; + for (std::size_t part = 0U; part < binding->part; ++part) { + const auto count = session.composite_parts[part].scene.nodes.size(); + if (count > std::numeric_limits::max() - node_begin) { + return std::nullopt; + } + node_begin += count; + } + if (node_begin + local_node >= session.scene.nodes.size()) { + return std::nullopt; + } + return session.scene.nodes[node_begin + local_node].world; +} + +[[nodiscard]] Vec3 dynamic_cross(const Vec3& a, const Vec3& b) noexcept { + return { + a.y * b.z - a.z * b.y, + a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x, + }; +} + +[[nodiscard]] float dynamic_length_sq(const Vec3& v) noexcept { + return v.x * v.x + v.y * v.y + v.z * v.z; +} + +[[nodiscard]] float dynamic_length(const Vec3& v) noexcept { + return std::sqrt(std::max(dynamic_length_sq(v), 0.0F)); +} + +[[nodiscard]] Vec3 dynamic_normalize( + Vec3 v, const Vec3& fallback) noexcept { + float length_sq = dynamic_length_sq(v); + if (!(length_sq > 1.0e-15F) || !std::isfinite(length_sq)) { + v = fallback; + length_sq = dynamic_length_sq(v); + } + if (!(length_sq > 1.0e-15F) || !std::isfinite(length_sq)) { + return {1.0F, 0.0F, 0.0F}; + } + const float inv = 1.0F / std::sqrt(length_sq); + return {v.x * inv, v.y * inv, v.z * inv}; +} + +[[nodiscard]] std::array lady_slot30_worlds( + const Vec3& anchor, + const Vec3& endpoint) noexcept { + const Vec3 delta{ + endpoint.x - anchor.x, + endpoint.y - anchor.y, + endpoint.z - anchor.z, + }; + std::array points{}; + for (std::size_t i = 0U; i < points.size(); ++i) { + const float t = static_cast(i) * 0.25F; + points[i] = { + anchor.x + delta.x * t, + anchor.y + delta.y * t, + anchor.z + delta.z * t, + }; + } + + const Vec3 segment{ + points[1].x - points[0].x, + points[1].y - points[0].y, + points[1].z - points[0].z, + }; + const float segment_length = dynamic_length(segment); + const Vec3 direction = dynamic_normalize(segment, {1.0F, 0.0F, 0.0F}); + + // 0x14032EEE0 with reference=(0,1,0,1): row0 follows the segment, + // row2 = direction x reference, row1 = row2 x direction. The helper + // perturbs the reference by +0.1 X/Y/Z if it is parallel. + Vec3 reference{0.0F, 1.0F, 0.0F}; + Vec3 row2 = dynamic_cross(direction, reference); + if (!(dynamic_length_sq(row2) > 1.0e-15F)) { + reference.x += 0.1F; + row2 = dynamic_cross(direction, reference); + } + if (!(dynamic_length_sq(row2) > 1.0e-15F)) { + reference.y += 0.1F; + row2 = dynamic_cross(direction, reference); + } + if (!(dynamic_length_sq(row2) > 1.0e-15F)) { + reference.z += 0.1F; + row2 = dynamic_cross(direction, reference); + } + row2 = dynamic_normalize(row2, {0.0F, 0.0F, 1.0F}); + const Vec3 row1 = + dynamic_normalize(dynamic_cross(row2, direction), {0.0F, 1.0F, 0.0F}); + const float longitudinal_scale = segment_length / 70.0F; + + std::array current{}; + for (std::size_t i = 0U; i < current.size(); ++i) { + current[i].values = { + direction.x * longitudinal_scale, + direction.y * longitudinal_scale, + direction.z * longitudinal_scale, + 0.0F, + row1.x, row1.y, row1.z, 0.0F, + row2.x, row2.y, row2.z, 0.0F, + points[i].x, points[i].y, points[i].z, 1.0F, + }; + } + return current; +} + +[[nodiscard]] std::optional> skin_lady_slot30( + const Session& session, + const Session::LadyDynamicVisual& visual) { + if (visual.model_slot != 30U || + visual.source_scene.rig == nullptr || + visual.source_scene.rig->node_count() != 5U || + visual.source_mesh.vertices.empty()) { + return std::nullopt; + } + + const auto anchor_world = + lady_dynamic_component_node_world(session, 0U, 2U); + if (!anchor_world.has_value()) return std::nullopt; + + const Vec3 anchor{ + anchor_world->values[12], + anchor_world->values[13], + anchor_world->values[14], + }; + const Vec3 endpoint{ + visual.world.values[12], + visual.world.values[13], + visual.world.values[14], + }; + const auto current = lady_slot30_worlds(anchor, endpoint); + const auto palette = mod_world::build_skin_palette( + visual.source_scene.rig->domain, + std::span{current.data(), current.size()}); + if (!palette.has_value() || palette->size() != current.size()) { + return std::nullopt; + } + + std::vector influences; + if (!flatten_dynamic_influences( + visual.source_scene, current.size(), &influences) || + influences.size() != visual.source_mesh.vertices.size()) { + return std::nullopt; + } + + std::vector vertices; + vertices.reserve(visual.source_mesh.vertices.size()); + for (std::size_t index = 0U; + index < visual.source_mesh.vertices.size(); + ++index) { + const auto& rest = visual.source_mesh.vertices[index]; + const auto& skin = influences[index]; + Vec3 moved = rest; + float total = 0.0F; + for (std::uint8_t k = 0U; k < skin.count; ++k) { + total += skin.weight[k]; + } + if (skin.count > 0U && total > 0.0F) { + moved = {}; + for (std::uint8_t k = 0U; k < skin.count; ++k) { + const auto& matrix = (*palette)[skin.node[k]].values; + const Vec3 point{ + rest.x * matrix[0] + rest.y * matrix[4] + + rest.z * matrix[8] + matrix[12], + rest.x * matrix[1] + rest.y * matrix[5] + + rest.z * matrix[9] + matrix[13], + rest.x * matrix[2] + rest.y * matrix[6] + + rest.z * matrix[10] + matrix[14], + }; + const float weight = skin.weight[k] / total; + moved.x += point.x * weight; + moved.y += point.y * weight; + moved.z += point.z * weight; + } + } + if (!std::isfinite(moved.x) || !std::isfinite(moved.y) || + !std::isfinite(moved.z)) { + return std::nullopt; + } + vertices.push_back(moved); + } + return vertices; +} + [[nodiscard]] bool build_lady_dynamic_presentation( const Session& session, PreparedView* out) { if (out == nullptr) return false; @@ -758,8 +1016,20 @@ struct PreparedView final { if (!mesh.normal0.empty() || visual.source_mesh.has_normal0()) ensure_normal(); mesh.vertices.reserve(mesh.vertices.size() + visual.source_mesh.vertices.size()); - for (const auto& v : visual.source_mesh.vertices) { - mesh.vertices.push_back(transform_dynamic_vertex(v, visual.world)); + const auto tether_vertices = + visual.model_slot == 30U + ? skin_lady_slot30(session, visual) + : std::nullopt; + if (tether_vertices.has_value()) { + mesh.vertices.insert( + mesh.vertices.end(), + tether_vertices->begin(), + tether_vertices->end()); + } else { + for (const auto& v : visual.source_mesh.vertices) { + mesh.vertices.push_back( + transform_dynamic_vertex(v, visual.world)); + } } if (!mesh.uv0.empty()) { @@ -792,9 +1062,20 @@ struct PreparedView final { } if (!mesh.normal0.empty()) { if (visual.source_mesh.has_normal0()) { - for (const auto& n : visual.source_mesh.normal0) { - mesh.normal0.push_back( - transform_dynamic_normal(n, visual.world)); + if (tether_vertices.has_value()) { + // The current renderer, like MOT preview, does not rebuild + // skinned normals. Preserve the source normals rather than + // incorrectly applying the Shl03 actor transform to a + // cable whose vertices use five independent bone worlds. + mesh.normal0.insert( + mesh.normal0.end(), + visual.source_mesh.normal0.begin(), + visual.source_mesh.normal0.end()); + } else { + for (const auto& n : visual.source_mesh.normal0) { + mesh.normal0.push_back( + transform_dynamic_normal(n, visual.world)); + } } } else { mesh.normal0.resize(mesh.vertices.size());