Skip to content

Commit

Permalink
Add vetted mods
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenAppers committed Nov 12, 2024
1 parent cdc8229 commit ba290d1
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Launcher } from './Launcher'
import { PieRayHelper } from './PieRayHelper'

function App() {
const [selectedTab, setSelectedTab] = React.useState(1)
const [selectedTab, setSelectedTab] = React.useState(2)
return (
<Tabs
variant="soft-rounded"
Expand Down
45 changes: 42 additions & 3 deletions src/components/Launcher.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Box,
Button,
Checkbox,
Flex,
FormControl,
FormLabel,
Expand Down Expand Up @@ -29,6 +30,7 @@ import React, { useEffect, useState } from 'react'
import { v4 as uuidv4 } from 'uuid'

import {
findVersionManifest,
GameInstall,
getGameInstalModLoaderName,
ModLoaderName,
Expand All @@ -37,7 +39,11 @@ import {
QUERY_KEYS,
setGameInstallModLoaderName,
STORE_KEYS,
toggleGameInstallModeUrl,
} from '../constants'
import { mods } from '../utils/mods'

const defaultVersion = '1.20.6'

function assertValue<X>(x: X | undefined | null, name?: string): X {
if (!x) throw new Error(`missing ${name}`)
Expand Down Expand Up @@ -127,8 +133,9 @@ export function NewGameInstall(props: {
)

const updateNewInstallVersionManifest = (version: string) => {
const newVersionManifest = versionManifests.data?.versions?.find(
(x) => x.id === version
const newVersionManifest = findVersionManifest(
versionManifests.data,
version
)
if (!newVersionManifest) return
setNewInstall((prev) => ({
Expand All @@ -148,7 +155,15 @@ export function NewGameInstall(props: {

useEffect(() => {
if (!newInstall.versionManifest?.id && versionManifests.isSuccess) {
updateNewInstallVersionManifest(versionManifests.data.latest.release)
const defaultVersionManifest = findVersionManifest(
versionManifests.data,
defaultVersion
)
updateNewInstallVersionManifest(
defaultVersionManifest
? defaultVersion
: versionManifests.data.latest.release
)
}
}, [
newInstall.versionManifest?.id,
Expand Down Expand Up @@ -221,6 +236,30 @@ export function NewGameInstall(props: {
))}
</Select>
</FormControl>
{newInstall.fabricLoaderVersion && (
<List marginTop="1rem">
{Object.entries(
mods[`${newInstall?.versionManifest?.id}-fabric`] || {}
).map(([name, url]) => (
<ListItem key={name}>
<Checkbox
isChecked={newInstall?.mods?.includes(url)}
onChange={(e) =>
setNewInstall((prev) =>
toggleGameInstallModeUrl(
prev,
url,
!!e.target.checked
)
)
}
>
{name}
</Checkbox>
</ListItem>
))}
</List>
)}
</ModalBody>
)}
<ModalFooter>
Expand Down
19 changes: 19 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const gameInstall = z.object({
uuid: z.string(),
versionManifest: mojangVersionManifest,
fabricLoaderVersion: z.optional(z.string()),
mods: z.optional(z.array(z.string())),
})

export type MojangLibrary = z.infer<typeof mojangLibrary>
Expand Down Expand Up @@ -161,6 +162,11 @@ export const CHANNELS = {

export const LAUNCH_CHANNEL = (uuid: string) => `launch-game-install-${uuid}`

export const findVersionManifest = (
versionManifests: MojangVersionManifests | undefined,
version: string
) => versionManifests?.versions?.find((x) => x.id === version)

export const getGameInstalModLoaderName = (
gameInstall: Partial<GameInstall>
): ModLoaderName => {
Expand All @@ -180,6 +186,19 @@ export const setGameInstallModLoaderName = (
}
}

export const toggleGameInstallModeUrl = (
gameInstall: Partial<GameInstall>,
url: string,
includeUrl?: boolean
): Partial<GameInstall> => ({
...gameInstall,
mods: (
includeUrl !== undefined ? includeUrl : gameInstall.mods?.includes(url)
)
? [...(gameInstall.mods ?? []), url]
: (gameInstall.mods ?? []).filter((x) => x !== url),
})

export const parseLibraryName = (libraryName: string) => {
const [jarOrg, jarName, jarVersion] = libraryName.split(':')
return {
Expand Down
13 changes: 12 additions & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ export const schema: Schema<StoreSchema> = {
name: { type: 'string' },
path: { type: 'string' },
uuid: { type: 'string' },
version: { type: 'string' },
versionManifest: {
type: 'object',
properties: {
id: { type: 'string' },
type: { type: 'string' },
url: { type: 'string' },
time: { type: 'string' },
releaseTime: { type: 'string' },
},
},
fabricLoaderVersion: { type: 'string', default: '' },
mods: { type: 'array', items: { type: 'string' }, default: [] },
},
},
default: [],
Expand Down
11 changes: 11 additions & 0 deletions src/utils/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ export async function updateInstall(install: GameInstall) {
versionDetails.mainClass = fabricDetails.mainClass
}

const modsPath = path.join(install.path, 'mods')
for (const mod of install.mods ?? []) {
const url = new URL(mod)
downloadLibraries.push(() =>
downloadIfMissing(
mod,
path.join(modsPath, path.basename(url.pathname))
)
)
}

await pSettle(downloadLibraries, { concurrency: 8 })
return versionDetails
}
Expand Down
14 changes: 14 additions & 0 deletions src/utils/mods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const mods: Record<string, Record<string, string>> = {
'1.20.6-fabric': {
baritone:
'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/baritone/baritone-1.20.6-SNAPSHOT.jar?raw=true',
litematica:
'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/litematica/litematica-fabric-1.20.6-0.18.0.jar?raw=true',
malilib:
'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/malilib/malilib-fabric-1.20.6-0.19.0.jar?raw=true',
'meteor-client':
'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/meteor-client/meteor-client-0.5.7.jar?raw=true',
replaymod:
'https://github.com/AngleOpera/meteor-archive/blob/6da1d84dea90fa02a91b9ffb0a706725e5b5caa1/files/replaymod/replaymod-1.20.6-2.6.20.jar?raw=true',
},
}

0 comments on commit ba290d1

Please sign in to comment.