Try my new app to fix input lag (cs2_timer_fix_by_yam1ke)

Everything about latency. This section is mainly user/consumer discussion. (Peer-reviewed scientific discussion should go in Laboratory section). Tips, mouse lag, display lag, game engine lag, network lag, whole input lag chain, VSYNC OFF vs VSYNC ON, and more! Input Lag Articles on Blur Busters.
urikawa
Posts: 15
Joined: 13 Mar 2024, 14:21

Re: Try my new app to fix input lag (cs2_timer_fix_by_yam1ke)

Post by urikawa » 19 Dec 2025, 08:46

yam1ke wrote:
19 Dec 2025, 08:32
urikawa wrote:
19 Dec 2025, 08:16
it's you ? https://www.twitch.tv/gr0mjkeee/clip/Co ... ye?lang=it :p

what technique do you use ? corehoping ? its switch the core used to play how does it work ?
No, it's not me. I'm not a YouTuber or streamer.
All I can say, thay I burn CPU in systematic way, so CPU and Windows processes start to march to my beat in perfect timing.
Clever run like the way i run :)

yam1ke
Posts: 21
Joined: 03 Dec 2025, 19:29

Re: Try my new app to fix input lag (cs2_timer_fix_by_yam1ke)

Post by yam1ke » 19 Dec 2025, 08:52

urikawa wrote:
19 Dec 2025, 08:46
Clever run like the way i run :)
I a little bit extended my answer)

urikawa
Posts: 15
Joined: 13 Mar 2024, 14:21

Re: Try my new app to fix input lag (cs2_timer_fix_by_yam1ke)

Post by urikawa » 19 Dec 2025, 09:37

urikawa wrote:
19 Dec 2025, 08:16
it's you ? https://www.twitch.tv/gr0mjkeee/clip/Co ... ye?lang=it :p

what technique do you use ? corehoping ? its switch the core used to play how does it work ?

in rust what i have cooked instead of c++
THIS CODE is PROVIDED AS IS you it at your own risk !!

for my ryzen 9800x3d a little tuned
cargo.toml

Code: Select all

[package]
name = "cs2_optimizer_x3d"
version = "0.6.0"
edition = "2021"

[dependencies]
rand = "0.8"
windows-sys = { version = "0.48", features = [
    "Win32_Foundation",
    "Win32_System_Threading",
    "Win32_Media",
    "Win32_UI_Input_KeyboardAndMouse",
    "Win32_System_SystemInformation",
    "Win32_System_Performance"
] }
main.rs

the rust main.rs

Code: Select all

use std::thread;
use std::time::Duration;
use std::io::{self, Write};
use std::ffi::CString;

// --- IMPORTS X3D OPTIMIZED (INTRINSICS) ---
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::{
    _mm_mfence, _mm_pause, _rdtsc, 
    _mm_prefetch, _MM_HINT_T0, // Pour gérer le cache manuellement
    _mm_setzero_ps, // Instructions froides (peu de chaleur)
};

// --- IMPORTS WINDOWS ---
use windows_sys::Win32::UI::Input::KeyboardAndMouse::*;
use windows_sys::Win32::System::Threading::*;
use windows_sys::Win32::System::Performance::{QueryPerformanceCounter, QueryPerformanceFrequency};
use windows_sys::Win32::Media::timeBeginPeriod;

#[link(name = "ntdll")]
extern "system" {
    fn NtSetTimerResolution(Desired: u32, Set: u8, Current: *mut u32) -> i32;
    fn NtDelayExecution(Alertable: u8, DelayInterval: *const i64) -> i32;
}

#[link(name = "avrt")]
extern "system" {
    fn AvSetMmThreadCharacteristicsA(TaskName: *const u8, TaskIndex: *mut u32) -> isize;
    fn AvRevertMmThreadCharacteristics(Handle: isize) -> bool;
}

// --- CONFIGURATION X3D ---
const X3D_THERMAL_PROTECT: bool = true; // Réduit la charge si inutile
const CACHE_LINE_SIZE: usize = 64;

// --- ÉTAT GLOBAL ---
static mut STATE_HZ: u32 = 5000;
static mut STATE_MMCSS: bool = false;
static mut STATE_MMCSS_HANDLE: isize = 0;
static mut STATE_SCRAMBLE: bool = false;
static mut STATE_CORE: usize = 2; // On commence à 2 (souvent meilleur coeur sur Ryzen)
static mut STATE_FENCE: bool = true;
static mut STATE_X3D_MODE: bool = true; // Activé par défaut pour vous

// --- TIMER PRECISION ---
fn get_time_us() -> u64 {
    unsafe {
        let mut freq = 0;
        let mut count = 0;
        QueryPerformanceFrequency(&mut freq);
        QueryPerformanceCounter(&mut count);
        (count as u128 * 1_000_000 / freq as u128) as u64
    }
}

// --- MOTEUR DE CHARGE "CACHE AWARE" ---
// Conçu pour ne PAS évincer CS2 du V-Cache (L3)
unsafe fn run_x3d_load(iterations: u64) {
    // Mode L1/L2 Resident : On touche un tout petit buffer qui tient dans le L1
    // Cela garde le coeur actif SANS toucher au L3 (V-Cache)
    const L1_SIZE: usize = 32 * 1024; // 32KB
    static mut L1_BUFFER: [u8; L1_SIZE] = [0; L1_SIZE];
    
    // Instructions SSE légères (Low Power) pour ne pas chauffer
    let a = _mm_setzero_ps(); 
    
    for i in 0..iterations {
        // 1. Calcul Froid (Zero latency dependency)
        // Empêche le core parking sans générer de chaleur (pas de calcul lourd)
        std::hint::black_box(a);

        // 2. Prefetch L1 (Garde le core chaud)
        // On touche le buffer par sauts de 64 bytes (Cache Line)
        let idx = (i as usize * CACHE_LINE_SIZE) % L1_SIZE;
        let ptr = L1_BUFFER.as_ptr().add(idx) as *const i8;
        
        // _MM_HINT_T0 = Prefetch dans L1 cache seulement
        _mm_prefetch(ptr, _MM_HINT_T0); 
    }
}

// --- MOTEUR D'ATTENTE "COOL LOOP" ---
// Remplace le SpinLock pur par un hybride plus froid
unsafe fn cool_wait_us(target_us: u64) {
    let start = get_time_us();
    
    // Si on a beaucoup de temps, on utilise MWAIT/Sleep (0% CPU usage)
    // Sur X3D, cela permet aux autres coeurs de monter en fréquence (Thermal Headroom)
    if target_us > 1500 {
        let sleep_val = -((target_us - 500) * 10) as i64; // Convert to 100ns
        NtDelayExecution(0, &sleep_val);
    }

    // Finition précise (Spinning léger)
    // _mm_pause() est crucial sur Ryzen pour économiser l'énergie en boucle
    while get_time_us() - start < target_us {
        _mm_pause(); 
        _mm_pause(); // Double pause sur Ryzen = mieux géré
    }
}

// --- GESTION ENTRÉES ---
fn check_inputs() {
    unsafe {
        let kp = |vk| (GetAsyncKeyState(vk) & 1) != 0;
        
        // [X] X3D MODE TOGGLE
        if kp(0x58) { STATE_X3D_MODE = !STATE_X3D_MODE; }
        
        if kp(VK_F1 as i32) { STATE_HZ = if STATE_HZ == 5000 { 10000 } else { 5000 }; }
        if kp(VK_HOME as i32) { STATE_SCRAMBLE = !STATE_SCRAMBLE; }
        if kp(VK_END as i32) { STATE_FENCE = !STATE_FENCE; }
        
        if kp(VK_M as i32) {
            if !STATE_MMCSS {
                let name = CString::new("Pro Audio").unwrap();
                let mut i = 0;
                let h = AvSetMmThreadCharacteristicsA(name.as_ptr() as *const u8, &mut i);
                if h != 0 { STATE_MMCSS_HANDLE = h; STATE_MMCSS = true; }
            } else {
                AvRevertMmThreadCharacteristics(STATE_MMCSS_HANDLE);
                STATE_MMCSS = false;
            }
        }
    }
}

// --- MAIN LOOP ---
fn main() {
    unsafe {
        timeBeginPeriod(1);
        // Sur X3D, HIGH_PRIORITY est souvent mieux que REALTIME pour éviter de bloquer les drivers GPU
        SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); 
        SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
    }

    println!("=====================================================");
    println!("      CS2 OPTIMIZER: V6 X3D VELOCITY EDITION         ");
    println!("=====================================================");
    println!(" [X] X3D MODE  : L3 Cache Protection + Cool Loop");
    println!(" [M] MMCSS     : Pro Audio Priority");
    println!(" [HOME] SCRMBL : CCD/Core Hopping");
    println!("=====================================================");

    let mut last_scramble = get_time_us();
    let mut frame_count = 0u64;

    loop {
        unsafe {
            let start_loop = get_time_us();
            
            // 1. TIMER HARDWARE
            let mut cur: u32 = 0;
            NtSetTimerResolution(STATE_HZ, 1, &mut cur);

            // 2. SCRAMBLE INTELLIGENT (Ryzen Topology)
            // Sur 7950X3D, CCD0 = Coeurs 0-15 (Logiques). V-Cache est ici.
            // On veut rester sur les cœurs physiques pairs: 0, 2, 4, 6, 8...
            if STATE_SCRAMBLE && (start_loop - last_scramble > 2_000_000) {
                let x3d_cores = [0, 2, 4, 6]; // Cibles primaires CCD0
                let idx = (frame_count as usize) % x3d_cores.len();
                STATE_CORE = x3d_cores[idx];
                
                SetProcessAffinityMask(GetCurrentProcess(), 1 << STATE_CORE);
                last_scramble = start_loop;
            } else if !STATE_SCRAMBLE {
                // Par défaut, Core 2 est souvent le meilleur sur Ryzen (Core 0 gère l'OS)
                SetProcessAffinityMask(GetCurrentProcess(), 1 << 2);
            }

            // 3. X3D LOAD (L3 Guard)
            // On exécute la charge seulement si nécessaire pour garder le core actif
            // Mais avec une intensité plus faible pour ne pas chauffer
            if STATE_X3D_MODE {
                run_x3d_load(200); // 200 itérations = très léger, juste pour le L1
            }

            // 4. MEMORY FENCE
            // Sur Ryzen, MFENCE est coûteux. On réduit la fréquence.
            if STATE_FENCE && (frame_count % 10 == 0) {
                 _mm_mfence();
            }

            // 5. COOL WAIT
            // On vise 1ms (1000us) ou 0.5ms (500us) de cycle
            let target_cycle = if STATE_HZ == 5000 { 500 } else { 1000 };
            let elapsed = get_time_us() - start_loop;
            
            if elapsed < target_cycle {
                cool_wait_us(target_cycle - elapsed);
            }

            // 6. DASHBOARD
            if frame_count % 200 == 0 {
                print!("\r [X3D] CORE:{:<2} | MODE:{:<7} | MMC:{} | FNC:{} | TMR:{:.1}ms | 3D-L3:PROTECTED ",
                    STATE_CORE,
                    if STATE_X3D_MODE { "COOL" } else { "RAW" },
                    if STATE_MMCSS { "ON" } else { "--" },
                    if STATE_FENCE { "ON" } else { "--" },
                    STATE_HZ as f32 / 10000.0
                );
                io::stdout().flush().unwrap();
            }
        }

        check_inputs();
        frame_count = frame_count.wrapping_add(1);
    }
}

Lev1n
Posts: 91
Joined: 17 Apr 2023, 05:40

Re: Try my new app to fix input lag (cs2_timer_fix_by_yam1ke)

Post by Lev1n » 19 Dec 2025, 13:00

MK92 wrote:
19 Dec 2025, 08:41
Lev1n wrote:
19 Dec 2025, 08:13
MK92 wrote:
19 Dec 2025, 07:04
Then why are those "fixes" not working for 95% of people, while for the remaining 5% its just placebo :lol:

EVERYTHING is hardware / outside interference related, NOTHING is related to some fucking obscure windows settings, or how many times will you people mess around with those bcedit userplatformclock bullshit, before realising that this doesn't do ANYTHING as those commands are only relevant for Windows 7 and earlier ??
Basically you are saying you are delusional the fix is placebo. Finally i can enjoy the game after 200 windows installs used every tweaks out there. I didnt change anything on my pc(9800x3d,4080 super,6kcl30 rams) only used this config and its night and day difference. If you think something suddenly got fixed in my house you are the delusional one. Just leave us alone let us be happy while we fixed our issues.
Cool, so after nearly 3 years and 100 posts, you can now delete your account because there is nothing for you here anymore since you found your "fix"...se you in 2-3 days when this magical "fix" won't work anymore...time to change something else in cmd, or bios, or regedit, or download more suspicious files - but keep ignoring the actual culprit, which is network routing or/and electricity.

You do realise that if this would be a Windows problem, then 100 million people would have those problems and not just a few of us, right?
Do you own this forum? So you are the guy who decide stay and who leave.

yam1ke
Posts: 21
Joined: 03 Dec 2025, 19:29

Re: Try my new app to fix input lag (cs2_timer_fix_by_yam1ke)

Post by yam1ke » 22 Dec 2025, 14:11

Update: Added FAQ and settings description to the Telegram group.

One of our members scanned the app for viruses. You can view the report here: https://www.virustotal.com/gui/file/309 ... b48e017db9

Post Reply