#include "osc_server.h" #include "param_map.h" #include "daemon_log.h" #include #include #include // Decode inbound OSC packets and dispatch the whitelisted subset // (/avatar/parameters/Backglow{R|G|B}{0-9} and /avatar/parameters/BackglowBri) // into the shared ParamMap. Anything outside the whitelist is dropped silently // per D-21; malformed OSC throws from oscpp and is caught here to match D-21. namespace { // WR-01 (iter-3) fix: returns true iff this message hit a whitelisted Backglow // address AND actually dispatched into ParamMap. Non-whitelisted traffic must // NOT mark OSC-arrived — otherwise VRChat's non-backglow avatar param firehose // pins NsSinceLastOsc at 0 and D-15 silence-fade never triggers. bool HandleOscMessage(const OSCPP::Server::Message& msg, ParamMap& map) { const char* addr = msg.address(); static constexpr const char* kPrefix = "/avatar/parameters/Backglow"; static constexpr size_t kPrefixLen = 27; if (std::strncmp(addr, kPrefix, kPrefixLen) != 0) return false; // D-21 silent drop const char* suffix = addr + kPrefixLen; // "R3", "G9", "Bri" OSCPP::Server::ArgStream args = msg.args(); if (args.atEnd() || args.tag() != 'f') return false; // D-21 malformed -> drop const float v = args.float32(); if (std::strcmp(suffix, "Bri") == 0) { map.SetBrightness(v); return true; } if (suffix[0] != 'R' && suffix[0] != 'G' && suffix[0] != 'B') return false; if (suffix[1] < '0' || suffix[1] > '9') return false; if (suffix[2] != '\0') return false; const int channel = (suffix[0] == 'R') ? 0 : (suffix[0] == 'G') ? 1 : 2; const int ledIdx = suffix[1] - '0'; map.SetChannel(ledIdx, channel, v); return true; } bool HandleOscPacketImpl(const uint8_t* buf, std::size_t size, ParamMap& map) { OSCPP::Server::Packet pkt(buf, size); bool anyDispatched = false; if (pkt.isBundle()) { OSCPP::Server::Bundle b(pkt); OSCPP::Server::PacketStream elems = b.packets(); while (!elems.atEnd()) { OSCPP::Server::Packet sub = elems.next(); if (HandleOscPacketImpl(static_cast(sub.data()), sub.size(), map)) { anyDispatched = true; } } } else { if (HandleOscMessage(OSCPP::Server::Message(pkt), map)) { anyDispatched = true; } } return anyDispatched; } } // namespace bool HandleOscPacket(const uint8_t* buf, std::size_t size, ParamMap& map) { // D-21: wrap oscpp in try/catch — malformed packet is DROPPED silently. try { const bool dispatched = HandleOscPacketImpl(buf, size, map); // WR-01 (iter-3) fix: only reset silence-fade timer when the packet // actually contained at least one whitelisted Backglow address. VRChat // streams dozens of non-backglow avatar params per second; marking any // valid packet as "OSC arrived" defeats the D-15 silence-fade entirely. if (dispatched) map.MarkOscArrived(); return dispatched; } catch (const std::exception& e) { DaemonLog("malformed OSC dropped: %s", e.what()); } catch (...) { DaemonLog("malformed OSC dropped (unknown exception)"); } return false; }