<?phpnamespace App\Alis;// Host-side helpers of the port that have no C function of their own: the decoding parts of// sys_sdl2.c (mouse cursor image, per-line palette list) used by sys.php./** * C sys_dirty_mouse() of sys_sdl2.c: the cursor image of the sprite descriptor at $desmouse. * @return array{rows: list<list<int>>, palette: list<int>, hotx: int, hoty: int}|null */function image_mouse_cursor(int $desmouse): ?array{ $type = xread8($desmouse); $width = read16($desmouse + 2) + 1; $height = read16($desmouse + 4) + 1; if ($width <= 0 || $height <= 0 || $width > 128 || $height > 128) { return null; } $palette = Img::$mpalet; $paloff = 0; $colors = []; // global palette index => local index $local = []; $rows = []; $px = function (int $index) use (&$colors, &$local, $palette): int { $index &= 0xff; if (!isset($colors[$index])) { $colors[$index] = count($local); $local[] = $palette[$index] ?? 0; } return $colors[$index]; }; switch ($type) { case 0x00: case 0x02: if (Img::$flinepal) { $list = image_line_palettes(); for ($i = 0; $i < 3 && $i < count($list); $i++) { $paloff = $list[$i][1]; } } $clear = $type === 0 ? 0 : 0xff; $at = $desmouse + 6; $half = intdiv($width, 2); for ($h = 0; $h < $height; $h++) { $row = []; for ($w = 0; $w < $width; $w++) { $c = xread8($at + intdiv($w, 2) + $h * $half); $c = $w % 2 === 0 ? ($c >> 4) & 0x0f : $c & 0x0f; $row[] = $c === $clear ? -1 : $px($c + $paloff); } $rows[] = $row; } break; case 0x10: case 0x12: $palidx = xread8($desmouse + 6); $clear = $type === 0x10 ? xread8($desmouse + 7) : 0xff; $at = $desmouse + 8; $half = intdiv($width, 2); // the C loops h < width, w < height (square cursors in practice) for ($h = 0; $h < $width; $h++) { $row = []; for ($w = 0; $w < $height; $w++) { $c = xread8($at + intdiv($w, 2) + $h * $half); $c = $w % 2 === 0 ? ($c >> 4) & 0x0f : $c & 0x0f; $row[] = $c === $clear ? -1 : $px($palidx + $c); } $rows[] = $row; } break; case 0x14: case 0x16: $clear = 0; if (Alis::$platform->uid == C::EGameIshar_2) { $clear = $type === 0x14 ? xread8($desmouse + 7) : 0x100; } $at = $desmouse + 8; for ($h = 0; $h < $height; $h++) { $row = []; for ($w = 0; $w < $width; $w++) { $c = xread8($at + $h * $width + $w); $row[] = $c === $clear ? -1 : $px($c); } $rows[] = $row; } break; default: return null; } return ['rows' => $rows, 'palette' => $local, 'hotx' => 0, 'hoty' => 0];}