Skip to content

Commit

Permalink
fix: Improve error message about emulator connection failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Reder committed Sep 26, 2018
1 parent 8def6ee commit aad5d74
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/main/Connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export class Connector {
deleteEmulator()
}

public connectEmulator (): void {
this.window.webContents.send(MainMessage.EMULATOR_CONNECTED)
}

public updateEmulators (emulators: FilteredEmulator[]): void {
this.window.webContents.send(MainMessage.UPDATE_EMULATORS, emulators)
}
Expand Down
26 changes: 24 additions & 2 deletions src/main/Emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ export class Emulator {
if (val2 !== 0x275A7650) continue
this.baseAddress = i
}
if (!this.checkMemory()) {
throw new Error('Memory check failed')
}
this.patchMemory(characterId)
connector.connectEmulator()
}

private checkMemory (): boolean {
try {
this.readMemory(0xFF5FF0, 0x10)
return true
} catch (err) {}
return false
}

private async patchMemory (characterId: number): Promise<void> {
Expand Down Expand Up @@ -110,8 +122,18 @@ export class Emulator {
return memory
}
deleteEmulator()
connector.setEmulatorError('Insufficient permission to read memory. Try starting Net64+ with admin privileges')
throw new Error('Insufficient permission')
// let errorMessage = 'An error occured. Please double check whether your memory is set to 16MB and/or try starting Net64+ and PJ64 with admin privileges'
let errorMessage = 'An unknown error occured'
switch (memory) {
case 6:
errorMessage = 'Insufficient permission to read memory. Try starting Net64+ with admin privileges'
break
case 299:
errorMessage = 'Your memory is not set to 16MB. RTFM!'
break
}
connector.setEmulatorError(errorMessage)
throw new Error(errorMessage)
}

public reset (): void {
Expand Down
8 changes: 6 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ export const createEmulator = (
{ processId, characterId, inGameChatEnabled }:
{ processId: number, characterId: number, inGameChatEnabled: boolean }
) => {
emulator = new Emulator(processId, characterId, inGameChatEnabled)
emulator.displayChatMessage('- Net64 connected -')
try {
emulator = new Emulator(processId, characterId, inGameChatEnabled)
emulator.displayChatMessage('- Net64 connected -')
} catch (err) {
console.warn(err)
}
}

export const deleteEmulator = () => {
Expand Down
1 change: 1 addition & 0 deletions src/models/Message.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum MainMessage {
WEBSOCKET_CLOSE = 'WEBSOCKET_CLOSE',
EMULATOR_DISCONNECT = 'EMULATOR_DISCONNECT',
EMULATOR_CONNECTED = 'EMULATOR_CONNECTED',
UPDATE_EMULATORS = 'UPDATE_EMULATORS',
SET_SERVER = 'SET_SERVER',
SET_PLAYERS = 'SET_PLAYERS',
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/Connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class Connector {
constructor () {
ipcRenderer.on(MainMessage.WEBSOCKET_CLOSE, this.onWebSocketClose)
ipcRenderer.on(MainMessage.EMULATOR_DISCONNECT, this.onEmulatorDisconnect)
ipcRenderer.on(MainMessage.EMULATOR_CONNECTED, this.onEmulatorConnected)
ipcRenderer.on(MainMessage.UPDATE_EMULATORS, this.onUpdateEmulators)
ipcRenderer.on(MainMessage.SET_SERVER, this.onSetServer)
ipcRenderer.on(MainMessage.SET_PLAYERS, this.onSetPlayers)
Expand Down Expand Up @@ -55,7 +56,14 @@ export class Connector {

private onEmulatorDisconnect = () => {
store.dispatch(isConnectedToEmulator(false))
store.dispatch(setConnectionError('Emulator disconnected or closed'))
store.dispatch(setEmulatorError('Emulator disconnected or closed'))
store.dispatch(push('/emulator'))
}

private onEmulatorConnected = () => {
store.dispatch(isConnectedToEmulator(true))
store.dispatch(setEmulatorError())
store.dispatch(push('/browse'))
}

private onUpdateEmulators = (_: Electron.Event, emulators: FilteredEmulator[]) => {
Expand Down
19 changes: 16 additions & 3 deletions src/renderer/components/views/EmulatorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const TIMEOUT = 1000
interface EmulatorViewProps {
dispatch: Dispatch<State>
emulators: FilteredEmulator[]
isConnectedToEmulator: boolean
characterId: number
emuChat: boolean
error: string
Expand Down Expand Up @@ -48,6 +49,20 @@ class View extends React.PureComponent<EmulatorViewProps, EmulatorViewState> {
this.timer = setInterval(this.scan, 10000)
}

public componentWillReceiveProps (nextProps: EmulatorViewProps) {
if (nextProps.error) {
this.setState({
loading: false,
warning: nextProps.error
})
}
if (nextProps.isConnectedToEmulator && !this.props.isConnectedToEmulator) {
this.props.dispatch(isConnectedToEmulator(true))
this.props.dispatch(setEmulatorError())
this.props.dispatch(push('/browse'))
}
}

public componentWillUnmount (): void {
if (!this.timer) return
clearInterval(this.timer)
Expand All @@ -69,9 +84,6 @@ class View extends React.PureComponent<EmulatorViewProps, EmulatorViewState> {
characterId: this.props.characterId,
inGameChatEnabled: false
})
this.props.dispatch(isConnectedToEmulator(true))
this.props.dispatch(setEmulatorError())
this.props.dispatch(push('/browse'))
}, 50)
setTimeout(() => {
if (!this.mounted) return
Expand Down Expand Up @@ -170,6 +182,7 @@ class View extends React.PureComponent<EmulatorViewProps, EmulatorViewState> {
}
export const EmulatorView = connect((state: State) => ({
emulators: state.emulator.emulators,
isConnectedToEmulator: state.emulator.isConnectedToEmulator,
characterId: state.save.appSaveData.character,
emuChat: state.save.appSaveData.emuChat,
error: state.emulator.error
Expand Down
9 changes: 8 additions & 1 deletion src/renderer/components/views/FaqView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@ class View extends React.PureComponent<FaqViewProps> {
text='Got it!'
onClick={this.onDone}
/>
<h2 style={{marginTop: '40px'}}>Emulator settings</h2>
<div style={{marginTop: '40px'}}></div>
<div style={styles.text}>
You must use the emulator which comes bundled with Net64+!
</div>
<h2>Emulator settings</h2>
<div style={styles.text}>
Make sure your emulator settings match the green circles
</div>
<div style={styles.imgWrapper}>
<img style={styles.img} src='img/pj64_help1.png' />
</div>
<div style={styles.text}>
After setting your memory to 16MB, you will have to restart Project64
</div>
<div style={styles.imgWrapper}>
<img style={styles.img} src='img/pj64_help2.png' />
</div>
Expand Down

0 comments on commit aad5d74

Please sign in to comment.