Skip to content

Commit ef752a9

Browse files
Added multi fix support for games + slay the spire 2 fix
1 parent 9a8401c commit ef752a9

4 files changed

Lines changed: 177 additions & 1 deletion

File tree

app/src/main/java/app/gamenative/gamefixes/GameFixesRegistry.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ object GameFixesRegistry {
3434
STEAM_Fix_752580,
3535
STEAM_Fix_400,
3636
STEAM_Fix_413150,
37-
STEAM_Fix_3373660,
3837
STEAM_Fix_1637320,
38+
STEAM_Fix_2868840,
39+
STEAM_Fix_3373660,
3940
EPIC_Fix_b1b4e0b67a044575820cb5e63028dcae,
4041
EPIC_Fix_dabb52e328834da7bbe99691e374cb84,
4142
EPIC_Fix_59a0c86d02da42e8ba6444cb171e61bf,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package app.gamenative.gamefixes
2+
3+
import app.gamenative.data.GameSource
4+
5+
/**
6+
* Slay the Spire 2 (Steam)
7+
*/
8+
val STEAM_Fix_2868840: KeyedGameFix = KeyedCompositeGameFix(
9+
gameSource = GameSource.STEAM,
10+
gameId = "2868840",
11+
fixes = listOf(
12+
LaunchArgFix("--rendering-driver vulkan"),
13+
WineEnvVarFix(
14+
mapOf(
15+
"WINEDLLOVERRIDES" to "icu=d",
16+
"DOTNET_EnableWriteXorExecute" to "0",
17+
"DOTNET_GCHeapHardLimit" to "0x400000000",
18+
),
19+
),
20+
),
21+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package app.gamenative.gamefixes
2+
3+
import android.content.Context
4+
import app.gamenative.data.GameSource
5+
import com.winlator.container.Container
6+
7+
/**
8+
* Applies multiple fixes for the same game key.
9+
* Every fix in [fixes] runs in order.
10+
*/
11+
class CompositeGameFix(
12+
private val fixes: List<GameFix>,
13+
) : GameFix {
14+
override fun apply(
15+
context: Context,
16+
gameId: String,
17+
installPath: String,
18+
installPathWindows: String,
19+
container: Container,
20+
): Boolean {
21+
var allSucceeded = true
22+
for (fix in fixes) {
23+
val succeeded = fix.apply(context, gameId, installPath, installPathWindows, container)
24+
if (!succeeded) {
25+
allSucceeded = false
26+
}
27+
}
28+
return allSucceeded
29+
}
30+
}
31+
32+
class KeyedCompositeGameFix(
33+
override val gameSource: GameSource,
34+
override val gameId: String,
35+
fixes: List<GameFix>,
36+
) : KeyedGameFix, GameFix by CompositeGameFix(fixes)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package app.gamenative.gamefixes
2+
3+
import androidx.test.core.app.ApplicationProvider
4+
import app.gamenative.data.GameSource
5+
import com.winlator.container.Container
6+
import java.io.File
7+
import java.nio.file.Files
8+
import org.junit.Assert.assertEquals
9+
import org.junit.Assert.assertFalse
10+
import org.junit.Assert.assertTrue
11+
import org.junit.Before
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
import org.robolectric.RobolectricTestRunner
15+
16+
@RunWith(RobolectricTestRunner::class)
17+
class KeyedCompositeGameFixTest {
18+
private lateinit var baseDir: File
19+
20+
@Before
21+
fun setUp() {
22+
baseDir = Files.createTempDirectory("keyed-composite-fix-tests").toFile()
23+
baseDir.deleteOnExit()
24+
}
25+
26+
@Test
27+
fun keyedComposite_apply_runsAllFixesInOrder_whenAllFixesSucceed() {
28+
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
29+
val applied = mutableListOf<String>()
30+
val container = createContainer("c1")
31+
32+
val fix = KeyedCompositeGameFix(
33+
gameSource = GameSource.STEAM,
34+
gameId = "2868840",
35+
fixes = listOf(
36+
RecordingFix("first", true, applied),
37+
RecordingFix("second", true, applied),
38+
RecordingFix("third", true, applied),
39+
),
40+
)
41+
42+
val result = fix.apply(
43+
context = context,
44+
gameId = "2868840",
45+
installPath = "",
46+
installPathWindows = "",
47+
container = container,
48+
)
49+
50+
assertTrue(result)
51+
assertEquals(listOf("first", "second", "third"), applied)
52+
}
53+
54+
@Test
55+
fun keyedComposite_apply_returnsFalseButStillRunsRemainingFixes_whenAnyFixFails() {
56+
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
57+
val applied = mutableListOf<String>()
58+
val container = createContainer("c2")
59+
60+
val fix = KeyedCompositeGameFix(
61+
gameSource = GameSource.STEAM,
62+
gameId = "2868840",
63+
fixes = listOf(
64+
RecordingFix("first", true, applied),
65+
RecordingFix("second", false, applied),
66+
RecordingFix("third", true, applied),
67+
),
68+
)
69+
70+
val result = fix.apply(
71+
context = context,
72+
gameId = "2868840",
73+
installPath = "",
74+
installPathWindows = "",
75+
container = container,
76+
)
77+
78+
assertFalse(result)
79+
assertEquals(listOf("first", "second", "third"), applied)
80+
}
81+
82+
@Test
83+
fun keyedComposite_keyedProperties_matchConstructorValues() {
84+
val fix = KeyedCompositeGameFix(
85+
gameSource = GameSource.GOG,
86+
gameId = "1635627436",
87+
fixes = emptyList(),
88+
)
89+
90+
assertEquals(GameSource.GOG, fix.gameSource)
91+
assertEquals("1635627436", fix.gameId)
92+
}
93+
94+
private fun createContainer(id: String): Container {
95+
val rootDir = File(baseDir, id).apply { mkdirs() }
96+
return Container(id).apply {
97+
this.rootDir = rootDir
98+
this.envVars = "WINEESYNC=1"
99+
}
100+
}
101+
102+
private class RecordingFix(
103+
private val label: String,
104+
private val result: Boolean,
105+
private val applied: MutableList<String>,
106+
) : GameFix {
107+
override fun apply(
108+
context: android.content.Context,
109+
gameId: String,
110+
installPath: String,
111+
installPathWindows: String,
112+
container: Container,
113+
): Boolean {
114+
applied += label
115+
return result
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)