MCPcopy Create free account
hub / github.com/TASEmulators/fceux / ApplyIPS

Function ApplyIPS

src/file.cpp:65–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64
65void ApplyIPS(FILE *ips, FCEUFILE* fp)
66{
67 uint8 header[5];
68 uint32 count=0;
69
70 if(!ips) return;
71
72 char* buf = (char*)FCEU_malloc(fp->size);
73 memcpy(buf,fp->EnsureMemorystream()->buf(),fp->size);
74
75
76 FCEU_printf(" Applying IPS...\n");
77 if(fread(header,1,5,ips)!=5)
78 {
79 goto end;
80 }
81 if(memcmp(header,"PATCH",5))
82 {
83 goto end;
84 }
85
86 while(fread(header,1,3,ips)==3)
87 {
88 uint32 offset=(header[0]<<16)|(header[1]<<8)|header[2];
89 uint16 size;
90
91 if(!memcmp(header,"EOF",3))
92 {
93 FCEU_printf(" IPS EOF: Did %d patches\n\n",count);
94 goto end;
95 }
96
97 size=fgetc(ips)<<8;
98 size|=fgetc(ips);
99 if(!size) /* RLE */
100 {
101 char *start;
102 char b;
103 size=fgetc(ips)<<8;
104 size|=fgetc(ips);
105
106 //FCEU_printf(" Offset: %8d Size: %5d RLE\n",offset,size);
107
108 if((offset+size)>(uint32)fp->size)
109 {
110 // Probably a little slow.
111 char *newbuf=(char *)FCEU_realloc(buf,offset+size);
112 buf=newbuf;
113 memset(buf+fp->size,0,offset+size-fp->size);
114 fp->size=offset+size;
115 }
116 b=fgetc(ips);
117 start=buf+offset;
118 do
119 {
120 *start=b;
121 start++;
122 } while(--size);

Callers 1

FCEU_fopenFunction · 0.85

Calls 6

FCEU_mallocFunction · 0.85
FCEU_printfFunction · 0.85
FCEU_reallocFunction · 0.85
bufMethod · 0.80
EnsureMemorystreamMethod · 0.80
SetStreamMethod · 0.80

Tested by

no test coverage detected