2011-09-22 00:03:11 +00:00
|
|
|
#ifndef NALL_IPS_HPP
|
|
|
|
#define NALL_IPS_HPP
|
|
|
|
|
|
|
|
#include <nall/file.hpp>
|
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
#include <nall/string.hpp>
|
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
|
|
|
struct ips {
|
|
|
|
inline bool apply();
|
|
|
|
inline void source(const uint8_t *data, unsigned size);
|
|
|
|
inline void modify(const uint8_t *data, unsigned size);
|
|
|
|
inline bool source(const string &filename);
|
|
|
|
inline bool modify(const string &filename);
|
|
|
|
inline ips();
|
|
|
|
inline ~ips();
|
|
|
|
|
|
|
|
uint8_t *data;
|
|
|
|
unsigned size;
|
|
|
|
const uint8_t *sourceData;
|
|
|
|
unsigned sourceSize;
|
|
|
|
const uint8_t *modifyData;
|
|
|
|
unsigned modifySize;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool ips::apply() {
|
|
|
|
if(modifySize < 8) return false;
|
|
|
|
if(modifyData[0] != 'P') return false;
|
|
|
|
if(modifyData[1] != 'A') return false;
|
|
|
|
if(modifyData[2] != 'T') return false;
|
|
|
|
if(modifyData[3] != 'C') return false;
|
|
|
|
if(modifyData[4] != 'H') return false;
|
|
|
|
|
|
|
|
if(data) delete[] data;
|
|
|
|
data = new uint8_t[16 * 1024 * 1024 + 65536](); //maximum size of IPS patch + single-tag padding
|
|
|
|
size = sourceSize;
|
|
|
|
memcpy(data, sourceData, sourceSize);
|
|
|
|
unsigned offset = 5;
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
unsigned address, length;
|
|
|
|
|
|
|
|
if(offset > modifySize - 3) break;
|
|
|
|
address = modifyData[offset++] << 16;
|
|
|
|
address |= modifyData[offset++] << 8;
|
|
|
|
address |= modifyData[offset++] << 0;
|
|
|
|
|
|
|
|
if(address == 0x454f46) { //EOF
|
|
|
|
if(offset == modifySize) return true;
|
|
|
|
if(offset == modifySize - 3) {
|
|
|
|
size = modifyData[offset++] << 16;
|
|
|
|
size |= modifyData[offset++] << 8;
|
|
|
|
size |= modifyData[offset++] << 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(offset > modifySize - 2) break;
|
|
|
|
length = modifyData[offset++] << 8;
|
|
|
|
length |= modifyData[offset++] << 0;
|
|
|
|
|
|
|
|
if(length) { //Copy
|
|
|
|
if(offset > modifySize - length) break;
|
|
|
|
while(length--) data[address++] = modifyData[offset++];
|
|
|
|
} else { //RLE
|
|
|
|
if(offset > modifySize - 3) break;
|
|
|
|
length = modifyData[offset++] << 8;
|
|
|
|
length |= modifyData[offset++] << 0;
|
|
|
|
if(length == 0) break; //illegal
|
|
|
|
while(length--) data[address++] = modifyData[offset];
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = max(size, address);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] data;
|
Update to v084r03 release.
(r02 was not posted to the WIP thread)
byuu says:
Internally, all color is processed with 30-bit precision. The filters
also operate at 30-bit depth.
There's a new config file setting, video.depth, which defaults to 24.
This causes the final output to downsample to 24-bit, as most will
require.
If you set it to 30-bit, the downsampling will not occur, and bsnes will
ask ruby for a 30-bit surface. If you don't have one available, you're
going to get bad colors. Or maybe even a crash with OpenGL.
I don't yet have detection code to make sure you have an appropriate
visual in place.
30-bit mode will really only work if you are running Linux, running Xorg
at Depth 30, use the OpenGL or XShm driver, have an nVidia Quadro or AMD
FireGL card with the official drivers, and have a 30-bit capable
monitor.
Lots of planning and work for very little gain here, but it's nice that
it's finally finished.
Oh, I had to change the contrast/brightness formulas a tiny bit, but
they still work and look nice.
2011-12-03 03:22:54 +00:00
|
|
|
data = nullptr;
|
2011-09-22 00:03:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ips::source(const uint8_t *data, unsigned size) {
|
|
|
|
sourceData = data, sourceSize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ips::modify(const uint8_t *data, unsigned size) {
|
|
|
|
modifyData = data, modifySize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ips::source(const string &filename) {
|
|
|
|
return file::read(filename, sourceData, sourceSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ips::modify(const string &filename) {
|
|
|
|
return file::read(filename, modifyData, modifySize);
|
|
|
|
}
|
|
|
|
|
Update to v084r03 release.
(r02 was not posted to the WIP thread)
byuu says:
Internally, all color is processed with 30-bit precision. The filters
also operate at 30-bit depth.
There's a new config file setting, video.depth, which defaults to 24.
This causes the final output to downsample to 24-bit, as most will
require.
If you set it to 30-bit, the downsampling will not occur, and bsnes will
ask ruby for a 30-bit surface. If you don't have one available, you're
going to get bad colors. Or maybe even a crash with OpenGL.
I don't yet have detection code to make sure you have an appropriate
visual in place.
30-bit mode will really only work if you are running Linux, running Xorg
at Depth 30, use the OpenGL or XShm driver, have an nVidia Quadro or AMD
FireGL card with the official drivers, and have a 30-bit capable
monitor.
Lots of planning and work for very little gain here, but it's nice that
it's finally finished.
Oh, I had to change the contrast/brightness formulas a tiny bit, but
they still work and look nice.
2011-12-03 03:22:54 +00:00
|
|
|
ips::ips() : data(nullptr), sourceData(nullptr), modifyData(nullptr) {
|
2011-09-22 00:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ips::~ips() {
|
|
|
|
if(data) delete[] data;
|
|
|
|
if(sourceData) delete[] sourceData;
|
|
|
|
if(modifyData) delete[] modifyData;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|