Merge pull request #422 from Laupetin/refactor/oat-64

refactor: fix compilation warnings for x64
This commit is contained in:
Jan 2025-04-27 22:08:34 +02:00 committed by GitHub
commit d94a004433
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
177 changed files with 1668 additions and 1728 deletions

View File

@ -10,6 +10,9 @@ on:
jobs: jobs:
build-test-linux: build-test-linux:
strategy:
matrix:
build_arch: [x86, x64]
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: ubuntu:24.04 container: ubuntu:24.04
steps: steps:
@ -35,10 +38,10 @@ jobs:
- name: Build - name: Build
working-directory: ${{ github.workspace }} working-directory: ${{ github.workspace }}
run: make -C build -j$(nproc) config=release_x86 all run: make -C build -j$(nproc) config=release_${{ matrix.build_arch }} all
- name: Test - name: Test
working-directory: ${{ github.workspace }}/build/lib/Release_x86/tests working-directory: ${{ github.workspace }}/build/lib/Release_${{ matrix.build_arch }}/tests
run: | run: |
./ObjCommonTests ./ObjCommonTests
./ObjCompilingTests ./ObjCompilingTests
@ -48,6 +51,14 @@ jobs:
./ZoneCommonTests ./ZoneCommonTests
build-test-windows: build-test-windows:
strategy:
matrix:
build_arch: [x86, x64]
include:
- build_arch: x86
msbuild_config: Win32
- build_arch: x64
msbuild_config: x64
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
@ -66,10 +77,10 @@ jobs:
- name: Build - name: Build
working-directory: ${{ github.workspace }} working-directory: ${{ github.workspace }}
run: msbuild /m /p:Configuration=Release /p:Platform=Win32 build run: msbuild /m /p:Configuration=Release /p:Platform=${{ matrix.msbuild_config }} build
- name: Test - name: Test
working-directory: ${{ github.workspace }}/build/lib/Release_x86/tests working-directory: ${{ github.workspace }}/build/lib/Release_${{ matrix.build_arch }}/tests
run: | run: |
$combinedExitCode = 0 $combinedExitCode = 0
./ObjCommonTests ./ObjCommonTests

View File

@ -117,7 +117,7 @@ group ""
-- Projects -- Projects
-- ======================== -- ========================
include "src/Common.lua" include "src/Common.lua"
include "src/Crypto.lua" include "src/Cryptography.lua"
include "src/ImageConverter.lua" include "src/ImageConverter.lua"
include "src/Linker.lua" include "src/Linker.lua"
include "src/Parser.lua" include "src/Parser.lua"
@ -141,7 +141,7 @@ include "tools/scripts/raw.lua"
-- Components group: All projects assist or are part of a tool -- Components group: All projects assist or are part of a tool
group "Components" group "Components"
Common:project() Common:project()
Crypto:project() Cryptography:project()
Parser:project() Parser:project()
Utils:project() Utils:project()
ZoneCode:project() ZoneCode:project()

View File

@ -135,7 +135,7 @@ namespace IW3
typedef float vec2_t[2]; typedef float vec2_t[2];
typedef float vec3_t[3]; typedef float vec3_t[3];
typedef float vec4_t[4]; typedef float vec4_t[4];
typedef tdef_align(128) unsigned int raw_uint128; typedef tdef_align32(128) unsigned int raw_uint128;
struct XModelPiece struct XModelPiece
{ {
@ -179,7 +179,7 @@ namespace IW3
}; };
typedef unsigned char ByteVec[3]; typedef unsigned char ByteVec[3];
typedef tdef_align(4) unsigned short UShortVec[3]; typedef tdef_align32(4) unsigned short UShortVec[3];
union XAnimDynamicIndicesTrans union XAnimDynamicIndicesTrans
{ {
@ -214,7 +214,7 @@ namespace IW3
XAnimPartTransData u; XAnimPartTransData u;
}; };
typedef tdef_align(4) short XQuat[2]; typedef tdef_align32(4) short XQuat[2];
union XAnimDynamicIndicesQuat union XAnimDynamicIndicesQuat
{ {
@ -360,7 +360,7 @@ namespace IW3
uint16_t* vertsBlend; uint16_t* vertsBlend;
}; };
typedef tdef_align(16) uint16_t r_index16_t; typedef tdef_align32(16) uint16_t r_index16_t;
struct XSurface struct XSurface
{ {
@ -709,7 +709,7 @@ namespace IW3
MaterialTextureDefInfo u; MaterialTextureDefInfo u;
}; };
struct gcc_align(8) GfxDrawSurfFields struct gcc_align32(8) GfxDrawSurfFields
{ {
uint64_t objectId : 16; uint64_t objectId : 16;
uint64_t reflectionProbeIndex : 8; uint64_t reflectionProbeIndex : 8;
@ -724,8 +724,8 @@ namespace IW3
union GfxDrawSurf union GfxDrawSurf
{ {
gcc_align(8) GfxDrawSurfFields fields; gcc_align32(8) GfxDrawSurfFields fields;
gcc_align(8) uint64_t packed; gcc_align32(8) uint64_t packed;
}; };
enum materialSurfType_t enum materialSurfType_t
@ -1314,9 +1314,9 @@ namespace IW3
{ {
char levelCount; char levelCount;
char flags; char flags;
int16_t dimensions[3]; uint16_t dimensions[3];
int format; int format;
int resourceSize; unsigned int resourceSize;
char data[1]; char data[1];
}; };
@ -1605,7 +1605,7 @@ namespace IW3
cLeaf_t leaf; cLeaf_t leaf;
}; };
struct type_align(16) cbrush_t struct type_align32(16) cbrush_t
{ {
float mins[3]; float mins[3];
int contents; int contents;
@ -1671,7 +1671,7 @@ namespace IW3
typedef unsigned short LeafBrush; typedef unsigned short LeafBrush;
typedef tdef_align(16) cbrush_t cbrush_array_t; typedef tdef_align32(16) cbrush_t cbrush_array_t;
struct clipMap_t struct clipMap_t
{ {
@ -2265,7 +2265,7 @@ namespace IW3
char pad; char pad;
}; };
typedef tdef_align(4) GfxSceneDynModel GfxSceneDynModel4; typedef tdef_align32(4) GfxSceneDynModel GfxSceneDynModel4;
struct GfxWorld struct GfxWorld
{ {

View File

@ -155,10 +155,10 @@ namespace IW4
void* data; void* data;
}; };
typedef tdef_align(16) char raw_byte16; typedef tdef_align32(16) char raw_byte16;
typedef tdef_align(16) float raw_float16; typedef tdef_align32(16) float raw_float16;
typedef unsigned int raw_uint; typedef unsigned int raw_uint;
typedef tdef_align(128) unsigned int raw_uint128; typedef tdef_align32(128) unsigned int raw_uint128;
typedef unsigned char cbrushedge_t; typedef unsigned char cbrushedge_t;
typedef unsigned short r_index_t; typedef unsigned short r_index_t;
typedef float vec2_t[2]; typedef float vec2_t[2];
@ -289,7 +289,7 @@ namespace IW4
}; };
typedef unsigned char ByteVec[3]; typedef unsigned char ByteVec[3];
typedef tdef_align(4) unsigned short UShortVec[3]; typedef tdef_align32(4) unsigned short UShortVec[3];
union XAnimDynamicFrames union XAnimDynamicFrames
{ {
@ -303,7 +303,7 @@ namespace IW4
uint16_t _2[1]; uint16_t _2[1];
}; };
struct type_align(4) XAnimPartTransFrames struct type_align32(4) XAnimPartTransFrames
{ {
float mins[3]; float mins[3];
float size[3]; float size[3];
@ -330,9 +330,9 @@ namespace IW4
uint16_t _2[1]; uint16_t _2[1];
}; };
typedef tdef_align(4) short XQuat2[2]; typedef tdef_align32(4) short XQuat2[2];
struct type_align(4) XAnimDeltaPartQuatDataFrames2 struct type_align32(4) XAnimDeltaPartQuatDataFrames2
{ {
XQuat2* frames; XQuat2* frames;
XAnimDynamicIndicesQuat2 indices; XAnimDynamicIndicesQuat2 indices;
@ -356,7 +356,7 @@ namespace IW4
uint16_t _2[1]; uint16_t _2[1];
}; };
typedef tdef_align(4) short XQuat[4]; typedef tdef_align32(4) short XQuat[4];
struct XAnimDeltaPartQuatDataFrames struct XAnimDeltaPartQuatDataFrames
{ {
@ -489,7 +489,7 @@ namespace IW4
XSurfaceCollisionTree* collisionTree; XSurfaceCollisionTree* collisionTree;
}; };
typedef tdef_align(16) uint16_t r_index16_t; typedef tdef_align32(16) uint16_t r_index16_t;
struct XSurface struct XSurface
{ {
@ -843,7 +843,7 @@ namespace IW4
unsigned int toolFlags; unsigned int toolFlags;
}; };
struct gcc_align(8) GfxDrawSurfFields struct gcc_align32(8) GfxDrawSurfFields
{ {
uint64_t objectId : 16; uint64_t objectId : 16;
uint64_t reflectionProbeIndex : 8; uint64_t reflectionProbeIndex : 8;
@ -860,8 +860,8 @@ namespace IW4
union GfxDrawSurf union GfxDrawSurf
{ {
gcc_align(8) GfxDrawSurfFields fields; gcc_align32(8) GfxDrawSurfFields fields;
gcc_align(8) uint64_t packed; gcc_align32(8) uint64_t packed;
}; };
// The sort key is translated to a numeric value inside the material templates // The sort key is translated to a numeric value inside the material templates
@ -993,7 +993,7 @@ namespace IW4
GfxStateBits* stateBitsTable; GfxStateBits* stateBitsTable;
}; };
struct type_align(4) GfxImageLoadDef struct type_align32(4) GfxImageLoadDef
{ {
char levelCount; char levelCount;
char pad[3]; char pad[3];
@ -2918,8 +2918,8 @@ namespace IW4
float linkMaxs[2]; float linkMaxs[2];
}; };
typedef tdef_align(128) cbrush_t cbrush_array_t; typedef tdef_align32(128) cbrush_t cbrush_array_t;
typedef tdef_align(128) Bounds BoundsArray; typedef tdef_align32(128) Bounds BoundsArray;
struct clipMap_t struct clipMap_t
{ {
@ -3539,7 +3539,7 @@ namespace IW4
Bounds bounds; Bounds bounds;
}; };
struct type_align(4) GfxBrushModel struct type_align32(4) GfxBrushModel
{ {
GfxBrushModelWritable writable; GfxBrushModelWritable writable;
Bounds bounds; Bounds bounds;
@ -3744,8 +3744,8 @@ namespace IW4
int exponent; int exponent;
}; };
typedef tdef_align(128) GfxCellTree GfxCellTree128; typedef tdef_align32(128) GfxCellTree GfxCellTree128;
typedef tdef_align(4) GfxSceneDynModel GfxSceneDynModel4; typedef tdef_align32(4) GfxSceneDynModel GfxSceneDynModel4;
struct GfxWorld struct GfxWorld
{ {

View File

@ -221,9 +221,9 @@ namespace IW5
}; };
}; };
typedef tdef_align(16) char raw_byte16; typedef tdef_align32(16) char raw_byte16;
typedef tdef_align(16) float raw_float16; typedef tdef_align32(16) float raw_float16;
typedef tdef_align(128) unsigned int raw_uint128; typedef tdef_align32(128) unsigned int raw_uint128;
typedef unsigned char raw_byte; typedef unsigned char raw_byte;
typedef unsigned int raw_uint; typedef unsigned int raw_uint;
typedef unsigned short r_index_t; typedef unsigned short r_index_t;
@ -338,7 +338,7 @@ namespace IW5
}; };
typedef unsigned char ByteVec[3]; typedef unsigned char ByteVec[3];
typedef tdef_align(4) unsigned short UShortVec[3]; typedef tdef_align32(4) unsigned short UShortVec[3];
union XAnimDynamicFrames union XAnimDynamicFrames
{ {
@ -352,7 +352,7 @@ namespace IW5
uint16_t _2[1]; uint16_t _2[1];
}; };
struct type_align(4) XAnimPartTransFrames struct type_align32(4) XAnimPartTransFrames
{ {
float mins[3]; float mins[3];
float size[3]; float size[3];
@ -379,9 +379,9 @@ namespace IW5
uint16_t _2[1]; uint16_t _2[1];
}; };
typedef tdef_align(4) short XQuat2[2]; typedef tdef_align32(4) short XQuat2[2];
struct type_align(4) XAnimDeltaPartQuatDataFrames2 struct type_align32(4) XAnimDeltaPartQuatDataFrames2
{ {
XQuat2* frames; XQuat2* frames;
XAnimDynamicIndicesQuat2 indices; XAnimDynamicIndicesQuat2 indices;
@ -405,7 +405,7 @@ namespace IW5
uint16_t _2[1]; uint16_t _2[1];
}; };
typedef tdef_align(4) short XQuat[4]; typedef tdef_align32(4) short XQuat[4];
struct XAnimDeltaPartQuatDataFrames struct XAnimDeltaPartQuatDataFrames
{ {
@ -543,7 +543,7 @@ namespace IW5
uint16_t i[3]; uint16_t i[3];
}; };
typedef tdef_align(16) XSurfaceTri XSurfaceTri16; typedef tdef_align32(16) XSurfaceTri XSurfaceTri16;
struct XSurface struct XSurface
{ {
@ -653,7 +653,7 @@ namespace IW5
float quantization; float quantization;
}; };
struct gcc_align(8) GfxDrawSurfFields struct gcc_align32(8) GfxDrawSurfFields
{ {
uint64_t unused : 1; uint64_t unused : 1;
uint64_t primarySortKey : 6; uint64_t primarySortKey : 6;
@ -671,8 +671,8 @@ namespace IW5
union GfxDrawSurf union GfxDrawSurf
{ {
gcc_align(8) GfxDrawSurfFields fields; gcc_align32(8) GfxDrawSurfFields fields;
gcc_align(8) uint64_t packed; gcc_align32(8) uint64_t packed;
}; };
enum MaterialGameFlags enum MaterialGameFlags
@ -1127,7 +1127,7 @@ namespace IW5
MaterialTechnique* techniques[54]; MaterialTechnique* techniques[54];
}; };
struct type_align(4) GfxImageLoadDef struct type_align32(4) GfxImageLoadDef
{ {
char levelCount; char levelCount;
char pad[3]; char pad[3];
@ -1339,8 +1339,8 @@ namespace IW5
unsigned char edgeCount[2][3]; unsigned char edgeCount[2][3];
}; };
typedef tdef_align(128) cbrush_t cbrush_array_t; typedef tdef_align32(128) cbrush_t cbrush_array_t;
typedef tdef_align(128) Bounds BoundsArray; typedef tdef_align32(128) Bounds BoundsArray;
struct ClipInfo struct ClipInfo
{ {
@ -2190,7 +2190,7 @@ namespace IW5
Bounds bounds; Bounds bounds;
}; };
struct type_align(4) GfxBrushModel struct type_align32(4) GfxBrushModel
{ {
GfxBrushModelWritable writable; GfxBrushModelWritable writable;
Bounds bounds; Bounds bounds;
@ -2396,7 +2396,7 @@ namespace IW5
int exponent; int exponent;
}; };
typedef tdef_align(128) GfxCellTree GfxCellTree128; typedef tdef_align32(128) GfxCellTree GfxCellTree128;
struct GfxWorld struct GfxWorld
{ {
@ -3446,7 +3446,7 @@ namespace IW5
SndAliasCustom projIgnitionSound; SndAliasCustom projIgnitionSound;
}; };
typedef tdef_align(4) AttSight AttSight4; typedef tdef_align32(4) AttSight AttSight4;
struct WeaponAttachment struct WeaponAttachment
{ {

View File

@ -193,20 +193,20 @@ namespace T5
void* data; void* data;
}; };
typedef tdef_align(16) char char16; typedef tdef_align32(16) char char16;
typedef tdef_align(32) char byte32; typedef tdef_align32(32) char byte32;
typedef tdef_align(128) char byte128; typedef tdef_align32(128) char byte128;
typedef tdef_align(4) char char_align4; typedef tdef_align32(4) char char_align4;
typedef tdef_align(128) char char_align128; typedef tdef_align32(128) char char_align128;
typedef tdef_align(16) char raw_byte16; typedef tdef_align32(16) char raw_byte16;
typedef tdef_align(128) char raw_byte128; typedef tdef_align32(128) char raw_byte128;
typedef tdef_align(128) float float_align128; typedef tdef_align32(128) float float_align128;
typedef char cbrushedge_t; typedef char cbrushedge_t;
typedef tdef_align(128) unsigned int raw_uint128; typedef tdef_align32(128) unsigned int raw_uint128;
typedef uint16_t ScriptString; typedef uint16_t ScriptString;
@ -350,7 +350,7 @@ namespace T5
}; };
typedef unsigned char ByteVec[3]; typedef unsigned char ByteVec[3];
typedef tdef_align(4) unsigned short UShortVec[3]; typedef tdef_align32(4) unsigned short UShortVec[3];
union XAnimDynamicFrames union XAnimDynamicFrames
{ {
@ -385,7 +385,7 @@ namespace T5
XAnimPartTransData u; XAnimPartTransData u;
}; };
typedef tdef_align(4) short XQuat[2]; typedef tdef_align32(4) short XQuat[2];
union XAnimDynamicIndicesQuat union XAnimDynamicIndicesQuat
{ {
@ -542,7 +542,7 @@ namespace T5
uint16_t i[3]; uint16_t i[3];
}; };
typedef tdef_align(16) XSurfaceTri XSurfaceTri16; typedef tdef_align32(16) XSurfaceTri XSurfaceTri16;
struct XSurface struct XSurface
{ {
@ -627,7 +627,7 @@ namespace T5
int sflags; int sflags;
}; };
struct type_align(16) BrushWrapper struct type_align32(16) BrushWrapper
{ {
vec3_t mins; vec3_t mins;
int contents; int contents;
@ -650,7 +650,7 @@ namespace T5
vec3_t halfLengths; vec3_t halfLengths;
}; };
typedef tdef_align(16) PhysGeomInfo PhysGeomInfo16; typedef tdef_align32(16) PhysGeomInfo PhysGeomInfo16;
struct PhysGeomList struct PhysGeomList
{ {
@ -713,7 +713,7 @@ namespace T5
PhysConstraints* physConstraints; PhysConstraints* physConstraints;
}; };
struct gcc_align(8) GfxDrawSurfFields struct gcc_align32(8) GfxDrawSurfFields
{ {
uint64_t objectId : 16; uint64_t objectId : 16;
uint64_t fade : 4; uint64_t fade : 4;
@ -732,8 +732,8 @@ namespace T5
union GfxDrawSurf union GfxDrawSurf
{ {
gcc_align(8) GfxDrawSurfFields fields; gcc_align32(8) GfxDrawSurfFields fields;
gcc_align(8) uint64_t packed; gcc_align32(8) uint64_t packed;
}; };
struct MaterialInfo struct MaterialInfo
@ -1138,7 +1138,7 @@ namespace T5
SND_ASSET_FLAG_PAD_LOOP_BUFFER = 0x2, SND_ASSET_FLAG_PAD_LOOP_BUFFER = 0x2,
}; };
typedef tdef_align(2048) char snd_align_char; typedef tdef_align32(2048) char snd_align_char;
struct snd_asset struct snd_asset
{ {
@ -1164,7 +1164,7 @@ namespace T5
snd_asset sound; snd_asset sound;
}; };
typedef tdef_align(2048) char char_align_2048; typedef tdef_align32(2048) char char_align_2048;
struct PrimedSound struct PrimedSound
{ {
@ -1426,7 +1426,7 @@ namespace T5
cLeaf_s leaf; cLeaf_s leaf;
}; };
struct type_align(16) cbrush_t struct type_align32(16) cbrush_t
{ {
float mins[3]; float mins[3];
int contents; int contents;
@ -1935,7 +1935,7 @@ namespace T5
}; };
}; };
struct type_align(16) GfxLight struct type_align32(16) GfxLight
{ {
char type; char type;
char canUseShadowMap; char canUseShadowMap;
@ -2142,7 +2142,7 @@ namespace T5
char rgb[56][3]; char rgb[56][3];
}; };
typedef tdef_align(4) char aligned_byte_pointer; typedef tdef_align32(4) char aligned_byte_pointer;
struct GfxLightGrid struct GfxLightGrid
{ {
@ -2220,7 +2220,7 @@ namespace T5
uint16_t dynEntId; uint16_t dynEntId;
}; };
typedef tdef_align(4) GfxSceneDynModel GfxSceneDynModel4; typedef tdef_align32(4) GfxSceneDynModel GfxSceneDynModel4;
struct BModelDrawInfo struct BModelDrawInfo
{ {
@ -2283,7 +2283,7 @@ namespace T5
int stream2ByteOffset; int stream2ByteOffset;
}; };
struct type_align(16) GfxSurface struct type_align32(16) GfxSurface
{ {
srfTriangles_t tris; srfTriangles_t tris;
Material* material; Material* material;
@ -2935,7 +2935,7 @@ namespace T5
ITEM_TYPE_MENUMODEL = 0x27 ITEM_TYPE_MENUMODEL = 0x27
}; };
struct type_align(8) itemDef_s struct type_align32(8) itemDef_s
{ {
windowDef_t window; windowDef_t window;
int type; int type;
@ -2949,15 +2949,15 @@ namespace T5
menuDef_t* parent; menuDef_t* parent;
rectData_s* rectExpData; rectData_s* rectExpData;
ExpressionStatement visibleExp; ExpressionStatement visibleExp;
gcc_align(8) uint64_t showBits; gcc_align32(8) uint64_t showBits;
gcc_align(8) uint64_t hideBits; gcc_align32(8) uint64_t hideBits;
ExpressionStatement forecolorAExp; ExpressionStatement forecolorAExp;
int ui3dWindowId; int ui3dWindowId;
GenericEventHandler* onEvent; GenericEventHandler* onEvent;
UIAnimInfo* animInfo; UIAnimInfo* animInfo;
}; };
struct type_align(8) menuDef_t struct type_align32(8) menuDef_t
{ {
windowDef_t window; windowDef_t window;
const char* font; const char* font;
@ -2984,8 +2984,8 @@ namespace T5
GenericEventHandler* onEvent; GenericEventHandler* onEvent;
ItemKeyHandler* onKey; ItemKeyHandler* onKey;
ExpressionStatement visibleExp; ExpressionStatement visibleExp;
gcc_align(8) uint64_t showBits; gcc_align32(8) uint64_t showBits;
gcc_align(8) uint64_t hideBits; gcc_align32(8) uint64_t hideBits;
const char* allowedBinding; const char* allowedBinding;
const char* soundName; const char* soundName;
int imageTrack; int imageTrack;

View File

@ -10,17 +10,17 @@ namespace T6
{ {
#endif #endif
typedef tdef_align(16) char char16; typedef tdef_align32(16) char char16;
typedef tdef_align(32) char byte32; typedef tdef_align32(32) char byte32;
typedef tdef_align(128) char byte128; typedef tdef_align32(128) char byte128;
typedef tdef_align(4) char char_align4; typedef tdef_align32(4) char char_align4;
typedef tdef_align(128) char char_align128; typedef tdef_align32(128) char char_align128;
typedef tdef_align(16) char raw_byte16; typedef tdef_align32(16) char raw_byte16;
typedef tdef_align(128) char raw_byte128; typedef tdef_align32(128) char raw_byte128;
typedef tdef_align(128) float float_align128; typedef tdef_align32(128) float float_align128;
typedef uint16_t ScriptString; typedef uint16_t ScriptString;
@ -643,7 +643,7 @@ namespace T6
float lightingOriginRange; float lightingOriginRange;
}; };
struct gcc_align(8) GfxDrawSurfFields struct gcc_align32(8) GfxDrawSurfFields
{ {
uint64_t objectId : 16; uint64_t objectId : 16;
uint64_t customIndex : 9; uint64_t customIndex : 9;
@ -658,8 +658,8 @@ namespace T6
union GfxDrawSurf union GfxDrawSurf
{ {
gcc_align(8) GfxDrawSurfFields fields; gcc_align32(8) GfxDrawSurfFields fields;
gcc_align(8) uint64_t packed; gcc_align32(8) uint64_t packed;
}; };
// The sort key is translated to a numeric value inside the material templates // The sort key is translated to a numeric value inside the material templates
@ -702,7 +702,7 @@ namespace T6
MTL_GAMEFLAG_1000 = 0x1000, MTL_GAMEFLAG_1000 = 0x1000,
}; };
struct type_align(8) MaterialInfo struct type_align32(8) MaterialInfo
{ {
const char* name; const char* name;
unsigned int gameFlags; unsigned int gameFlags;
@ -735,7 +735,7 @@ namespace T6
CAMERA_REGION_NONE = CAMERA_REGION_COUNT, CAMERA_REGION_NONE = CAMERA_REGION_COUNT,
}; };
typedef tdef_align(8) GfxStateBits GfxStateBitsTable; typedef tdef_align32(8) GfxStateBits GfxStateBitsTable;
struct Material struct Material
{ {
@ -960,9 +960,9 @@ namespace T6
unsigned int entryCount; unsigned int entryCount;
unsigned int dependencyCount; unsigned int dependencyCount;
unsigned int pad32; unsigned int pad32;
gcc_align(8) int64_t fileSize; gcc_align32(8) int64_t fileSize;
gcc_align(8) int64_t entryOffset; gcc_align32(8) int64_t entryOffset;
gcc_align(8) int64_t checksumOffset; gcc_align32(8) int64_t checksumOffset;
char checksumChecksum[16]; char checksumChecksum[16];
char dependencies[512]; char dependencies[512];
char padding[1464]; char padding[1464];
@ -970,7 +970,7 @@ namespace T6
#pragma pack(push, 1) #pragma pack(push, 1)
struct type_align(2) SndRuntimeAssetBank struct type_align32(2) SndRuntimeAssetBank
{ {
const char* zone; const char* zone;
const char* language; const char* language;
@ -985,7 +985,7 @@ namespace T6
#pragma pack(pop) #pragma pack(pop)
typedef tdef_align(2048) char SndChar2048; typedef tdef_align32(2048) char SndChar2048;
struct SndLoadedAssets struct SndLoadedAssets
{ {
@ -1041,8 +1041,8 @@ namespace T6
}; };
typedef unsigned short LeafBrush; typedef unsigned short LeafBrush;
typedef tdef_align(128) cbrush_t cbrush_array_t; typedef tdef_align32(128) cbrush_t cbrush_array_t;
typedef tdef_align(128) Bounds BoundsArray; typedef tdef_align32(128) Bounds BoundsArray;
struct ClipInfo struct ClipInfo
{ {
@ -1066,7 +1066,7 @@ namespace T6
int* brushContents; int* brushContents;
}; };
struct type_align(4) cLeaf_s struct type_align32(4) cLeaf_s
{ {
uint16_t firstCollAabbIndex; uint16_t firstCollAabbIndex;
uint16_t collAabbCount; uint16_t collAabbCount;
@ -1273,8 +1273,8 @@ namespace T6
void /*ID3D11Buffer*/* indexBuffer; void /*ID3D11Buffer*/* indexBuffer;
}; };
typedef tdef_align(4) char aligned_byte_pointer; typedef tdef_align32(4) char aligned_byte_pointer;
typedef tdef_align(4) GfxCompressedLightGridCoeffs GfxCompressedLightGridCoeffs_align4; typedef tdef_align32(4) GfxCompressedLightGridCoeffs GfxCompressedLightGridCoeffs_align4;
struct GfxLightGrid struct GfxLightGrid
{ {
@ -1323,7 +1323,7 @@ namespace T6
vec3_t sunFxPosition; vec3_t sunFxPosition;
}; };
typedef tdef_align(4) GfxDrawSurf GfxDrawSurf_align4; typedef tdef_align32(4) GfxDrawSurf GfxDrawSurf_align4;
struct GfxWorldDpvsStatic struct GfxWorldDpvsStatic
{ {
@ -1449,7 +1449,7 @@ namespace T6
int lightingQuality; int lightingQuality;
}; };
struct type_align(4) GfxLightImage struct type_align32(4) GfxLightImage
{ {
GfxImage* image; GfxImage* image;
char samplerState; char samplerState;
@ -1478,8 +1478,8 @@ namespace T6
struct FontIcon struct FontIcon
{ {
const char* name; const char* name;
int numEntries; unsigned int numEntries;
int numAliasEntries; unsigned int numAliasEntries;
FontIconEntry* fontIconEntry; FontIconEntry* fontIconEntry;
FontIconAlias* fontIconAlias; FontIconAlias* fontIconAlias;
}; };
@ -1535,7 +1535,7 @@ namespace T6
expressionRpn* rpn; expressionRpn* rpn;
}; };
struct type_align(8) menuDef_t struct type_align32(8) menuDef_t
{ {
windowDef_t window; windowDef_t window;
const char* font; const char* font;
@ -1562,8 +1562,8 @@ namespace T6
GenericEventHandler* onEvent; GenericEventHandler* onEvent;
ItemKeyHandler* onKey; ItemKeyHandler* onKey;
ExpressionStatement visibleExp; ExpressionStatement visibleExp;
gcc_align(8) uint64_t showBits; gcc_align32(8) uint64_t showBits;
gcc_align(8) uint64_t hideBits; gcc_align32(8) uint64_t hideBits;
const char* allowedBinding; const char* allowedBinding;
const char* soundName; const char* soundName;
int imageTrack; int imageTrack;
@ -2753,9 +2753,9 @@ namespace T6
uint16_t i[3]; uint16_t i[3];
}; };
typedef tdef_align(16) XSurfaceTri XSurfaceTri16; typedef tdef_align32(16) XSurfaceTri XSurfaceTri16;
struct type_align(16) XSurface struct type_align32(16) XSurface
{ {
char tileMode; char tileMode;
unsigned char vertListCount; unsigned char vertListCount;
@ -2783,7 +2783,7 @@ namespace T6
int surfFlags; int surfFlags;
}; };
struct type_align(4) XBoneInfo struct type_align32(4) XBoneInfo
{ {
vec3_t bounds[2]; vec3_t bounds[2];
vec3_t offset; vec3_t offset;
@ -3058,7 +3058,7 @@ namespace T6
{ {
};*/ };*/
struct type_align(4) GfxImageLoadDef struct type_align32(4) GfxImageLoadDef
{ {
char levelCount; char levelCount;
char flags; char flags;
@ -3104,7 +3104,7 @@ namespace T6
float returnHighpass; float returnHighpass;
}; };
typedef tdef_align(16) float SndFloatAlign16; typedef tdef_align32(16) float SndFloatAlign16;
struct SndDuck struct SndDuck
{ {
@ -3206,7 +3206,7 @@ namespace T6
cLeafBrushNodeData_t data; cLeafBrushNodeData_t data;
}; };
struct type_align(16) cbrush_t struct type_align32(16) cbrush_t
{ {
vec3_t mins; vec3_t mins;
int contents; int contents;
@ -3352,7 +3352,7 @@ namespace T6
ROPE_CENTITY_CONSTRAINT = 0x3, ROPE_CENTITY_CONSTRAINT = 0x3,
}; };
struct type_align(4) constraint_t struct type_align32(4) constraint_t
{ {
vec3_t p; vec3_t p;
rope_constraint_e type; rope_constraint_e type;
@ -3374,7 +3374,7 @@ namespace T6
unsigned int frame_index; unsigned int frame_index;
}; };
struct type_align(4) rope_t struct type_align32(4) rope_t
{ {
par_t m_particles[25]; par_t m_particles[25];
constraint_t m_constraints[30]; constraint_t m_constraints[30];
@ -3489,7 +3489,7 @@ namespace T6
uint16_t infoIndex; uint16_t infoIndex;
}; };
struct type_align(4) pathnode_dynamic_t struct type_align32(4) pathnode_dynamic_t
{ {
SentientHandle pOwner; SentientHandle pOwner;
int iFreeTime; int iFreeTime;
@ -3595,7 +3595,7 @@ namespace T6
}; };
}; };
struct type_align(16) GfxLight struct type_align32(16) GfxLight
{ {
char type; char type;
char canUseShadowMap; char canUseShadowMap;
@ -3815,7 +3815,7 @@ namespace T6
}; };
// Usually __m128, but that is not portable // Usually __m128, but that is not portable
union gcc_align(8) custom_m128 union gcc_align32(8) custom_m128
{ {
float m128_f32[4]; float m128_f32[4];
uint64_t m128_u64[2]; uint64_t m128_u64[2];
@ -3836,7 +3836,7 @@ namespace T6
custom_m128 w; custom_m128 w;
}; };
struct type_align(16) SSkinInstance struct type_align32(16) SSkinInstance
{ {
union union
{ {
@ -3888,7 +3888,7 @@ namespace T6
int baseIndex; int baseIndex;
}; };
struct type_align(16) GfxSurface struct type_align32(16) GfxSurface
{ {
srfTriangles_t tris; srfTriangles_t tris;
Material* material; Material* material;
@ -3913,7 +3913,7 @@ namespace T6
uint16_t V2[4]; uint16_t V2[4];
}; };
struct type_align(4) GfxStaticModelLmapVertexInfo struct type_align32(4) GfxStaticModelLmapVertexInfo
{ {
unsigned int* lmapVertexColors; unsigned int* lmapVertexColors;
void /*ID3D11Buffer*/* lmapVertexColorsVB; void /*ID3D11Buffer*/* lmapVertexColorsVB;
@ -4113,7 +4113,7 @@ namespace T6
void* data; void* data;
}; };
struct type_align(8) itemDef_s struct type_align32(8) itemDef_s
{ {
windowDef_t window; windowDef_t window;
int type; int type;
@ -5587,7 +5587,7 @@ namespace T6
LOCAL_CLIENT_COUNT = 0x1, LOCAL_CLIENT_COUNT = 0x1,
}; };
struct type_align(4) DevGraph struct type_align32(4) DevGraph
{ {
vec2_t* knots; vec2_t* knots;
int* knotCount; int* knotCount;
@ -5609,7 +5609,7 @@ namespace T6
}; };
typedef char ByteVec[3]; typedef char ByteVec[3];
typedef tdef_align(4) uint16_t UShortVec[3]; typedef tdef_align32(4) uint16_t UShortVec[3];
union XAnimDynamicFrames union XAnimDynamicFrames
{ {
@ -5623,7 +5623,7 @@ namespace T6
uint16_t _2[1]; uint16_t _2[1];
}; };
struct type_align(4) XAnimPartTransFrames struct type_align32(4) XAnimPartTransFrames
{ {
vec3_t mins; vec3_t mins;
vec3_t size; vec3_t size;
@ -5650,9 +5650,9 @@ namespace T6
uint16_t _2[1]; uint16_t _2[1];
}; };
typedef tdef_align(4) int16_t XQuat2[2]; typedef tdef_align32(4) int16_t XQuat2[2];
struct type_align(4) XAnimDeltaPartQuatDataFrames2 struct type_align32(4) XAnimDeltaPartQuatDataFrames2
{ {
XQuat2* frames; XQuat2* frames;
XAnimDynamicIndicesDeltaQuat2 indices; XAnimDynamicIndicesDeltaQuat2 indices;
@ -5676,9 +5676,9 @@ namespace T6
uint16_t _2[1]; uint16_t _2[1];
}; };
typedef tdef_align(4) int16_t XQuat[4]; typedef tdef_align32(4) int16_t XQuat[4];
struct type_align(4) XAnimDeltaPartQuatDataFrames struct type_align32(4) XAnimDeltaPartQuatDataFrames
{ {
XQuat* frames; XQuat* frames;
XAnimDynamicIndicesDeltaQuat indices; XAnimDynamicIndicesDeltaQuat indices;
@ -5738,7 +5738,7 @@ namespace T6
vec4_t tvec; vec4_t tvec;
}; };
typedef tdef_align(16) PhysGeomInfo PhysGeomInfo16; typedef tdef_align32(16) PhysGeomInfo PhysGeomInfo16;
struct PhysGeomList struct PhysGeomList
{ {
@ -6295,7 +6295,7 @@ namespace T6
static_assert(sizeof(SndAliasFlags) == 8); static_assert(sizeof(SndAliasFlags) == 8);
#endif #endif
struct type_align(4) pathlink_s struct type_align32(4) pathlink_s
{ {
float fDist; float fDist;
uint16_t nodeNum; uint16_t nodeNum;
@ -6404,7 +6404,7 @@ namespace T6
unsigned int v; unsigned int v;
}; };
struct type_align(4) SSkinVert struct type_align32(4) SSkinVert
{ {
half4 pos_bone; half4 pos_bone;
PackedUnitVec normal; PackedUnitVec normal;
@ -6495,7 +6495,7 @@ namespace T6
} vector; } vector;
}; };
struct type_align(8) dvar_t struct type_align32(8) dvar_t
{ {
const char* name; const char* name;
const char* description; const char* description;
@ -7006,7 +7006,7 @@ namespace T6
uint16_t triangleBeginIndex; uint16_t triangleBeginIndex;
}; };
struct type_align(16) BrushWrapper struct type_align32(16) BrushWrapper
{ {
vec3_t mins; vec3_t mins;
int contents; int contents;

View File

@ -7,9 +7,6 @@
#ifdef tdef_align #ifdef tdef_align
#undef tdef_align #undef tdef_align
#endif #endif
#ifdef memb_align
#undef memb_align
#endif
#ifdef gcc_align #ifdef gcc_align
#undef gcc_align #undef gcc_align
#endif #endif
@ -17,25 +14,44 @@
#ifdef __zonecodegenerator #ifdef __zonecodegenerator
#define type_align(x) alignas(x) #define type_align(x) alignas(x)
#define tdef_align(x) alignas(x) #define tdef_align(x) alignas(x)
#define memb_align(x) alignas(x)
#define gcc_align(x) #define gcc_align(x)
#else #else
#ifdef __ida #ifdef __ida
#define type_align(x) __declspec(align(x)) #define type_align(x) __declspec(align(x))
#define tdef_align(x) __declspec(align(x)) #define tdef_align(x) __declspec(align(x))
#define memb_align(x) __declspec(align(x))
#define gcc_align(x) #define gcc_align(x)
#else #else
#ifdef _MSVC_LANG #ifdef _MSVC_LANG
#define type_align(x) __declspec(align(x)) #define type_align(x) __declspec(align(x))
#define tdef_align(x) __declspec(align(x)) #define tdef_align(x) __declspec(align(x))
#define memb_align(x) __declspec(align(x))
#define gcc_align(x) #define gcc_align(x)
#else #else
#define type_align(x) __attribute__((__aligned__(x))) #define type_align(x) __attribute__((__aligned__(x)))
#define tdef_align(x) #define tdef_align(x)
#define memb_align(x) __attribute__((__aligned__(x)))
#define gcc_align(x) __attribute__((__aligned__(x))) #define gcc_align(x) __attribute__((__aligned__(x)))
#endif #endif
#endif #endif
#endif #endif
#if defined(__zonecodegenerator) || defined(__ida)
#define type_align32(x) type_align(x)
#define tdef_align32(x) tdef_align(x)
#define gcc_align32(x) gcc_align(x)
#define type_align64(x) type_align(x)
#define tdef_align64(x) tdef_align(x)
#define gcc_align64(x) gcc_align(x)
#elif defined(ARCH_x86)
#define type_align32(x) type_align(x)
#define tdef_align32(x) tdef_align(x)
#define gcc_align32(x) gcc_align(x)
#define type_align64(x)
#define tdef_align64(x)
#define gcc_align64(x)
#elif defined(ARCH_x64)
#define type_align32(x)
#define tdef_align32(x)
#define gcc_align32(x)
#define type_align64(x) type_align(x)
#define tdef_align64(x) tdef_align(x)
#define gcc_align64(x) gcc_align(x)
#endif

View File

@ -14,6 +14,6 @@ typedef uint32_t xblock_size_t;
constexpr uint16_t SCR_STRING_MAX = std::numeric_limits<scr_string_t>::max(); constexpr uint16_t SCR_STRING_MAX = std::numeric_limits<scr_string_t>::max();
typedef int block_t; typedef unsigned block_t;
typedef int asset_type_t; typedef unsigned asset_type_t;
typedef unsigned int zone_priority_t; typedef unsigned int zone_priority_t;

View File

@ -1,32 +0,0 @@
#include "Crypto.h"
#include "Impl/AlgorithmMD5.h"
#include "Impl/AlgorithmRSA.h"
#include "Impl/AlgorithmSHA1.h"
#include "Impl/AlgorithmSHA256.h"
#include "Impl/AlgorithmSalsa20.h"
std::unique_ptr<IHashFunction> Crypto::CreateMD5()
{
return std::make_unique<AlgorithmMD5>();
}
std::unique_ptr<IHashFunction> Crypto::CreateSHA1()
{
return std::make_unique<AlgorithmSHA1>();
}
std::unique_ptr<IHashFunction> Crypto::CreateSHA256()
{
return std::make_unique<AlgorithmSHA256>();
}
std::unique_ptr<IStreamCipher> Crypto::CreateSalsa20(const uint8_t* keyBytes, const size_t keySize)
{
return std::make_unique<AlgorithmSalsa20>(keyBytes, keySize);
}
std::unique_ptr<IPublicKeyAlgorithm> Crypto::CreateRSA(const IPublicKeyAlgorithm::HashingAlgorithm hashingAlgorithm, const RSAPaddingMode paddingMode)
{
return std::make_unique<AlgorithmRSA>(hashingAlgorithm, paddingMode);
}

View File

@ -1,27 +0,0 @@
#pragma once
#include "IHashFunction.h"
#include "IPublicKeyAlgorithm.h"
#include "IStreamCipher.h"
#include <cstddef>
#include <memory>
class Crypto
{
public:
enum class RSAPaddingMode
{
RSA_PADDING_PKS1,
RSA_PADDING_PSS,
};
static std::unique_ptr<IHashFunction> CreateMD5();
static std::unique_ptr<IHashFunction> CreateSHA1();
static std::unique_ptr<IHashFunction> CreateSHA256();
static std::unique_ptr<IStreamCipher> CreateSalsa20(const uint8_t* keyBytes, size_t keySize);
static std::unique_ptr<IPublicKeyAlgorithm> CreateRSA(IPublicKeyAlgorithm::HashingAlgorithm hashingAlgorithm, RSAPaddingMode paddingMode);
};

View File

@ -1,14 +0,0 @@
#pragma once
#include <cstddef>
class IHashFunction
{
public:
virtual ~IHashFunction() = default;
virtual size_t GetHashSize() = 0;
virtual void Init() = 0;
virtual void Process(const void* input, size_t inputSize) = 0;
virtual void Finish(void* hashBuffer) = 0;
};

View File

@ -1,22 +0,0 @@
#pragma once
#include <cstddef>
#include <cstdint>
class IPublicKeyAlgorithm
{
public:
enum class HashingAlgorithm
{
RSA_HASH_SHA256,
RSA_HASH_SHA512
};
virtual ~IPublicKeyAlgorithm() = default;
virtual bool SetKey(const uint8_t* keyData, size_t keySize) = 0;
// If needed add a signing method
virtual bool Verify(const uint8_t* signedData, size_t signedDataSize, const uint8_t* signature, size_t signatureSize) = 0;
};

View File

@ -1,14 +0,0 @@
#pragma once
#include <cstddef>
#include <cstdint>
class IStreamCipher
{
public:
virtual ~IStreamCipher() = default;
virtual void SetIV(const uint8_t* iv, size_t ivSize) = 0;
virtual void Process(const void* plainText, void* cipherText, size_t amount) = 0;
};

View File

@ -1,64 +0,0 @@
#include "AlgorithmMD5.h"
#include "CryptoLibrary.h"
#include <cstdint>
class AlgorithmMD5::AlgorithmMD5Impl
{
hash_state m_state{};
public:
AlgorithmMD5Impl()
{
CryptoLibrary::Init();
Init();
}
void Init()
{
md5_init(&m_state);
}
void Process(const void* input, const size_t inputSize)
{
md5_process(&m_state, static_cast<const uint8_t*>(input), inputSize);
}
void Finish(void* hashBuffer)
{
md5_done(&m_state, static_cast<uint8_t*>(hashBuffer));
}
};
AlgorithmMD5::AlgorithmMD5()
{
m_impl = new AlgorithmMD5Impl();
}
AlgorithmMD5::~AlgorithmMD5()
{
delete m_impl;
m_impl = nullptr;
}
size_t AlgorithmMD5::GetHashSize()
{
return HASH_SIZE;
}
void AlgorithmMD5::Init()
{
m_impl->Init();
}
void AlgorithmMD5::Process(const void* input, const size_t inputSize)
{
m_impl->Process(input, inputSize);
}
void AlgorithmMD5::Finish(void* hashBuffer)
{
m_impl->Finish(hashBuffer);
}

View File

@ -1,20 +0,0 @@
#pragma once
#include "IHashFunction.h"
class AlgorithmMD5 : public IHashFunction
{
class AlgorithmMD5Impl;
AlgorithmMD5Impl* m_impl;
public:
static const int HASH_SIZE = 16;
AlgorithmMD5();
~AlgorithmMD5() override;
size_t GetHashSize() override;
void Init() override;
void Process(const void* input, size_t inputSize) override;
void Finish(void* hashBuffer) override;
};

View File

@ -1,119 +0,0 @@
#include "AlgorithmRSA.h"
#include "CryptoLibrary.h"
#include <cstring>
class AlgorithmRSA::AlgorithmRSAImpl
{
rsa_key m_key{};
HashingAlgorithm m_hash;
Crypto::RSAPaddingMode m_padding;
const ltc_hash_descriptor* GetHashDescriptor() const
{
switch (m_hash)
{
case HashingAlgorithm::RSA_HASH_SHA256:
return &sha256_desc;
default:
case HashingAlgorithm::RSA_HASH_SHA512:
return &sha512_desc;
}
}
int GetPaddingMode() const
{
switch (m_padding)
{
case Crypto::RSAPaddingMode::RSA_PADDING_PKS1:
return LTC_PKCS_1_V1_5;
default:
case Crypto::RSAPaddingMode::RSA_PADDING_PSS:
return LTC_PKCS_1_PSS;
}
}
public:
AlgorithmRSAImpl(const HashingAlgorithm hash, const Crypto::RSAPaddingMode padding)
{
m_hash = hash;
m_padding = padding;
CryptoLibrary::Init();
}
~AlgorithmRSAImpl() = default;
AlgorithmRSAImpl(AlgorithmRSAImpl& other) = default;
AlgorithmRSAImpl(AlgorithmRSAImpl&& other) = delete;
AlgorithmRSAImpl& operator=(AlgorithmRSAImpl const& other) = default;
AlgorithmRSAImpl& operator=(AlgorithmRSAImpl&& other) = delete;
bool SetKey(const uint8_t* keyData, const size_t keySize)
{
return rsa_import(keyData, keySize, &m_key) == CRYPT_OK;
}
bool Verify(const uint8_t* signedData, const size_t signedDataSize, const uint8_t* signature, const size_t signatureSize)
{
const ltc_hash_descriptor* hashDesc = GetHashDescriptor();
const int hashId = register_hash(hashDesc);
const int padding = GetPaddingMode();
int result;
rsa_verify_hash_ex(signature, signatureSize, signedData, signedDataSize, padding, hashId, 8, &result, &m_key);
return result == 1;
}
};
AlgorithmRSA::AlgorithmRSA(const HashingAlgorithm hash, const Crypto::RSAPaddingMode padding)
{
m_impl = new AlgorithmRSAImpl(hash, padding);
}
AlgorithmRSA::~AlgorithmRSA()
{
delete m_impl;
m_impl = nullptr;
}
AlgorithmRSA::AlgorithmRSA(AlgorithmRSA& other)
{
m_impl = new AlgorithmRSAImpl(*other.m_impl);
}
AlgorithmRSA::AlgorithmRSA(AlgorithmRSA&& other) noexcept
{
m_impl = other.m_impl;
other.m_impl = nullptr;
}
AlgorithmRSA& AlgorithmRSA::operator=(AlgorithmRSA const& other)
{
m_impl = new AlgorithmRSAImpl(*other.m_impl);
return *this;
}
AlgorithmRSA& AlgorithmRSA::operator=(AlgorithmRSA&& other) noexcept
{
m_impl = other.m_impl;
other.m_impl = nullptr;
return *this;
}
bool AlgorithmRSA::SetKey(const uint8_t* keyData, size_t keySize)
{
return m_impl->SetKey(keyData, keySize);
}
bool AlgorithmRSA::Verify(const uint8_t* signedData, const size_t signedDataSize, const uint8_t* signature, const size_t signatureSize)
{
return m_impl->Verify(signedData, signedDataSize, signature, signatureSize);
}

View File

@ -1,25 +0,0 @@
#pragma once
#include "Crypto.h"
#include "IPublicKeyAlgorithm.h"
#include <cstdint>
class AlgorithmRSA final : public IPublicKeyAlgorithm
{
class AlgorithmRSAImpl;
AlgorithmRSAImpl* m_impl;
public:
AlgorithmRSA(HashingAlgorithm hash, Crypto::RSAPaddingMode padding);
~AlgorithmRSA() override;
AlgorithmRSA(AlgorithmRSA& other);
AlgorithmRSA(AlgorithmRSA&& other) noexcept;
AlgorithmRSA& operator=(AlgorithmRSA const& other);
AlgorithmRSA& operator=(AlgorithmRSA&& other) noexcept;
bool SetKey(const uint8_t* keyData, size_t keySize) override;
bool Verify(const uint8_t* signedData, size_t signedDataSize, const uint8_t* signature, size_t signatureSize) override;
};

View File

@ -1,64 +0,0 @@
#include "AlgorithmSHA1.h"
#include "CryptoLibrary.h"
#include <cstdint>
class AlgorithmSHA1::AlgorithmSHA1Impl
{
hash_state m_state{};
public:
AlgorithmSHA1Impl()
{
CryptoLibrary::Init();
Init();
}
void Init()
{
sha1_init(&m_state);
}
void Process(const void* input, const size_t inputSize)
{
sha1_process(&m_state, static_cast<const uint8_t*>(input), inputSize);
}
void Finish(void* hashBuffer)
{
sha1_done(&m_state, static_cast<uint8_t*>(hashBuffer));
}
};
AlgorithmSHA1::AlgorithmSHA1()
{
m_impl = new AlgorithmSHA1Impl();
}
AlgorithmSHA1::~AlgorithmSHA1()
{
delete m_impl;
m_impl = nullptr;
}
size_t AlgorithmSHA1::GetHashSize()
{
return HASH_SIZE;
}
void AlgorithmSHA1::Init()
{
m_impl->Init();
}
void AlgorithmSHA1::Process(const void* input, const size_t inputSize)
{
m_impl->Process(input, inputSize);
}
void AlgorithmSHA1::Finish(void* hashBuffer)
{
m_impl->Finish(hashBuffer);
}

View File

@ -1,20 +0,0 @@
#pragma once
#include "IHashFunction.h"
class AlgorithmSHA1 : public IHashFunction
{
class AlgorithmSHA1Impl;
AlgorithmSHA1Impl* m_impl;
public:
static const int HASH_SIZE = 20;
AlgorithmSHA1();
~AlgorithmSHA1() override;
size_t GetHashSize() override;
void Init() override;
void Process(const void* input, size_t inputSize) override;
void Finish(void* hashBuffer) override;
};

View File

@ -1,64 +0,0 @@
#include "AlgorithmSHA256.h"
#include "CryptoLibrary.h"
#include <cstdint>
class AlgorithmSHA256::Impl
{
hash_state m_state{};
public:
Impl()
{
CryptoLibrary::Init();
Init();
}
void Init()
{
sha256_init(&m_state);
}
void Process(const void* input, const size_t inputSize)
{
sha256_process(&m_state, static_cast<const uint8_t*>(input), inputSize);
}
void Finish(void* hashBuffer)
{
sha256_done(&m_state, static_cast<uint8_t*>(hashBuffer));
}
};
AlgorithmSHA256::AlgorithmSHA256()
{
m_impl = new Impl();
}
AlgorithmSHA256::~AlgorithmSHA256()
{
delete m_impl;
m_impl = nullptr;
}
size_t AlgorithmSHA256::GetHashSize()
{
return HASH_SIZE;
}
void AlgorithmSHA256::Init()
{
m_impl->Init();
}
void AlgorithmSHA256::Process(const void* input, const size_t inputSize)
{
m_impl->Process(input, inputSize);
}
void AlgorithmSHA256::Finish(void* hashBuffer)
{
m_impl->Finish(hashBuffer);
}

View File

@ -1,20 +0,0 @@
#pragma once
#include "IHashFunction.h"
class AlgorithmSHA256 : public IHashFunction
{
class Impl;
Impl* m_impl;
public:
static const int HASH_SIZE = 32;
AlgorithmSHA256();
~AlgorithmSHA256() override;
size_t GetHashSize() override;
void Init() override;
void Process(const void* input, size_t inputSize) override;
void Finish(void* hashBuffer) override;
};

View File

@ -1,89 +0,0 @@
#include "AlgorithmSalsa20.h"
#include "salsa20.h"
#include <cassert>
#include <stdexcept>
class AlgorithmSalsa20::AlgorithmSalsa20Impl
{
salsa20_ctx m_context{};
public:
AlgorithmSalsa20Impl(const uint8_t* keyBytes, const size_t keySize)
{
Salsa20_KeySetup(&m_context, keyBytes, keySize * 8);
}
~AlgorithmSalsa20Impl() = default;
AlgorithmSalsa20Impl(AlgorithmSalsa20Impl& other) = default;
AlgorithmSalsa20Impl(AlgorithmSalsa20Impl&& other) = delete;
AlgorithmSalsa20Impl& operator=(AlgorithmSalsa20Impl const& other) = default;
AlgorithmSalsa20Impl& operator=(AlgorithmSalsa20Impl&& other) = delete;
void SetIV(const uint8_t* iv, const size_t ivSize)
{
assert(ivSize == 8);
if (ivSize != 8)
{
throw std::invalid_argument("Salsa20 IV size must be 8");
}
Salsa20_IVSetup(&m_context, iv);
}
void Process(const void* plainText, void* cipherText, const size_t amount)
{
Salsa20_Encrypt_Bytes(&m_context, static_cast<const uint8_t*>(plainText), static_cast<uint8_t*>(cipherText), amount);
}
};
AlgorithmSalsa20::AlgorithmSalsa20(const uint8_t* keyBytes, const size_t keySize)
{
m_impl = new AlgorithmSalsa20Impl(keyBytes, keySize);
}
AlgorithmSalsa20::~AlgorithmSalsa20()
{
delete m_impl;
m_impl = nullptr;
}
AlgorithmSalsa20::AlgorithmSalsa20(AlgorithmSalsa20& other)
{
m_impl = new AlgorithmSalsa20Impl(*other.m_impl);
}
AlgorithmSalsa20::AlgorithmSalsa20(AlgorithmSalsa20&& other) noexcept
{
m_impl = other.m_impl;
other.m_impl = nullptr;
}
AlgorithmSalsa20& AlgorithmSalsa20::operator=(AlgorithmSalsa20 const& other)
{
m_impl = new AlgorithmSalsa20Impl(*other.m_impl);
return *this;
}
AlgorithmSalsa20& AlgorithmSalsa20::operator=(AlgorithmSalsa20&& other) noexcept
{
m_impl = other.m_impl;
other.m_impl = nullptr;
return *this;
}
void AlgorithmSalsa20::SetIV(const uint8_t* iv, const size_t ivSize)
{
m_impl->SetIV(iv, ivSize);
}
void AlgorithmSalsa20::Process(const void* plainText, void* cipherText, const size_t amount)
{
m_impl->Process(plainText, cipherText, amount);
}

View File

@ -1,21 +0,0 @@
#pragma once
#include "IStreamCipher.h"
class AlgorithmSalsa20 final : public IStreamCipher
{
class AlgorithmSalsa20Impl;
AlgorithmSalsa20Impl* m_impl;
public:
AlgorithmSalsa20(const uint8_t* keyBytes, size_t keySize);
~AlgorithmSalsa20() override;
AlgorithmSalsa20(AlgorithmSalsa20& other);
AlgorithmSalsa20(AlgorithmSalsa20&& other) noexcept;
AlgorithmSalsa20& operator=(AlgorithmSalsa20 const& other);
AlgorithmSalsa20& operator=(AlgorithmSalsa20&& other) noexcept;
void SetIV(const uint8_t* iv, size_t ivSize) override;
void Process(const void* plainText, void* cipherText, size_t amount) override;
};

View File

@ -1,15 +0,0 @@
#include "CryptoLibrary.h"
#include "tommath.h"
void CryptoLibrary::Init()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
ltc_mp = ltm_desc;
}
}

View File

@ -1,10 +0,0 @@
#pragma once
#define LTC_NO_PROTOTYPES
#include "tomcrypt.h"
class CryptoLibrary
{
public:
static void Init();
};

View File

@ -1,29 +1,29 @@
Crypto = {} Cryptography = {}
function Crypto:include(includes) function Cryptography:include(includes)
if includes:handle(self:name()) then if includes:handle(self:name()) then
includedirs { includedirs {
path.join(ProjectFolder(), "Crypto") path.join(ProjectFolder(), "Cryptography")
} }
end end
end end
function Crypto:link(links) function Cryptography:link(links)
links:add(self:name()) links:add(self:name())
links:linkto(libtomcrypt) links:linkto(libtomcrypt)
links:linkto(libtommath) links:linkto(libtommath)
links:linkto(salsa20) links:linkto(salsa20)
end end
function Crypto:use() function Cryptography:use()
end end
function Crypto:name() function Cryptography:name()
return "Crypto" return "Cryptography"
end end
function Crypto:project() function Cryptography:project()
local folder = ProjectFolder() local folder = ProjectFolder()
local includes = Includes:create() local includes = Includes:create()
@ -34,8 +34,8 @@ function Crypto:project()
language "C++" language "C++"
files { files {
path.join(folder, "Crypto/**.h"), path.join(folder, "Cryptography/**.h"),
path.join(folder, "Crypto/**.cpp") path.join(folder, "Cryptography/**.cpp")
} }
self:include(includes) self:include(includes)

View File

@ -0,0 +1,54 @@
#include "AlgorithmMd5.h"
#include "Internal/CryptoLibrary.h"
#include <cstdint>
using namespace cryptography;
namespace
{
constexpr int HASH_SIZE = 16;
class AlgorithmMd5 final : public IHashFunction
{
public:
AlgorithmMd5()
{
internal::CryptoLibrary::Init();
Init();
}
size_t GetHashSize() override
{
return HASH_SIZE;
}
void Init() override
{
md5_init(&m_state);
}
void Process(const void* input, const size_t inputSize) override
{
md5_process(&m_state, static_cast<const uint8_t*>(input), static_cast<unsigned long>(inputSize));
}
void Finish(void* hashBuffer) override
{
md5_done(&m_state, static_cast<uint8_t*>(hashBuffer));
}
private:
hash_state m_state{};
};
} // namespace
namespace cryptography
{
std::unique_ptr<IHashFunction> CreateMd5()
{
return std::make_unique<AlgorithmMd5>();
}
} // namespace cryptography

View File

@ -0,0 +1,10 @@
#pragma once
#include "IHashFunction.h"
#include <memory>
namespace cryptography
{
std::unique_ptr<IHashFunction> CreateMd5();
}

View File

@ -0,0 +1,84 @@
#include "AlgorithmRsa.h"
#include "Internal/CryptoLibrary.h"
using namespace cryptography;
namespace
{
class AlgorithmRsa final : public IPublicKeyAlgorithm
{
public:
AlgorithmRsa(const HashingAlgorithm hash, const RsaPaddingMode padding)
{
m_hash = hash;
m_padding = padding;
internal::CryptoLibrary::Init();
}
bool SetKey(const uint8_t* keyData, const size_t keySize) override
{
return rsa_import(keyData, static_cast<unsigned long>(keySize), &m_key) == CRYPT_OK;
}
bool Verify(const uint8_t* signedData, const size_t signedDataSize, const uint8_t* signature, const size_t signatureSize) override
{
const ltc_hash_descriptor* hashDesc = GetHashDescriptor();
const int hashId = register_hash(hashDesc);
const int padding = GetPaddingMode();
int result;
rsa_verify_hash_ex(signature,
static_cast<unsigned long>(signatureSize),
signedData,
static_cast<unsigned long>(signedDataSize),
padding,
hashId,
8,
&result,
&m_key);
return result == 1;
}
private:
[[nodiscard]] const ltc_hash_descriptor* GetHashDescriptor() const
{
switch (m_hash)
{
case HashingAlgorithm::RSA_HASH_SHA256:
return &sha256_desc;
default:
case HashingAlgorithm::RSA_HASH_SHA512:
return &sha512_desc;
}
}
[[nodiscard]] int GetPaddingMode() const
{
switch (m_padding)
{
case RsaPaddingMode::RSA_PADDING_PKS1:
return LTC_PKCS_1_V1_5;
default:
case RsaPaddingMode::RSA_PADDING_PSS:
return LTC_PKCS_1_PSS;
}
}
rsa_key m_key{};
HashingAlgorithm m_hash;
RsaPaddingMode m_padding;
};
} // namespace
namespace cryptography
{
std::unique_ptr<IPublicKeyAlgorithm> CreateRsa(const HashingAlgorithm hashingAlgorithm, const RsaPaddingMode paddingMode)
{
return std::make_unique<AlgorithmRsa>(hashingAlgorithm, paddingMode);
}
} // namespace cryptography

View File

@ -0,0 +1,17 @@
#pragma once
#include "IPublicKeyAlgorithm.h"
#include <cstdint>
#include <memory>
namespace cryptography
{
enum class RsaPaddingMode : std::uint8_t
{
RSA_PADDING_PKS1,
RSA_PADDING_PSS,
};
std::unique_ptr<IPublicKeyAlgorithm> CreateRsa(HashingAlgorithm hashingAlgorithm, RsaPaddingMode paddingMode);
} // namespace cryptography

View File

@ -0,0 +1,46 @@
#include "AlgorithmSalsa20.h"
#include "salsa20.h"
#include <cassert>
#include <stdexcept>
using namespace cryptography;
namespace
{
class AlgorithmSalsa20 final : public IStreamCipher
{
public:
AlgorithmSalsa20(const uint8_t* keyBytes, const size_t keySize)
{
Salsa20_KeySetup(&m_context, keyBytes, static_cast<uint32_t>(keySize * 8uz));
}
void SetIv(const uint8_t* iv, const size_t ivSize) override
{
assert(ivSize == 8);
if (ivSize != 8)
throw std::invalid_argument("Salsa20 IV size must be 8");
Salsa20_IVSetup(&m_context, iv);
}
void Process(const void* plainText, void* cipherText, const size_t amount) override
{
Salsa20_Encrypt_Bytes(&m_context, static_cast<const uint8_t*>(plainText), static_cast<uint8_t*>(cipherText), static_cast<uint32_t>(amount));
}
private:
salsa20_ctx m_context{};
};
} // namespace
namespace cryptography
{
std::unique_ptr<IStreamCipher> CreateSalsa20(const uint8_t* keyBytes, const size_t keySize)
{
return std::make_unique<AlgorithmSalsa20>(keyBytes, keySize);
}
} // namespace cryptography

View File

@ -0,0 +1,10 @@
#pragma once
#include "IStreamCipher.h"
#include <memory>
namespace cryptography
{
std::unique_ptr<IStreamCipher> CreateSalsa20(const uint8_t* keyBytes, size_t keySize);
}

View File

@ -0,0 +1,54 @@
#include "AlgorithmSha1.h"
#include "Internal/CryptoLibrary.h"
#include <cstdint>
using namespace cryptography;
namespace
{
constexpr int HASH_SIZE = 20;
class AlgorithmSha1 final : public IHashFunction
{
public:
AlgorithmSha1()
{
internal::CryptoLibrary::Init();
Init();
}
size_t GetHashSize() override
{
return HASH_SIZE;
}
void Init() override
{
sha1_init(&m_state);
}
void Process(const void* input, const size_t inputSize) override
{
sha1_process(&m_state, static_cast<const uint8_t*>(input), static_cast<unsigned long>(inputSize));
}
void Finish(void* hashBuffer) override
{
sha1_done(&m_state, static_cast<uint8_t*>(hashBuffer));
}
private:
hash_state m_state{};
};
} // namespace
namespace cryptography
{
std::unique_ptr<IHashFunction> CreateSha1()
{
return std::make_unique<AlgorithmSha1>();
}
} // namespace cryptography

View File

@ -0,0 +1,10 @@
#pragma once
#include "IHashFunction.h"
#include <memory>
namespace cryptography
{
std::unique_ptr<IHashFunction> CreateSha1();
}

View File

@ -0,0 +1,54 @@
#include "AlgorithmSha256.h"
#include "Internal/CryptoLibrary.h"
#include <cstdint>
using namespace cryptography;
namespace
{
constexpr int HASH_SIZE = 32;
class AlgorithmSha256 final : public IHashFunction
{
public:
AlgorithmSha256()
{
internal::CryptoLibrary::Init();
Init();
}
size_t GetHashSize() override
{
return HASH_SIZE;
}
void Init() override
{
sha256_init(&m_state);
}
void Process(const void* input, const size_t inputSize) override
{
sha256_process(&m_state, static_cast<const uint8_t*>(input), static_cast<unsigned long>(inputSize));
}
void Finish(void* hashBuffer) override
{
sha256_done(&m_state, static_cast<uint8_t*>(hashBuffer));
}
private:
hash_state m_state{};
};
} // namespace
namespace cryptography
{
std::unique_ptr<IHashFunction> CreateSha256()
{
return std::make_unique<AlgorithmSha256>();
}
} // namespace cryptography

View File

@ -0,0 +1,10 @@
#pragma once
#include "IHashFunction.h"
#include <memory>
namespace cryptography
{
std::unique_ptr<IHashFunction> CreateSha256();
}

View File

@ -20,8 +20,9 @@ namespace base64
bool EncodeBase64(const void* inputData, const size_t inputLength, void* outputBuffer, const size_t outputBufferSize) bool EncodeBase64(const void* inputData, const size_t inputLength, void* outputBuffer, const size_t outputBufferSize)
{ {
unsigned long outLength = outputBufferSize; unsigned long outLength = static_cast<unsigned long>(outputBufferSize);
const auto result = base64_encode(static_cast<const unsigned char*>(inputData), inputLength, static_cast<char*>(outputBuffer), &outLength); const auto result =
base64_encode(static_cast<const unsigned char*>(inputData), static_cast<unsigned long>(inputLength), static_cast<char*>(outputBuffer), &outLength);
return result == CRYPT_OK; return result == CRYPT_OK;
} }
@ -32,12 +33,13 @@ namespace base64
size_t DecodeBase64(const void* base64Data, const size_t inputLength, void* outputBuffer, const size_t outputBufferSize) size_t DecodeBase64(const void* base64Data, const size_t inputLength, void* outputBuffer, const size_t outputBufferSize)
{ {
unsigned long outLength = GetBase64DecodeOutputLength(base64Data, inputLength); auto outLength = static_cast<unsigned long>(GetBase64DecodeOutputLength(base64Data, inputLength));
assert(outLength <= outputBufferSize); assert(outLength <= outputBufferSize);
if (outLength > outputBufferSize) if (outLength > outputBufferSize)
return 0u; return 0u;
const auto result = base64_decode(static_cast<const char*>(base64Data), inputLength, static_cast<unsigned char*>(outputBuffer), &outLength); const auto result =
base64_decode(static_cast<const char*>(base64Data), static_cast<unsigned long>(inputLength), static_cast<unsigned char*>(outputBuffer), &outLength);
assert(result == CRYPT_OK); assert(result == CRYPT_OK);
return static_cast<size_t>(outLength); return static_cast<size_t>(outLength);

View File

@ -8,6 +8,6 @@ namespace base64
size_t GetBase64EncodeOutputLength(size_t inputLength); size_t GetBase64EncodeOutputLength(size_t inputLength);
size_t DecodeBase64(const void* base64Data, size_t inputLength, void* outputBuffer, size_t outputBufferSize); size_t DecodeBase64(const void* base64Data, size_t inputLength, void* outputBuffer, size_t outputBufferSize);
size_t GetBase64DecodeOutputLength(const void* base64Data, const size_t inputLength); size_t GetBase64DecodeOutputLength(const void* base64Data, size_t inputLength);
size_t GetBase64DecodeOutputLength(size_t inputLength); size_t GetBase64DecodeOutputLength(size_t inputLength);
} // namespace base64 } // namespace base64

View File

@ -0,0 +1,7 @@
#pragma once
#include "Algorithms/AlgorithmMd5.h"
#include "Algorithms/AlgorithmRsa.h"
#include "Algorithms/AlgorithmSalsa20.h"
#include "Algorithms/AlgorithmSha1.h"
#include "Algorithms/AlgorithmSha256.h"

View File

@ -0,0 +1,22 @@
#pragma once
#include <cstdlib>
namespace cryptography
{
class IHashFunction
{
public:
IHashFunction() = default;
virtual ~IHashFunction() = default;
IHashFunction(const IHashFunction& other) = default;
IHashFunction(IHashFunction&& other) noexcept = default;
IHashFunction& operator=(const IHashFunction& other) = default;
IHashFunction& operator=(IHashFunction&& other) noexcept = default;
virtual size_t GetHashSize() = 0;
virtual void Init() = 0;
virtual void Process(const void* input, size_t inputSize) = 0;
virtual void Finish(void* hashBuffer) = 0;
};
} // namespace cryptography

View File

@ -0,0 +1,30 @@
#pragma once
#include <cstdint>
#include <cstdlib>
namespace cryptography
{
enum class HashingAlgorithm : std::uint8_t
{
RSA_HASH_SHA256,
RSA_HASH_SHA512
};
class IPublicKeyAlgorithm
{
public:
IPublicKeyAlgorithm() = default;
virtual ~IPublicKeyAlgorithm() = default;
IPublicKeyAlgorithm(const IPublicKeyAlgorithm& other) = default;
IPublicKeyAlgorithm(IPublicKeyAlgorithm&& other) noexcept = default;
IPublicKeyAlgorithm& operator=(const IPublicKeyAlgorithm& other) = default;
IPublicKeyAlgorithm& operator=(IPublicKeyAlgorithm&& other) noexcept = default;
virtual bool SetKey(const uint8_t* keyData, size_t keySize) = 0;
// If needed, add a signing method
virtual bool Verify(const uint8_t* signedData, size_t signedDataSize, const uint8_t* signature, size_t signatureSize) = 0;
};
} // namespace cryptography

View File

@ -0,0 +1,21 @@
#pragma once
#include <cstdint>
#include <cstdlib>
namespace cryptography
{
class IStreamCipher
{
public:
IStreamCipher() = default;
virtual ~IStreamCipher() = default;
IStreamCipher(const IStreamCipher& other) = default;
IStreamCipher(IStreamCipher&& other) noexcept = default;
IStreamCipher& operator=(const IStreamCipher& other) = default;
IStreamCipher& operator=(IStreamCipher&& other) noexcept = default;
virtual void SetIv(const uint8_t* iv, size_t ivSize) = 0;
virtual void Process(const void* plainText, void* cipherText, size_t amount) = 0;
};
} // namespace cryptography

View File

@ -0,0 +1,18 @@
#include "CryptoLibrary.h"
#include "tommath.h"
namespace cryptography::internal
{
void CryptoLibrary::Init()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
ltc_mp = ltm_desc;
}
}
} // namespace cryptography::internal

View File

@ -0,0 +1,13 @@
#pragma once
#define LTC_NO_PROTOTYPES
#include "tomcrypt.h"
namespace cryptography::internal
{
class CryptoLibrary
{
public:
static void Init();
};
} // namespace cryptography::internal

View File

@ -56,8 +56,8 @@ namespace
void CreateFromString(const std::string& templateString) void CreateFromString(const std::string& templateString)
{ {
const auto templateStringLength = templateString.size(); const auto templateStringLength = templateString.size();
auto partStart = 0u; auto partStart = 0uz;
for (auto i = 0u; i < templateStringLength; i++) for (auto i = 0uz; i < templateStringLength; i++)
{ {
if (templateString[i] != '?') if (templateString[i] != '?')
continue; continue;

View File

@ -21,7 +21,7 @@ bool CsvHeaderRow::RequireIndexForHeader(const std::string& headerName, unsigned
if (existingHeader == m_header_row.end()) if (existingHeader == m_header_row.end())
return false; return false;
out = std::distance(m_header_row.begin(), existingHeader); out = static_cast<unsigned>(std::distance(m_header_row.begin(), existingHeader));
return true; return true;
} }

View File

@ -13,7 +13,7 @@ public:
bool Read(const CsvInputStream& inputStream); bool Read(const CsvInputStream& inputStream);
const std::string& HeaderNameForColumn(unsigned columnIndex) const; [[nodiscard]] const std::string& HeaderNameForColumn(unsigned columnIndex) const;
bool RequireIndexForHeader(const std::string& headerName, unsigned& out) const; bool RequireIndexForHeader(const std::string& headerName, unsigned& out) const;
[[nodiscard]] std::optional<unsigned> GetIndexForHeader(const std::string& headerName) const; [[nodiscard]] std::optional<unsigned> GetIndexForHeader(const std::string& headerName) const;

View File

@ -42,14 +42,14 @@ uint32_t CommonStructuredDataEnum::CalculateChecksum(const uint32_t initialValue
{ {
auto checksum = initialValue; auto checksum = initialValue;
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(m_name.c_str()), m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(m_name.c_str()), static_cast<unsigned>(m_name.size() + 1u));
const auto littleEndianElementCount = endianness::ToLittleEndian(ElementCount()); const auto littleEndianElementCount = endianness::ToLittleEndian(ElementCount());
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianElementCount), sizeof(littleEndianElementCount)); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianElementCount), sizeof(littleEndianElementCount));
for (const auto& entry : m_entries) for (const auto& entry : m_entries)
{ {
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(entry.m_name.c_str()), entry.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(entry.m_name.c_str()), static_cast<unsigned>(entry.m_name.size() + 1));
const auto littleEndianValue = endianness::ToLittleEndian(entry.m_value); const auto littleEndianValue = endianness::ToLittleEndian(entry.m_value);
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianValue), sizeof(littleEndianValue)); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianValue), sizeof(littleEndianValue));

View File

@ -41,10 +41,10 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
{ {
auto checksum = initialValue; auto checksum = initialValue;
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(m_name.c_str()), m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(m_name.c_str()), static_cast<unsigned>(m_name.size() + 1u));
for (const auto& property : m_properties) for (const auto& property : m_properties)
{ {
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(property.m_name.c_str()), property.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(property.m_name.c_str()), static_cast<unsigned>(property.m_name.size() + 1u));
const auto littleEndianOffset = endianness::ToLittleEndian(property.m_offset_in_bits); const auto littleEndianOffset = endianness::ToLittleEndian(property.m_offset_in_bits);
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianOffset), sizeof(littleEndianOffset)); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianOffset), sizeof(littleEndianOffset));
@ -68,7 +68,7 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
if (currentType.m_info.type_index < def.m_enums.size()) if (currentType.m_info.type_index < def.m_enums.size())
{ {
const auto& _enum = *def.m_enums[currentType.m_info.type_index]; const auto& _enum = *def.m_enums[currentType.m_info.type_index];
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_enum.m_name.c_str()), _enum.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_enum.m_name.c_str()), static_cast<unsigned>(_enum.m_name.size() + 1u));
currentType = CommonStructuredDataType(CommonStructuredDataTypeCategory::UNKNOWN); currentType = CommonStructuredDataType(CommonStructuredDataTypeCategory::UNKNOWN);
} }
break; break;
@ -76,7 +76,7 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
if (currentType.m_info.type_index < def.m_structs.size()) if (currentType.m_info.type_index < def.m_structs.size())
{ {
const auto& _struct = *def.m_structs[currentType.m_info.type_index]; const auto& _struct = *def.m_structs[currentType.m_info.type_index];
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_struct.m_name.c_str()), _struct.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_struct.m_name.c_str()), static_cast<unsigned>(_struct.m_name.size() + 1u));
currentType = CommonStructuredDataType(CommonStructuredDataTypeCategory::UNKNOWN); currentType = CommonStructuredDataType(CommonStructuredDataTypeCategory::UNKNOWN);
} }
break; break;
@ -99,7 +99,7 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
if (enumedArray.m_enum_index < def.m_enums.size()) if (enumedArray.m_enum_index < def.m_enums.size())
{ {
const auto& _enum = *def.m_enums[enumedArray.m_enum_index]; const auto& _enum = *def.m_enums[enumedArray.m_enum_index];
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_enum.m_name.c_str()), _enum.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_enum.m_name.c_str()), static_cast<unsigned>(_enum.m_name.size() + 1u));
} }
currentType = enumedArray.m_array_type; currentType = enumedArray.m_array_type;
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CommonStructuredDataTypes.h" #include "CommonStructuredDataTypes.h"
#include "Utils/ClassUtils.h"
#include <cstdint> #include <cstdint>
#include <string> #include <string>
@ -8,29 +8,29 @@
struct CommonStructuredDataStructProperty struct CommonStructuredDataStructProperty
{ {
std::string m_name;
CommonStructuredDataType m_type;
size_t m_offset_in_bits;
CommonStructuredDataStructProperty(); CommonStructuredDataStructProperty();
explicit CommonStructuredDataStructProperty(std::string name); explicit CommonStructuredDataStructProperty(std::string name);
CommonStructuredDataStructProperty(std::string name, CommonStructuredDataType type, size_t offsetInBits); CommonStructuredDataStructProperty(std::string name, CommonStructuredDataType type, size_t offsetInBits);
std::string m_name;
CommonStructuredDataType m_type;
size_t m_offset_in_bits;
}; };
class CommonStructuredDataDef; class CommonStructuredDataDef;
struct CommonStructuredDataStruct struct CommonStructuredDataStruct
{ {
CommonStructuredDataStruct();
explicit CommonStructuredDataStruct(std::string name);
[[nodiscard]] uint32_t CalculateChecksum(const CommonStructuredDataDef& def, uint32_t initialValue) const;
void SortPropertiesByOffset();
void SortPropertiesByName();
std::string m_name; std::string m_name;
std::vector<CommonStructuredDataStructProperty> m_properties; std::vector<CommonStructuredDataStructProperty> m_properties;
size_t m_bit_offset; size_t m_bit_offset;
size_t m_size_in_byte; size_t m_size_in_byte;
CommonStructuredDataStruct();
explicit CommonStructuredDataStruct(std::string name);
_NODISCARD uint32_t CalculateChecksum(const CommonStructuredDataDef& def, uint32_t initialValue) const;
void SortPropertiesByOffset();
void SortPropertiesByName();
}; };

View File

@ -6,7 +6,6 @@
#include <cassert> #include <cassert>
#include <format> #include <format>
#include <iostream>
using namespace T6; using namespace T6;
@ -42,7 +41,7 @@ namespace
auto* gameKvps = m_memory.Alloc<KeyValuePairs>(); auto* gameKvps = m_memory.Alloc<KeyValuePairs>();
gameKvps->name = m_memory.Dup(m_zone.m_name.c_str()); gameKvps->name = m_memory.Dup(m_zone.m_name.c_str());
gameKvps->numVariables = commonKvps.size(); gameKvps->numVariables = static_cast<unsigned>(commonKvps.size());
gameKvps->keyValuePairs = m_memory.Alloc<KeyValuePair>(commonKvps.size()); gameKvps->keyValuePairs = m_memory.Alloc<KeyValuePair>(commonKvps.size());
const auto namespaceHash = Common::Com_HashKey(m_zone.m_name.c_str(), 64); const auto namespaceHash = Common::Com_HashKey(m_zone.m_name.c_str(), 64);

View File

@ -1,7 +1,6 @@
#include "IPakCreator.h" #include "IPakCreator.h"
#include "Game/T6/CommonT6.h" #include "Game/T6/CommonT6.h"
#include "Game/T6/GameT6.h"
#include "GitVersion.h" #include "GitVersion.h"
#include "ObjContainer/IPak/IPakTypes.h" #include "ObjContainer/IPak/IPakTypes.h"
#include "Utils/Alignment.h" #include "Utils/Alignment.h"
@ -23,7 +22,7 @@ namespace
static constexpr char BRANDING[] = "Created with OpenAssetTools " GIT_VERSION; static constexpr char BRANDING[] = "Created with OpenAssetTools " GIT_VERSION;
static constexpr auto SECTION_COUNT = 3; // Index + Data + Branding static constexpr auto SECTION_COUNT = 3; // Index + Data + Branding
inline static const std::string PAD_DATA = std::string(256, '\xA7'); inline static const auto PAD_DATA = std::string(256, '\xA7');
public: public:
IPakWriter(std::ostream& stream, ISearchPath& searchPath, const std::vector<std::string>& images) IPakWriter(std::ostream& stream, ISearchPath& searchPath, const std::vector<std::string>& images)
@ -70,8 +69,8 @@ namespace
void Write(const void* data, const size_t dataSize) void Write(const void* data, const size_t dataSize)
{ {
m_stream.write(static_cast<const char*>(data), dataSize); m_stream.write(static_cast<const char*>(data), static_cast<std::streamsize>(dataSize));
m_current_offset += dataSize; m_current_offset += static_cast<int64_t>(dataSize);
} }
void Pad(const size_t paddingSize) void Pad(const size_t paddingSize)
@ -100,27 +99,30 @@ namespace
{ {
GoTo(0); GoTo(0);
const IPakHeader header{ipak_consts::IPAK_MAGIC, ipak_consts::IPAK_VERSION, static_cast<uint32_t>(m_total_size), SECTION_COUNT}; const IPakHeader header{.magic = ipak_consts::IPAK_MAGIC,
.version = ipak_consts::IPAK_VERSION,
.size = static_cast<uint32_t>(m_total_size),
.sectionCount = SECTION_COUNT};
const IPakSection dataSection{ const IPakSection dataSection{
ipak_consts::IPAK_DATA_SECTION, .type = ipak_consts::IPAK_DATA_SECTION,
static_cast<uint32_t>(m_data_section_offset), .offset = static_cast<uint32_t>(m_data_section_offset),
static_cast<uint32_t>(m_data_section_size), .size = static_cast<uint32_t>(m_data_section_size),
static_cast<uint32_t>(m_index_entries.size()), .itemCount = static_cast<uint32_t>(m_index_entries.size()),
}; };
const IPakSection indexSection{ const IPakSection indexSection{
ipak_consts::IPAK_INDEX_SECTION, .type = ipak_consts::IPAK_INDEX_SECTION,
static_cast<uint32_t>(m_index_section_offset), .offset = static_cast<uint32_t>(m_index_section_offset),
static_cast<uint32_t>(sizeof(IPakIndexEntry) * m_index_entries.size()), .size = static_cast<uint32_t>(sizeof(IPakIndexEntry) * m_index_entries.size()),
static_cast<uint32_t>(m_index_entries.size()), .itemCount = static_cast<uint32_t>(m_index_entries.size()),
}; };
const IPakSection brandingSection{ const IPakSection brandingSection{
ipak_consts::IPAK_BRANDING_SECTION, .type = ipak_consts::IPAK_BRANDING_SECTION,
static_cast<uint32_t>(m_branding_section_offset), .offset = static_cast<uint32_t>(m_branding_section_offset),
std::extent_v<decltype(BRANDING)>, .size = std::extent_v<decltype(BRANDING)>,
1, .itemCount = 1,
}; };
Write(&header, sizeof(header)); Write(&header, sizeof(header));
@ -147,7 +149,7 @@ namespace
imageSize = static_cast<size_t>(openFile.m_length); imageSize = static_cast<size_t>(openFile.m_length);
auto imageData = std::make_unique<char[]>(imageSize); auto imageData = std::make_unique<char[]>(imageSize);
openFile.m_stream->read(imageData.get(), imageSize); openFile.m_stream->read(imageData.get(), static_cast<std::streamsize>(imageSize));
return imageData; return imageData;
} }
@ -177,7 +179,7 @@ namespace
IPakDataBlockHeader skipBlockHeader{}; IPakDataBlockHeader skipBlockHeader{};
skipBlockHeader.countAndOffset.count = 1; skipBlockHeader.countAndOffset.count = 1;
skipBlockHeader.commands[0].compressed = ipak_consts::IPAK_COMMAND_SKIP; skipBlockHeader.commands[0].compressed = ipak_consts::IPAK_COMMAND_SKIP;
skipBlockHeader.commands[0].size = sizeToSkip - sizeof(IPakDataBlockHeader); skipBlockHeader.commands[0].size = static_cast<uint32_t>(sizeToSkip - sizeof(IPakDataBlockHeader));
Write(&skipBlockHeader, sizeof(skipBlockHeader)); Write(&skipBlockHeader, sizeof(skipBlockHeader));
} }
@ -199,12 +201,12 @@ namespace
m_current_block.countAndOffset.offset = static_cast<uint32_t>(m_file_offset); m_current_block.countAndOffset.offset = static_cast<uint32_t>(m_file_offset);
// Reserve space to later write actual block header data // Reserve space to later write actual block header data
GoTo(m_current_offset + sizeof(IPakDataBlockHeader)); GoTo(static_cast<int64_t>(m_current_offset + sizeof(IPakDataBlockHeader)));
} }
void WriteChunkData(const void* data, const size_t dataSize) void WriteChunkData(const void* data, const size_t dataSize)
{ {
auto dataOffset = 0u; auto dataOffset = 0uz;
while (dataOffset < dataSize) while (dataOffset < dataSize)
{ {
if (m_current_block.countAndOffset.count >= std::extent_v<decltype(IPakDataBlockHeader::commands)>) if (m_current_block.countAndOffset.count >= std::extent_v<decltype(IPakDataBlockHeader::commands)>)
@ -225,7 +227,7 @@ namespace
continue; continue;
} }
const auto commandSize = std::min(std::min(remainingSize, ipak_consts::IPAK_COMMAND_DEFAULT_SIZE), remainingChunkBufferWindowSize); const auto commandSize = std::min({remainingSize, ipak_consts::IPAK_COMMAND_DEFAULT_SIZE, remainingChunkBufferWindowSize});
auto writeUncompressed = true; auto writeUncompressed = true;
if (USE_IPAK_COMPRESSION) if (USE_IPAK_COMPRESSION)
@ -254,7 +256,7 @@ namespace
Write(&static_cast<const char*>(data)[dataOffset], commandSize); Write(&static_cast<const char*>(data)[dataOffset], commandSize);
const auto currentCommand = m_current_block.countAndOffset.count; const auto currentCommand = m_current_block.countAndOffset.count;
m_current_block.commands[currentCommand].size = commandSize; m_current_block.commands[currentCommand].size = static_cast<uint32_t>(commandSize);
m_current_block.commands[currentCommand].compressed = ipak_consts::IPAK_COMMAND_UNCOMPRESSED; m_current_block.commands[currentCommand].compressed = ipak_consts::IPAK_COMMAND_UNCOMPRESSED;
m_current_block.countAndOffset.count = currentCommand + 1u; m_current_block.countAndOffset.count = currentCommand + 1u;
} }
@ -281,7 +283,7 @@ namespace
return; return;
const auto nameHash = T6::Common::R_HashString(imageName.c_str(), 0); const auto nameHash = T6::Common::R_HashString(imageName.c_str(), 0);
const auto dataHash = static_cast<unsigned>(crc32(0u, reinterpret_cast<const Bytef*>(imageData.get()), imageSize)); const auto dataHash = static_cast<unsigned>(crc32(0u, reinterpret_cast<const Bytef*>(imageData.get()), static_cast<unsigned>(imageSize)));
StartNewFile(); StartNewFile();
const auto startOffset = m_current_block_header_offset; const auto startOffset = m_current_block_header_offset;
@ -294,7 +296,7 @@ namespace
WriteChunkData(imageData.get(), imageSize); WriteChunkData(imageData.get(), imageSize);
const auto writtenImageSize = static_cast<size_t>(m_current_offset - startOffset); const auto writtenImageSize = static_cast<size_t>(m_current_offset - startOffset);
indexEntry.size = writtenImageSize; indexEntry.size = static_cast<uint32_t>(writtenImageSize);
m_index_entries.emplace_back(indexEntry); m_index_entries.emplace_back(indexEntry);
} }

View File

@ -14,16 +14,28 @@ namespace dds
{ {
static constexpr auto DDS_MAGIC = FileUtils::MakeMagic32('D', 'D', 'S', ' '); static constexpr auto DDS_MAGIC = FileUtils::MakeMagic32('D', 'D', 'S', ' ');
std::istream& m_stream; public:
explicit DdsLoaderInternal(std::istream& stream)
: m_stream(stream),
m_texture_type(TextureType::T_2D),
m_has_mip_maps(false),
m_width(0u),
m_height(0u),
m_depth(0u),
m_format(nullptr)
{
}
TextureType m_texture_type; std::unique_ptr<Texture> LoadDds()
bool m_has_mip_maps; {
size_t m_width; if (!ReadMagic() || !ReadHeader())
size_t m_height; return nullptr;
size_t m_depth;
const ImageFormat* m_format;
_NODISCARD bool ReadMagic() const return ReadTextureData();
}
private:
[[nodiscard]] bool ReadMagic() const
{ {
uint32_t magic; uint32_t magic;
m_stream.read(reinterpret_cast<char*>(&magic), sizeof(magic)); m_stream.read(reinterpret_cast<char*>(&magic), sizeof(magic));
@ -42,7 +54,7 @@ namespace dds
return true; return true;
} }
_NODISCARD bool ReadDxt10Header() [[nodiscard]] bool ReadDxt10Header()
{ {
DDS_HEADER_DXT10 headerDx10{}; DDS_HEADER_DXT10 headerDx10{};
m_stream.read(reinterpret_cast<char*>(&headerDx10), sizeof(headerDx10)); m_stream.read(reinterpret_cast<char*>(&headerDx10), sizeof(headerDx10));
@ -86,7 +98,7 @@ namespace dds
return false; return false;
} }
_NODISCARD bool ReadPixelFormatFourCc(DDS_PIXELFORMAT& pf) [[nodiscard]] bool ReadPixelFormatFourCc(DDS_PIXELFORMAT& pf)
{ {
switch (pf.dwFourCC) switch (pf.dwFourCC)
{ {
@ -132,7 +144,7 @@ namespace dds
} }
} }
_NODISCARD bool ReadPixelFormatUnsigned(DDS_PIXELFORMAT& pf) [[nodiscard]] bool ReadPixelFormatUnsigned(DDS_PIXELFORMAT& pf)
{ {
unsigned rOffset, rSize, gOffset, gSize, bOffset, bSize, aOffset, aSize; unsigned rOffset, rSize, gOffset, gSize, bOffset, bSize, aOffset, aSize;
@ -163,7 +175,7 @@ namespace dds
return false; return false;
} }
_NODISCARD bool ReadPixelFormat(DDS_PIXELFORMAT& pf) [[nodiscard]] bool ReadPixelFormat(DDS_PIXELFORMAT& pf)
{ {
if (pf.dwFlags & DDPF_FOURCC) if (pf.dwFlags & DDPF_FOURCC)
return ReadPixelFormatFourCc(pf); return ReadPixelFormatFourCc(pf);
@ -200,7 +212,7 @@ namespace dds
return ReadPixelFormat(header.ddspf); return ReadPixelFormat(header.ddspf);
} }
_NODISCARD std::unique_ptr<Texture> ReadTextureData() const [[nodiscard]] std::unique_ptr<Texture> ReadTextureData() const
{ {
std::unique_ptr<Texture> result; std::unique_ptr<Texture> result;
@ -229,7 +241,7 @@ namespace dds
for (auto mipLevel = 0; mipLevel < mipMapCount; mipLevel++) for (auto mipLevel = 0; mipLevel < mipMapCount; mipLevel++)
{ {
const auto mipSize = result->GetSizeOfMipLevel(mipLevel); const auto mipSize = static_cast<std::streamsize>(result->GetSizeOfMipLevel(mipLevel));
for (auto face = 0; face < faceCount; face++) for (auto face = 0; face < faceCount; face++)
{ {
@ -246,25 +258,14 @@ namespace dds
return result; return result;
} }
public: std::istream& m_stream;
explicit DdsLoaderInternal(std::istream& stream)
: m_stream(stream),
m_texture_type(TextureType::T_2D),
m_has_mip_maps(false),
m_width(0u),
m_height(0u),
m_depth(0u),
m_format(nullptr)
{
}
std::unique_ptr<Texture> LoadDds() TextureType m_texture_type;
{ bool m_has_mip_maps;
if (!ReadMagic() || !ReadHeader()) unsigned m_width;
return nullptr; unsigned m_height;
unsigned m_depth;
return ReadTextureData(); const ImageFormat* m_format;
}
}; };
std::unique_ptr<Texture> LoadDds(std::istream& stream) std::unique_ptr<Texture> LoadDds(std::istream& stream)

View File

@ -55,7 +55,7 @@ public:
{ {
const auto* buffer = m_texture->GetBufferForMipLevel(mipLevel); const auto* buffer = m_texture->GetBufferForMipLevel(mipLevel);
const auto mipLevelSize = m_texture->GetSizeOfMipLevel(mipLevel) * m_texture->GetFaceCount(); const auto mipLevelSize = m_texture->GetSizeOfMipLevel(mipLevel) * m_texture->GetFaceCount();
m_stream.write(reinterpret_cast<const char*>(buffer), mipLevelSize); m_stream.write(reinterpret_cast<const char*>(buffer), static_cast<std::streamsize>(mipLevelSize));
} }
} }
@ -153,7 +153,7 @@ public:
header.dwHeight = m_texture->GetHeight(); header.dwHeight = m_texture->GetHeight();
header.dwWidth = m_texture->GetWidth(); header.dwWidth = m_texture->GetWidth();
header.dwDepth = m_texture->GetDepth(); header.dwDepth = m_texture->GetDepth();
header.dwPitchOrLinearSize = m_texture->GetFormat()->GetPitch(0, m_texture->GetWidth()); header.dwPitchOrLinearSize = static_cast<uint32_t>(m_texture->GetFormat()->GetPitch(0, m_texture->GetWidth()));
header.dwMipMapCount = m_texture->HasMipMaps() ? m_texture->GetMipMapCount() : 1; header.dwMipMapCount = m_texture->HasMipMaps() ? m_texture->GetMipMapCount() : 1;
PopulatePixelFormat(header.ddspf); PopulatePixelFormat(header.ddspf);

View File

@ -14,7 +14,7 @@ Dx12TextureLoader::Dx12TextureLoader()
const ImageFormat* Dx12TextureLoader::GetFormatForDx12Format() const const ImageFormat* Dx12TextureLoader::GetFormatForDx12Format() const
{ {
for (auto i : ImageFormat::ALL_FORMATS) for (const auto* i : ImageFormat::ALL_FORMATS)
{ {
if (i->GetDxgiFormat() == m_format) if (i->GetDxgiFormat() == m_format)
return i; return i;
@ -41,19 +41,19 @@ Dx12TextureLoader& Dx12TextureLoader::HasMipMaps(const bool hasMipMaps)
return *this; return *this;
} }
Dx12TextureLoader& Dx12TextureLoader::Width(const size_t width) Dx12TextureLoader& Dx12TextureLoader::Width(const unsigned width)
{ {
m_width = width; m_width = width;
return *this; return *this;
} }
Dx12TextureLoader& Dx12TextureLoader::Height(const size_t height) Dx12TextureLoader& Dx12TextureLoader::Height(const unsigned height)
{ {
m_height = height; m_height = height;
return *this; return *this;
} }
Dx12TextureLoader& Dx12TextureLoader::Depth(const size_t depth) Dx12TextureLoader& Dx12TextureLoader::Depth(const unsigned depth)
{ {
m_depth = depth; m_depth = depth;
return *this; return *this;

View File

@ -2,8 +2,6 @@
#include "Image/DxgiFormat.h" #include "Image/DxgiFormat.h"
#include "Image/Texture.h" #include "Image/Texture.h"
#include "Utils/ClassUtils.h"
#include "Utils/MemoryManager.h"
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
@ -16,21 +14,21 @@ public:
Dx12TextureLoader& Format(oat::DXGI_FORMAT format); Dx12TextureLoader& Format(oat::DXGI_FORMAT format);
Dx12TextureLoader& Type(TextureType textureType); Dx12TextureLoader& Type(TextureType textureType);
Dx12TextureLoader& HasMipMaps(bool hasMipMaps); Dx12TextureLoader& HasMipMaps(bool hasMipMaps);
Dx12TextureLoader& Width(size_t width); Dx12TextureLoader& Width(unsigned width);
Dx12TextureLoader& Height(size_t height); Dx12TextureLoader& Height(unsigned height);
Dx12TextureLoader& Depth(size_t depth); Dx12TextureLoader& Depth(unsigned depth);
std::unique_ptr<Texture> LoadTexture(const void* data); std::unique_ptr<Texture> LoadTexture(const void* data);
private: private:
_NODISCARD const ImageFormat* GetFormatForDx12Format() const; [[nodiscard]] const ImageFormat* GetFormatForDx12Format() const;
static std::unordered_map<ImageFormatId, ImageFormatId> m_conversion_table; static std::unordered_map<ImageFormatId, ImageFormatId> m_conversion_table;
oat::DXGI_FORMAT m_format; oat::DXGI_FORMAT m_format;
TextureType m_type; TextureType m_type;
bool m_has_mip_maps; bool m_has_mip_maps;
size_t m_width; unsigned m_width;
size_t m_height; unsigned m_height;
size_t m_depth; unsigned m_depth;
}; };

View File

@ -41,19 +41,19 @@ Dx9TextureLoader& Dx9TextureLoader::HasMipMaps(const bool hasMipMaps)
return *this; return *this;
} }
Dx9TextureLoader& Dx9TextureLoader::Width(const size_t width) Dx9TextureLoader& Dx9TextureLoader::Width(const unsigned width)
{ {
m_width = width; m_width = width;
return *this; return *this;
} }
Dx9TextureLoader& Dx9TextureLoader::Height(const size_t height) Dx9TextureLoader& Dx9TextureLoader::Height(const unsigned height)
{ {
m_height = height; m_height = height;
return *this; return *this;
} }
Dx9TextureLoader& Dx9TextureLoader::Depth(const size_t depth) Dx9TextureLoader& Dx9TextureLoader::Depth(const unsigned depth)
{ {
m_depth = depth; m_depth = depth;
return *this; return *this;

View File

@ -2,11 +2,8 @@
#include "Image/D3DFormat.h" #include "Image/D3DFormat.h"
#include "Image/Texture.h" #include "Image/Texture.h"
#include "Utils/ClassUtils.h"
#include "Utils/MemoryManager.h"
#include <memory> #include <memory>
#include <unordered_map>
class Dx9TextureLoader class Dx9TextureLoader
{ {
@ -16,19 +13,19 @@ public:
Dx9TextureLoader& Format(oat::D3DFORMAT format); Dx9TextureLoader& Format(oat::D3DFORMAT format);
Dx9TextureLoader& Type(TextureType textureType); Dx9TextureLoader& Type(TextureType textureType);
Dx9TextureLoader& HasMipMaps(bool hasMipMaps); Dx9TextureLoader& HasMipMaps(bool hasMipMaps);
Dx9TextureLoader& Width(size_t width); Dx9TextureLoader& Width(unsigned width);
Dx9TextureLoader& Height(size_t height); Dx9TextureLoader& Height(unsigned height);
Dx9TextureLoader& Depth(size_t depth); Dx9TextureLoader& Depth(unsigned depth);
std::unique_ptr<Texture> LoadTexture(const void* data); std::unique_ptr<Texture> LoadTexture(const void* data);
private: private:
_NODISCARD const ImageFormat* GetFormatForDx9Format() const; [[nodiscard]] const ImageFormat* GetFormatForDx9Format() const;
oat::D3DFORMAT m_format; oat::D3DFORMAT m_format;
TextureType m_type; TextureType m_type;
bool m_has_mip_maps; bool m_has_mip_maps;
size_t m_width; unsigned m_width;
size_t m_height; unsigned m_height;
size_t m_depth; unsigned m_depth;
}; };

View File

@ -48,13 +48,13 @@ protected:
public: public:
virtual ~ImageFormat() = default; virtual ~ImageFormat() = default;
ImageFormatId GetId() const; [[nodiscard]] ImageFormatId GetId() const;
oat::D3DFORMAT GetD3DFormat() const; [[nodiscard]] oat::D3DFORMAT GetD3DFormat() const;
oat::DXGI_FORMAT GetDxgiFormat() const; [[nodiscard]] oat::DXGI_FORMAT GetDxgiFormat() const;
virtual ImageFormatType GetType() const = 0; [[nodiscard]] virtual ImageFormatType GetType() const = 0;
virtual size_t GetPitch(unsigned mipLevel, unsigned width) const = 0; [[nodiscard]] virtual size_t GetPitch(unsigned mipLevel, unsigned width) const = 0;
virtual size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const = 0; [[nodiscard]] virtual size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const = 0;
static const ImageFormatUnsigned FORMAT_R8_G8_B8; static const ImageFormatUnsigned FORMAT_R8_G8_B8;
static const ImageFormatUnsigned FORMAT_B8_G8_R8_X8; static const ImageFormatUnsigned FORMAT_B8_G8_R8_X8;
@ -98,14 +98,14 @@ public:
unsigned aOffset, unsigned aOffset,
unsigned aSize); unsigned aSize);
ImageFormatType GetType() const override; [[nodiscard]] ImageFormatType GetType() const override;
size_t GetPitch(unsigned mipLevel, unsigned width) const override; [[nodiscard]] size_t GetPitch(unsigned mipLevel, unsigned width) const override;
size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override; [[nodiscard]] size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override;
bool HasR() const; [[nodiscard]] bool HasR() const;
bool HasG() const; [[nodiscard]] bool HasG() const;
bool HasB() const; [[nodiscard]] bool HasB() const;
bool HasA() const; [[nodiscard]] bool HasA() const;
}; };
class ImageFormatBlockCompressed final : public ImageFormat class ImageFormatBlockCompressed final : public ImageFormat
@ -116,7 +116,7 @@ public:
ImageFormatBlockCompressed(ImageFormatId id, oat::D3DFORMAT d3dFormat, oat::DXGI_FORMAT dxgiFormat, unsigned blockSize, unsigned bitsPerBlock); ImageFormatBlockCompressed(ImageFormatId id, oat::D3DFORMAT d3dFormat, oat::DXGI_FORMAT dxgiFormat, unsigned blockSize, unsigned bitsPerBlock);
ImageFormatType GetType() const override; [[nodiscard]] ImageFormatType GetType() const override;
size_t GetPitch(unsigned mipLevel, unsigned width) const override; [[nodiscard]] size_t GetPitch(unsigned mipLevel, unsigned width) const override;
size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override; [[nodiscard]] size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override;
}; };

View File

@ -110,7 +110,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
currentFileSize += mipLevelSize; currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>)) if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>))
header.fileSizeForPicmip[currentMipLevel] = currentFileSize; header.fileSizeForPicmip[currentMipLevel] = static_cast<uint32_t>(currentFileSize);
} }
if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture)) if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))

View File

@ -113,7 +113,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
currentFileSize += mipLevelSize; currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(iwi27::IwiHeader::fileSizeForPicmip)>)) if (currentMipLevel < static_cast<int>(std::extent_v<decltype(iwi27::IwiHeader::fileSizeForPicmip)>))
header.fileSizeForPicmip[currentMipLevel] = currentFileSize; header.fileSizeForPicmip[currentMipLevel] = static_cast<uint32_t>(currentFileSize);
} }
if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture)) if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))

View File

@ -105,7 +105,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
currentFileSize += mipLevelSize; currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>)) if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>))
header.fileSizeForPicmip[currentMipLevel] = currentFileSize; header.fileSizeForPicmip[currentMipLevel] = static_cast<uint32_t>(currentFileSize);
} }
if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture)) if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))

View File

@ -105,7 +105,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
currentFileSize += mipLevelSize; currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>)) if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>))
header.fileSizeForPicmip[currentMipLevel] = currentFileSize; header.fileSizeForPicmip[currentMipLevel] = static_cast<uint32_t>(currentFileSize);
} }
if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture)) if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))

View File

@ -55,7 +55,7 @@ function ObjLoading:project()
useSourceTemplating("ObjLoading") useSourceTemplating("ObjLoading")
self:include(includes) self:include(includes)
Crypto:include(includes) Cryptography:include(includes)
Utils:include(includes) Utils:include(includes)
minilzo:include(includes) minilzo:include(includes)
minizip:include(includes) minizip:include(includes)

View File

@ -81,7 +81,7 @@ namespace
const auto mipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1; const auto mipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1;
const auto faceCount = texture->GetFaceCount(); const auto faceCount = texture->GetFaceCount();
size_t dataSize = 0; auto dataSize = 0uz;
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++) for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)
dataSize += texture->GetSizeOfMipLevel(mipLevel) * faceCount; dataSize += texture->GetSizeOfMipLevel(mipLevel) * faceCount;
@ -99,7 +99,7 @@ namespace
loadDef->dimensions[1] = image->height; loadDef->dimensions[1] = image->height;
loadDef->dimensions[2] = image->depth; loadDef->dimensions[2] = image->depth;
loadDef->format = static_cast<int>(texture->GetFormat()->GetD3DFormat()); loadDef->format = static_cast<int>(texture->GetFormat()->GetD3DFormat());
loadDef->resourceSize = dataSize; loadDef->resourceSize = static_cast<unsigned>(dataSize);
char* currentDataBuffer = loadDef->data; char* currentDataBuffer = loadDef->data;
for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++) for (auto mipLevel = 0; mipLevel < mipCount; mipLevel++)

View File

@ -83,7 +83,7 @@ namespace
menu::MenuAssetZoneState& zoneState, menu::MenuAssetZoneState& zoneState,
MenuConversionZoneState& conversionState, MenuConversionZoneState& conversionState,
std::vector<menuDef_t*>& menus, std::vector<menuDef_t*>& menus,
AssetRegistration<AssetMenuList>& registration) AssetRegistration<AssetMenuList>& registration) const
{ {
const auto alreadyLoadedMenuFile = conversionState.m_menus_by_filename.find(menuFilePath); const auto alreadyLoadedMenuFile = conversionState.m_menus_by_filename.find(menuFilePath);
if (alreadyLoadedMenuFile != conversionState.m_menus_by_filename.end()) if (alreadyLoadedMenuFile != conversionState.m_menus_by_filename.end())
@ -125,12 +125,12 @@ namespace
menu::MenuAssetZoneState& zoneState, menu::MenuAssetZoneState& zoneState,
MenuConversionZoneState& conversionState, MenuConversionZoneState& conversionState,
std::vector<menuDef_t*>& menus, std::vector<menuDef_t*>& menus,
AssetRegistration<AssetMenuList>& registration) AssetRegistration<AssetMenuList>& registration) const
{ {
const auto menuCount = parsingResult.m_menus.size(); const auto menuCount = parsingResult.m_menus.size();
const auto functionCount = parsingResult.m_functions.size(); const auto functionCount = parsingResult.m_functions.size();
const auto menuLoadCount = parsingResult.m_menus_to_load.size(); const auto menuLoadCount = parsingResult.m_menus_to_load.size();
auto totalItemCount = 0u; auto totalItemCount = 0uz;
for (const auto& menu : parsingResult.m_menus) for (const auto& menu : parsingResult.m_menus)
totalItemCount += menu->m_items.size(); totalItemCount += menu->m_items.size();
@ -182,7 +182,7 @@ namespace
return true; return true;
} }
void CreateMenuListAsset(MenuList& menuList, const std::vector<menuDef_t*>& menus) void CreateMenuListAsset(MenuList& menuList, const std::vector<menuDef_t*>& menus) const
{ {
menuList.menuCount = static_cast<int>(menus.size()); menuList.menuCount = static_cast<int>(menus.size());
@ -196,7 +196,8 @@ namespace
menuList.menus = nullptr; menuList.menus = nullptr;
} }
std::unique_ptr<menu::ParsingResult> ParseMenuFile(std::istream& stream, const std::string& menuFileName, const menu::MenuAssetZoneState& zoneState) std::unique_ptr<menu::ParsingResult>
ParseMenuFile(std::istream& stream, const std::string& menuFileName, const menu::MenuAssetZoneState& zoneState) const
{ {
menu::MenuFileReader reader(stream, menuFileName, menu::FeatureLevel::IW4, m_search_path); menu::MenuFileReader reader(stream, menuFileName, menu::FeatureLevel::IW4, m_search_path);

View File

@ -43,7 +43,7 @@ namespace
zs.zfree = Z_NULL; zs.zfree = Z_NULL;
zs.opaque = Z_NULL; zs.opaque = Z_NULL;
zs.avail_in = static_cast<uInt>(file.m_length); zs.avail_in = static_cast<uInt>(file.m_length);
zs.avail_out = compressionBufferSize; zs.avail_out = static_cast<unsigned>(compressionBufferSize);
zs.next_in = reinterpret_cast<const Bytef*>(uncompressedBuffer.get()); zs.next_in = reinterpret_cast<const Bytef*>(uncompressedBuffer.get());
zs.next_out = reinterpret_cast<Bytef*>(compressedBuffer); zs.next_out = reinterpret_cast<Bytef*>(compressedBuffer);

View File

@ -38,38 +38,38 @@ namespace
} }
private: private:
StructuredDataType ConvertType(CommonStructuredDataType inputType) static StructuredDataType ConvertType(const CommonStructuredDataType inputType)
{ {
switch (inputType.m_category) switch (inputType.m_category)
{ {
case CommonStructuredDataTypeCategory::INT: case CommonStructuredDataTypeCategory::INT:
return {DATA_INT, {0}}; return {.type = DATA_INT, .u = {}};
case CommonStructuredDataTypeCategory::BYTE: case CommonStructuredDataTypeCategory::BYTE:
return {DATA_BYTE, {0}}; return {.type = DATA_BYTE, .u = {}};
case CommonStructuredDataTypeCategory::BOOL: case CommonStructuredDataTypeCategory::BOOL:
return {DATA_BOOL, {0}}; return {.type = DATA_BOOL, .u = {}};
case CommonStructuredDataTypeCategory::FLOAT: case CommonStructuredDataTypeCategory::FLOAT:
return {DATA_FLOAT, {0}}; return {.type = DATA_FLOAT, .u = {}};
case CommonStructuredDataTypeCategory::SHORT: case CommonStructuredDataTypeCategory::SHORT:
return {DATA_SHORT, {0}}; return {.type = DATA_SHORT, .u = {}};
case CommonStructuredDataTypeCategory::STRING: case CommonStructuredDataTypeCategory::STRING:
return {DATA_STRING, {static_cast<unsigned>(inputType.m_info.string_length)}}; return {.type = DATA_STRING, .u = {static_cast<unsigned>(inputType.m_info.string_length)}};
case CommonStructuredDataTypeCategory::ENUM: case CommonStructuredDataTypeCategory::ENUM:
return {DATA_ENUM, {static_cast<unsigned>(inputType.m_info.type_index)}}; return {.type = DATA_ENUM, .u = {static_cast<unsigned>(inputType.m_info.type_index)}};
case CommonStructuredDataTypeCategory::STRUCT: case CommonStructuredDataTypeCategory::STRUCT:
return {DATA_STRUCT, {static_cast<unsigned>(inputType.m_info.type_index)}}; return {.type = DATA_STRUCT, .u = {static_cast<unsigned>(inputType.m_info.type_index)}};
case CommonStructuredDataTypeCategory::INDEXED_ARRAY: case CommonStructuredDataTypeCategory::INDEXED_ARRAY:
return {DATA_INDEXED_ARRAY, {static_cast<unsigned>(inputType.m_info.type_index)}}; return {.type = DATA_INDEXED_ARRAY, .u = {static_cast<unsigned>(inputType.m_info.type_index)}};
case CommonStructuredDataTypeCategory::ENUM_ARRAY: case CommonStructuredDataTypeCategory::ENUM_ARRAY:
return {DATA_ENUM_ARRAY, {static_cast<unsigned>(inputType.m_info.type_index)}}; return {.type = DATA_ENUM_ARRAY, .u = {static_cast<unsigned>(inputType.m_info.type_index)}};
case CommonStructuredDataTypeCategory::UNKNOWN: case CommonStructuredDataTypeCategory::UNKNOWN:
default: default:
assert(false); assert(false);
return {DATA_INT, {0}}; return {.type = DATA_INT, .u = {0}};
} }
} }
void ConvertEnum(CommonStructuredDataEnum& inputEnum, StructuredDataEnum& outputEnum) void ConvertEnum(CommonStructuredDataEnum& inputEnum, StructuredDataEnum& outputEnum) const
{ {
outputEnum.entryCount = static_cast<int>(inputEnum.m_entries.size()); outputEnum.entryCount = static_cast<int>(inputEnum.m_entries.size());
if (inputEnum.m_reserved_entry_count <= 0) if (inputEnum.m_reserved_entry_count <= 0)
@ -94,10 +94,10 @@ namespace
outputEnum.entries = nullptr; outputEnum.entries = nullptr;
} }
void ConvertStruct(CommonStructuredDataStruct& inputStruct, StructuredDataStruct& outputStruct) void ConvertStruct(CommonStructuredDataStruct& inputStruct, StructuredDataStruct& outputStruct) const
{ {
outputStruct.size = static_cast<int>(inputStruct.m_size_in_byte); outputStruct.size = static_cast<int>(inputStruct.m_size_in_byte);
outputStruct.bitOffset = inputStruct.m_bit_offset; outputStruct.bitOffset = static_cast<unsigned>(inputStruct.m_bit_offset);
outputStruct.propertyCount = static_cast<int>(inputStruct.m_properties.size()); outputStruct.propertyCount = static_cast<int>(inputStruct.m_properties.size());
inputStruct.SortPropertiesByName(); inputStruct.SortPropertiesByName();
@ -115,34 +115,34 @@ namespace
if (outputProperty.type.type != DATA_BOOL) if (outputProperty.type.type != DATA_BOOL)
{ {
assert(inputProperty.m_offset_in_bits % 8 == 0); assert(inputProperty.m_offset_in_bits % 8 == 0);
outputProperty.offset = inputProperty.m_offset_in_bits / 8; outputProperty.offset = static_cast<unsigned>(inputProperty.m_offset_in_bits / 8uz);
} }
else else
outputProperty.offset = inputProperty.m_offset_in_bits; outputProperty.offset = static_cast<unsigned>(inputProperty.m_offset_in_bits);
} }
} }
else else
outputStruct.properties = nullptr; outputStruct.properties = nullptr;
} }
void ConvertIndexedArray(const CommonStructuredDataIndexedArray& inputIndexedArray, StructuredDataIndexedArray& outputIndexedArray) static void ConvertIndexedArray(const CommonStructuredDataIndexedArray& inputIndexedArray, StructuredDataIndexedArray& outputIndexedArray)
{ {
outputIndexedArray.arraySize = static_cast<int>(inputIndexedArray.m_element_count); outputIndexedArray.arraySize = static_cast<int>(inputIndexedArray.m_element_count);
outputIndexedArray.elementType = ConvertType(inputIndexedArray.m_array_type); outputIndexedArray.elementType = ConvertType(inputIndexedArray.m_array_type);
outputIndexedArray.elementSize = utils::Align(inputIndexedArray.m_element_size_in_bits, 8uz) / 8uz; outputIndexedArray.elementSize = static_cast<unsigned>(utils::Align(inputIndexedArray.m_element_size_in_bits, 8uz) / 8uz);
} }
void ConvertEnumedArray(const CommonStructuredDataEnumedArray& inputEnumedArray, StructuredDataEnumedArray& outputEnumedArray) void ConvertEnumedArray(const CommonStructuredDataEnumedArray& inputEnumedArray, StructuredDataEnumedArray& outputEnumedArray)
{ {
outputEnumedArray.enumIndex = static_cast<int>(inputEnumedArray.m_enum_index); outputEnumedArray.enumIndex = static_cast<int>(inputEnumedArray.m_enum_index);
outputEnumedArray.elementType = ConvertType(inputEnumedArray.m_array_type); outputEnumedArray.elementType = ConvertType(inputEnumedArray.m_array_type);
outputEnumedArray.elementSize = utils::Align(inputEnumedArray.m_element_size_in_bits, 8uz) / 8uz; outputEnumedArray.elementSize = static_cast<unsigned>(utils::Align(inputEnumedArray.m_element_size_in_bits, 8uz) / 8uz);
} }
void ConvertDef(const CommonStructuredDataDef& inputDef, StructuredDataDef& outputDef) void ConvertDef(const CommonStructuredDataDef& inputDef, StructuredDataDef& outputDef)
{ {
outputDef.version = inputDef.m_version; outputDef.version = inputDef.m_version;
outputDef.formatChecksum = inputDef.m_checksum; outputDef.formatChecksum = static_cast<unsigned>(inputDef.m_checksum);
outputDef.enumCount = static_cast<int>(inputDef.m_enums.size()); outputDef.enumCount = static_cast<int>(inputDef.m_enums.size());
if (!inputDef.m_enums.empty()) if (!inputDef.m_enums.empty())
@ -185,7 +185,7 @@ namespace
outputDef.enumedArrays = nullptr; outputDef.enumedArrays = nullptr;
outputDef.rootType = ConvertType(inputDef.m_root_type); outputDef.rootType = ConvertType(inputDef.m_root_type);
outputDef.size = inputDef.m_size_in_byte; outputDef.size = static_cast<unsigned>(inputDef.m_size_in_byte);
} }
StructuredDataDefSet* ConvertSet(const std::string& assetName, const std::vector<std::unique_ptr<CommonStructuredDataDef>>& commonDefs) StructuredDataDefSet* ConvertSet(const std::string& assetName, const std::vector<std::unique_ptr<CommonStructuredDataDef>>& commonDefs)
@ -193,7 +193,7 @@ namespace
auto* set = m_memory.Alloc<StructuredDataDefSet>(); auto* set = m_memory.Alloc<StructuredDataDefSet>();
set->name = m_memory.Dup(assetName.c_str()); set->name = m_memory.Dup(assetName.c_str());
set->defCount = commonDefs.size(); set->defCount = static_cast<unsigned>(commonDefs.size());
set->defs = m_memory.Alloc<StructuredDataDef>(commonDefs.size()); set->defs = m_memory.Alloc<StructuredDataDef>(commonDefs.size());
for (auto defIndex = 0u; defIndex < commonDefs.size(); defIndex++) for (auto defIndex = 0u; defIndex < commonDefs.size(); defIndex++)

View File

@ -31,14 +31,14 @@ namespace
class LoadedTechnique class LoadedTechnique
{ {
public: public:
MaterialTechnique* m_technique;
std::vector<XAssetInfoGeneric*> m_dependencies;
LoadedTechnique(MaterialTechnique* technique, std::vector<XAssetInfoGeneric*> dependencies) LoadedTechnique(MaterialTechnique* technique, std::vector<XAssetInfoGeneric*> dependencies)
: m_technique(technique), : m_technique(technique),
m_dependencies(std::move(dependencies)) m_dependencies(std::move(dependencies))
{ {
} }
MaterialTechnique* m_technique;
std::vector<XAssetInfoGeneric*> m_dependencies;
}; };
class TechniqueZoneLoadingState final : public IZoneAssetCreationState class TechniqueZoneLoadingState final : public IZoneAssetCreationState
@ -46,8 +46,7 @@ namespace
public: public:
typedef const float (*literal_t)[4]; typedef const float (*literal_t)[4];
public: [[nodiscard]] const LoadedTechnique* FindLoadedTechnique(const std::string& techniqueName) const
_NODISCARD const LoadedTechnique* FindLoadedTechnique(const std::string& techniqueName) const
{ {
const auto loadedTechnique = m_loaded_techniques.find(techniqueName); const auto loadedTechnique = m_loaded_techniques.find(techniqueName);
if (loadedTechnique != m_loaded_techniques.end()) if (loadedTechnique != m_loaded_techniques.end())
@ -86,8 +85,6 @@ namespace
class ShaderInfoFromFileSystemCacheState final : public IZoneAssetCreationState class ShaderInfoFromFileSystemCacheState final : public IZoneAssetCreationState
{ {
std::unordered_map<std::string, std::unique_ptr<d3d9::ShaderInfo>> m_cached_shader_info;
public: public:
[[nodiscard]] const d3d9::ShaderInfo* LoadShaderInfoFromDisk(ISearchPath& searchPath, const std::string& fileName) [[nodiscard]] const d3d9::ShaderInfo* LoadShaderInfoFromDisk(ISearchPath& searchPath, const std::string& fileName)
{ {
@ -108,9 +105,9 @@ namespace
} }
const auto shaderData = std::make_unique<char[]>(shaderSize); const auto shaderData = std::make_unique<char[]>(shaderSize);
file.m_stream->read(shaderData.get(), shaderSize); file.m_stream->read(shaderData.get(), static_cast<std::streamsize>(shaderSize));
auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(reinterpret_cast<const uint32_t*>(shaderData.get()), shaderSize); auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(shaderData.get(), shaderSize);
if (!shaderInfo) if (!shaderInfo)
return nullptr; return nullptr;
@ -118,6 +115,9 @@ namespace
m_cached_shader_info.emplace(std::make_pair(fileName, std::move(shaderInfo))); m_cached_shader_info.emplace(std::make_pair(fileName, std::move(shaderInfo)));
return result; return result;
} }
private:
std::unordered_map<std::string, std::unique_ptr<d3d9::ShaderInfo>> m_cached_shader_info;
}; };
class TechniqueCreator final : public techset::ITechniqueDefinitionAcceptor class TechniqueCreator final : public techset::ITechniqueDefinitionAcceptor
@ -126,10 +126,13 @@ namespace
class PassShaderArgument class PassShaderArgument
{ {
public: public:
MaterialShaderArgument m_arg; explicit PassShaderArgument(const MaterialShaderArgument arg)
MaterialUpdateFrequency m_update_frequency; : m_arg(arg),
m_update_frequency(GetUpdateFrequencyForArg(arg))
{
}
static MaterialUpdateFrequency GetUpdateFrequencyForArg(MaterialShaderArgument arg) static MaterialUpdateFrequency GetUpdateFrequencyForArg(const MaterialShaderArgument arg)
{ {
switch (arg.type) switch (arg.type)
{ {
@ -160,15 +163,22 @@ namespace
} }
} }
explicit PassShaderArgument(const MaterialShaderArgument arg) MaterialShaderArgument m_arg;
: m_arg(arg), MaterialUpdateFrequency m_update_frequency;
m_update_frequency(GetUpdateFrequencyForArg(arg))
{
}
}; };
struct Pass struct Pass
{ {
Pass()
: m_vertex_shader(nullptr),
m_vertex_shader_info(nullptr),
m_pixel_shader(nullptr),
m_pixel_shader_info(nullptr),
m_vertex_decl{},
m_vertex_decl_asset(nullptr)
{
}
XAssetInfo<MaterialVertexShader>* m_vertex_shader; XAssetInfo<MaterialVertexShader>* m_vertex_shader;
const d3d9::ShaderInfo* m_vertex_shader_info; const d3d9::ShaderInfo* m_vertex_shader_info;
std::unique_ptr<d3d9::ShaderInfo> m_vertex_shader_info_unq; std::unique_ptr<d3d9::ShaderInfo> m_vertex_shader_info_unq;
@ -184,21 +194,8 @@ namespace
MaterialVertexDeclaration m_vertex_decl; MaterialVertexDeclaration m_vertex_decl;
XAssetInfo<MaterialVertexDeclaration>* m_vertex_decl_asset; XAssetInfo<MaterialVertexDeclaration>* m_vertex_decl_asset;
std::vector<PassShaderArgument> m_arguments; std::vector<PassShaderArgument> m_arguments;
Pass()
: m_vertex_shader(nullptr),
m_vertex_shader_info(nullptr),
m_pixel_shader(nullptr),
m_pixel_shader_info(nullptr),
m_vertex_decl{},
m_vertex_decl_asset(nullptr)
{
}
}; };
std::vector<Pass> m_passes;
std::vector<XAssetInfoGeneric*> m_dependencies;
TechniqueCreator( TechniqueCreator(
const std::string& techniqueName, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context, ITechsetCreator* techsetCreator) const std::string& techniqueName, ISearchPath& searchPath, MemoryManager& memory, AssetCreationContext& context, ITechsetCreator* techsetCreator)
: m_technique_name(techniqueName), : m_technique_name(techniqueName),
@ -217,10 +214,11 @@ namespace
m_passes.emplace_back(); m_passes.emplace_back();
} }
static size_t RegisterCountPerElement(const d3d9::ShaderConstant& constant) static unsigned RegisterCountPerElement(const d3d9::ShaderConstant& constant)
{ {
const auto valuesPerRegister = const auto valuesPerRegister =
constant.m_register_set == d3d9::RegisterSet::BOOL || constant.m_register_set == d3d9::RegisterSet::SAMPLER ? 1u : 4u; constant.m_register_set == d3d9::RegisterSet::BOOL || constant.m_register_set == d3d9::RegisterSet::SAMPLER ? 1u : 4u;
return utils::Align(constant.m_type_columns * constant.m_type_rows, valuesPerRegister) / valuesPerRegister; return utils::Align(constant.m_type_columns * constant.m_type_rows, valuesPerRegister) / valuesPerRegister;
} }
@ -243,7 +241,7 @@ namespace
if (shaderType == techset::ShaderSelector::VERTEX_SHADER && isSamplerArgument) if (shaderType == techset::ShaderSelector::VERTEX_SHADER && isSamplerArgument)
return false; return false;
MaterialShaderArgument argument{}; MaterialShaderArgument argument;
argument.dest = static_cast<uint16_t>(shaderArgument.m_register_index + registerOffset); argument.dest = static_cast<uint16_t>(shaderArgument.m_register_index + registerOffset);
unsigned arrayCount; unsigned arrayCount;
@ -258,7 +256,7 @@ namespace
return false; return false;
argument.type = MTL_ARG_CODE_PIXEL_SAMPLER; argument.type = MTL_ARG_CODE_PIXEL_SAMPLER;
argument.u.codeSampler = samplerSource->source + elementOffset; argument.u.codeSampler = samplerSource->source + static_cast<unsigned>(elementOffset);
arrayCount = static_cast<unsigned>(samplerSource->arrayCount); arrayCount = static_cast<unsigned>(samplerSource->arrayCount);
} }
@ -304,13 +302,12 @@ namespace
{ {
if (!AutoCreateShaderArgument(techset::ShaderSelector::VERTEX_SHADER, argument, elementIndex, registerIndex)) if (!AutoCreateShaderArgument(techset::ShaderSelector::VERTEX_SHADER, argument, elementIndex, registerIndex))
{ {
std::ostringstream ss; std::string elementIndexStr;
ss << "Unassigned vertex shader \"" << pass.m_vertex_shader->m_name << "\" arg: " << argument.m_name;
if (argument.m_type_elements > 1) if (argument.m_type_elements > 1)
ss << '[' << elementIndex << ']'; elementIndexStr = std::format("[{}]", elementIndex);
errorMessage = ss.str(); errorMessage =
std::format("Unassigned vertex shader \"{}\" arg: {}{}", pass.m_vertex_shader->m_name, argument.m_name, elementIndexStr);
return false; return false;
} }
} }
@ -572,11 +569,11 @@ namespace
return foundSource; return foundSource;
} }
bool FindShaderArgument(const d3d9::ShaderInfo& shaderInfo, static bool FindShaderArgument(const d3d9::ShaderInfo& shaderInfo,
const techset::ShaderArgument& argument, const techset::ShaderArgument& argument,
size_t& constantIndex, size_t& constantIndex,
size_t& registerOffset, size_t& registerOffset,
std::string& errorMessage) const std::string& errorMessage)
{ {
const auto matchingShaderConstant = std::ranges::find_if(shaderInfo.m_constants, const auto matchingShaderConstant = std::ranges::find_if(shaderInfo.m_constants,
[argument](const d3d9::ShaderConstant& constant) [argument](const d3d9::ShaderConstant& constant)
@ -854,14 +851,14 @@ namespace
} }
bool AcceptShaderLiteralArgument(const techset::ShaderSelector shader, bool AcceptShaderLiteralArgument(const techset::ShaderSelector shader,
techset::ShaderArgument shaderArgument, const techset::ShaderArgument shaderArgument,
techset::ShaderArgumentLiteralSource source, const techset::ShaderArgumentLiteralSource source,
std::string& errorMessage) override std::string& errorMessage) override
{ {
assert(!m_passes.empty()); assert(!m_passes.empty());
auto& pass = m_passes.at(m_passes.size() - 1); auto& pass = m_passes.at(m_passes.size() - 1);
MaterialShaderArgument argument{}; MaterialShaderArgument argument;
const d3d9::ShaderInfo* shaderInfo; const d3d9::ShaderInfo* shaderInfo;
if (shader == techset::ShaderSelector::VERTEX_SHADER) if (shader == techset::ShaderSelector::VERTEX_SHADER)
@ -913,14 +910,14 @@ namespace
} }
bool AcceptShaderMaterialArgument(const techset::ShaderSelector shader, bool AcceptShaderMaterialArgument(const techset::ShaderSelector shader,
techset::ShaderArgument shaderArgument, const techset::ShaderArgument shaderArgument,
const techset::ShaderArgumentMaterialSource source, const techset::ShaderArgumentMaterialSource source,
std::string& errorMessage) override std::string& errorMessage) override
{ {
assert(!m_passes.empty()); assert(!m_passes.empty());
auto& pass = m_passes.at(m_passes.size() - 1); auto& pass = m_passes.at(m_passes.size() - 1);
MaterialShaderArgument argument{}; MaterialShaderArgument argument;
const d3d9::ShaderInfo* shaderInfo; const d3d9::ShaderInfo* shaderInfo;
if (shader == techset::ShaderSelector::VERTEX_SHADER) if (shader == techset::ShaderSelector::VERTEX_SHADER)
@ -1016,6 +1013,8 @@ namespace
return true; return true;
} }
std::vector<Pass> m_passes;
private: private:
const std::string& m_technique_name; const std::string& m_technique_name;
ISearchPath& m_search_path; ISearchPath& m_search_path;

View File

@ -1,8 +1,8 @@
#include "JsonMaterialLoader.h" #include "JsonMaterialLoader.h"
#include "Base64.h"
#include "Game/IW5/CommonIW5.h" #include "Game/IW5/CommonIW5.h"
#include "Game/IW5/Material/JsonMaterial.h" #include "Game/IW5/Material/JsonMaterial.h"
#include "Impl/Base64.h"
#include <format> #include <format>
#include <iostream> #include <iostream>

View File

@ -83,7 +83,7 @@ namespace
menu::MenuAssetZoneState& zoneState, menu::MenuAssetZoneState& zoneState,
MenuConversionZoneState& conversionState, MenuConversionZoneState& conversionState,
std::vector<menuDef_t*>& menus, std::vector<menuDef_t*>& menus,
AssetRegistration<AssetMenuList>& registration) AssetRegistration<AssetMenuList>& registration) const
{ {
const auto alreadyLoadedMenuFile = conversionState.m_menus_by_filename.find(menuFilePath); const auto alreadyLoadedMenuFile = conversionState.m_menus_by_filename.find(menuFilePath);
if (alreadyLoadedMenuFile != conversionState.m_menus_by_filename.end()) if (alreadyLoadedMenuFile != conversionState.m_menus_by_filename.end())
@ -125,14 +125,14 @@ namespace
menu::MenuAssetZoneState& zoneState, menu::MenuAssetZoneState& zoneState,
MenuConversionZoneState& conversionState, MenuConversionZoneState& conversionState,
std::vector<menuDef_t*>& menus, std::vector<menuDef_t*>& menus,
AssetRegistration<AssetMenuList>& registration) AssetRegistration<AssetMenuList>& registration) const
{ {
const auto menuCount = parsingResult.m_menus.size(); const auto menuCount = parsingResult.m_menus.size();
const auto functionCount = parsingResult.m_functions.size(); const auto functionCount = parsingResult.m_functions.size();
const auto menuLoadCount = parsingResult.m_menus_to_load.size(); const auto menuLoadCount = parsingResult.m_menus_to_load.size();
auto totalItemCount = 0u; auto totalItemCount = 0u;
for (const auto& menu : parsingResult.m_menus) for (const auto& menu : parsingResult.m_menus)
totalItemCount += menu->m_items.size(); totalItemCount += static_cast<unsigned>(menu->m_items.size());
std::cout << std::format("Successfully read menu file \"{}\" ({} loads, {} menus, {} functions, {} items)\n", std::cout << std::format("Successfully read menu file \"{}\" ({} loads, {} menus, {} functions, {} items)\n",
fileName, fileName,
@ -152,7 +152,7 @@ namespace
// Convert all menus and add them as assets // Convert all menus and add them as assets
for (auto& commonMenu : parsingResult.m_menus) for (auto& commonMenu : parsingResult.m_menus)
{ {
auto converter = IMenuConverter::Create(ObjLoading::Configuration.MenuNoOptimization, m_search_path, m_memory, context); const auto converter = IMenuConverter::Create(ObjLoading::Configuration.MenuNoOptimization, m_search_path, m_memory, context);
auto* menuAsset = m_memory.Alloc<menuDef_t>(); auto* menuAsset = m_memory.Alloc<menuDef_t>();
AssetRegistration<AssetMenu> menuRegistration(commonMenu->m_name, menuAsset); AssetRegistration<AssetMenu> menuRegistration(commonMenu->m_name, menuAsset);
@ -182,7 +182,7 @@ namespace
return true; return true;
} }
void CreateMenuListAsset(MenuList& menuList, const std::vector<menuDef_t*>& menus) void CreateMenuListAsset(MenuList& menuList, const std::vector<menuDef_t*>& menus) const
{ {
menuList.menuCount = static_cast<int>(menus.size()); menuList.menuCount = static_cast<int>(menus.size());
@ -196,7 +196,8 @@ namespace
menuList.menus = nullptr; menuList.menus = nullptr;
} }
std::unique_ptr<menu::ParsingResult> ParseMenuFile(std::istream& stream, const std::string& menuFileName, const menu::MenuAssetZoneState& zoneState) std::unique_ptr<menu::ParsingResult>
ParseMenuFile(std::istream& stream, const std::string& menuFileName, const menu::MenuAssetZoneState& zoneState) const
{ {
menu::MenuFileReader reader(stream, menuFileName, menu::FeatureLevel::IW5, m_search_path); menu::MenuFileReader reader(stream, menuFileName, menu::FeatureLevel::IW5, m_search_path);

View File

@ -44,7 +44,7 @@ namespace
zs.zfree = Z_NULL; zs.zfree = Z_NULL;
zs.opaque = Z_NULL; zs.opaque = Z_NULL;
zs.avail_in = static_cast<uInt>(file.m_length); zs.avail_in = static_cast<uInt>(file.m_length);
zs.avail_out = compressionBufferSize; zs.avail_out = static_cast<unsigned>(compressionBufferSize);
zs.next_in = reinterpret_cast<const Bytef*>(uncompressedBuffer.get()); zs.next_in = reinterpret_cast<const Bytef*>(uncompressedBuffer.get());
zs.next_out = reinterpret_cast<Bytef*>(compressedBuffer); zs.next_out = reinterpret_cast<Bytef*>(compressedBuffer);

View File

@ -57,7 +57,7 @@ namespace
return AssetCreationResult::Failure(); return AssetCreationResult::Failure();
} }
if (offset + (scriptFile->compressedLen + scriptFile->bytecodeLen) > file.m_length) if (offset + static_cast<size_t>(scriptFile->compressedLen + scriptFile->bytecodeLen) > static_cast<size_t>(file.m_length))
{ {
std::cerr << std::format("Error: Specified length in {} GSC BIN structure exceeds the actual file size\n", assetName); std::cerr << std::format("Error: Specified length in {} GSC BIN structure exceeds the actual file size\n", assetName);
return AssetCreationResult::Failure(); return AssetCreationResult::Failure();

View File

@ -232,7 +232,7 @@ namespace
} }
m_weapon.weapCompleteDef.animOverrides = animOverrides; m_weapon.weapCompleteDef.animOverrides = animOverrides;
m_weapon.weapCompleteDef.numAnimOverrides = valueArray.size(); m_weapon.weapCompleteDef.numAnimOverrides = static_cast<unsigned>(valueArray.size());
return true; return true;
} }
@ -267,7 +267,7 @@ namespace
} }
m_weapon.weapCompleteDef.soundOverrides = soundOverrides; m_weapon.weapCompleteDef.soundOverrides = soundOverrides;
m_weapon.weapCompleteDef.numSoundOverrides = valueArray.size(); m_weapon.weapCompleteDef.numSoundOverrides = static_cast<unsigned>(valueArray.size());
return true; return true;
} }
@ -305,7 +305,7 @@ namespace
} }
m_weapon.weapCompleteDef.fxOverrides = fxOverrides; m_weapon.weapCompleteDef.fxOverrides = fxOverrides;
m_weapon.weapCompleteDef.numFxOverrides = valueArray.size(); m_weapon.weapCompleteDef.numFxOverrides = static_cast<unsigned>(valueArray.size());
return true; return true;
} }
@ -339,7 +339,7 @@ namespace
} }
m_weapon.weapCompleteDef.reloadOverrides = reloadOverrides; m_weapon.weapCompleteDef.reloadOverrides = reloadOverrides;
m_weapon.weapCompleteDef.numReloadStateTimerOverrides = valueArray.size(); m_weapon.weapCompleteDef.numReloadStateTimerOverrides = static_cast<unsigned>(valueArray.size());
return true; return true;
} }
@ -392,7 +392,7 @@ namespace
m_weapon.weapCompleteDef.notetrackOverrides = m_memory.Alloc<NoteTrackToSoundEntry>(overrideVector.size()); m_weapon.weapCompleteDef.notetrackOverrides = m_memory.Alloc<NoteTrackToSoundEntry>(overrideVector.size());
memcpy(m_weapon.weapCompleteDef.notetrackOverrides, overrideVector.data(), sizeof(NoteTrackToSoundEntry) * overrideVector.size()); memcpy(m_weapon.weapCompleteDef.notetrackOverrides, overrideVector.data(), sizeof(NoteTrackToSoundEntry) * overrideVector.size());
m_weapon.weapCompleteDef.numNotetrackOverrides = overrideVector.size(); m_weapon.weapCompleteDef.numNotetrackOverrides = static_cast<unsigned>(overrideVector.size());
return true; return true;
} }
@ -437,7 +437,7 @@ namespace
return false; return false;
} }
void ParseAnim(const std::string& value, const char*& animName) void ParseAnim(const std::string& value, const char*& animName) const
{ {
if (value == "none") if (value == "none")
{ {
@ -449,7 +449,7 @@ namespace
m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReference<AssetXAnim>(value)); m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReference<AssetXAnim>(value));
} }
void ParseSoundAlias(const std::string& value, SndAliasCustom& soundAlias) void ParseSoundAlias(const std::string& value, SndAliasCustom& soundAlias) const
{ {
if (value == "none") if (value == "none")
{ {
@ -462,7 +462,7 @@ namespace
m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReference<AssetSound>(value)); m_registration.AddIndirectAssetReference(m_context.LoadIndirectAssetReference<AssetSound>(value));
} }
bool ParseFxEffectDef(const std::string& value, FxEffectDef*& fx) bool ParseFxEffectDef(const std::string& value, FxEffectDef*& fx) const
{ {
if (value == "none") if (value == "none")
{ {
@ -542,7 +542,7 @@ namespace
return true; return true;
} }
void ParseScriptString(const std::string& value, ScriptString& out) void ParseScriptString(const std::string& value, ScriptString& out) const
{ {
out = m_zone_script_strings.AddOrGetScriptString(value); out = m_zone_script_strings.AddOrGetScriptString(value);
m_registration.AddScriptString(out); m_registration.AddScriptString(out);
@ -863,7 +863,7 @@ InfoStringLoaderWeapon::InfoStringLoaderWeapon(MemoryManager& memory, ISearchPat
{ {
} }
AssetCreationResult InfoStringLoaderWeapon::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) AssetCreationResult InfoStringLoaderWeapon::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) const
{ {
auto* weaponFullDef = m_memory.Alloc<WeaponFullDef>(); auto* weaponFullDef = m_memory.Alloc<WeaponFullDef>();

View File

@ -11,7 +11,7 @@ namespace IW5
public: public:
InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) const;
private: private:
MemoryManager& m_memory; MemoryManager& m_memory;

View File

@ -40,7 +40,7 @@ namespace
} }
private: private:
AssetCreationResult LoadGsc(const SearchPathOpenFile& file, const std::string& assetName, AssetCreationContext& context) AssetCreationResult LoadGsc(const SearchPathOpenFile& file, const std::string& assetName, AssetCreationContext& context) const
{ {
const auto uncompressedBuffer = std::make_unique<char[]>(static_cast<size_t>(file.m_length + 1)); const auto uncompressedBuffer = std::make_unique<char[]>(static_cast<size_t>(file.m_length + 1));
@ -58,7 +58,7 @@ namespace
zs.zfree = Z_NULL; zs.zfree = Z_NULL;
zs.opaque = Z_NULL; zs.opaque = Z_NULL;
zs.avail_in = static_cast<uInt>(file.m_length + 1); zs.avail_in = static_cast<uInt>(file.m_length + 1);
zs.avail_out = compressionBufferSize; zs.avail_out = static_cast<unsigned>(compressionBufferSize);
zs.next_in = reinterpret_cast<const Bytef*>(uncompressedBuffer.get()); zs.next_in = reinterpret_cast<const Bytef*>(uncompressedBuffer.get());
zs.next_out = reinterpret_cast<Bytef*>(&compressedBuffer[sizeof(uint32_t) + sizeof(uint32_t)]); zs.next_out = reinterpret_cast<Bytef*>(&compressedBuffer[sizeof(uint32_t) + sizeof(uint32_t)]);
@ -79,7 +79,7 @@ namespace
const auto compressedSize = compressionBufferSize - zs.avail_out; const auto compressedSize = compressionBufferSize - zs.avail_out;
reinterpret_cast<uint32_t*>(compressedBuffer)[0] = static_cast<uint32_t>(file.m_length + 1); // outLen reinterpret_cast<uint32_t*>(compressedBuffer)[0] = static_cast<uint32_t>(file.m_length + 1); // outLen
reinterpret_cast<uint32_t*>(compressedBuffer)[1] = compressedSize; // inLen reinterpret_cast<uint32_t*>(compressedBuffer)[1] = static_cast<uint32_t>(compressedSize); // inLen
auto* rawFile = m_memory.Alloc<RawFile>(); auto* rawFile = m_memory.Alloc<RawFile>();
rawFile->name = m_memory.Dup(assetName.c_str()); rawFile->name = m_memory.Dup(assetName.c_str());
@ -91,7 +91,7 @@ namespace
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile)); return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile));
} }
AssetCreationResult LoadDefault(const SearchPathOpenFile& file, const std::string& assetName, AssetCreationContext& context) AssetCreationResult LoadDefault(const SearchPathOpenFile& file, const std::string& assetName, AssetCreationContext& context) const
{ {
auto* rawFile = m_memory.Alloc<RawFile>(); auto* rawFile = m_memory.Alloc<RawFile>();
rawFile->name = m_memory.Dup(assetName.c_str()); rawFile->name = m_memory.Dup(assetName.c_str());

View File

@ -5,9 +5,7 @@
#include "Game/T6/T6.h" #include "Game/T6/T6.h"
#include <algorithm> #include <algorithm>
#include <cstring>
#include <format> #include <format>
#include <sstream>
using namespace T6; using namespace T6;
@ -25,8 +23,8 @@ namespace
constexpr unsigned ROW_ALIAS_NAME = 2; constexpr unsigned ROW_ALIAS_NAME = 2;
constexpr unsigned ROW_ALIAS_BUTTON = 3; constexpr unsigned ROW_ALIAS_BUTTON = 3;
constexpr const char* VALUE_TYPE_ICON = "icon"; constexpr auto VALUE_TYPE_ICON = "icon";
constexpr const char* VALUE_TYPE_ALIAS = "alias"; constexpr auto VALUE_TYPE_ALIAS = "alias";
constexpr unsigned COL_COUNT_ICON = 7; constexpr unsigned COL_COUNT_ICON = 7;
constexpr unsigned COL_COUNT_ALIAS = 4; constexpr unsigned COL_COUNT_ALIAS = 4;
@ -125,8 +123,8 @@ namespace
} }
} }
fontIcon->numEntries = entries.size(); fontIcon->numEntries = static_cast<unsigned>(entries.size());
fontIcon->numAliasEntries = aliases.size(); fontIcon->numAliasEntries = static_cast<unsigned>(aliases.size());
if (fontIcon->numEntries > 0) if (fontIcon->numEntries > 0)
{ {
@ -159,7 +157,7 @@ namespace
{ {
for (auto& cell : row) for (auto& cell : row)
{ {
for (auto c : cell) for (const auto c : cell)
{ {
if (isspace(c)) if (isspace(c))
continue; continue;
@ -220,7 +218,7 @@ namespace
const std::string& assetName, const std::string& assetName,
const unsigned rowIndex, const unsigned rowIndex,
AssetCreationContext& context, AssetCreationContext& context,
AssetRegistration<AssetFontIcon>& registration) AssetRegistration<AssetFontIcon>& registration) const
{ {
if (row.size() < COL_COUNT_ICON) if (row.size() < COL_COUNT_ICON)
{ {
@ -246,6 +244,7 @@ namespace
std::cerr << std::format("{} Failed to load material \"{}\"\n", ErrorPrefix(assetName, rowIndex), row[ROW_ICON_MATERIAL]); std::cerr << std::format("{} Failed to load material \"{}\"\n", ErrorPrefix(assetName, rowIndex), row[ROW_ICON_MATERIAL]);
return false; return false;
} }
registration.AddDependency(materialDependency);
icon.fontIconMaterialHandle = materialDependency->Asset(); icon.fontIconMaterialHandle = materialDependency->Asset();
icon.fontIconName.string = m_memory.Dup(row[ROW_ICON_NAME].c_str()); icon.fontIconName.string = m_memory.Dup(row[ROW_ICON_NAME].c_str());
@ -254,7 +253,7 @@ namespace
return true; return true;
} }
bool ReadAliasRow( static bool ReadAliasRow(
const std::vector<std::string>& row, FontIconAlias& alias, const std::string& assetName, const unsigned rowIndex, AssetCreationContext& context) const std::vector<std::string>& row, FontIconAlias& alias, const std::string& assetName, const unsigned rowIndex, AssetCreationContext& context)
{ {
if (row.size() < COL_COUNT_ALIAS) if (row.size() < COL_COUNT_ALIAS)

View File

@ -32,8 +32,8 @@ namespace
const auto fileSize = static_cast<size_t>(file.m_length); const auto fileSize = static_cast<size_t>(file.m_length);
const auto fileData = std::make_unique<char[]>(fileSize); const auto fileData = std::make_unique<char[]>(fileSize);
file.m_stream->read(fileData.get(), fileSize); file.m_stream->read(fileData.get(), static_cast<std::streamsize>(fileSize));
const auto dataHash = static_cast<unsigned>(crc32(0u, reinterpret_cast<const Bytef*>(fileData.get()), fileSize)); const auto dataHash = static_cast<unsigned>(crc32(0u, reinterpret_cast<const Bytef*>(fileData.get()), static_cast<unsigned>(fileSize)));
std::istringstream ss(std::string(fileData.get(), fileSize)); std::istringstream ss(std::string(fileData.get(), fileSize));
const auto texture = iwi::LoadIwi(ss); const auto texture = iwi::LoadIwi(ss);

View File

@ -58,7 +58,7 @@ namespace
zs.zfree = Z_NULL; zs.zfree = Z_NULL;
zs.opaque = Z_NULL; zs.opaque = Z_NULL;
zs.avail_in = static_cast<uInt>(file.m_length); zs.avail_in = static_cast<uInt>(file.m_length);
zs.avail_out = compressionBufferSize; zs.avail_out = static_cast<unsigned>(compressionBufferSize);
zs.next_in = reinterpret_cast<const Bytef*>(uncompressedBuffer.get()); zs.next_in = reinterpret_cast<const Bytef*>(uncompressedBuffer.get());
zs.next_out = reinterpret_cast<Bytef*>(&compressedBuffer[sizeof(uint32_t)]); zs.next_out = reinterpret_cast<Bytef*>(&compressedBuffer[sizeof(uint32_t)]);
@ -92,7 +92,7 @@ namespace
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile)); return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile));
} }
AssetCreationResult LoadDefault(const SearchPathOpenFile& file, const std::string& assetName, AssetCreationContext& context) AssetCreationResult LoadDefault(const SearchPathOpenFile& file, const std::string& assetName, AssetCreationContext& context) const
{ {
auto* rawFile = m_memory.Alloc<RawFile>(); auto* rawFile = m_memory.Alloc<RawFile>();
rawFile->name = m_memory.Dup(assetName.c_str()); rawFile->name = m_memory.Dup(assetName.c_str());

View File

@ -679,7 +679,7 @@ namespace
if (!aliasList.empty()) if (!aliasList.empty())
aliasLists.emplace_back(CreateAliasList(aliasList, memory)); aliasLists.emplace_back(CreateAliasList(aliasList, memory));
sndBank->aliasCount = aliasLists.size(); sndBank->aliasCount = static_cast<unsigned>(aliasLists.size());
if (sndBank->aliasCount) if (sndBank->aliasCount)
{ {
sndBank->alias = memory.Alloc<SndAliasList>(sndBank->aliasCount); sndBank->alias = memory.Alloc<SndAliasList>(sndBank->aliasCount);
@ -702,7 +702,7 @@ namespace
const auto idx = sndBank->alias[i].id % sndBank->aliasCount; const auto idx = sndBank->alias[i].id % sndBank->aliasCount;
if (sndBank->aliasIndex[idx].value == std::numeric_limits<unsigned short>::max()) if (sndBank->aliasIndex[idx].value == std::numeric_limits<unsigned short>::max())
{ {
sndBank->aliasIndex[idx].value = i; sndBank->aliasIndex[idx].value = static_cast<unsigned short>(i);
sndBank->aliasIndex[idx].next = std::numeric_limits<unsigned short>::max(); sndBank->aliasIndex[idx].next = std::numeric_limits<unsigned short>::max();
setAliasIndexList[i] = true; setAliasIndexList[i] = true;
} }
@ -720,14 +720,14 @@ namespace
} }
auto offset = 1u; auto offset = 1u;
auto freeIdx = std::numeric_limits<unsigned short>::max(); unsigned short freeIdx;
while (true) while (true)
{ {
freeIdx = (idx + offset) % sndBank->aliasCount; freeIdx = static_cast<unsigned short>((idx + offset) % sndBank->aliasCount);
if (sndBank->aliasIndex[freeIdx].value == std::numeric_limits<unsigned short>::max()) if (sndBank->aliasIndex[freeIdx].value == std::numeric_limits<unsigned short>::max())
break; break;
freeIdx = (idx + sndBank->aliasCount - offset) % sndBank->aliasCount; freeIdx = static_cast<unsigned short>((idx + sndBank->aliasCount - offset) % sndBank->aliasCount);
if (sndBank->aliasIndex[freeIdx].value == std::numeric_limits<unsigned short>::max()) if (sndBank->aliasIndex[freeIdx].value == std::numeric_limits<unsigned short>::max())
break; break;
@ -745,7 +745,7 @@ namespace
} }
sndBank->aliasIndex[idx].next = freeIdx; sndBank->aliasIndex[idx].next = freeIdx;
sndBank->aliasIndex[freeIdx].value = i; sndBank->aliasIndex[freeIdx].value = static_cast<unsigned short>(i);
sndBank->aliasIndex[freeIdx].next = std::numeric_limits<unsigned short>::max(); sndBank->aliasIndex[freeIdx].next = std::numeric_limits<unsigned short>::max();
setAliasIndexList[i] = true; setAliasIndexList[i] = true;
} }
@ -849,7 +849,7 @@ namespace
radverbs.emplace_back(radverb); radverbs.emplace_back(radverb);
} }
sndBank->radverbCount = radverbs.size(); sndBank->radverbCount = static_cast<unsigned>(radverbs.size());
if (sndBank->radverbCount) if (sndBank->radverbCount)
{ {
sndBank->radverbs = memory.Alloc<SndRadverb>(sndBank->radverbCount); sndBank->radverbs = memory.Alloc<SndRadverb>(sndBank->radverbCount);
@ -912,7 +912,7 @@ namespace
for (auto& valueJson : duckJson["values"]) for (auto& valueJson : duckJson["values"])
{ {
auto index = GetValueIndex(valueJson["duckGroup"].get<std::string>(), SOUND_DUCK_GROUPS, std::extent_v<decltype(SOUND_DUCK_GROUPS)>); const auto index = GetValueIndex(valueJson["duckGroup"].get<std::string>(), SOUND_DUCK_GROUPS, std::extent_v<decltype(SOUND_DUCK_GROUPS)>);
duck.attenuation[index] = valueJson["attenuation"].get<float>(); duck.attenuation[index] = valueJson["attenuation"].get<float>();
duck.filter[index] = valueJson["filter"].get<float>(); duck.filter[index] = valueJson["filter"].get<float>();
@ -921,7 +921,7 @@ namespace
ducks.emplace_back(duck); ducks.emplace_back(duck);
} }
sndBank->duckCount = ducks.size(); sndBank->duckCount = static_cast<unsigned>(ducks.size());
if (sndBank->duckCount) if (sndBank->duckCount)
{ {
sndBank->ducks = memory.Alloc<SndDuck>(sndBank->duckCount); sndBank->ducks = memory.Alloc<SndDuck>(sndBank->duckCount);
@ -1046,7 +1046,7 @@ namespace
if (result) if (result)
{ {
sndBank->loadedAssets.dataSize = dataSize; sndBank->loadedAssets.dataSize = static_cast<unsigned>(dataSize);
sndBank->loadedAssets.data = m_memory.Alloc<SndChar2048>(dataSize); sndBank->loadedAssets.data = m_memory.Alloc<SndChar2048>(dataSize);
} }
else else

View File

@ -574,12 +574,12 @@ namespace
{ {
if (lastSibling == nullptr) if (lastSibling == nullptr)
{ {
attachmentUnique.childLink = attachmentUniqueIndex; attachmentUnique.childLink = static_cast<int>(attachmentUniqueIndex);
lastSibling = weapon.attachmentUniques[attachmentUniqueIndex]; lastSibling = weapon.attachmentUniques[attachmentUniqueIndex];
} }
else else
{ {
lastSibling->siblingLink = attachmentUniqueIndex; lastSibling->siblingLink = static_cast<int>(attachmentUniqueIndex);
lastSibling = weapon.attachmentUniques[attachmentUniqueIndex]; lastSibling = weapon.attachmentUniques[attachmentUniqueIndex];
} }
} }

View File

@ -151,7 +151,7 @@ namespace
{ {
if (!jWeaponCamoMaterialSet.materials.empty()) if (!jWeaponCamoMaterialSet.materials.empty())
{ {
weaponCamoMaterialSet.numMaterials = jWeaponCamoMaterialSet.materials.size(); weaponCamoMaterialSet.numMaterials = static_cast<unsigned>(jWeaponCamoMaterialSet.materials.size());
weaponCamoMaterialSet.materials = m_memory.Alloc<WeaponCamoMaterial>(weaponCamoMaterialSet.numMaterials); weaponCamoMaterialSet.materials = m_memory.Alloc<WeaponCamoMaterial>(weaponCamoMaterialSet.numMaterials);
for (auto i = 0u; i < weaponCamoMaterialSet.numMaterials; i++) for (auto i = 0u; i < weaponCamoMaterialSet.numMaterials; i++)
@ -197,7 +197,7 @@ namespace
if (!jWeaponCamo.camoSets.empty()) if (!jWeaponCamo.camoSets.empty())
{ {
weaponCamo.numCamoSets = jWeaponCamo.camoSets.size(); weaponCamo.numCamoSets = static_cast<unsigned>(jWeaponCamo.camoSets.size());
weaponCamo.camoSets = m_memory.Alloc<WeaponCamoSet>(weaponCamo.numCamoSets); weaponCamo.camoSets = m_memory.Alloc<WeaponCamoSet>(weaponCamo.numCamoSets);
for (auto i = 0u; i < weaponCamo.numCamoSets; i++) for (auto i = 0u; i < weaponCamo.numCamoSets; i++)
@ -214,7 +214,7 @@ namespace
if (!jWeaponCamo.camoMaterials.empty()) if (!jWeaponCamo.camoMaterials.empty())
{ {
weaponCamo.numCamoMaterials = jWeaponCamo.camoMaterials.size(); weaponCamo.numCamoMaterials = static_cast<unsigned>(jWeaponCamo.camoMaterials.size());
weaponCamo.camoMaterials = m_memory.Alloc<WeaponCamoMaterialSet>(weaponCamo.numCamoMaterials); weaponCamo.camoMaterials = m_memory.Alloc<WeaponCamoMaterialSet>(weaponCamo.numCamoMaterials);
for (auto i = 0u; i < weaponCamo.numCamoMaterials; i++) for (auto i = 0u; i < weaponCamo.numCamoMaterials; i++)

View File

@ -56,9 +56,9 @@ namespace
[[nodiscard]] std::unique_ptr<iobjstream> GetEntryStream(const Hash nameHash, const Hash dataHash) const override [[nodiscard]] std::unique_ptr<iobjstream> GetEntryStream(const Hash nameHash, const Hash dataHash) const override
{ {
IPakIndexEntryKey wantedKey{}; const IPakIndexEntryKey wantedKey{
wantedKey.nameHash = nameHash; {.dataHash = dataHash, .nameHash = nameHash}
wantedKey.dataHash = dataHash; };
for (auto& entry : m_index_entries) for (auto& entry : m_index_entries)
{ {
@ -209,5 +209,5 @@ IIPak::Hash IIPak::HashString(const std::string& str)
IIPak::Hash IIPak::HashData(const void* data, const size_t dataSize) IIPak::Hash IIPak::HashData(const void* data, const size_t dataSize)
{ {
return crc32(0, static_cast<const Bytef*>(data), dataSize); return crc32(0, static_cast<const Bytef*>(data), static_cast<unsigned>(dataSize));
} }

View File

@ -2,6 +2,7 @@
#include "ObjContainer/IPak/IPakTypes.h" #include "ObjContainer/IPak/IPakTypes.h"
#include <algorithm>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <minilzo.h> #include <minilzo.h>
@ -24,7 +25,7 @@ IPakEntryReadStream::IPakEntryReadStream(
m_current_command_offset(0), m_current_command_offset(0),
m_pos(startOffset), m_pos(startOffset),
m_base_pos(startOffset), m_base_pos(startOffset),
m_end_pos(startOffset + entrySize), m_end_pos(startOffset + static_cast<int64_t>(entrySize)),
m_buffer_start_pos(0), m_buffer_start_pos(0),
m_buffer_end_pos(0) m_buffer_end_pos(0)
{ {
@ -53,8 +54,7 @@ bool IPakEntryReadStream::SetChunkBufferWindow(const int64_t startPos, size_t ch
{ {
// Cannot load more than IPAK_CHUNK_COUNT_PER_READ chunks without overflowing the buffer // Cannot load more than IPAK_CHUNK_COUNT_PER_READ chunks without overflowing the buffer
assert(chunkCount <= IPAK_CHUNK_COUNT_PER_READ); assert(chunkCount <= IPAK_CHUNK_COUNT_PER_READ);
if (chunkCount > IPAK_CHUNK_COUNT_PER_READ) chunkCount = std::min(chunkCount, IPAK_CHUNK_COUNT_PER_READ);
chunkCount = IPAK_CHUNK_COUNT_PER_READ;
// The start position must be aligned to IPAK_CHUNK_SIZE // The start position must be aligned to IPAK_CHUNK_SIZE
assert(startPos % IPAK_CHUNK_SIZE == 0); assert(startPos % IPAK_CHUNK_SIZE == 0);
@ -66,7 +66,7 @@ bool IPakEntryReadStream::SetChunkBufferWindow(const int64_t startPos, size_t ch
return true; return true;
} }
const auto endPos = startPos + static_cast<int64_t>(chunkCount) * IPAK_CHUNK_SIZE; const auto endPos = startPos + static_cast<int64_t>(chunkCount) * static_cast<int64_t>(IPAK_CHUNK_SIZE);
// Check whether the start position is already part of the loaded data // Check whether the start position is already part of the loaded data
// We might be able to reuse previously loaded data // We might be able to reuse previously loaded data
@ -133,7 +133,7 @@ bool IPakEntryReadStream::ValidateBlockHeader(const IPakDataBlockHeader* blockHe
} }
// We expect the current file to be continued where we left off // We expect the current file to be continued where we left off
if (blockHeader->countAndOffset.offset != m_file_head) if (static_cast<int64_t>(blockHeader->countAndOffset.offset) != m_file_head)
{ {
// A matching offset is only relevant if a command contains data // A matching offset is only relevant if a command contains data
for (unsigned currentCommand = 0; currentCommand < blockHeader->countAndOffset.count; currentCommand++) for (unsigned currentCommand = 0; currentCommand < blockHeader->countAndOffset.count; currentCommand++)
@ -228,7 +228,7 @@ bool IPakEntryReadStream::ProcessCommand(const size_t commandSize, const int com
m_current_command_buffer = m_decompress_buffer; m_current_command_buffer = m_decompress_buffer;
m_current_command_length = outputSize; m_current_command_length = outputSize;
m_current_command_offset = 0; m_current_command_offset = 0;
m_file_head += outputSize; m_file_head += static_cast<int64_t>(outputSize);
} }
else else
{ {
@ -240,9 +240,9 @@ bool IPakEntryReadStream::ProcessCommand(const size_t commandSize, const int com
m_current_command_buffer = &m_chunk_buffer[m_pos - m_buffer_start_pos]; m_current_command_buffer = &m_chunk_buffer[m_pos - m_buffer_start_pos];
m_current_command_length = commandSize; m_current_command_length = commandSize;
m_current_command_offset = 0; m_current_command_offset = 0;
m_file_head += commandSize; m_file_head += static_cast<int64_t>(commandSize);
} }
m_pos += commandSize; m_pos += static_cast<int64_t>(commandSize);
return true; return true;
} }
@ -326,7 +326,7 @@ std::streambuf::int_type IPakEntryReadStream::uflow()
std::streamsize IPakEntryReadStream::xsgetn(char* ptr, const std::streamsize count) std::streamsize IPakEntryReadStream::xsgetn(char* ptr, const std::streamsize count)
{ {
auto* destBuffer = reinterpret_cast<uint8_t*>(ptr); auto* destBuffer = reinterpret_cast<uint8_t*>(ptr);
int64_t countRead = 0; std::streamsize countRead = 0;
while (countRead < count) while (countRead < count)
{ {
@ -337,12 +337,11 @@ std::streamsize IPakEntryReadStream::xsgetn(char* ptr, const std::streamsize cou
} }
auto sizeToRead = count - countRead; auto sizeToRead = count - countRead;
if (sizeToRead > m_current_command_length - m_current_command_offset) sizeToRead = std::min(sizeToRead, static_cast<std::streamsize>(m_current_command_length - m_current_command_offset));
sizeToRead = m_current_command_length - m_current_command_offset;
if (sizeToRead > 0) if (sizeToRead > 0)
{ {
assert(static_cast<size_t>(count - countRead) >= static_cast<size_t>(sizeToRead)); assert(count - countRead >= sizeToRead);
memcpy(&destBuffer[countRead], &m_current_command_buffer[m_current_command_offset], static_cast<size_t>(sizeToRead)); memcpy(&destBuffer[countRead], &m_current_command_buffer[m_current_command_offset], static_cast<size_t>(sizeToRead));
countRead += sizeToRead; countRead += sizeToRead;
m_current_command_offset += static_cast<size_t>(sizeToRead); m_current_command_offset += static_cast<size_t>(sizeToRead);

View File

@ -1,9 +1,9 @@
#include "SoundBank.h" #include "SoundBank.h"
#include "Utils/FileUtils.h"
#include "zlib.h" #include "zlib.h"
#include <cstring> #include <cstring>
#include <format>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
@ -67,18 +67,18 @@ protected:
if (dir == std::ios_base::end) if (dir == std::ios_base::end)
{ {
if (off > m_size) if (off > static_cast<off_type>(m_size))
return pos_type(-1); return pos_type(-1);
return seekpos(m_size - off, mode); return seekpos(static_cast<off_type>(m_size) - off, mode);
} }
return seekpos(m_offset + off, mode); return seekpos(static_cast<pos_type>(m_offset) + off, mode);
} }
pos_type seekpos(const pos_type pos, std::ios_base::openmode mode) override pos_type seekpos(const pos_type pos, std::ios_base::openmode mode) override
{ {
if (pos < 0 || pos >= m_size) if (pos < 0 || pos >= static_cast<pos_type>(m_size))
return pos_type(-1); return pos_type(-1);
m_stream.seekg(m_base_offset + pos); m_stream.seekg(m_base_offset + pos);
@ -96,7 +96,7 @@ public:
{ {
} }
_NODISCARD bool is_open() const override [[nodiscard]] bool is_open() const override
{ {
return m_open; return m_open;
} }
@ -116,13 +116,13 @@ SoundBankEntryInputStream::SoundBankEntryInputStream()
SoundBankEntryInputStream::SoundBankEntryInputStream(std::unique_ptr<std::istream> stream, SoundAssetBankEntry entry) SoundBankEntryInputStream::SoundBankEntryInputStream(std::unique_ptr<std::istream> stream, SoundAssetBankEntry entry)
: m_stream(std::move(stream)), : m_stream(std::move(stream)),
m_entry(entry) m_entry(std::move(entry))
{ {
} }
bool SoundBankEntryInputStream::IsOpen() const bool SoundBankEntryInputStream::IsOpen() const
{ {
return m_stream.get() != nullptr; return m_stream != nullptr;
} }
bool SoundBank::ReadHeader() bool SoundBank::ReadHeader()
@ -130,49 +130,50 @@ bool SoundBank::ReadHeader()
m_stream->read(reinterpret_cast<char*>(&m_header), sizeof(m_header)); m_stream->read(reinterpret_cast<char*>(&m_header), sizeof(m_header));
if (m_stream->gcount() != sizeof(m_header)) if (m_stream->gcount() != sizeof(m_header))
{ {
printf("Unexpected eof when trying to load sndbank header.\n"); std::cerr << "Unexpected eof when trying to load sndbank header.\n";
return false; return false;
} }
if (m_header.magic != MAGIC) if (m_header.magic != MAGIC)
{ {
std::cout << "Invalid sndbank magic 0x" << std::hex << m_header.magic << "\n"; std::cerr << std::format("Invalid sndbank magic 0x{:x}\n", m_header.magic);
return false; return false;
} }
if (m_header.version != VERSION) if (m_header.version != VERSION)
{ {
std::cout << "Unsupported sndbank version " << m_header.version << " (should be " << VERSION << ")\n"; std::cerr << std::format("Unsupported sndbank version {} (should be {})\n", m_header.version, VERSION);
return false; return false;
} }
if (m_header.entrySize != sizeof(SoundAssetBankEntry)) if (m_header.entrySize != sizeof(SoundAssetBankEntry))
{ {
std::cout << "Invalid sndbank entry size 0x" << std::hex << m_header.entrySize << " (should be 0x" << std::hex << sizeof(SoundAssetBankEntry) << ")\n"; std::cerr << std::format("Invalid sndbank entry size 0x{:x} (should be 0x{:x})\n", m_header.entrySize, sizeof(SoundAssetBankEntry));
return false; return false;
} }
if (m_header.fileSize != m_file_size) if (m_header.fileSize != m_file_size)
{ {
std::cout << "Invalid sndbank " << m_file_size << " (header expects " << m_header.fileSize << ")\n"; std::cerr << std::format("Invalid sndbank {} (header expects {})\n", m_file_size, m_header.fileSize);
return false; return false;
} }
if (m_header.entryCount && (m_header.entryOffset <= 0 || m_header.entryOffset + sizeof(SoundAssetBankEntry) * m_header.entryCount > m_file_size)) if (m_header.entryCount
&& (m_header.entryOffset <= 0 || m_header.entryOffset + sizeof(SoundAssetBankEntry) * m_header.entryCount > static_cast<size_t>(m_file_size)))
{ {
std::cout << "Invalid sndbank entry offset " << m_header.entryOffset << " (filesize is " << m_file_size << ")\n"; std::cerr << std::format("Invalid sndbank entry offset {} (filesize is {})\n", m_header.entryOffset, m_file_size);
return false; return false;
} }
if (m_header.checksumOffset <= 0 || m_header.checksumOffset + sizeof(SoundAssetBankChecksum) * m_header.entryCount > m_file_size) if (m_header.checksumOffset <= 0 || m_header.checksumOffset + sizeof(SoundAssetBankChecksum) * m_header.entryCount > static_cast<size_t>(m_file_size))
{ {
std::cout << "Invalid sndbank checksum offset " << m_header.checksumOffset << " (filesize is " << m_file_size << ")\n"; std::cerr << std::format("Invalid sndbank checksum offset {} (filesize is {})\n", m_header.checksumOffset, m_file_size);
return false; return false;
} }
if (m_header.dependencyCount * m_header.dependencySize > sizeof(SoundAssetBankHeader::dependencies)) if (m_header.dependencyCount * m_header.dependencySize > sizeof(SoundAssetBankHeader::dependencies))
{ {
std::cout << "Invalid sndbank dependency sizes (count is " << m_header.dependencyCount << "; size is " << m_header.dependencySize << ")\n"; std::cerr << std::format("Invalid sndbank dependency sizes (count is {}; size is {})\n", m_header.dependencyCount, m_header.dependencySize);
return false; return false;
} }
@ -201,13 +202,13 @@ bool SoundBank::ReadEntries()
if (m_stream->gcount() != sizeof(entry)) if (m_stream->gcount() != sizeof(entry))
{ {
std::cout << "Failed to read sound bank entry at index " << i << "\n"; std::cerr << std::format("Failed to read sound bank entry at index {}\n", i);
return false; return false;
} }
if (entry.offset == 0 || entry.offset + entry.size >= m_file_size) if (entry.offset == 0 || entry.offset + entry.size >= m_file_size)
{ {
std::cout << "Invalid sound bank entry data offset " << entry.offset << " (filesize is " << m_header.fileSize << ")\n"; std::cerr << std::format("Invalid sound bank entry data offset {} (filesize is {})\n", entry.offset, m_header.fileSize);
return false; return false;
} }
@ -229,7 +230,7 @@ bool SoundBank::ReadChecksums()
if (m_stream->gcount() != sizeof(checksum)) if (m_stream->gcount() != sizeof(checksum))
{ {
std::cout << "Failed to read sound bank checksum at index " << i << "\n"; std::cerr << std::format("Failed to read sound bank checksum at index {}\n", i);
return false; return false;
} }

View File

@ -1,6 +1,6 @@
#include "SoundBankWriter.h" #include "SoundBankWriter.h"
#include "Crypto.h" #include "Cryptography.h"
#include "ObjContainer/SoundBank/SoundBankTypes.h" #include "ObjContainer/SoundBank/SoundBankTypes.h"
#include "Sound/FlacDecoder.h" #include "Sound/FlacDecoder.h"
#include "Sound/WavTypes.h" #include "Sound/WavTypes.h"
@ -251,7 +251,7 @@ public:
SoundAssetBankChecksum checksum{}; SoundAssetBankChecksum checksum{};
const auto md5Crypt = Crypto::CreateMD5(); const auto md5Crypt = cryptography::CreateMd5();
md5Crypt->Process(soundData.get(), soundSize); md5Crypt->Process(soundData.get(), soundSize);
md5Crypt->Finish(checksum.checksumBytes); md5Crypt->Finish(checksum.checksumBytes);

View File

@ -145,7 +145,7 @@ namespace
{ {
char temp[1024]; char temp[1024];
const auto toRead = skipAmount > sizeof(temp) ? sizeof(temp) : static_cast<size_t>(skipAmount); const auto toRead = skipAmount > sizeof(temp) ? sizeof(temp) : static_cast<size_t>(skipAmount);
unzReadCurrentFile(m_container, temp, toRead); unzReadCurrentFile(m_container, temp, static_cast<unsigned>(toRead));
skipAmount -= toRead; skipAmount -= toRead;
} }

View File

@ -36,8 +36,7 @@ namespace string_table
while (csv.NextRow(currentLine)) while (csv.NextRow(currentLine))
{ {
if (currentLine.size() > maxCols) maxCols = std::max(static_cast<unsigned>(currentLine.size()), maxCols);
maxCols = currentLine.size();
csvLines.emplace_back(std::move(currentLine)); csvLines.emplace_back(std::move(currentLine));
currentLine = std::vector<std::string>(); currentLine = std::vector<std::string>();
} }

View File

@ -213,7 +213,7 @@ namespace techset
const auto& shaderArgumentIndexToken = result.NextCapture(CAPTURE_SHADER_INDEX); const auto& shaderArgumentIndexToken = result.NextCapture(CAPTURE_SHADER_INDEX);
if (shaderArgumentIndexToken.IntegerValue() < 0) if (shaderArgumentIndexToken.IntegerValue() < 0)
throw ParsingException(shaderArgumentIndexToken.GetPos(), "Index cannot be negative"); throw ParsingException(shaderArgumentIndexToken.GetPos(), "Index cannot be negative");
const auto index = static_cast<size_t>(shaderArgumentIndexToken.IntegerValue()); const auto index = static_cast<unsigned>(shaderArgumentIndexToken.IntegerValue());
arg = ShaderArgument(shaderArgumentNameToken.IdentifierValue(), index); arg = ShaderArgument(shaderArgumentNameToken.IdentifierValue(), index);
} }
else else

View File

@ -15,7 +15,7 @@ ShaderArgument::ShaderArgument(std::string argumentName)
{ {
} }
ShaderArgument::ShaderArgument(std::string argumentName, const size_t argumentIndex) ShaderArgument::ShaderArgument(std::string argumentName, const unsigned argumentIndex)
: m_argument_name(std::move(argumentName)), : m_argument_name(std::move(argumentName)),
m_argument_index_specified(true), m_argument_index_specified(true),
m_argument_index(argumentIndex) m_argument_index(argumentIndex)
@ -35,7 +35,7 @@ ShaderArgumentCodeSource::ShaderArgumentCodeSource(std::vector<std::string> acce
{ {
} }
ShaderArgumentCodeSource::ShaderArgumentCodeSource(std::vector<std::string> accessors, const size_t indexAccessor) ShaderArgumentCodeSource::ShaderArgumentCodeSource(std::vector<std::string> accessors, const unsigned indexAccessor)
: m_accessors(std::move(accessors)), : m_accessors(std::move(accessors)),
m_index_accessor_specified(true), m_index_accessor_specified(true),
m_index_accessor(indexAccessor) m_index_accessor(indexAccessor)
@ -102,7 +102,7 @@ ShaderArgumentMaterialSource::ShaderArgumentMaterialSource()
{ {
} }
ShaderArgumentMaterialSource::ShaderArgumentMaterialSource(const size_t hash) ShaderArgumentMaterialSource::ShaderArgumentMaterialSource(const unsigned hash)
: m_is_hash(true), : m_is_hash(true),
m_hash(hash) m_hash(hash)
{ {

View File

@ -16,11 +16,11 @@ namespace techset
public: public:
std::string m_argument_name; std::string m_argument_name;
bool m_argument_index_specified; bool m_argument_index_specified;
size_t m_argument_index; unsigned m_argument_index;
ShaderArgument(); ShaderArgument();
explicit ShaderArgument(std::string argumentName); explicit ShaderArgument(std::string argumentName);
ShaderArgument(std::string argumentName, size_t argumentIndex); ShaderArgument(std::string argumentName, unsigned argumentIndex);
}; };
class ShaderArgumentCodeSource class ShaderArgumentCodeSource
@ -28,11 +28,11 @@ namespace techset
public: public:
std::vector<std::string> m_accessors; std::vector<std::string> m_accessors;
bool m_index_accessor_specified; bool m_index_accessor_specified;
size_t m_index_accessor; unsigned m_index_accessor;
ShaderArgumentCodeSource(); ShaderArgumentCodeSource();
explicit ShaderArgumentCodeSource(std::vector<std::string> accessors); explicit ShaderArgumentCodeSource(std::vector<std::string> accessors);
ShaderArgumentCodeSource(std::vector<std::string> accessors, size_t indexAccessor); ShaderArgumentCodeSource(std::vector<std::string> accessors, unsigned indexAccessor);
}; };
class ShaderArgumentLiteralSource class ShaderArgumentLiteralSource
@ -53,13 +53,13 @@ namespace techset
class ShaderArgumentMaterialSource class ShaderArgumentMaterialSource
{ {
public: public:
bool m_is_hash;
size_t m_hash;
std::string m_name;
ShaderArgumentMaterialSource(); ShaderArgumentMaterialSource();
explicit ShaderArgumentMaterialSource(size_t hash); explicit ShaderArgumentMaterialSource(unsigned hash);
explicit ShaderArgumentMaterialSource(std::string name); explicit ShaderArgumentMaterialSource(std::string name);
bool m_is_hash;
unsigned m_hash;
std::string m_name;
}; };
class ITechniqueDefinitionAcceptor class ITechniqueDefinitionAcceptor

View File

@ -258,7 +258,7 @@ namespace
VerifyAccessorVertexCount("WEIGHTS_0", weightsAccessor, vertexCount); VerifyAccessorVertexCount("WEIGHTS_0", weightsAccessor, vertexCount);
// clang-format on // clang-format on
const auto vertexOffset = common.m_vertices.size(); const auto vertexOffset = static_cast<unsigned>(common.m_vertices.size());
common.m_vertices.reserve(vertexOffset + vertexCount); common.m_vertices.reserve(vertexOffset + vertexCount);
common.m_vertex_bone_weights.reserve(vertexOffset + vertexCount); common.m_vertex_bone_weights.reserve(vertexOffset + vertexCount);
for (auto vertexIndex = 0u; vertexIndex < vertexCount; vertexIndex++) for (auto vertexIndex = 0u; vertexIndex < vertexCount; vertexIndex++)
@ -300,6 +300,7 @@ namespace
} }
m_vertex_offset_for_accessors.emplace(accessorsForVertex, vertexOffset); m_vertex_offset_for_accessors.emplace(accessorsForVertex, vertexOffset);
return vertexOffset; return vertexOffset;
} }
@ -499,7 +500,7 @@ namespace
const auto boneInSkin = std::ranges::find(skin.joints, nodeIndex); const auto boneInSkin = std::ranges::find(skin.joints, nodeIndex);
if (boneInSkin == skin.joints.end()) if (boneInSkin == skin.joints.end())
throw GltfLoadException("Bone node is not part of skin"); throw GltfLoadException("Bone node is not part of skin");
const auto boneIndexInSkin = std::distance(skin.joints.begin(), boneInSkin); const auto boneIndexInSkin = static_cast<unsigned>(std::distance(skin.joints.begin(), boneInSkin));
const auto commonBoneOffset = skinBoneOffset + boneIndexInSkin; const auto commonBoneOffset = skinBoneOffset + boneIndexInSkin;
auto& bone = common.m_bones[commonBoneOffset]; auto& bone = common.m_bones[commonBoneOffset];
@ -548,7 +549,7 @@ namespace
return false; return false;
const auto rootNode = GetRootNodeForSkin(jRoot, skin).value_or(skin.joints[0]); const auto rootNode = GetRootNodeForSkin(jRoot, skin).value_or(skin.joints[0]);
const auto skinBoneOffset = common.m_bones.size(); const auto skinBoneOffset = static_cast<unsigned>(common.m_bones.size());
common.m_bones.resize(skinBoneOffset + skin.joints.size()); common.m_bones.resize(skinBoneOffset + skin.joints.size());
constexpr float defaultTranslation[3]{0.0f, 0.0f, 0.0f}; constexpr float defaultTranslation[3]{0.0f, 0.0f, 0.0f};

View File

@ -1,6 +1,6 @@
#include "GltfBuffer.h" #include "GltfBuffer.h"
#include "Impl/Base64.h" #include "Base64.h"
#include "XModel/Gltf/GltfConstants.h" #include "XModel/Gltf/GltfConstants.h"
#include <cassert> #include <cassert>

View File

@ -72,7 +72,7 @@ bool PartClassificationState::LoadRow(const char** hitLocStart, const char** hit
return false; return false;
} }
const auto hitLocNum = std::distance(hitLocStart, foundHitLoc); const auto hitLocNum = static_cast<unsigned>(std::distance(hitLocStart, foundHitLoc));
m_part_classifications.emplace(row[0], hitLocNum); m_part_classifications.emplace(row[0], hitLocNum);
return true; return true;

View File

@ -11,11 +11,11 @@ void TangentData::CreateTangentData(const XModelCommon& common)
m_tangents.resize(vertexCount); m_tangents.resize(vertexCount);
m_binormals.resize(vertexCount); m_binormals.resize(vertexCount);
auto triCount = 0u; auto triCount = 0uz;
for (const auto& object : common.m_objects) for (const auto& object : common.m_objects)
triCount += object.m_faces.size(); triCount += object.m_faces.size();
std::vector<uint16_t> indices(triCount * 3u); std::vector<uint16_t> indices(triCount * 3uz);
auto triOffset = 0u; auto triOffset = 0u;
for (const auto& object : common.m_objects) for (const auto& object : common.m_objects)
{ {

View File

@ -126,10 +126,10 @@ namespace
bone.globalOffset[1] = model->baseMat[boneNum].trans[1]; bone.globalOffset[1] = model->baseMat[boneNum].trans[1];
bone.globalOffset[2] = model->baseMat[boneNum].trans[2]; bone.globalOffset[2] = model->baseMat[boneNum].trans[2];
bone.globalRotation = { bone.globalRotation = {
model->baseMat[boneNum].quat[0], .x = model->baseMat[boneNum].quat[0],
model->baseMat[boneNum].quat[1], .y = model->baseMat[boneNum].quat[1],
model->baseMat[boneNum].quat[2], .z = model->baseMat[boneNum].quat[2],
model->baseMat[boneNum].quat[3], .w = model->baseMat[boneNum].quat[3],
}; };
if (boneNum < model->numRootBones) if (boneNum < model->numRootBones)
@ -137,7 +137,7 @@ namespace
bone.localOffset[0] = 0; bone.localOffset[0] = 0;
bone.localOffset[1] = 0; bone.localOffset[1] = 0;
bone.localOffset[2] = 0; bone.localOffset[2] = 0;
bone.localRotation = {0, 0, 0, 1}; bone.localRotation = {.x = 0, .y = 0, .z = 0, .w = 1};
} }
else else
{ {
@ -145,10 +145,10 @@ namespace
bone.localOffset[1] = model->trans[boneNum - model->numRootBones][1]; bone.localOffset[1] = model->trans[boneNum - model->numRootBones][1];
bone.localOffset[2] = model->trans[boneNum - model->numRootBones][2]; bone.localOffset[2] = model->trans[boneNum - model->numRootBones][2];
bone.localRotation = { bone.localRotation = {
QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][0]), .x = QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][0]),
QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][1]), .y = QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][1]),
QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][2]), .z = QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][2]),
QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][3]), .w = QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][3]),
}; };
} }
@ -166,7 +166,7 @@ namespace
void AddXModelMaterials(XModelCommon& out, DistinctMapper<Material*>& materialMapper, const XModel* model) void AddXModelMaterials(XModelCommon& out, DistinctMapper<Material*>& materialMapper, const XModel* model)
{ {
for (auto surfaceMaterialNum = 0; surfaceMaterialNum < model->numsurfs; surfaceMaterialNum++) for (auto surfaceMaterialNum = 0u; surfaceMaterialNum < model->numsurfs; surfaceMaterialNum++)
{ {
Material* material = model->materialHandles[surfaceMaterialNum]; Material* material = model->materialHandles[surfaceMaterialNum];
if (materialMapper.Add(material)) if (materialMapper.Add(material))
@ -271,7 +271,7 @@ namespace
const auto surfCount = model->lodInfo[lod].numsurfs; const auto surfCount = model->lodInfo[lod].numsurfs;
auto& weightCollection = out.m_bone_weight_data; auto& weightCollection = out.m_bone_weight_data;
size_t weightOffset = 0u; auto weightOffset = 0u;
for (auto surfIndex = 0u; surfIndex < surfCount; surfIndex++) for (auto surfIndex = 0u; surfIndex < surfCount; surfIndex++)
{ {
@ -285,7 +285,8 @@ namespace
const auto& vertList = surface.vertList[vertListIndex]; const auto& vertList = surface.vertList[vertListIndex];
const auto boneWeightOffset = weightOffset; const auto boneWeightOffset = weightOffset;
weightCollection.weights[weightOffset++] = XModelBoneWeight{static_cast<unsigned>(vertList.boneOffset / sizeof(DObjSkelMat)), 1.0f}; weightCollection.weights[weightOffset++] =
XModelBoneWeight{.boneIndex = static_cast<unsigned>(vertList.boneOffset / sizeof(DObjSkelMat)), .weight = 1.0f};
for (auto vertListVertexOffset = 0u; vertListVertexOffset < vertList.vertCount; vertListVertexOffset++) for (auto vertListVertexOffset = 0u; vertListVertexOffset < vertList.vertCount; vertListVertexOffset++)
{ {
@ -303,7 +304,7 @@ namespace
{ {
const auto boneWeightOffset = weightOffset; const auto boneWeightOffset = weightOffset;
const unsigned boneIndex0 = surface.vertInfo.vertsBlend[vertsBlendOffset + 0] / sizeof(DObjSkelMat); const unsigned boneIndex0 = surface.vertInfo.vertsBlend[vertsBlendOffset + 0] / sizeof(DObjSkelMat);
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex0, 1.0f}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex0, .weight = 1.0f};
vertsBlendOffset += 1; vertsBlendOffset += 1;
@ -319,8 +320,8 @@ namespace
const auto boneWeight1 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 2]); const auto boneWeight1 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 2]);
const auto boneWeight0 = 1.0f - boneWeight1; const auto boneWeight0 = 1.0f - boneWeight1;
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex0, boneWeight0}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex0, .weight = boneWeight0};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex1, boneWeight1}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex1, .weight = boneWeight1};
vertsBlendOffset += 3; vertsBlendOffset += 3;
@ -338,9 +339,9 @@ namespace
const auto boneWeight2 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 4]); const auto boneWeight2 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 4]);
const auto boneWeight0 = 1.0f - boneWeight1 - boneWeight2; const auto boneWeight0 = 1.0f - boneWeight1 - boneWeight2;
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex0, boneWeight0}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex0, .weight = boneWeight0};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex1, boneWeight1}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex1, .weight = boneWeight1};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex2, boneWeight2}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex2, .weight = boneWeight2};
vertsBlendOffset += 5; vertsBlendOffset += 5;
@ -360,10 +361,10 @@ namespace
const auto boneWeight3 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 6]); const auto boneWeight3 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 6]);
const auto boneWeight0 = 1.0f - boneWeight1 - boneWeight2 - boneWeight3; const auto boneWeight0 = 1.0f - boneWeight1 - boneWeight2 - boneWeight3;
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex0, boneWeight0}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex0, .weight = boneWeight0};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex1, boneWeight1}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex1, .weight = boneWeight1};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex2, boneWeight2}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex2, .weight = boneWeight2};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex3, boneWeight3}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex3, .weight = boneWeight3};
vertsBlendOffset += 7; vertsBlendOffset += 7;

View File

@ -121,10 +121,10 @@ namespace
bone.globalOffset[1] = model->baseMat[boneNum].trans[1]; bone.globalOffset[1] = model->baseMat[boneNum].trans[1];
bone.globalOffset[2] = model->baseMat[boneNum].trans[2]; bone.globalOffset[2] = model->baseMat[boneNum].trans[2];
bone.globalRotation = { bone.globalRotation = {
model->baseMat[boneNum].quat[0], .x = model->baseMat[boneNum].quat[0],
model->baseMat[boneNum].quat[1], .y = model->baseMat[boneNum].quat[1],
model->baseMat[boneNum].quat[2], .z = model->baseMat[boneNum].quat[2],
model->baseMat[boneNum].quat[3], .w = model->baseMat[boneNum].quat[3],
}; };
if (boneNum < model->numRootBones) if (boneNum < model->numRootBones)
@ -132,7 +132,7 @@ namespace
bone.localOffset[0] = 0; bone.localOffset[0] = 0;
bone.localOffset[1] = 0; bone.localOffset[1] = 0;
bone.localOffset[2] = 0; bone.localOffset[2] = 0;
bone.localRotation = {0, 0, 0, 1}; bone.localRotation = {.x = 0, .y = 0, .z = 0, .w = 1};
} }
else else
{ {
@ -140,10 +140,10 @@ namespace
bone.localOffset[1] = model->trans[boneNum - model->numRootBones][1]; bone.localOffset[1] = model->trans[boneNum - model->numRootBones][1];
bone.localOffset[2] = model->trans[boneNum - model->numRootBones][2]; bone.localOffset[2] = model->trans[boneNum - model->numRootBones][2];
bone.localRotation = { bone.localRotation = {
QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][0]), .x = QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][0]),
QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][1]), .y = QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][1]),
QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][2]), .z = QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][2]),
QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][3]), .w = QuatInt16::ToFloat(model->quats[boneNum - model->numRootBones][3]),
}; };
} }
@ -161,7 +161,7 @@ namespace
void AddXModelMaterials(XModelCommon& out, DistinctMapper<Material*>& materialMapper, const XModel* model) void AddXModelMaterials(XModelCommon& out, DistinctMapper<Material*>& materialMapper, const XModel* model)
{ {
for (auto surfaceMaterialNum = 0; surfaceMaterialNum < model->numsurfs; surfaceMaterialNum++) for (auto surfaceMaterialNum = 0u; surfaceMaterialNum < model->numsurfs; surfaceMaterialNum++)
{ {
Material* material = model->materialHandles[surfaceMaterialNum]; Material* material = model->materialHandles[surfaceMaterialNum];
if (materialMapper.Add(material)) if (materialMapper.Add(material))
@ -254,7 +254,7 @@ namespace
void AddXModelVertexBoneWeights(XModelCommon& out, const XModelSurfs* modelSurfs) void AddXModelVertexBoneWeights(XModelCommon& out, const XModelSurfs* modelSurfs)
{ {
auto& weightCollection = out.m_bone_weight_data; auto& weightCollection = out.m_bone_weight_data;
size_t weightOffset = 0u; auto weightOffset = 0u;
for (auto surfIndex = 0u; surfIndex < modelSurfs->numsurfs; surfIndex++) for (auto surfIndex = 0u; surfIndex < modelSurfs->numsurfs; surfIndex++)
{ {
@ -268,11 +268,12 @@ namespace
const auto& vertList = surface.vertList[vertListIndex]; const auto& vertList = surface.vertList[vertListIndex];
const auto boneWeightOffset = weightOffset; const auto boneWeightOffset = weightOffset;
weightCollection.weights[weightOffset++] = XModelBoneWeight{static_cast<unsigned>(vertList.boneOffset / sizeof(DObjSkelMat)), 1.0f}; weightCollection.weights[weightOffset++] =
XModelBoneWeight{.boneIndex = static_cast<unsigned>(vertList.boneOffset / sizeof(DObjSkelMat)), .weight = 1.0f};
for (auto vertListVertexOffset = 0u; vertListVertexOffset < vertList.vertCount; vertListVertexOffset++) for (auto vertListVertexOffset = 0u; vertListVertexOffset < vertList.vertCount; vertListVertexOffset++)
{ {
out.m_vertex_bone_weights.emplace_back(boneWeightOffset, 1); out.m_vertex_bone_weights.emplace_back(boneWeightOffset, 1u);
} }
handledVertices += vertList.vertCount; handledVertices += vertList.vertCount;
} }
@ -286,7 +287,7 @@ namespace
{ {
const auto boneWeightOffset = weightOffset; const auto boneWeightOffset = weightOffset;
const unsigned boneIndex0 = surface.vertInfo.vertsBlend[vertsBlendOffset + 0] / sizeof(DObjSkelMat); const unsigned boneIndex0 = surface.vertInfo.vertsBlend[vertsBlendOffset + 0] / sizeof(DObjSkelMat);
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex0, 1.0f}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex0, .weight = 1.0f};
vertsBlendOffset += 1; vertsBlendOffset += 1;
@ -302,8 +303,8 @@ namespace
const auto boneWeight1 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 2]); const auto boneWeight1 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 2]);
const auto boneWeight0 = 1.0f - boneWeight1; const auto boneWeight0 = 1.0f - boneWeight1;
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex0, boneWeight0}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex0, .weight = boneWeight0};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex1, boneWeight1}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex1, .weight = boneWeight1};
vertsBlendOffset += 3; vertsBlendOffset += 3;
@ -321,9 +322,9 @@ namespace
const auto boneWeight2 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 4]); const auto boneWeight2 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 4]);
const auto boneWeight0 = 1.0f - boneWeight1 - boneWeight2; const auto boneWeight0 = 1.0f - boneWeight1 - boneWeight2;
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex0, boneWeight0}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex0, .weight = boneWeight0};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex1, boneWeight1}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex1, .weight = boneWeight1};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex2, boneWeight2}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex2, .weight = boneWeight2};
vertsBlendOffset += 5; vertsBlendOffset += 5;
@ -343,10 +344,10 @@ namespace
const auto boneWeight3 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 6]); const auto boneWeight3 = BoneWeight16(surface.vertInfo.vertsBlend[vertsBlendOffset + 6]);
const auto boneWeight0 = 1.0f - boneWeight1 - boneWeight2 - boneWeight3; const auto boneWeight0 = 1.0f - boneWeight1 - boneWeight2 - boneWeight3;
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex0, boneWeight0}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex0, .weight = boneWeight0};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex1, boneWeight1}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex1, .weight = boneWeight1};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex2, boneWeight2}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex2, .weight = boneWeight2};
weightCollection.weights[weightOffset++] = XModelBoneWeight{boneIndex3, boneWeight3}; weightCollection.weights[weightOffset++] = XModelBoneWeight{.boneIndex = boneIndex3, .weight = boneWeight3};
vertsBlendOffset += 7; vertsBlendOffset += 7;

View File

@ -271,13 +271,13 @@ void MenuDumper::WriteStatementSkipInitialUnnecessaryParenthesis(const Statement
void MenuDumper::WriteStatementNaive(const Statement_s* statement) const void MenuDumper::WriteStatementNaive(const Statement_s* statement) const
{ {
const auto entryCount = static_cast<unsigned>(statement->numEntries); const auto entryCount = static_cast<size_t>(statement->numEntries);
const auto missingClosingParenthesis = statement->numEntries > 0 && statement->entries[0].type == EET_OPERATOR const auto missingClosingParenthesis = statement->numEntries > 0 && statement->entries[0].type == EET_OPERATOR
&& statement->entries[0].data.op == OP_LEFTPAREN && statement->entries[0].data.op == OP_LEFTPAREN
&& FindStatementClosingParenthesis(statement, 0) >= static_cast<size_t>(statement->numEntries); && FindStatementClosingParenthesis(statement, 0) >= static_cast<size_t>(statement->numEntries);
for (auto i = 0u; i < entryCount; i++) for (auto i = 0uz; i < entryCount; i++)
{ {
const auto& entry = statement->entries[i]; const auto& entry = statement->entries[i];
if (entry.type == EET_OPERAND) if (entry.type == EET_OPERAND)
@ -314,7 +314,7 @@ void MenuDumper::WriteStatementNaive(const Statement_s* statement) const
const auto closingParenPos = FindStatementClosingParenthesis(statement, i); const auto closingParenPos = FindStatementClosingParenthesis(statement, i);
m_stream << "("; m_stream << "(";
if (closingParenPos - i + 1 >= 1) if (closingParenPos - i + 1u >= 1u)
{ {
const auto& staticDvarEntry = statement->entries[i + 1]; const auto& staticDvarEntry = statement->entries[i + 1];
if (staticDvarEntry.type == EET_OPERAND && staticDvarEntry.data.operand.dataType == VAL_INT) if (staticDvarEntry.type == EET_OPERAND && staticDvarEntry.data.operand.dataType == VAL_INT)

View File

@ -1,8 +1,8 @@
#include "JsonMaterialWriter.h" #include "JsonMaterialWriter.h"
#include "Base64.h"
#include "Game/IW5/CommonIW5.h" #include "Game/IW5/CommonIW5.h"
#include "Game/IW5/Material/JsonMaterial.h" #include "Game/IW5/Material/JsonMaterial.h"
#include "Impl/Base64.h"
#include "MaterialConstantZoneState.h" #include "MaterialConstantZoneState.h"
#include <iomanip> #include <iomanip>

Some files were not shown because too many files have changed in this diff Show More