Skip to content
Open
4 changes: 2 additions & 2 deletions build_injector.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/sh

BASE64BUNDLE="return '$(base64 dist/index.js)'"
BASE64BUNDLE="return '$(base64 < dist/index.js)'"
VERSION="$(grep version package.json | sed -e 's/..version....//g' -e 's/...$//g')"
COMMITHASH="$(git rev-parse --short HEAD)"
echo -n $BASE64BUNDLE > bundle.b64
printf "%s" "$BASE64BUNDLE" > bundle.b64
sed -e "s/WISPCRAFTVERSION/$VERSION/g" -e "s/WISPCRAFTCOMMITHASH/$COMMITHASH/g" -e "/WISPCRAFTSRCBUNDLE/r bundle.b64" -e "/WISPCRAFTSRCBUNDLE/d" "index.html" > dist/injector.html
rm bundle.b64
echo "Injector Build Complete!"
2 changes: 0 additions & 2 deletions ci/_headers

This file was deleted.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<sub></sub>
<h1>Wispcraft Injector</h1>
<p>
Inject WISP into your EaglercraftX 1.8 client and play on real Minecraft
Inject WISP into your EaglercraftX 1.8/1.12 client and play on real Minecraft
servers!
</p>
<label id="file-label">
Expand Down
22 changes: 14 additions & 8 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/bin/sh

rm -rf dist
mkdir -p dist
npm run build

cd dist
curl -L https://bafybeialxd4xd7puchx555zqrfmuaz7e7n7nh4crb3sfhvprxedx4c64fq.ipfs.dweb.link/?filename=EaglercraftX_1.8_WASM-GC_Offline_Download.zip -o eaglercraft.zip
unzip eaglercraft.zip
rm eaglercraft.zip
mv EaglercraftX_1.8_WASM-GC_Offline_Download.html index.html
sed -i 's/<head>/<head>\<script src="index.js"><\/script>/' index.html
cp ../ci/_headers .
curl -L https://bafybeid5iwqp3uyc4q3dqajjzbsqggqatuttqk4dnkksluqqcxaizbhjpi.ipfs.dweb.link/?filename=u53_web.zip -o eaglercraft.zip
unzip eaglercraft.zip -d eaglercraft
rm -rf eaglercraft.zip
mv -f eaglercraft/web_wasm/index.html index.html
mv -f eaglercraft/web_wasm/assets.epw assets.epw
mv -f eaglercraft/web_wasm/bootstrap.js bootstrap.js
rm -rf eaglercraft
if [[ "$OSTYPE" != darwin* ]]; then
sed -i 's|<head>|<head><script src="index.js"></script>|' index.html
else
sed -i '' 's|<head>|<head><script src="index.js"></script>|' index.html
fi
33 changes: 25 additions & 8 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import encodeQR from "qr";
import { epoxyFetch } from "./connection/epoxy";

// https://gist.github.com/Plagiatus/ce5f18bc010395fc45d8553905e10f55
Expand Down Expand Up @@ -29,6 +30,30 @@ interface OAuthResponse {
refresh_token: string;
}

interface DeviceCodeResponse {
device_code: string;
user_code: string;
verification_uri: string;
expires_in: number;
interval: number;
}

type AuthCodeResponse = DeviceCodeResponse & {
link_url: string;
qr_svg: string;
qr_svg_uri: string;
};

export async function getAuthCodeResponse () {
const codeGenerator = await deviceCodeAuth();
const linkUrl = "https://microsoft.com/link?otc=" + codeGenerator.code;
const qrSvg = encodeQR(linkUrl, "svg", {
scale: 6,
border: 1,
});
return { ...codeGenerator, link_url: linkUrl, qr_svg: qrSvg, qr_svg_uri: `data:image/svg+xml;base64,${btoa(qrSvg)}` }
}

export async function deviceCodeAuth() {
// TOOD: Type
const deviceCodeRes = await epoxyFetch(
Expand All @@ -45,14 +70,6 @@ export async function deviceCodeAuth() {
}
);

interface DeviceCodeResponse {
device_code: string;
user_code: string;
verification_uri: string;
expires_in: number;
interval: number;
}

const deviceCodeData: DeviceCodeResponse = await deviceCodeRes.json();
const { device_code, user_code, verification_uri, interval } = deviceCodeData;

Expand Down
10 changes: 10 additions & 0 deletions src/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ export class Buffer {
this.extend(new Buffer(data));
}

readUByte(): number {
const ret = this.get(0);
this.take(1);
return ret;
}

writeUByte(num: number) {
this.extend(new Buffer([num & 0xff]));
}

readUShort(): number {
const ret = (this.get(0) << 8) | this.get(1);
this.take(2);
Expand Down
6 changes: 3 additions & 3 deletions src/connection/fakewebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { authstore, COMMITHASH, VERSION, wispUrl } from "..";
import { Buffer } from "../buffer";
import { showUI } from "../ui";
import { epoxyWs } from "./epoxy";
// @ts-ignore typescript sucks
import wispcraft from "./wispcraft.png";
// @ts-ignore
import workshop from "../img/workshop64.png";

class WispWS extends EventTarget {
inner: Connection;
Expand Down Expand Up @@ -132,7 +132,7 @@ class SettingsWS extends EventTarget {
}),
})
);
fetch(wispcraft)
fetch(workshop)
.then((response) => response.blob())
.then((blob) => createImageBitmap(blob))
.then((image) => {
Expand Down
2 changes: 1 addition & 1 deletion src/connection/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EaglerProxy } from "../1.8";
import { EaglerProxy } from "../proxy";
import { connect_tcp } from "./epoxy";
import { epoxyFetch } from "./epoxy";
import { Buffer } from "../buffer";
Expand Down
Binary file removed src/connection/wispcraft.png
Binary file not shown.
Binary file added src/img/workshop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/workshop64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 28 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { getProfile, minecraftAuth, UserInfo } from "./auth";
import { getAuthCodeResponse, getProfile, minecraftAuth, UserInfo } from "./auth";
import { epoxyFetch, initWisp } from "./connection/epoxy";
import { makeFakeWebSocket } from "./connection/fakewebsocket";
import { showUI } from "./ui";

//@ts-expect-error this gets filled in by rollup
export const VERSION = self.VERSION;
//@ts-expect-error this too
export const COMMITHASH = self.COMMITHASH;

export const DEFAULT_WISP_URL = "wss://anura.pro/";

export let wispUrl: string;

export type AuthStore = {
Expand Down Expand Up @@ -41,22 +44,35 @@ wispUrl =
((window as any).anura && (window as any).anura.wsproxyURL) ||
new URL(window.location.href).searchParams.get("wisp") ||
localStorage["wispcraft_wispurl"] ||
"wss://anura.pro/";
DEFAULT_WISP_URL;

try {
setWispUrl(wispUrl);
} catch (e) {
console.error(e);
}

export function getLoggedInAccounts (): TokenStore[] | undefined {
const accounts = localStorage["wispcraft_accounts"];
if (accounts) {
return JSON.parse(accounts) as TokenStore[];
} else {
return undefined;
}
}

export function getLastUsedAccount (): TokenStore | undefined {
const username = localStorage["wispcraft_last_used_account"];
const accounts = getLoggedInAccounts();
if (username && accounts) {
return accounts.find((account) => account.username === username);
} else {
return undefined;
}
}

if (localStorage["wispcraft_accounts"]) {
const accounts = JSON.parse(
localStorage["wispcraft_accounts"]
) as TokenStore[];
const account = accounts.find(
(account) =>
account.username === localStorage["wispcraft_last_used_account"]
);
const account = getLastUsedAccount();
if (account) {
(async () => {
try {
Expand All @@ -71,6 +87,9 @@ if (localStorage["wispcraft_accounts"]) {
}
}

export const showSettingsUI = showUI;
export const getAuthCode = getAuthCodeResponse;

// replace websocket with our own
window.WebSocket = makeFakeWebSocket();

Expand Down
Loading