mirror of
				https://github.com/PancakeTAS/lsfg-vk.git
				synced 2025-10-30 07:01:10 +00:00 
			
		
		
		
	refactor: fixing imports
This commit is contained in:
		
							parent
							
								
									cfbc105b9d
								
							
						
					
					
						commit
						0bdc70a4c3
					
				
					 6 changed files with 30 additions and 22 deletions
				
			
		|  | @ -14,9 +14,11 @@ project(lsfg-vk-framegen | |||
|     LANGUAGES C CXX) | ||||
| 
 | ||||
| file(GLOB SOURCES | ||||
|     "src/trans/*.cpp" | ||||
|     "src/vk/core/*.cpp" | ||||
|     "src/vk/pool/*.cpp" | ||||
|     "src/vk/registry/*.cpp" | ||||
|     "src/vk/types/*.cpp" | ||||
|     "src/vk/*.cpp" | ||||
|     "src/*.cpp" | ||||
|     "src/thirdparty/*.c" | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ namespace Trans::DLL { | |||
|     /// @param filename Path to the DLL file.
 | ||||
|     /// @return A map of resource IDs to their binary data.
 | ||||
|     ///
 | ||||
|     /// @throws std::runtime_error on various failure points.
 | ||||
|     /// @throws LSFG::error on various failure points.
 | ||||
|     ///
 | ||||
|     std::unordered_map<uint32_t, std::vector<uint8_t>> parseDLL( | ||||
|         const std::filesystem::path& filename); | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| #include "exception.hpp" | ||||
| 
 | ||||
| #include <exception> | ||||
| #include <stdexcept> | ||||
| #include <format> | ||||
| #include <string> | ||||
|  |  | |||
|  | @ -1,6 +1,8 @@ | |||
| #include "lsfg.hpp" | ||||
| #include "trans/rsrc.hpp" | ||||
| 
 | ||||
| #include <filesystem> | ||||
| 
 | ||||
| using namespace LSFG; | ||||
| 
 | ||||
| Instance::Instance(const std::filesystem::path& dll) | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| #include "trans/dll.hpp" | ||||
| #include "exception.hpp" | ||||
| 
 | ||||
| #include <unordered_map> | ||||
| #include <filesystem> | ||||
| #include <stdexcept> | ||||
| #include <algorithm> | ||||
| #include <iostream> | ||||
| #include <optional> | ||||
|  | @ -78,7 +78,7 @@ namespace { | |||
|     const T* safe_cast(const std::vector<uint8_t>& data, size_t offset) { | ||||
|         const size_t end = offset + sizeof(T); | ||||
|         if (end > data.size() || end < offset) | ||||
|             throw std::runtime_error("Buffer overflow during safe cast"); | ||||
|             throw LSFG::error("Buffer overflow during safe cast"); | ||||
|         return reinterpret_cast<const T*>(&data.at(offset)); | ||||
|     } | ||||
| 
 | ||||
|  | @ -87,7 +87,7 @@ namespace { | |||
|     std::span<const T> span_cast(const std::vector<uint8_t>& data, size_t offset, size_t count) { | ||||
|         const size_t end = offset + (count * sizeof(T)); | ||||
|         if (end > data.size() || end < offset) | ||||
|             throw std::runtime_error("Buffer overflow during safe cast"); | ||||
|             throw LSFG::error("Buffer overflow during safe cast"); | ||||
|         return std::span<const T>(reinterpret_cast<const T*>(&data.at(offset)), count); | ||||
|     } | ||||
| } | ||||
|  | @ -97,32 +97,32 @@ std::unordered_map<uint32_t, std::vector<uint8_t>> DLL::parseDLL( | |||
|         const std::filesystem::path& filename) { | ||||
|     std::ifstream file(filename, std::ios::binary | std::ios::ate); | ||||
|     if (!file.is_open()) | ||||
|         throw std::runtime_error("Failed to open Lossless.dll"); | ||||
|         throw LSFG::error("Failed to open Lossless.dll"); | ||||
| 
 | ||||
|     const auto size = file.tellg(); | ||||
|     file.seekg(0, std::ios::beg); | ||||
| 
 | ||||
|     std::vector<uint8_t> data(static_cast<size_t>(size)); | ||||
|     if (!file.read(reinterpret_cast<char*>(data.data()), size)) | ||||
|         throw std::runtime_error("Failed to read Lossless.dll"); | ||||
|         throw LSFG::error("Failed to read Lossless.dll"); | ||||
| 
 | ||||
|     // parse dos header
 | ||||
|     size_t fileOffset = 0; | ||||
|     const auto* dosHdr = safe_cast<const DOSHeader>(data, 0); | ||||
|     if (dosHdr->magic != 0x5A4D) | ||||
|         throw std::runtime_error("Invalid DOS header magic number"); | ||||
|         throw LSFG::error("Invalid DOS header magic number"); | ||||
| 
 | ||||
|     // parse pe header
 | ||||
|     fileOffset += static_cast<size_t>(dosHdr->pe_offset); | ||||
|     const auto* peHdr = safe_cast<const PEHeader>(data, fileOffset); | ||||
|     if (peHdr->signature != 0x00004550) | ||||
|         throw std::runtime_error("Invalid PE header signature"); | ||||
|         throw LSFG::error("Invalid PE header signature"); | ||||
| 
 | ||||
|     // parse optional pe header
 | ||||
|     fileOffset += sizeof(PEHeader); | ||||
|     const auto* peOptHdr = safe_cast<const PEOptionalHeader>(data, fileOffset); | ||||
|     if (peOptHdr->magic != 0x20B) | ||||
|         throw std::runtime_error("Unsupported PE format (not PE32+)"); | ||||
|         throw LSFG::error("Unsupported PE format (not PE32+)"); | ||||
|     const auto& [rsrc_rva, rsrc_size] = peOptHdr->resource_table; | ||||
| 
 | ||||
|     // locate section containing resources
 | ||||
|  | @ -137,13 +137,13 @@ std::unordered_map<uint32_t, std::vector<uint8_t>> DLL::parseDLL( | |||
|         break; | ||||
|     } | ||||
|     if (!rsrc_offset) | ||||
|         throw std::runtime_error("Failed to locate resource section"); | ||||
|         throw LSFG::error("Failed to locate resource section"); | ||||
| 
 | ||||
|     // parse resource directory
 | ||||
|     fileOffset = rsrc_offset.value(); | ||||
|     const auto* rsrcDir = safe_cast<const ResourceDirectory>(data, fileOffset); | ||||
|     if (rsrcDir->id_count < 3) | ||||
|         throw std::runtime_error("Incorrect resource directory"); | ||||
|         throw LSFG::error("Incorrect resource directory"); | ||||
| 
 | ||||
|     // find resource table with data type
 | ||||
|     std::optional<size_t> rsrc_tbl_offset; | ||||
|  | @ -154,18 +154,18 @@ std::unordered_map<uint32_t, std::vector<uint8_t>> DLL::parseDLL( | |||
|         if (rsrcDirEntry.id != 10) // RT_RCDATA
 | ||||
|             continue; | ||||
|         if ((rsrcDirEntry.offset & 0x80000000) == 0) | ||||
|             throw std::runtime_error("Expected resource directory, but found data entry"); | ||||
|             throw LSFG::error("Expected resource directory, but found data entry"); | ||||
| 
 | ||||
|         rsrc_tbl_offset.emplace(rsrcDirEntry.offset & 0x7FFFFFFF); | ||||
|     } | ||||
|     if (!rsrc_tbl_offset) | ||||
|         throw std::runtime_error("Failed to locate RT_RCDATA directory"); | ||||
|         throw LSFG::error("Failed to locate RT_RCDATA directory"); | ||||
| 
 | ||||
|     // parse data type resource directory
 | ||||
|     fileOffset = rsrc_offset.value() + rsrc_tbl_offset.value(); | ||||
|     const auto* rsrcTbl = safe_cast<const ResourceDirectory>(data, fileOffset); | ||||
|     if (rsrcTbl->id_count < 1) | ||||
|         throw std::runtime_error("Incorrect RT_RCDATA directory"); | ||||
|         throw LSFG::error("Incorrect RT_RCDATA directory"); | ||||
| 
 | ||||
|     // collect all resources
 | ||||
|     fileOffset += sizeof(ResourceDirectory); | ||||
|  | @ -174,30 +174,30 @@ std::unordered_map<uint32_t, std::vector<uint8_t>> DLL::parseDLL( | |||
|     std::unordered_map<uint32_t, std::vector<uint8_t>> resources; | ||||
|     for (const auto& rsrcTblEntry : rsrcTblEntries) { | ||||
|         if ((rsrcTblEntry.offset & 0x80000000) == 0) | ||||
|             throw std::runtime_error("Expected resource directory, but found data entry"); | ||||
|             throw LSFG::error("Expected resource directory, but found data entry"); | ||||
| 
 | ||||
|         // skip over language directory
 | ||||
|         fileOffset = rsrc_offset.value() + (rsrcTblEntry.offset & 0x7FFFFFFF); | ||||
|         const auto* langDir = safe_cast<const ResourceDirectory>(data, fileOffset); | ||||
|         if (langDir->id_count < 1) | ||||
|             throw std::runtime_error("Incorrect language directory"); | ||||
|             throw LSFG::error("Incorrect language directory"); | ||||
| 
 | ||||
|         fileOffset += sizeof(ResourceDirectory); | ||||
|         const auto* langDirEntry = safe_cast<const ResourceDirectoryEntry>(data, fileOffset); | ||||
|         if ((langDirEntry->offset & 0x80000000) != 0) | ||||
|             throw std::runtime_error("Expected resource data entry, but found directory"); | ||||
|             throw LSFG::error("Expected resource data entry, but found directory"); | ||||
| 
 | ||||
|         // parse resource data entry
 | ||||
|         fileOffset = rsrc_offset.value() + (langDirEntry->offset & 0x7FFFFFFF); | ||||
|         const auto* entry = safe_cast<const ResourceDataEntry>(data, fileOffset); | ||||
|         if (entry->offset < rsrc_rva || entry->offset > (rsrc_rva + rsrc_size)) | ||||
|             throw std::runtime_error("Resource data entry points outside resource section"); | ||||
|             throw LSFG::error("Resource data entry points outside resource section"); | ||||
| 
 | ||||
|         // extract resource
 | ||||
|         std::vector<uint8_t> resource(entry->size); | ||||
|         fileOffset = (entry->offset - rsrc_rva) + rsrc_offset.value(); | ||||
|         if (fileOffset + entry->size > data.size()) | ||||
|             throw std::runtime_error("Resource data entry points outside file"); | ||||
|             throw LSFG::error("Resource data entry points outside file"); | ||||
|         std::copy_n(&data.at(fileOffset), entry->size, resource.data()); | ||||
|         resources.emplace(rsrcTblEntry.id, std::move(resource)); | ||||
|     } | ||||
|  |  | |||
|  | @ -1,10 +1,13 @@ | |||
| #include "trans/rsrc.hpp" | ||||
| #include "exception.hpp" | ||||
| #include "trans/dll.hpp" | ||||
| #include "vk/registry/shader_registry.hpp" | ||||
| #include "exception.hpp" | ||||
| 
 | ||||
| #include <unordered_map> | ||||
| #include <filesystem> | ||||
| #include <cstddef> | ||||
| #include <cstdint> | ||||
| #include <filesystem> | ||||
| #include <string> | ||||
| #include <vector> | ||||
| 
 | ||||
| using namespace Trans; | ||||
|  | @ -56,7 +59,7 @@ void RSRC::loadResources( | |||
|     std::unordered_map<uint32_t, std::vector<uint8_t>> rsrcs; | ||||
|     try { | ||||
|         rsrcs = DLL::parseDLL(filename); | ||||
|     } catch (const std::runtime_error& e) { | ||||
|     } catch (const LSFG::error& e) { | ||||
|         throw LSFG::error("Unable to parse Lossless.dll file", e); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 PancakeTAS
						PancakeTAS