Welcome to Data Crystal's new home! Data Crystal is now part of the TCRF family (sort of).
The wiki has recently moved; please report any issues in Discord. Pardon the dust.

Pokémon Ranger/Notes

From Data Crystal
Jump to navigation Jump to search

Chip tiny.png The following article is a Notes Page for Pokémon Ranger.

Pokemon structure

The following describes the data structure used to represent pokemon in battles. Not sure if it's also used in the overworld.

Offset Size Description

0x78	4	scaleX
0x7C	4 	scaleY
0x80	4 	scaleZ
0x3B4	4 	velocityX
0x3B8	4 	velocityY
0x3BC	4 	velocityZ
0x4B8	4 	csvData: pointer to constant mon specific data loaded from pokemon_csv.cat
0x5f0	1 	enteiFlameShield: number of flames around Entei in the last fight
0x618	2 	state
0x61a	2 	substate: used in some of the state functions
0x62B	1 	enableGlow: when true, the mon turns white
0x636	1 	invulnerable: when true, loops don't do anything
0x637	1 	when true, enables run button and draws bubble around mon
0x63C	1 	forceGlowFrame: when true, causes enableGlow to be set for one frame
0x63D	1 	loopcount: this is also stored elsewhere outside of this structure
0x63E	1 	maxLoopcount
0x640	1 	collidesWithStyler
0x70C	2 	bonus

Here are some functions that operate on this structure:

Address		Function/Description

0203e1a8	void updateMon(mon*) - runs every frame, selects function to run based on mon->state
02043f8c	bool isMonCaptureComplete(mon*) - returns true if pokemon's loop count has been met
0203fdf4	bool isMonTransformedDeoxys(mon*) - returns true if pokemon is deoxys and not in normal form
0203cd98	void tryApplyMonGlow(mon*) - decides every frame whether mon->enableGlow should be set to 0 or 1
02044044	int getCapturePercentage(mon*) - returns 100 if capture is complete, 0 otherwise
02044038	int getMonRequiredLoops(mon*) - reads required loop count from mon->csvData
02044064	char getMonField_66A(mon*) - no idea what this field is
02044264	void setMonLoopcount(mon*, int loopCount, int) - this runs every time a loop is completed
020441fc	void tryResetMonCaptureData(mon*) - loopcount is reset here
02035760	void monStateBubble(mon*, int*) - function for state 0x5C, used when pokemon is in stun bubble and when capture has been completed
02028814	void displayMonOkText(void*, mon*) - displays "OK" text on mon, called after it has been captured
0203fd6c	void setMonState(mon*, int state) - sets mon->state and some other fields

Loop related

These functions are related to the loop mechanic

Address		Function/Description

02021130	void updateLoops(void*, int, mon*, int*, int) - called every time a loop has been completed, loop count is incremented and reset here
020222a8	- called when capture line is broken, or the player lets go of stylus after drawing loop(s)
0203fb9c	- called when loop collides with pokemon and breaks
0203fbd8	- called when player lets go of stylus after drawing loop(s)


The game handles graphics with a command system. Commands are added to a queue, and they're executed later. Each command is an int array where the first value is the type of the command and the following values are parameters. The number of parameters used depends on the command type.

A pointer to the queue can be found at 0x20f5008, the queue is structured like:

Offset Size Description

0x0	1	skip_commands: if true, the queue is not executed
0x1	1	set to true after tryRunGfxCommands
0x4	4	size
0x8	4	currentIndex
0xC	??	commands: each one is 0x18 bytes

Related functions:

Address		Function/Description

020b6780	void execGfxCommand(gfxQueue*, int* cmd) - executes a single graphics command
020b6550	void runGfxCommands(gfxQueue*) - executes all graphics commands on the queue
020b6524	void tryRunGfxCommands(gfxQueue*) - calls above if !skip_commands

Here are functions for adding commands to the queue:

Address		Function/Description

020b6750	void addGfxCmd_0param(gfxQueue*, int type)
020b6714	void addGfxCmd_1param(gfxQueue*, int type, int p1)
020b66c8	void addGfxCmd_2param(gfxQueue*, int type, int p1, int p2)
020b6674	void addGfxCmd_3param(gfxQueue*, int type, int p1, int p2, int p3)
020b6618	void addGfxCmd_4param(gfxQueue*, int type, int p1, int p2, int p3, int p4)
020b65b4	void addGfxCmd_5param(gfxQueue*, int type, int p1, int p2, int p3, int p4, int p5)

There are also wrapper functions for the different command types, that utilize these addGfxCmd_* functions.

Other functions

Address		Function/Description

020d8bd4	int divmod(int a, int b) - returns (a/b) in r0 and (a%b) in r1
020d5a74	int strlen(char*)
020d580c	int strcmp(char*, char*)
020b20e8	void* malloc(int)
020b20b0	void free(void*)
020b2118	void* other_malloc(int) - for a different heap?
020b20cc 	void other_free(void*)
02000304	void vBlankIntrWait()
020991c4	void loadChar(textPrinter*) - loads tiles and tilemap for a single character of text, not used for all types of text