Cavestory Mod API
Macros | Functions
Math

In-house math functions. More...

Macros

#define CSM_GETRED(x)   (unsigned char)((x) & 0xFF)
 Get the red value from an unsigned int color. More...
 
#define CSM_GETGREEN(x)   (unsigned char)(((x) >> 8) & 0xFF)
 Get the green value from an unsigned int color. More...
 
#define CSM_GETBLUE(x)   (unsigned char)(((x) >> 16) & 0xFF)
 Get the blue value from an unsigned int color. More...
 
#define CSM_GETALPHA(x)   (unsigned char)(((x) >> 24) & 0xFF)
 Get the alpha value from an unsigned int color. More...
 
#define CSM_RGBA(r, g, b, a)   ((r) | ((g) << 8) | ((b) << 16) | ((a) << 24))
 Combine R, G, B, A into one number. More...
 
#define CSM_RGB(r, g, b)   ((r) | ((g) << 8) | ((b) << 16) | (0xFF << 24))
 Combine R, G, B into one number. More...
 
#define SET_RECT(rect, l, t, r, b)
 Set a RECT object's values. More...
 
#define MAX(A, B)   ((A) > (B) ? (A) : (B))
 Get the maximum value between two values. More...
 
#define MIN(A, B)   ((A) < (B) ? (A) : (B))
 Get the minimum value between two values. More...
 
#define CLAMP(x, min, max)   ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
 Clamp a value. More...
 

Functions

CAVESTORY_MOD_API int Random (int iMin, int iMax)
 Get a random value. More...
 
CAVESTORY_MOD_API int GetCos (unsigned char iDeg)
 Calculate cos. More...
 
CAVESTORY_MOD_API int GetSin (unsigned char iDeg)
 Calculate sin. More...
 
CAVESTORY_MOD_API unsigned char GetArktan (int iX, int iY)
 Get arktan from x and y. More...
 
CAVESTORY_MOD_API bool IsNpcOnScreen (NPCHAR *pNpc)
 Check if an NPC is on screen. More...
 
CAVESTORY_MOD_API void CSM_Npc_GetPosition (NPCHAR *pNpc, NpcPositionType iType=NpcPositionType::NPT_DRAW_POSITION, int *iOutX=NULL, int *iOutY=NULL, int iFrameX=-1, int iFrameY=-1)
 Get the draw position of an NPC. More...
 
CAVESTORY_MOD_API void CSM_Npc_SkipUpdate (NPCHAR *pNpc)
 Skip one NPC update for a specific NPC. More...
 
CAVESTORY_MOD_API unsigned long long int CSM_Npc_GetTransmitNodes (unsigned int iCodeChar, int iActNo)
 Get the transmit nodes for a specific NPC type. More...
 
CAVESTORY_MOD_API unsigned long long int CSM_Npc_GetUpdateNodes (unsigned int iCodeChar, int iActNo)
 Get the update nodes for a specific NPC type. More...
 
CAVESTORY_MOD_API void GetMyCharDrawRectangle (MYCHAR *pMC, GUI_RECT *pOut)
 Get the draw rectangle of a MYCHAR. More...
 
CAVESTORY_MOD_API void CSM_Weapon_GetDrawOffset (MYCHAR *pMC, int iWeaponCode, GUI_POINT *pOut)
 Get the draw offset of a player's weapon. More...
 
CAVESTORY_MOD_API void CSM_Puppy_GetDrawOffset (MYCHAR *pMC, GUI_POINT *pOut)
 Get the held entity offset of a player's current frame. More...
 
CAVESTORY_MOD_API void CSM_Carry_GetDrawOffset (MYCHAR *pMC, GUI_POINT *pOut)
 Get the carried player offset of a player's current frame. More...
 
int SubpixelToScreenCoord (int iCoord)
 Convert a subpixel coordinate to screen coordinate. More...
 
int PixelToScreenCoord (int iCoord)
 Convert a pixel to a screen cordinate. More...
 
int ScreenCoordToPixel (int iCoord)
 Convert a screen cordinate to a pixel. More...
 
int ScreenCoordToSubPixel (int iCoord)
 Convert a screen cordinate to a subpixel. More...
 
CAVESTORY_MOD_API int CSM_GetWindowWidth ()
 Get the current window width. More...
 
CAVESTORY_MOD_API int CSM_GetWindowHeight ()
 Get the current window height. More...
 
CAVESTORY_MOD_API void CSM_SetBitmapLoadMagnification (int iMagnification)
 Set the magnification of all loaded bitmaps beyond this point. More...
 

Detailed Description

In-house math functions.

Several helpful in-house math functions.

Macro Definition Documentation

◆ CLAMP

#define CLAMP (   x,
  min,
  max 
)    ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))

Clamp a value.

Parameters
xThe value to clamp.
minThe minimum allowed value.
maxThe maximum allowed value.
Returns
Returns the 'x' value clamped between 'min' and 'max'.

◆ CSM_GETALPHA

#define CSM_GETALPHA (   x)    (unsigned char)(((x) >> 24) & 0xFF)

Get the alpha value from an unsigned int color.

Parameters
xThe number.
Returns
Returns an 'unsigned char' of the alpha value.
See also
CSM_RGBA
CSM_RGB

◆ CSM_GETBLUE

#define CSM_GETBLUE (   x)    (unsigned char)(((x) >> 16) & 0xFF)

Get the blue value from an unsigned int color.

Parameters
xThe number.
Returns
Returns an 'unsigned char' of the blue value.
See also
CSM_RGBA
CSM_RGB

◆ CSM_GETGREEN

#define CSM_GETGREEN (   x)    (unsigned char)(((x) >> 8) & 0xFF)

Get the green value from an unsigned int color.

Parameters
xThe number.
Returns
Returns an 'unsigned char' of the green value.
See also
CSM_RGBA
CSM_RGB

◆ CSM_GETRED

#define CSM_GETRED (   x)    (unsigned char)((x) & 0xFF)

Get the red value from an unsigned int color.

Parameters
xThe number.
Returns
Returns an 'unsigned char' of the red value.
See also
CSM_RGBA
CSM_RGB

◆ CSM_RGB

#define CSM_RGB (   r,
  g,
 
)    ((r) | ((g) << 8) | ((b) << 16) | (0xFF << 24))

Combine R, G, B into one number.

Parameters
rThe red value.
gThe green value.
bThe blue alpha.
Returns
Returns an 'unsigned int' of 'r', 'g' and 'b' being combined.

◆ CSM_RGBA

#define CSM_RGBA (   r,
  g,
  b,
 
)    ((r) | ((g) << 8) | ((b) << 16) | ((a) << 24))

Combine R, G, B, A into one number.

Parameters
rThe red value.
gThe green value.
bThe blue alpha.
aThe alpha alpha.
Returns
Returns an 'unsigned int' of 'r', 'g', 'b' and 'a' being combined.
Examples
RenderPipeline.cpp.

◆ MAX

#define MAX (   A,
 
)    ((A) > (B) ? (A) : (B))

Get the maximum value between two values.

Parameters
AThe first value.
BThe second value.
Returns
Returns 'A' if 'A' is greater than 'B', otherwise returns 'B'.

◆ MIN

#define MIN (   A,
 
)    ((A) < (B) ? (A) : (B))

Get the minimum value between two values.

Parameters
AThe first value.
BThe second value.
Returns
Returns 'A' if 'A' is less than 'B', otherwise returns 'B'.

◆ SET_RECT

#define SET_RECT (   rect,
  l,
  t,
  r,
 
)
Value:
rect.left = l; \
rect.top = t; \
rect.right = r; \
rect.bottom = b;

Set a RECT object's values.

Parameters
rectThe rect to set.
lLeft (X) value.
tTop (Y) value.
rRight (X + W) value.
bBottom (Y + H) value.

Function Documentation

◆ CSM_Carry_GetDrawOffset()

CAVESTORY_MOD_API void CSM_Carry_GetDrawOffset ( MYCHAR pMC,
GUI_POINT pOut 
)

Get the carried player offset of a player's current frame.

Parameters
pMCThe player.
pOutThe point to hold the carried player's draw offset.
Returns
Returns the draw position.
Note
This function returns magnified, non-subpixel coordinates relative to the player's topleft coordinates. All you need to do is add the player's draw position.

◆ CSM_GetWindowHeight()

CAVESTORY_MOD_API int CSM_GetWindowHeight ( )

Get the current window height.

Returns
Returns the window height.

◆ CSM_GetWindowWidth()

CAVESTORY_MOD_API int CSM_GetWindowWidth ( )

Get the current window width.

Returns
Returns the window width.

◆ CSM_Npc_GetPosition()

CAVESTORY_MOD_API void CSM_Npc_GetPosition ( NPCHAR pNpc,
NpcPositionType  iType = NpcPositionType::NPT_DRAW_POSITION,
int *  iOutX = NULL,
int *  iOutY = NULL,
int  iFrameX = -1,
int  iFrameY = -1 
)

Get the draw position of an NPC.

Parameters
pNpcThe NPC to get the position of.
iTypeThe type of position to get.
iOutXA pointer to an int that will hold the X position. Can be NULL.
iOutYA pointer to an int that will hold the Y position. Can be NULL.
iFrameXThe current frame. If left as '-1', it will use 'gFrame.x'.
iFrameYThe current frame. If left as '-1', it will use 'gFrame.y'.

◆ CSM_Npc_GetTransmitNodes()

CAVESTORY_MOD_API unsigned long long int CSM_Npc_GetTransmitNodes ( unsigned int  iCodeChar,
int  iActNo 
)

Get the transmit nodes for a specific NPC type.

Parameters
iCodeCharThe character code.
iActNoThe act number the NPC is on.
Returns
Returns the transmit node flags.

◆ CSM_Npc_GetUpdateNodes()

CAVESTORY_MOD_API unsigned long long int CSM_Npc_GetUpdateNodes ( unsigned int  iCodeChar,
int  iActNo 
)

Get the update nodes for a specific NPC type.

Parameters
iCodeCharThe character code.
iActNoThe act number the NPC is on.
Returns
Returns the update node flags.

◆ CSM_Npc_SkipUpdate()

CAVESTORY_MOD_API void CSM_Npc_SkipUpdate ( NPCHAR pNpc)

Skip one NPC update for a specific NPC.

Skips the next update for a specific NPC. Useful for NPCs that have information that doesn't need to be updated to all clients.

Parameters
pNpcThe NPC to skip the next update for.

◆ CSM_Puppy_GetDrawOffset()

CAVESTORY_MOD_API void CSM_Puppy_GetDrawOffset ( MYCHAR pMC,
GUI_POINT pOut 
)

Get the held entity offset of a player's current frame.

Parameters
pMCThe player.
pOutThe point to hold the held entity's draw offset.
Returns
Returns the draw position.
Note
This function returns magnified, non-subpixel coordinates relative to the player's topleft coordinates. All you need to do is add the player's draw position.

◆ CSM_SetBitmapLoadMagnification()

CAVESTORY_MOD_API void CSM_SetBitmapLoadMagnification ( int  iMagnification)

Set the magnification of all loaded bitmaps beyond this point.

Parameters
Thenew loading magnification.

◆ CSM_Weapon_GetDrawOffset()

CAVESTORY_MOD_API void CSM_Weapon_GetDrawOffset ( MYCHAR pMC,
int  iWeaponCode,
GUI_POINT pOut 
)

Get the draw offset of a player's weapon.

Parameters
pMCThe player.
iWeaponCodeThe index of the weapon.
pOutThe point to hold the weapon's draw offset.
Returns
Returns the draw position.
Note
This function returns magnified, non-subpixel coordinates relative to the player's topleft coordinates. All you need to do is add the player's draw position.

◆ GetArktan()

CAVESTORY_MOD_API unsigned char GetArktan ( int  iX,
int  iY 
)

Get arktan from x and y.

Parameters
iX
iY
Returns
Returns result.

◆ GetCos()

CAVESTORY_MOD_API int GetCos ( unsigned char  iDeg)

Calculate cos.

Parameters
iDegThe degrees.
Returnscos value.

◆ GetMyCharDrawRectangle()

CAVESTORY_MOD_API void GetMyCharDrawRectangle ( MYCHAR pMC,
GUI_RECT pOut 
)

Get the draw rectangle of a MYCHAR.

Parameters
pMCThe MYCHAR to check.
pOutA pointer to a GUI_RECT to hold the draw rectangle.
Returns
Returns the calculated draw rectangle.

◆ GetSin()

CAVESTORY_MOD_API int GetSin ( unsigned char  iDeg)

Calculate sin.

Parameters
iDegThe sin.
Returnssin value.

◆ IsNpcOnScreen()

CAVESTORY_MOD_API bool IsNpcOnScreen ( NPCHAR pNpc)

Check if an NPC is on screen.

Parameters
pNpcThe NPC to check.
Returns
Returns true if the NPC can be seen on-screen.

◆ PixelToScreenCoord()

int PixelToScreenCoord ( int  iCoord)
inline

Convert a pixel to a screen cordinate.

Parameters
iCoord
Returns
Returns (iCoord * magnification)

◆ Random()

CAVESTORY_MOD_API int Random ( int  iMin,
int  iMax 
)

Get a random value.

Parameters
iMinThe minimum value it can be.
iMaxThe maximum value it can be.
Returns
Returns a random value.

◆ ScreenCoordToPixel()

int ScreenCoordToPixel ( int  iCoord)
inline

Convert a screen cordinate to a pixel.

Parameters
iCoord
Returns
Returns (iCoord * magnification)

◆ ScreenCoordToSubPixel()

int ScreenCoordToSubPixel ( int  iCoord)
inline

Convert a screen cordinate to a subpixel.

Parameters
iCoord
Returns
Returns (iCoord * magnification)

◆ SubpixelToScreenCoord()

int SubpixelToScreenCoord ( int  iCoord)
inline

Convert a subpixel coordinate to screen coordinate.

Parameters
iCoordThe coordinate to convert.
Returns
Returns (iCoord * magnification / 0x200)