本帖最后由 jiangzhengwenjz 于 2018-11-18 06:08 编辑
时间过得真快,今天把2年前做的一些东西拿出来共享下,不过由于是从project里直接拉出来的所以很多不能编译。想要应用的朋友拿出你的实力吧,稍加改动或是添加素材即可。阅读需相当的ASM与C知识,以及改版经验!
禁止将代码用于你发布的ROM! 转载请注明原贴!
1. minihack: 道具型“训练师卡片”:
一个很有意思的程序,只需让道具数据指向它即可。火红的这个系统多次malloc后会crash,用init_malloc()来解决。不过现在看来也许是没有free()?也懒得去看了
- .thumb
- .global p_trainer_function
- p_trainer_function:
- push {r4, lr}
- mov r4, r0
- ldr r1, =0x3005090
- lsl r0, r4, #2
- add r0, r0, r4
- lsl r0, r0, #3
- add r0, r0, r1
- ldrh r0, [r0, #0xe]
- bl trainer_card_modified
- mov r0, r4
- ldr r1, =task_del
- bl bx_r1
- pop {r4, pc}
- trainer_card_modified:
- push {r4, lr}
- mov r4, r0
- ldr r0, =0x2037AB8
- ldrb r1, [r0, #7]
- mov r0, #0x80
- and r0, r1
- cmp r0, #0
- beq real
- mov r0, #0
- pop {r4, pc}
- real:
- ldr r1, =0x807B005
- bl bx_r1
- cmp r4, #0
- bne backtoow
- ldr r0, =backtobagfunc+1
- b mainhandler
- backtoow:
- ldr r0, =backtoowfunc+1
- mainhandler:
- ldr r1, =0x808B699
- bl bx_r1
- pop {r4, pc}
- .ltorg
- backtobagfunc:
- push {lr}
- ldr r0, =0x2000000
- ldr r1, =0x1c000
- ldr r2, =0x8002B81
- bl bx_r2
- ldr r1, =0x8107EB9
- bl bx_r1
- pop {pc}
- .ltorg
- backtoowfunc:
- push {lr}
- ldr r0, =0x2000000
- ldr r1, =0x1c000
- ldr r2, =0x8002B81
- bl bx_r2
- ldr r1, =0x80567DD
- bl bx_r1
- pop {pc}
- .ltorg
- bx_r1: bx r1
- bx_r2: bx r2
复制代码 2. 新型钓鱼系统:
挺复杂的一个连续回调系统,选择不同的钓饵,但是并没有做相应的遇怪系统(虽然很简单)。主逻辑用C解决
- ;fish hack
- .org 0x805D30C
- ldr r1, =ultrarod_task_hook|1
- bx r1
- .pool
- .org 0x805D350
- ldr r0, =ultrarod_chooser_hook|1
- bx r0
- .pool
复制代码- /*hook via r1 at 0x805D30C*/
- .global ultrarod_task_hook
- .global ultrarod_chooser_hook
- ultrarod_task_hook:
- ldr r2, =0x3005090
- lsl r1, r0, #2
- add r1, r1, r0
- lsl r1, r1, #3
- add r4, r1, r2
- ldrh r0, [r4, #0x26]
- cmp r0, #3
- bne normal_fishing
- ldr r0, =task_bait_choose+1
- ldr r3, =task_find_id_by_funcptr
- bl bx_r3
- cmp r0, #0xFF
- bne bait_choosing
- normal_fishing:
- ldr r0, =0x805D317
- bx r0
- bait_choosing:
- pop {r4, r5, pc}
- .ltorg
- /*hook via r0 at 0x805D350*/
- ultrarod_chooser_hook:
- ldrh r0, [r4, #0x26]
- cmp r0, #3
- bne back
- ldr r0, =task_bait_choose+1
- mov r1, #0x50
- ldr r3, =task_add
- bl bx_r3
- mov r0, #0
- back:
- pop {r4, pc}
- .ltorg
- bx_r3: bx r3
复制代码- #include <funcs.h>
- #define bait_index_start 0x63
- void stringnospecifiedbait_print(void);
- void baitpalfade(u8 mode);
- extern const unsigned int MugBoxTileTiles[72];
- extern const unsigned int MugBoxTilePal[8];
- extern struct oam oam32x32_prio0;
- extern struct image_frame* anim_null_ptr;
- extern struct image_frame* anim_flip_ptr;
- extern struct rotscale * rotscale_null_ptr;
- extern u16* char_name_rbox_draw_rectangle_around;
- extern u16* pal_rbox_draw_rectangle_around;
- extern void**image_buffer_ptr;
- extern void**image_buffer_ptr2;
- extern struct task *tasks;
- extern struct superstate*super;
- extern struct obj*objects;
- const struct rbox_short bait_boxes[] __attribute__((aligned(4))) = {
- {0,3,5,3,3,0xF,0x38},
- {0,10,5,3,3,0xF,0x38},
- {0,17,5,3,3,0xF,0x38},
- {0,24,5,3,3,0xF,0x38},
- {0,3,0xD,24,4,0xF,0x41}
- };
- const struct objtemplate bait_templates[] __attribute__((aligned(4))) = {
- {0x1600,0x1600,&oam32x32_prio0,&anim_null_ptr,(void*)0,&rotscale_null_ptr,objc_nullsub},
- {0x1601,0x1601,&oam32x32_prio0,&anim_null_ptr,(void*)0,&rotscale_null_ptr,objc_nullsub},
- {0x1602,0x1602,&oam32x32_prio0,&anim_null_ptr,(void*)0,&rotscale_null_ptr,objc_nullsub},
- {0x1603,0x1603,&oam32x32_prio0,&anim_null_ptr,(void*)0,&rotscale_null_ptr,objc_nullsub}
- };
- const char stringchoosebait[] = {
- 0x0B, 0x0D, 0x0E, 0x8A, 0x10, 0x06, 0x0F, 0x0B, 0x10, 0xA7, 0x03, 0x3D, 0x03, 0xA1, 0x37, 0xFF
- };
- const char stringnospecifiedbait[] = {
- 0x09, 0x53, 0x0F, 0x7E, 0x10, 0x55, 0x10, 0xA7, 0x03, 0x3D, 0x03, 0xA1, 0x07, 0x7D, 0x02, 0x51, 0x0B, 0xF1, 0x03, 0x2A, 0x3B, 0xFE, 0x09, 0xD9, 0x10, 0x59, 0x0F, 0x24, 0x0D, 0x70, 0x07, 0xE3, 0x03, 0x3D, 0x04, 0x37, 0x07, 0x7D, 0x09, 0xD2, 0x03, 0x3D, 0x03, 0x04, 0x0F, 0x91, 0x08, 0x9E, 0x3D, 0xFF
- };
- extern u8 Bait1Tiles;
- extern u8 Bait2Tiles;
- extern u8 Bait3Tiles;
- extern u8 Bait4Tiles;
- extern u8 Bait1Pal;
- extern u8 Bait2Pal;
- extern u8 Bait3Pal;
- extern u8 Bait4Pal;
- const void* baitimagepointers[] __attribute__((aligned(4))) = {
- &Bait1Tiles,
- &Bait2Tiles,
- &Bait3Tiles,
- &Bait4Tiles
- };
- const struct pal_graphic baitpalette[] __attribute__((aligned(4))) = {
- {&Bait1Pal,0x1600,0},
- {&Bait2Pal,0x1601,0},
- {&Bait3Pal,0x1602,0},
- {&Bait4Pal,0x1603,0}
- };
- void task_bait_choose(u8 task_id)
- {
- int i;
- u8 rboxid;
- struct graphic temp;
- switch ((tasks+task_id)->priv[0])
- {
- case 0:
- gpu_copy_to_tileset(0,MugBoxTileTiles,0x120,0x21D);
- gpu_pal_apply(MugBoxTilePal,0xD0,0x20);
- gpu_pal_apply((u16*)0x8471DEC,0xF0,0x20);
- for (i = 0; i < 4; i++)
- {
- rboxid = rbox_spawn(bait_boxes+i);
- (tasks+task_id)->priv[1+i] = rboxid;
- rboxid_bg_prepare(rboxid);
- *char_name_rbox_draw_rectangle_around = 0x21D;
- *pal_rbox_draw_rectangle_around = 0xD;
- rboxid_unpack_and_call(rboxid,rbox_draw_rectangle_around);
- rboxid_fill_pixels(rboxid,0x11);//white
- rboxid_bg_prepare(rboxid);
- rboxid_upload_and_tilemap_send(rboxid,3);
- }
- rboxid = rbox_spawn(bait_boxes+4);
- (tasks+task_id)->priv[5] = rboxid;
- rboxid_bg_prepare(rboxid);
- *char_name_rbox_draw_rectangle_around = 0x21D;
- *pal_rbox_draw_rectangle_around = 0xD;
- rboxid_unpack_and_call(rboxid,rbox_draw_rectangle_around);
- rboxid_fill_pixels(rboxid,0x11);//white
- rboxid_bg_prepare(rboxid);
- rboxid_upload_and_tilemap_send(rboxid,3);
- rboxid_print(rboxid,2,stringchoosebait,48,9,0,0);
- bgid_mark_for_sync(0);
- break;
- case 1:
- item_image_expand_buffer_malloc();
- for (i = 0; i < 4; ++i)
- {
- LZ77UnCompWram(baitimagepointers[i],*image_buffer_ptr);
- item_24x24_to_32x32(*image_buffer_ptr,*image_buffer_ptr2);
- temp.img = *image_buffer_ptr2;
- temp.size = 0x200;
- temp.tag = 0x1600+i;
- gpu_tile_obj_alloc_tag_and_upload(&temp);
- gpu_pal_obj_alloc_tag_and_apply_2(baitpalette+i);
- (tasks+task_id)->priv[6+i] = template_instanciate_forward_search(bait_templates+i,40+i*56,56,0);
- }
- free(*image_buffer_ptr);
- free(*image_buffer_ptr2);
- baitpalfade(0);
- break;
- case 2:
- if(super->buttons3_new_remapped != 1) //not A
- {
- if(super->buttons3_new_remapped == 0) //no buttons
- return;
- if(super->buttons3_new_remapped == 0x10) //RIGHT
- {
- if((tasks+task_id)->priv[10] == 3)
- return;
- else
- {
- ++(tasks+task_id)->priv[10];
- baitpalfade((tasks+task_id)->priv[10]);
- return;
- }
- }
- else if(super->buttons3_new_remapped == 0x20) //LEFT
- {
- if((tasks+task_id)->priv[10] == 0)
- return;
- else
- {
- --(tasks+task_id)->priv[10];
- baitpalfade((tasks+task_id)->priv[10]);
- return;
- }
- }
- return;
- }
- else break;
- case 3:
- for (i=0; i<4; ++i)
- {
- rboxid_80040B8((tasks+task_id)->priv[1+i]);
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1600+i) << 4),16,0,0);
- obj_delete_and_free_associated_resources(objects+(tasks+task_id)->priv[6+i]);
- rboxid_flush((tasks+task_id)->priv[1+i],1);
- rboxid_upload_and_tilemap_send((tasks+task_id)->priv[1+i],2);
- rboxid_free((tasks+task_id)->priv[1+i]);
- }
- rboxid_80040B8((tasks+task_id)->priv[5]);
- rboxid_flush((tasks+task_id)->priv[5],1);
- rboxid_upload_and_tilemap_send((tasks+task_id)->priv[5],2);
- rboxid_free((tasks+task_id)->priv[5]);
- break;
- case 4:
- if(!check_item_2(bait_index_start+(tasks+task_id)->priv[10],1))
- {
- stringnospecifiedbait_print();
- break;
- }
- else
- {
- bag_remove_item(bait_index_start+(tasks+task_id)->priv[10],1);
- task_del(task_id);
- return;
- }
- case 5:
- if(super->buttons3_new_remapped&1 || super->buttons3_new_remapped&2)
- {
- (tasks+task_find_id_by_funcptr(0x805D305))->priv[0]=0xF;//goto fishF
- task_del(task_id);
- }
- else return;
- default:
- break;
- }
- ++(tasks+task_id)->priv[0];
- return;
- }
- void stringnospecifiedbait_print()
- {
- box_border_curve_load_tiles_and_pal(0,1);
- rboxid_fill_pixels(0,0x11);
- rboxid_print(0,2,stringnospecifiedbait,1,1,0,0);
- return;
- }
- void baitpalfade(u8 mode)
- {
- if(mode!=0)
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1600) << 4),16,12,0);
- else
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1600) << 4),16,0,0);
- if(mode!=1)
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1601) << 4),16,12,0);
- else
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1601) << 4),16,0,0);
- if(mode!=2)
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1602) << 4),16,12,0);
- else
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1602) << 4),16,0,0);
- if(mode!=3)
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1603) << 4),16,12,0);
- else
- pal_fade_1(0x100+(gpu_pal_tags_index_of(0x1603) << 4),16,0,0);
- return;
- }
复制代码 3. 对战前动画,以及多向滑动背景
- .org 0x807FF90
- ldr r0, =pre_battle_anim_load_type+1
- bx r0
- .pool
- .org 0x80D0A58
- .word pre_battle_anim_type_functions
- .org 0x80D0A88
- .word pre_battle_anim_type_functions
- .org 0x80D09E8
- .word pre_battle_anim_fade_functions
- .org 0x80D0A20
- .word pre_battle_anim_fade_functions
复制代码- #include <funcs.h>
- u16* char_name_rbox_draw_rectangle_around = (u16*)0x203ADF0;
- u16* pal_rbox_draw_rectangle_around = (u16*)0x203ADF2;
- void**image_buffer_ptr = (void**)0x2039884;
- void**image_buffer_ptr2 = (void**)0x2039888;
- struct task *tasks = (struct task*)0x3005090;
- struct superstate*super = (struct superstate*)0x30030F0;
- struct obj*objects = (struct obj*)0x202063C;
- vu16 *VCOUNT = (vu16*)0x4000006;
- vu16 *BG0HOFS = (vu16*)0x4000010;
- u16* var_8000 = (u16*)0x20370B8;
- u16* var_8001 = (u16*)0x20370BA;
- u16* var_8002 = (u16*)0x20370BC;
- u16* var_8003 = (u16*)0x20370BE;
- u16* var_8004 = (u16*)0x20370C0;
- u16* var_8005 = (u16*)0x20370C2;
- u16* var_8006 = (u16*)0x20370C4;
- u16* var_8007 = (u16*)0x20370C6;
- u16* var_800A = (u16*)0x20370CC;
- u16* var_800B = (u16*)0x20370CE;
复制代码- /* Generated by BIN2S - please don't edit directly */
- .section .rodata
- .balign 4
- .global x3tm_LZ_bin_size
- .global x3tm_LZ_bin
- x3tm_LZ_bin:
- .byte 16, 0, 5, 0, 63, 0,240,240, 1,240, 1,240, 1,240, 1,240
- .byte 1,240, 1,224,240, 1,240, 1, 16, 1, 3,240, 4,240, 5, 0
- .byte 240, 6,240, 6,244, 5,244, 4, 14,244, 3,244, 0, 80, 1,240
- .byte 43,224, 1, 7, 2,240, 8,240, 9,240, 1, 48, 1,244,131, 16
- .byte 1, 9,244, 8,244, 7,240, 63,240, 1,142, 0, 1, 10,240, 11
- .byte 80, 59, 96, 63, 16, 1, 11, 51,244, 10,240, 63,240, 1,240, 13
- .byte 144, 61,128, 63, 24, 1,244, 13,240, 63,224, 1, 14,240, 15,198
- .byte 240, 63, 64, 1, 15,244, 14,240, 63,192, 1, 16,198,176, 61,160
- .byte 63, 1,244, 16,240, 63,192, 1, 17,128,128, 59, 36,240, 37,240
- .byte 37,244, 36,177,128, 63, 17,240, 63,192, 1, 18,240, 19, 96, 1
- .byte 0, 38,240, 39,240, 39,244, 38,244, 88, 19, 96, 1, 18,240, 63
- .byte 192, 1, 20,240, 21,128, 96, 1, 40,240, 41,240, 41,244, 40, 44
- .byte 244, 21, 96, 1, 20,240, 63,192, 1, 22,240, 64, 2, 96, 1, 42
- .byte 240, 43,240, 43,244, 22, 42,244, 2, 96, 1, 22,240, 63,192, 1
- .byte 23,227,128, 63, 32, 1,128, 61, 2,244, 23,240, 63,192, 1, 24
- .byte 24,240, 25,240, 63, 64, 1, 25,244, 24,219,240, 63,224, 1, 26
- .byte 240, 63, 64, 1, 26,242, 63,240, 1, 12,240, 27,240, 28,240, 63
- .byte 0, 1, 28,244,112, 27,240, 63,240, 1, 0, 1, 29,240, 30,240
- .byte 65, 31,160, 63, 31,244, 30,244, 29,243,129,192,240, 1, 96, 1
- .byte 32,240, 33,240, 34,240, 0, 35,240, 35,244, 34,244, 33,244,127
- .byte 32,115,191,240, 63,240, 1,240, 1,240, 1,240, 1,240, 1,192
- .byte 240, 1,240, 1,240, 0, 0, 0
- .global x3tm_LZ_bin_end
- x3tm_LZ_bin_end:
- .align
- x3tm_LZ_bin_size: .int 344
复制代码- .global pre_battle_anim_type_x12_functions
- pre_battle_anim_type_x12_functions:
- .word pre_battle_anim_type_x12_func1+1
- .word pre_battle_anim_type_x12_func2+1
复制代码- #include <funcs.h>
- extern u8 x3tm_LZ_bin;
- extern struct task *tasks;
- void pre_battle_anim_type_x12_hblank(void);
- void pre_battle_anim_type_x12_helper(u8 task_id);
- extern vu16 *VCOUNT;
- extern vu16 *BG0HOFS;
- u8 pre_battle_anim_type_x12_func1(struct task*task_addr)
- {
- reg_ie_orr(2);
- hblank_handler_set(pre_battle_anim_type_x12_hblank+1);
- decompress_with_fallback(0,&x3tm_LZ_bin,0,0,1);
- gpu_copy_to_tileset(0,0x83F87A0,0x580,0);
- task_addr->priv[0]++;
- gpu_pal_apply(0x83FA638,0xf0,0x20);
- tasks[task_add(pre_battle_anim_type_x12_helper+1,0x50)].priv[0]=56;
- return 0;
- }
- u8 pre_battle_anim_type_x12_func2(struct task*task_addr)
- {
- u8 x;
- x = task_find_id_by_funcptr(pre_battle_anim_type_x12_helper+1);
- if (x != 0xFF)
- return 0;
- else
- {
- if(task_addr->priv[1] <= 0x10)
- {
- pal_fade_1(0xf0,16,task_addr->priv[1],0x7fff);
- task_addr->priv[1]+=2;
- return 0;
- }
- else
- {
- if(task_addr->priv[1] <= 0x18)
- {
- task_addr->priv[1]+=2;
- return 0;
- }
- else
- {
- pal_0_fade(0xFFFFFFFF,0x10,0);
- task_del(task_find_id_by_funcptr(task_addr->fptr));
- }
- }
- }
- return 0;
- }
- void pre_battle_anim_type_x12_hblank()
- {
- u8 i;
- u16 j,k;
- i = task_find_id_by_funcptr(pre_battle_anim_type_x12_helper+1);
- if (i == 0xFF)
- {
- hblank_handler_set((void*)0);
- return;
- }
- else
- {
- j = *VCOUNT;
- k = tasks[i].priv[0];
- if(j <= 49)
- *BG0HOFS = k;
- else
- if(j <= 79)
- *BG0HOFS = 256-k;
- else
- if(j <= 109)
- *BG0HOFS = k;
- else
- *BG0HOFS = 256-k;
- }
- return;
- }
- void pre_battle_anim_type_x12_helper(u8 task_id)
- {
- u16 i;
- i = tasks[task_id].priv[0];
- if(i)
- tasks[task_id].priv[0]-=4;
- else
- task_del(task_id);
- return;
- }
复制代码- .thumb
- .global pre_battle_anim_type_x12
- pre_battle_anim_type_x12:
- push {lr}
- lsl r0, r0, #0x18
- lsr r0, r0, #0x18
- ldr r2, =0x3005090
- lsl r1, r0, #2
- add r1, r1, r0
- lsl r1, r1, #3
- add r1, r1, r2
- mov r2, #0
- strh r2, [r1, #0x26]
- bl mainsub_x12
- pop {pc}
- .ltorg
- mainsub_x12:
- push {r4, r5, lr}
- lsl r0, r0, #0x18
- lsr r0, r0, #0x18
- ldr r5, =pre_battle_anim_type_x12_functions
- ldr r2, =0x3005090
- lsl r1, r0, #2
- add r1, r1, r0
- lsl r1, r1, #3
- add r4, r1, r2
- loc_loop:
- mov r1, #8
- ldrsh r0, [r4, r1]
- lsl r0, r0, #2
- add r0, r0, r5
- ldr r1, [r0]
- mov r0, r4
- bl bx_r1
- lsl r0, r0, #0x18
- cmp r0, #0
- bne loc_loop
- pop {r4, r5, pc}
- bx_r1:
- bx r1
复制代码- .thumb
- .global pre_battle_anim_load_type
- @hook via r0 at 0x807FF90
- pre_battle_anim_load_type:
- ldrb r2, [r4, #3]
- cmp r2, #0
- beq normal
- mov r0, r2
- pop {r4-r6, pc}
- normal:
- ldrh r2, [r4]
- lsl r0, r2, #2
- add r0, r0, r2
- lsl r0, r0, #3
- add r0, r0, r1
- ldr r1, =0x807ff9b
- bx r1
- .ltorg
复制代码- .global pre_battle_anim_type_functions
- pre_battle_anim_type_functions:
- .word 0x080D0ADD
- .word 0x080D0BD5
- .word 0x080D0D55
- .word 0x080D0EE5
- .word 0x080D13C9
- .word 0x080D1639
- .word 0x080D1B59
- .word 0x080D1D2D
- .word 0x080D316D
- .word 0x080D33ED
- .word 0x080D3819
- .word 0x080D3929
- .word 0x080D2769
- .word 0x080D2789
- .word 0x080D27A9
- .word 0x080D27C9
- .word 0x080D27E9
- .word 0x080D1F2D
- .word pre_battle_anim_type_x12+1
复制代码- .global pre_battle_anim_fade_functions
- pre_battle_anim_fade_functions:
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
- .word 0x080D0A8D
复制代码 |