Skip to content

Commit

Permalink
First launch
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenAppers committed Nov 22, 2024
1 parent f8febe6 commit e9441b5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 67 deletions.
20 changes: 15 additions & 5 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,21 @@ export function App() {
/>
 
<TabList>
<Tab color="yellow.100">Analytics</Tab>
<Tab color="yellow.100">Anti/PieRay</Tab>
<Tab color="yellow.100">Launcher</Tab>
<Tab color="yellow.100">Strongholds</Tab>
<Tab color="yellow.100">Waypoints</Tab>
<Tab color="yellow.100" _hover={{ color: 'yellow.300' }}>
Analytics
</Tab>
<Tab color="yellow.100" _hover={{ color: 'yellow.300' }}>
Anti/PieRay
</Tab>
<Tab color="yellow.100" _hover={{ color: 'yellow.300' }}>
Launcher
</Tab>
<Tab color="yellow.100" _hover={{ color: 'yellow.300' }}>
Strongholds
</Tab>
<Tab color="yellow.100" _hover={{ color: 'yellow.300' }}>
Waypoints
</Tab>
</TabList>
<Spacer />
{gameAccount ? (
Expand Down
34 changes: 12 additions & 22 deletions src/components/PlayerHead.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CSSProperties, useCallback, useEffect, useRef } from 'react'
import { CSSProperties, useEffect, useRef } from 'react'

export function PlayerHead(props: { headSize?: number; skinUrl?: string }) {
const headSize = props.headSize || 120
Expand All @@ -22,18 +22,19 @@ export function PlayerHead(props: { headSize?: number; skinUrl?: string }) {
const divHeadRef = useRef<HTMLDivElement>(null)
const imgRef = useRef<HTMLImageElement>(null)

const rotateHead = useCallback(
(xPos: number, yPos: number) => {
useEffect(() => {
const handleMouseMove = (event: MouseEvent) => {
if (!divHeadRef.current) return
divHeadRef.current.style.transform =
xPos !== undefined && yPos !== undefined
? `translateZ(-${halfHeadSize}px) ` +
`rotateY(${xPos/12-60}deg) ` +
`rotateX(${-yPos/16}deg)`
: ''
},
[divHeadRef.current]
)
`translateZ(-${halfHeadSize}px) ` +
`rotateY(${event.clientX / 12 - 60}deg) ` +
`rotateX(${-Math.min(event.clientY, 400) / 16}deg)`
}
window.addEventListener('mousemove', handleMouseMove)
return () => {
window.removeEventListener('mousemove', handleMouseMove)
}
}, [])

useEffect(() => {
const img = imgRef.current
Expand Down Expand Up @@ -178,17 +179,6 @@ export function PlayerHead(props: { headSize?: number; skinUrl?: string }) {

return (
<div>
<div
onMouseMove={(event) => rotateHead(event.clientX, event.clientY)}
style={{
position: 'absolute',
width: '100%',
height: '100%',
top: '0px',
left: '0px',
}}
/>

<section
style={{
width: `${headSize}px`,
Expand Down
28 changes: 2 additions & 26 deletions src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,23 @@ export async function loginToMinecraft(
): Promise<GameAccount> {
if (!microsoftToken) throw new Error('Microsoft token is required')
const xboxLiveLogin = await postXSTSUserAuthenticate(microsoftToken)
console.log('got xbixLiveLogin', xboxLiveLogin)

const xboxLiveAuth = await postXSTSAuthorize(
xboxLiveLogin.Token,
'http://xboxlive.com'
)

console.log(
'got xboxLiveAuth',
xboxLiveAuth,
xboxLiveAuth.DisplayClaims.xui[0],
xboxLiveAuth.Token
)

const minecraftAuth = await postXSTSAuthorize(
xboxLiveLogin.Token,
'rp://api.minecraftservices.com/'
)
console.log(
'got minecraftAuth',
minecraftAuth,
minecraftAuth.DisplayClaims.xui[0],
minecraftAuth.Token
)

const profile = await getXBoxLiveProfile(
/* const profile = await getXBoxLiveProfile(
xboxLiveLogin.DisplayClaims.xui[0].uhs,
xboxLiveAuth.Token
)
console.log('got profile', profile, JSON.stringify(profile))

) */
const login = await postMinecraftLoginWithXBox(
minecraftAuth.DisplayClaims.xui[0].uhs,
minecraftAuth.Token
)
console.log('got login', login)

const minecraftProfile = await getMinecraftProfile(login.access_token)
console.log('got minecraft profile', minecraftProfile)

const gameAccount: GameAccount = {
active: true,
profile: minecraftProfile,
Expand All @@ -144,6 +121,5 @@ export async function loginToMinecraft(
yggdrasilToken: login,
}
updateGameAccount(store, gameAccount)

return gameAccount
}
31 changes: 17 additions & 14 deletions src/utils/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,6 @@ export async function launchInstall(
callback('Updating install')
const versionDetails = await updateInstall(install)

callback('Authenticating')
let accessToken = '0'
try {
const microsoftAuth = await authProvider.login()
const gameAccount = await loginToMinecraft(
microsoftAuth?.accessToken,
store
)
accessToken = gameAccount.yggdrasilToken.access_token
} catch (error) {
callback('Error authenticating: ' + error.toString())
}

const osArch = getOsArch()
const osName = getOsName()
const librariesPath = getLibrariesPath()
Expand All @@ -200,7 +187,7 @@ export async function launchInstall(
assets_root: '',
assets_index_name: '1.21',
auth_uuid: '',
auth_access_token: accessToken || '0',
auth_access_token: '0',
clientid: '',
auth_xuid: '',
user_type: '',
Expand All @@ -210,6 +197,22 @@ export async function launchInstall(
launcher_version: '1.0.0',
classpath: '',
}

callback('Authenticating')
try {
const microsoftAuth = await authProvider.login()
const gameAccount = await loginToMinecraft(
microsoftAuth?.accessToken,
store
)
template.auth_access_token = gameAccount.yggdrasilToken.access_token
template.auth_player_name = gameAccount.profile.name
template.auth_uuid = gameAccount.profile.id
template.user_type = 'msa'
} catch (error) {
callback('Error authenticating: ' + error.toString())
}

const appendClasspath = (path: string) =>
(template.classpath += `${template.classpath.length ? ':' : ''}${path}`)
for (const library of versionDetails.libraries) {
Expand Down

0 comments on commit e9441b5

Please sign in to comment.