Skip to content

Commit

Permalink
Merge branch 'radical-red' of https://github.com/andrewbenington/Open…
Browse files Browse the repository at this point in the history
…Home into radical-red
  • Loading branch information
evanwporter committed Nov 17, 2024
2 parents 8ad0c55 + 88885db commit 68fa93f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 39 deletions.
3 changes: 1 addition & 2 deletions src/renderer/components/InfoGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Card, Divider, Grid, Stack } from '@mui/joy'
import { isDayjs } from 'dayjs'
import { PKM } from 'pokemon-files'
import { PluginPKM } from 'src/types/interfaces'
import { ReactNode, useMemo } from 'react'
type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl'

Expand All @@ -28,7 +27,7 @@ function isArray(obj: object): obj is (object | Primitive)[] {
return Object.prototype.toString.call(obj) === '[object Array]'
}

function isPKM(obj: object): obj is (PKM | PluginPKM) {
function isPKM(obj: object): obj is PKM {
return 'format' in obj
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/images/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getTypeIconPath = (type: string): string => {

export function useMonSaveLogo(mon: PKMInterface) {
const [, , getEnabledSaveTypes] = useContext(AppInfoContext)
if (mon.pluginName) {
if (mon.pluginIdentifier) {
getEnabledSaveTypes().find((saveType) => saveType)
}
}
9 changes: 8 additions & 1 deletion src/renderer/pokemon/MetDataMovesDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { useContext, useMemo } from 'react'
import { PKMInterface } from '../../types/interfaces'
import { getCharacteristic, getMoveMaxPP } from '../../types/pkm/util'
import { getGameName, getPluginIdentifier } from '../../types/SAVTypes/util'
import { Styles } from '../../types/types'
import Markings from '../components/Markings'
import { getOriginMark } from '../images/game'
Expand Down Expand Up @@ -82,8 +83,14 @@ const MetDataMovesDisplay = (props: { mon: PKMInterface }) => {
}, [mon])

const metMessage = useMemo(() => {
if (mon.pluginOrigin) {
const saveType = getEnabledSaveTypes().find(
(saveType) => mon.pluginOrigin === getPluginIdentifier(saveType)
)
return `Met in ${saveType ? getGameName(saveType) : '(unknown game)'}`
}
if (!mon.metLocationIndex) {
return 'Met location unknown.'
return 'Met location unknown.' + mon.pluginIdentifier
}
let message = 'Met'
if (mon.metTimeOfDay) {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/saves/util.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import dayjs from 'dayjs'
import { colosseumOrXD, ColosseumOrXD, GameOfOrigin, GameOfOriginData } from 'pokemon-resources'
import { PKMInterface } from '../../types/interfaces'
import { SAVClass } from '../../types/SAVTypes/util'
import { getPluginIdentifier, SAVClass } from '../../types/SAVTypes/util'
import { GameLogos, getOriginMark } from '../images/game'
import { getPublicImageURL } from '../images/images'

export type SaveViewMode = 'cards' | 'grid'

export function getMonSaveLogo(mon: PKMInterface, supportedSaves: SAVClass[]) {
if (mon.pluginName) {
const pluginIdentifier = supportedSaves.find((s) => s.prototype.getPluginIdentifier.call({}))
if (mon.pluginOrigin) {
const pluginIdentifier = supportedSaves.find((s) => getPluginIdentifier(s) === mon.pluginOrigin)
return getPublicImageURL(`logos/${pluginIdentifier}.png`)
}
if (!mon.gameOfOrigin) {
Expand Down
32 changes: 18 additions & 14 deletions src/types/SAVTypes/radicalred/PK3RR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
uIntToBufferBits,
write30BitIVsToBytes,
writeGen3StringToBytes,
writeStatsToBytes
writeStatsToBytes,
} from 'pokemon-files'
import { getHPGen3Onward, getStatGen3Onward } from '../../../util/StatCalc'
import { ItemGen3RRFromString, ItemGen3RRToString } from './conversion/Gen3RRItems'
Expand All @@ -38,8 +38,14 @@ import {
toGen3RRPokemonIndex,
} from './conversion/Gen3RRPokemonIndex'

const FAKEMON_INDEXES = [
1186, 1200, 1274, 1275, 1276, 1277, 1278, 1279, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289,
1290, 1291, 1292, 1293, 1294, 1375,
]

export class PK3RR {
format: 'PK3RR' = 'PK3RR'
pluginIdentifier = 'radical_red'
personalityValue: number
trainerID: number
secretID: number
Expand Down Expand Up @@ -67,13 +73,6 @@ export class PK3RR {
nickname: string
trainerName: string
trainerGender: boolean
restricted_mons: number[] = [
1186,
1200,
1274, 1275, 1276, 1277, 1278, 1279,
1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294,
1375,
]
isLocked: boolean = false

constructor(arg: ArrayBuffer | AllPKMFields) {
Expand Down Expand Up @@ -107,8 +106,8 @@ export class PK3RR {

// Species 28:30
const speciesIndex: number = dataView.getUint16(0x1c, true)
const ret = fromGen3RRPokemonIndex(speciesIndex)
if (ret.NationalDexIndex < 0) {
const speciesData = fromGen3RRPokemonIndex(speciesIndex)
if (speciesData.NationalDexIndex < 0) {
this.dexNum = 0
this.formeNum = 0
console.warn(
Expand All @@ -118,13 +117,18 @@ export class PK3RR {
speciesIndex
)
} else {
this.dexNum = ret.NationalDexIndex
this.formeNum = ret.FormIndex
this.dexNum = speciesData.NationalDexIndex
this.formeNum = speciesData.FormIndex
}

this.isLocked = this.restricted_mons.includes(speciesIndex)
this.isLocked = FAKEMON_INDEXES.includes(speciesIndex)
if (this.isLocked) {
console.warn("The species is locked. Species: ", Gen3RRSpecies[speciesIndex], ", RR Dex Number: ", speciesIndex)
console.warn(
'The species is locked. Species: ',
Gen3RRSpecies[speciesIndex],
', RR Dex Number: ',
speciesIndex
)
}

// Held Item 30:32
Expand Down
4 changes: 4 additions & 0 deletions src/types/SAVTypes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export function getPluginIdentifier(saveType: SAVClass | undefined): string | un
return saveType?.prototype.getPluginIdentifier()
}

export function getGameName(saveType: SAVClass | undefined): string | undefined {
return saveType?.prototype.getGameName()
}

export function hasDesamumeFooter(bytes: Uint8Array, expectedOffset: number): boolean {
const possibleFooter = new TextDecoder().decode(bytes.slice(expectedOffset))
return possibleFooter.startsWith(DESAMUME_FOOTER_START)
Expand Down
17 changes: 6 additions & 11 deletions src/types/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { AllPKMFields, Stats } from 'pokemon-files'
import { PK3RR } from "./SAVTypes/radicalred/PK3RR"

export interface OfficialPKMInterface extends PKMInterface {
pluginName?: undefined
pluginIdentifier?: undefined
pluginOrigin?: undefined
}

export interface PluginPKMInterface extends PKMInterface {
pluginName: string
pluginIdentifier: string
pluginOrigin: string
}

export type PKMInterface = AllPKMFields & {
getStats(): Stats
pluginName?: string
pluginIdentifier?: string
pluginOrigin?: string
isLocked?: boolean
}

export type PluginPKM =
| PK3RR


export type PluginPKMType =
| typeof PK3RR
15 changes: 8 additions & 7 deletions src/types/pkm/OHPKM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ import {
writeIVsToBuffer,
} from './util'

const FILE_SIZE = 455
const FILE_SIZE = 497

export class OHPKM implements PKMInterface {
static fromBytes(bytes: ArrayBuffer) {
return new OHPKM(new Uint8Array(bytes))
}

public get fileSize() {
return 433
return FILE_SIZE
}

get markingCount(): number {
Expand All @@ -81,7 +81,7 @@ export class OHPKM implements PKMInterface {
}

bytes: Uint8Array = new Uint8Array(FILE_SIZE)
pluginName: undefined
pluginIdentifier: undefined

constructor(arg: PKMInterface | PluginPKMInterface | OHPKM | Uint8Array) {
if (arg instanceof Uint8Array) {
Expand Down Expand Up @@ -119,8 +119,8 @@ export class OHPKM implements PKMInterface {
this.nickname = other.nickname
this.language = other.language
this.gameOfOrigin = other.gameOfOrigin
if (other.pluginName) {
this.pluginOrigin = other.pluginName
if (other.pluginIdentifier) {
this.pluginOrigin = other.pluginIdentifier
}
this.isEgg = other.isEgg ?? false
this.pokerusByte = other.pokerusByte ?? 0
Expand Down Expand Up @@ -194,7 +194,7 @@ export class OHPKM implements PKMInterface {
this.abilityIndex = AbilityFromString(this.ability)

this.isShadow = other.isShadow ?? false

this.encryptionConstant =
other.encryptionConstant ?? other.personalityValue ?? prng.nextInt(0, 0xffffffff)

Expand Down Expand Up @@ -1145,7 +1145,8 @@ export class OHPKM implements PKMInterface {

public set pluginOrigin(value: string) {
const utfBytes = utf16StringToBytes(value, 32)
this.bytes.set(utfBytes, 0x1b1)
console.log(utfBytes.length, this.bytes.length, this.bytes.length - 433)
this.bytes.set(utfBytes, 433)
}

public get country() {
Expand Down

0 comments on commit 68fa93f

Please sign in to comment.