Skip to content

Commit

Permalink
removed cyclic ref
Browse files Browse the repository at this point in the history
  • Loading branch information
GoneUp committed Jul 23, 2020
1 parent b990b74 commit 71a6e3c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions GPK_RePack/Editors/TextureTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void exportTexture(GpkExport export, string file)
if (image == null || ddsFile == null)
return;

image.SaveObject(file, new DdsSaveConfig(image.GetFormat(), 0, 0, false, false));
image.SaveObject(file, new DdsSaveConfig(image.parsedImageFormat, 0, 0, false, false));
}
catch (Exception ex)
{
Expand All @@ -47,7 +47,7 @@ public static void importTexture(GpkExport export, string file)
var texture2d = export.Payload as Texture2D;

var image = new DdsFile();
var config = new DdsSaveConfig(texture2d.GetFormat(), 0, 0, false, false);
var config = new DdsSaveConfig(texture2d.parsedImageFormat, 0, 0, false, false);
image.Load(file);

if (image.MipMaps.Count == 0 || Settings.Default.GenerateMipMaps)
Expand Down
1 change: 1 addition & 0 deletions GPK_RePack/Forms/GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ private Dictionary<String, List<CompositeMapEntry>> filterCompositeList(string t
}
catch (Exception ex)
{
logger.Error(ex, "filter fail");
return gpkStore.CompositeMap;
}
}
Expand Down
3 changes: 3 additions & 0 deletions GPK_RePack/IO/MassDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ public static void DumpMassTextures(GpkStore store, String outdir, Dictionary<St
logger.Info("Extracted texture {0} to {1}", entry.UID, imagePath);
}
//remove ref to ease gc
exports.Clear();
package = null;
runningTasks.Remove(newTask);
});

Expand Down
29 changes: 16 additions & 13 deletions GPK_RePack/Model/Payload/Texture2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ class Texture2D : IPayload
{
private static Logger logger = LogManager.GetCurrentClassLogger();

public GpkExport objectExport;
public byte[] startUnk;
public string tgaPath;
public bool inUnicode = false;
public byte[] guid;

public FileFormat parsedImageFormat;

private const CompressionTypes NothingToDo = CompressionTypes.Unused | CompressionTypes.StoreInSeparatefile;

Expand Down Expand Up @@ -69,7 +68,7 @@ public void WriteData(BinaryWriter writer, GpkPackage package, GpkExport export)
int chunkSize = 16 + map.blocks.Count * 8 + map.compressedSize;
if (chunkSize != map.compChunkSize)
{
logger.Debug("fixing chunksize for " + objectExport.ObjectName);
logger.Debug("fixing chunksize for " + export.ObjectName);
map.compChunkSize = chunkSize;
}

Expand Down Expand Up @@ -124,10 +123,10 @@ public void WriteData(BinaryWriter writer, GpkPackage package, GpkExport export)

public void ReadData(GpkPackage package, GpkExport export)
{
objectExport = export;
BinaryReader reader = new BinaryReader(new MemoryStream(export.Data));
IProperty formatProp = export.Properties.Find(t => ((GpkBaseProperty)t).name == "Format");
String format = ((GpkByteProperty)formatProp).nameValue;
SaveFormat(export);

startUnk = reader.ReadBytes(12);
int mipMapCountOffset = reader.ReadInt32();
Expand Down Expand Up @@ -308,14 +307,18 @@ public override string ToString()
}


public FileFormat GetFormat()
public void SaveFormat(GpkExport export)
{
GpkByteProperty formatProp = objectExport.GetProperty("Format") as GpkByteProperty;
if (formatProp == null) return FileFormat.Unknown;

string format = formatProp.nameValue;

return DdsPixelFormat.ParseFileFormat(format);
GpkByteProperty formatProp = export.GetProperty("Format") as GpkByteProperty;
if (formatProp == null)
{
parsedImageFormat = FileFormat.Unknown;
}
else
{
string format = formatProp.nameValue;
parsedImageFormat = DdsPixelFormat.ParseFileFormat(format);
}
}

public Stream GetObjectStream()
Expand All @@ -332,7 +335,7 @@ public Stream GetObjectStream()
private Stream buildDdsImage(int mipMapIndex)
{
MipMap mipMap = maps[mipMapIndex];
DdsHeader ddsHeader = new DdsHeader(new DdsSaveConfig(GetFormat(), 0, 0, false, false), mipMap.sizeX, mipMap.sizeY);
DdsHeader ddsHeader = new DdsHeader(new DdsSaveConfig(parsedImageFormat, 0, 0, false, false), mipMap.sizeX, mipMap.sizeY);

MemoryStream stream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(stream);
Expand All @@ -353,7 +356,7 @@ public void SaveObject(string filename, object configuration)
if (maps == null || !maps.Any()) return;

DdsSaveConfig config = configuration as DdsSaveConfig ?? new DdsSaveConfig(FileFormat.Unknown, 0, 0, false, false);
config.FileFormat = GetFormat();
config.FileFormat = parsedImageFormat;

//parse uncompressed image
DdsFile ddsImage = new DdsFile(GetObjectStream());
Expand Down
1 change: 0 additions & 1 deletion GPK_RePack/Model/Prop/GpkBaseProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class GpkBaseProperty
public string type; //long index
public int size;
public int arrayIndex;
public object value;

public GpkBaseProperty()
{
Expand Down

0 comments on commit 71a6e3c

Please sign in to comment.