Skip to content

Commit 2b91d7e

Browse files
committed
Add AkinatorHelper
1 parent 55dab69 commit 2b91d7e

File tree

9 files changed

+166
-6
lines changed

9 files changed

+166
-6
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "me.kyuubiran.akinatorhelper"
1111
minSdk 21
1212
targetSdk 32
13-
versionCode 3
14-
versionName "1.2"
13+
versionCode 4
14+
versionName "1.4"
1515
}
1616

1717
buildTypes {

app/src/main/java/me/kyuubiran/akinatorhelper/hook/GameResultHook.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,14 @@ object GameResultHook : BaseHook() {
1717
it.result = true
1818
}
1919
// endregion
20+
21+
// region <isItemBought>
22+
findMethod("com.digidust.elokence.akinator.factories.AkPlayerBelongingsFactory") {
23+
name == "isItemBought"
24+
}.hookBefore {
25+
if (!ConfigManager.allItemBought) return@hookBefore
26+
Log.i("Hooked ${it.method.name}")
27+
it.result = true
28+
}
2029
}
2130
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package me.kyuubiran.akinatorhelper.util
2+
3+
import com.github.kyuubiran.ezxhelper.utils.findMethod
4+
5+
object AkinatorHelper {
6+
object Methods {
7+
private val mGetAkGameFactoryInstance by lazy {
8+
findMethod("com.digidust.elokence.akinator.factories.AkGameFactory") {
9+
name == "sharedInstance"
10+
}
11+
}
12+
13+
private val akGameFactoryInstance: Any by lazy {
14+
mGetAkGameFactoryInstance(null)!!
15+
}
16+
17+
private val mIsGameUnlocked by lazy {
18+
findMethod("com.digidust.elokence.akinator.factories.AkGameFactory") {
19+
name == "isUnlocked"
20+
}
21+
}
22+
23+
fun isGameUnlocked(): Boolean {
24+
return mIsGameUnlocked.invoke(akGameFactoryInstance) as Boolean
25+
}
26+
27+
private val mSetGameLocked by lazy {
28+
findMethod("com.digidust.elokence.akinator.factories.AkGameFactory") {
29+
name == "lockGame"
30+
}
31+
}
32+
33+
fun setGameLocked() {
34+
mSetGameLocked.invoke(akGameFactoryInstance)
35+
}
36+
37+
38+
private val mSetGameUnlocked by lazy {
39+
findMethod("com.digidust.elokence.akinator.factories.AkGameFactory") {
40+
name == "unlockGame"
41+
}
42+
}
43+
44+
fun setGameUnlocked() {
45+
mSetGameUnlocked.invoke(akGameFactoryInstance)
46+
}
47+
48+
}
49+
50+
var isGameUnlocked: Boolean
51+
set(value) {
52+
if (value) Methods.setGameUnlocked()
53+
else Methods.setGameLocked()
54+
}
55+
get() = Methods.isGameUnlocked()
56+
57+
}

app/src/main/java/me/kyuubiran/akinatorhelper/util/ConfigManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ object ConfigManager {
1515
var alwaysWinFirstTry: Boolean
1616
set(value) = sPrefs.edit().putBoolean("always_first_try", value).apply()
1717
get() = sPrefs.getBoolean("always_first_try", false)
18+
19+
var allItemBought: Boolean
20+
set(value) = sPrefs.edit().putBoolean("all_item_bought", value).apply()
21+
get() = sPrefs.getBoolean("all_item_bought", false)
22+
1823
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package me.kyuubiran.akinatorhelper.util
2+
3+
import android.content.Intent
4+
import android.net.Uri
5+
import com.github.kyuubiran.ezxhelper.init.InitFields.appContext
6+
7+
fun openUrl(url: String) {
8+
appContext.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
9+
}

app/src/main/java/me/kyuubiran/akinatorhelper/view/SettingDialog.kt

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import android.os.Bundle
88
import android.preference.Preference
99
import android.preference.PreferenceFragment
1010
import com.github.kyuubiran.ezxhelper.init.EzXHelperInit
11+
import com.github.kyuubiran.ezxhelper.utils.Log
12+
import me.kyuubiran.akinatorhelper.BuildConfig
1113
import me.kyuubiran.akinatorhelper.R
14+
import me.kyuubiran.akinatorhelper.util.AkinatorHelper
1215
import me.kyuubiran.akinatorhelper.util.ConfigManager
13-
16+
import me.kyuubiran.akinatorhelper.util.openUrl
1417

1518
class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {
1619

@@ -36,6 +39,14 @@ class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {
3639

3740
findPreference("unlock_pro").onPreferenceChangeListener = this
3841
findPreference("always_first_try").onPreferenceChangeListener = this
42+
findPreference("all_item_bought").onPreferenceChangeListener = this
43+
44+
findPreference("unlock_game").onPreferenceClickListener = this
45+
findPreference("relock_game").onPreferenceClickListener = this
46+
findPreference("goto_github").onPreferenceClickListener = this
47+
48+
findPreference("module_version").summary =
49+
"${BuildConfig.VERSION_NAME}(${BuildConfig.VERSION_CODE})"
3950
}
4051

4152
override fun onPreferenceChange(p: Preference?, v: Any?): Boolean {
@@ -50,11 +61,29 @@ class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {
5061
ConfigManager.alwaysWinFirstTry = it
5162
}
5263
}
64+
"all_item_bought" -> {
65+
(v as? Boolean)?.let {
66+
ConfigManager.allItemBought = it
67+
}
68+
}
5369
}
5470
return true
5571
}
5672

57-
override fun onPreferenceClick(p0: Preference?): Boolean {
73+
override fun onPreferenceClick(p: Preference?): Boolean {
74+
when (p?.key) {
75+
"unlock_game" -> {
76+
AkinatorHelper.isGameUnlocked = true
77+
Log.toast(getString(R.string.unlock_game_success))
78+
}
79+
"relock_game" -> {
80+
AkinatorHelper.isGameUnlocked = false
81+
Log.toast(getString(R.string.relock_game_success))
82+
}
83+
"goto_github" -> {
84+
openUrl("https://github.com/KyuubiRan/AkinatorHelper")
85+
}
86+
}
5887
return true
5988
}
6089
}

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22
<resources>
33
<string name="module_load">模块加载成功!</string>
44
<string name="base_funtion_title">基础功能</string>
5-
<string name="unlock_pro_title">解锁付费版</string>
5+
<string name="unlock_pro_title">解锁内购(钩子模式)</string>
66
<string name="game_hack_title">游戏修改</string>
77
<string name="always_first_try_title">永远是第一次尝试</string>
8+
<string name="unlock_relock_game_title">解锁/锁定内购</string>
9+
<string name="unlock_game_title">解锁内购</string>
10+
<string name="relock_game_title">锁定内购</string>
11+
<string name="unlock_game_success">成功解锁内购!</string>
12+
<string name="relock_game_success">成功锁定内购!</string>
13+
<string name="other_title">其他</string>
14+
<string name="goto_github_title">在Github上浏览本项目</string>
15+
<string name="goto_github_summary">点个Star吧!</string>
16+
<string name="module_version_title">模块版本</string>
17+
<string name="author_title">模块作者</string>
18+
<string name="all_item_bought_title">解锁商店所有物品</string>
819
</resources>

app/src/main/res/values/strings.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
<string name="app_name" translatable="false">Akinator Helper</string>
33
<string name="module_load">Module load success!</string>
44
<string name="base_funtion_title">Base funtions</string>
5-
<string name="unlock_pro_title">Unlock pro</string>
5+
<string name="unlock_pro_title">Unlock pro (Hook)</string>
66
<string name="game_hack_title">Game hack</string>
77
<string name="always_first_try_title">Always first try</string>
8+
<string name="unlock_relock_game_title">Unlock/Relock pro</string>
9+
<string name="unlock_game_title">Unlock the game</string>
10+
<string name="relock_game_title">Relock the game</string>
11+
<string name="unlock_game_success">Unlock game success!</string>
12+
<string name="relock_game_success">Relock game success</string>
13+
<string name="other_title">Other</string>
14+
<string name="goto_github_title">Browse this project on Github</string>
15+
<string name="goto_github_summary">One star plz!</string>
16+
<string name="module_version_title">Module version</string>
17+
<string name="author_title">Module author</string>
18+
<string name="author_summary" translatable="false">KyuubiRan</string>
19+
<string name="all_item_bought_title">Unlock all items in the shop</string>
820
</resources>

app/src/main/res/xml/setting_dialog_prefs.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,35 @@
1212
android:key="always_first_try"
1313
android:title="@string/always_first_try_title" />
1414

15+
<SwitchPreference
16+
android:key="all_item_bought"
17+
android:title="@string/all_item_bought_title" />
18+
</PreferenceCategory>
19+
20+
<PreferenceCategory android:title="@string/unlock_relock_game_title">
21+
<Preference
22+
android:key="unlock_game"
23+
android:title="@string/unlock_game_title" />
24+
25+
<Preference
26+
android:key="relock_game"
27+
android:title="@string/relock_game_title" />
1528
</PreferenceCategory>
1629

30+
<PreferenceCategory android:title="@string/other_title">
31+
<Preference
32+
android:key="author"
33+
android:title="@string/author_title"
34+
android:summary="@string/author_summary"/>
35+
36+
<Preference
37+
android:key="module_version"
38+
android:title="@string/module_version_title" />
39+
40+
<Preference
41+
android:key="goto_github"
42+
android:title="@string/goto_github_title"
43+
android:summary="@string/goto_github_summary"/>
44+
</PreferenceCategory>
1745

1846
</PreferenceScreen>

0 commit comments

Comments
 (0)