summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2023-09-24 13:39:02 -0600
committerKiritoDv <kiritodev01@gmail.com>2023-09-24 13:39:02 -0600
commitdea6dd369d60c09da6b5c1780010d7a5eb6cc11e (patch)
tree437ca4441ac511b59800d08eb79612fd0f922d18
parent48f52849d052ee60d961bc9e2646e0f33f4fa898 (diff)
Added SPDLOG and a lot of debug information
-rw-r--r--CMakeLists.txt9
-rw-r--r--src/Companion.cpp29
-rw-r--r--src/audio/AudioManager.cpp14
-rw-r--r--src/factories/BankFactory.cpp1
-rw-r--r--src/factories/TextureFactory.cpp5
-rw-r--r--src/factories/sm64/SAnimFactory.cpp14
-rw-r--r--src/factories/sm64/SDialogFactory.cpp17
7 files changed, 64 insertions, 25 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 299c043..16a8e6d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,15 @@ set(YAML_CPP_BUILD_TESTS OFF)
FetchContent_MakeAvailable(yaml-cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE yaml-cpp)
+FetchContent_Declare(
+ spdlog
+ GIT_REPOSITORY https://github.com/gabime/spdlog.git
+ GIT_TAG 7e635fca68d014934b4af8a1cf874f63989352b7
+)
+
+FetchContent_MakeAvailable(spdlog)
+target_link_libraries(${PROJECT_NAME} PRIVATE spdlog)
+
if((CMAKE_SYSTEM_NAME MATCHES "Windows") AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
include(../cmake/HandleCompilerRT.cmake)
find_compiler_rt_library(builtins CLANG_RT_BUILTINS_LIBRARY)
diff --git a/src/Companion.cpp b/src/Companion.cpp
index f18d3c6..e5f5cdd 100644
--- a/src/Companion.cpp
+++ b/src/Companion.cpp
@@ -13,6 +13,7 @@
#include "factories/sm64/SAnimFactory.h"
#include "factories/sm64/STextFactory.h"
#include "factories/sm64/SDialogFactory.h"
+#include "spdlog/spdlog.h"
#include <fstream>
#include <iostream>
@@ -22,6 +23,9 @@ namespace fs = std::filesystem;
void Companion::Init() {
+ spdlog::set_level(spdlog::level::debug);
+ spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
+
this->RegisterFactory("AUDIO:HEADER", new AudioHeaderFactory());
this->RegisterFactory("SEQUENCE", new SequenceFactory());
this->RegisterFactory("SAMPLE", new SampleFactory());
@@ -53,7 +57,7 @@ void Companion::Process() {
YAML::Node config = YAML::LoadFile("config.yml");
if(!config[cartridge->GetHash()]){
- std::cout << "No config found for " << cartridge->GetHash() << '\n';
+ SPDLOG_ERROR("No config found for {}", cartridge->GetHash());
return;
}
@@ -61,6 +65,15 @@ void Companion::Process() {
auto path = cfg["path"].as<std::string>();
auto otr = cfg["output"].as<std::string>();
+
+ SPDLOG_INFO("Starting CubeOS...");
+ SPDLOG_INFO("Game: {}", cartridge->GetGameTitle());
+ SPDLOG_INFO("CRC: {}", cartridge->GetCRC());
+ SPDLOG_INFO("Version: {}", cartridge->GetVersion());
+ SPDLOG_INFO("Country: [{}]", cartridge->GetCountryCode());
+ SPDLOG_INFO("Hash: {}", cartridge->GetHash());
+ SPDLOG_INFO("Assets: {}", path);
+
auto wrapper = SWrapper(otr);
auto vWriter = LUS::BinaryWriter();
@@ -69,7 +82,6 @@ void Companion::Process() {
vWriter.Write(cartridge->GetCRC());
for (const auto & entry : fs::directory_iterator(path)){
- std::cout << "Processing " << entry.path() << '\n';
YAML::Node root = YAML::LoadFile(entry.path().string());
for(auto asset = root.begin(); asset != root.end(); ++asset){
auto type = asset->second["type"].as<std::string>();
@@ -77,8 +89,12 @@ void Companion::Process() {
LUS::BinaryWriter write = LUS::BinaryWriter();
RawFactory* factory = this->GetFactory(type);
+ SPDLOG_INFO("------------------------------------------------");
+ SPDLOG_INFO("Processing {} [{}] from {}", asset->first.as<std::string>(), type);
+ SPDLOG_INFO("Root: {}", entry.path().string());
+
if(!factory->process(&write, asset->second, this->gRomData)){
- std::cout << "Failed to process " << asset->first.as<std::string>() << '\n';
+ SPDLOG_ERROR("Failed to process {}", asset->first.as<std::string>());
continue;
}
@@ -90,6 +106,7 @@ void Companion::Process() {
wrapper.CreateFile(output, buffer);
if(type != "TEXTURE") {
+ SPDLOG_DEBUG("Writing debug file");
std::string dpath = "debug/" + output;
if(!fs::exists(fs::path(dpath).parent_path())){
fs::create_directories(fs::path(dpath).parent_path());
@@ -99,14 +116,17 @@ void Companion::Process() {
stream.close();
}
- std::cout << "Processed " << output << std::endl;
+ SPDLOG_INFO("Processed {}", output);
write.Close();
}
}
+ SPDLOG_INFO("------------------------------------------------");
+ SPDLOG_INFO("Writing version file");
wrapper.CreateFile("version", vWriter.ToVector());
vWriter.Close();
+ SPDLOG_INFO("------------------------------------------------");
MIO0Decoder::ClearCache();
wrapper.Close();
@@ -116,6 +136,7 @@ void Companion::Process() {
void Companion::RegisterFactory(const std::string &extension, RawFactory *factory) {
this->gFactories[extension] = factory;
+ SPDLOG_DEBUG("Registered factory for {}", extension);
}
RawFactory *Companion::GetFactory(const std::string &extension) {
diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp
index 739800c..4410c64 100644
--- a/src/audio/AudioManager.cpp
+++ b/src/audio/AudioManager.cpp
@@ -2,14 +2,14 @@
#include <vector>
#include <sstream>
-#include <fstream>
#include <iostream>
#include <filesystem>
#include <cassert>
#include <cstring>
+#include "hj/zip.h"
#include "hj/pyutils.h"
+#include "spdlog/spdlog.h"
#include "binarytools/BinaryReader.h"
-#include "hj/zip.h"
std::unordered_map<std::string, uint32_t> name_table;
AudioManager* AudioManager::Instance;
@@ -441,16 +441,15 @@ void AudioManager::initialize(std::vector<uint8_t>& buffer, YAML::Node& data) {
std::vector<Entry> tbl = parse_seq_file(buffer, tblOffset, false);
std::vector<Entry> ctl = parse_seq_file(buffer, ctlOffset, true);
- std::cout << "Table entries: " << tbl.size() << std::endl;
- std::cout << "Control entries: " << ctl.size() << std::endl;
+ SPDLOG_INFO("Raw TBL Entries: {}", tbl.size());
+ SPDLOG_INFO("Raw CTL Entries: {}", ctl.size());
std::vector<uint8_t> tbl_data = PyUtils::slice(buffer, tblOffset, tblOffset + tblSize);
std::vector<uint8_t> ctl_data = PyUtils::slice(buffer, ctlOffset, ctlOffset + ctlSize);
this->loaded_tbl = parse_tbl(tbl_data, tbl);
- std::cout << "TBLs: " << this->loaded_tbl.tbls.size() << std::endl;
- std::cout << "Banks: " << this->loaded_tbl.banks.size() << std::endl;
- std::cout << "Map: " << this->loaded_tbl.map.size() << std::endl;
+ SPDLOG_INFO("Processed TBL Entries: {}", this->loaded_tbl.tbls.size());
+ SPDLOG_INFO("Processed TBL Banks: {}", this->loaded_tbl.banks.size());
auto zipped = zip(PyUtils::range(0, ctl.size()), ctl, this->loaded_tbl.tbls);
@@ -462,6 +461,7 @@ void AudioManager::initialize(std::vector<uint8_t>& buffer, YAML::Node& data) {
auto header = parse_ctl_header(headerRaw);
auto bank = parse_ctl(header, PyUtils::slice(entry, 16), sample_bank, index);
banks[index] = bank;
+ SPDLOG_INFO("Processed Bank {}", index);
}
int32_t idx = -1;
diff --git a/src/factories/BankFactory.cpp b/src/factories/BankFactory.cpp
index eec9ed9..f247c3d 100644
--- a/src/factories/BankFactory.cpp
+++ b/src/factories/BankFactory.cpp
@@ -69,7 +69,6 @@ bool BankFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::vect
writer->Write(std::string(gSampleTable[idx]));
writer->Write(value.tuning);
}
-
}
WRITE_U32(bank.drums.size());
diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp
index 257ef20..c92c8a5 100644
--- a/src/factories/TextureFactory.cpp
+++ b/src/factories/TextureFactory.cpp
@@ -1,6 +1,7 @@
#include "TextureFactory.h"
#include "utils/MIODecoder.h"
+#include "spdlog/spdlog.h"
namespace fs = std::filesystem;
@@ -43,5 +44,9 @@ bool TextureFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::v
WRITE_ARRAY(buffer.data() + offset, size);
}
+ SPDLOG_INFO("Texture: {} {}x{} {}", format, width, height, size);
+ SPDLOG_INFO("Offset: {}", offset);
+ SPDLOG_INFO("Has MIO0: {}", data["mio0"] ? "true" : "false");
+
return true;
}
diff --git a/src/factories/sm64/SAnimFactory.cpp b/src/factories/sm64/SAnimFactory.cpp
index 3358e24..06d5944 100644
--- a/src/factories/sm64/SAnimFactory.cpp
+++ b/src/factories/sm64/SAnimFactory.cpp
@@ -1,8 +1,6 @@
#include "SAnimFactory.h"
-#include <iostream>
-#include <filesystem>
-#include "Companion.h"
+#include "spdlog/spdlog.h"
#include "utils/MIODecoder.h"
#include "binarytools/BinaryReader.h"
@@ -25,6 +23,14 @@ void WriteAnimationHeader(LUS::BinaryWriter* writer, YAML::Node& data, std::vect
reader.ReadUInt32();
auto length = reader.ReadUInt32();
+ SPDLOG_INFO("Flags: {}", flags);
+ SPDLOG_INFO("Anim-Y Trans Divisor: {}", animYTransDivisor);
+ SPDLOG_INFO("Start Frame: {}", startFrame);
+ SPDLOG_INFO("Loop Start: {}", loopStart);
+ SPDLOG_INFO("Loop End: {}", loopEnd);
+ SPDLOG_INFO("Unused Bone Count: {}", unusedBoneCount);
+ SPDLOG_INFO("Length: {}", length);
+
WRITE_I16(flags);
WRITE_I16(animYTransDivisor);
WRITE_I16(startFrame);
@@ -42,6 +48,7 @@ void WriteAnimationIndex(LUS::BinaryWriter* writer, YAML::Node& data, std::vecto
LUS::BinaryReader reader((char*) buffer.data() + offset, size);
reader.SetEndianness(LUS::Endianness::Big);
size_t entries = size / sizeof(uint16_t);
+ SPDLOG_INFO("Found Indices: {}", entries);
WRITE_U32(entries);
for(size_t id = 0; id < entries; id++) {
WRITE_I16(reader.ReadInt16());
@@ -56,6 +63,7 @@ void WriteAnimationValues(LUS::BinaryWriter* writer, YAML::Node& data, std::vect
LUS::BinaryReader reader((char*) buffer.data() + offset, size);
reader.SetEndianness(LUS::Endianness::Big);
size_t entries = size / sizeof(uint16_t);
+ SPDLOG_INFO("Found Values: {}", entries);
WRITE_U32(entries);
for(size_t id = 0; id < entries; id++) {
WRITE_U16(reader.ReadUInt16());
diff --git a/src/factories/sm64/SDialogFactory.cpp b/src/factories/sm64/SDialogFactory.cpp
index ad6cca4..474690a 100644
--- a/src/factories/sm64/SDialogFactory.cpp
+++ b/src/factories/sm64/SDialogFactory.cpp
@@ -1,6 +1,7 @@
#include <iostream>
#include "SDialogFactory.h"
+#include "spdlog/spdlog.h"
#include "utils/MIODecoder.h"
#include "binarytools/BinaryReader.h"
@@ -38,11 +39,11 @@ bool SDialogFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::v
}
text.push_back(0xFF);
- std::cout << "unused: " << unused << std::endl;
- std::cout << "linesPerBox: " << (int) linesPerBox << std::endl;
- std::cout << "leftOffset: " << leftOffset << std::endl;
- std::cout << "width: " << width << std::endl;
- std::cout << "size: " << text.size() << std::endl;
+ SPDLOG_INFO("Unused: {}", unused);
+ SPDLOG_INFO("Lines per box: {}", linesPerBox);
+ SPDLOG_INFO("Left offset: {}", leftOffset);
+ SPDLOG_INFO("Width: {}", width);
+ SPDLOG_INFO("Size: {}", text.size());
WRITE_U32(unused);
WRITE_I8(linesPerBox);
@@ -58,8 +59,4 @@ bool SDialogFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::v
id++;
return true;
-}
-
-// seg2_dialog_table
-// seg2_course_name_table
-// seg2_act_name_table
+} \ No newline at end of file