|
@@ -0,0 +1,190 @@
|
|
1
|
+#include <bpre.h>
|
|
2
|
+
|
|
3
|
+enum time_type {
|
|
4
|
+ DAY,
|
|
5
|
+ NIGHT
|
|
6
|
+};
|
|
7
|
+
|
|
8
|
+enum map_type {
|
|
9
|
+ UNK_00,
|
|
10
|
+ VILLAGE,
|
|
11
|
+ CITY,
|
|
12
|
+ ROUTE,
|
|
13
|
+ CELLAR,
|
|
14
|
+ UNDERWATER,
|
|
15
|
+ UNK_07,
|
|
16
|
+ UNK_08,
|
|
17
|
+ INSIDE,
|
|
18
|
+ SECRET_BASE
|
|
19
|
+};
|
|
20
|
+
|
|
21
|
+struct mapdata_header {
|
|
22
|
+ u32 width;
|
|
23
|
+ u32 height;
|
|
24
|
+ void* border;
|
|
25
|
+ void* data;
|
|
26
|
+ void* blockset_one;
|
|
27
|
+ void* blockset_two;
|
|
28
|
+ u8 border_width;
|
|
29
|
+ u8 border_height;
|
|
30
|
+ u16 unknown;
|
|
31
|
+};
|
|
32
|
+
|
|
33
|
+struct mapheader {
|
|
34
|
+ struct mapdata_header* data_header;
|
|
35
|
+ void* events;
|
|
36
|
+ void* scripts;
|
|
37
|
+ void* connections;
|
|
38
|
+ u16 music;
|
|
39
|
+ u16 mapindex;
|
|
40
|
+ u8 name;
|
|
41
|
+ u8 cave;
|
|
42
|
+ u8 weather;
|
|
43
|
+ enum map_type maptype;
|
|
44
|
+ u8 field18;
|
|
45
|
+ u8 escape_rope;
|
|
46
|
+ u8 showname;
|
|
47
|
+ u8 battletype;
|
|
48
|
+};
|
|
49
|
+
|
|
50
|
+extern struct mapheader current_mapheader;
|
|
51
|
+
|
|
52
|
+struct color_shade {
|
|
53
|
+ struct color color;
|
|
54
|
+ u8 alpha;
|
|
55
|
+};
|
|
56
|
+
|
|
57
|
+struct npc_palette {
|
|
58
|
+ struct color* palette;
|
|
59
|
+ u16 tag;
|
|
60
|
+ u16 fill;
|
|
61
|
+};
|
|
62
|
+
|
|
63
|
+struct pal_replace {
|
|
64
|
+ void* blockset;
|
|
65
|
+ u8 pal;
|
|
66
|
+ u8 index;
|
|
67
|
+ struct color color;
|
|
68
|
+};
|
|
69
|
+
|
|
70
|
+extern struct npc_palette* npc_palettes;
|
|
71
|
+extern volatile u8 tint_filter;
|
|
72
|
+void apply_shaders(u8 pal, u8 fade_copy);
|
|
73
|
+struct color alpha_blend(struct color a, struct color b, u8 alpha);
|
|
74
|
+extern void blockset_load_palette_to_gpu(void* blockset, u16 start, u16 len);
|
|
75
|
+extern void gpu_pal_apply(struct color* src, u16 dst, u16 len);
|
|
76
|
+extern void tint_palette(u8 pal_slot);
|
|
77
|
+extern u8 gpu_pal_tags_index_of(u16 pal_tag);
|
|
78
|
+void copy_unfaded(u8 slot);
|
|
79
|
+u8 is_current_map_dn_valid(enum map_type current_type);
|
|
80
|
+//care, this has to be manually patched to be u16
|
|
81
|
+extern u16 npc_pal_idx_for_given_tag(u16 tag);
|
|
82
|
+struct color_shade get_color_from_time(enum time_type current_time);
|
|
83
|
+enum time_type get_time_of_day();
|
|
84
|
+void apply_lighting(void* blockset, u8 copy);
|
|
85
|
+
|
|
86
|
+enum time_type get_time_of_day() {
|
|
87
|
+ return NIGHT;
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+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}}
|
|
94
|
+};
|
|
95
|
+
|
|
96
|
+static struct color_shade color_shade_day = {
|
|
97
|
+ {0, 0, 0}, 255
|
|
98
|
+};
|
|
99
|
+static struct color_shade color_shade_night = {
|
|
100
|
+ {0, 6, 16}, 120
|
|
101
|
+};
|
|
102
|
+
|
|
103
|
+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);
|
|
108
|
+ return;
|
|
109
|
+}
|
|
110
|
+
|
|
111
|
+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);
|
|
116
|
+ return;
|
|
117
|
+}
|
|
118
|
+
|
|
119
|
+void apply_lighting(void* blockset, u8 copy)
|
|
120
|
+{
|
|
121
|
+ for (int i = 0; i < (sizeof (lightmap) / sizeof (lightmap[0])); ++i) {
|
|
122
|
+ if (blockset == lightmap[i].blockset) {
|
|
123
|
+ palette_unfaded_buffer[lightmap[i].pal * 16 + lightmap[i].index] = lightmap[i].color;
|
|
124
|
+ }
|
|
125
|
+ }
|
|
126
|
+ return;
|
|
127
|
+}
|
|
128
|
+
|
|
129
|
+void apply_shaders(u8 pal, u8 fade_copy) {
|
|
130
|
+ if (tint_filter != 0)
|
|
131
|
+ return;
|
|
132
|
+ if (!is_current_map_dn_valid(current_mapheader.maptype))
|
|
133
|
+ return;
|
|
134
|
+ for (int i = pal * 16; i < (pal * 16) + 16; ++i) {
|
|
135
|
+ 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);
|
|
137
|
+ }
|
|
138
|
+ if (fade_copy)
|
|
139
|
+ copy_unfaded(pal);
|
|
140
|
+}
|
|
141
|
+
|
|
142
|
+void copy_unfaded(u8 slot) {
|
|
143
|
+ for (int i = slot * 16; i < (slot * 16) + 16; ++i) {
|
|
144
|
+ palette_faded_buffer[i] = palette_unfaded_buffer[i];
|
|
145
|
+ }
|
|
146
|
+}
|
|
147
|
+
|
|
148
|
+u8 is_current_map_dn_valid(enum map_type current_type) {
|
|
149
|
+ switch (current_type) {
|
|
150
|
+ case VILLAGE:
|
|
151
|
+ case CITY:
|
|
152
|
+ case ROUTE:
|
|
153
|
+ return 1;
|
|
154
|
+ default:
|
|
155
|
+ return 0;
|
|
156
|
+ }
|
|
157
|
+ return 0;
|
|
158
|
+}
|
|
159
|
+
|
|
160
|
+struct color_shade get_color_from_time(enum time_type current_time) {
|
|
161
|
+ switch (current_time) {
|
|
162
|
+ case NIGHT:
|
|
163
|
+ return color_shade_night;
|
|
164
|
+ case DAY:
|
|
165
|
+ default:
|
|
166
|
+ return color_shade_day;
|
|
167
|
+ }
|
|
168
|
+}
|
|
169
|
+
|
|
170
|
+struct color alpha_blend(struct color a, struct color b, u8 alpha) {
|
|
171
|
+ if (alpha == 255)
|
|
172
|
+ return a;
|
|
173
|
+ if (alpha == 0)
|
|
174
|
+ return b;
|
|
175
|
+ struct color output;
|
|
176
|
+ u8 inverted_alpha = 255 - alpha;
|
|
177
|
+
|
|
178
|
+ output.r = ((a.r * alpha + b.r * inverted_alpha) / 255);
|
|
179
|
+ output.b = ((a.b * alpha + b.b * inverted_alpha) / 255);
|
|
180
|
+ output.g = ((a.g * alpha + b.g * inverted_alpha) / 255);
|
|
181
|
+ return output;
|
|
182
|
+}
|
|
183
|
+
|
|
184
|
+void pal_patch_for_npc(u16 tag, u8 pal_slot) {
|
|
185
|
+ u16 npc_map_entry = npc_pal_idx_for_given_tag(tag);
|
|
186
|
+ gpu_pal_apply(npc_palettes[npc_map_entry].palette, (pal_slot + 16) * 16, 32);
|
|
187
|
+ tint_palette(pal_slot);
|
|
188
|
+ apply_shaders(pal_slot + 16, 1);
|
|
189
|
+}
|
|
190
|
+/*use fade in animation, load palettes according to current fade state*/
|