Procházet zdrojové kódy

fixed some npc color issues, fixed npc_restore_state, fixed emoticons

SBird1337 před 7 roky
rodič
revize
67ac985c6c

+ 1
- 1
g3headers

@@ -1 +1 @@
1
-Subproject commit aacaa291e37618f8ba81812568040d367bd435f5
1
+Subproject commit 6763a72442cefbd7a0a41abfb41bf78a4a731f80

+ 15
- 2
patches/dynamic_overworld_hooks.asm Zobrazit soubor

@@ -258,7 +258,6 @@ bx r5
258 258
 .org 0x08007280
259 259
 ldr r1, =obj_delete_and_free_tiles_hook|1
260 260
 bx r1
261
-
262 261
 .pool
263 262
 
264 263
 .org 0x0800779A
@@ -277,5 +276,19 @@ bx r0
277 276
 
278 277
 bxr4:
279 278
 bx r4
279
+.pool
280
+
281
+.org 0x0808265C
282
+ldr r3, =ov_emot_load|1
283
+bx r3
284
+.pool
280 285
 
281
-.pool
286
+/*.org 0x08083614
287
+ldr r1, =oec01_load_pal_impl|1
288
+bx r1
289
+.pool
290
+
291
+.org 0x0808365C
292
+ldr r1, =oec02_load_pal_impl|1
293
+bx r1
294
+.pool*/

+ 1
- 1
sots-private

@@ -1 +1 @@
1
-Subproject commit d1a52f5efb3ed79995a0ff20a6470afe161c49d2
1
+Subproject commit 61328dd97eaad0594fa7c5161ecfeff0582afd74

+ 13
- 6
src/overworld/dyn_npc_hooks.S Zobrazit soubor

@@ -6,9 +6,16 @@
6 6
 obj_delete_and_free_tiles_hook:
7 7
 	push {r4-r7,lr}
8 8
 	mov r5, r0
9
+	ldr r0, [r5, #0x14] @template
10
+	ldr r1, =0x8231D00 @ template for empty OBJ
11
+	cmp r0, r1
12
+	beq no_entry_remove
9 13
     ldrb r0, [r5,#5]
14
+	ldr r1, [r5, #0x14]
15
+	ldrh r1, [r1,#2] @tag
10 16
     lsr r0, #4
11 17
     bl npc_dynamic_remove_entry
18
+no_entry_remove:
12 19
 	mov r0, r5
13 20
 	add r0, #0x3E
14 21
 	ldrb r1, [r0]
@@ -17,12 +24,12 @@ obj_delete_and_free_tiles_hook:
17 24
 
18 25
 .global obj_delete_all_hook
19 26
 obj_delete_all_hook:
20
-ldr r1, =obj_delete
21
-bl bxr1
22
-bl npc_dynamic_reset
23
-pop {r4-r5}
24
-pop {r0}
25
-bx r0
27
+	ldr r1, =obj_delete
28
+	bl bxr1
29
+	bl npc_dynamic_reset
30
+	pop {r4-r5}
31
+	pop {r0}
32
+	bx r0
26 33
 
27 34
 bxr1:
28 35
 bx r1

+ 13
- 6
src/overworld/dyn_npc_hooks.s Zobrazit soubor

@@ -6,9 +6,16 @@
6 6
 obj_delete_and_free_tiles_hook:
7 7
 	push {r4-r7,lr}
8 8
 	mov r5, r0
9
+	ldr r0, [r5, #0x14] @template
10
+	ldr r1, =0x8231D00 @ template for empty OBJ
11
+	cmp r0, r1
12
+	beq no_entry_remove
9 13
     ldrb r0, [r5,#5]
14
+	ldr r1, [r5, #0x14]
15
+	ldrh r1, [r1,#2] @tag
10 16
     lsr r0, #4
11 17
     bl npc_dynamic_remove_entry
18
+no_entry_remove:
12 19
 	mov r0, r5
13 20
 	add r0, #0x3E
14 21
 	ldrb r1, [r0]
@@ -17,12 +24,12 @@ obj_delete_and_free_tiles_hook:
17 24
 
18 25
 .global obj_delete_all_hook
19 26
 obj_delete_all_hook:
20
-ldr r1, =obj_delete
21
-bl bxr1
22
-bl npc_dynamic_reset
23
-pop {r4-r5}
24
-pop {r0}
25
-bx r0
27
+	ldr r1, =obj_delete
28
+	bl bxr1
29
+	bl npc_dynamic_reset
30
+	pop {r4-r5}
31
+	pop {r0}
32
+	bx r0
26 33
 
27 34
 bxr1:
28 35
 bx r1

+ 63
- 9
src/overworld/dynamic_overworld.c Zobrazit soubor

@@ -62,6 +62,18 @@ u8 npc_dynamic_load_palette(u16 tag) {
62 62
     return (u8)store_entry;
63 63
 }
64 64
 
65
+void ov_emot_load(struct Object *obj, u16 a2, u8 a3) {
66
+    (void)npc_dynamic_load_palette(0x1100);
67
+    obj->final_oam.priority = 2;
68
+    obj->bitfield2 |= 2;
69
+    obj->priv[0] = oe_state.effect_pos.x;
70
+    obj->priv[1] = oe_state.effect_pos.y;
71
+    obj->priv[2] = oe_state.priority;
72
+    obj->priv[3] = -5;
73
+    obj->priv[7] = a2;
74
+    obj_anim_image_start(obj, a3);
75
+}
76
+
65 77
 void npc_dynamic_reset() {
66 78
     for (u8 i = 0; i < MAX_PAL_STORE; ++i) {
67 79
         stored_palettes[i].reference_count = 0;
@@ -69,12 +81,14 @@ void npc_dynamic_reset() {
69 81
     }
70 82
 }
71 83
 
72
-void npc_dynamic_remove_entry(u8 id) {
73
-    if (stored_palettes[id].reference_count > 0) {
74
-        stored_palettes[id].reference_count--;
75
-        dprintf("npc_dynamic: removed entry #%d\n", id);
76
-        if (stored_palettes[id].reference_count == 0)
77
-            stored_palettes[id].tag = 0;
84
+void npc_dynamic_remove_entry(u8 id, u16 tag) {
85
+    if (stored_palettes[id].tag == tag) {
86
+        if (stored_palettes[id].reference_count > 0) {
87
+            stored_palettes[id].reference_count--;
88
+            dprintf("npc_dynamic: removed entry #%d\n", id);
89
+            if (stored_palettes[id].reference_count == 0)
90
+                stored_palettes[id].tag = 0;
91
+        }
78 92
     }
79 93
 }
80 94
 
@@ -87,14 +101,20 @@ void npc_restore_state(u8 id, u16 x, u16 y) {
87 101
     }
88 102
 
89 103
     struct NpcState *npc_to_load = &npc_states[id];
90
-    struct NpcType *type_to_load = npc_get_type(((u16)npc_to_load->type_id) | (((u16)npc_to_load->field1A << 8)));
104
+    u16 type_id = ((u16)npc_to_load->type_id) | (((u16)npc_to_load->field1A << 8));
105
+    struct NpcType *type_to_load = npc_get_type(type_id);
91 106
 
92 107
     struct Template template_to_load;
93 108
     u32 f14;
94
-    npc_to_objtemplate__with_indexed_objfunc(npc_to_load->type_id, npc_to_load->running_behavior, &template_to_load,
109
+    npc_to_objtemplate__with_indexed_objfunc(type_id, npc_to_load->running_behavior, &template_to_load,
95 110
                                              &f14);
96 111
     template_to_load.pal_tag = 0xFFFF;
97 112
     s8 pal_slot = npc_dynamic_load_palette(type_to_load->pal_num);
113
+
114
+    /*template_to_load.pal_tag = type_to_load->pal_num;
115
+    gpu_pal_obj_alloc_tag_and_apply(&npc_palettes[npc_pal_idx_for_given_tag(type_to_load->pal_num)]);
116
+    u8 pal_slot = gpu_pal_tags_index_of(type_to_load->pal_num);*/
117
+
98 118
     u8 obj_id = template_instanciate_forward_search(&template_to_load, 0, 0, 0);
99 119
 
100 120
     if (obj_id == 64)
@@ -113,7 +133,7 @@ void npc_restore_state(u8 id, u16 x, u16 y) {
113 133
     }
114 134
 
115 135
     if (f14 != 0) {
116
-        (void) obj_set_f18_to_r0_f42_to_40(npc_obj, f14);
136
+        (void)obj_set_f18_to_r0_f42_to_40(npc_obj, f14);
117 137
     }
118 138
 
119 139
     npc_obj->final_oam.palette_num = pal_slot;
@@ -135,11 +155,16 @@ u8 npc_spawn_with_provided_template(struct RomNpc *npc, struct Template *templat
135 155
 
136 156
     struct NpcState *created_state = &npc_states[state];
137 157
     struct NpcType *type = npc_get_type(created_state->type_id | (npc->field3 << 8));
158
+
138 159
     s8 pal_slot = npc_dynamic_load_palette(type->pal_num);
139 160
 
161
+    // gpu_pal_obj_alloc_tag_and_apply(&npc_palettes[npc_pal_idx_for_given_tag(type->pal_num)]);
162
+    // u8 pal_slot = gpu_pal_tags_index_of(type->pal_num);
163
+
140 164
     if (created_state->running_behavior == 76)
141 165
         created_state->field1 |= 0x20;
142 166
     template->pal_tag = 0xFFFF;
167
+    // template->pal_tag = type->pal_num;
143 168
     u8 obj_id = template_instanciate_forward_search(template, 0, 0, 0);
144 169
     if (obj_id == 64) {
145 170
         created_state->bitfield &= 0xFE;
@@ -168,3 +193,32 @@ u8 npc_spawn_with_provided_template(struct RomNpc *npc, struct Template *templat
168 193
     npc_obj_offscreen_culling_and_flag_update(created_state, npc_object);
169 194
     return state;
170 195
 }
196
+
197
+void oec01_load_pal_impl(u32 *oe_script) {
198
+    struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
199
+    s8 allocated = npc_dynamic_find_palette(pal->tag);
200
+    if (allocated == -1)
201
+        allocated = npc_dynamic_allocate_palette(pal->tag);
202
+    if (allocated > 0) {
203
+        gpu_pal_apply(pal->data, 256 + (16 * allocated), 32);
204
+        tint_palette_switch(allocated);
205
+        palette_obj_807AA8C(allocated);
206
+    } else {
207
+        dprintf("ERROR: RAN OUT OF PALETTES FOR DYNAMIC SYSTEM\n");
208
+    }
209
+    *oe_script += 4;
210
+}
211
+
212
+void oec02_load_pal_impl(u32 *oe_script) {
213
+    struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
214
+    s8 allocated = npc_dynamic_find_palette(pal->tag);
215
+    if (allocated == -1)
216
+        allocated = npc_dynamic_allocate_palette(pal->tag);
217
+    if (allocated > 0) {
218
+        gpu_pal_apply(pal->data, 256 + (16 * allocated), 32);
219
+        tint_palette_switch(allocated);
220
+    } else {
221
+        dprintf("ERROR: RAN OUT OF PALETTES FOR DYNAMIC SYSTEM\n");
222
+    }
223
+    *oe_script += 4;
224
+}