Skip to content

Commit

Permalink
flags implementation
Browse files Browse the repository at this point in the history
- implemented enum flags editing
  • Loading branch information
rfuzzo committed Sep 3, 2020
1 parent 706aa17 commit ee03e4d
Show file tree
Hide file tree
Showing 25 changed files with 481 additions and 483 deletions.
24 changes: 0 additions & 24 deletions CR2WTests/frmUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ private static int StressTestFile(BundleItem f, ref ConcurrentDictionary<string,
var diffDictList = dictvalues.Except(newdictvalues).ToList();

bool isclassicalinconsistentw2anims = true;
bool isclassicalinconsistentw2ent = true;
bool isclassicalinconsistentw2phase = true;

if (diffDictList.Count != 0)
Expand All @@ -252,24 +251,6 @@ private static int StressTestFile(BundleItem f, ref ConcurrentDictionary<string,
break;
}
}
//w2ent detlaff inconsistencies
foreach (string str in diffDictList)
{
if (str == "IF_Positive" ||
str == "IF_Negative" ||
str == "IF_Neutral" ||
str == "IF_Immobilize" ||
str == "IF_Confuse" ||
str == "IF_Damage")
{
continue;
}
else
{
isclassicalinconsistentw2ent = false;
break;
}
}
//w2phase inconsistencies
foreach (string str in diffDictList)
{
Expand All @@ -292,11 +273,6 @@ private static int StressTestFile(BundleItem f, ref ConcurrentDictionary<string,
//throw new InvalidBundleException("Classical inconsistent .w2anims - " +
// ".w2animev sound handles left behind in string lists, but actual data is empty");
}
else if (isclassicalinconsistentw2ent)
{
//throw new InvalidBundleException("Inconsistent .w2ent - " +
// "some Detlaff stuff");
}
else if (isclassicalinconsistentw2phase)
{
//throw new InvalidBundleException("Inconsistent .w2phase - " +
Expand Down
124 changes: 56 additions & 68 deletions WolvenKit.App/Model/ImageUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,82 +204,70 @@ public static byte[] Xbm2DdsBytes(CBitmapTexture xbm)
/// <returns></returns>
private static DDSMetadata GetDDSMetadata(CBitmapTexture xbm)
{
try
{
int residentMipIndex = xbm.ResidentMipIndex == null ? 0 : xbm.ResidentMipIndex.val;
int residentMipIndex = xbm.ResidentMipIndex == null ? 0 : xbm.ResidentMipIndex.val;

int mipcount = xbm.Mipdata.elements.Count - residentMipIndex;
int mipcount = xbm.Mipdata.elements.Count - residentMipIndex;

uint width = xbm.Mipdata.elements[residentMipIndex].Width.val;
uint height = xbm.Mipdata.elements[residentMipIndex].Height.val;
uint width = xbm.Mipdata.elements[residentMipIndex].Width.val;
uint height = xbm.Mipdata.elements[residentMipIndex].Height.val;

ETextureCompression compression = xbm.Compression.WrappedEnum;
ETextureCompression compression = xbm.Compression.WrappedEnum;

var ddsformat = ETextureFormat.TEXFMT_R8G8B8A8;
switch (compression)
{
var ddsformat = ETextureFormat.TEXFMT_R8G8B8A8;
switch (compression)
{

case ETextureCompression.TCM_DXTNoAlpha:
ddsformat = ETextureFormat.TEXFMT_BC1;
break;
case ETextureCompression.TCM_DXTAlpha:
ddsformat = ETextureFormat.TEXFMT_BC3;
break;
case ETextureCompression.TCM_Normals:
ddsformat = ETextureFormat.TEXFMT_BC1;
break;
case ETextureCompression.TCM_NormalsHigh:
ddsformat = ETextureFormat.TEXFMT_BC3;
break;
case ETextureCompression.TCM_NormalsGloss:
ddsformat = ETextureFormat.TEXFMT_BC3;
break;
case ETextureCompression.TCM_QualityR:
ddsformat = ETextureFormat.TEXFMT_BC4;
break;
case ETextureCompression.TCM_QualityRG:
ddsformat = ETextureFormat.TEXFMT_BC5;
break;
case ETextureCompression.TCM_QualityColor:
ddsformat = ETextureFormat.TEXFMT_BC3;
break;
case ETextureCompression.TCM_DXTAlphaLinear:
case ETextureCompression.TCM_RGBE:
case ETextureCompression.TCM_None:
case ETextureCompression.TCM_DXTNoAlpha:
ddsformat = ETextureFormat.TEXFMT_BC1;
break;
case ETextureCompression.TCM_DXTAlpha:
ddsformat = ETextureFormat.TEXFMT_BC3;
break;
case ETextureCompression.TCM_Normals:
ddsformat = ETextureFormat.TEXFMT_BC1;
break;
case ETextureCompression.TCM_NormalsHigh:
ddsformat = ETextureFormat.TEXFMT_BC3;
break;
case ETextureCompression.TCM_NormalsGloss:
ddsformat = ETextureFormat.TEXFMT_BC3;
break;
case ETextureCompression.TCM_QualityR:
ddsformat = ETextureFormat.TEXFMT_BC4;
break;
case ETextureCompression.TCM_QualityRG:
ddsformat = ETextureFormat.TEXFMT_BC5;
break;
case ETextureCompression.TCM_QualityColor:
ddsformat = ETextureFormat.TEXFMT_BC3;
break;
case ETextureCompression.TCM_DXTAlphaLinear:
case ETextureCompression.TCM_RGBE:
case ETextureCompression.TCM_None:
{
ETextureRawFormat format = xbm.Format.WrappedEnum;
switch (format)
{
ETextureRawFormat format = xbm.Format.WrappedEnum;
switch (format)
{
case ETextureRawFormat.TRF_TrueColor:
ddsformat = ETextureFormat.TEXFMT_R8G8B8A8;
break;
case ETextureRawFormat.TRF_Grayscale:
break;
case ETextureRawFormat.TRF_HDR:
case ETextureRawFormat.TRF_AlphaGrayscale:
case ETextureRawFormat.TRF_HDRGrayscale:
default:
throw new Exception("Invalid compression type! [" + compression + "]");
}
break;
case ETextureRawFormat.TRF_TrueColor:
ddsformat = ETextureFormat.TEXFMT_R8G8B8A8;
break;
case ETextureRawFormat.TRF_Grayscale:
break;
case ETextureRawFormat.TRF_HDR:
case ETextureRawFormat.TRF_AlphaGrayscale:
case ETextureRawFormat.TRF_HDRGrayscale:
default:
ddsformat = ETextureFormat.TEXFMT_R8G8B8A8;
//throw new Exception("Invalid texture format type! [" + format + "]");
break;
}
default:
throw new Exception("Invalid compression type! [" + compression + "]");
}

return new DDSMetadata(width, height, (uint)mipcount, ddsformat);


}
catch(Exception e)
{
//string message = e.Message;
//string caption = "Error!";
//MessageBoxButtons buttons = MessageBoxButtons.OK;
//MessageBox.Show(message, caption, buttons);
throw e;
break;
}
default:
throw new Exception("Invalid texture compression type! [" + compression + "]");
}


return new DDSMetadata(width, height, (uint)mipcount, ddsformat);
}

/// <summary>
Expand Down
19 changes: 11 additions & 8 deletions WolvenKit.CR2W/CR2W/CR2WFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,13 +1110,13 @@ var is SEntityBufferType1 ||
}
}
}
else if (var is CFlags)
{
foreach (var flag in (var as CFlags).flags)
{
AddUniqueToTable(flag.Value);
}
}
//else if (var is CFlags)
//{
// foreach (var flag in (var as CFlags).flags)
// {
// AddUniqueToTable(flag.Value);
// }
//}
else if (var is TagList)
{
foreach (var tag in (var as TagList).tags)
Expand Down Expand Up @@ -1217,7 +1217,10 @@ var is SEntityBufferType1 ||
}
else if (var is IEnumAccessor enumAccessor)
{
AddUniqueToTable(enumAccessor.Value);
foreach (var enumstring in enumAccessor.Value)
{
AddUniqueToTable(enumstring);
}
}
else
{
Expand Down
28 changes: 28 additions & 0 deletions WolvenKit.CR2W/Types/BufferedTypes/BufferStructs/SUmbraTileData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.IO;
using WolvenKit.CR2W.Editors;
using System.Diagnostics;
using System.Runtime.Serialization;
using static WolvenKit.CR2W.Types.Enums;
using WolvenKit.CR2W.Reflection;
using FastMember;

namespace WolvenKit.CR2W.Types
{
[REDMeta(EREDMetaInfo.REDStruct)]
public class SUmbraTileData : CVariable
{
[Ordinal(1000)] [REDBuffer] public CUInt64 Hash { get; set; }
[Ordinal(1001)] [REDBuffer] public CUInt16 Index { get; set; }
[Ordinal(1001)] [REDBuffer] public CUInt8 Flag1 { get; set; }
[Ordinal(1001)] [REDBuffer] public CUInt8 Flag2 { get; set; }

public SUmbraTileData(CR2WFile cr2w, CVariable parent, string name) :
base(cr2w, parent, name)
{

}


}
}
2 changes: 1 addition & 1 deletion WolvenKit.CR2W/Types/BufferedTypes/BufferedClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public partial class CWayPointsCollectionsSet : CResource
public partial class CUmbraTile : CResource
{

//[Ordinal(1000)] [REDBuffer] public CBufferUInt32<CHandle<>> Tiles { get; set; }
[Ordinal(1000)] [REDBuffer] public CBufferUInt32<SUmbraTileData> Tiles { get; set; }


}
Expand Down
File renamed without changes.
Loading

0 comments on commit ee03e4d

Please sign in to comment.