Skip to content

Commit

Permalink
[Improv]: Confirm installing broken anticheat games (#2981)
Browse files Browse the repository at this point in the history
* Ask the user to confirm the installation of broken anticheat games

* Ask the user to confirm the installation of broken anticheat games
  • Loading branch information
arielj authored Sep 4, 2023
1 parent 480067b commit ee1a060
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
6 changes: 6 additions & 0 deletions public/locales/en/gamepage.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
"version": "Version"
},
"install": {
"anticheat-warning": {
"cancel": "No",
"install": "Yes (I understand it will not work)",
"message": "The anticheat support is broken or denied. The game will not work. Do you want to install it anyway?",
"title": "Anticheat Broken/Denied"
},
"disk-space-left": "Space Available",
"not-enough-disk-space": "Not enough disk space",
"path": "Select Install Path",
Expand Down
24 changes: 4 additions & 20 deletions src/frontend/components/UI/Anticheat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { MouseEvent, useEffect, useState } from 'react'
import { AntiCheatInfo, GameInfo } from 'common/types'
import React, { MouseEvent } from 'react'
import { AntiCheatInfo } from 'common/types'
import { createNewWindow } from 'frontend/helpers'

import { ReactComponent as InfoIcon } from 'frontend/assets/info_icon.svg'
Expand All @@ -10,30 +10,14 @@ import './index.scss'
import { useTranslation } from 'react-i18next'

type Props = {
gameInfo: GameInfo
anticheatInfo: AntiCheatInfo | null
}

const awacyUrl = 'https://areweanticheatyet.com/'

export default function Anticheat({ gameInfo }: Props) {
export default function Anticheat({ anticheatInfo }: Props) {
const { t } = useTranslation()

const [anticheatInfo, setAnticheatInfo] = useState<AntiCheatInfo | null>(null)

useEffect(() => {
if (
gameInfo.runner !== 'sideload' &&
gameInfo.title &&
gameInfo.namespace !== undefined
) {
window.api
.getAnticheatInfo(gameInfo.namespace)
.then((anticheatInfo: AntiCheatInfo | null) => {
setAnticheatInfo(anticheatInfo)
})
}
}, [gameInfo])

if (!anticheatInfo) {
return null
}
Expand Down
22 changes: 22 additions & 0 deletions src/frontend/hooks/hasAnticheatInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect, useState } from 'react'
import { AntiCheatInfo, GameInfo } from 'common/types'

export const hasAnticheatInfo = (gameInfo: GameInfo) => {
const [anticheatInfo, setAnticheatInfo] = useState<AntiCheatInfo | null>(null)

useEffect(() => {
if (
gameInfo.runner !== 'sideload' &&
gameInfo.title &&
gameInfo.namespace !== undefined
) {
window.api
.getAnticheatInfo(gameInfo.namespace)
.then((anticheatInfo: AntiCheatInfo | null) => {
setAnticheatInfo(anticheatInfo)
})
}
}, [gameInfo])

return anticheatInfo
}
5 changes: 4 additions & 1 deletion src/frontend/screens/Game/GamePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import HowLongToBeat from 'frontend/components/UI/WikiGameInfo/components/HowLon
import GameScore from 'frontend/components/UI/WikiGameInfo/components/GameScore'
import DLCList from 'frontend/components/UI/DLCList'
import { NileInstallInfo } from 'common/types/nile'
import { hasAnticheatInfo } from 'frontend/hooks/hasAnticheatInfo'

export default React.memo(function GamePage(): JSX.Element | null {
const { appName, runner } = useParams() as { appName: string; runner: Runner }
Expand Down Expand Up @@ -130,6 +131,8 @@ export default React.memo(function GamePage(): JSX.Element | null {
const [showRequirements, setShowRequirements] = useState(false)
const [showDlcs, setShowDlcs] = useState(false)

const anticheatInfo = hasAnticheatInfo(gameInfo)

const isWin = platform === 'win32'
const isLinux = platform === 'linux'
const isMac = platform === 'darwin'
Expand Down Expand Up @@ -760,7 +763,7 @@ export default React.memo(function GamePage(): JSX.Element | null {
))}
</SelectField>
)}
<Anticheat gameInfo={gameInfo} />
<Anticheat anticheatInfo={anticheatInfo} />
{is_installed && !isQueued && (
<button
disabled={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { AvailablePlatforms } from '../index'
import { configStore } from 'frontend/helpers/electronStores'
import DLCDownloadListing from './DLCDownloadListing'
import { NileInstallInfo } from 'common/types/nile'
import { hasAnticheatInfo } from 'frontend/hooks/hasAnticheatInfo'

interface Props {
backdropClick: () => void
Expand Down Expand Up @@ -154,6 +155,8 @@ export default function DownloadDialog({
spaceLeftAfter: ''
})

const anticheatInfo = hasAnticheatInfo(gameInfo)

const { i18n, t } = useTranslation('gamepage')
const { t: tr } = useTranslation()

Expand Down Expand Up @@ -187,7 +190,37 @@ export default function DownloadDialog({
setInstallAllDlcs(!installAllDlcs)
}

async function handleInstall(path?: string) {
function confirmInstallBrokenAnticheat(path?: string) {
showDialogModal({
title: t('install.anticheat-warning.title', 'Anticheat Broken/Denied'),
message: t(
'install.anticheat-warning.message',
'The anticheat support is broken or denied. The game will not work. Do you want to install it anyway?'
),
buttons: [
{
text: t(
'install.anticheat-warning.install',
'Yes (I understand it will not work)'
),
onClick: async () => handleInstall(path, true)
},
{
text: t('install.anticheat-warning.cancel', 'No'),
onClick: () => null
}
]
})
}

async function handleInstall(path?: string, ignoreAnticheat = false) {
if (anticheatInfo && ['Denied', 'Broken'].includes(anticheatInfo.status)) {
if (!ignoreAnticheat) {
confirmInstallBrokenAnticheat(path)
return
}
}

backdropClick()

// Write Default game config with prefix on linux
Expand Down Expand Up @@ -394,7 +427,7 @@ export default function DownloadDialog({
/>
))}
</DialogHeader>
{gameInfo && <Anticheat gameInfo={gameInfo} />}
<Anticheat anticheatInfo={anticheatInfo} />
<DialogContent>
<div className="InstallModal__sizes">
<div className="InstallModal__size">
Expand Down

0 comments on commit ee1a060

Please sign in to comment.