Windows porting small changes.

This commit is contained in:
Federico Ponchio 2004-10-10 17:36:43 +00:00
parent d1a97fec8d
commit 255e1f6c43
1 changed files with 21 additions and 8 deletions

View File

@ -1,10 +1,18 @@
#include "patch.h" #include "patch.h"
#ifdef WIN32
#include "minilzo.108/minilzo.h"
#else
#include <lzo1x.h> #include <lzo1x.h>
#endif
#include <iostream> #include <iostream>
using namespace std; using namespace std;
using namespace nxs; using namespace nxs;
#ifdef WIN32
static double wrkmem[LZO1X_1_MEM_COMPRESS/sizeof(double) +1];
#else
static double wrkmem[LZO1X_999_MEM_COMPRESS/sizeof(double) +1]; static double wrkmem[LZO1X_999_MEM_COMPRESS/sizeof(double) +1];
#endif
void pad(unsigned int &size) { void pad(unsigned int &size) {
while(size&0x3) size++; while(size&0x3) size++;
@ -112,28 +120,34 @@ unsigned int Patch::ByteSize(Signature signature,
char *Patch::Compress(unsigned int ram_size, unsigned int &size) { char *Patch::Compress(unsigned int ram_size, unsigned int &size) {
//TODO use OVERLAP and test speed //TODO use OVERLAP and test speed
//TODO fill chunk padding with zeroes? //TODO fill chunk padding with zeroes?
//TODO compress only used memory! //TODO compress only used memory!
size = ram_size + ram_size/64 + 23; size = ram_size + ram_size/64 + 23;
char *buffer = new char[size]; char *buffer = new char[size];
lzo1x_1_compress(((unsigned char *)start), ram_size, #ifdef WIN32
lzo1x_1_compress(((unsigned char *)start), ram_size,
(unsigned char *)buffer + sizeof(int), &size, (unsigned char *)buffer + sizeof(int), &size,
(char *)wrkmem); (char *)wrkmem);
#else
lzo1x_999_compress(((unsigned char *)start), ram_size,
(unsigned char *)buffer + sizeof(int), &size,
(char *)wrkmem);
#endif
*(int *)buffer = size; *(int *)buffer = size;
size += sizeof(int); size += sizeof(int);
// memcpy(buffer, start, ram_size); // memcpy(buffer, start, ram_size);
// size = ram_size; // size = ram_size;
//TODO optimize! //TODO optimize!
// lzo1x_optimize((unsigned char *)entry.patch->start, // lzo1x_optimize((unsigned char *)entry.patch->start,
// entry.ram_size * chunk_size, // entry.ram_size * chunk_size,
// compressed, &compressed_size, NULL); // compressed, &compressed_size, NULL);
return buffer; return buffer;
} }
void Patch::Decompress(unsigned int ram_size, void *src, unsigned int src_sz) { void Patch::Decompress(unsigned int ram_size, void *src, unsigned int src_sz) {
@ -142,7 +156,6 @@ void Patch::Decompress(unsigned int ram_size, void *src, unsigned int src_sz) {
assert(size < src_sz + sizeof(int)); assert(size < src_sz + sizeof(int));
unsigned int dst_size = ram_size; unsigned int dst_size = ram_size;
// memcpy(start, src, ram_size);
int ret = lzo1x_decompress_safe(((unsigned char *)src) + sizeof(int), size, int ret = lzo1x_decompress_safe(((unsigned char *)src) + sizeof(int), size,
(unsigned char *)start, &dst_size, 0); (unsigned char *)start, &dst_size, 0);
if(ret != 0) { if(ret != 0) {