Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Jan 14, 2022
1 parent f35a86e commit 6bd3298
Show file tree
Hide file tree
Showing 19 changed files with 525 additions and 403 deletions.
129 changes: 4 additions & 125 deletions ScratchProject/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
std::shared_ptr<Sqex::RandomAccessStream> StripSecondaryMipmaps(std::shared_ptr<Sqex::RandomAccessStream> src) {
return src;

auto stream = std::make_shared<Sqex::Texture::ModifiableTextureStream>(std::move(src));
stream->TruncateMipmap(1);
auto stream = std::make_shared<Sqex::Texture::ModifiableTextureStream>(std::make_shared<Sqex::MemoryRandomAccessStream>(*src));
stream->Resize(1, stream->GetRepeatCount());
return stream;
}

Expand Down Expand Up @@ -115,7 +115,7 @@ std::string DumpSqtexInfo(std::span<uint8_t> buf) {
const auto subBlocks = std::span(reinterpret_cast<uint16_t*>(&buf[sizeof entryHeader + locators.size_bytes()]), locators.back().FirstSubBlockIndex.Value() + locators.back().SubBlockCount.Value());
const auto& texHeader = *reinterpret_cast<Sqex::Texture::Header*>(&buf[entryHeader.HeaderSize]);
ss << std::format("Unk1={} Header={} Type={} Width={} Height={} Layers={} Mipmaps={}\n",
texHeader.Unknown1.Value(), texHeader.HeaderSize.Value(), static_cast<uint32_t>(texHeader.Type.Value()), texHeader.Width.Value(), texHeader.Height.Value(), texHeader.Layers.Value(), texHeader.MipmapCount.Value());
texHeader.Unknown1.Value(), texHeader.HeaderSize.Value(), static_cast<uint32_t>(texHeader.Type.Value()), texHeader.Width.Value(), texHeader.Height.Value(), texHeader.Depth.Value(), texHeader.MipmapCount.Value());
const auto mipmapOffsets = std::span(reinterpret_cast<uint32_t*>(&buf[entryHeader.HeaderSize + sizeof texHeader]), texHeader.MipmapCount);

ss << "Locators:\n";
Expand Down Expand Up @@ -150,55 +150,6 @@ std::string DumpSqtexInfo(std::span<uint8_t> buf) {
}

int main() {
//const auto reader = Sqex::Sqpack::Reader(LR"(C:\Program Files (x86)\SquareEnix\FINAL FANTASY XIV - A Realm Reborn\game\sqpack\ffxiv\020000.win32.index)");

//std::vector<uint8_t> buf, buf2, buf3;
//std::map<Sqex::Sqpack::SqIndex::LEDataLocator, Sqex::Sqpack::SqIndex::LEDataLocator> locatorMap;
//for (size_t i = 0; i < reader.EntryInfo.size(); ++i) {
// // if (i != 22883) continue;
// if (i != 22889) continue;
// //if (i != 164870) continue;
// //if (i != 174182) continue;
// const auto& [locator, entry] = reader.EntryInfo[i];
// if (!locator.Value)
// continue;

// std::cout << std::format("{:0>6}/{:0>6} Locator={:08x} FullPathHash={:08x} PathHash={:08x} NameHash={:08x}\n",
// i, reader.EntryInfo.size(),
// locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash);

// buf.resize(entry.Allocation);
// reader.Data[locator.DatFileIndex].Stream->ReadStream(locator.DatFileOffset(), std::span(buf));
// auto& eh = *reinterpret_cast<Sqex::Sqpack::SqData::FileEntryHeader*>(&buf[0]);
// eh.AllocatedSpaceUnitCount = eh.OccupiedSpaceUnitCount;
// buf.resize(eh.GetTotalEntrySize());

// const auto provider = std::make_shared<Sqex::Sqpack::RandomAccessStreamAsEntryProviderView>(entry.PathSpec, std::make_shared<Sqex::MemoryRandomAccessStream>(std::span(buf)));
// if (provider->EntryType() != Sqex::Sqpack::SqData::FileEntryType::Texture)
// continue;

// const auto rawStream = std::make_shared<Sqex::Sqpack::EntryRawStream>(provider.get());
// buf2.resize(rawStream->StreamSize());
// rawStream->ReadStream(0, std::span(buf2));

// const auto decompressedEntryProvider = std::make_shared<Sqex::Sqpack::MemoryTextureEntryProvider>(entry.PathSpec, rawStream);
// buf3.resize(decompressedEntryProvider->StreamSize());
// decompressedEntryProvider->ReadStreamPartial(0, &buf3[0], buf3.size());

// if (memcmp(&buf[0], &buf3[0], buf3.size()) == 0)
// continue;

// DumpSqtexInfo(std::span(buf));
// DumpSqtexInfo(std::span(buf3));

// std::ofstream(std::format(L"Z:/sqpacktest/{}_{:0>6}_{:08x}_{:08x}_{:08x}_{:08x}.sqd", L"000000", i, locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash), std::ios::binary)
// .write(reinterpret_cast<const char*>(buf.data()), buf.size());
// std::ofstream(std::format(L"Z:/sqpacktest/{}_{:0>6}_{:08x}_{:08x}_{:08x}_{:08x}.tex", L"000000", i, locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash), std::ios::binary)
// .write(reinterpret_cast<const char*>(buf2.data()), buf2.size());
// std::ofstream(std::format(L"Z:/sqpacktest/{}_{:0>6}_{:08x}_{:08x}_{:08x}_{:08x}.rep", L"000000", i, locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash), std::ios::binary)
// .write(reinterpret_cast<const char*>(buf3.data()), buf3.size());
//}

Utils::Win32::TpEnvironment tpenv(L"Sqpack Repacker");
for (const auto& index : std::filesystem::recursive_directory_iterator(std::filesystem::path(LR"(C:\Program Files (x86)\SquareEnix\FINAL FANTASY XIV - A Realm Reborn\game\sqpack\)"))) {
if (index.path().extension() != ".index")
Expand Down Expand Up @@ -239,81 +190,9 @@ int main() {
continue;
}
creator.AddEntry(ToDecompressedEntryProvider(ep));

/*const auto provider = std::make_shared<Sqex::Sqpack::RandomAccessStreamAsEntryProviderView>(entry.PathSpec, std::make_shared<Sqex::MemoryRandomAccessStream>(std::span(buf)));
auto rawStream = std::make_shared<Sqex::Sqpack::EntryRawStream>(provider.get());
buf2.resize(rawStream->StreamSize());
rawStream->ReadStream(0, std::span(buf2));
const wchar_t* fileType;
std::shared_ptr<Sqex::Sqpack::EntryProvider> decompressedEntryProvider;
switch (rawStream->EntryType()) {
case Sqex::Sqpack::SqData::FileEntryType::Binary:
fileType = L"bin";
decompressedEntryProvider = std::make_shared<Sqex::Sqpack::MemoryBinaryEntryProvider>(entry.PathSpec, std::move(rawStream));
break;
case Sqex::Sqpack::SqData::FileEntryType::Model:
fileType = L"mdl";
decompressedEntryProvider = std::make_shared<Sqex::Sqpack::MemoryModelEntryProvider>(entry.PathSpec, std::move(rawStream));
break;
case Sqex::Sqpack::SqData::FileEntryType::Texture:
fileType = L"tex";
decompressedEntryProvider = std::make_shared<Sqex::Sqpack::MemoryTextureEntryProvider>(entry.PathSpec, std::move(rawStream));
break;
default:
continue;
}
buf3.resize(decompressedEntryProvider->StreamSize());
decompressedEntryProvider->ReadStreamPartial(0, &buf3[0], buf3.size());
auto ep = reader.GetEntryProvider(entry.PathSpec, locator, entry.Allocation);
if (memcmp(&buf[0], &buf3[0], buf3.size()) == 0)
creator.AddEntry(ToDecompressedEntryProvider(ep));
else {
creator.AddEntry(ep);
if (provider->EntryType() == Sqex::Sqpack::SqData::FileEntryType::Texture) {
auto s = DumpSqtexInfo(buf);
std::ofstream(std::format(L"Z:/sqpacktest/{}_{:0>6}_{:08x}_{:08x}_{:08x}_{:08x}.sqd.txt", creator.DatName, i, locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash, fileType), std::ios::binary)
.write(s.data(), s.size());
}
std::ofstream(std::format(L"Z:/sqpacktest/{}_{:0>6}_{:08x}_{:08x}_{:08x}_{:08x}.sqd", creator.DatName, i, locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash), std::ios::binary)
.write(reinterpret_cast<const char*>(buf.data()), buf.size());
std::ofstream(std::format(L"Z:/sqpacktest/{}_{:0>6}_{:08x}_{:08x}_{:08x}_{:08x}.{}", creator.DatName, i, locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash, fileType), std::ios::binary)
.write(reinterpret_cast<const char*>(buf2.data()), buf2.size());
if (provider->EntryType() == Sqex::Sqpack::SqData::FileEntryType::Texture) {
auto s = DumpSqtexInfo(buf3);
std::ofstream(std::format(L"Z:/sqpacktest/{}_{:0>6}_{:08x}_{:08x}_{:08x}_{:08x}.rep.txt", creator.DatName, i, locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash, fileType), std::ios::binary)
.write(s.data(), s.size());
}
std::ofstream(std::format(L"Z:/sqpacktest/{}_{:0>6}_{:08x}_{:08x}_{:08x}_{:08x}.rep", creator.DatName, i, locator.Value, entry.PathSpec.FullPathHash, entry.PathSpec.PathHash, entry.PathSpec.NameHash), std::ios::binary)
.write(reinterpret_cast<const char*>(buf3.data()), buf3.size());
}*/
}

const auto views = creator.AsViews(false);
if (views.Entries.empty()) {
std::filesystem::copy(path, dir / path.filename());
std::filesystem::copy(std::filesystem::path(path).replace_extension(".index2"), dir / path.filename().replace_extension(".index2"));
std::filesystem::copy(std::filesystem::path(path).replace_extension(".dat0"), dir / path.filename().replace_extension(".dat0"));
return;
}

StreamToFile(*views.Index1, (dir / path.filename()).string() + ".tmp");
StreamToFile(*views.Index2, (dir / path.filename().replace_extension(".index2")).string() + ".tmp");
for (size_t i = 0; i < views.Data.size(); ++i)
StreamToFile(*views.Data[i], (dir / path.filename().replace_extension(std::format(".dat{}", i))).string() + ".tmp");

std::filesystem::rename((dir / path.filename()).string() + ".tmp", dir / path.filename());
std::filesystem::rename((dir / path.filename().replace_extension(".index2")).string() + ".tmp", dir / path.filename().replace_extension(".index2"));
for (size_t i = 0; i < views.Data.size(); ++i)
std::filesystem::rename((dir / path.filename().replace_extension(std::format(".dat{}", i))).string() + ".tmp",
dir / path.filename().replace_extension(std::format(".dat{}", i)));
creator.WriteToFiles(dir);
});
}
tpenv.WaitOutstanding();
Expand Down
10 changes: 5 additions & 5 deletions StaticData/FontConfig/SourceHanSansK.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@
"dwrite:SourceHanSansK:9.6": {
"familyName": "Source Han Sans K",
"height": 10,
"renderMode": "DWRITE_RENDERING_MODE_NATURAL",
"weight": 600
},
"dwrite:SourceHanSansK:12": {
"familyName": "Source Han Sans K",
"height": 12,
"weight": 500
"renderMode": "DWRITE_RENDERING_MODE_NATURAL",
"weight": 600
},
"dwrite:SourceHanSansK:14": {
"familyName": "Source Han Sans K",
Expand All @@ -126,13 +128,11 @@
},
"dwrite:SourceHanSansK:24": {
"familyName": "Source Han Sans K",
"height": 24,
"weight": 500
"height": 24
},
"dwrite:SourceHanSansK:36": {
"familyName": "Source Han Sans K",
"height": 36,
"weight": 500
"height": 36
}
},
"ranges": {
Expand Down
Loading

0 comments on commit 6bd3298

Please sign in to comment.