-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrwfcfc.html
More file actions
382 lines (343 loc) · 18.2 KB
/
rwfcfc.html
File metadata and controls
382 lines (343 loc) · 18.2 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Is This FC Possible?</title>
<style>
:root {
--ok: #0a7f2e;
--no: #b00020;
--warn: #d97706;
--muted: #6b7280;
--bg: #0b1220;
--card: #0f172a;
--accent: #60a5fa;
}
html, body { height: 100%; }
body {
margin: 0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple Color Emoji", "Segoe UI Emoji";
background: radial-gradient(1200px 800px at 50% -10%, #1f2937 0%, #0b1220 60%, #060a12 100%);
color: #e5e7eb; display: grid; place-items: center; padding: 24px;
}
.card {
width: min(860px, 95vw);
background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
border: 1px solid rgba(255,255,255,0.08);
border-radius: 20px; padding: 28px 28px 32px; backdrop-filter: blur(6px);
box-shadow: 0 20px 60px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.06);
}
h1 { font-size: clamp(28px, 5vw, 48px); margin: 4px 0 18px; letter-spacing: 0.3px; }
p.lead { margin: 0 0 16px; color: #cbd5e1; opacity: .9 }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }
input[type="text"] {
width: 100%; font-size: 20px; line-height: 1; padding: 14px 16px; border-radius: 12px;
border: 1px solid rgba(255,255,255,0.18); background: rgba(255,255,255,0.06); color: #e5e7eb;
outline: none; transition: border 160ms ease, box-shadow 160ms ease; letter-spacing: 1px;
}
input[type="text"]::placeholder { color: #94a3b8; }
input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(96,165,250,0.2); }
button {
white-space: nowrap; font-size: 18px; padding: 14px 18px; border-radius: 12px; border: none; cursor: pointer;
background: linear-gradient(180deg, #3b82f6, #2563eb); color: white; font-weight: 600; letter-spacing: .3px;
box-shadow: 0 12px 30px rgba(37,99,235,.35), inset 0 1px 0 rgba(255,255,255,.2);
transition: transform 120ms ease, filter 150ms ease; flex: 0 0 auto;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(1px); }
.big {
font-size: clamp(40px, 8vw, 96px); font-weight: 800; line-height: 1.05; margin: 14px 0 2px;
}
.big.ok { color: var(--ok); text-shadow: 0 6px 22px rgba(10,127,46,.35); }
.big.no { color: var(--no); text-shadow: 0 6px 22px rgba(176,0,32,.35); }
.big.warn { color: var(--warn); text-shadow: 0 6px 22px rgba(217,119,6,.35); }
.sub { font-size: clamp(16px, 2.2vw, 24px); color: #e5e7eb; opacity: 0.92; margin: 8px 0 0; }
.muted { color: var(--muted); font-size: 14px; margin-top: 12px; }
.status {
margin-top: 18px; padding: 14px 16px; border-radius: 12px;
background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.10);
display: flex; align-items: center; gap: 10px; font-size: 16px;
}
.dot { width: 10px; height: 10px; border-radius: 999px; background: var(--muted); flex: 0 0 auto; }
.dot.ok { background: var(--ok); }
.dot.no { background: var(--no); }
.footnote { margin-top: 18px; font-size: 12px; color: #9ca3af; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12px; }
/* Explanation panel */
.explain { margin-top:14px; padding:12px 14px; border-radius:12px; background:rgba(255,255,255,0.05); border:1px solid rgba(255,255,255,0.1); }
.explain .row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.bits { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; font-size: 13px; padding:2px 6px; border-radius:8px; }
.bits.csum { background: rgba(176,0,32,.18); border:1px solid rgba(176,0,32,.35); }
.bits.pid { background: rgba(96,165,250,.15); border:1px solid rgba(96,165,250,.35); }
.tag { display:inline-block; padding:2px 6px; border-radius:8px; border:1px solid rgba(255,255,255,.15); background:rgba(255,255,255,.06); }
.tag.ok { border-color: rgba(10,127,46,.5); background: rgba(10,127,46,.2); }
.tag.no { border-color: rgba(176,0,32,.5); background: rgba(176,0,32,.2); }
/* Friend-code digit visualization */
.fcviz { display:inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; font-size: 20px; letter-spacing: 1px; background: rgba(255,255,255,0.04); padding: 6px 10px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.1); }
.fcviz .bar { height: 6px; border-radius: 4px; overflow: hidden; margin-top: 6px; display:flex; }
.fcviz .seg.csum { background: rgba(176,0,32,.55); width: 17.9487%; } /* 7/39*100 */
.fcviz .seg.pid { background: rgba(96,165,250,.55); flex: 1; }
/* Digit-by-digit highlight */
.fc-line { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; font-size: 22px; letter-spacing: 1px; margin-top: 6px; }
.fc-caption { display:inline-block; min-width: 96px; color: #cbd5e1; }
.dg { display:inline-block; padding: 0 2px; border-radius: 4px; }
.dg.same { opacity: 0.92; }
.dg.diff { background: rgba(176,0,32,.35); outline: 1px solid rgba(176,0,32,.5); }
.dg.fix { background: rgba(10,127,46,.35); outline: 1px solid rgba(10,127,46,.5); }
/* Contiguous 39-bit line (7 checksum + 32 PID) */
.bitsline {
display: inline-flex;
white-space: nowrap;
gap: 0;
line-height: 1;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 13px;
letter-spacing: 0;
}
.bitsline .seg {
display: inline-block;
padding: 2px 0; /* no horizontal padding to keep width = characters */
border: 1px solid rgba(255,255,255,0.15);
}
.bitsline .seg.csum {
background: rgba(176,0,32,.18);
border-color: rgba(176,0,32,.35);
border-right: 0;
border-radius: 8px 0 0 8px;
}
.bitsline .seg.pid {
background: rgba(96,165,250,.15);
border-color: rgba(96,165,250,.35);
border-left: 0;
border-radius: 0 8px 8px 0;
}
</style>
</head>
<body>
<main class="card" role="main">
<h1>Is This FC Possible? <font size=5>v1.1</font></h1>
<p class="lead">Enter a <strong>Mario Kart Wii</strong> friend code (12 digits, with or without dashes). This page checks two things:</p>
<ul class="lead" style="margin-top:6px; opacity:.9">
<li>Checksum-valid for MKW and <code>PID < 1,000,000,000</code>.</li>
<li>Whether that PID is <em>seen</em> on <strong>the RWFC VR leaderboard</strong>.</li>
</ul>
<div class="row" style="margin: 14px 0 4px;">
<input id="fc" type="text" inputmode="numeric" autocomplete="off" placeholder="e.g. 1892-8398-0920" aria-label="Mario Kart Wii friend code" />
<button id="checkBtn" type="button">Check</button>
</div>
<div class="muted">Tip: Press Enter to check.</div>
<div id="result" style="margin-top: 12px;">
<div id="big" class="big" aria-live="polite">—</div>
<div id="reason" class="sub"></div>
<div id="rwfc" class="status" hidden>
<span id="rwfcDot" class="dot"></span>
<span id="rwfcText">Waiting for input…</span>
</div>
<div id="note" class="footnote"></div>
<div id="explain" class="explain" hidden></div>
</div>
<div class="footnote">
<strong>Implementation notes</strong>: FC validity uses the MKW algorithm
(MD5 over <code>LE(PID) + "JCMR"</code>, then <code>(md5[0] >> 1)</code> matches the 7-bit checksum). PID is the lower 32 bits of the 39‑bit FC.
RWFC lookup calls <code>https://rwfc.net/api/leaderboard/player/FRIENDCODE</code>. The leaderboard API is not the single source of truth, please use the official pinfo API or the <code>/pinfo</code> command on the Retro WFC bot for PID checking. Made by ChatGPT 5 Thinking.
</div>
</main>
<script>
// === Utilities ===
const $$ = (sel) => document.querySelector(sel);
const fmtFC = (n) => String(n).padStart(12, '0').replace(/(\d{4})(\d{4})(\d{4})/, '$1-$2-$3');
function parseFC(input) {
const digits = (input || '').replace(/\D/g, '');
if (digits.length !== 12) {
return { ok: false, err: 'Friend code must have exactly 12 digits.', fc: null, pid: null, csum: null };
}
const fcVal = BigInt(digits); const MAX39 = (1n << 39n) - 1n;
if (fcVal > MAX39) {
return { ok: false, err: 'Out of range: FC must be ≤ 549,755,813,887 (39-bit).', fc: null, pid: null, csum: null, raw: digits };
}
// treat decimal as numeric 39-bit value
const pid = (Number(fcVal & 0xffffffffn)) >>> 0; // low 32 bits (unsigned)
const csum = Number((fcVal >> 32n) & 0x7fn); // high 7 bits only
return { ok: true, fcVal, pid, csum, raw: digits };
}
// Minimal MD5 -> Uint8Array(16)
function md5Bytes(bytes){
bytes = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
function rl(x,n){ return (x << n) | (x >>> (32 - n)); }
function add(x,y){ return (x + y) >>> 0; }
function F(x,y,z){ return (x & y) | (~x & z); }
function G(x,y,z){ return (x & z) | (y & ~z); }
function H(x,y,z){ return x ^ y ^ z; }
function I(x,y,z){ return y ^ (x | ~z); }
const S=[7,12,17,22, 7,12,17,22, 7,12,17,22, 7,12,17,22, 5,9,14,20, 5,9,14,20, 5,9,14,20, 5,9,14,20, 4,11,16,23, 4,11,16,23, 4,11,16,23, 4,11,16,23, 6,10,15,21, 6,10,15,21, 6,10,15,21, 6,10,15,21];
const K=new Uint32Array(64); for(let i=0;i<64;i++){ K[i]=(Math.floor(Math.abs(Math.sin(i+1))*4294967296)>>>0); }
const bitLen = BigInt(bytes.length)*8n;
const padLen = (56 - ((bytes.length + 1) % 64) + 64) % 64;
const buf = new Uint8Array(bytes.length + 1 + padLen + 8);
buf.set(bytes,0); buf[bytes.length]=0x80;
let t = bitLen; for(let i=0;i<8;i++){ buf[buf.length-8+i] = Number(t & 0xffn); t >>= 8n; }
let a=0x67452301,b=0xefcdab89,c=0x98badcfe,d=0x10325476;
const M=new Uint32Array(16);
for(let i=0;i<buf.length;i+=64){
for(let j=0;j<16;j++){ const o=i+j*4; M[j]=buf[o]|(buf[o+1]<<8)|(buf[o+2]<<16)|(buf[o+3]<<24); }
let A=a,B=b,C=c,D=d;
for(let i2=0;i2<64;i2++){
let f,g; if(i2<16){ f=F(B,C,D); g=i2; } else if(i2<32){ f=G(B,C,D); g=(5*i2+1)&15; } else if(i2<48){ f=H(B,C,D); g=(3*i2+5)&15; } else { f=I(B,C,D); g=(7*i2)&15; }
const tmp=D; D=C; C=B; const t0 = add(add(add(A,f), add(K[i2], M[g])), 0); B=add(B, rl(t0, S[i2])); A=tmp;
}
a=add(a,A); b=add(b,B); c=add(c,C); d=add(d,D);
}
const out=new Uint8Array(16), w=[a,b,c,d];
for(let i=0;i<4;i++){ out[i*4]=w[i]&255; out[i*4+1]=(w[i]>>>8)&255; out[i*4+2]=(w[i]>>>16)&255; out[i*4+3]=(w[i]>>>24)&255; }
return out;
}
function expectedChecksum7(pid) {
const b = new Uint8Array(8);
b[0] = pid & 0xff; b[1] = (pid >>> 8) & 0xff; b[2] = (pid >>> 16) & 0xff; b[3] = (pid >>> 24) & 0xff;
b[4] = 0x4a; b[5] = 0x43; b[6] = 0x4d; b[7] = 0x52; // 'J','C','M','R'
const digest = md5Bytes(b);
return (digest[0] >>> 1) & 0x7f;
}
// ---------------- Explain panel helpers ----------------
function clearExplain() {
const ex = $$('#explain');
if (ex) { ex.hidden = true; ex.innerHTML = ''; }
}
function renderInvalidChecksumExplain(rawDigits, pid, gotCsum, expected) {
const ex = $$('#explain');
if (!ex) return;
const fcVal = BigInt(rawDigits);
const fc39 = fcVal & ((1n<<39n) - 1n);
const bin = fc39.toString(2).padStart(39,'0');
const cbits = bin.slice(0,7);
const pbits = bin.slice(7);
// Recompute MD5 byte0 for explanation
const b = new Uint8Array(8);
b[0]=pid&0xff; b[1]=(pid>>>8)&0xff; b[2]=(pid>>>16)&0xff; b[3]=(pid>>>24)&0xff;
b[4]=0x4a; b[5]=0x43; b[6]=0x4d; b[7]=0x52;
const d = md5Bytes(b);
const d0 = d[0];
const d0hex = d0.toString(16).padStart(2,'0');
const pidHex = pid.toString(16).padStart(8,'0');
ex.innerHTML = `
<div><strong>Why it's impossible:</strong> checksum mismatch</div>
<div style="margin-top:6px">39‑bit layout:</div>
<div class="bitsline" role="img" aria-label="39-bit layout"><span class="seg csum">${cbits}</span><span class="seg pid">${pbits}</span></div>
<div style="margin-top:6px">PID: <span class="tag">${pid} (0x${pidHex})</span></div>
<div style="margin-top:6px">Checksum from FC: <span class="tag no">${gotCsum}</span></div>
<div style="margin-top:6px">Expected checksum: <span class="tag ok">${expected}</span>
<span class="muted">from MD5 byte0 = 0x${d0hex} → (byte0 >> 1) & 0x7F</span>
</div>
<div class="muted" style="margin-top:6px">Note: The decimal friend-code digits don’t align with bit fields; the binary view shows the 7 checksum bits (left) and 32 PID bits (right).</div>
`;
const correctedVal = (BigInt(expected) << 32n) | BigInt(pid);
const enteredDigits = String(rawDigits).padStart(12,'0');
const correctedDigits = correctedVal.toString(10).padStart(12,'0');
function dashedSpans(leftDigits, rightDigits, kind) {
leftDigits = String(leftDigits).padStart(12,'0');
rightDigits = String(rightDigits).padStart(12,'0');
let out = '';
for (let i = 0; i < 12; i++) {
const same = leftDigits[i] === rightDigits[i];
const cls = same ? 'dg same' : ('dg ' + kind);
const ch = leftDigits[i];
out += '<span class="' + cls + '" title="' + (same ? 'matches' : ('should be ' + rightDigits[i])) + '">' + ch + '</span>';
if (i === 3 || i === 7) out += '<span>-</span>';
}
return out;
}
const enteredHTML = dashedSpans(enteredDigits, correctedDigits, 'diff');
const correctedHTML = dashedSpans(correctedDigits, enteredDigits, 'fix');
ex.innerHTML += `
<div style="margin-top:10px">
<div class="fc-line"><span class="fc-caption">Entered:</span> ${enteredHTML}</div>
<div class="fc-line"><span class="fc-caption">Corrected:</span> ${correctedHTML}</div>
<div class="muted">Digits that differ from the correct friend code are highlighted.</div>
</div>`;
ex.hidden = false;
}
// ---------------- RWFC (Leaderboard) check ----------------
async function checkRWFC(friendCodeDigits) {
// Try digits-only and dashed forms; treat 200 as taken, 404 as not found.
const d = String(friendCodeDigits);
const candidates = [d, fmtFC(d)];
for (const fc of candidates) {
try {
const res = await fetch('https://rwfc.net/api/leaderboard/player/' + encodeURIComponent(fc), { method: 'GET' });
if (res.ok) return { ok: true, taken: true }; // 200
if (res.status === 404) continue; // try other representation
return { ok: false, err: 'Unexpected HTTP ' + res.status };
} catch (e) {
return { ok: false, err: (e && e.message) ? e.message : String(e) };
}
}
return { ok: true, taken: false };
}
// ---------------- UI ----------------
function setBigAnswer(mode, reasonText) {
const el = $$('#big');
el.textContent = (mode === 'no') ? 'NO' : 'YES';
el.classList.remove('ok','no','warn');
el.classList.add(mode === 'warn' ? 'warn' : (mode === 'no' ? 'no' : 'ok'));
$$('#reason').textContent = reasonText || '';
}
// Known-good runCheck: all awaits inside async, balanced braces
async function runCheck() {
const v = parseFC($$('#fc').value);
$$('#rwfc').hidden = true;
$$('#rwfcText').textContent = '';
$$('#note').textContent = '';
clearExplain();
if (!v.ok) { setBigAnswer('no', v.err); return; }
const expected = expectedChecksum7(v.pid);
if (v.csum !== expected) {
setBigAnswer('no', 'Invalid checksum for MKW. Parsed PID ' + v.pid + '.');
renderInvalidChecksumExplain(v.raw, v.pid, v.csum, expected);
return;
}
const pid = v.pid;
const WIIMMFI_ONLY_LOWER = 1000000000; // > this and <= upper → Wiimmfi-only
const WIIMMFI_ONLY_UPPER = 2147483483; // per request
const WIIMMFI_INVALID_BELOW = 600000000; // note for Wiimmfi invalid
// Wiimmfi-only range → yellow, skip RWFC check
if (pid > WIIMMFI_ONLY_LOWER && pid <= WIIMMFI_ONLY_UPPER) {
setBigAnswer('warn', 'Valid MKW FC. PID ' + pid + '. Only valid on Wiimmfi.');
return;
}
// Above upper bound → not supported anywhere
if (pid > WIIMMFI_ONLY_UPPER) {
setBigAnswer('no', 'PID ' + pid + ' is above supported ranges.');
return;
}
// pid == 1,000,000,000 exactly → treat as Wiimmfi-only (per your rule)
if (pid === WIIMMFI_ONLY_LOWER) {
setBigAnswer('warn', 'Valid MKW FC. PID ' + pid + '. Only valid on Wiimmfi.');
return;
}
// pid < 1e9 → RWFC-valid range (green) + optional Wiimmfi note + RWFC lookup
setBigAnswer('ok', 'Valid MKW FC. PID ' + pid + ' (< 1,000,000,000).');
if (pid < WIIMMFI_INVALID_BELOW) {
$$('#note').textContent = 'This code is invalid on Wiimmfi, they only allow codes starting with PID 600,000,000.';
}
$$('#rwfc').hidden = false;
$$('#rwfcDot').className = 'dot';
$$('#rwfcText').textContent = 'Checking RWFC…';
const rw = await checkRWFC(v.raw);
if (rw.ok) {
const taken = rw.taken;
$$('#rwfcDot').classList.add(taken ? 'no' : 'ok');
$$('#rwfcText').textContent = taken
? 'This code is taken on RWFC!'
: 'This code is not on the RWFC VR leaderboard!';
} else {
const _errMsg = "Couldn't check RWFC: " + rw.err + (/Failed to fetch/i.test(rw.err) ? " (network/CORS?)" : "");
$$('#rwfcText').textContent = _errMsg;
}
}
// Wire up UI
$$('#checkBtn').addEventListener('click', runCheck);
$$('#fc').addEventListener('keydown', (e)=>{ if (e.key === 'Enter') runCheck(); });
</script>
</body>
</html>