diff --git a/docs/release/CHANGELOG.md b/docs/release/CHANGELOG.md index 5fb4442..2ade46c 100644 --- a/docs/release/CHANGELOG.md +++ b/docs/release/CHANGELOG.md @@ -4,6 +4,21 @@ [README](../../README.md) · [Install](INSTALL.md) · [Settings](SETTINGS.md) · [Charting](CHARTING.md) · **Changelog** +## 1.0.0-beta.6 + +A bug-fix release for the finger markers (the "hand shape" markers on the neck) and a rare crash. Everything +else works as in 1.0.0-beta.5. + +### Fixed + +- A barre marker on a seven- or eight-string guitar now reaches across all strings. Before, it stopped at the sixth + string. +- On five- and six-string basses, and with custom string spacing, barre markers now have the right length. +- On seven- and eight-string guitars, a barre over the low strings was drawn one string too high. Its finger + marker now sits on the barre's lowest string. +- On bass, finger markers follow the bass string order, so they sit on the right string and have the right size. +- Fixed a rare crash while the game loads the headstock model. + ## 1.0.0-beta.5 ### Changed diff --git a/sites.json b/sites.json index 175b54d..fb21141 100644 --- a/sites.json +++ b/sites.json @@ -410,6 +410,8 @@ {"id": "PUBGB", "kind": "jmp", "length": 5, "pattern": "B8 02 00 00 00 5F 5E 5B 8B E5 5D C2 08 00 5F 5E B8 01 00 00 00 5B 8B E5 5D C2 08 00 CC CC CC CC", "offset": "0x0", "expect": "B8 02 00 00 00", "publish": "native", "note": "0x58FA25 publication grid exact port"}, {"id": "PUBGA", "kind": "jmp", "length": 6, "pattern": "55 8B EC 83 EC 4C A1 ?? ?? ?? ?? 33 C5 89 45 FC 8B 45 0C 53 56 57 8B F9 8D 4D B8 89 45 BC A1 CC", "offset": "0x0", "expect": "55 8B EC 83 EC 4C", "publish": "native", "note": "0x594530 publication grid exact port"}, {"id": "PUBGF", "kind": "jmp", "length": 5, "pattern": "55 8B EC 53 56 8B 75 08 32 C9 32 C0 B2 06 83 C6 0A 0F B6 1E 3B DF 75 ?? 3A C2 73 ?? 8A D0 3A C1", "offset": "0x0", "expect": "55 8B EC 53 56", "publish": "native", "note": "0x58CF90 publication grid exact port"}, + {"id": "PUBFA", "kind": "jmp", "length": 6, "pattern": "55 8B EC 83 EC 10 53 56 8B 75 0C 0F B6 D8 57 0F B6 7E 24 88 46 25", "offset": "0x0", "expect": "55 8B EC 83 EC 10", "publish": "native", "note": "0x58CDC0 neck finger marker entry: anchor a barre on its lowest physical string (the pattern stops before FG4 at 0x58CDD6)"}, + {"id": "PUBBC", "kind": "jmp", "length": 6, "pattern": "8B 73 1C 83 EC 0C D9 5C 24 08 D9 EE 8B D6 89 54 24 1C D9 5C 24 04 DB 44 24 1C 85 D2 79", "offset": "0x0", "expect": "8B 73 1C 83 EC 0C", "publish": "native", "note": "0x58C7DC in the finger marker update 0x58C690, where a changed span re-seeks the barre clip (EBX = marker, [EBP+8] = owner, [ESP+14h] = clip duration): fit the capsule to the span at the neck's string gap"}, {"id": "PUBEDGE", "kind": "jmp", "length": 13, "pattern": "84 C9 74 ?? 32 C0 EB ?? 8A 40 0B FE C8 8B 76 10 0F B6 C0 6B C0 4C D9 44 30 3C D9 5C 24 74 D9 44", "offset": "0x0", "expect": "84 C9 74 04 32 C0 EB 05 8A 40 0B FE C8", "publish": "native", "note": "0x7E72D0 publication grid exact port"}, {"id": "PUBNL", "kind": "jmp", "length": 9, "pattern": "55 8b ec 81 ec 70 0a 00 00 a1 40 b2 25 01 33 c5 89 45", "offset": "0x0", "expect": "55 8b ec 81 ec 70 0a 00 00", "note": "0x4e6e90: guarded native pitch reader", "publish": "native"}, {"id": "PUBAN", "kind": "jmp", "length": 6, "pattern": "55 8b ec 83 ec 08 53 8b 5d 0c 56 8b 75 10 57 c7 43 08", "offset": "0x0", "expect": "55 8b ec 83 ec 08", "note": "0x875430: guarded native pitch reader", "publish": "native"}, diff --git a/src/features/frets/frets.h b/src/features/frets/frets.h index 776d9f8..c5db129 100644 --- a/src/features/frets/frets.h +++ b/src/features/frets/frets.h @@ -55,6 +55,10 @@ __declspec(dllexport) void __cdecl Rsxr_FretsAfterApply(uint8_t* grid); __declspec(dllexport) void __cdecl Rsxr_InlaysAfter(uint8_t* guitar, uint8_t* inlays); } +// Entity_SetScale 0x7AE2C0 through X_SETSCALE (nothing when it did not resolve); hooks.cpp. Also used by the finger +// marker barres (features/publish). +void RsxrFrets_SetScale(uint8_t* entity, float k); + namespace rsxrfrets { constexpr float kDefaultHalfLen = 4.61f; // half bar length estimate (bound radius 4.638, see the note) using rsxr::kGuitarGrid; // FretGrid* (0x593043: EAX = [edi+10h]) diff --git a/src/features/frets/hooks.cpp b/src/features/frets/hooks.cpp index 6525909..06a3ba4 100644 --- a/src/features/frets/hooks.cpp +++ b/src/features/frets/hooks.cpp @@ -146,6 +146,12 @@ void GameSetScale(uint8_t* entity, float k) { // Entity_SetScale 0x7AE2C0: EAX } } // namespace rsxrfretglue +void RsxrFrets_SetScale(uint8_t* entity, float k) { + if (entity && g_rsxr_fn_setscale) { + rsxrfretglue::GameSetScale(entity, k); + } +} + namespace { using namespace rsxrfrets; using namespace rsxrfretglue; diff --git a/src/features/headstock/assetload_head.cpp b/src/features/headstock/assetload_head.cpp index 8d0fe17..37b6b16 100644 --- a/src/features/headstock/assetload_head.cpp +++ b/src/features/headstock/assetload_head.cpp @@ -143,13 +143,6 @@ void Show(Head& h) { // every frame while wanted: alt shown, its stock siblings } LayerExtra(h, e); } - - if (!h.texChecked) { - h.texChecked = true; - if (RsxrLog_Upto(&g_head.logFrameCheck, 1)) { - LogTextureList("first show"); - } - } } } // namespace @@ -243,7 +236,6 @@ void RsxrAsset_HeadFrame(uint8_t* guitar, bool want) { h->pointed = false; h->locSwapped = false; std::memset(h->altLocX, 0, sizeof h->altLocX); - h->texChecked = false; h->frames = 0; if (want && !h->alt && root && RsxrLog_Upto(&g_head.logNoAlt, 4)) { RsxrLog("assetload: guitar %p (frame entity %p, root %p) has no %s node: no edited model merged for it", diff --git a/src/features/headstock/assetload_head.h b/src/features/headstock/assetload_head.h index 1e09d1e..38398b1 100644 --- a/src/features/headstock/assetload_head.h +++ b/src/features/headstock/assetload_head.h @@ -36,7 +36,6 @@ struct Head { uint8_t* altLoc[kSegs]; // the same names in rsxr_alt uint8_t* altLocX[kExtra]; // rsxr_alt's Locator_Peg_7 / _8 (or _Invert_): PegSet slots 6 / 7 bool locSwapped; - bool texChecked; bool onNonInline; // the frame is not the in-line one (InstrumentInfo +0Ah = 0, 3+3): LT1, pegs uint8_t* pegDone[rsxrhead::kCapacity]; // peg entities whose clone shows the merged in-line peg (3+3) uint8_t* pegCheckedSet; // a stock guitar's PegSet whose pegs were checked for a left-over in-line peg diff --git a/src/features/headstock/assetload_load.cpp b/src/features/headstock/assetload_load.cpp index 33e5797..f0ce953 100644 --- a/src/features/headstock/assetload_load.cpp +++ b/src/features/headstock/assetload_load.cpp @@ -264,10 +264,6 @@ void MergeModels(const char* name, void* res, const void* buf, uint32_t size, bo RegisterTextures(name, second, bytes, buf, size, ®istered); Merge(name, res, second, bytes, kAltName5); } - - if (own && RsxrLog_Upto(&g_head.logTexCheck, 2)) { - LogTextureList("after the merge"); - } } // Eight strings: the 7-peg model file next to the 8-peg one, "" without one (or with eight off). The self-build writes diff --git a/src/features/headstock/assetload_tex.cpp b/src/features/headstock/assetload_tex.cpp index 699014e..fc91fa7 100644 --- a/src/features/headstock/assetload_tex.cpp +++ b/src/features/headstock/assetload_tex.cpp @@ -355,51 +355,4 @@ int RegisterTextures(const char* name, const std::wstring& path, const std::vect return n; } - -// Diagnostic (once): the engine's NiTexture list entries whose file name contains "rsxrhs" (our -// textures): one per texture with renderer data = the model's NiSourceTextures resolved to the -// registered ones; more, or none with renderer data = they did not. -void LogTextureList(const char* when) { - if (!g_rsxr_texlist_cs || !g_rsxr_texlist_head) { - return; - } - - struct E { - uintptr_t obj, rd; - char file[64]; - }; - - E found[24]; - int n = 0, nodes = 0; - auto* cs = reinterpret_cast(g_rsxr_texlist_cs); - - EnterCriticalSection(cs); - uintptr_t p = Rsxr_SafeRead(reinterpret_cast(g_rsxr_texlist_head), 0); - - for (; p && nodes < 8192; ++nodes) { - const char* file = Rsxr_SafeRead(reinterpret_cast(p), 0x3C); - char buf[64] = {}; - - if (file) { - Rsxr_SafeCopyZero(buf, file, sizeof buf - 1); - } - - if (std::strstr(buf, "rsxrhs") && n < 24) { - found[n].obj = p; - found[n].rd = Rsxr_SafeRead(reinterpret_cast(p), 0x2C); - std::memcpy(found[n].file, buf, sizeof buf); - ++n; - } - - p = Rsxr_SafeRead(reinterpret_cast(p), 0x34); - } - - LeaveCriticalSection(cs); - RsxrLog("assetload: texture list (%s): %d of %d node(s) are rsxrhs textures", when, n, nodes); - - for (int i = 0; i < n; ++i) { - RsxrLog("assetload: %p \"%s\" renderer data %p", reinterpret_cast(found[i].obj), found[i].file, - reinterpret_cast(found[i].rd)); - } -} } // namespace rsxrasset diff --git a/src/features/headstock/assetload_tex.h b/src/features/headstock/assetload_tex.h index cfb327f..2af1580 100644 --- a/src/features/headstock/assetload_tex.h +++ b/src/features/headstock/assetload_tex.h @@ -21,6 +21,4 @@ std::vector StockDdsNames(const void* stockBuf, uint32_t stockSize) // and the ones registered here are added (a second model merged into the same frame shares env / normal maps). int RegisterTextures(const char* name, const std::wstring& path, const std::vector& model, const void* stockBuf, uint32_t stockSize, std::vector* done = nullptr); -// Diagnostic: the engine's NiTexture list entries of our textures, logged. -void LogTextureList(const char* when); } // namespace rsxrasset diff --git a/src/features/headstock/state.h b/src/features/headstock/state.h index 6c08d3a..b20f84c 100644 --- a/src/features/headstock/state.h +++ b/src/features/headstock/state.h @@ -55,7 +55,7 @@ struct State { // Game thread; the peg-swap flag retains its interlocked write and volatile reads. volatile long pegSwapEver; // Game thread log limits, retaining interlocked RsxrLog_Upto updates. - volatile long logFrameCheck, logNoAlt, logFrame, logLetters; + volatile long logNoAlt, logFrame, logLetters; volatile long logPegs, logPegAlt, logBind, logSeg7, logLayer, logWidth; // Startup writes before hooks; loader threads then read without a lock. @@ -71,7 +71,7 @@ struct State { volatile long sbState, sbStateLh; // 0 untried, 1 running, 2 succeeded, 3 failed // Resource-loader threads: interlocked log limits (no additional lock). - volatile long logSeen, logMerged, logMissing, logFail, logLayout, logTexCheck, logTex; + volatile long logSeen, logMerged, logMissing, logFail, logLayout, logTex; // Resource-loader threads claim / publish shared and bass builds through interlocked operations. volatile long sbShared, sbBassRh, sbBassLh; // Resource-loader callbacks only take these stable addresses; the tags are never written. diff --git a/src/features/publish/grid.cpp b/src/features/publish/grid.cpp index 1a6e25c..5ea0a77 100644 --- a/src/features/publish/grid.cpp +++ b/src/features/publish/grid.cpp @@ -21,13 +21,22 @@ unsigned PhysicalEdge(unsigned n, bool first, bool bass) { return first && n > 6 ? n - 1 : first ? 0 : n > 6 ? 5 : n - 1; } -int FingerSpan(const uint8_t* fingers, unsigned n, unsigned finger, int* span) { +unsigned FingerRank(unsigned s, unsigned n, bool bass) { + // Bass keeps six template slots: E A D G in 0-3, the low B in 4 (lowest), the high C in 5 (highest). + if (bass) { + return s < 4 ? s + 1 : s == 4 ? 0 : s; + } + + return PhysicalRank(s, n); +} + +int FingerSpan(const uint8_t* fingers, unsigned n, unsigned finger, int* span, bool bass) { // Stock's no-match result is 0-6+1=-5 and its return tests maxIndex != 0. unsigned lo = n, hi = 0; for (unsigned s = 0; s < n; ++s) { if (fingers[s] == finger) { - const unsigned r = PhysicalRank(s, n); + const unsigned r = FingerRank(s, n, bass); lo = std::min(lo, r); hi = std::max(hi, r); @@ -39,6 +48,48 @@ int FingerSpan(const uint8_t* fingers, unsigned n, unsigned finger, int* span) { return hi != 0; } +unsigned FingerAnchor(const uint8_t* fingers, unsigned n, unsigned s, bool bass) { + // The marker loop anchors a finger on the first string in slot order, and the barre runs up from there. The low + // strings (guitar 6/7, bass 4) are not first in slot order, so a barre that includes them must start at its + // lowest physical string. + if (s >= n || fingers[s] == 0xFF) { + return s; + } + + unsigned anchor = s; + + for (unsigned i = 0; i < n; ++i) { + if (fingers[i] == fingers[s] && FingerRank(i, n, bass) < FingerRank(anchor, n, bass)) { + anchor = i; + } + } + + return anchor; +} + +// The marker update 0x58C690 seeks the barre clip to clamp((span - 1) / 5, 0, 1) of its length, and the clip ends at +// five gaps of clipGap. The barre needs span - 1 gaps of gap: up to the clip's end that is a seek (scale the duration +// the seek multiplies), beyond it the clip stays at its end and the capsule is scaled up. +namespace { +float BarreReach(int span, float gap, float clipGap) { + return span <= 1 || !(gap > 0.0f) || !(clipGap > 0.0f) ? 0.0f : float(span - 1) * gap / (5.0f * clipGap); +} +} // namespace + +float BarreClipScale(int span, float gap, float clipGap) { + const float reach = BarreReach(span, gap, clipGap); + + if (!(reach > 0.0f)) { + return 1.0f; + } + + return std::min(reach, 1.0f) / std::min(float(span - 1) / 5.0f, 1.0f); +} + +float BarreEntityScale(int span, float gap, float clipGap) { + return std::max(BarreReach(span, gap, clipGap), 1.0f); +} + int GetCellPos(const uint8_t* grid, unsigned n, unsigned fret, unsigned k, unsigned s, float* out) { if (!grid || !out || n > 8 || !n || fret < 1 || fret > 26 || k > 2 || s >= n) { return 0; diff --git a/src/features/publish/hooks.h b/src/features/publish/hooks.h index a18cfb3..0ea54c5 100644 --- a/src/features/publish/hooks.h +++ b/src/features/publish/hooks.h @@ -48,6 +48,10 @@ __declspec(dllexport) int __cdecl RsxrPublish_GridPos(uint8_t* grid, unsigned fr __declspec(dllexport) int __cdecl RsxrPublish_GridBuild(uint8_t* grid, uint8_t* guitar); __declspec(dllexport) int __cdecl RsxrPublish_FingerSpan(const uint8_t* tpl, unsigned finger, int* span); __declspec(dllexport) unsigned __cdecl RsxrPublish_Edge(uint8_t* info, unsigned first); +__declspec(dllexport) unsigned __cdecl RsxrPublish_FingerAnchor(const uint8_t* tpl, unsigned string, + const uint8_t* owner); +__declspec(dllexport) extern volatile uint32_t g_rsxr_finger_bass; +__declspec(dllexport) void __cdecl RsxrPublish_BarreFit(const uint8_t* owner, uint8_t* marker, float* duration); } // The pitch copies' call-in entries (hooks_callin.cpp; hooks_pitch.cpp writes them into the copies). diff --git a/src/features/publish/hooks_barre.cpp b/src/features/publish/hooks_barre.cpp new file mode 100644 index 0000000..e618a4b --- /dev/null +++ b/src/features/publish/hooks_barre.cpp @@ -0,0 +1,64 @@ +// The finger marker barres on an extended neck (PUBBC, hooks_gridsites.cpp): the stock barre clip ends at six guitar +// strings at the guitar gap, so its seek and the capsule's scale are fitted to the span at the neck's string gap. +#include "features/frets/frets.h" +#include "features/publish/hooks.h" +#include "features/spacing/spacing.h" +#include "model/instrument.h" +#include "platform/seh.h" +#include + +namespace { +constexpr float kGuitarGap = 1.608f; // the stock string gaps (features/spacing) +constexpr float kBassGap = 2.68f; +constexpr float kClipGap = 1.608f; // the barre clip at its end spans five guitar gaps (8.04, the stock neck width) + +// The string gap of an extended instrument's neck (owner +6Ch the player, its guitar's InstrumentInfo), 0 otherwise. +float ExtendedGap(const uint8_t* owner) { + const uint8_t* player = owner ? *reinterpret_cast(owner + 0x6C) : nullptr; + const uint8_t* guitar = player ? *reinterpret_cast(player + rsxr::kSessionGuitar) : nullptr; + const uint8_t* info = rsxr::GuitarInfo(guitar); + + if (!info) { + return 0.0f; + } + + const bool bass = rsxr::IsBassKind(info[rsxr::kInfoKind]); + + if (info[rsxr::kInfoStrings] <= (bass ? 4 : 6)) { + return 0.0f; + } + + return (bass ? kBassGap : kGuitarGap) * RsxrSpacing_Factor(info); +} + +void BarreFit(const uint8_t* owner, uint8_t* const* marker, float* duration) { + const float gap = ExtendedGap(owner); + + if (!(gap > 0.0f)) { + return; + } + + const int span = *reinterpret_cast(reinterpret_cast(marker) + 0x1C); + + *duration *= rsxrpubgrid::BarreClipScale(span, gap, kClipGap); + + const float k = rsxrpubgrid::BarreEntityScale(span, gap, kClipGap); + + for (int i = 1; i <= 2; ++i) { + RsxrFrets_SetScale(marker[i], k); + } +} +} // namespace + +// `owner` and `marker` (+4 / +8 the capsule entities, +1Ch the span) of the marker update 0x58C690 when the span +// changed, `duration` its barre clip length (the seek is clamp((span - 1) / 5, 0, 1) of it). On an extended +// instrument the clip is seeked to the barre's real length at the neck's string gap, and the capsule is scaled up +// where that is longer than the clip (wider than the stock neck). +extern "C" void __cdecl RsxrPublish_BarreFit(const uint8_t* owner, uint8_t* marker, float* duration) { + __try { + if (owner && marker && duration) { + BarreFit(owner, reinterpret_cast(marker), duration); + } + } __except (Rsxr_FaultFilter(GetExceptionCode())) { + } +} diff --git a/src/features/publish/hooks_grid.cpp b/src/features/publish/hooks_grid.cpp index fa40749..5ab1020 100644 --- a/src/features/publish/hooks_grid.cpp +++ b/src/features/publish/hooks_grid.cpp @@ -256,8 +256,13 @@ extern "C" int __cdecl RsxrPublish_GridBuild(uint8_t* grid, uint8_t* guitar) { } } +// The marker being placed belongs to an extended bass (5/6 strings): set by RsxrPublish_FingerAnchor (PUBFA) at the +// entry of the marker function, read by the span (PUBGF) that the same call makes next on the same thread. +extern "C" __declspec(dllexport) volatile uint32_t g_rsxr_finger_bass = 0; + extern "C" int __cdecl RsxrPublish_FingerSpan(const uint8_t* tpl, unsigned finger, int* span) { const uint8_t* t8 = RsxrNs_AsT8(tpl); + const bool bass = g_rsxr_finger_bass != 0; if (t8) { unsigned n = t8[rsxrns::kT8Slots]; @@ -265,10 +270,34 @@ extern "C" int __cdecl RsxrPublish_FingerSpan(const uint8_t* tpl, unsigned finge if (n < 6 || n > 8) { n = 6; } - return rsxrpubgrid::FingerSpan(t8 + rsxrns::kT8Fingers, n, finger, span); + return rsxrpubgrid::FingerSpan(t8 + rsxrns::kT8Fingers, n, finger, span, bass); } - return rsxrpubgrid::FingerSpan(tpl + 0xA, 6, finger, span); + return rsxrpubgrid::FingerSpan(tpl + 0xA, 6, finger, span, bass); +} + +// `owner` is the marker function's owner (EDI at its entry): +6Ch the player, whose guitar gives the instrument. +// Six-string guitar and four-string bass keep the stock anchor (slot order is physical order there). +extern "C" unsigned __cdecl RsxrPublish_FingerAnchor(const uint8_t* tpl, unsigned string, const uint8_t* owner) { + const uint8_t* player = owner ? *reinterpret_cast(owner + 0x6C) : nullptr; + const uint8_t* guitar = player ? *reinterpret_cast(player + rsxr::kSessionGuitar) : nullptr; + const uint8_t* info = rsxr::GuitarInfo(guitar); + const bool bass = info && rsxr::IsBassKind(info[rsxr::kInfoKind]) && info[rsxr::kInfoStrings] > 4; + const uint8_t* t8 = RsxrNs_AsT8(tpl); + + g_rsxr_finger_bass = bass ? 1 : 0; + + if (bass) { + return rsxrpubgrid::FingerAnchor(t8 ? t8 + rsxrns::kT8Fingers : tpl + 0xA, 6, string, true); + } + + if (!t8) { + return string; + } + + const unsigned n = t8[rsxrns::kT8Slots]; + + return n == 7 || n == 8 ? rsxrpubgrid::FingerAnchor(t8 + rsxrns::kT8Fingers, n, string) : string; } extern "C" unsigned __cdecl RsxrPublish_Edge(uint8_t* info, unsigned first) { diff --git a/src/features/publish/hooks_gridsites.cpp b/src/features/publish/hooks_gridsites.cpp index f2d84ed..880d124 100644 --- a/src/features/publish/hooks_gridsites.cpp +++ b/src/features/publish/hooks_gridsites.cpp @@ -8,6 +8,8 @@ // PUBGB Rnd_FretGrid_Build exit: build the extra cells 6/7 once // PUBGA Rnd_GetStringAttachPoint entry: strings 6/7 via RsxrGs_AttachExt; [neck] spacing_* scaled // PUBGF finger span over the template's physical ranks +// PUBFA the string a finger marker is anchored on: the barre's lowest physical string (light) +// PUBBC a finger marker's changed span: fit the barre capsule to the neck's string gap // PUBEDGE the edge string of a string action over N strings (light) // PUBGP (site R1) Rnd_FretGrid_GetCellPos: every cell position query from the native cells (sse) // Converted from naked stubs (frozen at 9c0e44f, tools/tests/test_midhook_features.py). Light @@ -151,6 +153,34 @@ extern "C" __declspec(dllexport) void __cdecl Rsxr_Mid_PUBGF(Context& c) { RsxrMid::Return(c, static_cast(span), 8); } +// PUBFA - 0x58CDC0, entry of the neck finger marker (AL = string, ECX = template, EDI = the marker owner; only caller +// 0x58CD5F in the marker loop 0x58CC80). The loop picks the first string in slot order that uses a finger, and PUBGF's +// span runs up from it, so a barre over the low B and E was drawn from the E, one string too high. With the +// publication ports the anchor becomes the barre's lowest physical string, on an extended bass in the bass order (low +// B in slot 4). It also records whether the marker is a bass one for PUBGF's span. Replays `push ebp; mov ebp,esp; sub +// esp,10h`; the flags are rewritten by that `sub` (contract "dead"). +extern "C" __declspec(dllexport) void __cdecl Rsxr_Mid_PUBFA(Context& c) { + if (!g_rsxr_native_publish) { + return; + } + + c.eax = + WithLow8(c.eax, RsxrPublish_FingerAnchor(Ptr(c.ecx), c.eax & 0xFF, Ptr(c.edi))); +} + +// PUBBC - 0x58C7DC in the finger marker update 0x58C690 (EBP frame: [EBP+8] = the owner, EBX = the marker), in the +// block that re-seeks the barre clip when the span changed, after the clip duration was stored at [ESP+14h]. The seek +// is clamp((span - 1) / 5, 0, 1) of it, fit for six guitar strings; RsxrPublish_BarreFit scales the duration and the +// capsule to the span at an extended neck's string gap. Replays `mov esi,[ebx+1Ch]; sub esp,0Ch`; the flags are +// rewritten by that `sub` (contract "dead"). +extern "C" __declspec(dllexport) void __cdecl Rsxr_Mid_PUBBC(Context& c) { + if (!g_rsxr_native_publish) { + return; + } + + RsxrPublish_BarreFit(Ptr(Dword(c.ebp + 8)), Ptr(c.ebx), Ptr(c.esp + 0x14)); +} + // PUBEDGE - 0x7E72D0 in the string-action function 0x7E7140 (EAX = info, CL = first): the stock edge string `first ? 0 // : count-1` (13 bytes: test cl,cl / xor al,al / mov al,[eax+0Bh] / dec al) becomes RsxrPublish_Edge (physical rank of // the first / last string of the published count). EAX = the edge string. The flags at the exit are dead diff --git a/src/features/publish/publish.h b/src/features/publish/publish.h index 40355c8..1952035 100644 --- a/src/features/publish/publish.h +++ b/src/features/publish/publish.h @@ -71,7 +71,15 @@ namespace rsxrpubgrid { unsigned PhysicalRank(unsigned string, unsigned count); unsigned PhysicalEdge(unsigned count, bool first, bool bass = false); // Exact stock scan for stock templates; native T8 scans physical ranks. -int FingerSpan(const uint8_t* fingers, unsigned count, unsigned finger, int* span); +// A template slot's physical rank for the finger markers (bass: the six-slot bass order, low B in slot 4). +unsigned FingerRank(unsigned string, unsigned count, bool bass); +int FingerSpan(const uint8_t* fingers, unsigned count, unsigned finger, int* span, bool bass = false); +// The string a finger's neck marker is anchored on: the physically lowest string with the same finger as `string`. +unsigned FingerAnchor(const uint8_t* fingers, unsigned count, unsigned string, bool bass = false); +// The barre capsule over span strings at a string gap (the stock clip ends at five gaps of clipGap): the factor for +// the clip duration the stock seek multiplies, and the capsule's scale beyond the clip's end (1 within it). +float BarreClipScale(int span, float gap, float clipGap); +float BarreEntityScale(int span, float gap, float clipGap); // GridBuild's bounded wait (pure, tests): one entry per grid that reported "not ready". WaitStep returns true // (give up) once `grid` has been not ready for limitMs; WaitDone clears its entry. // An entry belongs to one build. A poll that finds the entry's owner (the guitar) changed, or that comes diff --git a/src/features/publish/registration.cpp b/src/features/publish/registration.cpp index 787a44c..3f403e2 100644 --- a/src/features/publish/registration.cpp +++ b/src/features/publish/registration.cpp @@ -13,7 +13,7 @@ void Rsxr_Mid_PUBGP(RsxrMid::Context&); // hooks_gridsites.cpp (site R1, sse mo // clang-format off PUB_DECL(PUBCL) PUB_DECL(PUBTO) PUB_DECL(PUBWU) PUB_DECL(PUBNL) PUB_DECL(PUBAN) PUB_DECL(PUBAC) // hooks_entries.cpp PUB_DECL_GUARD(PUBGS) PUB_DECL_GUARD(PUBGE1) PUB_DECL_GUARD(PUBGE2) // hooks_gridsites.cpp -PUB_DECL_RESUME(PUBGC) PUB_DECL_RESUME(PUBGO) PUB_DECL_RESUME(PUBGB) PUB_DECL(PUBGA) PUB_DECL(PUBGF) +PUB_DECL_RESUME(PUBGC) PUB_DECL_RESUME(PUBGO) PUB_DECL_RESUME(PUBGB) PUB_DECL(PUBGA) PUB_DECL(PUBGF) PUB_DECL(PUBFA) PUB_DECL(PUBBC) PUB_DECL_RESUME(PUBEDGE) PUB_DECL(PUBZ) // hooks_pitch.cpp: PUBZ0-PUBZ6, the callees of the call sites extern uintptr_t g_rsxr_target_PUBZ0, g_rsxr_target_PUBZ4, g_rsxr_target_PUBZ5, g_rsxr_target_PUBZ6; @@ -47,6 +47,8 @@ const RsxrHook kHooks[] = { RSXR_PUB_MID(PUBGB, &g_rsxr_resume_PUBGB, nullptr, Full), RSXR_PUB_MID(PUBGA, nullptr, nullptr, Full), RSXR_PUB_MID(PUBGF, nullptr, nullptr, Full), + RSXR_PUB_MID(PUBFA, nullptr, nullptr, Light), + RSXR_PUB_MID(PUBBC, nullptr, nullptr, Full), RSXR_PUB_MID(PUBEDGE, &g_rsxr_resume_PUBEDGE, nullptr, Light), RSXR_PUB_MID(PUBNL, nullptr, nullptr, Light), RSXR_PUB_MID(PUBAN, nullptr, nullptr, Light), diff --git a/src/version.h b/src/version.h index 90378ce..7bd6866 100644 --- a/src/version.h +++ b/src/version.h @@ -1,2 +1,2 @@ #pragma once -#define RSXR_VERSION "1.0.0-beta.5" +#define RSXR_VERSION "1.0.0-beta.6" diff --git a/tests/publish/test_publish_grid.cpp b/tests/publish/test_publish_grid.cpp index 471548d..b49e28e 100644 --- a/tests/publish/test_publish_grid.cpp +++ b/tests/publish/test_publish_grid.cpp @@ -18,6 +18,138 @@ TEST(publish_grid_physical_order_and_barres) { } } +TEST(publish_grid_finger_anchor_is_the_lowest_physical_string) { + // Seven strings: slot 6 is the low B, below slot 0 (E). A B+E barre found first on the E anchors on the B. + const uint8_t barre7[8] = {1, 1, 255, 255, 255, 255, 1, 255}; + + CHECK_EQ(rsxrpubgrid::FingerAnchor(barre7, 7, 0), 6u); + CHECK_EQ(rsxrpubgrid::FingerAnchor(barre7, 7, 6), 6u); + + // Eight strings: slot 7 (low F#) is below slot 6 (low B). + const uint8_t barre8[8] = {2, 255, 255, 255, 255, 255, 2, 2}; + + CHECK_EQ(rsxrpubgrid::FingerAnchor(barre8, 8, 0), 7u); + + // A finger only on stock strings keeps its first string; another finger is ignored. + const uint8_t stock[8] = {255, 1, 1, 3, 255, 255, 3, 255}; + + CHECK_EQ(rsxrpubgrid::FingerAnchor(stock, 7, 1), 1u); + CHECK_EQ(rsxrpubgrid::FingerAnchor(stock, 7, 3), 6u); + + // Six strings, an unused finger or an out-of-range string: unchanged. + CHECK_EQ(rsxrpubgrid::FingerAnchor(barre7, 6, 0), 0u); + CHECK_EQ(rsxrpubgrid::FingerAnchor(barre7, 7, 2), 2u); + CHECK_EQ(rsxrpubgrid::FingerAnchor(barre7, 7, 9), 9u); +} + +TEST(publish_grid_bass_finger_anchor_and_span_use_the_bass_order) { + // Bass slots: E A D G in 0-3, low B in 4, high C in 5. Physical order B E A D G C. + int span = 0; + + // Low B + E barre, found first on the E: anchored on the B, two strings wide (slot order said five). + const uint8_t be[8] = {1, 255, 255, 255, 1, 255, 255, 255}; + + CHECK_EQ(rsxrpubgrid::FingerAnchor(be, 6, 0, true), 4u); + rsxrpubgrid::FingerSpan(be, 6, 1, &span, true); + CHECK_EQ(span, 2); + rsxrpubgrid::FingerSpan(be, 6, 1, &span); + CHECK_EQ(span, 5); // the guitar order, for comparison + + // G + high C barre on six strings: two strings wide, anchored on the G. + const uint8_t gc[8] = {255, 255, 255, 2, 255, 2, 255, 255}; + + CHECK_EQ(rsxrpubgrid::FingerAnchor(gc, 6, 3, true), 3u); + rsxrpubgrid::FingerSpan(gc, 6, 2, &span, true); + CHECK_EQ(span, 2); + + // B E A barre: three strings from the B. A barre on E A only keeps the E. + const uint8_t bea[8] = {1, 1, 255, 255, 1, 255, 255, 255}; + + CHECK_EQ(rsxrpubgrid::FingerAnchor(bea, 6, 0, true), 4u); + rsxrpubgrid::FingerSpan(bea, 6, 1, &span, true); + CHECK_EQ(span, 3); + const uint8_t ea[8] = {1, 1, 255, 255, 255, 255, 255, 255}; + + CHECK_EQ(rsxrpubgrid::FingerAnchor(ea, 6, 0, true), 0u); + rsxrpubgrid::FingerSpan(ea, 6, 1, &span, true); + CHECK_EQ(span, 2); + + CHECK_EQ(rsxrpubgrid::FingerRank(4, 6, true), 0u); + CHECK_EQ(rsxrpubgrid::FingerRank(0, 6, true), 1u); + CHECK_EQ(rsxrpubgrid::FingerRank(5, 6, true), 5u); +} + +TEST(publish_grid_finger_anchor_and_span_match_open_pitch_order_for_every_pattern) { + // Every finger pattern (none, thumb 0, fingers 1-4 on each string) of every extended instrument. The oracle + // orders the template slots by their open pitch, independent of FingerRank: the anchor must be the lowest + // string with that finger and the span must run from it to the highest. + struct Case { + unsigned n; + bool bass; + int midi[8]; + }; + + const Case cases[] = { + {7, false, {40, 45, 50, 55, 59, 64, 35, 0}}, + {8, false, {40, 45, 50, 55, 59, 64, 35, 30}}, + {6, true, {28, 33, 38, 43, 23, 0, 0, 0}}, // five-string bass: slot 5 unused + {6, true, {28, 33, 38, 43, 23, 48, 0, 0}}, + }; + const uint8_t values[] = {255, 0, 1, 2, 3, 4}; + unsigned checked = 0; + + for (const Case& c : cases) { + const unsigned used = c.bass && c.midi[5] == 0 ? 5 : c.n; // strings that can hold a finger + unsigned total = 1; + + for (unsigned i = 0; i < used; ++i) { + total *= 6; + } + + for (unsigned code = 0; code < total; ++code) { + uint8_t f[8] = {255, 255, 255, 255, 255, 255, 255, 255}; + unsigned k = code; + + for (unsigned i = 0; i < used; ++i, k /= 6) { + f[i] = values[k % 6]; + } + + for (unsigned s = 0; s < used; ++s) { + if (f[s] == 255) { + continue; + } + + int lo = 1000, hi = -1, loSlot = -1, ranksBelowLo = 0, ranksBelowHi = 0; + + for (unsigned i = 0; i < used; ++i) { + if (f[i] == f[s] && c.midi[i] < lo) { + lo = c.midi[i]; + loSlot = int(i); + } + + if (f[i] == f[s] && c.midi[i] > hi) { + hi = c.midi[i]; + } + } + + for (unsigned i = 0; i < used; ++i) { + ranksBelowLo += c.midi[i] < lo; + ranksBelowHi += c.midi[i] < hi; + } + + int span = 0; + + rsxrpubgrid::FingerSpan(f, c.n, f[s], &span, c.bass); + CHECK_EQ(rsxrpubgrid::FingerAnchor(f, c.n, s, c.bass), unsigned(loSlot)); + CHECK_EQ(span, ranksBelowHi - ranksBelowLo + 1); + ++checked; + } + } + } + + CHECK(checked > 1000000u); +} + TEST(publish_grid_native_query_guards_and_actual_cells) { std::vector grid(rsxrfg::kSizeNative); @@ -150,3 +282,40 @@ TEST(publish_grid_wait_entry_does_not_outlive_its_build) { CHECK(!rsxrpubgrid::Failed(u, 2, &other)); CHECK(u[0].grid == nullptr); } + +TEST(publish_grid_barre_fit_reaches_the_span_at_the_neck_gap) { + const auto approx = [](float a, float b) { + return a > b - 1e-4f && a < b + 1e-4f; + }; + const float g = 1.608f; // the guitar gap, the clip's own + + // Up to six strings at the clip's gap: stock (the seek (span - 1) / 5, no scale). + for (int span = -1; span <= 6; ++span) { + CHECK(approx(rsxrpubgrid::BarreClipScale(span, g, g), 1.0f)); + CHECK(approx(rsxrpubgrid::BarreEntityScale(span, g, g), 1.0f)); + } + + // Seven and eight strings: the clip stays at its end, the capsule grows to six / seven gaps. + CHECK(approx(rsxrpubgrid::BarreClipScale(7, g, g), 1.0f)); + CHECK(approx(rsxrpubgrid::BarreEntityScale(7, g, g), 6.0f / 5.0f)); + CHECK(approx(rsxrpubgrid::BarreEntityScale(8, g, g), 7.0f / 5.0f)); + + // A wider gap within the clip: a longer seek, no scale (bass: 2 strings = one gap of 2.68). + CHECK(approx(rsxrpubgrid::BarreClipScale(2, 2.68f, g), 2.68f / g)); + CHECK(approx(rsxrpubgrid::BarreEntityScale(2, 2.68f, g), 1.0f)); + // ... and beyond it: the clip's end, then the scale (a 6-string bass full barre: 5 gaps of 2.68). + CHECK(approx(rsxrpubgrid::BarreClipScale(6, 2.68f, g), 1.0f)); + CHECK(approx(rsxrpubgrid::BarreEntityScale(6, 2.68f, g), 5.0f * 2.68f / (5.0f * g))); + + // A narrow 8-string neck as wide as a six-string one: the full barre is the clip's end exactly, unscaled. + const float narrow = 5.0f * g / 7.0f; + + CHECK(approx(rsxrpubgrid::BarreClipScale(8, narrow, g), 1.0f)); + CHECK(approx(rsxrpubgrid::BarreEntityScale(8, narrow, g), 1.0f)); + // ... and its two-string barre a shorter seek: one narrow gap of the 1/5 the stock seek gives. + CHECK(approx(rsxrpubgrid::BarreClipScale(2, narrow, g), narrow / g)); + + // Bad gaps keep the stock seek. + CHECK(approx(rsxrpubgrid::BarreClipScale(7, 0.0f, g), 1.0f)); + CHECK(approx(rsxrpubgrid::BarreEntityScale(7, g, 0.0f), 1.0f)); +} diff --git a/tests/test_isolate.cpp b/tests/test_isolate.cpp index 0c39d35..5bbed34 100644 --- a/tests/test_isolate.cpp +++ b/tests/test_isolate.cpp @@ -222,8 +222,8 @@ TEST(publish_and_chordloops_sites_have_their_own_groups) { } } - CHECK_EQ(pub, 25u); - CHECK_EQ(cl, 20u); // + CLVE + CHECK_EQ(pub, 27u); // + PUBFA, PUBBC + CHECK_EQ(cl, 20u); // + CLVE for (const char* id : {"PA1", "PA2", "PM0", "PR0", "PT1", "PM1", "PE0", "PC1", "PC2", "PC3", "PC4", "PBH"}) { const RsxrHook* h = Rsxr_FindHook(id); diff --git a/tools/gen_publish_grid.py b/tools/gen_publish_grid.py index 7cf1419..692d331 100644 --- a/tools/gen_publish_grid.py +++ b/tools/gen_publish_grid.py @@ -17,6 +17,8 @@ ("PUBGB", 0x58FA25, 5, None), ("PUBGA", 0x594530, 6, None), ("PUBGF", 0x58CF90, 5, None), + ("PUBFA", 0x58CDC0, 6, None), + ("PUBBC", 0x58C7DC, 6, None), ("PUBEDGE", 0x7E72D0, 13, None), ] diff --git a/tools/tests/emu_harness.py b/tools/tests/emu_harness.py index 0e478fa..5279a7f 100644 --- a/tools/tests/emu_harness.py +++ b/tools/tests/emu_harness.py @@ -275,15 +275,15 @@ *("TU8H", "TU8C", "TU8A", "TU8INIT", "TU8FREE", "AT"), # features/tuner/hooks_entries.cpp (+ the TS8* entries) *("TS8SEL", "TS8STA", "TS8STB", "TS8M2E", "TS8MD2", "TS8MD0", "TS8MD1", "TS8MD3", "TS8FIN", "TS8FOU", "TS8PLS"), *("TS8PEK", "TS8LET", "TS8LPL", "TS8LRL", "TS8PKS", "TS8PKR", "TS8PKP", "TS8PKL", "TS8LOF", "TS8HNT"), - *("PUBCL", "PUBTO", "PUBWU", "PUBNL", "PUBAN", "PUBAC"), # features/publish/hooks_entries.cpp - *("PUBGS", "PUBGE1", "PUBGE2", "PUBGC", "PUBGO", "PUBGB", "PUBGA", "PUBGF", "PUBEDGE"), # hooks_gridsites.cpp + *("PUBCL", "PUBTO", "PUBWU", "PUBNL", "PUBAN", "PUBAC"), # features/publish: hooks_entries.cpp, hooks_gridsites.cpp + *("PUBGS", "PUBGE1", "PUBGE2", "PUBGC", "PUBGO", "PUBGB", "PUBGA", "PUBGF", "PUBFA", "PUBBC", "PUBEDGE"), *("PSU1", "PSU2", "PSM1", "LT0", "LT1", "AL1"), # features/headstock/hooks_mid.cpp *private_features.get("MID_SITES", ()), # the private extras (tools/private_features.py) *("GSFR", "GSBD", "GSUL", "GSLD", "GSFO", "GSFI", "GSXF", "GSWD", "GSUP", "GSRS", "GSPK", "GSVB"), *("GSIC", "GSDM", "GSGL", "GSHC", "GRM1", "GRM2"), # features/strings/hooks_entries.cpp ) BATCH5_LIGHT = { - *("CLBM", "CLBA", "CLGU", "CLGE", "CLVB", "CLVE", "NG1"), + *("CLBM", "CLBA", "CLGU", "CLGE", "CLVB", "CLVE", "NG1", "PUBFA"), *("PUBCL", "PUBTO", "PUBWU", "PUBNL", "PUBAN", "PUBAC", "PUBGS", "PUBGE1", "PUBGE2", "PUBGC", "PUBGO", "PUBEDGE"), } MID_CALLBACKS.update({sid: f"Rsxr_Mid_{sid}" for sid in BATCH5_MID})