-
-
Notifications
You must be signed in to change notification settings - Fork 210
fix/feat: extract XAudio DLLs from DirectX redistributables #1184
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
Open
joshuatam
wants to merge
13
commits into
utkarshdalal:master
Choose a base branch
from
joshuatam:feat/decompress-directx-fix-xaudio
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
203eba8
feat: extract XAudio DLLs from DirectX redistributables
joshuatam 4356a6e
refactor replaceXAudioDllsFromRedistributable to XServerScreenUtils
joshuatam ab97c33
fix gameId detection
joshuatam ce923a1
surround gameId detection with try catch
joshuatam 82a6300
update use FileOutputStream for dll extraction
joshuatam 1c74eb2
add log when appDirPath detection failed
joshuatam 2cd8bde
move SevenZip init outside per file function
joshuatam 6dda193
ai comments
joshuatam f416f05
only apply for proton 10, fix proton 9.0 compatibility
joshuatam e4a94bf
revert SteamUtils changes
joshuatam be1eef4
fix directXDir detection logic
joshuatam 4b20b86
fix directXDir detection logic
joshuatam 7c684e0
update proton 10 logic
joshuatam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreenUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package app.gamenative.ui.screen.xserver | ||
|
|
||
| import android.content.Context | ||
| import app.gamenative.data.GameSource | ||
| import app.gamenative.service.SteamService | ||
| import app.gamenative.service.amazon.AmazonService | ||
| import app.gamenative.service.epic.EpicService | ||
| import app.gamenative.service.gog.GOGService | ||
| import app.gamenative.utils.ContainerUtils | ||
| import app.gamenative.utils.CustomGameScanner | ||
| import app.gamenative.utils.FileUtils | ||
| import com.winlator.xenvironment.ImageFs | ||
| import net.sf.sevenzipjbinding.ExtractAskMode | ||
| import net.sf.sevenzipjbinding.ExtractOperationResult | ||
| import net.sf.sevenzipjbinding.IArchiveExtractCallback | ||
| import net.sf.sevenzipjbinding.IInArchive | ||
| import net.sf.sevenzipjbinding.ISequentialOutStream | ||
| import net.sf.sevenzipjbinding.SevenZip | ||
| import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream | ||
| import timber.log.Timber | ||
| import java.io.File | ||
| import java.io.FileOutputStream | ||
| import java.io.RandomAccessFile | ||
|
|
||
| class XServerScreenUtils { | ||
| /** | ||
| * Replace DLLs from DirectX Redistributable | ||
| */ | ||
| companion object { | ||
| fun replaceXAudioDllsFromRedistributable(context: Context, appId: String) { | ||
| val gameSource = ContainerUtils.extractGameSourceFromContainerId(appId) | ||
| val appDirPath = try { | ||
| when (gameSource) { | ||
| GameSource.STEAM -> { | ||
| val gameId = ContainerUtils.extractGameIdFromContainerId(appId) | ||
| SteamService.getAppDirPath(gameId) | ||
| } | ||
| GameSource.GOG -> GOGService.getInstallPath(appId) | ||
| GameSource.EPIC -> { | ||
| val gameId = ContainerUtils.extractGameIdFromContainerId(appId) | ||
| EpicService.getInstallPath(gameId) | ||
| } | ||
| GameSource.AMAZON -> AmazonService.getInstallPath(appId) | ||
| GameSource.CUSTOM_GAME -> CustomGameScanner.getFolderPathFromAppId(appId) | ||
| } | ||
| } catch (e: Exception) { | ||
| Timber.tag("replaceXAudioDllsFromRedistributable") | ||
| .w(e, "Failed to resolve install path for appId=%s source=%s", appId, gameSource) | ||
| null | ||
| } | ||
|
|
||
| // Not Support Type | ||
| if (appDirPath == null) { | ||
| return | ||
| } | ||
|
|
||
| val appDir = File(appDirPath) | ||
|
|
||
| // Check the common path first, otherwise scan the game dir for DXSETUP.exe | ||
| var directXDir = File(appDirPath, "_CommonRedist/DirectX") | ||
| if (!directXDir.exists()) { | ||
| val dxSetupFile = FileUtils.findFilesRecursive( | ||
| rootPath = appDir.toPath(), | ||
| pattern = "DXSETUP.exe", | ||
| maxDepth = 5, | ||
| ).findFirst().orElse(null) | ||
|
|
||
| if (dxSetupFile != null) { | ||
| directXDir = dxSetupFile.parent.toFile() | ||
| } | ||
| } | ||
|
|
||
| if (directXDir.exists()) { | ||
| val imageFs = ImageFs.find(context) | ||
| val rootDir = imageFs.rootDir | ||
| val windowsDir = File(rootDir, ImageFs.WINEPREFIX + "/drive_c/windows") | ||
|
|
||
| // Do this once at app startup or before the loop | ||
| SevenZip.initSevenZipFromPlatformJAR() | ||
|
|
||
| directXDir.walkTopDown() | ||
| .filter { file -> | ||
| val name = file.name.lowercase() | ||
| val isAudioType = | ||
| name.contains("xaudio") || | ||
| name.contains("xact") || | ||
| name.contains("x3daudio") | ||
|
|
||
| isAudioType && file.extension.equals("cab", ignoreCase = true) | ||
| } | ||
| .forEach { cabFile -> | ||
| Timber.tag("replaceXAudioDllsFromRedistributable").d("Processing cabinet: ${cabFile.name}") | ||
|
|
||
| if (cabFile.name.lowercase().contains("x86")) { | ||
| val targetDir = File(windowsDir, "syswow64") | ||
| extractDllsFromCab(cabFile, targetDir) | ||
| } else if (cabFile.name.lowercase().contains("x64")) { | ||
| val targetDir = File(windowsDir, "system32") | ||
| extractDllsFromCab(cabFile, targetDir) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun extractDllsFromCab(cabFile: File, targetDir: File) { | ||
| val raf = RandomAccessFile(cabFile, "r") | ||
| val inStream = RandomAccessFileInStream(raf) | ||
| val archive: IInArchive = SevenZip.openInArchive(null, inStream) | ||
|
joshuatam marked this conversation as resolved.
|
||
|
|
||
| try { | ||
| val numberOfItems = archive.numberOfItems | ||
| for (i in 0 until numberOfItems) { | ||
| val name = archive.getProperty(i, net.sf.sevenzipjbinding.PropID.PATH) as String | ||
|
|
||
| if (name.endsWith(".dll", ignoreCase = true)) { | ||
| val outFile = File(targetDir, name.lowercase()) | ||
| if (outFile.exists()) { | ||
|
joshuatam marked this conversation as resolved.
|
||
| outFile.delete() | ||
| } | ||
|
|
||
| FileOutputStream(outFile).use { fos -> | ||
| archive.extract( | ||
| intArrayOf(i), false, | ||
| object : IArchiveExtractCallback { | ||
| override fun getStream(index: Int, extractAskMode: ExtractAskMode): ISequentialOutStream? { | ||
| if (extractAskMode != ExtractAskMode.EXTRACT) return null | ||
|
|
||
| return ISequentialOutStream { data -> | ||
| fos.write(data) | ||
| data.size // Return the number of bytes written | ||
| } | ||
| } | ||
|
|
||
| override fun prepareOperation(extractAskMode: ExtractAskMode) {} | ||
| override fun setOperationResult(extractOperationResult: ExtractOperationResult) {} | ||
| override fun setCompleted(completeValue: Long) {} | ||
| override fun setTotal(total: Long) {} | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| Timber.tag("replaceXAudioDllsFromRedistributable").d("Extracted: ${outFile.name}") | ||
| } | ||
| } | ||
| } finally { | ||
| archive.close() | ||
| inStream.close() | ||
| raf.close() | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add this as a preinstallstep like we do with the other common redists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the dlls have to be always replaced just before game start as changing proton will override the xaudio, which the preinstallstep may only run once.