Selaa lähdekoodia

start revamp dns

SBird1337 6 vuotta sitten
vanhempi
commit
d2bf1dd9cd

+ 1
- 1
g3headers

@@ -1 +1 @@
1
-Subproject commit f332778115f7c814f63d2192bcd4bce5504ecf00
1
+Subproject commit 252b211d9c1cefed1ed41ae2a42a34043a1145cc

+ 2
- 1
main.asm Näytä tiedosto

@@ -46,7 +46,8 @@
46 46
 
47 47
 .include "patches/overworlds/pkm_wild.asm"
48 48
 .include "patches/overworlds/trainer.asm"
49
-//.include "patches/dns/core.asm"
49
+
50
+.include "patches/dns/core.asm"
50 51
 
51 52
 .include "patches/overworlds/overworld.asm"
52 53
 

+ 27
- 1
patches/dns/core.asm Näytä tiedosto

@@ -21,4 +21,30 @@
21 21
 .org 0x08056578
22 22
     //ldr r0, =dns_cb_overworld_hacked+1
23 23
     //bx r0
24
-    //.pool
24
+    //.pool
25
+
26
+
27
+//new dn system
28
+
29
+//tile palettes
30
+.org 0x080599C8
31
+    ldr r3, =dns_blockset_load_palette+1
32
+    bx r3
33
+    .pool
34
+
35
+//oec palettes
36
+.org 0x08083614
37
+ldr r1, =dns_oec01_load_pal_impl|1
38
+bx r1
39
+.pool
40
+
41
+.org 0x0808365C
42
+ldr r1, =dns_oec02_load_pal_impl|1
43
+bx r1
44
+.pool
45
+
46
+//npc palettes
47
+.org 0x0805F538
48
+ldr r2, =dns_pal_patch_for_npc|1
49
+bx r2
50
+.pool

+ 0
- 10
patches/dynamic_overworld_hooks.asm Näytä tiedosto

@@ -283,16 +283,6 @@ ldr r3, =ov_emot_load|1
283 283
 bx r3
284 284
 .pool*/
285 285
 
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*/
295
-
296 286
 .org 0x0805E510
297 287
 ldr r1, =npc_delete_obj_and_free_tiles_for_npc_hack|1
298 288
 bx r1

+ 10
- 0
src/include/dns.h Näytä tiedosto

@@ -0,0 +1,10 @@
1
+#ifndef DNS_H_
2
+#define DNS_H_
3
+
4
+#include <pokeagb/pokeagb.h>
5
+
6
+#define DNS_ACTICE 1
7
+
8
+void dns_modify_palette(union Color* buffer, u16 size);
9
+
10
+#endif

+ 137
- 0
src/overworld/dns/dns.c Näytä tiedosto

@@ -0,0 +1,137 @@
1
+#include <pokeagb/pokeagb.h>
2
+#include <agb_debug.h>
3
+#include <dns.h>
4
+
5
+#define DNS_BUF_SIZE 256
6
+#define DNS_SEC_PAL_START 224
7
+#define DNS_SEC_PAL_START_C (DNS_SEC_PAL_START / 2)
8
+
9
+#define crgb5(r,g,b) (union Color)(((u16)(((b) << 10) | ((g)<<5) | ((r)))))
10
+#define rgb82rgb5(r,g,b) (crgb5(r/8, g/8, b/8))
11
+
12
+const union Color dns_color_times[5] = {
13
+    rgb82rgb5(70, 70, 196),
14
+    rgb82rgb5(70, 70, 196),
15
+    rgb82rgb5(70, 70, 196),
16
+    rgb82rgb5(70, 70, 196),
17
+    rgb82rgb5(70, 70, 196)
18
+};
19
+
20
+union Color dns_color_multiply(union Color a, union Color b);
21
+
22
+
23
+void dns_blockset_load_palette(struct MapBlockset* blockset, u16 offset, u16 size){
24
+    dprintf("loading blocset 0x%x\n", blockset);
25
+    if(blockset != NULL){
26
+        union Color *dns_buffer = malloc(DNS_BUF_SIZE*2);
27
+        if(blockset->secondary > 0)
28
+        {
29
+            if(blockset->secondary == 1)
30
+            {
31
+                //load secondary palette uncompressed
32
+                memcpy(dns_buffer, blockset->palettes+DNS_SEC_PAL_START, size);
33
+                dns_modify_palette(dns_buffer, size/2);
34
+                gpu_pal_apply(dns_buffer, offset,size);
35
+                load_palette3(offset, size/2);
36
+            }
37
+            else
38
+            {
39
+                //load secondary palette compressed 
40
+                LZ77UnCompWram(blockset->palettes, dns_buffer);
41
+
42
+                dns_modify_palette(&dns_buffer[DNS_SEC_PAL_START_C], size/2);
43
+
44
+                gpu_pal_apply(&dns_buffer[DNS_SEC_PAL_START_C], offset, size);
45
+                load_palette3(offset,size/2);
46
+                
47
+            }
48
+        }
49
+        else
50
+        {
51
+            union Color black;
52
+            black.packed = 0x0000;
53
+            gpu_pal_apply(&black, 0, 2);
54
+            memcpy(dns_buffer, blockset->palettes, size);
55
+            dns_modify_palette(dns_buffer, size/2);
56
+            gpu_pal_apply(&dns_buffer[1], offset+1, size-2);
57
+            load_palette3(offset+1, (size-2)/2);
58
+            //load primary palette
59
+            
60
+        }
61
+        free(dns_buffer);
62
+    }
63
+}
64
+
65
+void dns_oec01_load_pal_impl(u32 *oe_script) {
66
+    struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
67
+    struct SpritePalette palToApply = {
68
+        .data = NULL,
69
+        .tag = pal->tag
70
+    };
71
+    u8 idx = gpu_pal_tags_index_of(palToApply.tag);
72
+
73
+    union Color *buffer = malloc(32);
74
+    memcpy(buffer, pal->data, 32);
75
+    dns_modify_palette(buffer, 16);
76
+    palToApply.data = buffer;
77
+
78
+    gpu_pal_obj_alloc_tag_and_apply(&palToApply);
79
+    if(idx == 0xFF) {
80
+        u8 idx = gpu_pal_tags_index_of(palToApply.tag);
81
+        tint_palette_switch(idx);
82
+    }
83
+    idx = gpu_pal_tags_index_of(palToApply.tag);
84
+    free(buffer);
85
+    palette_obj_807AA8C(idx);
86
+    *oe_script += 4;
87
+}
88
+
89
+void dns_oec02_load_pal_impl(u32 *oe_script) {
90
+    struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
91
+    struct SpritePalette palToApply = {
92
+        .data = NULL,
93
+        .tag = pal->tag
94
+    };
95
+    u8 idx = gpu_pal_tags_index_of(palToApply.tag);
96
+
97
+    union Color *buffer = malloc(32);
98
+    memcpy(buffer, pal->data, 32);
99
+    dns_modify_palette(buffer, 16);
100
+    palToApply.data = buffer;
101
+    
102
+    gpu_pal_obj_alloc_tag_and_apply(&palToApply);
103
+    if(idx == 0xFF) {
104
+        u8 idx = gpu_pal_tags_index_of(palToApply.tag);
105
+        tint_palette_switch(idx);
106
+    }
107
+    free(buffer);
108
+    *oe_script += 4;
109
+}
110
+
111
+void dns_pal_patch_for_npc(u16 tag, u8 idx)
112
+{
113
+    extern struct SpritePalette ow_pal_table[1100];
114
+    u16 npcPalIdx = hacked_npc_pal_idx_for_given_tag(tag);
115
+    union Color *buffer = malloc(32);
116
+    memcpy(buffer, ow_pal_table[npcPalIdx].data,32);
117
+    dns_modify_palette(buffer,16);
118
+    gpu_pal_apply(buffer, 256 + 16*idx, 32);
119
+
120
+    free(buffer);
121
+    tint_palette_switch(idx);
122
+}
123
+
124
+void dns_modify_palette(union Color* buffer, u16 size){
125
+    if(current_map_header.light == 8)
126
+        return;
127
+    for(u16 i = 0; i < size; ++i) {
128
+        buffer[i] = dns_color_multiply(dns_color_times[0], buffer[i]);
129
+    }
130
+}
131
+
132
+union Color dns_color_multiply(union Color a, union Color b) {
133
+    u32 red = (a.components.r * b.components.r) / 31;
134
+    u32 green = (a.components.g * b.components.g) / 31;
135
+    u32 blue = (a.components.b * b.components.b) / 31;
136
+    return crgb5(red,green,blue);
137
+}

src/dns/dns_core.c → src/overworld/dns/dns_core.c.old Näytä tiedosto


+ 0
- 29
src/overworld/dynamic_overworld.c Näytä tiedosto

@@ -191,35 +191,6 @@ u8 npc_spawn_with_provided_template(struct RomNpc *npc, struct Template *templat
191 191
     return state;
192 192
 }
193 193
 
194
-void oec01_load_pal_impl(u32 *oe_script) {
195
-    struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
196
-    s8 allocated = npc_dynamic_find_palette(pal->tag);
197
-    if (allocated == -1)
198
-        allocated = npc_dynamic_allocate_palette(pal->tag);
199
-    if (allocated > 0) {
200
-        gpu_pal_apply(pal->data, 256 + (16 * allocated), 32);
201
-        tint_palette_switch(allocated);
202
-        palette_obj_807AA8C(allocated);
203
-    } else {
204
-        dprintf("ERROR: RAN OUT OF PALETTES FOR DYNAMIC SYSTEM\n");
205
-    }
206
-    *oe_script += 4;
207
-}
208
-
209
-void oec02_load_pal_impl(u32 *oe_script) {
210
-    struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
211
-    s8 allocated = npc_dynamic_find_palette(pal->tag);
212
-    if (allocated == -1)
213
-        allocated = npc_dynamic_allocate_palette(pal->tag);
214
-    if (allocated > 0) {
215
-        gpu_pal_apply(pal->data, 256 + (16 * allocated), 32);
216
-        tint_palette_switch(allocated);
217
-    } else {
218
-        dprintf("ERROR: RAN OUT OF PALETTES FOR DYNAMIC SYSTEM\n");
219
-    }
220
-    *oe_script += 4;
221
-}
222
-
223 194
 void npc_delete_obj_and_free_tiles_for_npc_hack(struct NpcState *state) {
224 195
     struct SpriteTiles tiles;
225 196
     u16 npc_id = ((u16)state->type_id) | (((u16)state->field1A << 8));