Skip to content

Commit f1fc3b1

Browse files
committed
Add more hooks
1 parent dcaee88 commit f1fc3b1

File tree

6 files changed

+146
-23
lines changed

6 files changed

+146
-23
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 5
14-
versionName "1.5"
13+
versionCode 6
14+
versionName "1.6"
1515
}
1616

1717
buildTypes {

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

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,79 @@ import com.github.kyuubiran.ezxhelper.utils.findMethod
44
import com.github.kyuubiran.ezxhelper.utils.loadClass
55

66
object AkinatorHelper {
7-
object Methods {
8-
private val C_AK_GAME_FACTORY by lazy {
9-
loadClass("com.digidust.elokence.akinator.factories.AkGameFactory")
7+
object AkPlayerBelongingsFactory {
8+
private val C_AK_PLAYER_BELONGINGS_FACTORY by lazy {
9+
loadClass("com.digidust.elokence.akinator.factories.AkPlayerBelongingsFactory")
1010
}
1111

12-
private val mGetAkGameFactoryInstance by lazy {
13-
findMethod(C_AK_GAME_FACTORY) {
12+
private val sInstance: Any by lazy {
13+
findMethod(C_AK_PLAYER_BELONGINGS_FACTORY) {
14+
name == "sharedInstance"
15+
}.invoke(null)!!
16+
}
17+
18+
private val mSetGenizBalance by lazy {
19+
findMethod(C_AK_PLAYER_BELONGINGS_FACTORY) {
20+
name == "setGenizBalance"
21+
}
22+
}
23+
24+
private val mSetGenizBalanceAccount by lazy {
25+
findMethod(C_AK_PLAYER_BELONGINGS_FACTORY) {
26+
name == "setGenizBalanceAccount"
27+
}
28+
}
29+
30+
fun setGenizBalance(balance: Int) {
31+
mSetGenizBalance.invoke(sInstance, balance)
32+
}
33+
34+
fun setGenizBalanceAccount(balance: Int) {
35+
mSetGenizBalanceAccount.invoke(sInstance, balance)
36+
}
37+
38+
private val mAddXp by lazy {
39+
findMethod(C_AK_PLAYER_BELONGINGS_FACTORY) {
40+
name == "addXp"
41+
}
42+
}
43+
44+
fun addXp(xp: Int) {
45+
mAddXp.invoke(sInstance, xp)
46+
}
47+
}
48+
49+
object AKConfigFactory {
50+
private val C_AK_CONFIG_FACTORY by lazy {
51+
loadClass("com.digidust.elokence.akinator.factories.AkConfigFactory")
52+
}
53+
54+
private val sInstance: Any by lazy {
55+
findMethod(C_AK_CONFIG_FACTORY) {
1456
name == "sharedInstance"
57+
}.invoke(null)!!
58+
}
59+
60+
private val mIsUserConnected by lazy {
61+
findMethod(C_AK_CONFIG_FACTORY) {
62+
name == "isUserConnected"
1563
}
1664
}
1765

18-
private val akGameFactoryInstance: Any by lazy {
19-
mGetAkGameFactoryInstance(null)!!
66+
fun isUserConnected(): Boolean {
67+
return mIsUserConnected.invoke(sInstance) as Boolean
68+
}
69+
}
70+
71+
object AKGameFactory {
72+
private val C_AK_GAME_FACTORY by lazy {
73+
loadClass("com.digidust.elokence.akinator.factories.AkGameFactory")
74+
}
75+
76+
private val sInstance: Any by lazy {
77+
findMethod(C_AK_GAME_FACTORY) {
78+
name == "sharedInstance"
79+
}.invoke(null)!!
2080
}
2181

2282
private val mIsGameUnlocked by lazy {
@@ -26,7 +86,7 @@ object AkinatorHelper {
2686
}
2787

2888
fun isGameUnlocked(): Boolean {
29-
return mIsGameUnlocked.invoke(akGameFactoryInstance) as Boolean
89+
return mIsGameUnlocked.invoke(sInstance) as Boolean
3090
}
3191

3292
private val mSetGameLocked by lazy {
@@ -36,7 +96,7 @@ object AkinatorHelper {
3696
}
3797

3898
fun setGameLocked() {
39-
mSetGameLocked.invoke(akGameFactoryInstance)
99+
mSetGameLocked.invoke(sInstance)
40100
}
41101

42102

@@ -47,7 +107,7 @@ object AkinatorHelper {
47107
}
48108

49109
fun setGameUnlocked() {
50-
mSetGameUnlocked.invoke(akGameFactoryInstance)
110+
mSetGameUnlocked.invoke(sInstance)
51111
}
52112

53113
private val mAddOneWonGame by lazy {
@@ -57,7 +117,7 @@ object AkinatorHelper {
57117
}
58118

59119
fun addOneWonGame() {
60-
mAddOneWonGame.invoke(akGameFactoryInstance)
120+
mAddOneWonGame.invoke(sInstance)
61121
}
62122

63123
private val mAddOneLostGame by lazy {
@@ -67,16 +127,15 @@ object AkinatorHelper {
67127
}
68128

69129
fun addOneLostGame() {
70-
mAddOneLostGame.invoke(akGameFactoryInstance)
130+
mAddOneLostGame.invoke(sInstance)
71131
}
72-
73132
}
74133

75134
var isGameUnlocked: Boolean
76135
set(value) {
77-
if (value) Methods.setGameUnlocked()
78-
else Methods.setGameLocked()
136+
if (value) AKGameFactory.setGameUnlocked()
137+
else AKGameFactory.setGameLocked()
79138
}
80-
get() = Methods.isGameUnlocked()
139+
get() = AKGameFactory.isGameUnlocked()
81140

82141
}

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

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {
7474
findPreference("relock_game").onPreferenceClickListener = this
7575
findPreference("add_win_times").onPreferenceClickListener = this
7676
findPreference("add_lose_times").onPreferenceClickListener = this
77+
findPreference("set_gz").onPreferenceClickListener = this
78+
findPreference("add_xp").onPreferenceClickListener = this
7779
findPreference("goto_github").onPreferenceClickListener = this
7880

7981
findPreference("module_version").summary =
@@ -124,7 +126,7 @@ class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {
124126
return@showEditDialog
125127
}
126128
repeat(num) {
127-
AkinatorHelper.Methods.addOneWonGame()
129+
AkinatorHelper.AKGameFactory.addOneWonGame()
128130
}
129131
Log.toast(getString(R.string.success_increate_win_times, num))
130132
}
@@ -144,13 +146,53 @@ class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {
144146
return@showEditDialog
145147
}
146148
repeat(num) {
147-
AkinatorHelper.Methods.addOneWonGame()
149+
AkinatorHelper.AKGameFactory.addOneWonGame()
148150
}
149151
Log.toast(getString(R.string.success_increate_lose_times, num))
150152
}
151153
}
152154
)
153155
}
156+
"set_gz" -> {
157+
showEditDialog(
158+
getString(R.string.set_gz_title),
159+
defText = "100000",
160+
inputType = InputType.TYPE_CLASS_NUMBER,
161+
onConfirm = { num ->
162+
num.toIntOrNull().let {
163+
if (it == null) {
164+
Log.toast(getString(R.string.invalid_num, num))
165+
} else {
166+
if (AkinatorHelper.AKConfigFactory.isUserConnected())
167+
AkinatorHelper.AkPlayerBelongingsFactory.setGenizBalanceAccount(
168+
it
169+
)
170+
else
171+
AkinatorHelper.AkPlayerBelongingsFactory.setGenizBalance(it)
172+
Log.toast(getString(R.string.success_set_gz, it))
173+
}
174+
}
175+
}
176+
)
177+
}
178+
"add_xp" -> {
179+
showEditDialog(
180+
getString(R.string.add_xp_title),
181+
getString(R.string.offline_only),
182+
defText = "0",
183+
inputType = InputType.TYPE_CLASS_NUMBER,
184+
onConfirm = { num ->
185+
num.toIntOrNull().let {
186+
if (it == null) {
187+
Log.toast(getString(R.string.invalid_num, num))
188+
} else {
189+
AkinatorHelper.AkPlayerBelongingsFactory.addXp(it)
190+
Log.toast(getString(R.string.success_add_xp, it))
191+
}
192+
}
193+
}
194+
)
195+
}
154196
"goto_github" -> {
155197
this.activity.openUrl("https://github.com/KyuubiRan/AkinatorHelper")
156198
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121
<string name="increase_win_times_title">增加胜利次数</string>
2222
<string name="increase_lose_times_title">增加失败次数</string>
2323
<string name="times_to_add">增加的次数</string>
24-
<string name="local_hack_title">本地修改</string>
24+
<string name="pref_hack">本地修改</string>
2525
<string name="success_increate_win_times">已增加%d次胜利次数</string>
2626
<string name="success_increate_lose_times">已增加%d次失败次数</string>
2727
<string name="num_must_be_greater_than_zero">数字必须大于0!</string>
2828
<string name="save">保存</string>
2929
<string name="close">关闭</string>
30+
<string name="set_gz_title">设置Gz</string>
31+
<string name="offline_only">仅离线模式</string>
32+
<string name="add_xp_title">增加Xp</string>
33+
<string name="success_set_gz">成功设置Gz: %d</string>
34+
<string name="invalid_num">%s 不是一个有效的数字!</string>
35+
<string name="success_add_xp">成功增加Xp: %d</string>
36+
<string name="data_will_not_be_sync">仅修改本地值,数据不会同步到服务器。</string>
3037
</resources>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@
2222
<string name="increase_win_times_title">Increase win times</string>
2323
<string name="increase_lose_times_title">Increase lose times</string>
2424
<string name="times_to_add">Times to add</string>
25-
<string name="local_hack_title">Local hack</string>
25+
<string name="pref_hack">Preferences hack</string>
2626
<string name="success_increate_win_times">Increase %d win times</string>
2727
<string name="success_increate_lose_times">Increase %d lose times</string>
2828
<string name="num_must_be_greater_than_zero">The number must be greater than zero!</string>
2929
<string name="save">Save</string>
3030
<string name="close">Close</string>
31+
<string name="set_gz_title">Set gz</string>
32+
<string name="offline_only">Offline only</string>
33+
<string name="add_xp_title">Add xp</string>
34+
<string name="success_set_gz">Success set gz: %d</string>
35+
<string name="invalid_num">%s is not an valid number!</string>
36+
<string name="success_add_xp">Success add xp: %d</string>
37+
<string name="data_will_not_be_sync">Only modified local data and will not be sync to the server.</string>
3138
</resources>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
android:title="@string/all_item_bought_title" />
1818
</PreferenceCategory>
1919

20-
<PreferenceCategory android:title="@string/local_hack_title">
20+
<PreferenceCategory android:title="@string/pref_hack">
2121
<Preference
2222
android:key="add_win_times"
2323
android:title="@string/increase_win_times_title" />
@@ -32,6 +32,14 @@
3232
<Preference
3333
android:key="relock_game"
3434
android:title="@string/relock_game_title" />
35+
36+
<Preference
37+
android:key="set_gz"
38+
android:title="@string/set_gz_title" />
39+
40+
<Preference
41+
android:key="add_xp"
42+
android:title="@string/add_xp_title" />
3543
</PreferenceCategory>
3644

3745
<PreferenceCategory android:title="@string/other_title">

0 commit comments

Comments
 (0)