Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ object GameFixesRegistry {
STEAM_Fix_752580,
STEAM_Fix_400,
STEAM_Fix_413150,
STEAM_Fix_3373660,
STEAM_Fix_1637320,
STEAM_Fix_2868840,
STEAM_Fix_3373660,
EPIC_Fix_b1b4e0b67a044575820cb5e63028dcae,
EPIC_Fix_dabb52e328834da7bbe99691e374cb84,
EPIC_Fix_59a0c86d02da42e8ba6444cb171e61bf,
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/app/gamenative/gamefixes/STEAM_2868840.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app.gamenative.gamefixes

import app.gamenative.data.GameSource

/**
* Slay the Spire 2 (Steam)
*/
val STEAM_Fix_2868840: KeyedGameFix = KeyedCompositeGameFix(
gameSource = GameSource.STEAM,
gameId = "2868840",
fixes = listOf(
LaunchArgFix("--rendering-driver vulkan"),
WineEnvVarFix(
mapOf(
"WINEDLLOVERRIDES" to "icu=d",
"DOTNET_EnableWriteXorExecute" to "0",
"DOTNET_GCHeapHardLimit" to "0x400000000",
),
),
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package app.gamenative.gamefixes

import android.content.Context
import app.gamenative.data.GameSource
import com.winlator.container.Container

/**
* Applies multiple fixes for the same game key.
* Every fix in [fixes] runs in order.
*/
class CompositeGameFix(
private val fixes: List<GameFix>,
) : GameFix {
override fun apply(
context: Context,
gameId: String,
installPath: String,
installPathWindows: String,
container: Container,
): Boolean {
var allSucceeded = true
for (fix in fixes) {
val succeeded = fix.apply(context, gameId, installPath, installPathWindows, container)
if (!succeeded) {
allSucceeded = false
}
}
Comment thread
unbelievableflavour marked this conversation as resolved.
return allSucceeded
}
}

class KeyedCompositeGameFix(
override val gameSource: GameSource,
override val gameId: String,
fixes: List<GameFix>,
) : KeyedGameFix, GameFix by CompositeGameFix(fixes)
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package app.gamenative.gamefixes

import androidx.test.core.app.ApplicationProvider
import app.gamenative.data.GameSource
import com.winlator.container.Container
import java.io.File
import java.nio.file.Files
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class KeyedCompositeGameFixTest {
private lateinit var baseDir: File

@Before
fun setUp() {
baseDir = Files.createTempDirectory("keyed-composite-fix-tests").toFile()
baseDir.deleteOnExit()
}

@Test
fun keyedComposite_apply_runsAllFixesInOrder_whenAllFixesSucceed() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
val applied = mutableListOf<String>()
val container = createContainer("c1")

val fix = KeyedCompositeGameFix(
gameSource = GameSource.STEAM,
gameId = "2868840",
fixes = listOf(
RecordingFix("first", true, applied),
RecordingFix("second", true, applied),
RecordingFix("third", true, applied),
),
)

val result = fix.apply(
context = context,
gameId = "2868840",
installPath = "",
installPathWindows = "",
container = container,
)

assertTrue(result)
assertEquals(listOf("first", "second", "third"), applied)
}

@Test
fun keyedComposite_apply_returnsFalseButStillRunsRemainingFixes_whenAnyFixFails() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
val applied = mutableListOf<String>()
val container = createContainer("c2")

val fix = KeyedCompositeGameFix(
gameSource = GameSource.STEAM,
gameId = "2868840",
fixes = listOf(
RecordingFix("first", true, applied),
RecordingFix("second", false, applied),
RecordingFix("third", true, applied),
),
)

val result = fix.apply(
context = context,
gameId = "2868840",
installPath = "",
installPathWindows = "",
container = container,
)

assertFalse(result)
assertEquals(listOf("first", "second", "third"), applied)
}

@Test
fun keyedComposite_keyedProperties_matchConstructorValues() {
val fix = KeyedCompositeGameFix(
gameSource = GameSource.GOG,
gameId = "1635627436",
fixes = emptyList(),
)

assertEquals(GameSource.GOG, fix.gameSource)
assertEquals("1635627436", fix.gameId)
}

private fun createContainer(id: String): Container {
val rootDir = File(baseDir, id).apply { mkdirs() }
return Container(id).apply {
this.rootDir = rootDir
this.envVars = "WINEESYNC=1"
}
}

private class RecordingFix(
private val label: String,
private val result: Boolean,
private val applied: MutableList<String>,
) : GameFix {
override fun apply(
context: android.content.Context,
gameId: String,
installPath: String,
installPathWindows: String,
container: Container,
): Boolean {
applied += label
return result
}
}
}
Loading