Skip to content

Commit

Permalink
Support sided obfuscated names, handle namespace localization
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Jul 8, 2022
1 parent 627d1da commit 33246e5
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 20 deletions.
32 changes: 30 additions & 2 deletions backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ import me.shedaniel.linkie.Method
import me.shedaniel.linkie.Namespaces
import me.shedaniel.linkie.getClassByObfName
import me.shedaniel.linkie.getMappedDesc
import me.shedaniel.linkie.getObfClientDesc
import me.shedaniel.linkie.getObfMergedDesc
import me.shedaniel.linkie.getObfServerDesc
import me.shedaniel.linkie.obfClientName
import me.shedaniel.linkie.obfMergedName
import me.shedaniel.linkie.obfServerName
import me.shedaniel.linkie.utils.MemberEntry
import me.shedaniel.linkie.utils.ResultHolder
import me.shedaniel.linkie.utils.toVersion
Expand Down Expand Up @@ -129,8 +133,8 @@ fun main() {
val allowFields = call.parameters["allowFields"]?.toBoolean() ?: true
val translateNsStr = call.parameters["translate"]?.lowercase()
require(limit in 1..1000) { "Limit must be between 1 and 1000" }
val namespace = Namespaces[namespaceStr]
val translateNamespace = translateNsStr?.let { Namespaces[it] }
val namespace = Namespaces.namespaces[namespaceStr] ?: throw IllegalArgumentException("No namespace found for $namespaceStr")
val translateNamespace = translateNsStr?.let { Namespaces.namespaces[it] ?: throw IllegalArgumentException("No namespace found for $it") }

val allVersions = namespace.getAllSortedVersions().toMutableList()
if (translateNamespace != null) {
Expand Down Expand Up @@ -253,6 +257,8 @@ fun toJsonFromEntry(mappings: MappingsContainer, entry: Any?, score: Double): Js
obf = entry.obfMergedName,
intermediary = entry.intermediaryName,
named = entry.mappedName,
obfClient = entry.obfClientName,
obfServer = entry.obfServerName,
score = score,
memberType = "c",
)
Expand All @@ -268,6 +274,12 @@ fun toJsonFromEntry(mappings: MappingsContainer, entry: Any?, score: Double): Js
descObf = entry.member.getObfMergedDesc(mappings),
descIntermediary = entry.member.intermediaryDesc,
descNamed = entry.member.getMappedDesc(mappings),
ownerObfClient = entry.owner.obfClientName,
obfClient = entry.member.obfClientName,
descObfClient = entry.member.getObfClientDesc(mappings),
ownerObfServer = entry.owner.obfServerName,
obfServer = entry.member.obfServerName,
descObfServer = entry.member.getObfServerDesc(mappings),
score = score,
memberType = if (entry.member is Field) "f" else "m"
)
Expand Down Expand Up @@ -349,6 +361,10 @@ data class SearchResultClassEntry(
val intermediary: String,
@SerialName("n")
val named: String?,
@SerialName("h")
val obfClient: String?,
@SerialName("l")
val obfServer: String?,
@SerialName("z")
val score: Double,
@SerialName("t")
Expand All @@ -375,6 +391,18 @@ data class SearchResultMemberEntry(
val descIntermediary: String,
@SerialName("f")
val descNamed: String?,
@SerialName("g")
val ownerObfClient: String?,
@SerialName("h")
val obfClient: String?,
@SerialName("j")
val descObfClient: String?,
@SerialName("k")
val ownerObfServer: String?,
@SerialName("l")
val obfServer: String?,
@SerialName("m")
val descObfServer: String?,
@SerialName("z")
val score: Double,
@SerialName("t")
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/app/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ export function reqSearch<T = any>(namespace: string, version: string, query: st
export function reqOss<T = any>(): Promise<AxiosResponse<T>> {
return HTTP.get(`/api/oss`)
}

export let namespaceLocalizations: { [namespace: string]: string } = {
"yarn": "Yarn",
"mojang": "Official Mojang (Fabric Intermediary)",
"mojang_srg": "Official Mojang (Forge SRG)",
"mojang_hashed": "Official Mojang (Quilt Hashed)",
"mcp": "MCP",
"quilt-mappings": "Quilt Mappings",
"legacy-yarn": "Legacy Yarn (Unofficial)",
"yarrn": "Yarrn",
"plasma": "Plasma",
}
42 changes: 33 additions & 9 deletions frontend/src/components/mappings/MappingsEntryBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Block>
<SubHeader :addPadding="false">
{{ getDisplayName(entry) }}
<span v-if="entry.translatedTo"> > {{ getDisplayName(entry.translatedTo) }}</span>
<span v-if="hasTranslation"> > {{ getDisplayName(entry.translatedTo) }}</span>
<div class="badge badge-sm ml-2" :class="{
'badge-primary': entry.type === 'class',
'badge-secondary': entry.type === 'field',
Expand All @@ -21,7 +21,7 @@
<EntryDetails v-if="namespace.supportsAT" title="AT:" :content="atText(entry)"/>
<EntryDetails v-if="namespace.supportsAW" title="AW:" :content="awText(entry)"/>

<div v-if="entry.translatedTo">
<div v-if="hasTranslation">
<div class="divider mt-0 mb-0"/>
<EntryDetails v-if="entry.type === 'field' && translatedToNamespace.supportsFieldDescription" title="Type:" :content="fieldType(entry.translatedTo)"
:code="false"/>
Expand Down Expand Up @@ -79,6 +79,22 @@ function getObf(entry: MappingEntry) {
}
}
function getObfClient(entry: MappingEntry) {
if (entry.type == "class") {
return formatName(entry.obfClient)
} else {
return `${formatName(entry.ownerObfClient)}.${onlyClass(entry.obfClient)}`
}
}
function getObfServer(entry: MappingEntry) {
if (entry.type == "class") {
return formatName(entry.obfServer)
} else {
return `${formatName(entry.ownerObfServer)}.${onlyClass(entry.obfServer)}`
}
}
function getIntermediaryName(entry: MappingEntry) {
if (entry.type == "class") {
return formatName(entry.intermediary)
Expand All @@ -103,11 +119,18 @@ function getDisplayName(entry: MappingEntry, simplify: boolean = true) {
}
}
function getBreadcrumbs(entry: MappingEntry) {
function getBreadcrumbs(hasTranslation: boolean, entry: MappingEntry) {
let breadcrumbs = [] as string[]
if (!entry.translatedTo) {
if (!hasTranslation) {
if (entry.obf) {
breadcrumbs.push(getObf(entry)!)
} else {
let list = [] as string[]
if (entry.obfClient) list.push(getObfClient(entry)! + " (client)")
if (entry.obfServer) list.push(getObfServer(entry)! + " (server)")
if (list.length > 0) {
breadcrumbs.push(list.join(" / "))
}
}
let intermediary = getIntermediaryName(entry)!
let named = getDisplayName(entry, false)!
Expand Down Expand Up @@ -199,7 +222,10 @@ export default defineComponent({
},
computed: {
breadcrumbs() {
return getBreadcrumbs(this.entry)
return getBreadcrumbs(this.hasTranslation, this.entry)
},
hasTranslation() {
return this.entry.translatedTo && this.translatedToNamespace
},
},
methods: {
Expand Down Expand Up @@ -228,12 +254,10 @@ export default defineComponent({
},
props: {
namespace: {
type: Object as PropType<Namespace | undefined>,
required: true,
type: Object as PropType<Namespace>,
},
translatedToNamespace: {
type: Object as PropType<Namespace | undefined>,
required: true,
type: Object as PropType<Namespace>,
},
entry: {
type: Object as PropType<MappingEntry>,
Expand Down
43 changes: 34 additions & 9 deletions frontend/src/components/mappings/MappingsFilterBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<div class="flex flex-col">
<SubHeader :add-padding="false" class="pb-2">Namespace</SubHeader>
<select class="select select-sm font-light p-0"
@change="namespace = ($event.target as any)?.value?.toLowerCase() ?? namespace" :value="namespace ?? ''">
@change="namespace = delocalizeNamespace(($event.target as any)?.value).id" :value="localizeNamespace(namespace) ?? localizeNamespace(firstNamespace) ?? ''">
<option disabled selected>Select namespace</option>
<option v-for="namespace in namespaces">
{{ namespace.id }}
<option v-for="namespace in namespacesSorted">
{{ localizeNamespace(namespace) }}
</option>
</select>

<div class="divider mt-0 mb-0"/>
<SubHeader :add-padding="false" class="pb-2">Version</SubHeader>
<div class="flex flex-col flex-nowrap justify-center h-full whitespace-nowrap pb-2">
Expand All @@ -18,7 +18,7 @@
@input="allowSnapshots = ($event.target as any)?.checked ?? allowSnapshots"/>
</div>
</div>

<select class="select select-sm font-light p-0"
@change="version = ($event.target as any)?.value ?? version" :value="version ?? ''">
<option disabled selected>Select version</option>
Expand Down Expand Up @@ -50,11 +50,12 @@
<div class="divider mt-0 mb-0"/>
<SubHeader :add-padding="false" class="pb-2">Translate To</SubHeader>
<select class="select select-sm font-light p-0"
@change="translateAs = ($event.target as any)?.value === 'Do not translate' ? undefined : ($event.target as any)?.value?.toLowerCase()" :value="translateAs ?? 'Do not translate'">
@change="translateAs = ($event.target as any)?.value === 'Do not translate' ? undefined : delocalizeNamespace(($event.target as any)?.value).id"
:value="localizeNamespace(translateAs) ?? 'Do not translate'">
<option disabled selected>Select namespace</option>
<option>Do not translate</option>
<option v-for="ns in namespaces" :disabled="ns.id === namespace">
{{ ns.id }}
{{ localizeNamespace(ns) }}
</option>
</select>
</div>
Expand All @@ -65,25 +66,49 @@ import {defineComponent, PropType} from "vue"
import {mapWritableState} from "pinia"
import {useMappingsStore} from "../../app/mappings-store"
import {MappingsData, Namespace} from "../../routes/Mappings.vue"
import {useDependencySearchStore} from "../../app/dependency-store"
import SubHeader from "../dependencies/SubHeader.vue"
import {namespaceLocalizations} from "../../app/backend"
export default defineComponent({
name: "MappingsFilterBlock",
components: {SubHeader},
methods: {
localizeNamespace(namespace?: Namespace | string): string | undefined {
if (typeof namespace === "string") {
return namespaceLocalizations[namespace.toLowerCase()] || namespace.toLowerCase()
} else if (namespace) {
let id = namespace.id
return namespaceLocalizations[id.toLowerCase()] || id.toLowerCase()
} else {
return undefined
}
},
delocalizeNamespace(string: string) : Namespace {
let id = Object.entries(namespaceLocalizations)
.find(([id, name]) => name === string)
?.[0] ?? this.namespace?.id
return this.namespaces.find(ns => ns.id === id) ?? (this.namespace ?? this.namespaces[0])
}
},
computed: {
...mapWritableState(useMappingsStore, ["namespace", "version", "allowSnapshots", "allowClasses", "allowFields", "allowMethods", "translateAs"]),
namespaces(): Namespace[] {
return this.data.namespaces
},
namespacesSorted(): Namespace[] {
return this.namespaces.sort((a, b) => (this.localizeNamespace(a) ?? "").localeCompare(this.localizeNamespace(b) ?? ""))
},
firstNamespace(): Namespace | undefined {
return this.namespaces.at(0)
},
applicableVersions(): string[] {
let {namespace, allowSnapshots, translateAs} = useMappingsStore()
if (!namespace) return []
let namespaceObj = this.data.namespaces.find(value => value.id === namespace)
if (!namespaceObj) return []
let versions = namespaceObj.versions
if (versions && !allowSnapshots) {
versions = versions.filter(entry => entry.stable)
versions = versions.filter(entry => entry.stable)
}
if (versions && translateAs) {
let translateAsObj = this.data.namespaces.find(value => value.id === translateAs)
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/routes/Mappings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export interface MappingEntry {
ownerObf?: string,
ownerIntermediary?: string,
ownerNamed?: string,
ownerObfClient?: string,
obfClient?: string,
descObfClient?: string,
ownerObfServer?: string,
obfServer?: string,
descObfServer?: string,
type: MappingType,
translatedTo?: MappingEntry,
}
Expand Down Expand Up @@ -259,6 +265,12 @@ export default defineComponent({
ownerObf: obj.a,
ownerIntermediary: obj.b,
ownerNamed: obj.c,
ownerObfClient: obj.g,
obfClient: obj.h,
descObfClient: obj.j,
ownerObfServer: obj.k,
obfServer: obj.l,
descObfServer: obj.m,
type,
translatedTo,
} as MappingEntry
Expand Down

0 comments on commit 33246e5

Please sign in to comment.