2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 20:27:42 +00:00

Camera filter refactor

This commit is contained in:
Jack Andersen
2017-05-31 19:34:24 -10:00
parent a550ce1959
commit ca69a54faf
56 changed files with 1201 additions and 260 deletions

View File

@@ -161,7 +161,7 @@ void CTweakPlayer::read(athena::io::IStreamReader& __dna_reader)
x130_ = __dna_reader.readFloatBig();
/* x134_ */
x134_ = __dna_reader.readFloatBig();
/* x138_ */
/* x138_hudLagAmount */
x138_hudLagAmount = __dna_reader.readFloatBig();
/* x13c_ */
x13c_ = __dna_reader.readFloatBig();
@@ -291,33 +291,33 @@ void CTweakPlayer::read(athena::io::IStreamReader& __dna_reader)
x1a0_ = __dna_reader.readFloatBig();
/* x1a4_ */
x1a4_ = __dna_reader.readFloatBig();
/* x1a8_[0] */
/* x1a8_orbitScreenBoxHalfExtentX[0] */
x1a8_orbitScreenBoxHalfExtentX[0] = __dna_reader.readUint32Big();
/* x1b0_[0] */
/* x1b0_orbitScreenBoxHalfExtentY[0] */
x1b0_orbitScreenBoxHalfExtentY[0] = __dna_reader.readUint32Big();
/* x1b8_[0] */
/* x1b8_orbitScreenBoxCenterX[0] */
x1b8_orbitScreenBoxCenterX[0] = __dna_reader.readUint32Big();
/* x1c0_[0] */
/* x1c0_orbitScreenBoxCenterY[0] */
x1c0_orbitScreenBoxCenterY[0] = __dna_reader.readUint32Big();
/* x1c8_[0] */
/* x1c8_enemyScreenBoxCenterX[0] */
x1c8_enemyScreenBoxCenterX[0] = __dna_reader.readUint32Big();
/* x1d0_[0] */
/* x1d0_enemyScreenBoxCenterY[0] */
x1d0_enemyScreenBoxCenterY[0] = __dna_reader.readUint32Big();
/* x1a8_[1] */
/* x1a8_orbitScreenBoxHalfExtentX[1] */
x1a8_orbitScreenBoxHalfExtentX[1] = __dna_reader.readUint32Big();
/* x1b0_[1] */
/* x1b0_orbitScreenBoxHalfExtentY[1] */
x1b0_orbitScreenBoxHalfExtentY[1] = __dna_reader.readUint32Big();
/* x1b8_[1] */
/* x1b8_orbitScreenBoxCenterX[1] */
x1b8_orbitScreenBoxCenterX[1] = __dna_reader.readUint32Big();
/* x1c0_[1] */
/* x1c0_orbitScreenBoxCenterY[1] */
x1c0_orbitScreenBoxCenterY[1] = __dna_reader.readUint32Big();
/* x1c8_[1] */
/* x1c8_enemyScreenBoxCenterX[1] */
x1c8_enemyScreenBoxCenterX[1] = __dna_reader.readUint32Big();
/* x1d0_[1] */
/* x1d0_enemyScreenBoxCenterY[1] */
x1d0_enemyScreenBoxCenterY[1] = __dna_reader.readUint32Big();
/* x1d8_ */
/* x1d8_orbitNearX */
x1d8_orbitNearX = __dna_reader.readFloatBig();
/* x1dc_ */
/* x1dc_orbitNearZ */
x1dc_orbitNearZ = __dna_reader.readFloatBig();
/* x1e0_ */
x1e0_ = __dna_reader.readFloatBig();
@@ -349,17 +349,17 @@ void CTweakPlayer::read(athena::io::IStreamReader& __dna_reader)
x210_ = __dna_reader.readFloatBig();
/* x214_ */
x214_ = __dna_reader.readFloatBig();
/* x218_ */
/* x218_scanningRange */
x218_scanningRange = __dna_reader.readFloatBig();
/* x21c_24_ */
x21c_24_ = __dna_reader.readBool();
/* x21c_25_ */
/* x21c_25_scanFreezesGame */
x21c_25_scanFreezesGame = __dna_reader.readBool();
/* x21c_26_ */
x21c_26_ = __dna_reader.readBool();
/* x220_ */
x220_ = __dna_reader.readFloatBig();
/* x224_ */
/* x224_scanningFrameSenseRange */
x224_scanningFrameSenseRange = __dna_reader.readFloatBig();
/* x2a0_ */
x2a0_ = __dna_reader.readFloatBig();
@@ -437,11 +437,11 @@ void CTweakPlayer::read(athena::io::IStreamReader& __dna_reader)
x2f8_ = __dna_reader.readFloatBig();
/* x2fc_ */
x2fc_ = __dna_reader.readUint32Big();
/* x300_ */
/* x300_variaDamageReduction */
x300_variaDamageReduction = __dna_reader.readFloatBig();
/* x304_ */
/* x304_gravityDamageReduction */
x304_gravityDamageReduction = __dna_reader.readFloatBig();
/* x308_ */
/* x308_phazonDamageReduction */
x308_phazonDamageReduction = __dna_reader.readFloatBig();
}
@@ -731,33 +731,33 @@ void CTweakPlayer::write(athena::io::IStreamWriter& __dna_writer) const
__dna_writer.writeFloatBig(x1a0_);
/* x1a4_ */
__dna_writer.writeFloatBig(x1a4_);
/* x1a8_[0] */
/* x1a8_orbitScreenBoxHalfExtentX[0] */
__dna_writer.writeUint32Big(x1a8_orbitScreenBoxHalfExtentX[0]);
/* x1b0_[0] */
/* x1b0_orbitScreenBoxHalfExtentY[0] */
__dna_writer.writeUint32Big(x1b0_orbitScreenBoxHalfExtentY[0]);
/* x1b8_[0] */
/* x1b8_orbitScreenBoxCenterX[0] */
__dna_writer.writeUint32Big(x1b8_orbitScreenBoxCenterX[0]);
/* x1c0_[0] */
/* x1c0_orbitScreenBoxCenterY[0] */
__dna_writer.writeUint32Big(x1c0_orbitScreenBoxCenterY[0]);
/* x1c8_[0] */
/* x1c8_enemyScreenBoxCenterX[0] */
__dna_writer.writeUint32Big(x1c8_enemyScreenBoxCenterX[0]);
/* x1d0_[0] */
/* x1d0_enemyScreenBoxCenterY[0] */
__dna_writer.writeUint32Big(x1d0_enemyScreenBoxCenterY[0]);
/* x1a8_[1] */
/* x1a8_orbitScreenBoxHalfExtentX[1] */
__dna_writer.writeUint32Big(x1a8_orbitScreenBoxHalfExtentX[1]);
/* x1b0_[1] */
/* x1b0_orbitScreenBoxHalfExtentY[1] */
__dna_writer.writeUint32Big(x1b0_orbitScreenBoxHalfExtentY[1]);
/* x1b8_[1] */
/* x1b8_orbitScreenBoxCenterX[1] */
__dna_writer.writeUint32Big(x1b8_orbitScreenBoxCenterX[1]);
/* x1c0_[1] */
/* x1c0_orbitScreenBoxCenterY[1] */
__dna_writer.writeUint32Big(x1c0_orbitScreenBoxCenterY[1]);
/* x1c8_[1] */
/* x1c8_enemyScreenBoxCenterX[1] */
__dna_writer.writeUint32Big(x1c8_enemyScreenBoxCenterX[1]);
/* x1d0_[1] */
/* x1d0_enemyScreenBoxCenterY[1] */
__dna_writer.writeUint32Big(x1d0_enemyScreenBoxCenterY[1]);
/* x1d8_ */
/* x1d8_orbitNearX */
__dna_writer.writeFloatBig(x1d8_orbitNearX);
/* x1dc_ */
/* x1dc_orbitNearZ */
__dna_writer.writeFloatBig(x1dc_orbitNearZ);
/* x1e0_ */
__dna_writer.writeFloatBig(x1e0_);
@@ -789,17 +789,17 @@ void CTweakPlayer::write(athena::io::IStreamWriter& __dna_writer) const
__dna_writer.writeFloatBig(x210_);
/* x214_ */
__dna_writer.writeFloatBig(x214_);
/* x218_ */
/* x218_scanningRange */
__dna_writer.writeFloatBig(x218_scanningRange);
/* x21c_24_ */
__dna_writer.writeBool(x21c_24_);
/* x21c_25_ */
/* x21c_25_scanFreezesGame */
__dna_writer.writeBool(x21c_25_scanFreezesGame);
/* x21c_26_ */
__dna_writer.writeBool(x21c_26_);
/* x220_ */
__dna_writer.writeFloatBig(x220_);
/* x224_ */
/* x224_scanningFrameSenseRange */
__dna_writer.writeFloatBig(x224_scanningFrameSenseRange);
/* x2a0_ */
__dna_writer.writeFloatBig(x2a0_);
@@ -877,11 +877,11 @@ void CTweakPlayer::write(athena::io::IStreamWriter& __dna_writer) const
__dna_writer.writeFloatBig(x2f8_);
/* x2fc_ */
__dna_writer.writeUint32Big(x2fc_);
/* x300_ */
/* x300_variaDamageReduction */
__dna_writer.writeFloatBig(x300_variaDamageReduction);
/* x304_ */
/* x304_gravityDamageReduction */
__dna_writer.writeFloatBig(x304_gravityDamageReduction);
/* x308_ */
/* x308_phazonDamageReduction */
__dna_writer.writeFloatBig(x308_phazonDamageReduction);
}

View File

@@ -10,6 +10,7 @@
#include "DNACommon/TXTR.hpp"
#include <time.h>
#include <png.h>
namespace DataSpec
{
@@ -402,4 +403,70 @@ void SpecBase::doPackage(const PackagePassInfo& info)
{
}
static void PNGErr(png_structp png, png_const_charp msg)
{
Log.report(logvisor::Error, msg);
}
static void PNGWarn(png_structp png, png_const_charp msg)
{
Log.report(logvisor::Warning, msg);
}
static inline uint8_t Convert4To8(uint8_t v)
{
/* Swizzle bits: 00001234 -> 12341234 */
return (v << 4) | v;
}
void SpecBase::ExtractRandomStaticEntropy(const uint8_t* buf, const hecl::ProjectPath& noAramPath)
{
hecl::ProjectPath entropyPath(noAramPath, _S("RandomStaticEntropy.png"));
hecl::ProjectPath catalogPath(noAramPath, _S("!catalog.yaml"));
if (FILE* fp = hecl::Fopen(catalogPath.getAbsolutePath().c_str(), _S("a")))
{
fprintf(fp, "RandomStaticEntropy: %s\n", entropyPath.getRelativePathUTF8().c_str());
fclose(fp);
}
FILE* fp = hecl::Fopen(entropyPath.getAbsolutePath().c_str(), _S("wb"));
if (!fp)
{
Log.report(logvisor::Error,
_S("Unable to open '%s' for writing"),
entropyPath.getAbsolutePath().c_str());
return;
}
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGErr, PNGWarn);
png_init_io(png, fp);
png_infop info = png_create_info_struct(png);
png_text textStruct = {};
textStruct.key = png_charp("urde_nomip");
png_set_text(png, info, &textStruct, 1);
png_set_IHDR(png, info, 1024, 512, 8,
PNG_COLOR_TYPE_GRAY_ALPHA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png, info);
std::unique_ptr<uint8_t[]> rowbuf(new uint8_t[1024*2]);
for (int y=0 ; y<512 ; ++y)
{
for (int x=0 ; x<1024 ; ++x)
{
uint8_t texel = buf[y*1024+x];
rowbuf[x*2] = Convert4To8(texel >> 4 & 0xf);
rowbuf[x*2+1] = Convert4To8(texel & 0xf);
}
png_write_row(png, rowbuf.get());
}
png_write_end(png, info);
png_write_flush(png);
png_destroy_write_struct(&png, &info);
fclose(fp);
}
}

View File

@@ -113,6 +113,9 @@ struct SpecBase : hecl::Database::IDataSpec
/* Project accessor */
hecl::Database::Project& getProject() const {return m_project;}
/* Extract RandomStatic entropy */
void ExtractRandomStaticEntropy(const uint8_t* buf, const hecl::ProjectPath& noAramPath);
SpecBase(const hecl::Database::DataSpecEntry* specEntry, hecl::Database::Project& project, bool pc);
protected:
hecl::Database::Project& m_project;

View File

@@ -169,6 +169,8 @@ struct SpecMP1 : SpecBase
hecl::ProjectPath m_cookPath;
PAKRouter<DNAMP1::PAKBridge> m_pakRouter;
std::unique_ptr<uint8_t[]> m_dolBuf;
SpecMP1(const hecl::Database::DataSpecEntry* specEntry, hecl::Database::Project& project, bool pc)
: SpecBase(specEntry, project, pc)
, m_workPath(project.getProjectWorkingPath(), _S("MP1"))
@@ -257,8 +259,8 @@ struct SpecMP1 : SpecBase
const std::vector<hecl::SystemString>& args, std::vector<ExtractReport>& reps)
{
nod::Partition* partition = disc.getDataPartition();
std::unique_ptr<uint8_t[]> dolBuf = partition->getDOLBuf();
const char* buildInfo = (char*)memmem(dolBuf.get(), partition->getDOLSize(), "MetroidBuildInfo", 16) + 19;
m_dolBuf = partition->getDOLBuf();
const char* buildInfo = (char*)memmem(m_dolBuf.get(), partition->getDOLSize(), "MetroidBuildInfo", 16) + 19;
if (!buildInfo)
return false;
@@ -318,8 +320,8 @@ struct SpecMP1 : SpecBase
if (dolIt == root.end())
return false;
std::unique_ptr<uint8_t[]> dolBuf = dolIt->getBuf();
const char* buildInfo = (char*)memmem(dolBuf.get(), dolIt->size(), "MetroidBuildInfo", 16) + 19;
m_dolBuf = dolIt->getBuf();
const char* buildInfo = (char*)memmem(m_dolBuf.get(), dolIt->size(), "MetroidBuildInfo", 16) + 19;
/* Root Report */
reps.emplace_back();
@@ -342,7 +344,7 @@ struct SpecMP1 : SpecBase
return true;
}
bool extractFromDisc(nod::DiscBase&, bool force, FProgress progress)
bool extractFromDisc(nod::DiscBase& disc, bool force, FProgress progress)
{
m_project.enableDataSpecs({_S("MP1-PC")});
@@ -419,6 +421,10 @@ struct SpecMP1 : SpecBase
process.waitUntilComplete();
/* Extract part of .dol for RandomStatic entropy */
hecl::ProjectPath noAramPath(m_project.getProjectWorkingPath(), _S("MP1/NoARAM"));
ExtractRandomStaticEntropy(m_dolBuf.get() + 0x4f60, noAramPath);
return true;
}