|
@@ -2,7 +2,9 @@
|
2
|
2
|
|
3
|
3
|
enum time_type {
|
4
|
4
|
DAY,
|
5
|
|
- NIGHT
|
|
5
|
+ NIGHT,
|
|
6
|
+ EVENING,
|
|
7
|
+ MORNING
|
6
|
8
|
};
|
7
|
9
|
|
8
|
10
|
enum map_type {
|
|
@@ -23,8 +25,8 @@ struct mapdata_header {
|
23
|
25
|
u32 height;
|
24
|
26
|
void* border;
|
25
|
27
|
void* data;
|
26
|
|
- void* blockset_one;
|
27
|
|
- void* blockset_two;
|
|
28
|
+ struct blockset* blockset_one;
|
|
29
|
+ struct blockset* blockset_two;
|
28
|
30
|
u8 border_width;
|
29
|
31
|
u8 border_height;
|
30
|
32
|
u16 unknown;
|
|
@@ -67,32 +69,98 @@ struct pal_replace {
|
67
|
69
|
struct color color;
|
68
|
70
|
};
|
69
|
71
|
|
|
72
|
+struct blockset {
|
|
73
|
+ u8 is_compressed;
|
|
74
|
+ u8 is_secondary;
|
|
75
|
+ u16 padding;
|
|
76
|
+ void* tiles;
|
|
77
|
+ void* palette;
|
|
78
|
+ void* block_tiles;
|
|
79
|
+ void* funcptr;
|
|
80
|
+ void* behavior;
|
|
81
|
+};
|
|
82
|
+
|
|
83
|
+struct dynamic_pal {
|
|
84
|
+ u8 type;
|
|
85
|
+ u8 count;
|
|
86
|
+ u16 tag;
|
|
87
|
+};
|
|
88
|
+
|
|
89
|
+#define dynamic_palettes ((struct dynamic_pal*) 0x0203FF00)
|
|
90
|
+
|
|
91
|
+void blockset_load_virtual_palette_and_shade(struct blockset* blockset, u16 start, u16 len, struct color* destination);
|
70
|
92
|
extern struct npc_palette* npc_palettes;
|
71
|
93
|
extern volatile u8 tint_filter;
|
72
|
|
-void apply_shaders(u8 pal, u8 fade_copy);
|
|
94
|
+void apply_shaders(u8 pal, u8 fade_copy, struct color* to_apply);
|
73
|
95
|
struct color alpha_blend(struct color a, struct color b, u8 alpha);
|
74
|
96
|
extern void blockset_load_palette_to_gpu(void* blockset, u16 start, u16 len);
|
75
|
97
|
extern void gpu_pal_apply(struct color* src, u16 dst, u16 len);
|
|
98
|
+extern void load_palette_3(u16 start, u16 len);
|
76
|
99
|
extern void tint_palette(u8 pal_slot);
|
77
|
100
|
extern u8 gpu_pal_tags_index_of(u16 pal_tag);
|
|
101
|
+extern void lz77u_wram(void* src, void* dst);
|
|
102
|
+extern void* oe_read_word(void* oe_script_pointer);
|
|
103
|
+extern void some_weather_func(u8 pal_index);
|
78
|
104
|
void copy_unfaded(u8 slot);
|
|
105
|
+void pal_patch_for_npc(u16 tag, u8 pal);
|
79
|
106
|
u8 is_current_map_dn_valid(enum map_type current_type);
|
80
|
107
|
//care, this has to be manually patched to be u16
|
81
|
108
|
extern u16 npc_pal_idx_for_given_tag(u16 tag);
|
82
|
109
|
struct color_shade get_color_from_time(enum time_type current_time);
|
83
|
110
|
enum time_type get_time_of_day();
|
84
|
|
-void apply_lighting(void* blockset, u8 copy);
|
|
111
|
+void update_dns_palettes();
|
|
112
|
+void apply_lighting(void* blockset, u8 copy, struct color* to_apply);
|
|
113
|
+
|
|
114
|
+extern void mapdata_load_palettes_to_gpu(struct mapdata_header* data_header);
|
|
115
|
+extern u16 npc_paltag_by_palslot(u8 slot);
|
|
116
|
+
|
|
117
|
+extern void script_something();
|
|
118
|
+extern void camera_update();
|
|
119
|
+extern void foo_115798();
|
|
120
|
+extern void foo_5ae28();
|
|
121
|
+extern void foo_6ffbc();
|
|
122
|
+extern void tilemaps_sync();
|
85
|
123
|
|
86
|
124
|
enum time_type get_time_of_day() {
|
87
|
|
- return NIGHT;
|
|
125
|
+ volatile u8* time_pointer = (u8*) (0x0203FAB1);
|
|
126
|
+ return *time_pointer;
|
88
|
127
|
}
|
89
|
128
|
|
90
|
129
|
static struct pal_replace lightmap[] = {
|
91
|
|
- {(void*) 0x082D4AAC, 9, 10, {31, 31, 0}},
|
92
|
|
- {(void*) 0x082D4AAC, 9, 9, {31, 31, 0}},
|
93
|
|
- {(void*) 0x082D4AAC, 9, 8, {31, 31, 0}}
|
|
130
|
+ {(void*) 0x082D4AAC, 9, 10, {
|
|
131
|
+ 31, 31, 0
|
|
132
|
+ }}
|
|
133
|
+
|
|
134
|
+ ,
|
|
135
|
+ {(void*) 0x082D4AAC, 9, 9, {
|
|
136
|
+ 31, 31, 0
|
|
137
|
+ }}
|
|
138
|
+
|
|
139
|
+ ,
|
|
140
|
+ {(void*) 0x082D4AAC, 9, 8, {
|
|
141
|
+ 31, 31, 0
|
|
142
|
+ }}
|
94
|
143
|
};
|
95
|
144
|
|
|
145
|
+void overworld_loop() {
|
|
146
|
+ script_something();
|
|
147
|
+ task_exec();
|
|
148
|
+ objc_exec();
|
|
149
|
+ camera_update();
|
|
150
|
+ foo_115798();
|
|
151
|
+ foo_5ae28();
|
|
152
|
+ obj_sync();
|
|
153
|
+ fade_update();
|
|
154
|
+ foo_6ffbc();
|
|
155
|
+ tilemaps_sync();
|
|
156
|
+
|
|
157
|
+ volatile u8* test_pointer = (u8*) (0x0203FAB0);
|
|
158
|
+ if (*test_pointer == 1 && (fade_controller.mix_color & 0x8000) == 0) {
|
|
159
|
+ update_dns_palettes();
|
|
160
|
+ *test_pointer = 0;
|
|
161
|
+ }
|
|
162
|
+}
|
|
163
|
+
|
96
|
164
|
static struct color_shade color_shade_day = {
|
97
|
165
|
{0, 0, 0}, 255
|
98
|
166
|
};
|
|
@@ -100,40 +168,184 @@ static struct color_shade color_shade_night = {
|
100
|
168
|
{0, 6, 16}, 120
|
101
|
169
|
};
|
102
|
170
|
|
|
171
|
+static struct color_shade color_shade_evening = {
|
|
172
|
+ {12, 7, 17}, 120
|
|
173
|
+};
|
|
174
|
+
|
|
175
|
+static struct color_shade color_shade_morning = {
|
|
176
|
+ {6, 16, 6}, 150
|
|
177
|
+};
|
|
178
|
+
|
|
179
|
+void npc_load_virtual_pal(struct color* dst, u16 tag, u8 slot, u8 shade) {
|
|
180
|
+ u16 npc_map_entry = npc_pal_idx_for_given_tag(tag);
|
|
181
|
+ memcpy(dst + (16 + slot)*16, npc_palettes[npc_map_entry].palette, 32);
|
|
182
|
+ if (shade) {
|
|
183
|
+ tint_palette(slot);
|
|
184
|
+ apply_shaders(slot + 16, 0, dst);
|
|
185
|
+ }
|
|
186
|
+}
|
|
187
|
+
|
|
188
|
+struct color* dns_alloc_virtual_pal_and_load() {
|
|
189
|
+ struct color* destination = malloc(0x400);
|
|
190
|
+ blockset_load_virtual_palette_and_shade(current_mapheader.data_header->blockset_one, 0x0, 0xE0, destination);
|
|
191
|
+ blockset_load_virtual_palette_and_shade(current_mapheader.data_header->blockset_two, 0x70, 0xC0, destination);
|
|
192
|
+
|
|
193
|
+ npc_load_virtual_pal(destination, 0x1120, 0, false);
|
|
194
|
+ load_palette_3(0x0, 0xD0);
|
|
195
|
+ for (int i = 0; i < 16; ++i) {
|
|
196
|
+ if (dynamic_palettes[i].tag >= 0x1100) {
|
|
197
|
+ npc_load_virtual_pal(destination, dynamic_palettes[i].tag, i, true);
|
|
198
|
+ } else if (dynamic_palettes[i].tag == 0x1004) {
|
|
199
|
+ //oe_0001
|
|
200
|
+ struct color* oe_pal_1 = (struct color*) (0x08398FA8);
|
|
201
|
+ memcpy(destination + (16 + i) * 16, oe_pal_1, 32);
|
|
202
|
+ apply_shaders(16 + i, 0, destination);
|
|
203
|
+
|
|
204
|
+ } else if (dynamic_palettes[i].tag == 0x1005) {
|
|
205
|
+ //oe_0002
|
|
206
|
+ struct color* oe_pal_2 = (struct color*) (0x08398FC8);
|
|
207
|
+ memcpy(destination + (16 + i) * 16, oe_pal_2, 32);
|
|
208
|
+ apply_shaders(16 + 1, 0, destination);
|
|
209
|
+ }
|
|
210
|
+ }
|
|
211
|
+ return destination;
|
|
212
|
+}
|
|
213
|
+
|
|
214
|
+void update_dns_palettes() {
|
|
215
|
+ struct color* destination = dns_alloc_virtual_pal_and_load();
|
|
216
|
+ gpu_pal_apply(destination, 0x0, 0x1A0);
|
|
217
|
+ gpu_pal_apply(destination + 0x100, 0x100, 0x200);
|
|
218
|
+ free(destination);
|
|
219
|
+}
|
|
220
|
+
|
|
221
|
+void overworld_anim_load_pal(void** oe_script_pointer) {
|
|
222
|
+ struct npc_palette* pal_to_apply = oe_read_word(oe_script_pointer);
|
|
223
|
+ u16 current_idx = gpu_pal_tags_index_of(pal_to_apply->tag);
|
|
224
|
+
|
|
225
|
+ struct color* temp_color = malloc(32);
|
|
226
|
+ memcpy(temp_color, pal_to_apply->palette, 32);
|
|
227
|
+ apply_shaders(0, 0, temp_color);
|
|
228
|
+
|
|
229
|
+ struct resource temp_resource = {temp_color, pal_to_apply->tag, pal_to_apply->fill};
|
|
230
|
+ gpu_pal_obj_alloc_tag_and_apply(&temp_resource);
|
|
231
|
+ free(temp_color);
|
|
232
|
+ if (current_idx != 0xFF) {
|
|
233
|
+ current_idx = gpu_pal_tags_index_of(pal_to_apply->tag);
|
|
234
|
+ tint_palette(current_idx);
|
|
235
|
+ }
|
|
236
|
+ current_idx = gpu_pal_tags_index_of(pal_to_apply->tag);
|
|
237
|
+ some_weather_func(current_idx);
|
|
238
|
+ *oe_script_pointer += 4;
|
|
239
|
+ return;
|
|
240
|
+}
|
|
241
|
+
|
|
242
|
+void blockset_load_virtual_palette_and_shade(struct blockset* blockset, u16 start, u16 len, struct color* destination) {
|
|
243
|
+ if (blockset == 0)
|
|
244
|
+ return;
|
|
245
|
+ if (blockset->is_secondary) {
|
|
246
|
+ if (blockset->is_secondary == 1) {
|
|
247
|
+ memcpy(destination + start, blockset->palette + (start * 2), len);
|
|
248
|
+ for (u8 i = 7; i < 7 + 6; ++i)
|
|
249
|
+ apply_shaders(i, 0, destination);
|
|
250
|
+ apply_lighting(blockset, 0, destination);
|
|
251
|
+ //gpu_pal_apply((color_memory), start, len);
|
|
252
|
+ //load_palette_3(start, len >> 1);
|
|
253
|
+ } else {
|
|
254
|
+ struct color* pal_buffer = (struct color*) (0x02037ACC);
|
|
255
|
+ lz77u_wram(blockset->palette, pal_buffer);
|
|
256
|
+ memcpy(destination + start, pal_buffer + (start * 2), len);
|
|
257
|
+ for (u8 i = 7; i < 7 + 6; ++i)
|
|
258
|
+ apply_shaders(i, 0, destination);
|
|
259
|
+ apply_lighting(blockset, 0, destination);
|
|
260
|
+ //gpu_pal_apply(pal_buffer, start, len);
|
|
261
|
+ //load_palette_3(start, len >> 1);
|
|
262
|
+ }
|
|
263
|
+ } else {
|
|
264
|
+ //struct color* color_memory = malloc(224);
|
|
265
|
+ memcpy(destination, blockset->palette, len);
|
|
266
|
+ for (u8 i = 0; i < 7; ++i)
|
|
267
|
+ apply_shaders(i, 0, destination);
|
|
268
|
+ apply_lighting(blockset, 0, destination);
|
|
269
|
+ //gpu_pal_apply(color_memory, start, len);
|
|
270
|
+ //load_palette_3(start, len >> 1);
|
|
271
|
+ //free(color_memory);
|
|
272
|
+ }
|
|
273
|
+ return;
|
|
274
|
+}
|
|
275
|
+
|
|
276
|
+void blockset_load_palette_to_gpu_and_shade(struct blockset* blockset, u16 start, u16 len) {
|
|
277
|
+ if (blockset == 0)
|
|
278
|
+ return;
|
|
279
|
+ if (blockset->is_secondary) {
|
|
280
|
+ if (blockset->is_secondary == 1) {
|
|
281
|
+ struct color* color_memory = malloc(224);
|
|
282
|
+ memcpy(color_memory, blockset->palette + 0xE0, 224);
|
|
283
|
+ for (u8 i = 0; i < 7; ++i)
|
|
284
|
+ apply_shaders(i, 0, color_memory);
|
|
285
|
+ apply_lighting(blockset, 1, color_memory);
|
|
286
|
+ gpu_pal_apply((color_memory), start, len);
|
|
287
|
+ load_palette_3(start, len >> 1);
|
|
288
|
+ free(color_memory);
|
|
289
|
+ } else {
|
|
290
|
+ struct color* pal_buffer = (struct color*) (0x02037ACC);
|
|
291
|
+ lz77u_wram(blockset->palette, pal_buffer);
|
|
292
|
+ for (u8 i = 7; i < 7 + 6; ++i)
|
|
293
|
+ apply_shaders(i, 0, pal_buffer);
|
|
294
|
+ apply_lighting(blockset, 0, pal_buffer);
|
|
295
|
+ gpu_pal_apply(pal_buffer, start, len);
|
|
296
|
+ load_palette_3(start, len >> 1);
|
|
297
|
+ }
|
|
298
|
+ } else {
|
|
299
|
+ struct color* color_memory = malloc(224);
|
|
300
|
+ memcpy(color_memory, blockset->palette, 224);
|
|
301
|
+ for (u8 i = 0; i < 7; ++i)
|
|
302
|
+ apply_shaders(i, 0, color_memory);
|
|
303
|
+ apply_lighting(blockset, 0, color_memory);
|
|
304
|
+ gpu_pal_apply(color_memory, start, len);
|
|
305
|
+ load_palette_3(start, len >> 1);
|
|
306
|
+ free(color_memory);
|
|
307
|
+ }
|
|
308
|
+ return;
|
|
309
|
+}
|
|
310
|
+
|
103
|
311
|
void mapdata_load_palette_two(struct mapdata_header* data_header) {
|
104
|
|
- blockset_load_palette_to_gpu(data_header->blockset_two, 0x70, 0xC0);
|
105
|
|
- for (u8 i = 7; i < 7 + 6; ++i)
|
106
|
|
- apply_shaders(i, 0);
|
107
|
|
- apply_lighting(data_header->blockset_two, 0);
|
|
312
|
+ //struct color* destination = malloc(0x200);
|
|
313
|
+ //blockset_load_virtual_palette_and_shade(data_header->blockset_two, 0x70, 0xC0, destination);
|
|
314
|
+ //gpu_pal_apply(destination, 0x70, 0xC0);
|
|
315
|
+ //load_palette_3(0x70, 0xC0 >> 1);
|
|
316
|
+ blockset_load_palette_to_gpu_and_shade(data_header->blockset_two, 0x70, 0xC0);
|
108
|
317
|
return;
|
109
|
318
|
}
|
110
|
319
|
|
111
|
320
|
void mapdata_load_palette_one(struct mapdata_header* data_header) {
|
112
|
|
- blockset_load_palette_to_gpu(data_header->blockset_one, 0x0, 0xE0);
|
113
|
|
- for (u8 i = 0; i < 7; ++i)
|
114
|
|
- apply_shaders(i, 0);
|
115
|
|
- apply_lighting(data_header->blockset_one, 0);
|
|
321
|
+ //struct color* destination = malloc(0x200);
|
|
322
|
+ //blockset_load_virtual_palette_and_shade(data_header->blockset_one, 0x0, 0xE0, destination);
|
|
323
|
+ //gpu_pal_apply(destination, 0x0, 0xE0);
|
|
324
|
+ //load_palette_3(0x0, 0xE0 >> 1);
|
|
325
|
+
|
|
326
|
+ blockset_load_palette_to_gpu_and_shade(data_header->blockset_one, 0x0, 0xE0);
|
116
|
327
|
return;
|
117
|
328
|
}
|
118
|
329
|
|
119
|
|
-void apply_lighting(void* blockset, u8 copy)
|
120
|
|
-{
|
|
330
|
+void apply_lighting(void* blockset, u8 secondary, struct color* buffer) {
|
|
331
|
+ if (get_time_of_day() != NIGHT)
|
|
332
|
+ return;
|
121
|
333
|
for (int i = 0; i < (sizeof (lightmap) / sizeof (lightmap[0])); ++i) {
|
122
|
334
|
if (blockset == lightmap[i].blockset) {
|
123
|
|
- palette_unfaded_buffer[lightmap[i].pal * 16 + lightmap[i].index] = lightmap[i].color;
|
|
335
|
+ buffer[(lightmap[i].pal - (secondary ? 7 : 0)) * 16 + lightmap[i].index] = lightmap[i].color;
|
124
|
336
|
}
|
125
|
337
|
}
|
126
|
338
|
return;
|
127
|
339
|
}
|
128
|
340
|
|
129
|
|
-void apply_shaders(u8 pal, u8 fade_copy) {
|
|
341
|
+void apply_shaders(u8 pal, u8 fade_copy, struct color* buffer) {
|
130
|
342
|
if (tint_filter != 0)
|
131
|
343
|
return;
|
132
|
344
|
if (!is_current_map_dn_valid(current_mapheader.maptype))
|
133
|
345
|
return;
|
134
|
346
|
for (int i = pal * 16; i < (pal * 16) + 16; ++i) {
|
135
|
347
|
struct color_shade current_shade = get_color_from_time(get_time_of_day());
|
136
|
|
- palette_unfaded_buffer[i] = alpha_blend(palette_unfaded_buffer[i], current_shade.color, current_shade.alpha);
|
|
348
|
+ buffer[i] = alpha_blend(buffer[i], current_shade.color, current_shade.alpha);
|
137
|
349
|
}
|
138
|
350
|
if (fade_copy)
|
139
|
351
|
copy_unfaded(pal);
|
|
@@ -161,7 +373,12 @@ struct color_shade get_color_from_time(enum time_type current_time) {
|
161
|
373
|
switch (current_time) {
|
162
|
374
|
case NIGHT:
|
163
|
375
|
return color_shade_night;
|
|
376
|
+ case EVENING:
|
|
377
|
+ return color_shade_evening;
|
|
378
|
+ case MORNING:
|
|
379
|
+ return color_shade_morning;
|
164
|
380
|
case DAY:
|
|
381
|
+
|
165
|
382
|
default:
|
166
|
383
|
return color_shade_day;
|
167
|
384
|
}
|
|
@@ -185,6 +402,6 @@ void pal_patch_for_npc(u16 tag, u8 pal_slot) {
|
185
|
402
|
u16 npc_map_entry = npc_pal_idx_for_given_tag(tag);
|
186
|
403
|
gpu_pal_apply(npc_palettes[npc_map_entry].palette, (pal_slot + 16) * 16, 32);
|
187
|
404
|
tint_palette(pal_slot);
|
188
|
|
- apply_shaders(pal_slot + 16, 1);
|
|
405
|
+ apply_shaders(pal_slot + 16, 1, palette_unfaded_buffer);
|
189
|
406
|
}
|
190
|
407
|
/*use fade in animation, load palettes according to current fade state*/
|