Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document pokemon.c and Pokemon data structs #47

Merged
merged 11 commits into from
Sep 14, 2023

Conversation

wildfire248
Copy link
Contributor

@wildfire248 wildfire248 commented Sep 5, 2023

There's still a lot of work to be done on this but there's also already too much here and I don't know how to split it up in a way that makes sense to read so I'm just PR'ing as is for now while I continue working on it.

Added Doxygen comments to most of the functions in pokemon.h and the structs.

(Edit: There's been some more renames and a good few structural changes since initial PR)

Deleted Files

  • include/
    • struct_decls/
      • party_pokemon.h
      • struct_02075874_decl.h
      • struct_0207821C_decl.h
      • struct_0207821C_sub1_decl.h
    • struct_defs/
      • box_pokemon.h
      • party_pokemon.h
      • pokemon.h
      • pokemon_substruct_0.h
      • pokemon_substruct_1.h
      • pokemon_substruct_2.h
      • pokemon_substruct_3.h
      • struct_02075874.h
      • struct_0207821C.h
      • struct_0207821C_sub1.h
      • struct_0207825C.h
      • struct_0207825C_{1..23}.h

Renamed Files

  • include/
    • unk_02073C2C.h -> pokemon.h
  • src/
    • unk_02073C2C.c -> pokemon.c

Deleted Structs

  • include/struct_defs/
    • struct_0207825C.h
      • UnkStruct_0207825C
    • struct_0207825C_{1..23}.h
      • UnkStruct_0207825C_{1..23}

Moved Structs

  • include/struct_defs/
    • box_pokemon.h
      • BoxPokemon -> include/pokemon.h
    • party_pokemon.h
      • PartyPokemon -> include/pokemon.h
    • pokemon.h`
      • Pokemon -> include/pokemon.h
    • pokemon_substruct_0.h
      • PokemonSubstruct0 -> include/pokemon.h (renamed PokemonDataBlockA)
    • pokemon_substruct_1.h
      • PokemonSubstruct1 -> include/pokemon.h (renamed PokemonDataBlockB)
    • pokemon_substruct_2.h
      • PokemonSubstruct2 -> include/pokemon.h (renamed PokemonDataBlockC)
    • pokemon_substruct_3.h
      • PokemonSubstruct3 -> include/pokemon.h (renamed PokemonDataBlockD)
    • struct_02075874.h
      • UnkStruct_02075874 -> include/pokemon.h (renamed PokemonPersonalData)
    • struct_0207821C.h
      • UnkStruct_0207821C -> src/pokemon.c (renamed PokemonEvolutionData)
    • struct_0207821C_sub1.h
      • UnkStruct_0207821C_sub1 -> src/pokemon.c (renamed PokemonEvolutionMethod)

Edited Structs,Enums,Constants,Globals

  • include/
    • constants/
      • pokemon.h
        • New enum PokemonType: replaces block of #defines
        • New enum PokemonStats: IDs for mon stats (HP, Atk, etc.)
        • New enum PokemonGender: IDs for mon gender
        • Edited enum PokemonDataParam: used to be anonymous enum
        • New enum PokemonPersonalDataParam: IDs for getting values from PokemonPersonalData funcs
    • struct_defs/
      • struct_02078B40.h
        • Edited struct UnkStruct_02078B40: renamed fields, contains pokemon data
    • pokemon.h
      • Moved,Edited struct PokemonPersonalData: Data shared across all mons of the same species/form (base stats, gender chance etc.)
      • Moved,Edited struct PokemonDataBlock{A/B/C/D}: Boxed Pokemon data blocks
      • New union PokemonDataBlock: For array dataBlocks in BoxPokemon
      • Moved,Edited struct BoxPokemon: renamed all but one (unused/padding) field
      • Moved,Edited struct PartyPokemon: renamed field unk_04 -> level
      • Moved struct Pokemon:
  • src/
    • pokemon.c
      • Renamed static const s8 Unk_020F0695[][5] -> sNatureFlavorAffinities: Mapping from pokemon natures to liked/disliked flavors
      • Moved,Edited struct PokemonEvolutionMethod: Pokemon evolution method
      • Moved,Edited struct PokemonEvolutionData: Data table for storing a pokemons possible evolution methods
      • New static enum PokemonDataBlockID: For getting data blocks from a BoxPokemon
      • New static enum PokemonGenderRatio: Special values for pokemon gender ratio
      • Renamed static const s8 Unk_020F0618[][5] -> sNatureStatAffinities: Mapping from pokemon natures to increased/decreased stats
      • Renamed static const u16 Unk_020F0574[][2] -> sHeldItemChance: Chances of a wild pokemon holding an item
    • unk_0201D15C.c
      • Renamed u32 Unk_021BFB14 -> gLCRNG_State: State for the Linear Congruential RNG
      • Renamed static u32 Unk_021BFB18[624] -> sMTRNG_State: State for the Mersenne Twister RNG
      • Renamed static int Unk_02100834 -> sMTRNG_Size: Size of Mersenne Twister State
      • Renamed static u32 Unk_02100838[2] -> sMTRNG_Xor: Constants for Mersenne Twister RNG

Edited Functions

  • include/
    • unk_0201D15C.h:
      • sub_0201D608 -> LCRNG_NextFrom
      • sub_0201D2D0 -> LCRNG_GetSeed
      • sub_0201D2DC -> LCRNG_SetSeed
      • sub_0201D2E8 -> LCRNG_Next
      • sub_0201D30C -> ARNG_Next
      • sub_0201D318 -> MTRNG_SetSeed
      • sub_0201D35C -> MTRNG_Next
      • sub_0201D5D4 -> EncryptData -> (planned: )
      • sub_0201D600 -> DecryptData -> (planned: )
    • pokemon.h:
      • ZeroMonData -> Pokemon_Init
      • ZeroBoxMonData -> BoxPokemon_Init
      • PokemonStructSize -> Pokemon_StructSize
      • AllocMonZeroed -> Pokemon_New
      • sub_02073C88 -> Pokemon_EnterDecryptionContext
      • sub_02073CD4 -> Pokemon_ExitDecryptionContext
      • sub_02073D20 -> BoxPokemon_EnterDecryptionContext
      • sub_02073D48 -> BoxPokemon_ExitDecryptionContext
      • sub_02073D80 ->
      • sub_02073E18 -> moved (static)
      • sub_02074044 ->
      • sub_02074088 ->
      • sub_02074128 ->
      • sub_02074158 ->
      • sub_0207418C -> Pokemon_CalcLevelAndStats
      • sub_020741B8 -> Pokemon_CalcStats
      • GetMonData -> Pokemon_GetValue
      • sub_02074570 -> BoxPokemon_GetValue
      • sub_02074B30 -> Pokemon_SetValue
      • SetBoxMonData -> BoxPokemon_SetValue
      • sub_0207536C -> Pokemon_IncreaseValue
      • sub_02075874 -> PokemonPersonalData_FromMonForm
      • sub_02075894 -> PokemonPersonalData_FromMonSpecies
      • sub_020758B0 -> PokemonPersonalData_GetValue
      • sub_020759B8 -> PokemonPersonalData_Free
      • sub_020759CC -> PokemonPersonalData_GetFormValue
      • sub_020759F0 -> PokemonPersonalData_GetSpeciesValue
      • sub_02075A10 -> Pokemon_GetPercentToNextLevel
      • sub_02075A70 -> Pokemon_GetExpToNextLevel
      • sub_02075A78 -> moved (static)
      • sub_02075AAC -> Pokemon_GetCurrentLevelBaseExp
      • sub_02075AD0 -> Pokemon_GetSpeciesBaseExpAt
      • sub_02075B38 -> Pokemon_GetLevel
      • sub_02075B40 -> BoxPokemon_GetLevel
      • sub_02075B78 -> Pokemon_GetSpeciesLevelAt
      • sub_02075B9C -> PokemonPersonalData_GetLevelAt
      • sub_02075BCC -> Pokemon_GetNature
      • sub_02075BD4 -> BoxPokemon_GetNature
      • GetNatureFromPersonality -> Pokemon_GetNatureOf
      • sub_02075C60 -> Pokemon_GetStatAffinityOf
      • sub_02075C74 ->
      • sub_02075D6C -> Pokemon_GetGender
      • sub_02075D74 -> BoxPokemon_GetGender
      • sub_02075DAC -> Pokemon_GetGenderOf
      • sub_02075DD0 -> PokemonPersonalData_GetGenderOf
      • sub_02075E0C -> Pokemon_IsShiny
      • sub_02075E14 -> moved (static)
      • sub_02075E38 -> Pokemon_IsPersonalityShiny
      • sub_02075E64 ->
      • sub_02075EF4 ->
      • sub_02075F00 ->
      • sub_02075F0C ->
      • sub_02075FB4 ->
      • SanitizeFormId -> Pokemon_SanitizeFormId
      • sub_020765AC ->
      • sub_020765B8 ->
      • sub_020765C4 ->
      • sub_02076648 ->
      • sub_0207697C ->
      • sub_02076994 ->
      • sub_02076AAC ->
      • sub_02076AF0 -> Pokemon_GetStructSize
      • sub_02076AF4 -> BoxPokemon_GetStructSize
      • sub_02076AF8 -> Pokemon_GetForm
      • sub_02076B00 -> BoxPokemon_GetForm
      • sub_02076B10 -> Pokemon_GetBoxPokemon
      • sub_02076B14 ->
      • sub_02076B94 ->
      • sub_02076F84 ->
      • sub_02076FD4 ->
      • sub_02077020 -> moved (static)
      • sub_020770C4 -> Pokemon_AddMove
      • sub_020770D4 -> moved (static)
      • sub_02077134 -> Pokemon_ReplaceMove
      • sub_02077144 -> moved (static)
      • sub_020771F8 -> Pokemon_ResetMoveSlot
      • sub_02077230 -> Pokemon_SetMoveSlot
      • sub_02077238 -> moved (static)
      • sub_0207727C ->
      • sub_02077344 -> Pokemon_SwapMoveSlots
      • sub_0207734C -> BoxPokemon_SwapMoveSlots
      • sub_02077408 -> Pokemon_ClearMoveSlot
      • sub_0207749C -> moved (static)
      • sub_020774C8 -> Pokemon_FromBoxPokemon
      • sub_02077550 -> Party_GetMaxLevel
      • sub_020775A4 ->
      • sub_020775C4 ->
      • sub_020775EC -> Pokemon_Copy
      • sub_02077604 -> BoxPokemon_Copy
      • sub_02077618 -> BoxPokemon_FromPokemon
      • sub_0207762C -> Pokemon_GetFlavorAffinity
      • sub_02077634 -> moved (static)
      • sub_02077648 -> Pokemon_GetFlavorAffinityOf
      • sub_02077660 -> Pokemon_LoadLevelUpMoveIdsOf
      • sub_020776B0 ->
      • sub_02077758 ->
      • sub_020777B4 ->
      • sub_0207782C ->
      • sub_020778D8 ->
      • sub_020778E0 -> moved (static)
      • sub_020778F8 ->
      • sub_02077900 -> moved (static)
      • sub_02077928 -> Pokemon_SetArceusForm
      • sub_02077930 -> BoxPokemon_SetArceusForm
      • sub_02077988 -> Pokemon_GetArceusTypeOf
      • sub_02077A00 -> Pokemon_SetGiratinaForm
      • sub_02077A1C -> BoxPokemon_SetGiratinaForm
      • sub_02077A64 -> Pokemon_SetGiratinaOriginForm
      • sub_02077A9C -> Party_SetGiratinaForm
      • SetShayminForm -> Pokemon_SetShayminForm
      • SetBoxShayminForm -> BoxPokemon_SetShayminForm
      • sub_02077B14 -> Pokemon_CanShayminSkyForm
      • sub_02077B8C -> Party_SetShayminLandForm
      • sub_02077BD8 -> Party_SetShayminForm
      • SetRotomForm -> Pokemon_SetRotomForm
      • sub_02077D28 -> Pokemon_LoadLevelUpMovesOf
      • sub_02077D3C ->
      • sub_02077DB4 ->
      • sub_02077E3C ->
      • sub_02077E64 ->
      • sub_02077EA4 -> moved (static)
      • sub_02077EE4 ->
      • sub_02077EF8 -> moved (static)
      • sub_02077F0C ->
      • sub_02077FB4 -> Pokemon_CanLearnTM
      • sub_02077FBC -> moved (static)
      • sub_02077FE4 -> Pokemon_CanFormLearnTM
      • sub_0207803C -> Pokemon_CalcAbility
      • sub_02078044 -> moved (static)
      • sub_020780C4 ->
      • sub_020787CC -> Pokemon_GetFlagMaskOf
      • sub_020787EC -> Pokemon_GetLowestFlagIndex
      • sub_02078804 ->
      • sub_02078824 ->
      • sub_02078838 ->
      • sub_0207884C ->
      • sub_020788D0 ->
      • sub_0207893C ->
      • sub_0207896C ->
      • sub_020789BC ->
      • sub_020789F4 ->
      • sub_02078A4C ->
      • sub_02078A80 ->
      • sub_02078AA4 ->
      • sub_02078AC8 ->
      • sub_02078AEC ->
      • sub_02078B40 ->
      • sub_02078E0C ->
  • src/pokemon.c:
    • Moved sub_02073E18 ->
    • sub_020744E8 -> Pokemon_GetDataInternal
    • sub_020745D0 -> BoxPokemon_GetDataInternal
    • sub_02074BC0 -> Pokemon_SetDataInternal
    • sub_02074CD8 -> BoxPokemon_SetDataInternal
    • sub_020753F4 -> Pokemon_IncreaseDataInternal
    • sub_02075454 -> BoxPokemon_IncreaseDataInternal
    • Moved sub_02075A78 -> BoxPokemon_GetExpToNextLevel
    • sub_02075AE4 -> Pokemon_LoadExperienceTableOf
    • sub_02075B00 -> Pokemon_GetExpRateBaseExpAt
    • sub_02075C0C -> Pokemon_GetNatureStatValue
    • Moved sub_02075E14 -> BoxPokemon_IsShiny
    • New -> inline Pokemon_InlineIsPersonalityShiny
    • sub_02076300 ->
    • sub_020767BC ->
    • Moved sub_02077020 -> BoxPokemon_SetDefaultMoves
    • Moved sub_020770D4 -> BoxPokemon_AddMove
    • Moved sub_02077144 -> BoxPokemon_ReplaceMove
    • Moved sub_02077238 -> BoxPokemon_SetMoveSlot
    • Moved sub_0207749C -> Pokemon_HasMove
    • Moved sub_02077634 -> BoxPokemon_GetFlavorAffinity
    • Moved sub_020778E0 ->
    • Moved sub_02077900 ->
    • Moved sub_02077EA4 ->
    • Moved sub_02077EF8 ->
    • Moved sub_02077FBC -> BoxPokemon_CanLearnTM
    • Moved sub_02078044 -> BoxPokemon_CalcAbility
    • sub_020781F8 -> PokemonPersonalData_LoadSpecies
    • sub_02078208 -> PokemonPersonalData_LoadForm
    • sub_0207821C -> PokemonEvolutionData_LoadSpecies
    • sub_0207822C -> Pokemon_EncryptData
    • sub_02078234 -> Pokemon_DecryptData
    • sub_0207823C -> Pokemon_GetDataChecksum
    • sub_0207825C -> BoxPokemon_GetDataBlock
    • sub_02078740 -> Pokemon_GetFormNarcIndex
    • inline_020789BC -> inline Pokemon_GetLowestBitInverse

@wildfire248 wildfire248 marked this pull request as ready for review September 5, 2023 12:07
Copy link
Collaborator

@lhearachel lhearachel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, try to separate out mass-renames as a separate commit from manual cleanup work. Makes these big reviews much more manageable, as I can just skim over those commits and focus on the meat of your changes.

include/constants/pokemon.h Outdated Show resolved Hide resolved
include/constants/pokemon.h Outdated Show resolved Hide resolved
include/pokemon.h Outdated Show resolved Hide resolved
include/pokemon.h Outdated Show resolved Hide resolved
include/pokemon.h Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
@luckytyphlosion
Copy link
Member

Probably look at pret/pokeheartgold#213 on how to name functions.

@luckytyphlosion
Copy link
Member

The list of renamed functions should also contain static functions as well.

src/pokemon.c Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
src/pokemon.c Outdated Show resolved Hide resolved
@luckytyphlosion
Copy link
Member

From the discussion in Discord:

  • Decrypt(Box)?Mon -> (Box)?Mon_EnterDecryptionContext
  • Encrypt(Box)?Mon -> (Box)?Mon_ExitDecryptionContext
  • DecryptMonData -> Mon_DecryptData
  • EncryptMonData -> Mon_EncryptData

@luckytyphlosion
Copy link
Member

BOOL encrypt is probably BOOL alreadyInContext

@wildfire248
Copy link
Contributor Author

because I'm not sure how to name a lot of these consistently, i made a list of all the functions in pokemon.c and their counterparts in dp and hgss
I put suggestions for a bunch of them (both my own and ones from here) and some general notes
this was just hand done by scrolling each of the files so there might be a couple errors? I don't know how to try match them programmatically
https://gist.github.com/wildfire248/353f21af99e1c66349bc208e19625f8e

@Nomura-RH Nomura-RH merged commit 7d42f39 into pret:main Sep 14, 2023
1 check passed
@wildfire248 wildfire248 deleted the mon_data branch September 24, 2023 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants