fix(mapper): score update mapper

This commit is contained in:
rhunk
2024-04-02 23:36:24 +02:00
parent b5dda0353a
commit 0f041ec107
2 changed files with 16 additions and 12 deletions

View File

@ -5,7 +5,8 @@ import me.rhunk.snapenhance.core.features.FeatureLoadParams
import me.rhunk.snapenhance.core.util.hook.HookStage
import me.rhunk.snapenhance.core.util.hook.hookConstructor
import me.rhunk.snapenhance.mapper.impl.ScoreUpdateMapper
import java.lang.reflect.Constructor
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.minutes
class NoFriendScoreDelay : Feature("NoFriendScoreDelay", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
override fun onActivityCreate() {
@ -13,9 +14,12 @@ class NoFriendScoreDelay : Feature("NoFriendScoreDelay", loadParams = FeatureLoa
context.mappings.useMapper(ScoreUpdateMapper::class) {
classReference.get()?.hookConstructor(HookStage.BEFORE) { param ->
val constructor = param.method() as Constructor<*>
if (constructor.parameterTypes.size < 3 || constructor.parameterTypes[3] != java.util.Collection::class.java) return@hookConstructor
param.setArg(2, 0L)
param.args().indexOfFirst {
val longValue = it.toString().toLongOrNull() ?: return@indexOfFirst false
longValue > 30.minutes.inWholeMilliseconds && longValue < 10.days.inWholeMilliseconds
}.takeIf { it != -1 }?.let { index ->
param.setArg(index, 0)
}
}
}
}

View File

@ -10,15 +10,15 @@ class ScoreUpdateMapper : AbstractClassMapper("ScoreUpdate") {
init {
mapper {
for (classDef in classes) {
classDef.methods.firstOrNull {
it.name == "<init>" &&
it.parameterTypes.size > 4 &&
it.parameterTypes[1] == "Ljava/lang/Long;" &&
it.parameterTypes[3] == "Ljava/util/Collection;"
} ?: continue
if (classDef.methods.firstOrNull {
val toStringMethod = classDef.methods.firstOrNull {
it.name == "toString"
}?.implementation?.findConstString("Friend.sq:selectFriendUserScoresNeedToUpdate") != true) continue
} ?: continue
if (classDef.methods.none {
it.name == "<init>" &&
it.parameterTypes.size > 4
}) continue
if (toStringMethod.implementation?.findConstString("selectFriendUserScoresNeedToUpdate", contains = true) != true) continue
classReference.set(classDef.getClassName())
return@mapper