Initial commit

This commit is contained in:
筱傑 2021-10-17 23:43:52 +08:00
commit 3ce74af20d
61 changed files with 1841 additions and 0 deletions

121
.gitignore vendored Normal file
View File

@ -0,0 +1,121 @@
# User-specific stuff
.idea/
*.iml
*.ipr
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Cache of project
.gradletasknamecache
**/build/
# Common working directory
run/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
# Local Test Launch point
src/test/kotlin/RunTerminal.kt

15
build.gradle.kts Normal file
View File

@ -0,0 +1,15 @@
plugins {
val kotlinVersion = "1.5.10"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
id("net.mamoe.mirai-console") version "2.7.0"
}
group = "me.jie65535"
version = "0.1.0"
repositories {
maven("https://maven.aliyun.com/repository/public")
mavenCentral()
}

1
gradle.properties Normal file
View File

@ -0,0 +1 @@
kotlin.code.style=official

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

185
gradlew vendored Normal file
View File

@ -0,0 +1,185 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MSYS* | MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

89
gradlew.bat vendored Normal file
View File

@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

1
settings.gradle.kts Normal file
View File

@ -0,0 +1 @@
rootProject.name = "mirai-console-jcf-plugin"

View File

@ -0,0 +1,225 @@
package me.jie65535.jcf
import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import io.ktor.client.features.*
import io.ktor.client.request.*
import io.ktor.http.*
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import me.jie65535.jcf.model.addon.*
import me.jie65535.jcf.model.addon.file.*
import me.jie65535.jcf.model.addon.request.*
import me.jie65535.jcf.model.category.*
import me.jie65535.jcf.model.fingerprint.*
import me.jie65535.jcf.model.fingerprint.request.*
import me.jie65535.jcf.model.game.*
import me.jie65535.jcf.model.minecraft.*
import me.jie65535.jcf.model.minecraft.modloader.*
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@OptIn(ExperimentalSerializationApi::class)
class CurseClient {
private val json = Json {
isLenient = true
ignoreUnknownKeys = true
serializersModule
}
private val http = HttpClient(OkHttp) {
install(HttpTimeout) {
this.requestTimeoutMillis = 30_0000
this.connectTimeoutMillis = 30_0000
this.socketTimeoutMillis = 30_0000
}
defaultRequest {
url.protocol = URLProtocol.HTTPS
url.host = "addons-ecs.forgesvc.net"
header("accept", "*/*")
}
}
suspend fun getGames(supportsAddons: Boolean = false): List<Game> {
return json.decodeFromString(
http.get("api/v2/game") {
parameter("supportsAddons", supportsAddons.toString())
}
)
}
suspend fun getGame(gameId: Int): Game {
return json.decodeFromString(http.get("api/v2/game/$gameId"))
}
suspend fun getGameDatabaseTimestamp(): Date {
return json.decodeFromString(http.get("api/v2/game/timestamp"))
}
suspend fun getAddon(projectId: Int): Addon {
return json.decodeFromString(http.get("api/v2/addon/$projectId"))
}
suspend fun getAddons(projectIds: Collection<Int>): List<Addon> {
return json.decodeFromString(
http.post("api/v2/addon") {
contentType(ContentType.Application.Json)
body = projectIds
}
)
}
suspend fun getAddons(vararg projectIds: Int): List<Addon> = getAddons(projectIds.toList())
suspend fun getAddonDescription(projectId: Int): String {
return json.decodeFromString(http.get("api/v2/addon/$projectId/description"))
}
suspend fun getAddonFiles(projectId: Int): List<AddonFile> {
return json.decodeFromString(http.get("api/v2/addon/$projectId/files"))
}
suspend fun getAddonFiles(keys: Collection<Int>): Map<Int, List<AddonFile>> {
return json.decodeFromString(
http.post("api/v2/addon/files") {
contentType(ContentType.Application.Json)
body = keys
}
)
}
suspend fun getAddonFiles(vararg keys: Int): Map<Int, List<AddonFile>> = getAddonFiles(keys.toList())
suspend fun getAddonFileDownloadUrl(projectId: Int, fileId: Int): String {
return json.decodeFromString(http.get("api/v2/addon/$projectId/file/$fileId/download-url"))
}
suspend fun getAddonFile(projectId: Int, fileId: Int): AddonFile {
return json.decodeFromString(http.get("api/v2/addon/$projectId/file/$fileId"))
}
suspend fun searchAddons(
gameId: Int,
sectionId: Int = -1,
categoryId: Int = -1,
sort: AddonSortMethod = AddonSortMethod.FEATURED,
sortDescending: Boolean = true,
gameVersion: String? = null,
index: Int = 0,
pageSize: Int = 1000,
searchFilter: String? = null
): List<Addon> {
return json.decodeFromString(
http.get("api/v2/addon/search") {
parameter("gameId", gameId)
parameter("sectionId", sectionId)
parameter("categoryId", categoryId)
parameter("gameVersion", gameVersion)
parameter("index", index)
parameter("pageSize", pageSize)
parameter("searchFilter", searchFilter)
parameter("sort", sort)
parameter("sortDescending", sortDescending)
}
)
}
suspend fun getFeaturedAddons(
gameId: Int,
featuredCount: Int = 6,
popularCount: Int = 14,
updatedCount: Int = 14,
excludedAddons: Collection<Int> = listOf()
): Map<FeaturedAddonType, List<Addon>> {
return json.decodeFromString(
http.post("api/v2/addon/featured") {
contentType(ContentType.Application.Json)
body = FeaturedAddonsRequest(gameId, featuredCount, popularCount, updatedCount, excludedAddons)
}
)
}
suspend fun getFeaturedAddons(
gameId: Int,
featuredCount: Int = 6,
popularCount: Int = 14,
updatedCount: Int = 14,
vararg excludedAddons: Int
): Map<FeaturedAddonType, List<Addon>> = getFeaturedAddons(gameId, featuredCount, popularCount, updatedCount, excludedAddons.toList())
suspend fun getCategory(categoryId: Int): Category {
return json.decodeFromString(http.get("api/v2/category/$categoryId"))
}
suspend fun getCategory(slug: String): List<Category> {
return json.decodeFromString(
http.get("api/v2/category") {
parameter("slug", slug)
}
)
}
suspend fun getCategorySection(sectionId: Int): List<Category> {
return json.decodeFromString(http.get("api/v2/category/section/$sectionId"))
}
suspend fun getCategories(): List<Category> {
return json.decodeFromString(http.get("api/v2/category"))
}
suspend fun getCategoryDatabaseTimestamp(): Date {
return json.decodeFromString(http.get("api/v2/category/timestamp"))
}
suspend fun getFingerprintMatches(fingerprints: Collection<Long>): FingerprintMatchResult {
return json.decodeFromString(
http.post("api/v2/fingerprint") {
contentType(ContentType.Application.Json)
body = fingerprints
}
)
}
suspend fun getFingerprintMatches(vararg fingerprints: Long): FingerprintMatchResult = getFingerprintMatches(fingerprints.toList())
suspend fun getFuzzyFingerprintMatches(gameId: Int, fingerprints: List<FolderFingerprint>): List<FuzzyFingerprintMatch> {
return json.decodeFromString(
http.post("api/v2/fingerprint/fuzzy") {
contentType(ContentType.Application.Json)
body = FuzzyMatchesRequest(gameId, fingerprints)
}
)
}
suspend fun getModloader(key: String): ModloaderVersion {
return json.decodeFromString(http.get("api/v2/minecraft/modloader/$key"))
}
suspend fun getModloaders(): List<ModloaderIndex> {
return json.decodeFromString(http.get("api/v2/minecraft/modloader"))
}
suspend fun getModloaders(gameVersion: String): List<ModloaderIndex> {
return json.decodeFromString(
http.get("api/v2/minecraft/modloader") {
parameter("version", gameVersion)
}
)
}
suspend fun getModloadersDatabaseTimestamp(): Date {
return json.decodeFromString(http.get("api/v2/minecraft/modloader/timestamp"))
}
suspend fun getMinecraftVersions(): List<MinecraftVersion> {
return json.decodeFromString(http.get("api/v2/minecraft/version"))
}
suspend fun getMinecraftVersion(gameVersion: String): MinecraftVersion {
return json.decodeFromString(http.get("api/v2/minecraft/version/$gameVersion"))
}
suspend fun getMinecraftVersionsDatabaseTimestamp(): Date {
return json.decodeFromString(http.get("api/v2/minecraft/version/timestamp"))
}
}

View File

@ -0,0 +1,27 @@
package me.jie65535.jcf
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregister
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
import net.mamoe.mirai.utils.info
object JCurseforge : KotlinPlugin(
JvmPluginDescription(
id = "me.jie65535.jcf",
name = "J Curseforge Util",
version = "0.1.0",
) {
author("jie65535")
info("""Curseforge Util""")
}
) {
override fun onEnable() {
logger.info { "Plugin loaded" }
JcfCommand.register()
}
override fun onDisable() {
JcfCommand.unregister()
}
}

View File

@ -0,0 +1,18 @@
package me.jie65535.jcf
import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.CompositeCommand
object JcfCommand : CompositeCommand(
JCurseforge, "jcf",
description = "Curseforge Util"
) {
private val curse = CurseClient()
@SubCommand
@Description("帮助")
suspend fun CommandSender.help() {
sendMessage(usage)
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.addon.file.AddonFile
import me.jie65535.jcf.model.addon.file.AddonFileLatestForGameVersion
import me.jie65535.jcf.model.category.CategorySection
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@Serializable
data class Addon(
val id: Int,
val name: String,
val authors: List<AddonAuthor>,
val attachments: List<AddonAttachment>,
val websiteUrl: String,
val gameId: Int,
val summary: String,
val defaultFileId: Int,
val downloadCount: Double,
val latestFiles: List<AddonFile>,
val categories: List<AddonCategory>,
val status: AddonStatus,
val primaryCategoryId: Int,
val categorySection: CategorySection,
val slug: String,
val gameVersionLatestFiles: List<AddonFileLatestForGameVersion>,
val isFeatured: Boolean,
val popularityScore: Double,
val gamePopularityRank: Int,
val primaryLanguage: String,
val gameSlug: String,
val gameName: String,
val portalName: String,
@Serializable(with = DateSerializer::class)
val dateModified: Date,
@Serializable(with = DateSerializer::class)
val dateCreated: Date,
@Serializable(with = DateSerializer::class)
val dateReleased: Date,
val isAvailable: Boolean,
@SerialName("isExperiemental")
val isExperimental: Boolean
)

View File

@ -0,0 +1,22 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
@Serializable
data class AddonAttachment(
val id: Int,
val projectId: Int,
val description: String,
val isDefault: Boolean,
val thumbnailUrl: String,
val title: String,
val url: String,
val status: AddonAttachmentStatus
)

View File

@ -0,0 +1,24 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = AddonAttachmentStatus.Ser::class)
enum class AddonAttachmentStatus {
NORMAL,
DELETED,
UPLOADING,
BANNED,
PENDING_MODERATION;
internal object Ser : EnumIntSerializer<AddonAttachmentStatus>("$MODEL_PACKAGE.addon.AttachmentStatus", values())
}

View File

@ -0,0 +1,22 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
@Serializable
data class AddonAuthor(
val name: String,
val url: String,
val projectId: Int,
val id: Int,
val projectTitleId: Int?,
val projectTitleTitle: String?,
val userId: Int,
val twitchId: Int?
)

View File

@ -0,0 +1,23 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
@Serializable
data class AddonCategory(
val categoryId: Int,
val name: String,
val url: String,
val avatarUrl: String?,
val parentId: Int?,
val rootId: Int?,
val projectId: Int,
val avatarId: Int?,
val gameId: Int
)

View File

@ -0,0 +1,24 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = AddonPackageType.Ser::class)
enum class AddonPackageType {
FOLDER,
CTOC,
SINGLE_FILE,
CMOD2,
MOD_PACK,
MOD;
internal object Ser : EnumIntSerializer<AddonPackageType>("$MODEL_PACKAGE.addon.AddonPackageType", values())
}

View File

@ -0,0 +1,17 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.addon.file.AddonFile
@Serializable
data class AddonRepositoryMatch(
val id: Int,
val latestFiles: List<AddonFile>
)

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = AddonRestrictFileAccess.Ser::class)
enum class AddonRestrictFileAccess {
NONE,
ALPHA,
ALPHA_AND_BETA;
internal object Ser : EnumIntSerializer<AddonRestrictFileAccess>("$MODEL_PACKAGE.addon.AddonRestrictFileAccess", values())
}

View File

@ -0,0 +1,20 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
enum class AddonSortMethod {
FEATURED,
POPULARITY,
LAST_UPDATED,
NAME,
AUTHOR,
TOTAL_DOWNLOADS,
CATEGORY,
GAME_VERSION
}

View File

@ -0,0 +1,28 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = AddonStatus.Ser::class)
enum class AddonStatus {
NEW,
CHANGES_REQUIRED,
UNDER_SOFT_REVIEW,
APPROVED,
REJECTED,
CHANGES_MADE,
INACTIVE,
ABANDONED,
DELETED,
UNDER_REVIEW;
internal object Ser : EnumIntSerializer<AddonStatus>("$MODEL_PACKAGE.addon.AddonStatus", values())
}

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
enum class FeaturedAddonType {
@SerialName("Featured")
FEATURED,
@SerialName("Popular")
POPULAR,
@SerialName("RecentlyUpdated")
RECENTLY_UPDATED;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@Serializable
data class SortableGameVersion(
val gameVersionPadded: String,
val gameVersion: String,
@Serializable(with = DateSerializer::class)
val gameVersionReleaseDate: Date,
val gameVersionName: String
)

View File

@ -0,0 +1,60 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.file
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.addon.AddonPackageType
import me.jie65535.jcf.model.addon.AddonRestrictFileAccess
import me.jie65535.jcf.model.addon.AddonStatus
import me.jie65535.jcf.model.addon.SortableGameVersion
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@Serializable
data class AddonFile(
val id: Int,
val displayName: String,
val fileName: String,
@Serializable(with = DateSerializer::class)
val fileDate: Date,
val fileLength: Long,
val releaseType: AddonFileReleaseType,
val fileStatus: AddonFileStatus,
val downloadUrl: String,
val isAlternate: Boolean,
val alternateFileId: Int,
val dependencies: List<AddonFileDependency>,
val isAvailable: Boolean,
val modules: List<AddonFileModule>,
val packageFingerprint: Long,
val gameVersion: List<String>,
val sortableGameVersion: List<SortableGameVersion>? = null,
val installMetadata: String?,
val changelog: String? = null,
val hasInstallScript: Boolean,
val isCompatibleWithClient: Boolean? = null,
val categorySectionPackageType: AddonPackageType? = null,
val restrictProjectFileAccess: AddonRestrictFileAccess? = null,
val projectStatus: AddonStatus? = null,
val renderCacheId: Int? = null,
val fileLegacyMappingId: Int? = null,
val projectId: Int? = null,
val parentProjectFileId: Int? = null,
val parentFileLegacyMappingId: Int? = null,
val fileTypeId: Int? = null,
val exposeAsAlternative: Boolean? = null,
val packageFingerprintId: Int? = null,
@Serializable(with = DateSerializer::class)
val gameVersionDateReleased: Date?,
val gameVersionMappingId: Int? = null,
val gameVersionId: Int? = null,
val gameId: Int? = null,
val isServerPack: Boolean = false,
val serverPackFileId: Int?,
val gameVersionFlavor: String?
)

View File

@ -0,0 +1,18 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.file
import kotlinx.serialization.Serializable
@Serializable
data class AddonFileDependency(
val id: Int? = null,
val addonId: Int,
val type: AddonFileRelationType,
val fileId: Int? = null
)

View File

@ -0,0 +1,23 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.file
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = AddonFileFingerprintType.Ser::class)
enum class AddonFileFingerprintType {
PACKAGE,
MODULE,
MAIN_MODULE,
FILE,
REFERRENCED_FILE;
internal object Ser : EnumIntSerializer<AddonFileFingerprintType>("$MODEL_PACKAGE.addon.file.AddonFileFingerprintType", values())
}

View File

@ -0,0 +1,19 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.file
import kotlinx.serialization.Serializable
@Serializable
data class AddonFileLatestForGameVersion(
val gameVersion: String,
val projectFileId: Int,
val projectFileName: String,
val fileType: AddonFileReleaseType,
val gameVersionFlavor: String?
)

View File

@ -0,0 +1,19 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.file
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class AddonFileModule(
@SerialName("foldername")
val folderName: String,
val fingerprint: Long,
val type: AddonFileFingerprintType? = null
)

View File

@ -0,0 +1,24 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.file
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = AddonFileRelationType.Ser::class)
enum class AddonFileRelationType {
EMBEDDED_LIBRARY,
OPTIONAL_DEPENDENCY,
REQUIRED_DEPENDENCY,
TOOL,
INCOMPATIBLE,
INCLUDE;
internal object Ser : EnumIntSerializer<AddonFileRelationType>("$MODEL_PACKAGE.addon.file.AddonFileRelationType", values())
}

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.file
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = AddonFileReleaseType.Ser::class)
enum class AddonFileReleaseType {
RELEASE,
BETA,
ALPHA;
internal object Ser : EnumIntSerializer<AddonFileReleaseType>("$MODEL_PACKAGE.addon.file.AddonFileReleaseType", values())
}

View File

@ -0,0 +1,33 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.file
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = AddonFileStatus.Ser::class)
enum class AddonFileStatus {
PROCESSING,
CHANGES_REQUIRED,
UNDER_REVIEW,
APPROVED,
REJECTED,
MALWARE_DETECTED,
DELETED,
ARCHIVED,
TESTING,
RELEASED,
READY_FOR_REVIEW,
DEPRECATED,
BAKING,
AWAITING_FOR_PUBLISHING,
FAILED_PUBLISHING;
internal object Ser : EnumIntSerializer<AddonFileStatus>("$MODEL_PACKAGE.addon.file.AddonFileStatus", values())
}

View File

@ -0,0 +1,18 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.addon.request
import kotlinx.serialization.Serializable
@Serializable
data class FeaturedAddonsRequest(
val gameId: Int,
val featuredCount: Int,
val popularCount: Int,
val updatedCount: Int,
val excludedAddons: Collection<Int>
)

View File

@ -0,0 +1,25 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.category
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@Serializable
data class Category(
val id: Int,
val name: String,
val slug: String,
val avatarUrl: String?,
@Serializable(with = DateSerializer::class)
val dateModified: Date,
val parentGameCategoryId: Int?,
val rootGameCategoryId: Int?,
val gameId: Int
)

View File

@ -0,0 +1,23 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.category
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.addon.AddonPackageType
@Serializable
data class CategorySection(
val extraIncludePattern: String?,
val gameCategoryId: Int,
val gameId: Int,
val id: Int,
val initialInclusionPattern: String,
val name: String,
val packageType: AddonPackageType,
val path: String
)

View File

@ -0,0 +1,18 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.fingerprint
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.addon.file.AddonFile
@Serializable
data class FingerprintMatch(
val id: Int,
val file: AddonFile,
val latestFiles: List<AddonFile>
)

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.fingerprint
import kotlinx.serialization.Serializable
@Serializable
data class FingerprintMatchResult(
val isCacheBuilt: Boolean,
val exactMatches: List<FingerprintMatch>,
val exactFingerprints: List<Long>,
val partialMatches: List<FingerprintMatch>,
val partialMatchFingerprints: Map<String, List<Long>>,
val installedFingerprints: List<Long>,
val unmatchedFingerprints: List<Long>
)

View File

@ -0,0 +1,18 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.fingerprint
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class FolderFingerprint(
@SerialName("foldername")
val folderName: String,
val fingerprints: List<Long>
)

View File

@ -0,0 +1,19 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.fingerprint
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.addon.file.AddonFile
@Serializable
data class FuzzyFingerprintMatch(
val id: Int,
val file: AddonFile,
val latestFiles: List<AddonFile>,
val fingerprints: List<Long>
)

View File

@ -0,0 +1,17 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.fingerprint.request
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.fingerprint.FolderFingerprint
@Serializable
data class FuzzyMatchesRequest(
val gameId: Int,
val fingerprints: List<FolderFingerprint>
)

View File

@ -0,0 +1,41 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.category.CategorySection
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@Serializable
data class Game(
val id: Int,
val name: String,
val slug: String,
@Serializable(with = DateSerializer::class)
val dateModified: Date,
val gameFiles: List<GameFile>,
val gameDetectionHints: List<GameDetectionHint>,
val fileParsingRules: List<GameFileParsingRule>,
val categorySections: List<CategorySection>,
val maxFreeStorage: Long,
val maxPremiumStorage: Long,
val maxFileSize: Long,
val addonSettingsFolderFilter: String?,
val addonSettingsStartingFolder: String?,
val addonSettingsFileFilter: String?,
val addonSettingsFileRemovalFilter: String?,
val supportsAddons: Boolean,
val supportsPartnerAddons: Boolean,
@Serializable(with = SupportedClientConfiguration.Ser::class)
val supportedClientConfiguration: Set<SupportedClientConfiguration>,
val supportsNotifications: Boolean,
val profilerAddonId: Int,
val twitchGameId: Int,
val clientGameSettingsId: Int
)

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import kotlinx.serialization.Serializable
@Serializable
data class GameDetectionHint(
val id: Int,
val hintType: GameDetectionHintType,
val hintPath: String,
val hintKey: String?,
@Serializable(with = GameDetectionHintOption.Ser::class)
val hintOptions: Set<GameDetectionHintOption>,
val gameId: Int
)

View File

@ -0,0 +1,19 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import me.jie65535.jcf.util.internal.FlagSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
enum class GameDetectionHintOption {
NONE,
INCLUDE_SUB_FOLDERS,
FOLDER_ONLY;
internal object Ser : FlagSerializer<GameDetectionHintOption>("$MODEL_PACKAGE.game.GameDetectionHintOption", NONE to 0x1, INCLUDE_SUB_FOLDERS to 0x2, FOLDER_ONLY to 0x4)
}

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = GameDetectionHintType.Ser::class)
enum class GameDetectionHintType {
REGISTRY,
FILE_PATH;
internal object Ser : EnumIntSerializer<GameDetectionHintType>("$MODEL_PACKAGE.game.GameDetectionHintType", values())
}

View File

@ -0,0 +1,20 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import kotlinx.serialization.Serializable
@Serializable
data class GameFile(
val id: Int,
val gameId: Int,
val isRequired: Boolean,
val fileName: String,
val fileType: GameFileType,
val platformType: GamePlatformType
)

View File

@ -0,0 +1,19 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import kotlinx.serialization.Serializable
@Serializable
data class GameFileParsingRule(
val commentStripPattern: String,
val fileExtension: String,
val inclusionPattern: String,
val gameId: Int,
val id: Int
)

View File

@ -0,0 +1,22 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = GameFileType.Ser::class)
enum class GameFileType {
GENERIC,
GAME,
LAUNCHER,
PROFILER_LOCK_CHECK;
internal object Ser : EnumIntSerializer<GameFileType>("$MODEL_PACKAGE.game.GameFileType", values())
}

View File

@ -0,0 +1,23 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = GamePlatformType.Ser::class)
enum class GamePlatformType {
GENERIC,
WINDOWS_32,
WINDOWS_64,
WINDOWS,
OSX;
internal object Ser : EnumIntSerializer<GamePlatformType>("$MODEL_PACKAGE.game.GamePlatformType", values())
}

View File

@ -0,0 +1,19 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.game
import me.jie65535.jcf.util.internal.FlagSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
enum class SupportedClientConfiguration {
DEBUG,
BETA,
RELEASE;
internal object Ser : FlagSerializer<SupportedClientConfiguration>("$MODEL_PACKAGE.game.SupportedClientConfiguration", DEBUG to 0x1, BETA to 0x2, RELEASE to 0x4)
}

View File

@ -0,0 +1,27 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.minecraft
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@Serializable
data class MinecraftVersion(
val id: Int,
val gameVersionId: Int,
val versionString: String,
val jarDownloadUrl: String,
val jsonDownloadUrl: String,
val approved: Boolean,
@Serializable(with = DateSerializer::class)
val dateModified: Date,
val gameVersionTypeId: Int,
val gameVersionStatus: MinecraftVersionStatus,
val gameVersionTypeStatus: MinecraftVersionTypeStatus
)

View File

@ -0,0 +1,21 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.minecraft
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = MinecraftVersionStatus.Ser::class)
enum class MinecraftVersionStatus {
APPROVED,
DELETED,
NEW;
internal object Ser : EnumIntSerializer<MinecraftVersionStatus>("$MODEL_PACKAGE.game.MinecraftVersionStatus", values())
}

View File

@ -0,0 +1,20 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.minecraft
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = MinecraftVersionTypeStatus.Ser::class)
enum class MinecraftVersionTypeStatus {
NORMAL,
DELETED;
internal object Ser : EnumIntSerializer<MinecraftVersionTypeStatus>("$MODEL_PACKAGE.game.MinecraftVersionTypeStatus", values())
}

View File

@ -0,0 +1,22 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.minecraft.modloader
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@Serializable
data class ModloaderIndex(
val name: String,
val gameVersion: String,
val latest: Boolean,
val recommended: Boolean,
@Serializable(with = DateSerializer::class)
val dateModified: Date
)

View File

@ -0,0 +1,22 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.minecraft.modloader
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = ModloaderInstallMethod.Ser::class)
enum class ModloaderInstallMethod {
ANY,
FORGE,
CAULDRON,
LITE_LOADER;
internal object Ser : EnumIntSerializer<ModloaderInstallMethod>("$MODEL_PACKAGE.game.ModloaderInstallMethod", values())
}

View File

@ -0,0 +1,22 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.minecraft.modloader
import kotlinx.serialization.Serializable
import me.jie65535.jcf.util.internal.EnumIntSerializer
import me.jie65535.jcf.util.internal.MODEL_PACKAGE
@Serializable(with = ModloaderType.Ser::class)
enum class ModloaderType {
ANY,
FORGE,
CAULDRON,
LITE_LOADER;
internal object Ser : EnumIntSerializer<ModloaderType>("$MODEL_PACKAGE.game.ModloaderType", values(), 0)
}

View File

@ -0,0 +1,48 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.model.minecraft.modloader
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import me.jie65535.jcf.model.minecraft.MinecraftVersionStatus
import me.jie65535.jcf.model.minecraft.MinecraftVersionTypeStatus
import me.jie65535.jcf.util.Date
import me.jie65535.jcf.util.internal.DateSerializer
@Serializable
data class ModloaderVersion(
val id: Int,
val gameVersionId: Int,
val minecraftGameVersionId: Int,
val forgeVersion: String,
val name: String,
val type: ModloaderType,
val downloadUrl: String,
@SerialName("filename")
val fileName: String,
val installMethod: ModloaderInstallMethod,
val latest: Boolean,
val recommended: Boolean,
val approved: Boolean,
@Serializable(with = DateSerializer::class)
val dateModified: Date,
val mavenVersionString: String,
val versionJson: String,
val librariesInstallLocation: String,
val minecraftVersion: String,
val additionalFilesJson: String,
val modLoaderGameVersionId: Int,
val modLoaderGameVersionTypeId: Int,
val modLoaderGameVersionStatus: MinecraftVersionStatus,
val modLoaderGameVersionTypeStatus: MinecraftVersionTypeStatus,
val mcGameVersionId: Int,
val mcGameVersionTypeId: Int,
val mcGameVersionStatus: MinecraftVersionStatus,
val mcGameVersionTypeStatus: MinecraftVersionTypeStatus,
val installProfileJson: String
)

View File

@ -0,0 +1,5 @@
package me.jie65535.jcf.util
import java.time.OffsetDateTime
typealias Date = OffsetDateTime

View File

@ -0,0 +1,26 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.util.internal
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import me.jie65535.jcf.util.Date
import java.time.OffsetDateTime
internal object DateSerializer : KSerializer<Date> {
override val descriptor = PrimitiveSerialDescriptor("Date", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): Date {
return OffsetDateTime.parse(decoder.decodeString())
}
override fun serialize(encoder: Encoder, value: Date) {
encoder.encodeString(value.toString())
}
}

View File

@ -0,0 +1,25 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.util.internal
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
internal open class EnumIntSerializer<T>(private val serialName: String, private val values: Array<T>, private val startFrom: Int = 1) : KSerializer<T> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(serialName, PrimitiveKind.INT)
override fun deserialize(decoder: Decoder): T {
val value = decoder.decodeInt()
return values[value - startFrom] ?: throw NoSuchElementException("Can't find $serialName with key $value")
}
override fun serialize(encoder: Encoder, value: T) {
encoder.encodeInt(values.indexOf(value) + startFrom)
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright © 2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package me.jie65535.jcf.util.internal
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
internal open class FlagSerializer<T : Enum<T>>(serialName: String, private val map: Map<T, Int>) : KSerializer<Set<T>> {
constructor(serialName: String, vararg pairs: Pair<T, Int>) : this(serialName, mapOf(*pairs))
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(serialName, PrimitiveKind.INT)
override fun serialize(encoder: Encoder, value: Set<T>) {
var bits = 0
for(flag in value) {
bits = bits or (map[flag] ?: error(""))
}
encoder.encodeInt(bits)
}
override fun deserialize(decoder: Decoder): Set<T> {
val set = mutableSetOf<T>()
val bits = decoder.decodeInt()
for((flag, shift) in map) {
if(bits and shift == shift)
set += flag
}
return set
}
}

View File

@ -0,0 +1,3 @@
package me.jie65535.jcf.util.internal
internal const val MODEL_PACKAGE = "me.jie65535.jcf.model"

View File

@ -0,0 +1 @@
me.jie65535.jcf.JCurseforge