]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_vrs.c
wwww
[16.git] / src / lib / 16_vrs.c
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <ctype.h>
4 #include <errno.h>
5 #include <assert.h>
6 #include <stdint.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10
11 #include "stdlib.h"
12 #include "16_vrs.h"
13
14 int read_vrs(char *filename, struct vrs_container *vrs_cont){
15         int fd;
16         unsigned long size;
17         unsigned char *buffer;
18         fd = open(filename, O_RDONLY|O_BINARY);
19         // Insert sanity cheks later
20         size = lseek(fd, 0, SEEK_END);
21         buffer = malloc(size);
22         lseek(fd, 0, SEEK_SET);
23         read(fd, buffer, size);
24         vrs_cont->size = size;
25         vrs_cont->buffer = buffer;
26
27         return 0;
28 }
29
30 struct vrl_container* get_vrl_by_id(struct vrs_container *vrs_cont, uint16_t id){
31         uint16_t *ids; 
32         uint32_t *vrl_list;
33         int counter = 0;
34         struct vrl_container *vrl_cont;
35         if(id == 0){
36                 return 0;
37         }
38         ids = (uint16_t*)vrs_cont->buffer + (unsigned long)vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST];
39         while(ids[counter] != id && ids[counter]){
40                 counter++;
41         }
42         vrl_list = (uint32_t *)(vrs_cont->buffer + vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]);
43         vrl_cont = (struct vrl_container*)malloc(sizeof(struct vrl_container));
44         vrl_cont->vrl_header = (struct vrl1_vgax_header*)(vrs_cont->buffer + vrl_list[counter]);
45         vrl_cont->size = vrl_list[counter+1] - vrl_list[counter];
46         return vrl_cont;
47 }