Skip to content

Commit

Permalink
fix bugs + preview 41 release
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Jun 13, 2019
1 parent 630a837 commit ba685bd
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 75 deletions.
16 changes: 11 additions & 5 deletions IndustrialPark/ArchiveEditor/ArchiveEditorFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void OpenFile(string fileName)
autoCompleteSource.AddRange(autoComplete.ToArray());

if (GetAssetsOfType(AssetType.RWTX).Any())
SetupCustomTextures();
SetupTextureDisplay();

RecalculateAllMatrices();

Expand Down Expand Up @@ -517,7 +517,7 @@ private void AddAssetToDictionary(Section_AHDR AHDR, bool fast = false)
private static string pathToGcTXD => tempGcTxdsDir + "temp.txd";
private static string pathToPcTXD => tempPcTxdsDir + "temp.txd";

private void SetupCustomTextures()
public void SetupTextureDisplay()
{
if (!Directory.Exists(tempGcTxdsDir))
Directory.CreateDirectory(tempGcTxdsDir);
Expand All @@ -528,7 +528,8 @@ private void SetupCustomTextures()

PerformTXDConversionExternal();

TextureManager.LoadTexturesFromTXD(pathToPcTXD);
TextureManager.LoadTexturesFromTXD(pathToPcTXD, false);
TextureManager.ReapplyTextures();

File.Delete(pathToGcTXD);
File.Delete(pathToPcTXD);
Expand Down Expand Up @@ -565,7 +566,11 @@ private static void PerformTXDConversionExternal(bool toPC = true, bool compress
"gameRoot=" + tempPcTxdsDir + "\r\n" +
"outputRoot=" + tempGcTxdsDir + "\r\n" +
"targetVersion=VC\r\n" +
"targetPlatform=Gamecube\r\n") +
"targetPlatform=" +
(currentPlatform == Platform.GameCube ? "Gamecube" :
currentPlatform == Platform.Xbox ? "XBOX" :
currentPlatform == Platform.PS2 ? "PS2" : "PC")
+ "\r\n") +

"clearMipmaps=false\r\n" +
"generateMipmaps=" + generateMipmaps.ToString().ToLower() + "\r\n" +
Expand Down Expand Up @@ -802,7 +807,8 @@ public bool ImportMultipleAssets(int layerIndex, List<Section_AHDR> AHDRs, out L

if (overwrite)
{
RemoveAsset(AHDR.assetID);
if (ContainsAsset(AHDR.assetID))
RemoveAsset(AHDR.assetID);
AddAsset(layerIndex, AHDR);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,24 @@ private void MergeSNDI(Section_AHDR AHDR)
}
}

public static int scoobyTextureVersion => 0x0C02FFFF;
public static int bfbbTextureVersion => 0x1003FFFF;
public static int tssmTextureVersion => 0x1C02000A;

public static int currentTextureVersion
{
get
{
if (currentGame == Game.Scooby)
return scoobyTextureVersion;
if (currentGame == Game.BFBB)
return bfbbTextureVersion; // VC
if (currentGame == Game.Incredibles)
return tssmTextureVersion; // Bully
return 0;
}
}

public static void ExportSingleTextureToDictionary(string fileName, Section_AHDR RWTX)
{
ExportSingleTextureToDictionary(fileName, RWTX.data, RWTX.ADBG.assetName.Replace(".RW3", ""));
Expand Down Expand Up @@ -646,7 +664,7 @@ public void AddTextureDictionary(string fileName, bool RW3)
ReadFileMethods.treatStuffAsByteArray = false;
}

public static Section_AHDR CreateRWTXFromPNG(string fileName, bool appendRW3, bool flip, bool mipmaps, bool compress)
public static Section_AHDR CreateRWTXFromBitmap(string fileName, bool appendRW3, bool flip, bool mipmaps, bool compress)
{
string textureName = Path.GetFileNameWithoutExtension(fileName);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fileName);
Expand Down Expand Up @@ -703,14 +721,18 @@ public static Section_AHDR CreateRWTXFromPNG(string fileName, bool appendRW3, bo
if (!Directory.Exists(tempGcTxdsDir))
Directory.CreateDirectory(tempGcTxdsDir);

ExportSingleTextureToDictionary(pathToPcTXD, ReadFileMethods.ExportRenderWareFile(td, 0x1003FFFF), textureName);
ExportSingleTextureToDictionary(pathToPcTXD, ReadFileMethods.ExportRenderWareFile(td, currentTextureVersion), textureName);

PerformTXDConversionExternal(false, compress, mipmaps);

string assetName = textureName + (appendRW3 ? ".RW3" : "");

Section_ADBG ADBG = new Section_ADBG(0, assetName, "", 0);
Section_AHDR AHDR = new Section_AHDR(BKDRHash(assetName), AssetType.RWTX, AHDRFlagsFromAssetType(AssetType.RWTX), ADBG, File.ReadAllBytes(pathToGcTXD));
ReadFileMethods.treatStuffAsByteArray = true;

Section_AHDR AHDR = new Section_AHDR(BKDRHash(assetName), AssetType.RWTX, AHDRFlagsFromAssetType(AssetType.RWTX),
new Section_ADBG(0, assetName, "", 0), ReadFileMethods.ExportRenderWareFile(ReadFileMethods.ReadRenderWareFile(pathToGcTXD), currentTextureVersion));

ReadFileMethods.treatStuffAsByteArray = false;

File.Delete(pathToGcTXD);
File.Delete(pathToPcTXD);
Expand Down
10 changes: 6 additions & 4 deletions IndustrialPark/ArchiveEditor/Dialogs/ImportTextures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ public ImportTextures()
buttonOK.Enabled = false;
TopMost = true;
}

public static string filter => "All supported formats|*.bmp;*.png;*.gif;*.jpg;*.jpeg;*.jpe;*.jif;*.jfif;*.jfi;*.tif;*.tiff;*.rwtex|All files|*";

List<string> filePaths = new List<string>();
private List<string> filePaths = new List<string>();

private void buttonImportRawData_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog()
{
Multiselect = true,
Filter = "All supported formats|*.png;*.bmp;*.rwtex|PNG files|*.png|BMP files|*.bmp|RWTEX files|*.rwtex|All files|*"
Filter = filter
};

if (openFileDialog.ShowDialog() == DialogResult.OK)
Expand Down Expand Up @@ -79,7 +81,7 @@ public static List<Section_AHDR> GetAssets(out bool success, out bool overwrite)
textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = 1, unknown = 0 },
textureNativeList = new List<TextureNative_0015>() { new TextureNative_0015().FromBytes(File.ReadAllBytes(a.filePaths[i])) },
textureDictionaryExtension = new Extension_0003()
}, 0x1003FFFF);
}, ArchiveEditorFunctions.currentTextureVersion);

string assetName = Path.GetFileNameWithoutExtension(a.filePaths[i]) + (a.checkBoxRW3.Checked ? ".RW3" : "");

Expand All @@ -90,7 +92,7 @@ public static List<Section_AHDR> GetAssets(out bool success, out bool overwrite)
}
else
{
AHDRs.Add(ArchiveEditorFunctions.CreateRWTXFromPNG(a.filePaths[i], a.checkBoxRW3.Checked, a.checkBoxFlipTextures.Checked, a.checkBoxMipmaps.Checked, a.checkBoxCompress.Checked));
AHDRs.Add(ArchiveEditorFunctions.CreateRWTXFromBitmap(a.filePaths[i], a.checkBoxRW3.Checked, a.checkBoxFlipTextures.Checked, a.checkBoxMipmaps.Checked, a.checkBoxCompress.Checked));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public InternalTextureEditor(AssetRWTX asset, ArchiveEditorFunctions archive)

this.asset = asset;
this.archive = archive;

if (asset.AHDR.assetType != HipHopFile.AssetType.MODL)
buttonImport.Enabled = false;


propertyGridAsset.SelectedObject = asset;
labelAssetName.Text = $"[{asset.AHDR.assetType.ToString()}] {asset.ToString()}";
}
Expand Down Expand Up @@ -72,7 +69,7 @@ private void buttonImport_Click(object sender, System.EventArgs e)
{
OpenFileDialog a = new OpenFileDialog()
{
Filter = "All supported formats|*.png;*.rwtex|PNG Files|*.png|RWTEX Files|*.rwtex"
Filter = ImportTextures.filter
};

if (a.ShowDialog() == DialogResult.OK)
Expand All @@ -88,11 +85,11 @@ private void buttonImport_Click(object sender, System.EventArgs e)
textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = 1, unknown = 0 },
textureNativeList = new List<TextureNative_0015>() { new TextureNative_0015().FromBytes(File.ReadAllBytes(i)) },
textureDictionaryExtension = new Extension_0003()
}, 0x1003FFFF);
}, ArchiveEditorFunctions.currentTextureVersion);
}
else
{
asset.Data = ArchiveEditorFunctions.CreateRWTXFromPNG(i, false, false, true, true).data;
asset.Data = ArchiveEditorFunctions.CreateRWTXFromBitmap(i, false, false, true, true).data;
}

archive.EnableTextureForDisplay(asset);
Expand Down
2 changes: 1 addition & 1 deletion IndustrialPark/MainForm/AboutBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AboutBox()
this.labelCompanyName.Text = AssemblyCompany;
ComponentResourceManager resources = new ComponentResourceManager(typeof(AboutBox));
this.textBoxDescription.Text = resources.GetString("textBoxDescription.Text");
this.labelVersion.Text = new IPversion().versionName;
this.labelVersion.Text = new IPversion().versionName.Split('.')[0];
TopMost = true;
}

Expand Down
4 changes: 2 additions & 2 deletions IndustrialPark/MainForm/Json/IPversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class IPversion
{
public string version = "preview40";
public string versionName = "Preview 40. Automatic updates; Download EditorFiles; Merge similar assets; Xbox saving fix";
public string version = "preview41";
public string versionName = "Preview 41. Load textures from HOP. Import textures from image files (Archive Editor->Edit->Import Textures).";
}
}
10 changes: 1 addition & 9 deletions IndustrialPark/MainForm/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,7 @@ private void ApplySettings(ProjectJson ipSettings)
foreach (ArchiveEditor ae in archiveEditors)
ae.CloseArchiveEditor();

foreach (string s in ipSettings.TextureFolderPaths)
if (Directory.Exists(s))
TextureManager.LoadTexturesFromFolder(s);
else
{
TopMost = true;
MessageBox.Show("Error loading textures from " + s + ": folder not found");
TopMost = false;
}
TextureManager.LoadTexturesFromFolder(ipSettings.TextureFolderPaths);

ArchiveEditorFunctions.hiddenAssets = ipSettings.hiddenAssets;
HipHopFile.Functions.currentPlatform = ipSettings.platformForScooby;
Expand Down
4 changes: 2 additions & 2 deletions IndustrialPark/Resources/ip_version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "preview40",
"versionName": "Preview 40. Automatic updates; Download EditorFiles; Merge similar assets; Xbox saving fix"
"version": "preview41",
"versionName": "Preview 41. Load textures from HOP. Import textures from image files (Archive Editor->Edit->Import Textures)."
}
67 changes: 26 additions & 41 deletions IndustrialPark/SharpDX/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RenderWareFile;
using RenderWareFile.Sections;
using HipHopFile;
using System.Linq;

namespace IndustrialPark
{
Expand Down Expand Up @@ -42,71 +43,53 @@ public static ShaderResourceView GetTextureFromDictionary(uint assetID)
return SharpRenderer.whiteDefault;
}

public static void LoadTexturesFromTXD(string textureFile, string textureName = null)
public static void LoadTexturesFromTXD(string textureFile, bool reapply = true)
{
LoadTexturesFromTXD(ReadFileMethods.ReadRenderWareFile(textureFile), textureName);
}

public static void LoadTexturesFromTXD(byte[] txdData, string textureName = null)
{
LoadTexturesFromTXD(ReadFileMethods.ReadRenderWareFile(txdData), textureName);
}

public static void LoadTexturesFromTXD(RWSection[] txdFile, string textureName = null)
{
foreach (RWSection rw in txdFile)
foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(textureFile))
if (rw is TextureDictionary_0016 td)
foreach (TextureNative_0015 tn in td.textureNativeList)
AddTextureNative(tn.textureNativeStruct, textureName);
AddTextureNative(tn.textureNativeStruct);

ReapplyTextures();
if (reapply)
ReapplyTextures();
}

private static void AddTextureNative(TextureNativeStruct_0001 tnStruct, string textureName = null)
private static void AddTextureNative(TextureNativeStruct_0001 tnStruct)
{
if (textureName == null)
textureName = tnStruct.textureName;

ShaderResourceView texture;

try { texture = Program.MainForm.renderer.device.LoadTextureFromRenderWareNative(tnStruct); }
catch { return; }

DisposeTexture(textureName);
Textures[textureName] = texture;
DisposeTexture(tnStruct.textureName);
Textures[tnStruct.textureName] = texture;
}

public static void RemoveTexture(string textureName)
{
DisposeTexture(textureName);
Textures[textureName] = SharpRenderer.whiteDefault;
}

public static void LoadTexturesFromFolder(IEnumerable<string> folderNames)
{
foreach (string folderName in folderNames)
{
OpenTextureFolders.Add(folderName);
foreach (string i in Directory.GetFiles(folderName))
if (Path.GetExtension(i).ToLower().Equals(".png"))
AddTexturePNG(i);
}

Textures.Remove(textureName);
ReapplyTextures();
}

public static void LoadTexturesFromFolder(string folderName)
public static void LoadTexturesFromFolder(IEnumerable<string> folderNames)
{
OpenTextureFolders.Add(folderName);

foreach (string i in Directory.GetFiles(folderName))
if (Path.GetExtension(i).ToLower().Equals(".png"))
AddTexturePNG(i);
string[] extensions = new string[] { ".png", ".bmp", ".gif", ".jpg", ".jpeg", ".jpe", ".jif", ".jfif", ".jfi", ".tif", ".tiff" };

foreach (string folderName in folderNames)
if (Directory.Exists(folderName))
{
OpenTextureFolders.Add(folderName);
foreach (string i in Directory.GetFiles(folderName))
if (extensions.Contains(Path.GetExtension(i).ToLower()))
AddTextureBitmap(i);
}
else System.Windows.Forms.MessageBox.Show("Error loading textures from " + folderName + ": folder not found");

ReapplyTextures();
}

private static void AddTexturePNG(string path)
private static void AddTextureBitmap(string path)
{
string textureName = TreatTextureName(Path.GetFileNameWithoutExtension(path));
DisposeTexture(textureName);
Expand Down Expand Up @@ -187,7 +170,9 @@ public static void ClearTextures()
OpenTextureFolders.Clear();
DisposeTextures();
Textures.Clear();
ReapplyTextures();

foreach (ArchiveEditor ae in Program.MainForm.archiveEditors)
ae.archive.SetupTextureDisplay();
}
}
}

0 comments on commit ba685bd

Please sign in to comment.