aboutsummaryrefslogtreecommitdiffstats
path: root/steamvr/driver_vrlink/ack-window.c
blob: acd668d701b783ebf52aa0c67f698084d6bfcd25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-FileCopyrightText: 2026 Tomasz Kramkowski <tomasz@kramkow.ski>
// SPDX-License-Identifier: CC0-1.0

#include <layout.h>
#include <stdint.h>
#include <trampoline.h>

struct Transmitter {
	unsigned char unknown_000[0x17c];
	int32_t next_frame; // -1 before the first frame is issued
	int32_t last_ack;
	int32_t cutoff;
};
ASSERT_OFFSET(struct Transmitter, next_frame, 0x17c);
ASSERT_OFFSET(struct Transmitter, last_ack, 0x180);
ASSERT_OFFSET(struct Transmitter, cutoff, 0x184);

void maybe_update_ack(struct Transmitter *tx, uint32_t incoming)
{
	if (tx->next_frame < 0) return;
	uint16_t behind = (uint16_t)(tx->next_frame - 1 - incoming);
	if (behind >= 0x8000) return;

	if (tx->cutoff >= 0 && (uint16_t)(incoming - tx->cutoff) >= 0x8000) return;
	tx->last_ack = incoming;
	tx->cutoff = incoming;
}

// Hooks where the current code checks an incoming ack, clears the cutoff, and
// updates the last ack. The intent is to specifically replace all of that.
TRAMPOLINE(
	accept_ack, CALL(maybe_update_ack, 0, "r8",
			 "mov rdi, rbx\n"
			 "mov esi, eax\n") "jmp resume_ack\n"
);