mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-04-02 10:42:14 -04:00
byuu says: Changelog: - added Cocoa target: higan can now be compiled for OS X Lion [Cydrak, byuu] - SNES/accuracy profile hires color blending improvements - fixes Marvelous text [AWJ] - fixed a slight bug in SNES/SA-1 VBR support caused by a typo - added support for multi-pass shaders that can load external textures (requires OpenGL 3.2+) - added game library path (used by ananke->Import Game) to Settings->Advanced - system profiles, shaders and cheats database can be stored in "all users" shared folders now (eg /usr/share on Linux) - all configuration files are in BML format now, instead of XML (much easier to read and edit this way) - main window supports drag-and-drop of game folders (but not game files / ZIP archives) - audio buffer clears when entering a modal loop on Windows (prevents audio repetition with DirectSound driver) - a substantial amount of code clean-up (probably the biggest refactoring to date) One highly desired target for this release was to default to the optimal drivers instead of the safest drivers, but because AMD drivers don't seem to like my OpenGL 3.2 driver, I've decided to postpone that. AMD has too big a market share. Hopefully with v093 officially released, we can get some public input on what AMD doesn't like.
126 lines
2.8 KiB
C++
126 lines
2.8 KiB
C++
#ifndef NALL_UNZIP_HPP
|
|
#define NALL_UNZIP_HPP
|
|
|
|
#include <nall/filemap.hpp>
|
|
#include <nall/inflate.hpp>
|
|
#include <nall/string.hpp>
|
|
#include <nall/vector.hpp>
|
|
|
|
namespace nall {
|
|
|
|
struct unzip {
|
|
struct File {
|
|
string name;
|
|
const uint8_t* data;
|
|
unsigned size;
|
|
unsigned csize;
|
|
unsigned cmode; //0 = uncompressed, 8 = deflate
|
|
unsigned crc32;
|
|
};
|
|
|
|
inline bool open(const string& filename) {
|
|
close();
|
|
if(fm.open(filename, filemap::mode::read) == false) return false;
|
|
if(open(fm.data(), fm.size()) == false) {
|
|
fm.close();
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
inline bool open(const uint8_t* data, unsigned size) {
|
|
if(size < 22) return false;
|
|
|
|
filedata = data;
|
|
filesize = size;
|
|
|
|
file.reset();
|
|
|
|
const uint8_t* footer = data + size - 22;
|
|
while(true) {
|
|
if(footer <= data + 22) return false;
|
|
if(read(footer, 4) == 0x06054b50) {
|
|
unsigned commentlength = read(footer + 20, 2);
|
|
if(footer + 22 + commentlength == data + size) break;
|
|
}
|
|
footer--;
|
|
}
|
|
const uint8_t* directory = data + read(footer + 16, 4);
|
|
|
|
while(true) {
|
|
unsigned signature = read(directory + 0, 4);
|
|
if(signature != 0x02014b50) break;
|
|
|
|
File file;
|
|
file.cmode = read(directory + 10, 2);
|
|
file.crc32 = read(directory + 16, 4);
|
|
file.csize = read(directory + 20, 4);
|
|
file.size = read(directory + 24, 4);
|
|
|
|
unsigned namelength = read(directory + 28, 2);
|
|
unsigned extralength = read(directory + 30, 2);
|
|
unsigned commentlength = read(directory + 32, 2);
|
|
|
|
char* filename = new char[namelength + 1];
|
|
memcpy(filename, directory + 46, namelength);
|
|
filename[namelength] = 0;
|
|
file.name = filename;
|
|
delete[] filename;
|
|
|
|
unsigned offset = read(directory + 42, 4);
|
|
unsigned offsetNL = read(data + offset + 26, 2);
|
|
unsigned offsetEL = read(data + offset + 28, 2);
|
|
file.data = data + offset + 30 + offsetNL + offsetEL;
|
|
|
|
directory += 46 + namelength + extralength + commentlength;
|
|
|
|
this->file.append(file);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
inline vector<uint8_t> extract(File& file) {
|
|
vector<uint8_t> buffer;
|
|
|
|
if(file.cmode == 0) {
|
|
buffer.resize(file.size);
|
|
memcpy(buffer.data(), file.data, file.size);
|
|
}
|
|
|
|
if(file.cmode == 8) {
|
|
buffer.resize(file.size);
|
|
if(inflate(buffer.data(), buffer.size(), file.data, file.csize) == false) {
|
|
buffer.reset();
|
|
}
|
|
}
|
|
|
|
return buffer;
|
|
}
|
|
|
|
inline void close() {
|
|
if(fm.open()) fm.close();
|
|
}
|
|
|
|
~unzip() {
|
|
close();
|
|
}
|
|
|
|
protected:
|
|
filemap fm;
|
|
const uint8_t* filedata;
|
|
unsigned filesize;
|
|
|
|
unsigned read(const uint8_t* data, unsigned size) {
|
|
unsigned result = 0, shift = 0;
|
|
while(size--) { result |= *data++ << shift; shift += 8; }
|
|
return result;
|
|
}
|
|
|
|
public:
|
|
vector<File> file;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|