Skip to content

fix(iracing): fix non-Latin driver names showing as ??? in session YAML#15

Merged
mvoof merged 5 commits into
mainfrom
fix/cyrillic-encoding
Jun 27, 2026
Merged

fix(iracing): fix non-Latin driver names showing as ??? in session YAML#15
mvoof merged 5 commits into
mainfrom
fix/cyrillic-encoding

Conversation

@mvoof

@mvoof mvoof commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Problem

Driver names with Cyrillic (and other non-Latin) characters appeared as ?
in the session YAML. Two root causes:

  1. session_yaml() always decoded bytes as CP-1252, but iRacing now sends
    the session string as UTF-8 when irsdkUTF8SessionStr is set (introduced
    to support international names). UTF-8 bytes decoded as CP-1252 → ?.

  2. For the non-UTF-8 fallback path, CP-1252 was hardcoded. On Russian Windows
    the system ACP is CP-1251, so Cyrillic bytes were still corrupted even
    before iRacing added the UTF-8 flag.

Changes

  • session_yaml() now reads the irsdkUTF8SessionStr telemetry variable at
    runtime and switches to String::from_utf8_lossy when it is non-zero.
  • decode_cp1252 now calls GetACP() (Win32) to pick the correct codec from
    encoding_rs based on the actual system locale instead of always using
    CP-1252. Supports CP-1251/1250/1253/1254/1255/1256/1257/1258/874/932/936/949/950.
  • Added Win32_Globalization feature to the windows-sys dependency.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for UTF-8 session strings in iRacing telemetry and dynamically resolves the Windows system Active Code Page (ACP) instead of hardcoding CP-1252. Feedback suggests caching the resolved system ACP encoding using std::sync::OnceLock to avoid the overhead of calling the FFI function GetACP() on every string decoding operation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/utils.rs
Comment on lines +15 to +42
fn system_acp_encoding() -> &'static encoding_rs::Encoding {
#[cfg(all(windows, any(feature = "iracing", feature = "ac-evo", feature = "lmu")))]
{
// SAFETY: GetACP() is always safe to call and never fails.
let acp = unsafe { windows_sys::Win32::Globalization::GetACP() };
match acp {
1251 => encoding_rs::WINDOWS_1251,
1252 => encoding_rs::WINDOWS_1252,
1250 => encoding_rs::WINDOWS_1250,
1253 => encoding_rs::WINDOWS_1253,
1254 => encoding_rs::WINDOWS_1254,
1255 => encoding_rs::WINDOWS_1255,
1256 => encoding_rs::WINDOWS_1256,
1257 => encoding_rs::WINDOWS_1257,
1258 => encoding_rs::WINDOWS_1258,
874 => encoding_rs::WINDOWS_874,
932 => encoding_rs::SHIFT_JIS,
936 => encoding_rs::GBK,
949 => encoding_rs::EUC_KR,
950 => encoding_rs::BIG5,
_ => encoding_rs::WINDOWS_1252,
}
}
#[cfg(not(all(windows, any(feature = "iracing", feature = "ac-evo", feature = "lmu"))))]
{
encoding_rs::WINDOWS_1252
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling GetACP() on every string decoding operation can introduce unnecessary FFI overhead, especially since telemetry string decoding can happen multiple times per frame. Since the system active code page (ACP) does not change during the lifetime of the process, we can cache the resolved encoding using std::sync::OnceLock to completely eliminate this overhead after the first call.

fn system_acp_encoding() -> &'static encoding_rs::Encoding {
    static ENCODING: std::sync::OnceLock<&'static encoding_rs::Encoding> = std::sync::OnceLock::new();
    *ENCODING.get_or_init(|| {
        #[cfg(all(windows, any(feature = "iracing", feature = "ac-evo", feature = "lmu")))]
        {
            // SAFETY: GetACP() is always safe to call and never fails.
            let acp = unsafe { windows_sys::Win32::Globalization::GetACP() };
            match acp {
                1251 => encoding_rs::WINDOWS_1251,
                1252 => encoding_rs::WINDOWS_1252,
                1250 => encoding_rs::WINDOWS_1250,
                1253 => encoding_rs::WINDOWS_1253,
                1254 => encoding_rs::WINDOWS_1254,
                1255 => encoding_rs::WINDOWS_1255,
                1256 => encoding_rs::WINDOWS_1256,
                1257 => encoding_rs::WINDOWS_1257,
                1258 => encoding_rs::WINDOWS_1258,
                874  => encoding_rs::WINDOWS_874,
                932  => encoding_rs::SHIFT_JIS,
                936  => encoding_rs::GBK,
                949  => encoding_rs::EUC_KR,
                950  => encoding_rs::BIG5,
                _    => encoding_rs::WINDOWS_1252,
            }
        }
        #[cfg(not(all(windows, any(feature = "iracing", feature = "ac-evo", feature = "lmu"))))]
        {
            encoding_rs::WINDOWS_1252
        }
    })
}

@mvoof mvoof merged commit eca8eb8 into main Jun 27, 2026
1 check passed
@mvoof mvoof deleted the fix/cyrillic-encoding branch June 27, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant