From 1dbdc159387eb0d5efcc40f70c8873316591f280 Mon Sep 17 00:00:00 2001 From: Andrew Benington Date: Sun, 17 Nov 2024 14:32:12 -0600 Subject: [PATCH 1/3] add plugin name to PK3RR --- src/types/SAVTypes/radicalred/PK3RR.ts | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/types/SAVTypes/radicalred/PK3RR.ts b/src/types/SAVTypes/radicalred/PK3RR.ts index e20a1b94..491c22e1 100644 --- a/src/types/SAVTypes/radicalred/PK3RR.ts +++ b/src/types/SAVTypes/radicalred/PK3RR.ts @@ -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' @@ -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' + pluginName = 'radical_red' personalityValue: number trainerID: number secretID: number @@ -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) { @@ -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( @@ -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 From 66890e8bf247584d7c142a7ff51defc9bf2361df Mon Sep 17 00:00:00 2001 From: Andrew Benington Date: Sun, 17 Nov 2024 14:59:39 -0600 Subject: [PATCH 2/3] fix pluginOrigin field --- src/renderer/images/images.ts | 2 +- src/renderer/pokemon/MetDataMovesDisplay.tsx | 9 ++++++++- src/renderer/saves/util.ts | 6 +++--- src/types/SAVTypes/radicalred/PK3RR.ts | 2 +- src/types/SAVTypes/util.ts | 4 ++++ src/types/interfaces.ts | 18 +++++++++--------- src/types/pkm/OHPKM.ts | 15 ++++++++------- 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/renderer/images/images.ts b/src/renderer/images/images.ts index 07e2fd32..9059907a 100644 --- a/src/renderer/images/images.ts +++ b/src/renderer/images/images.ts @@ -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) } } diff --git a/src/renderer/pokemon/MetDataMovesDisplay.tsx b/src/renderer/pokemon/MetDataMovesDisplay.tsx index b0cb3bdf..defde6ff 100644 --- a/src/renderer/pokemon/MetDataMovesDisplay.tsx +++ b/src/renderer/pokemon/MetDataMovesDisplay.tsx @@ -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' @@ -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) { diff --git a/src/renderer/saves/util.ts b/src/renderer/saves/util.ts index cf98fd40..bd693966 100644 --- a/src/renderer/saves/util.ts +++ b/src/renderer/saves/util.ts @@ -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) { diff --git a/src/types/SAVTypes/radicalred/PK3RR.ts b/src/types/SAVTypes/radicalred/PK3RR.ts index 491c22e1..9a39a0fe 100644 --- a/src/types/SAVTypes/radicalred/PK3RR.ts +++ b/src/types/SAVTypes/radicalred/PK3RR.ts @@ -45,7 +45,7 @@ const FAKEMON_INDEXES = [ export class PK3RR { format: 'PK3RR' = 'PK3RR' - pluginName = 'radical_red' + pluginIdentifier = 'radical_red' personalityValue: number trainerID: number secretID: number diff --git a/src/types/SAVTypes/util.ts b/src/types/SAVTypes/util.ts index bce45723..452317eb 100644 --- a/src/types/SAVTypes/util.ts +++ b/src/types/SAVTypes/util.ts @@ -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) diff --git a/src/types/interfaces.ts b/src/types/interfaces.ts index 6b2be46f..417cebaa 100644 --- a/src/types/interfaces.ts +++ b/src/types/interfaces.ts @@ -1,23 +1,23 @@ import { AllPKMFields, Stats } from 'pokemon-files' -import { PK3RR } from "./SAVTypes/radicalred/PK3RR" +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 PluginPKM = PK3RR - -export type PluginPKMType = - | typeof PK3RR +export type PluginPKMType = typeof PK3RR diff --git a/src/types/pkm/OHPKM.ts b/src/types/pkm/OHPKM.ts index 34072971..fe486d44 100644 --- a/src/types/pkm/OHPKM.ts +++ b/src/types/pkm/OHPKM.ts @@ -57,7 +57,7 @@ import { writeIVsToBuffer, } from './util' -const FILE_SIZE = 455 +const FILE_SIZE = 497 export class OHPKM implements PKMInterface { static fromBytes(bytes: ArrayBuffer) { @@ -65,7 +65,7 @@ export class OHPKM implements PKMInterface { } public get fileSize() { - return 433 + return FILE_SIZE } get markingCount(): number { @@ -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) { @@ -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 @@ -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) @@ -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() { From 88885db038d78b453d9c21722f80564cef8d2fee Mon Sep 17 00:00:00 2001 From: Andrew Benington Date: Sun, 17 Nov 2024 15:00:26 -0600 Subject: [PATCH 3/3] remove unnecessary types --- src/renderer/components/InfoGrid.tsx | 3 +-- src/types/interfaces.ts | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/renderer/components/InfoGrid.tsx b/src/renderer/components/InfoGrid.tsx index b88af92f..73fd0db7 100644 --- a/src/renderer/components/InfoGrid.tsx +++ b/src/renderer/components/InfoGrid.tsx @@ -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' @@ -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 } diff --git a/src/types/interfaces.ts b/src/types/interfaces.ts index 417cebaa..d12b1c01 100644 --- a/src/types/interfaces.ts +++ b/src/types/interfaces.ts @@ -1,5 +1,4 @@ import { AllPKMFields, Stats } from 'pokemon-files' -import { PK3RR } from './SAVTypes/radicalred/PK3RR' export interface OfficialPKMInterface extends PKMInterface { pluginIdentifier?: undefined @@ -17,7 +16,3 @@ export type PKMInterface = AllPKMFields & { pluginOrigin?: string isLocked?: boolean } - -export type PluginPKM = PK3RR - -export type PluginPKMType = typeof PK3RR