From 645c45431b0e091234699c3706ff90d1654cfb57 Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 26 Jul 2021 06:11:01 +0200 Subject: Pokemon related decomp (#47) * decompile last function in pokemon_1.s * some pokemon related decomp * more decomp * decomp another function * decompile function * another one * decompile GetPokemonLevelData * decompile more * more decomp * more structure and decomp * decomp another function (need to do some renaming) * rename some stuff * I cant do anything without committing these 2 files --- tools/scaninc/scaninc.cpp | 256 ++++++++++++++++++++--------------------- tools/scaninc/source_file.cpp | 260 +++++++++++++++++++++--------------------- 2 files changed, 258 insertions(+), 258 deletions(-) (limited to 'tools') diff --git a/tools/scaninc/scaninc.cpp b/tools/scaninc/scaninc.cpp index a91b872..a3e40c5 100644 --- a/tools/scaninc/scaninc.cpp +++ b/tools/scaninc/scaninc.cpp @@ -1,128 +1,128 @@ -// Copyright(c) 2015-2017 YamaArashi -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#include -#include -#include -#include -#include -#include -#include "scaninc.h" -#include "source_file.h" - -bool CanOpenFile(std::string path) -{ - FILE *fp = std::fopen(path.c_str(), "rb"); - - if (fp == NULL) - return false; - - std::fclose(fp); - return true; -} - -const char *const USAGE = "Usage: scaninc [-I INCLUDE_PATH] FILE_PATH\n"; - -int main(int argc, char **argv) -{ - std::queue filesToProcess; - std::set dependencies; - - std::vector includeDirs; - - argc--; - argv++; - - while (argc > 1) - { - std::string arg(argv[0]); - if (arg.substr(0, 2) == "-I") - { - std::string includeDir = arg.substr(2); - if (includeDir.empty()) - { - argc--; - argv++; - includeDir = std::string(argv[0]); - } - if (!includeDir.empty() && includeDir.back() != '/') - { - includeDir += '/'; - } - includeDirs.push_back(includeDir); - } - else - { - FATAL_ERROR(USAGE); - } - argc--; - argv++; - } - - if (argc != 1) { - FATAL_ERROR(USAGE); - } - - std::string initialPath(argv[0]); - - filesToProcess.push(initialPath); - - while (!filesToProcess.empty()) - { - std::string filePath = filesToProcess.front(); - SourceFile file(filePath); - filesToProcess.pop(); - - includeDirs.push_back(file.GetSrcDir()); - for (auto incbin : file.GetIncbins()) - { - dependencies.insert(incbin); - } - for (auto include : file.GetIncludes()) - { - bool exists = false; - std::string path(""); - for (auto includeDir : includeDirs) - { - path = includeDir + include; - if (CanOpenFile(path)) - { - exists = true; - break; - } - } - if (!exists && file.FileType() == SourceFileType::Asm) - { - path = include; - } - bool inserted = dependencies.insert(path).second; - if (inserted && exists) - { - filesToProcess.push(path); - } - } - includeDirs.pop_back(); - } - - for (const std::string &path : dependencies) - { - std::printf("%s\n", path.c_str()); - } -} +// Copyright(c) 2015-2017 YamaArashi +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include +#include +#include +#include +#include +#include +#include "scaninc.h" +#include "source_file.h" + +bool CanOpenFile(std::string path) +{ + FILE *fp = std::fopen(path.c_str(), "rb"); + + if (fp == NULL) + return false; + + std::fclose(fp); + return true; +} + +const char *const USAGE = "Usage: scaninc [-I INCLUDE_PATH] FILE_PATH\n"; + +int main(int argc, char **argv) +{ + std::queue filesToProcess; + std::set dependencies; + + std::vector includeDirs; + + argc--; + argv++; + + while (argc > 1) + { + std::string arg(argv[0]); + if (arg.substr(0, 2) == "-I") + { + std::string includeDir = arg.substr(2); + if (includeDir.empty()) + { + argc--; + argv++; + includeDir = std::string(argv[0]); + } + if (!includeDir.empty() && includeDir.back() != '/') + { + includeDir += '/'; + } + includeDirs.push_back(includeDir); + } + else + { + FATAL_ERROR(USAGE); + } + argc--; + argv++; + } + + if (argc != 1) { + FATAL_ERROR(USAGE); + } + + std::string initialPath(argv[0]); + + filesToProcess.push(initialPath); + + while (!filesToProcess.empty()) + { + std::string filePath = filesToProcess.front(); + SourceFile file(filePath); + filesToProcess.pop(); + + includeDirs.push_back(file.GetSrcDir()); + for (auto incbin : file.GetIncbins()) + { + dependencies.insert(incbin); + } + for (auto include : file.GetIncludes()) + { + bool exists = false; + std::string path(""); + for (auto includeDir : includeDirs) + { + path = includeDir + include; + if (CanOpenFile(path)) + { + exists = true; + break; + } + } + if (!exists && file.FileType() == SourceFileType::Asm) + { + path = include; + } + bool inserted = dependencies.insert(path).second; + if (inserted && exists) + { + filesToProcess.push(path); + } + } + includeDirs.pop_back(); + } + + for (const std::string &path : dependencies) + { + std::printf("%s\n", path.c_str()); + } +} diff --git a/tools/scaninc/source_file.cpp b/tools/scaninc/source_file.cpp index 255c818..df31282 100644 --- a/tools/scaninc/source_file.cpp +++ b/tools/scaninc/source_file.cpp @@ -1,130 +1,130 @@ -// Copyright(c) 2019 Phlosioneer -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#include -#include "source_file.h" - - -SourceFileType GetFileType(std::string& path) -{ - std::size_t pos = path.find_last_of('.'); - - if (pos == std::string::npos) - FATAL_ERROR("no file extension in path \"%s\"\n", path.c_str()); - - std::string extension = path.substr(pos + 1); - - if (extension == "c") - return SourceFileType::Cpp; - else if (extension == "s") - return SourceFileType::Asm; - else if (extension == "h") - return SourceFileType::Header; - else if (extension == "inc") - return SourceFileType::Inc; - else - FATAL_ERROR("Unrecognized extension \"%s\"\n", extension.c_str()); - - // Unreachable - return SourceFileType::Cpp; -} - -std::string GetDir(std::string& path) -{ - std::size_t slash = path.rfind('/'); - - if (slash != std::string::npos) - return path.substr(0, slash + 1); - else - return std::string(""); -} - -SourceFile::SourceFile(std::string path) -{ - m_file_type = GetFileType(path); - - m_src_dir = GetDir(path); - - if (m_file_type == SourceFileType::Cpp - || m_file_type == SourceFileType::Header) - { - new (&m_source_file.c_file) CFile(path); - m_source_file.c_file.FindIncbins(); - } - else - { - AsmFile file(path); - std::set incbins; - std::set includes; - - IncDirectiveType incDirectiveType; - std::string outputPath; - - while ((incDirectiveType = file.ReadUntilIncDirective(outputPath)) != IncDirectiveType::None) - { - if (incDirectiveType == IncDirectiveType::Include) - includes.insert(outputPath); - else - incbins.insert(outputPath); - } - - new (&m_source_file.asm_wrapper) SourceFile::InnerUnion::AsmWrapper{incbins, includes}; - } -} - -SourceFileType SourceFile::FileType() -{ - return m_file_type; -} - -SourceFile::~SourceFile() -{ - if (m_file_type == SourceFileType::Cpp || m_file_type == SourceFileType::Header) - { - m_source_file.c_file.~CFile(); - } - else - { - m_source_file.asm_wrapper.asm_incbins.~set(); - m_source_file.asm_wrapper.asm_includes.~set(); - } -} - -const std::set& SourceFile::GetIncbins() -{ - if (m_file_type == SourceFileType::Cpp || m_file_type == SourceFileType::Header) - return m_source_file.c_file.GetIncbins(); - else - return m_source_file.asm_wrapper.asm_incbins; -} - -const std::set& SourceFile::GetIncludes() -{ - if (m_file_type == SourceFileType::Cpp || m_file_type == SourceFileType::Header) - return m_source_file.c_file.GetIncludes(); - else - return m_source_file.asm_wrapper.asm_includes; -} - -std::string& SourceFile::GetSrcDir() -{ - return m_src_dir; -} - +// Copyright(c) 2019 Phlosioneer +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include +#include "source_file.h" + + +SourceFileType GetFileType(std::string& path) +{ + std::size_t pos = path.find_last_of('.'); + + if (pos == std::string::npos) + FATAL_ERROR("no file extension in path \"%s\"\n", path.c_str()); + + std::string extension = path.substr(pos + 1); + + if (extension == "c") + return SourceFileType::Cpp; + else if (extension == "s") + return SourceFileType::Asm; + else if (extension == "h") + return SourceFileType::Header; + else if (extension == "inc") + return SourceFileType::Inc; + else + FATAL_ERROR("Unrecognized extension \"%s\"\n", extension.c_str()); + + // Unreachable + return SourceFileType::Cpp; +} + +std::string GetDir(std::string& path) +{ + std::size_t slash = path.rfind('/'); + + if (slash != std::string::npos) + return path.substr(0, slash + 1); + else + return std::string(""); +} + +SourceFile::SourceFile(std::string path) +{ + m_file_type = GetFileType(path); + + m_src_dir = GetDir(path); + + if (m_file_type == SourceFileType::Cpp + || m_file_type == SourceFileType::Header) + { + new (&m_source_file.c_file) CFile(path); + m_source_file.c_file.FindIncbins(); + } + else + { + AsmFile file(path); + std::set incbins; + std::set includes; + + IncDirectiveType incDirectiveType; + std::string outputPath; + + while ((incDirectiveType = file.ReadUntilIncDirective(outputPath)) != IncDirectiveType::None) + { + if (incDirectiveType == IncDirectiveType::Include) + includes.insert(outputPath); + else + incbins.insert(outputPath); + } + + new (&m_source_file.asm_wrapper) SourceFile::InnerUnion::AsmWrapper{incbins, includes}; + } +} + +SourceFileType SourceFile::FileType() +{ + return m_file_type; +} + +SourceFile::~SourceFile() +{ + if (m_file_type == SourceFileType::Cpp || m_file_type == SourceFileType::Header) + { + m_source_file.c_file.~CFile(); + } + else + { + m_source_file.asm_wrapper.asm_incbins.~set(); + m_source_file.asm_wrapper.asm_includes.~set(); + } +} + +const std::set& SourceFile::GetIncbins() +{ + if (m_file_type == SourceFileType::Cpp || m_file_type == SourceFileType::Header) + return m_source_file.c_file.GetIncbins(); + else + return m_source_file.asm_wrapper.asm_incbins; +} + +const std::set& SourceFile::GetIncludes() +{ + if (m_file_type == SourceFileType::Cpp || m_file_type == SourceFileType::Header) + return m_source_file.c_file.GetIncludes(); + else + return m_source_file.asm_wrapper.asm_includes; +} + +std::string& SourceFile::GetSrcDir() +{ + return m_src_dir; +} + -- cgit v1.2.3