Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
ottomated committed Nov 20, 2020
2 parents 01a0e53 + 0c0552c commit 92162ed
Show file tree
Hide file tree
Showing 9 changed files with 332 additions and 183 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crewlink",
"version": "1.0.4",
"version": "1.1.0",
"license": "GPL-3.0-or-later",
"description": "Free, open, Among Us proximity voice chat",
"repository": {
Expand Down
17 changes: 14 additions & 3 deletions src/main/GameReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IOffsets } from "./hook";

export interface AmongUsState {
gameState: GameState;
oldGameState: GameState;
lobbyCode: string;
players: Player[];
}
Expand Down Expand Up @@ -36,6 +37,8 @@ export default class GameReader {
offsets: IOffsets;
PlayerStruct: any;

menuUpdateTimer = 20;
lastPlayerPtr = 0;
shouldReadLobby = false;
exileCausesEnd = false;
oldGameState = GameState.UNKNOWN;
Expand Down Expand Up @@ -122,8 +125,14 @@ export default class GameReader {
state = GameState.LOBBY;
}
}
this.oldGameState = state;

if (this.oldGameState === GameState.MENU && state === GameState.LOBBY && this.menuUpdateTimer > 0 &&
(this.lastPlayerPtr === allPlayers || players.length === 1 || !players.find(p => p.isLocal))) {
state = GameState.MENU;
this.menuUpdateTimer--;
} else {
this.menuUpdateTimer = 20;
}
this.lastPlayerPtr = allPlayers;

let inGame = state === GameState.TASKS || state === GameState.DISCUSSION || state === GameState.LOBBY;
let newGameCode = 'MENU';
Expand All @@ -147,7 +156,8 @@ export default class GameReader {
let newState = {
lobbyCode: this.gameCode,
players,
gameState: state
gameState: state,
oldGameState: this.oldGameState
};
let patch = patcher.diff(this.lastState, newState);
if (patch) {
Expand All @@ -158,6 +168,7 @@ export default class GameReader {
}
}
this.lastState = newState;
this.oldGameState = state;
}
}

Expand Down
168 changes: 93 additions & 75 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import {autoUpdater} from 'electron-updater';
import { autoUpdater } from 'electron-updater';
import { app, BrowserWindow, ipcMain } from 'electron';
import * as path from 'path'
import { format as formatUrl } from 'url'
Expand All @@ -11,88 +11,106 @@ const isDevelopment = process.env.NODE_ENV !== 'production'
// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow: BrowserWindow | null;

// app.disableHardwareAcceleration();
autoUpdater.checkForUpdatesAndNotify();

function createMainWindow() {
const window = new BrowserWindow({
width: 250,
height: 350,
resizable: false,
frame: false,
fullscreenable: false,
maximizable: false,
transparent: true,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
webSecurity: false
app.commandLine.appendSwitch('disable-pinch');

const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
// app.disableHardwareAcceleration();
autoUpdater.checkForUpdatesAndNotify();
app.on('second-instance', (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()
}
});
})

if (isDevelopment) {
window.webContents.openDevTools()
}

if (isDevelopment) {
window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`)
}
else {
window.loadURL(formatUrl({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true
}))
}
function createMainWindow() {
const window = new BrowserWindow({
width: 250,
height: 350,
resizable: false,
frame: false,
fullscreenable: false,
maximizable: false,
transparent: true,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
webSecurity: false
}
});

if (isDevelopment) {
window.webContents.openDevTools()
}

window.on('closed', () => {
mainWindow = null
})
if (isDevelopment) {
window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}?version=${autoUpdater.currentVersion.version}`)
}
else {
window.loadURL(formatUrl({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
query: {
version: autoUpdater.currentVersion.version
},
slashes: true
}))
}

window.on('closed', () => {
mainWindow = null
})

window.webContents.on('devtools-opened', () => {
window.focus()
setImmediate(() => {
window.webContents.on('devtools-opened', () => {
window.focus()
setImmediate(() => {
window.focus()
})
})

return window
}

// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit()
}
})

return window
}
app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow()
}
})

// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit()
}
})
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow();
});

app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow()
}
})

// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow();
});

// ipcMain.on('alwaysOnTop', (event, onTop: boolean) => {
// if (mainWindow) {
// mainWindow.setAlwaysOnTop(onTop, 'floating', 1);
// mainWindow.setVisibleOnAllWorkspaces(true);
// mainWindow.setFullScreenable(false);
// }
// });

ipcMain.on('shortcut', (event, val) => {
event.returnValue = false;
// console.log('register', val);
// globalShortcut.unregisterAll();
// event.returnValue = globalShortcut.register(val!, () => {
// console.log("push-to-talk");
// })

});
// ipcMain.on('alwaysOnTop', (event, onTop: boolean) => {
// if (mainWindow) {
// mainWindow.setAlwaysOnTop(onTop, 'floating', 1);
// mainWindow.setVisibleOnAllWorkspaces(true);
// mainWindow.setFullScreenable(false);
// }
// });

ipcMain.on('shortcut', (event, val) => {
event.returnValue = false;
// console.log('register', val);
// globalShortcut.unregisterAll();
// event.returnValue = globalShortcut.register(val!, () => {
// console.log("push-to-talk");
// })

});
}
13 changes: 11 additions & 2 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { ipcRenderer, remote } from 'electron';
import { AmongUsState } from '../main/GameReader';
import Settings, { ISettings, settingsReducer } from './Settings';

let appVersion = '';
if (typeof window !== 'undefined' && window.location) {
let query = new URLSearchParams(window.location.search.substring(1));
appVersion = (' v' + query.get('version')) || '';
}


enum AppState { MENU, VOICE };

export const GameStateContext = createContext<AmongUsState>({} as AmongUsState);
Expand All @@ -30,7 +37,9 @@ function App() {
offsets: {
version: '',
data: ''
}
},
hideCode: false,
stereoInLobby: true
});

useEffect(() => {
Expand Down Expand Up @@ -74,7 +83,7 @@ function App() {
<GameStateContext.Provider value={gameState}>
<SettingsContext.Provider value={settings}>
<div className="titlebar">
<span className="title">CrewLink</span>
<span className="title">CrewLink{appVersion}</span>
<svg className="titlebar-button settings" onClick={() => setSettingsOpen(!settingsOpen)} enableBackground="new 0 0 24 24" viewBox="0 0 24 24" fill="#868686" width="20px" height="20px">
<g>
<path d="M0,0h24v24H0V0z" fill="none" />
Expand Down
76 changes: 44 additions & 32 deletions src/renderer/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,56 @@ function Canvas({ src, hat, skin, color, shadow, isAlive }: CanvasProps) {
const image = useRef<HTMLImageElement>(null);

useEffect(() => {
if (!canvas.current || !image.current || !hatImg.current || !skinImg.current) return;
const ctx = canvas.current.getContext('2d')!;
(async () => {
if (!canvas.current || !image.current || !hatImg.current || !skinImg.current) return;
const ctx = canvas.current.getContext('2d')!;

canvas.current.width = image.current.width;
canvas.current.height = image.current.height;
ctx.clearRect(0, 0, canvas.current.width, canvas.current.height);
ctx.drawImage(image.current, 0, 0);
if (!image.current.complete) {
await new Promise(r => image!.current!.onload = r);
}
if (!hatImg.current.complete) {
await new Promise(r => hatImg!.current!.onload = r);
}
if (!skinImg.current.complete) {
await new Promise(r => skinImg!.current!.onload = r);
}

function drawHat() {
let hatY = 17 - hatOffsets[hat];
ctx.drawImage(hatImg.current!, 0, hatY > 0 ? 0 : -hatY, hatImg.current!.width, hatImg.current!.height, canvas.current!.width / 2 - hatImg.current!.width / 2 + 2, Math.max(hatY, 0), hatImg.current!.width, hatImg.current!.height);
}
canvas.current.width = image.current.width;
canvas.current.height = image.current.height;
ctx.clearRect(0, 0, canvas.current.width, canvas.current.height);
ctx.drawImage(image.current, 0, 0);

function drawHat() {
let hatY = 17 - hatOffsets[hat];
ctx.drawImage(hatImg.current!, 0, hatY > 0 ? 0 : -hatY, hatImg.current!.width, hatImg.current!.height, canvas.current!.width / 2 - hatImg.current!.width / 2 + 2, Math.max(hatY, 0), hatImg.current!.width, hatImg.current!.height);
}

let data = ctx.getImageData(0, 0, image.current.width, image.current.height);
for (let i = 0; i < data.data.length; i += 4) {
let r = data.data[i],
g = data.data[i + 1],
b = data.data[i + 2];
if (r !== 255 || g !== 255 || b !== 255) {
let pixelColor = Color('#000000')
.mix(Color(shadow), b / 255)
.mix(Color(color), r / 255)
.mix(Color('#9acad5'), g / 255);
data.data[i] = pixelColor.red();
data.data[i + 1] = pixelColor.green();
data.data[i + 2] = pixelColor.blue();

let data = ctx.getImageData(0, 0, image.current.width, image.current.height);
for (let i = 0; i < data.data.length; i += 4) {
let r = data.data[i],
g = data.data[i + 1],
b = data.data[i + 2];
if (r !== 255 || g !== 255 || b !== 255) {
let pixelColor = Color('#000000')
.mix(Color(shadow), b / 255)
.mix(Color(color), r / 255)
.mix(Color('#9acad5'), g / 255);
data.data[i] = pixelColor.red();
data.data[i + 1] = pixelColor.green();
data.data[i + 2] = pixelColor.blue();
}
}
}
ctx.putImageData(data, 0, 0);
if (isAlive) {
if (backLayerHats.has(hat))
ctx.globalCompositeOperation = 'destination-over';
drawHat();
ctx.globalCompositeOperation = 'source-over';
ctx.putImageData(data, 0, 0);
if (isAlive) {
if (backLayerHats.has(hat))
ctx.globalCompositeOperation = 'destination-over';
drawHat();
ctx.globalCompositeOperation = 'source-over';

ctx.drawImage(skinImg.current, 25, 46);
}
ctx.drawImage(skinImg.current, 25, 46);
}
})();

}, [src, color, shadow, hat, skin, isAlive]);

Expand Down

0 comments on commit 92162ed

Please sign in to comment.