Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/release/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sites.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
4 changes: 4 additions & 0 deletions src/features/frets/frets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
6 changes: 6 additions & 0 deletions src/features/frets/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions src/features/headstock/assetload_head.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/features/headstock/assetload_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/features/headstock/assetload_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ void MergeModels(const char* name, void* res, const void* buf, uint32_t size, bo
RegisterTextures(name, second, bytes, buf, size, &registered);
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
Expand Down
47 changes: 0 additions & 47 deletions src/features/headstock/assetload_tex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CRITICAL_SECTION*>(g_rsxr_texlist_cs);

EnterCriticalSection(cs);
uintptr_t p = Rsxr_SafeRead<uintptr_t>(reinterpret_cast<void*>(g_rsxr_texlist_head), 0);

for (; p && nodes < 8192; ++nodes) {
const char* file = Rsxr_SafeRead<const char*>(reinterpret_cast<void*>(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<uintptr_t>(reinterpret_cast<void*>(p), 0x2C);
std::memcpy(found[n].file, buf, sizeof buf);
++n;
}

p = Rsxr_SafeRead<uintptr_t>(reinterpret_cast<void*>(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<void*>(found[i].obj), found[i].file,
reinterpret_cast<void*>(found[i].rd));
}
}
} // namespace rsxrasset
2 changes: 0 additions & 2 deletions src/features/headstock/assetload_tex.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ std::vector<std::string> 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<uint8_t>& model,
const void* stockBuf, uint32_t stockSize, std::vector<std::string>* done = nullptr);
// Diagnostic: the engine's NiTexture list entries of our textures, logged.
void LogTextureList(const char* when);
} // namespace rsxrasset
4 changes: 2 additions & 2 deletions src/features/headstock/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
55 changes: 53 additions & 2 deletions src/features/publish/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/features/publish/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
64 changes: 64 additions & 0 deletions src/features/publish/hooks_barre.cpp
Original file line number Diff line number Diff line change
@@ -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 <windows.h>

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<const uint8_t* const*>(owner + 0x6C) : nullptr;
const uint8_t* guitar = player ? *reinterpret_cast<const uint8_t* const*>(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<const int*>(reinterpret_cast<const uint8_t*>(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<uint8_t* const*>(marker), duration);
}
} __except (Rsxr_FaultFilter(GetExceptionCode())) {
}
}
33 changes: 31 additions & 2 deletions src/features/publish/hooks_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,48 @@ 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];

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<const uint8_t* const*>(owner + 0x6C) : nullptr;
const uint8_t* guitar = player ? *reinterpret_cast<const uint8_t* const*>(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) {
Expand Down
Loading
Loading