|
|
|
@ -1,58 +1,45 @@
|
|
|
|
|
package moe.tqlwsl.aicemu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import com.google.gson.Gson
|
|
|
|
|
import com.google.gson.JsonSyntaxException
|
|
|
|
|
import com.google.gson.reflect.TypeToken
|
|
|
|
|
import java.io.BufferedReader
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
import java.io.InputStreamReader
|
|
|
|
|
|
|
|
|
|
class FelicaCard(IDm: String) {
|
|
|
|
|
class FelicaCard(context: Context, IDm: String) {
|
|
|
|
|
private var cardData = mutableMapOf<String, String>()
|
|
|
|
|
private val gson = Gson()
|
|
|
|
|
private val TAG = "AICEmu"
|
|
|
|
|
private val fileName = "felica_template.json"
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
// instance = this
|
|
|
|
|
// val fileName = "felica_template.json"
|
|
|
|
|
// Log.d("HCEFService", "Load Felica Data from assets/$fileName")
|
|
|
|
|
// val fileContent = readAssetFile(applicationContext, fileName)
|
|
|
|
|
// val mutableBlock = object : TypeToken<MutableMap<String, String>>() {}.type
|
|
|
|
|
// try {
|
|
|
|
|
// val jsonData = gson.fromJson<MutableMap<String, String>>(fileContent, mutableBlock)
|
|
|
|
|
// if (jsonData != null) {
|
|
|
|
|
// cardData = jsonData
|
|
|
|
|
// val block82 = ByteArray(16)
|
|
|
|
|
// val IDmBytes = IDm.decodeHex()
|
|
|
|
|
// System.arraycopy(IDmBytes, 0, block82, 0, 16)
|
|
|
|
|
// cardData["82"] = block82.toHexString()
|
|
|
|
|
// }
|
|
|
|
|
Log.d(TAG, "Load Felica Data from assets/$fileName")
|
|
|
|
|
val fileContent = readAssetFile(context, fileName)
|
|
|
|
|
val mutableBlock = object : TypeToken<MutableMap<String, String>>() {}.type
|
|
|
|
|
try {
|
|
|
|
|
val jsonData = gson.fromJson<MutableMap<String, String>>(fileContent, mutableBlock)
|
|
|
|
|
if (jsonData != null) {
|
|
|
|
|
cardData = jsonData
|
|
|
|
|
val block82 = ByteArray(16)
|
|
|
|
|
Log.d("HCEFService","Felica Card $IDm")
|
|
|
|
|
val IDmBytes = IDm.decodeHex()
|
|
|
|
|
System.arraycopy(IDmBytes, 0, block82, 0, 8)
|
|
|
|
|
cardData["82"] = block82.toHexString()
|
|
|
|
|
val block = ByteArray(16)
|
|
|
|
|
cardData["80"] = block.toHexString()
|
|
|
|
|
cardData["86"] = block.toHexString()
|
|
|
|
|
cardData["90"] = block.toHexString()
|
|
|
|
|
cardData["91"] = block.toHexString()
|
|
|
|
|
cardData["00"] = block.toHexString()
|
|
|
|
|
Log.d("HCEFService","Felica Card Data")
|
|
|
|
|
Log.d("HCEFService","=".repeat(53))
|
|
|
|
|
}
|
|
|
|
|
Log.d(TAG,"[Felica Card Data]")
|
|
|
|
|
Log.d(TAG, "=".repeat(53))
|
|
|
|
|
for (en in cardData.entries) {
|
|
|
|
|
Log.d("HCEFService","[${en.key}]: ${en.value}")
|
|
|
|
|
Log.d(TAG,"[${en.key}]: ${en.value}")
|
|
|
|
|
}
|
|
|
|
|
Log.d(TAG, "=".repeat(53))
|
|
|
|
|
} catch (e: IOException) {
|
|
|
|
|
Log.e(TAG, "assets/$fileName Read Error")
|
|
|
|
|
} catch (e: JsonSyntaxException) {
|
|
|
|
|
Log.e(TAG, "assets/$fileName Syntax Error")
|
|
|
|
|
}
|
|
|
|
|
Log.d("HCEFService","=".repeat(53))
|
|
|
|
|
// } catch (e: IOException) {
|
|
|
|
|
// Log.e("Error", "File Read Error")
|
|
|
|
|
// } catch (e: JsonSyntaxException) {
|
|
|
|
|
// Log.e("Error", "File Syntax Error")
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// utils
|
|
|
|
@ -76,33 +63,23 @@ class FelicaCard(IDm: String) {
|
|
|
|
|
System.arraycopy(blockData, 0, resp, 0, blockData.size)
|
|
|
|
|
return resp
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.e("Error", "Invalid Block")
|
|
|
|
|
Log.e(TAG, "Invalid Block $idStr")
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun writeBlock(id: Byte, data: ByteArray) { }
|
|
|
|
|
|
|
|
|
|
fun readAssetFile(context: Context, fileName: String): String {
|
|
|
|
|
private fun readAssetFile(context: Context, fileName: String): String {
|
|
|
|
|
val stringBuilder = StringBuilder()
|
|
|
|
|
|
|
|
|
|
// 获取AssetManager
|
|
|
|
|
val assetManager = context.assets
|
|
|
|
|
|
|
|
|
|
// 通过AssetManager打开文件
|
|
|
|
|
val inputStream = assetManager.open(fileName)
|
|
|
|
|
val bufferedReader = BufferedReader(InputStreamReader(inputStream))
|
|
|
|
|
|
|
|
|
|
// 逐行读取文件内容并将其添加到StringBuilder中
|
|
|
|
|
bufferedReader.forEachLine { line ->
|
|
|
|
|
stringBuilder.append(line)
|
|
|
|
|
stringBuilder.append("\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 关闭流资源
|
|
|
|
|
bufferedReader.close()
|
|
|
|
|
inputStream.close()
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString()
|
|
|
|
|
}
|
|
|
|
|
}
|