Framerects
Sprites and such

A sprite is any little picture that may (or may not) move across the screen in a videogame. For example, Quote has a jumping sprite, a standing sprite, etc.

Pretty much every NPC in Cavestory will use framerects, or numbers that determine the borders of that NPC's sprites.

Such NPCs will use sprites taken from spritesheets, such as NpcSym.

NpcSym

Now, let's take a look at the Pot entity, which is NPC #78. The offset is 4367E0 if you look it up in the compendium.
Here I've highlighted the rects in green:
Address   Command                          Comments
004367E0  PUSH EBP
004367E1  MOV EBP,ESP
004367E3  SUB ESP,20
004367E6  MOV DWORD PTR SS:[EBP-20],0A0    ;these are the framerects.
004367ED  MOV DWORD PTR SS:[EBP-1C],30
004367F4  MOV DWORD PTR SS:[EBP-18],0B0
004367FB  MOV DWORD PTR SS:[EBP-14],40
00436802  MOV DWORD PTR SS:[EBP-10],0B0
00436809  MOV DWORD PTR SS:[EBP-0C],30
00436810  MOV DWORD PTR SS:[EBP-8],0C0
00436817  MOV DWORD PTR SS:[EBP-4],40
0043681E  MOV EAX,DWORD PTR SS:[EBP+8]
00436821  CMP DWORD PTR DS:[EAX+4C],0
00436825  JNE SHORT 00436846
00436827  MOV ECX,DWORD PTR SS:[EBP+8]
0043682A  ADD ECX,54
0043682D  MOV EDX,DWORD PTR SS:[EBP-20]
00436830  MOV DWORD PTR DS:[ECX],EDX
00436832  MOV EAX,DWORD PTR SS:[EBP-1C]
00436835  MOV DWORD PTR DS:[ECX+4],EAX
00436838  MOV EDX,DWORD PTR SS:[EBP-18]
0043683B  MOV DWORD PTR DS:[ECX+8],EDX
0043683E  MOV EAX,DWORD PTR SS:[EBP-14]
00436841  MOV DWORD PTR DS:[ECX+0C],EAX
00436844  JMP SHORT 00436863
00436846  MOV ECX,DWORD PTR SS:[EBP+8]
00436849  ADD ECX,54
0043684C  MOV EDX,DWORD PTR SS:[EBP-10]
0043684F  MOV DWORD PTR DS:[ECX],EDX
00436851  MOV EAX,DWORD PTR SS:[EBP-0C]
00436854  MOV DWORD PTR DS:[ECX+4],EAX
00436857  MOV EDX,DWORD PTR SS:[EBP-8]
0043685A  MOV DWORD PTR DS:[ECX+8],EDX
0043685D  MOV EAX,DWORD PTR SS:[EBP-4]
00436860  MOV DWORD PTR DS:[ECX+0C],EAX
00436863  MOV ESP,EBP
00436865  POP EBP
00436866  RETN
Well look at that. [EBP-4], [EBP-8], [EBP-C], and so on. The framerect values are being MOVed into local variables!

The rects are nothing but a set of numbers, as follows:
A0,30,B0,40,B0,30,C0,40
All of those numbers are in hexadecimal format. Let's convert them to decimal:
160,48,176,64,176,48,192,64
Well, that's not helpful. What do these numbers mean?

MS Paint
Open up NpcSym.pbm (or NpcSym.bmp, if you set it up that way) using Microsoft Paint.

First, go to the Magnification Tool and zoom in a few times until the picture is sufficiently big. Then, go to the Paintbrush Tool and select a line thickness of 1-pixel. We're not going to edit anything, but I want you to pay close attention to the little coordinate system on the bottom panel of the program.

Finding Rect Coordinates

You can think of the framerects as the borders of the sprites of any Cavestory NPC:

Rects Explained

Notice that this corresponds perfectly with our set of numbers: 160,48,176,64,176,48,192,64

We've concluded that the Pot entity contains 2 sprites, a big pot and a small pot.
Address   Instruction                           Comments
004367E6  MOV DWORD PTR SS:[EBP-20],0A0         ;left border of sprite 1 (big pot)
004367ED  MOV DWORD PTR SS:[EBP-1C],30          ;upper border of sprite 1
004367F4  MOV DWORD PTR SS:[EBP-18],0B0         ;right border of sprite 1
004367FB  MOV DWORD PTR SS:[EBP-14],40          ;bottom border of sprite 1
00436802  MOV DWORD PTR SS:[EBP-10],0B0         ;left border of sprite 2 (small pot)
00436809  MOV DWORD PTR SS:[EBP-0C],30          ;upper border of sprite 2
00436810  MOV DWORD PTR SS:[EBP-8],0C0          ;right border of sprite 2
00436817  MOV DWORD PTR SS:[EBP-4],40           ;bottom border of sprite 2
The framerect borders for any entity will be in the order {left, upper, right, lower}, with each framerect listed one after the other. By editing these rects, you can change the sprites of any NPC to your liking. This is especially important when making custom NPCs, when you have to specify your own rects.

Not only NPCs use rects. Weapons, bullets, and basically anything else that has a sprite will also use framerects.

Navigation
Previous Lesson: Local and Global Variables
Next Lesson: Binary
Table of Contents