Skip to content

108 worked example the radar grid

Alex Diakovsky edited this page Nov 21, 2026 · 7 revisions

108. Worked example: the radar's grid overlay

Update (document 176): the enemy-direction sector is computed in the vehicle's own tick (FUN_0040b980's tail) from the vehicle itself (obj+0x40) toward the other player's vehicle, not from the base: vehicle+0x5c is the per-player record where the sector is stored (+0x80, every 0x3c ticks). The dead zone is FUN_0041d5b0(enemy, vehicle, record + 0x2ac) and the sector ((FUN_00422e70(vehicle, enemy) + 0x40000) & 0x380000) >> 19, 0 = north.

Question: continuing issue #17 after document 107's ping: document 68 already spotted cel 1963 ("a white grid on transparent") and cel 1964 ("four corner brackets with edge arrowheads") sitting in FUN_004122d0's draw callback, but never pinned down exactly where or when either one draws. Scripts and field names are in the tracing cheat sheet.

Step 1: two cels, two very different amounts of tracing needed

The callback's own config struct (the "a" parameter, record + 0x270) carries a field at +0x18 — not one of the panel factory's three stored parameters (+8/+0xc/+0x10, which are the tracked object's pointer, the map bitmap's cel and the config struct's own address respectively), but a value inside the config struct itself. Near the very end of the callback (DecompileMany.java 0x4122d0 0x412790, re-read for this document):

iVar5 = *(int *)(iVar1 + 0x18);
if (iVar5 < 0) {
    iVar5 = FUN_00413c90((uint *)(iVar5 * -0x44 + DAT_0044964c));   // a different cel when negative -- not read further
    ...
    iVar5 = -*(int *)(iVar1 + 0x18);
} else if (iVar5 < 1) goto LAB_0041267b;
*(int *)(iVar1 + 0x24) = iVar5 + 1;          // the CURSOR's cel number, derived as the grid's + 1 -- 1963 + 1 = 1964
LAB_0041267b:
if ((*(int *)(iVar1 + 0x24) != 0) && (iVar4 = *(int *)(iVar4 + 0x5c), iVar4 != 0) && (-1 < *(short *)(iVar4 + 0x80))) {
    puVar8 = FUN_00413c90((uint *)(*(int *)(iVar1 + 0x24) * 0x44 + DAT_0044964c));   // draws cel 1964 here
    ...
    if (*(short *)(iVar4 + 0x80) < 8) {
        pbVar10 = (byte *)(*(short *)(iVar4 + 0x80) * 4 + *(int *)(iVar1 + 0x28));    // an 8-entry rectangle table, cropping cel 1964
        FUN_0041d350(puVar8, 0, *pbVar10, pbVar10[1], pbVar10[2] - *pbVar10 + 1, pbVar10[3] - pbVar10[1] + 1);
        ...
    }
}
if (0 < *(int *)(iVar1 + 0x18)) {
    iVar4 = FUN_00413c90((uint *)(*(int *)(iVar1 + 0x18) * 0x44 + DAT_0044964c));   // draws cel 1963 here, unconditionally
    *(int *)(iVar4 + 0x10) = *(int *)(param_1 + 8) + *(int *)(iVar1 + 4) + 0x8000;
    *(int *)(iVar4 + 0x14) = *(int *)(param_1 + 0x104) + *(int *)(iVar1 + 8) + 0x8000;
    *(undefined4 *)(iVar4 + 0x34) = 0xb;
}

The grid (iVar1+0x18, cel 1963) needs nothing but its own field. The last four lines run whenever that field is positive — true for every ordinary vehicle's radar record — and draw the cel at the window's own position with no other condition: no state, no timer, no object to check. It is drawn last, after the map bitmap, the flag's blip and the ping, so it sits on top of all three.

The cursor (cel 1964, iVar1+0x24, always the grid's cel number + 1) needs a real trace of its own. It only draws when *(int *)(tracked_vehicle + 0x5c) is a non-null pointer whose own +0x80 (a 16-bit value) is 0 to 7. Document 68 called +0x5c "child (the player's marker)" when it first read this line — a guess, not a confirmed field: +0x5c is heavily reused (document 65: a flag's own +0x5c is its wave-animation frame counter; document 64: a Tank's own +0x5c is the turret's aim target, zeroed to recentre it) and this document did not itself confirm what a vehicle's +0x5c holds when the radar callback reads it. FUN_00412170, kind 6's own init, sets the pointed-to structure's +0x80 to 0xffff at creation (off, by default) but does not create the structure itself. Nothing this pass read creates it or ever writes 0-7 into its +0x80; the 8-entry rectangle table at iVar1 + 0x28 (four bytes each, x0, y0, x1, y1 — a sub-rectangle crop of cel 1964) is real and readable, but neither what fills +0x5c nor what the eight states mean is answered here. Not built. Left for whoever traces it next, alongside document 107's still-open ping growth curve.

Step 2: what cel 1963 actually is

Cel 1963 is one of document 9's PRE0 == 3 masks — the same family the port already has to approximate for the hangar spotlight (there a PRE0 == 5 "brighten" mask): a per-pixel background-recolour blend, where the mask's own byte value selects which row of the shared 256 x 256 tint table to blend the pixel underneath toward — not a plain sprite with its own colours. This pack has no real per-pixel blend built yet, so it gets the same additive-white stand-in the spotlight uses. Checking the raw mask bytes this time found a real difference from that case: cel 1963's dominant nonzero value is 192 (out of 255, on about a quarter of its 32 x 32 pixels — a grid of lines), not the spotlight's 0-24 — no rescale is needed here for the shape to actually show.

Applied in the port

tools/extract_radar.py now writes "grid": {"cel": 1963} into radar.json; build_pack.py resolves it to a sprite id the same way "ping" already is. game/radar_view.gd adds a second overlay TextureRect, built and added after the ping's (so it draws on top, matching the callback's own order), with the same additive CanvasItemMaterial the hangar spotlight uses, shown unconditionally:

if _rd.has("grid"):   # added AFTER _ping: FUN_004122d0 draws the grid last, over the ping too
	_grid = TextureRect.new()
	...
	var mat := CanvasItemMaterial.new()
	mat.blend_mode = CanvasItemMaterial.BLEND_MODE_ADD
	_grid.material = mat
	var s := mc.pack.get_sprite(String(_rd["grid"]["sprite_id"]))
	...
	_grid.texture = at
	add_child(_grid)

tools/tests/radar_grid_check.gd (6 checks): the pack carries the grid data; RadarView builds the overlay, sized to the window; its texture is the real 32 x 32 cel; it's visible unconditionally (no trigger, unlike the ping); it's added after the ping so paint order matches the trace. A screenshot of the panel's radar shows a clean cyan grid over the map, matching document 68's original description and the reference footage already gathered in document 103.

Issue #17, what's left: the corner-bracket cursor (this document's Step 1) and the fixed-colour fill drawn behind the map when the tracked vehicle is near the level edge. The "panel frame around the radar" turned out not to be a missing piece at all — the metal bezel is part of the panel's own base cel (document 70), already drawn by HudPanel._base; removed from radar_view.gd's own list of gaps.

Addendum: one step further into the cursor's +0x5c, and the off-map fill's colour

Followed +0x5c one step past where Step 1 left it. The vehicle's own creation function, FUN_0040b700, sets it directly: *(int *)(new_object + 0x5c) = param_3[2] — the third of its own three arguments, not anything derived from a class or state table. That function is only ever reached indirectly (FindPointerRefsMulti.java 40b700 finds one reference, a data slot at 0x445440 — a class-dispatch table entry, not a call site FindCallRel.java can follow), so the caller that fills param_3[2] for a vehicle specifically would need tracing through that dispatcher next — a bigger step than this pass had time for. Still open, but the exact next question to ask is now precise: what does the generic "spawn object of class N" dispatcher at 0x445440's table pass as its third argument when N is a vehicle class.

The off-map background fill (FUN_004121b0, drawn behind the map bitmap whenever the tracked vehicle's radar window would run past the level's edge) traces to a real colour, just not one this project's tools can read: its PLUT override, &DAT_0046aa04, sits in memory the game only allocates and fills at runtime (FUN_00424950, the art loader, builds several such scratch buffers alongside the loaded file data) — there's no byte for it sitting in the static RFIRE.BIN a disassembler can show. The port fills black there instead, a port choice now recorded as one rather than an accidental gap.

Second addendum: the grid was never one shared cel — a real bug, fixed

Re-reading the config struct's +0x18 (the grid's own cel number) directly from all four vehicle records, not just the Tank's, found the first addendum's own fix was itself wrong in a new way: it used the Tank's cel (1963, 32 x 32) for every type. The real data:

type +0x18 cel size window (document 70) kind
Tank 1963 32x32 32x32 effect.tint.colour.006, document 9's tint-mask family
MSV 1973 39x34 39x34 — matches the MSV's own larger radar exactly effect.tint.colour.008, same family
Heli -1975 (negative) 40x38 close to its 32x32 window, not exact marker.hollow_square.33 — PRE0 == 0, an ordinary sprite, not a tint mask at all
Jeep 0 — — no kind-6 element (kind 8, the compass, lives at this same record offset instead)

The MSV's cel being exactly its own window's size, while differing from the Tank's, rules out "one shared grid cel" as anything but a wrong guess — confirmed by the cel's own dimensions, not assumed. The Heli's -1975 matches FUN_004122d0's own negative branch (iVar5 * -0x44 + celtable, a different draw path with a toggling tint, 0xe/0xf) that the first read of this function noted but didn't follow up on; that cel turning out to be a plain sprite (not a background-recolour blend) means it needs no additive-white approximation at all — a real ordinary draw, once the port stops trying to force it through the tint-mask code path.

Fixed: tools/extract_hud_panels.py now reads each type's own grid_cel live via rfexe, and RadarView.set_grid() is called per vehicle-type change (HudPanel._layout), the same way the panel's other per-type elements already work, instead of build_pack.py resolving one shared cel out of radar.json. A screenshot of the MSV's panel now shows the grid covering its radar edge to edge, where it previously only covered a 32 x 32 patch inside the larger window, leaving an ungridded strip.

The lesson, again: the first addendum already found the direction of a fix can't be assumed from a similar-looking earlier one (document 44's shadow bias). This is the same lesson from the opposite side — the underlying data, not just the arithmetic sign, needs checking per instance too. A single passing test built from one vehicle's numbers proved nothing about the other three.

Third addendum: the cursor's +0x5c, actually resolved this time

Followed the second addendum's own lead — "what does the dispatcher pass as FUN_0040b700's third argument for a vehicle" — properly. It turned out FUN_0040b700 isn't reached through the class-dispatch table at all for a player's own vehicle: the confirm button's own handler, FUN_0040b510 (document 76), builds an 8-dword argument block on its own stack and calls FUN_0042c290(0x44db40, player, targetX, targetY, -0x200000, &args) — a generic spawn-object-of-this-class function that itself calls FUN_0040b700 with a pointer into that same stack block as param_3. The block's third dword (param_3[2], the value that lands in object + 0x5c) is &DAT_0048c880 + player * 0xd0 — a pointer straight to the player's own per-player base record, the same block issue #17's earlier docs already knew held vehicle stock counts. Document 68's "child (the player's marker)" label turns out to have been groping toward something real, just not quite named right: it isn't a child object at all, it's a pointer back to the player's own base.

That base record's +0x80 (the field the radar reads) is written by a small, self-contained routine inside the vehicle's own per-tick update, force-disassembled since Ghidra had not marked it as code (DisasmForce.java 0x40c0b0 0x40c130):

if (/* a gating test, see below */) { *(short *)(base + 0x80) = 0xffff; }             // off
else if (FUN_0041d5b0(enemyPos, basePos, someRecordRect) != 0) { *(short *)(base + 0x80) = 8; }   // "no clear direction"
else {
    bearing = FUN_00422e70(basePos, enemyPos);          // the SAME bearing function document 71's Jeep compass uses
    sector = (bearing + 0x40000) & 0x380000 >> 0x13;     // round to the nearest of 8 compass sectors (0x400000 / 8 = 0x80000 each)
    if (sector > 7) sector = 7;
    *(short *)(base + 0x80) = sector;
}

FUN_0041d5b0(a, b, rect) is a plain axis-aligned box test: does a - b fall inside rect's {minX, minY, maxX, maxY}. Put together with document 71's own already-traced bearing math, this reads as an 8-way compass telling the player roughly which direction the enemy's current vehicle is from their own base — corner-bracket cel 1964, cropped to one of 8 rectangles by this same sector value, exactly the "cursor" document 68 first spotted.

What still keeps this from being built: the gating condition before the FUN_0041d5b0 call (a per-vehicle-record flag around +0x298) and the exact rectangle FUN_0041d5b0 tests against (a constant at what looks like record + 0x2ac, close enough to other already-traced per-type record fields — document 98's music theme at +0x2bc — that it is very plausibly a real per-type record field too, but not read closely enough to be sure whose position it is relative to, or whether every vehicle type even has this feature at all) were not pinned down with the same confidence as the bearing math itself. Attempting the crop-rectangle table and per-type position (+0x1c/+0x20 of the same config struct) also ran into a second config struct at the identical record + 0x270 offset being used for a different element kind (9, the Heli's weapon-select icons) in code this pass read while chasing this — meaning the struct's own field layout past +0x18 cannot be trusted yet without sorting out that overlap first, the same category of mistake the second addendum just corrected. Given that, and this document already containing one shipped-then-reverted-then-refixed mistake, the direction indicator itself stays unbuilt rather than risk a third wrong attempt in one document. The trigger and the bearing math are traced with real confidence; the exact gate and the crop table are not, and are flagged as such rather than guessed past.

Fourth addendum: the "kind 9 overlap" was a misread, not a conflict — the cursor is built

The third addendum's own blocker turned out to be a mistake of the same shape as the second addendum's, just one level up: a misread of argument order, not a real structural conflict. FUN_00412cd0(panel, slot, kind, a, b, c) creates every panel element — the already-traced fuel bar (document 68) calls it with slot = 5, kind = 5; the radar's own creation call is slot = 9 (a literal, always 9), kind = *(record + 0x270) (data-driven: 6 for Tank/MSV/Heli, 8 for the Jeep's compass). The Heli's weapon-select icons (document 83, kind 9) are a different slot (8) with a literal kind of 9 — nothing shares record + 0x270 with the radar's config struct at all. Re-deriving this precisely (re-reading the creation call directly, not trusting the earlier skim) found no overlap: the config struct's fields past +0x18 are exactly where document 70 already said they were, and the crop-rectangle table and per-type position are both real, live data.

+0x270 + 0x24 (the cursor's own cel, already known from Step 1 to be the grid's cel + 1) and +0x270 + 0x28 — a pointer, not the table itself — to the live 8-entry {x0, y0, x1, y1} byte rectangle table, read directly off the four vehicle records:

// FUN_004122d0's crop, re-read directly (Step 1's own `pbVar10` line):
pbVar10 = (byte *)(*(short *)(iVar4 + 0x80) * 4 + *(int *)(iVar1 + 0x28));   // iVar1+0x28 IS the pointer, not inline data
FUN_0041d350(puVar8, 0, *pbVar10, pbVar10[1], pbVar10[2] - *pbVar10 + 1, pbVar10[3] - pbVar10[1] + 1);

Reading that pointer's own 8 entries for each of the Tank, MSV and Heli confirms a real baked-in "compass rose" cut into cel 1964 (and its own +1 cels, 1974 and 1976): eight small crops arranged clockwise around the cel's edge, one per sector. record + 0x298 (the same table's pointer, read directly off the full record rather than through the config struct) is nonzero for Tank/MSV/Heli and zero for the Jeep — confirming the third addendum's guess that this is how the feature disables itself for the one type with no radar at all, without needing a separate kind check. record + 0x2ac (four direct 16.16 dwords, not a pointer) is the dead-zone rectangle FUN_0041d5b0 tests the enemy's position against, relative to the base position — inside it, the sector is forced to 8 (draw the whole cel, uncropped) rather than an unstable bearing at point-blank range.

Applied in the port

tools/extract_hud_panels.py reads all four fields (grid_cel, the rectangle table via its pointer, the cursor's own position, and the dead zone) live off RECORD for Tank/MSV/Heli (the Jeep is excluded — it has no kind-6 radar at all):

_base = _rec + 0x270
_grid_cel = rfexe.dword(_base + 0x18, signed=True)
panels[_id]["slot9"]["grid_cel"] = _grid_cel
_rect_ptr = rfexe.dword(_rec + 0x298)
panels[_id]["slot9"]["cursor"] = {
    "cel": abs(_grid_cel) + 1,
    "pos": [rfexe.dword(_base + 0x1c) / 65536.0, rfexe.dword(_base + 0x20) / 65536.0],
    "rects": [[rfexe.byte(_rect_ptr + i * 4), rfexe.byte(_rect_ptr + i * 4 + 1),
               rfexe.byte(_rect_ptr + i * 4 + 2) - rfexe.byte(_rect_ptr + i * 4) + 1,
               rfexe.byte(_rect_ptr + i * 4 + 3) - rfexe.byte(_rect_ptr + i * 4 + 1) + 1] for i in range(8)],
    "dead_zone": [rfexe.dword(_rec + 0x2ac + i * 4, signed=True) / 65536.0 for i in range(4)],
}

MatchController ports the bearing/dead-zone/sector logic (FUN_004122d0's tail, reusing document 71's FUN_00422e70 the same way the Jeep's compass already does) as radar_direction_sector(), recomputed every 60 ticks like the original:

func _compute_direction_sector() -> int:
	var nearest: Vehicle = null
	var nearest_d2 := INF
	for e in enemy_vehicles:
		var ev: Vehicle = e
		if ev != null and is_instance_valid(ev) and ev.alive:
			var d2: float = ev.position.distance_squared_to(vehicle.position)
			if d2 < nearest_d2:
				nearest_d2 = d2
				nearest = ev
	if nearest == null:
		return -1
	var s9: Dictionary = pack.hud_panels.get("panels", {}).get(str(vehicle.vehicle_type), {}).get("slot9", {})
	var cursor: Dictionary = s9.get("cursor", {})
	if cursor.is_empty():
		return -1
	var dz: Array = cursor["dead_zone"]
	var delta := nearest.position - _player_spawn_px
	if delta.x >= dz[0] and delta.y >= dz[1] and delta.x <= dz[2] and delta.y <= dz[3]:
		return 8
	var to := nearest.position - _player_spawn_px
	var steps := floori(fposmod(rad_to_deg(to.angle()), 360.0) / 5.625)
	var bearing := (steps * 0x10000) & 0x3FFFFF
	return mini(((bearing + 0x40000) & 0x380000) >> 0x13, 7)

Two port choices, not traced: which enemy (the original is a strict 1v1 game with exactly one "other team" vehicle and no such ambiguity; this port's single-player-vs-several-AI setup uses the nearest live one instead), and "the player's own base" position, which reuses _player_spawn_px — the same untraced stand-in the Jeep's compass already leans on for its own "home" (document 71). The base record's own position fields (vehicle + 0x5c's own +0x40/+0x44) were read this pass but not connected to anything independently verifiable, so they aren't relied on here either.

RadarView.set_cursor()/_update_cursor() show or hide a third overlay (added after the ping, before the grid — matching the callback's own draw order from Step 1) and crop it to the sector's own rectangle, or show it uncropped at sector 8. tools/tests/radar_direction_check.gd (11 checks) covers: no live enemy → -1; the only enemy dead → -1; sitting inside the dead zone → 8; all four cardinal sectors (0, 2, 4, 6) against known bearings; the nearer of two live enemies wins over the farther one even when the farther one's bearing differs; and the Jeep's own panel carrying no cursor data at all. Visual rendering was not screenshotted this pass — this project's Godot instances run --headless for tracing and testing, and no windowed capture tool was available in this session — so the crop/atlas rendering itself rests on the automated checks and code review rather than a picture, unlike the ping and grid's own screenshots above.

Correction (2026-10-15). The cursor's position from extract_hud_panels.py (slot9.cursor.pos) is in the panel's coordinates, the same as the radar window's own slot9.pos: for the Tank and the MSV they are equal, and the Heli's is 3 px left and 2 px up of its window. But RadarView draws the cursor as a child of the window, so the window's offset was added a second time. The Tank's cursor overhung the radar's right edge by 19 px, and the MSV's (window at (89, 9)) was drawn off the panel altogether, over the game view to its right. It was first noticed in a game against the computer player (issue #77): the cursor only shows while an enemy vehicle is in play. RadarView.set_cursor(cursor_data, window_pos) now places it at pos - window_pos, so it sits on the window as the record says (openfire-engine 1a69640).

Issue #17 is now fully built. The one remaining open item is the off-map fill colour (this document's first addendum), which is a permanent port choice rather than a blocker: the real value lives only in runtime-allocated memory RFIRE.BIN's static bytes never show.

Clone this wiki locally