Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP support for GamePass/Xbox/WindowsStore edition of Among Us #422

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/main/GameReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import patcher from '../patcher';
import { GameState, AmongUsState, Player } from '../common/AmongUsState';
import { IOffsets } from './IOffsets';

const extraStructronTypes = {
__proto__: null,
// HACK assuming the value in a 64bit uint is never too large
'UINT64': {
read(buffer: Buffer, offset: number) {
return Number(buffer.readBigUInt64LE(offset));
},
write(value: number, buffer: Buffer, offset: number) {
buffer.writeBigUInt64LE(BigInt(value), offset);
},
SIZE: 8
}
};

interface ValueType<T> {
read(buffer: BufferSource, offset: number): T;
Expand Down Expand Up @@ -87,7 +100,9 @@ export default class GameReader {
break;
}

// TODO pretty sure this does not read 64bit ptrs correctly
const allPlayersPtr = this.readMemory<number>('ptr', this.gameAssembly.modBaseAddr, this.offsets.allPlayersPtr) & 0xffffffff;
// TODO pretty sure this does not read 64bit ptrs correctly
const allPlayers = this.readMemory<number>('ptr', allPlayersPtr, this.offsets.allPlayers);
const playerCount = this.readMemory<number>('int' as const, allPlayersPtr, this.offsets.playerCount);
let playerAddrPtr = allPlayers + this.offsets.playerAddrPtr;
Expand Down Expand Up @@ -178,7 +193,8 @@ export default class GameReader {
if (member.type === 'SKIP' && member.skip) {
this.PlayerStruct = this.PlayerStruct.addMember(Struct.TYPES.SKIP(member.skip), member.name);
} else {
this.PlayerStruct = this.PlayerStruct.addMember<unknown>(Struct.TYPES[member.type] as ValueType<unknown>, member.name);
const type = (extraStructronTypes[member.type as unknown as keyof typeof extraStructronTypes] ?? Struct.TYPES[member.type]) as ValueType<unknown>;
this.PlayerStruct = this.PlayerStruct.addMember<unknown>(type, member.name);
}
}

Expand All @@ -199,7 +215,7 @@ export default class GameReader {
if (!this.amongUs) throw 'Among Us not open? Weird error';
address = address & 0xffffffff;
for (let i = 0; i < offsets.length - 1; i++) {
address = readMemoryRaw<number>(this.amongUs.handle, address + offsets[i], 'uint32');
address = readMemoryRaw<number>(this.amongUs.handle, address + offsets[i], this.offsets.is64Bit ? 'uint64' : 'uint32');

if (address == 0) break;
}
Expand All @@ -208,8 +224,8 @@ export default class GameReader {
}
readString(address: number): string {
if (address === 0 || !this.amongUs) return '';
const length = readMemoryRaw<number>(this.amongUs.handle, address + 0x8, 'int');
const buffer = readBuffer(this.amongUs.handle, address + 0xC, length << 1);
const length = readMemoryRaw<number>(this.amongUs.handle, address + (this.offsets.is64Bit ? 0x10 : 0x8), 'int');
const buffer = readBuffer(this.amongUs.handle, address + (this.offsets.is64Bit ? 0x14 : 0xC), length << 1);
return buffer.toString('utf8').replace(/\0/g, '');
}

Expand Down
1 change: 1 addition & 0 deletions src/main/IOffsets.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

export interface IOffsets {
is64Bit?: boolean;
meetingHud: number[];
meetingHudCachePtr: number[];
meetingHudState: number[];
Expand Down
54 changes: 54 additions & 0 deletions src/main/baked-offsets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export const bundledOffsets: Record<string, string> = {
// Windows Store UWP 2020.12.4.0
'2020.12.4.0': `
is64Bit: true
meetingHud: [0x21D03E0, 0xB8, 0]
meetingHudCachePtr: [0x8]
meetingHudState: [0xC0]
gameState: [0x21D0EA0, 0xB8, 0, 0xAC]
allPlayersPtr: [0x1BE0BB8, 0xB8, 0, 0x30]
allPlayers: [0x08]
playerCount: [0x0c]
playerAddrPtr: 0x10
exiledPlayerId: [0xff, 0x21D03E0, 0xB8, 0, 0xE0, 0x10]
gameCode: [0x1D50138, 0xB8, 0, 0x40, 0x48]
player:
struct:
- type: SKIP
skip: 10
name: unused
- type: UINT
name: id
- type: UINT64
name: name
- type: UINT
name: color
- type: UINT
name: hat
- type: UINT
name: pet
- type: UINT
name: skin
- type: UINT
name: disconnected
- type: UINT64
name: taskPtr
- type: BYTE
name: impostor
- type: BYTE
name: dead
- type: SKIP
skip: 2
name: unused
- type: UINT64
name: objectPtr
isLocal: [0x78]
localX: [0x90, 0x6C]
localY: [0x90, 0x70]
remoteX: [0x90, 0x58]
remoteY: [0x90, 0x5C]
bufferLength: 64
offsets: [0, 0]
inVent: [0x3D]
`
};
1 change: 1 addition & 0 deletions src/main/hook-ti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as t from 'ts-interface-checker';
// tslint:disable:object-literal-key-quotes

export const IOffsets = t.iface([], {
'is64Bit': t.opt('boolean'),
'meetingHud': t.array('number'),
'meetingHudCachePtr': t.array('number'),
'meetingHudState': t.array('number'),
Expand Down
32 changes: 30 additions & 2 deletions src/main/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createCheckers } from 'ts-interface-checker';
import TI from './hook-ti';
import { existsSync, readFileSync } from 'fs';
import { IOffsets } from './IOffsets';
import { bundledOffsets } from './baked-offsets';
const { IOffsets } = createCheckers(TI);

interface IOHookEvent {
Expand All @@ -28,6 +29,7 @@ interface IOHookEvent {
}

const store = new Store<ISettings>();
let edition: 'steam' | 'windowsstore' = 'steam';

async function loadOffsets(event: Electron.IpcMainEvent): Promise<IOffsets | undefined> {

Expand All @@ -43,14 +45,37 @@ async function loadOffsets(event: Electron.IpcMainEvent): Promise<IOffsets | und
return;
}
} else {
event.reply('error', 'Couldn\'t determine the Among Us version - Unity analytics file doesn\'t exist. Try opening Among Us and then restarting CrewLink.');
return;
// Try to get Windows Store install location via Windows Powershell cmdlet
const process = spawn.sync('powershell.exe', [
'-nologo',
'-executionpolicy', 'remotesigned',
'-noprofile',
'-command', 'Get-AppxPackage -Name InnerSloth.AmongUs | ConvertTo-Json'
], {
stdio: ['ignore', 'pipe', 'ignore'],
encoding: 'utf8'
});
if (process.status === 0) {
try {
const appxManifest = JSON.parse(process.output[1]);
version = appxManifest.Version;
edition = 'windowsstore';
} catch (e) {
console.error(e);
event.reply('error', `Couldn't determine the Among Us version - ${e}. Try opening Among Us and then restarting CrewLink.`);
return;
}
} else {
event.reply('error', 'Couldn\'t determine the Among Us version - Unity analytics file or Windows Store installation doesn\'t exist. Try opening Among Us and then restarting CrewLink.');
}
}

let data: string;
const offsetStore = store.get('offsets') || {};
if (version === offsetStore.version) {
data = offsetStore.data;
} else if(bundledOffsets[version]) {
data = bundledOffsets[version];
} else {
try {
const response = await axios({
Expand Down Expand Up @@ -173,6 +198,9 @@ function keyCodeMatches(key: K, ev: IOHookEvent): boolean {


ipcMain.on('openGame', () => {
if(edition === 'windowsstore') {
dialog.showErrorBox('Error', 'CrewLink thinks you are using the Windows Store / XBox edition of Among Us. You must launch Among Us manually.');
}
// Get steam path from registry
const steamPath = enumerateValues(HKEY.HKEY_LOCAL_MACHINE,
'SOFTWARE\\WOW6432Node\\Valve\\Steam')
Expand Down
14 changes: 7 additions & 7 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ function createMainWindow() {
const mainWindowState = windowStateKeeper({});

const window = new BrowserWindow({
width: 250,
height: 350,
maxWidth: 250,
minWidth: 250,
maxHeight: 350,
minHeight: 350,
width: 1000,
height: 1000,
// maxWidth: 1000,
// minWidth: 1000,
// maxHeight: 1000,
// minHeight: 1000,
x: mainWindowState.x,
y: mainWindowState.y,

resizable: false,
// resizable: false,
frame: false,
fullscreenable: false,
maximizable: false,
Expand Down