summaryrefslogtreecommitdiff
path: root/includes/bitset.php
blob: 6483669afd58abece24e98705dd9962b6db92c76 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php

function parseBitset ($bitset) {
    $bin = str_repeat("0", 48 - strlen(decbin($bitset))) . decbin($bitset);

    $sharedMemory = bindec(substr($bin, 8 + 16, 2));
    $median = substr($bin, 10 + 16, 1) !== "0";
    $little = bindec(substr($bin, 11 + 16, 2));
    $food = bindec(substr($bin, 16, 2));
    $magic = bindec(substr($bin, 2 + 16, 3));
    $sensitivity = bindec(substr($bin, 5 + 16, 3));
    $protector = substr($bin, 13 + 16, 1) !== "0";
    $fictive = substr($bin, 14 + 16, 1) !== "0";
    $notTalking = substr($bin, 15 + 16, 1) !== "0";
    $host = substr($bin, 16 + 16, 1) !== "0";
    $robot = substr($bin, 29 + 16, 1) !== "0";
    $plush = substr($bin, 30 + 16, 1) !== "0";
    $age = substr($bin, 31 + 16, 1) !== "0";
    $species1 = substr($bin, 17 + 16, 4);
    $species2 = substr($bin, 21 + 16, 4);
    $species3 = substr($bin, 25 + 16, 4);

    $species1 = match ($species1) {
        "0001" => "earth",
        "0010" => "unicorn",
        "0011" => "pegasus",
        "0100" => "alicorn",
        "0101" => "batpony",
        "0110" => "crystal",
        default => null,
    };

    $species2 = match ($species2) {
        "0001" => "earth",
        "0010" => "unicorn",
        "0011" => "pegasus",
        "0100" => "alicorn",
        "0101" => "batpony",
        "0110" => "crystal",
        default => null,
    };

    $species3 = match ($species3) {
        "0001" => "earth",
        "0010" => "unicorn",
        "0011" => "pegasus",
        "0100" => "alicorn",
        "0101" => "batpony",
        "0110" => "crystal",
        default => null,
    };

    return [
        'shared_memory' => $sharedMemory,
        'median' => $median,
        'protector' => $protector,
        'fictive' => $fictive,
        'little' => $little,
        'not_talking' => $notTalking,
        'host' => $host,
        'robot' => $robot,
        'magic' => $magic,
        'sensitivity' => $sensitivity,
        'food' => $food,
        'plush' => $plush,
        'age_spells' => $age,
        'species' => array_filter([
            $species1,
            $species2,
            $species3
        ], function ($i) {
            return isset($i);
        })
    ];
}

function parseMetadata ($metadata) {
    if (isset($metadata)) {
        if ($metadata["bitset"]) {
            $m = parseBitset($metadata["bitset"]);
            $m["marefriends"] = $metadata["marefriends"] ?? [];
            $m["bitset"] = $metadata["bitset"] ?? [];
            $m["sisters"] = $metadata["sisters"] ?? [];
            $m["regression"] = $metadata["regression"] ?? null;
            $m["caretakers"] = $metadata["caretakers"] ?? [];
            $m["median"] = $metadata["median"] ?? null;
        } else {
            $m = $metadata;
        }

        return $m;
    } else {
        return $metadata;
    }
}