mirror of
https://github.com/ModOrganizer2/libbsarch.git
synced 2026-07-27 14:06:31 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8331290047 | ||
|
|
4f7aeaf4f1 | ||
|
|
4f32506570 | ||
|
|
bf840701de | ||
|
|
37f139a236 | ||
|
|
3a277db0fb |
@@ -134,6 +134,7 @@ ui_*.h
|
||||
*.jsc
|
||||
Makefile*
|
||||
*build-*
|
||||
vsbuild
|
||||
|
||||
# Qt unit tests
|
||||
target_wrapper.*
|
||||
|
||||
+104
-81
@@ -1,73 +1,92 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
option(copy_dll_to_binary_dir "Will copy libbsarch DLL to the binary directory. May not work if libbsarch is used as a subproject" ON)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
# Project
|
||||
project(libbsarch CXX)
|
||||
|
||||
# Add library to build.
|
||||
add_library(libbsarch SHARED
|
||||
src/DDS.h
|
||||
src/libbsarch.h
|
||||
src/libbsarch.cpp
|
||||
src/libbsarch.def
|
||||
)
|
||||
|
||||
target_compile_features(libbsarch PRIVATE cxx_std_11)
|
||||
|
||||
# Preprocessor definitions
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
if(MSVC)
|
||||
target_compile_options(libbsarch PRIVATE /W3 /MDd /Od /EHsc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
if(MSVC)
|
||||
target_compile_options(libbsarch PRIVATE /W3 /Zi /EHsc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_compile_definitions(libbsarch PRIVATE BSARCH_DLL_EXPORT)
|
||||
|
||||
#We only want the lib file. The DLL will be provided by Delphi
|
||||
#Removing the generated DLL
|
||||
add_custom_command(TARGET libbsarch POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E remove
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libbsarch.dll)
|
||||
|
||||
############################################################
|
||||
# libbsarch_OOP #
|
||||
############################################################
|
||||
|
||||
find_package(mo2-dds-header CONFIG REQUIRED)
|
||||
find_package(Qt6 COMPONENTS Core REQUIRED)
|
||||
|
||||
add_library(libbsarch_OOP STATIC
|
||||
src/base_types.hpp
|
||||
src/bs_archive_auto.cpp
|
||||
src/bs_archive_auto.hpp
|
||||
src/bs_archive.cpp
|
||||
src/bs_archive.h
|
||||
src/bs_archive_entries.cpp
|
||||
src/bs_archive_entries.h
|
||||
src/dds.h
|
||||
get_target_property(SRCS mo2::dds-header SOURCES)
|
||||
|
||||
src/libbsarch.hpp
|
||||
src/libbsarch.h
|
||||
src/dds.h
|
||||
# libbsarch
|
||||
add_library(libbsarch SHARED)
|
||||
target_sources(libbsarch
|
||||
PRIVATE
|
||||
src/libbsarch.cpp
|
||||
src/libbsarch.def
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/libbsarch.h
|
||||
)
|
||||
target_include_directories(libbsarch PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch)
|
||||
set_target_properties(libbsarch PROPERTIES DEBUG_POSTFIX "d" CXX_STANDARD 11)
|
||||
target_link_libraries(libbsarch PUBLIC mo2::dds-header)
|
||||
target_compile_definitions(libbsarch PRIVATE BSARCH_DLL_EXPORT)
|
||||
|
||||
src/utils/convertible_string.cpp
|
||||
src/utils/convertible_string.hpp
|
||||
src/utils/convertible_ostream.cpp
|
||||
src/utils/convertible_ostream.hpp
|
||||
src/utils/string_convert.cpp
|
||||
src/utils/string_convert.hpp
|
||||
# preprocessor definitions
|
||||
if(MSVC)
|
||||
target_compile_options(libbsarch PRIVATE
|
||||
/W3 /EHsc /MP
|
||||
$<$<CONFIG:DEBUG>:/MDd /Od>
|
||||
$<$<CONFIG:RELEASE>:/Zi>
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
## Copying the corresponding DLL ##
|
||||
# libbsarch_OOP
|
||||
add_library(libbsarch_OOP STATIC)
|
||||
|
||||
#Finding 32 or 64bits
|
||||
target_sources(libbsarch_OOP
|
||||
PRIVATE
|
||||
src/bs_archive_entries.cpp
|
||||
src/utils/string_convert.cpp
|
||||
src/utils/convertible_ostream.cpp
|
||||
src/utils/convertible_string.cpp
|
||||
src/bs_archive_auto.cpp
|
||||
src/bs_archive.cpp
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/base_types.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive_auto.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive_entries.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/libbsarch.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/libbsarch.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/utils/convertible_string.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/utils/convertible_ostream.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/utils/string_convert.hpp
|
||||
)
|
||||
target_include_directories(libbsarch_OOP PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/utils)
|
||||
target_link_libraries(libbsarch_OOP PUBLIC mo2::dds-header)
|
||||
|
||||
set_target_properties(libbsarch_OOP PROPERTIES
|
||||
DEBUG_POSTFIX "d"
|
||||
CXX_STANDARD 17
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(libbsarch_OOP PRIVATE /MP)
|
||||
endif()
|
||||
|
||||
# adding Qt support
|
||||
if(Qt6_FOUND)
|
||||
message("libbsarch: Qt6 found, enabling Qt support")
|
||||
target_link_libraries(libbsarch_OOP PUBLIC Qt::Core)
|
||||
target_compile_definitions(libbsarch PUBLIC "LIBBSARCH_QT_SUPPORT")
|
||||
target_compile_definitions(libbsarch_OOP PUBLIC "LIBBSARCH_QT_SUPPORT")
|
||||
endif()
|
||||
|
||||
# target_link_libraries(libbsarch_OOP PUBLIC libbsarch)
|
||||
|
||||
# install
|
||||
|
||||
# finding 32 or 64bits
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
# 64 bits
|
||||
set(lib_delphi "${CMAKE_CURRENT_SOURCE_DIR}/delphi/lib64")
|
||||
@@ -78,30 +97,34 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
message("libbsarch: using 32bits DLL")
|
||||
endif()
|
||||
|
||||
if(copy_dll_to_binary_dir)
|
||||
#Finding debug or release
|
||||
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||
set(libbsarch_dll_path "${lib_delphi}/libbsarchd.dll")
|
||||
else()
|
||||
set(libbsarch_dll_path "${lib_delphi}/libbsarch.dll")
|
||||
endif()
|
||||
install(TARGETS libbsarch libbsarch_OOP EXPORT libbsarchTargets FILE_SET HEADERS)
|
||||
install(FILES $<TARGET_PDB_FILE:libbsarch> DESTINATION pdb OPTIONAL)
|
||||
install(EXPORT libbsarchTargets
|
||||
FILE mo2-libbsarch-targets.cmake
|
||||
NAMESPACE mo2::
|
||||
DESTINATION lib/cmake/mo2-libbsarch
|
||||
)
|
||||
|
||||
#Actually copying the DLL
|
||||
add_custom_command(TARGET libbsarch POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${libbsarch_dll_path}
|
||||
${CMAKE_BINARY_DIR}/libbsarch.dll)
|
||||
message("libbsarch: Copying the DLL to ${CMAKE_BINARY_DIR}/libbsarch.dll")
|
||||
endif()
|
||||
# install the true DLLs
|
||||
install(FILES ${lib_delphi}/libbsarch.dll DESTINATION bin CONFIGURATIONS Release RelWithDebInfo MinSizeRel)
|
||||
install(FILES ${lib_delphi}/libbsarchd.dll DESTINATION bin CONFIGURATIONS Debug)
|
||||
|
||||
#Adding Qt support
|
||||
if(Qt6_FOUND)
|
||||
message("libbsarch: Qt6 found, enabling Qt support")
|
||||
target_link_libraries(libbsarch_OOP PUBLIC Qt::Core)
|
||||
target_compile_definitions(libbsarch PUBLIC "QT")
|
||||
target_compile_definitions(libbsarch_OOP PUBLIC "QT")
|
||||
endif()
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config.cmake"
|
||||
INSTALL_DESTINATION "lib/cmake/mo2-libbsarch"
|
||||
NO_SET_AND_CHECK_MACRO
|
||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||
)
|
||||
|
||||
target_link_libraries(libbsarch_OOP PUBLIC libbsarch)
|
||||
target_compile_features(libbsarch_OOP PRIVATE cxx_std_17)
|
||||
target_compile_definitions(libbsarch_OOP PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config-version.cmake"
|
||||
VERSION "0.0.13"
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
ARCH_INDEPENDENT
|
||||
)
|
||||
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config-version.cmake
|
||||
DESTINATION lib/cmake/mo2-libbsarch
|
||||
)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"configurePresets": [
|
||||
{
|
||||
"binaryDir": "${sourceDir}/vsbuild",
|
||||
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
|
||||
"generator": "Visual Studio 17 2022",
|
||||
"name": "vs2022-windows"
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "vs2022-windows",
|
||||
"configurePreset": "vs2022-windows"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
# BSArchive DLL and C++ bindings
|
||||
|
||||
BSArchive Dynamic Link Library and C++ bindings
|
||||
|
||||
## How to build
|
||||
@@ -9,7 +10,7 @@ BSArchive Dynamic Link Library and C++ bindings
|
||||
|
||||
## How to use
|
||||
|
||||
With CMake:
|
||||
With CMake:
|
||||
Use ``add_subdirectory`` and ``target_link_library``
|
||||
Then ``#include "libbsarch.h"`` for the C wrapper, or ``#include "bs_archive_auto"`` for the C++ wrapper.
|
||||
See the example for code use.
|
||||
@@ -20,4 +21,5 @@ Use `libbsarch.dll` (provided in delphi/lib), `libbsarch.lib` and `libbsarch.h`
|
||||
## Credits
|
||||
|
||||
The original BSArchive can be found at: https://github.com/TES5Edit/TES5Edit/tree/dev/Tools/BSArchive
|
||||
The version in this project had been modified for better compatibility with C/C++ and allow the users to allocate their own memory in some cases.
|
||||
The version in this project had been modified for better compatibility with C/C++ and
|
||||
allow the users to allocate their own memory in some cases.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include ( "${CMAKE_CURRENT_LIST_DIR}/mo2-libbsarch-targets.cmake" )
|
||||
|
||||
target_link_libraries(mo2::libbsarch PUBLIC mo2::libbsarch_OOP)
|
||||
|
||||
# libbsarch is usually be build in Debug or Release/RelWithDebInfo, so we need to map
|
||||
# missing configurations to avoid issue with CMP0111
|
||||
list(FIND _LIBBSARCH_CONFIGURATIONS "RELEASE" _LIBBSARCH_HAS_RELEASE)
|
||||
if (_LIBBSARCH_HAS_RELEASE EQUAL -1)
|
||||
set_target_properties(mo2::libbsarch PROPERTIES
|
||||
MAP_IMPORTED_CONFIG_MINSIZEREL RelWithDebInfo
|
||||
MAP_IMPORTED_CONFIG_RELEASE RelWithDebInfo
|
||||
)
|
||||
set_property(TARGET mo2::libbsarch APPEND PROPERTY IMPORTED_CONFIGURATIONS MINSIZEREL)
|
||||
set_property(TARGET mo2::libbsarch APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
|
||||
else()
|
||||
set_target_properties(mo2::libbsarch PROPERTIES
|
||||
MAP_IMPORTED_CONFIG_MINSIZEREL Release
|
||||
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
|
||||
)
|
||||
set_property(TARGET mo2::libbsarch APPEND PROPERTY IMPORTED_CONFIGURATIONS MINSIZEREL)
|
||||
set_property(TARGET mo2::libbsarch APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
|
||||
endif()
|
||||
Binary file not shown.
Binary file not shown.
+4
-21
@@ -9,10 +9,6 @@ uses
|
||||
wbBSArchive;
|
||||
|
||||
type
|
||||
TwbBSResultBuffer = packed record
|
||||
size: Cardinal;
|
||||
data: PByte;
|
||||
end;
|
||||
TwbBSResultCode = (
|
||||
BSA_RESULT_NONE = 0,
|
||||
BSA_RESULT_EXCEPTION = -1
|
||||
@@ -197,14 +193,10 @@ begin
|
||||
end;
|
||||
|
||||
function bsa_add_file_from_memory(obj: Pointer; const aFilePath: PChar; const aSize: Cardinal; const aData: PByte): TwbBSResultMessage; stdcall;
|
||||
var
|
||||
Buffer: TBytes;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
SetLength(Buffer, aSize);
|
||||
Move(aData[0], Buffer[0], aSize);
|
||||
try
|
||||
TwbBSArchive(obj).AddFileData(String(aFilePath), Buffer);
|
||||
TwbBSArchive(obj).AddFileData(String(aFilePath), aSize, aData);
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
@@ -221,14 +213,10 @@ begin
|
||||
end;
|
||||
|
||||
function bsa_extract_file_data_by_record(obj: Pointer; aFileRecord: Pointer): TwbBSResultMessageBuffer; stdcall;
|
||||
var
|
||||
Buffer: TBytes;
|
||||
begin
|
||||
Result.message.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
Buffer := TwbBSArchive(obj).ExtractFileData(aFileRecord);
|
||||
Result.buffer.data := @Buffer[0];
|
||||
Result.buffer.size := Length(Buffer);
|
||||
Result.buffer := TwbBSArchive(obj).ExtractFileData(aFileRecord);
|
||||
except
|
||||
on E: Exception do
|
||||
buffer_exception_handler(E, Result);
|
||||
@@ -236,14 +224,10 @@ begin
|
||||
end;
|
||||
|
||||
function bsa_extract_file_data_by_filename(obj: Pointer; const aFilePath: PChar): TwbBSResultMessageBuffer; stdcall;
|
||||
var
|
||||
Buffer: TBytes;
|
||||
begin
|
||||
Result.message.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
Buffer := TwbBSArchive(obj).ExtractFileData(String(aFilePath));
|
||||
Result.buffer.data := @Buffer[0];
|
||||
Result.buffer.size := Length(Buffer);
|
||||
Result.buffer := TwbBSArchive(obj).ExtractFileData(String(aFilePath));
|
||||
except
|
||||
on E: Exception do
|
||||
buffer_exception_handler(E, Result);
|
||||
@@ -254,8 +238,7 @@ function bsa_file_data_free(obj: Pointer; fileDataResult: TwbBSResultMessageBuff
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
FreeMem(fileDataResult.buffer.data);
|
||||
fileDataResult.buffer.size := 0;
|
||||
TwbBSArchive(obj).ReleaseFileData(fileDataResult.buffer);
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
|
||||
+73
-45
@@ -232,11 +232,11 @@ type
|
||||
TBSArchiveType = (baNone, baTES3, baTES4, baFO3, baSSE, baFO4, baFO4dds, baSF, baSFdds);
|
||||
TBSArchiveState = (stReading, stWriting);
|
||||
TBSArchiveStates = set of TBSArchiveState;
|
||||
TBSFileIterationProc = function(aArchive: TwbBSArchive; const aFileName: string;
|
||||
TBSFileIterationProc = function(aArchive: Pointer; const aFileName: string;
|
||||
aFileRecord: Pointer; aFolderRecord: Pointer; aData: Pointer): Boolean; stdcall;
|
||||
|
||||
TDDSInfo = record Width, Height, MipMaps: Integer; end;
|
||||
TBSFileDDSInfoProc = procedure(aArchive: TwbBSArchive; const aFileName: string;
|
||||
TBSFileDDSInfoProc = procedure(aArchive: Pointer; const aFileName: string;
|
||||
var aInfo: TDDSInfo; aContext: Pointer); stdcall;
|
||||
|
||||
TwbBSHeaderTES3 = packed record
|
||||
@@ -346,6 +346,11 @@ type
|
||||
end;
|
||||
PPackedDataInfo = ^TPackedDataInfo;
|
||||
|
||||
TwbBSResultBuffer = packed record
|
||||
size: Cardinal;
|
||||
data: PByte;
|
||||
end;
|
||||
|
||||
TwbBSArchive = class
|
||||
private
|
||||
fStream: TwbBaseCachedFileStream;
|
||||
@@ -413,11 +418,11 @@ type
|
||||
procedure Save;
|
||||
procedure AddFileDisk(const aFilePath, aSourcePath: string);
|
||||
procedure AddFileDiskRoot(const aRootDir, aSourcePath: string);
|
||||
procedure AddFileData(const aFileName: string; const aData: TBytes); overload;
|
||||
procedure AddFileData(const aFileName: string; const aSize: Cardinal; const aData: PByte); overload;
|
||||
function FindFileRecord(const aFileName: string): Pointer;
|
||||
function ExtractFileData(aFileRecord: Pointer): TBytes; overload;
|
||||
function ExtractFileData(const aFileName: string): TBytes; overload;
|
||||
procedure ExtractFileToStream(const aFileName: string; aStream: TStream);
|
||||
function ExtractFileData(aFileRecord: Pointer): TwbBSResultBuffer; overload;
|
||||
function ExtractFileData(const aFileName: string): TwbBSResultBuffer; overload;
|
||||
procedure ReleaseFileData(fileDataResult: TwbBSResultBuffer);
|
||||
procedure ExtractFile(const aFileName, aSaveAs: string);
|
||||
procedure IterateFiles(aProc: TBSFileIterationProc; aData: Pointer = nil;
|
||||
aSingleThreaded: Boolean = False);
|
||||
@@ -1757,19 +1762,26 @@ procedure TwbBSArchive.AddFileDisk(const aFilePath, aSourcePath: string);
|
||||
var
|
||||
fname: string;
|
||||
i: integer;
|
||||
Buffer: TBytes;
|
||||
buffer: PByte;
|
||||
stream: TFileStream;
|
||||
begin
|
||||
if not (stWriting in fStates) then
|
||||
raise Exception.Create('Archive is not in writing mode');
|
||||
|
||||
with TFileStream.Create(aSourcePath, fmOpenRead + fmShareDenyNone) do try
|
||||
SetLength(Buffer, Size);
|
||||
Read(Buffer[0], Length(Buffer));
|
||||
stream := TFileStream.Create(aSourcePath, fmOpenRead + fmShareDenyNone);
|
||||
try
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
buffer := AllocMem(stream.Size);
|
||||
try
|
||||
stream.Read(buffer^, stream.Size);
|
||||
AddFileData(aFilePath, stream.Size, buffer);
|
||||
finally
|
||||
if Assigned(buffer) then
|
||||
FreeMem(buffer);
|
||||
end;
|
||||
finally
|
||||
Free;
|
||||
stream.Free;
|
||||
end;
|
||||
|
||||
AddFileData(aFilePath, Buffer);
|
||||
end;
|
||||
|
||||
procedure TwbBSArchive.AddFileDiskRoot(const aRootDir, aSourcePath: string);
|
||||
@@ -1919,7 +1931,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TwbBSArchive.AddFileData(const aFileName: string; const aData: TBytes);
|
||||
procedure TwbBSArchive.AddFileData(const aFileName: string; const aSize: Cardinal; const aData: PByte);
|
||||
var
|
||||
i, j, Off, MipSize, BitsPerPixel: integer;
|
||||
DataHash: TPackedDataHash;
|
||||
@@ -1932,7 +1944,7 @@ begin
|
||||
|
||||
// dds mipmaps have their own partial hash calculation down below
|
||||
if fShareData and not (fType in [baFO4dds, baSFdds]) then
|
||||
DataHash := CalcDataHash(@aData[0], Length(aData));
|
||||
DataHash := CalcDataHash(@aData[0], aSize);
|
||||
|
||||
SyncBeginWrite;
|
||||
try
|
||||
@@ -1941,7 +1953,7 @@ begin
|
||||
if not FindFileRecordTES3(aFileName, i) then
|
||||
raise Exception.Create('File not found in files table: ' + aFileName);
|
||||
|
||||
PackData(@fFilesTES3[i], aFileName, DataHash, @aData[0], Length(aData), False);
|
||||
PackData(@fFilesTES3[i], aFileName, DataHash, @aData[0], aSize, False);
|
||||
end;
|
||||
|
||||
baTES4, baFO3, baSSE: begin
|
||||
@@ -1950,7 +1962,7 @@ begin
|
||||
|
||||
PackData(
|
||||
@fFoldersTES4[i].Files[j], fFoldersTES4[i].Name + '\' + fFoldersTES4[i].Files[j].Name,
|
||||
DataHash, @aData[0], Length(aData), fFoldersTES4[i].Files[j].Compress(Self)
|
||||
DataHash, @aData[0], aSize, fFoldersTES4[i].Files[j].Compress(Self)
|
||||
);
|
||||
end;
|
||||
|
||||
@@ -1959,11 +1971,11 @@ begin
|
||||
raise Exception.Create('File not found in files table: ' + aFileName);
|
||||
|
||||
fFilesFO4[i].Offset := fStream.Position;
|
||||
fFilesFO4[i].Size := Length(aData);
|
||||
fFilesFO4[i].Size := aSize;
|
||||
|
||||
PackData(
|
||||
@fFilesFO4[i], fFilesFO4[i].Name,
|
||||
DataHash, @aData[0], Length(aData), fFilesFO4[i].Compress(Self)
|
||||
DataHash, @aData[0], aSize, fFilesFO4[i].Compress(Self)
|
||||
);
|
||||
end;
|
||||
|
||||
@@ -2081,7 +2093,7 @@ begin
|
||||
else begin
|
||||
// last chunk stores all remaining mipmaps
|
||||
fFilesFO4[i].TexChunks[j].EndMip := Pred(fFilesFO4[i].NumMips);
|
||||
MipSize := Length(aData) - Off;
|
||||
MipSize := Integer(aSize) - Off;
|
||||
end;
|
||||
|
||||
DataHash := CalcDataHash(@aData[Off], MipSize);
|
||||
@@ -2102,7 +2114,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TwbBSArchive.ExtractFileData(aFileRecord: Pointer): TBytes;
|
||||
function TwbBSArchive.ExtractFileData(aFileRecord: Pointer): TwbBSResultBuffer;
|
||||
var
|
||||
FileTES3: PwbBSFileTES3;
|
||||
FileTES4: PwbBSFileTES4;
|
||||
@@ -2125,8 +2137,9 @@ begin
|
||||
baTES3: begin
|
||||
FileTES3 := aFileRecord;
|
||||
fStream.Position := fDataOffset + FileTES3.Offset;
|
||||
SetLength(Result, FileTES3.Size);
|
||||
fStream.ReadBuffer(Result[0], Length(Result));
|
||||
Result.size := FileTES3.Size;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(FileTES3.Size);
|
||||
end;
|
||||
|
||||
baTES4, baFO3, baSSE: begin
|
||||
@@ -2145,23 +2158,27 @@ begin
|
||||
|
||||
if bCompressed then begin
|
||||
// reading uncompressed size
|
||||
SetLength(Result, fStream.ReadCardinal);
|
||||
Result.size := fStream.ReadCardinal;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
dec(size, SizeOf(Cardinal));
|
||||
if (Length(Result) > 0) and (size > 0) then begin
|
||||
if (Result.size > 0) and (size > 0) then begin
|
||||
SetLength(Buffer, size);
|
||||
fStream.ReadBuffer(Buffer[0], Length(Buffer));
|
||||
SyncEndWrite;
|
||||
try
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result[0], Length(Result));
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result.data[0], Result.size);
|
||||
finally
|
||||
SyncBeginWrite;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
SetLength(Result, size);
|
||||
Result.size := size;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
if size > 0 then
|
||||
fStream.ReadBuffer(Result[0], size);
|
||||
fStream.ReadBuffer(Result.data[0], Result.size);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -2171,17 +2188,21 @@ begin
|
||||
if FileFO4.PackedSize <> 0 then begin
|
||||
SetLength(Buffer, FileFO4.PackedSize);
|
||||
fStream.ReadBuffer(Buffer[0], Length(Buffer));
|
||||
SetLength(Result, FileFO4.Size);
|
||||
Result.size := FileFO4.Size;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
SyncEndWrite;
|
||||
try
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result[0], Length(Result));
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result.data[0], Result.size);
|
||||
finally
|
||||
SyncBeginWrite;
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
SetLength(Result, FileFO4.Size);
|
||||
fStream.ReadBuffer(Result[0], Length(Result));
|
||||
Result.size := FileFO4.Size;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
fStream.ReadBuffer(Result.data[0], Result.size);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -2191,9 +2212,12 @@ begin
|
||||
TexSize := SizeOf(TDDSHeader);
|
||||
for i := Low(FileFO4.TexChunks) to High(FileFO4.TexChunks) do
|
||||
Inc(TexSize, FileFO4.TexChunks[i].Size);
|
||||
SetLength(Result, TexSize);
|
||||
Result.size := Texsize;
|
||||
|
||||
DDSHeader := @Result[0];
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
|
||||
DDSHeader := @Result.data[0];
|
||||
DDSHeader.Magic := MAGIC_DDS;
|
||||
DDSHeader.dwSize := SizeOf(TDDSHeader) - SizeOf(TMagic4);
|
||||
DDSHeader.dwWidth := FileFO4.Width;
|
||||
@@ -2206,7 +2230,7 @@ begin
|
||||
DDSHeader.dwCaps := DDSHeader.dwCaps or DDSCAPS_MIPMAP or DDSCAPS_COMPLEX;
|
||||
DDSHeader.dwDepth := 1;
|
||||
|
||||
DDSHeaderDX10 := @Result[SizeOf(TDDSHeader)];
|
||||
DDSHeaderDX10 := @Result.data[SizeOf(TDDSHeader)];
|
||||
DDSHeaderDX10.resourceDimension := DDS_DIMENSION_TEXTURE2D;
|
||||
DDSHeaderDX10.arraySize := 1;
|
||||
|
||||
@@ -2381,8 +2405,9 @@ begin
|
||||
|
||||
TexSize := SizeOf(TDDSHeader);
|
||||
if DDSHeader.ddspf.dwFourCC = MAGIC_DX10 then begin
|
||||
SetLength(Result, Length(Result) + SizeOf(TDDSHeaderDX10));
|
||||
ReallocMem(Result.data, Result.size + SizeOf(TDDSHeaderDX10));
|
||||
Inc(TexSize, SizeOf(TDDSHeaderDX10));
|
||||
Result.size := TexSize;
|
||||
end;
|
||||
|
||||
// append chunks
|
||||
@@ -2394,16 +2419,17 @@ begin
|
||||
fStream.ReadBuffer(Buffer[0], Length(Buffer));
|
||||
SyncEndWrite;
|
||||
try
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result[TexSize], Size);
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result.data[TexSize], Size);
|
||||
finally
|
||||
SyncBeginWrite;
|
||||
end;
|
||||
end
|
||||
// uncompressed chunk
|
||||
else
|
||||
fStream.ReadBuffer(Result[TexSize], Size);
|
||||
fStream.ReadBuffer(Result.data[TexSize], Size);
|
||||
|
||||
Inc(TexSize, Size);
|
||||
Result.size := TexSize;
|
||||
end;
|
||||
end
|
||||
|
||||
@@ -2415,7 +2441,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TwbBSArchive.ExtractFileData(const aFileName: string): TBytes;
|
||||
function TwbBSArchive.ExtractFileData(const aFileName: string): TwbBSResultBuffer;
|
||||
var
|
||||
FileRecord: Pointer;
|
||||
begin
|
||||
@@ -2430,25 +2456,27 @@ begin
|
||||
Result := ExtractFileData(FileRecord);
|
||||
end;
|
||||
|
||||
procedure TwbBSArchive.ExtractFileToStream(const aFileName: string; aStream: TStream);
|
||||
var
|
||||
FileData: TBytes;
|
||||
// Addded: For use in non-Borland C/C++
|
||||
procedure TwbBSArchive.ReleaseFileData(fileDataResult: TwbBSResultBuffer);
|
||||
begin
|
||||
FileData := ExtractFileData(aFileName);
|
||||
aStream.Write(FileData[0], Length(FileData));
|
||||
FreeMem(fileDataResult.data);
|
||||
fileDataResult.size := 0;
|
||||
end;
|
||||
|
||||
procedure TwbBSArchive.ExtractFile(const aFileName, aSaveAs: string);
|
||||
var
|
||||
fs: TFileStream;
|
||||
fileData: TwbBSResultBuffer;
|
||||
begin
|
||||
if not (stReading in fStates) then
|
||||
raise Exception.Create('Archive is not loaded');
|
||||
|
||||
fs := TFileStream.Create(aSaveAs, fmCreate);
|
||||
try
|
||||
ExtractFileToStream(aFileName, fs);
|
||||
fileData := ExtractFileData(aFileName);
|
||||
fs.Write(fileData.data[0], fileData.size);
|
||||
finally
|
||||
ReleaseFileData(fileData);
|
||||
fs.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "dds.h"
|
||||
#include <dxgiformat.h>
|
||||
|
||||
#include <DDS.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef BSARCH_DLL_EXPORT
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
operator std::ostream &();
|
||||
operator std::wostream &();
|
||||
|
||||
#ifdef QT
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
operator QDebug();
|
||||
convertible_ostream &operator<<(const QString &rh);
|
||||
#endif
|
||||
@@ -6,11 +6,12 @@
|
||||
|
||||
//See https://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string
|
||||
|
||||
#include "string_convert.hpp"
|
||||
#ifdef QT
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
#include <QString>
|
||||
#endif
|
||||
|
||||
#include "string_convert.hpp"
|
||||
|
||||
namespace libbsarch {
|
||||
class convertible_string
|
||||
{
|
||||
@@ -23,23 +24,20 @@ public:
|
||||
convertible_string(const char *const val_array, bool to_native_path = true);
|
||||
convertible_string(const std::wstring &wvalue, bool to_native_path = true);
|
||||
convertible_string(const wchar_t *const wval_array, bool to_native_path = true);
|
||||
#ifdef QT
|
||||
convertible_string(const QString &qsvalue, bool to_native_path = true);
|
||||
#endif
|
||||
|
||||
/* assignment operators */
|
||||
convertible_string &operator=(const std::string &value);
|
||||
convertible_string &operator=(const std::wstring &wvalue);
|
||||
convertible_string &operator=(const wchar_t *wvalue);
|
||||
#ifdef QT
|
||||
convertible_string &operator=(const QString &qsvalue);
|
||||
#endif
|
||||
|
||||
/* implicit conversion operators */
|
||||
operator std::string() const;
|
||||
operator std::wstring() const;
|
||||
operator const wchar_t *() const;
|
||||
#ifdef QT
|
||||
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
convertible_string(const QString &qsvalue, bool to_native_path = true);
|
||||
convertible_string &operator=(const QString &qsvalue);
|
||||
operator QString() const;
|
||||
#endif
|
||||
|
||||
@@ -4,15 +4,16 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
#pragma once
|
||||
|
||||
#ifdef QT
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
#include <QDebug>
|
||||
#endif
|
||||
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
||||
namespace libbsarch {
|
||||
#ifdef QT
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
std::wstring to_wstring(const QString &str);
|
||||
std::string to_string(const QString &str);
|
||||
QString to_qstring(const std::string &str);
|
||||
@@ -1,240 +0,0 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// dds.h
|
||||
//
|
||||
// This header defines constants and structures that are useful when parsing
|
||||
// DDS files. DDS files were originally designed to use several structures
|
||||
// and constants that are native to DirectDraw and are defined in ddraw.h,
|
||||
// such as DDSURFACEDESC2 and DDSCAPS2. This file defines similar
|
||||
// (compatible) constants and structures so that one can use DDS files
|
||||
// without needing to include ddraw.h.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248926
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
||||
// http://go.microsoft.com/fwlink/?LinkID=615561
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dxgiformat.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace DirectX {
|
||||
#pragma pack(push, 1)
|
||||
|
||||
const uint32_t DDS_MAGIC = 0x20534444; // "DDS "
|
||||
|
||||
struct DDS_PIXELFORMAT
|
||||
{
|
||||
uint32_t size;
|
||||
uint32_t flags;
|
||||
uint32_t fourCC;
|
||||
uint32_t RGBBitCount;
|
||||
uint32_t RBitMask;
|
||||
uint32_t GBitMask;
|
||||
uint32_t BBitMask;
|
||||
uint32_t ABitMask;
|
||||
};
|
||||
|
||||
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
||||
#define DDS_RGB 0x00000040 // DDPF_RGB
|
||||
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
||||
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
||||
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
||||
#define DDS_ALPHAPIXELS 0x00000001 // DDPF_ALPHAPIXELS
|
||||
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
||||
#define DDS_PAL8 0x00000020 // DDPF_PALETTEINDEXED8
|
||||
#define DDS_PAL8A 0x00000021 // DDPF_PALETTEINDEXED8 | DDPF_ALPHAPIXELS
|
||||
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
||||
|
||||
#ifndef MAKEFOURCC
|
||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||
(static_cast<uint32_t>(static_cast<uint8_t>(ch0)) | (static_cast<uint32_t>(static_cast<uint8_t>(ch1)) << 8) \
|
||||
| (static_cast<uint32_t>(static_cast<uint8_t>(ch2)) << 16) \
|
||||
| (static_cast<uint32_t>(static_cast<uint8_t>(ch3)) << 24))
|
||||
#endif /* defined(MAKEFOURCC) */
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_DXT1 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_DXT2 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '2'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_DXT3 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '3'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_DXT4 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '4'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_DXT5 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '5'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_BC4_UNORM = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '4', 'U'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_BC4_SNORM = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '4', 'S'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_BC5_UNORM = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '5', 'U'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_BC5_SNORM = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '5', 'S'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_R8G8_B8G8 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R', 'G', 'B', 'G'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_G8R8_G8B8 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G', 'R', 'G', 'B'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_YUY2 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'), 0, 0, 0, 0, 0};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_A8R8G8B8 = {sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_X8R8G8B8 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_A8B8G8R8 = {sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_X8B8G8R8 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_G16R16 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_R5G6B5 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_A1R5G5B5 = {sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_A4R4G4B4 = {sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_R8G8B8 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000};
|
||||
|
||||
extern __declspec(selectany) const
|
||||
DDS_PIXELFORMAT DDSPF_L8 = {sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00};
|
||||
|
||||
extern __declspec(selectany) const
|
||||
DDS_PIXELFORMAT DDSPF_L16 = {sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_A8L8 = {sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_A8L8_ALT = {sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 8, 0x00ff, 0x0000, 0x0000, 0xff00};
|
||||
|
||||
extern __declspec(selectany) const
|
||||
DDS_PIXELFORMAT DDSPF_A8 = {sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_V8U8 = {sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_Q8W8V8U8 = {sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000};
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_V16U16 = {sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000};
|
||||
|
||||
// D3DFMT_A2R10G10B10/D3DFMT_A2B10G10R10 should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue
|
||||
|
||||
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
||||
DDSPF_DX10 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', '1', '0'), 0, 0, 0, 0, 0};
|
||||
|
||||
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
||||
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
||||
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
|
||||
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
||||
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
||||
|
||||
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
|
||||
#define DDS_WIDTH 0x00000004 // DDSD_WIDTH
|
||||
|
||||
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
||||
#define DDS_SURFACE_FLAGS_MIPMAP 0x00400008 // DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
|
||||
#define DDS_SURFACE_FLAGS_CUBEMAP 0x00000008 // DDSCAPS_COMPLEX
|
||||
|
||||
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
|
||||
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
|
||||
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
|
||||
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
|
||||
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
|
||||
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
|
||||
|
||||
#define DDS_CUBEMAP_ALLFACES \
|
||||
(DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX | DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY \
|
||||
| DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ)
|
||||
|
||||
#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP
|
||||
|
||||
#define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME
|
||||
|
||||
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
|
||||
enum DDS_RESOURCE_DIMENSION
|
||||
{
|
||||
DDS_DIMENSION_TEXTURE1D = 2,
|
||||
DDS_DIMENSION_TEXTURE2D = 3,
|
||||
DDS_DIMENSION_TEXTURE3D = 4,
|
||||
};
|
||||
|
||||
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
|
||||
enum DDS_RESOURCE_MISC_FLAG
|
||||
{
|
||||
DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L,
|
||||
};
|
||||
|
||||
enum DDS_MISC_FLAGS2
|
||||
{
|
||||
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
|
||||
};
|
||||
|
||||
enum DDS_ALPHA_MODE
|
||||
{
|
||||
DDS_ALPHA_MODE_UNKNOWN = 0,
|
||||
DDS_ALPHA_MODE_STRAIGHT = 1,
|
||||
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||
DDS_ALPHA_MODE_OPAQUE = 3,
|
||||
DDS_ALPHA_MODE_CUSTOM = 4,
|
||||
};
|
||||
|
||||
struct DDS_HEADER
|
||||
{
|
||||
uint32_t size;
|
||||
uint32_t flags;
|
||||
uint32_t height;
|
||||
uint32_t width;
|
||||
uint32_t pitchOrLinearSize;
|
||||
uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags
|
||||
uint32_t mipMapCount;
|
||||
uint32_t reserved1[11];
|
||||
DDS_PIXELFORMAT ddspf;
|
||||
uint32_t caps;
|
||||
uint32_t caps2;
|
||||
uint32_t caps3;
|
||||
uint32_t caps4;
|
||||
uint32_t reserved2;
|
||||
};
|
||||
|
||||
struct DDS_HEADER_DXT10
|
||||
{
|
||||
DXGI_FORMAT dxgiFormat;
|
||||
uint32_t resourceDimension;
|
||||
uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG
|
||||
uint32_t arraySize;
|
||||
uint32_t miscFlags2; // see DDS_MISC_FLAGS2
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
|
||||
static_assert(sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
|
||||
|
||||
} // namespace DirectX
|
||||
@@ -44,7 +44,7 @@ convertible_ostream::operator std::wostream &()
|
||||
return std::wcout;
|
||||
}
|
||||
|
||||
#ifdef QT
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
convertible_ostream::operator QDebug()
|
||||
{
|
||||
return qDebug();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user