- 17
- Posts
- 4
- Years
- Seen Jan 4, 2025
Display Mugshots/Other Images In The Overworld (Emerald / Firered)
This modification allows you to load images onto BG0 from a script. It can only show one 16-color image at a time.
![]()
![]()
1. Installation
Spoiler:
1. Create mugshot.c in the src folder and copy the following code to it:
Spoiler:Code:#include "global.h" #include "blit.h" #include "window.h" #include "menu.h" #include "palette.h" #include "event_data.h" #include "constants/mugshots.h" #define MUGSHOT_PALETTE_NUM 13 struct Mugshot{ u8 x; u8 y; u8 width; u8 height; const u32* image; const u16* palette; }; void DrawMugshot(void); //VAR_0x8000 = mugshot id void DrawMugshotAtPos(void); //VAR_0x8000 = mugshot id, VAR_0x8001 = x, VAR_0x8002 = y void ClearMugshot(void); static const struct Mugshot sMugshots[] = { //ADD YOUR MUGSHOTS HERE }; //WindowId + 1, 0 if window is not open static EWRAM_DATA u8 sMugshotWindow = 0; void ClearMugshot(void){ if(sMugshotWindow != 0){ ClearStdWindowAndFrameToTransparent(sMugshotWindow - 1, 0); CopyWindowToVram(sMugshotWindow - 1, 3); RemoveWindow(sMugshotWindow - 1); sMugshotWindow = 0; } } static void DrawMugshotCore(const struct Mugshot* const mugshot, int x, int y){ struct WindowTemplate t; u16 windowId; if(sMugshotWindow != 0){ ClearMugshot(); } #if GAME_VERSION==VERSION_EMERALD SetWindowTemplateFields(&t, 0, x, y, mugshot->width/8, mugshot->height/8, MUGSHOT_PALETTE_NUM, 0x40); #else t = SetWindowTemplateFields(0, x, y, mugshot->width/8, mugshot->height/8, MUGSHOT_PALETTE_NUM, 0x40); #endif windowId = AddWindow(&t); sMugshotWindow = windowId + 1; LoadPalette(mugshot->palette, 16 * MUGSHOT_PALETTE_NUM, 32); CopyToWindowPixelBuffer(windowId, (const void*)mugshot->image, 0, 0); PutWindowRectTilemap(windowId, 0, 0, mugshot->width/8, mugshot->height/8); CopyWindowToVram(windowId, 3); } void DrawMugshot(void){ const struct Mugshot* const mugshot = sMugshots + VarGet(VAR_0x8000); DrawMugshotCore(mugshot, mugshot->x, mugshot->y); } void DrawMugshotAtPos(void){ DrawMugshotCore(sMugshots + VarGet(VAR_0x8000), VarGet(VAR_0x8001), VarGet(VAR_0x8002)); }
2. Create mugshots.h in include/constants/ and copy the following to it:
Spoiler:Code:#ifndef GUARD_CONSTANTS_MUGSHOTS_H #define GUARD_CONSTANTS_MUGSHOTS_H //Add your mugshot constants here #endif
3. Open ld_script.txt and add .text and .rodata for mugshot.o:
Add this somewhere among the other src files' text sections (for example here):
Code:src/mugshot.o(.text);
Add this somewhere among the other src files' rodata sections (for example here):
Code:src/mugshot.o(.rodata);
4. Open sym_ewram.txt and add this to the end:
Code:.include "src/mugshot.o"
5. Open data/event_scripts.s and add this after the includes at the top of the file:Code:#include "constants/mugshots.h"
2. Adding new mugshots
Spoiler:
Your mugshot images need to be 16-color indexed PNGs. Their width and height must be multiples of 8.
(OPTIONAL). Make a new folder called "mugshots" in the graphics folder for your images, you could also just place them in some other folder.
1. Add a constant for each image in include/constants/mugshots.h, each with a number one higher than the last:
Code:#ifndef GUARD_CONSTANTS_MUGSHOT_H #define GUARD_CONSTANTS_MUGSHOT_H //Add your mugshot constants here [COLOR="Lime"]#define MUGSHOT_BLAINE 0[/COLOR] [COLOR="Lime"]#define MUGSHOT_MAZE 1[/COLOR] #endif
2. Load the image's tiles and palette in src/mugshot.c, above the definition of sMugshots
The path in the incbin is the path to your image except "png" is replaced with "4bpp.lz" for the tiles and "gbapal" for the palette.Code:[COLOR="Lime"]static const u32 sMugshotImg_Blaine[] = INCBIN_U32("graphics/mugshots/blaine.4bpp.lz"); static const u16 sMugshotPal_Blaine[] = INCBIN_U16("graphics/mugshots/blaine.gbapal"); static const u32 sMugshotImg_Maze[] = INCBIN_U32("graphics/mugshots/maze.4bpp.lz"); static const u16 sMugshotPal_Maze[] = INCBIN_U16("graphics/mugshots/maze.gbapal"); [/COLOR]
3. Create mugshot templates in sMugshots in src/mugshot.c using the images and palettes from the last step and the constants from the first step
Code:static const struct Mugshot sMugshots[] = { //ADD YOUR MUGSHOTS HERE [COLOR="Lime"][MUGSHOT_BLAINE] = {.x = 16, .y = 5, .width = 80, .height = 72, .image = sMugshotImg_Blaine, .palette = sMugshotPal_Blaine},[/COLOR] [COLOR="Lime"][MUGSHOT_MAZE] = {.x = 6, .y = 1, .width = 144, .height = 96, .image = sMugshotImg_Maze, .palette = sMugshotPal_Maze},[/COLOR] };
Note that x & y are tile coordinates, so the mugshot will be drawn at (8*x, 8*y).
3. Using mugshots in a script
Spoiler:
There are 3 new functions, which you can call with the callnative command:
DrawMugshot: draws mugshot that's id is in VAR_0x8000
DrawMugshotAtPos: draws mugshot that's id is in VAR_0x8000, at coordinates stored in VAR_0x8001 and VAR_0x8002
ClearMugshot: clears drawn mugshot
If a mugshot is drawn while one is already on the screen, the previous one is automatically cleared.
Example script:
Code:setvar VAR_0x8000, MUGSHOT_BLAINE callnative DrawMugshot msgbox SomeText, MSGBOX_NPC callnative ClearMugshot end SomeText: .string "hi.$"
I have an issue for some larger mugshots and text
So my Mugshot here is 104 pixels tall, 240 wide. But when text comes up it glitches like so
![[PokeCommunity.com] Simple Modifications Directory [PokeCommunity.com] Simple Modifications Directory](https://cdn.discordapp.com/attachments/419214240277200898/916868858533531679/unknown.png)
Params in Mugshot.c
Code:
[MUGSHOT_MENUA] = {.x = 0,.y = 0,.width = 240,.height = 104,.image = sMugshotImg_MenuA,.palette = sMugshotPal_MenuA},