Skip to content

Commit

Permalink
Fixed the path being ignored if a texture has a valid hash as a name.…
Browse files Browse the repository at this point in the history
… (Texture names will only be treated as hashes if they're in the root of the texture folder.) Reorganized menu options to be more sensical.
  • Loading branch information
BobDoleOwndU committed Apr 26, 2022
1 parent 39fc4a7 commit f33f928
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CopyMaterialsWindow : EditorWindow
private GameObject sourceModel;
private GameObject targetModel;

[MenuItem("FMDL Studio/Copy Mesh Settings", false, 400)]
[MenuItem("FMDL Studio/Copy Mesh Settings", false, 304)]
static void Init()
{
CopyMaterialsWindow window = (CopyMaterialsWindow)GetWindow(typeof(CopyMaterialsWindow));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ public static void FixTangents()
Debug.Log("No objects selected.");
} //FixTangents

[MenuItem("FMDL Studio/Reload Dictionaries", false, 102)]
public static void ReloadDictionaries()
{
Hashing.LoadDictionaries();
} //ReloadDictionaries

[MenuItem("FMDL Studio/Fmdl Version/2.03 (GZ\u200A\u2215\u200APES)", false, 103)]
public static void SetFmdlVersionToGZ()
{
Globals.SetFmdlVersion(2.03f);
Debug.Log("Fmdl version set to 2.03");
} //SetFmdlVersionToGZ

[MenuItem("FMDL Studio/Fmdl Version/2.04 (TPP)", false, 104)]
public static void SetFmdlVersionToTPP()
{
Globals.SetFmdlVersion(2.04f);
Debug.Log("Fmdl version set to 2.04");
} //SetFmdlVersionToTPP

[MenuItem("FMDL Studio/Set Texture Folder", false, 200)]
public static void SetTextureFolder()
{
Expand All @@ -120,7 +140,7 @@ public static void SetTextureFolder()
Debug.Log("No folder selected.");
} //SetTextureFolder

[MenuItem("FMDL Studio/Set FBX Converter Path", false, 202)]
[MenuItem("FMDL Studio/Set FBX Converter Path", false, 201)]
public static void SetFbxConverterPath()
{
string filePath = EditorUtility.OpenFilePanel("Select FbxConverter.exe", "", "exe");
Expand All @@ -133,21 +153,7 @@ public static void SetFbxConverterPath()
Debug.Log("No folder selected.");
} //SetFbxConverterPath

[MenuItem("FMDL Studio/Fmdl Version/2.03 (GZ\u200A\u2215\u200APES)", false, 203)]
public static void SetFmdlVersionToGZ()
{
Globals.SetFmdlVersion(2.03f);
Debug.Log("Fmdl version set to 2.03");
} //SetFmdlVersionToGZ

[MenuItem("FMDL Studio/Fmdl Version/2.04 (TPP)", false, 204)]
public static void SetFmdlVersionToTPP()
{
Globals.SetFmdlVersion(2.04f);
Debug.Log("Fmdl version set to 2.04");
} //SetFmdlVersionToTPP

[MenuItem("FMDL Studio/Bounding Box Tools/Copy Bounding Boxes", false, 300)]
[MenuItem("FMDL Studio/Bounding Box Tools/Copy Bounding Boxes", false, 301)]
public static void CopyBoundingBoxes()
{
if (Selection.activeGameObject != null)
Expand All @@ -159,7 +165,7 @@ public static void CopyBoundingBoxes()
Debug.Log("No objects selected.");
} //CopyBoundingBoxes

[MenuItem("FMDL Studio/Bounding Box Tools/Paste Bounding Boxes", false, 301)]
[MenuItem("FMDL Studio/Bounding Box Tools/Paste Bounding Boxes", false, 302)]
public static void PasteBoundingBoxes()
{
if (Selection.activeGameObject != null)
Expand All @@ -171,7 +177,7 @@ public static void PasteBoundingBoxes()
Debug.Log("No objects selected.");
} //CopyBoundingBoxes

[MenuItem("FMDL Studio/Bounding Box Tools/Clear Bounding Boxes", false, 302)]
[MenuItem("FMDL Studio/Bounding Box Tools/Clear Bounding Boxes", false, 303)]
public static void ClearBoundingBoxes()
{
if (Selection.activeGameObject != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MaterialEditorWindow : EditorWindow
private int selected = 0;
private string materialName = "";

[MenuItem("FMDL Studio/Edit Material Presets", false, 201)]
[MenuItem("FMDL Studio/Edit Material Presets", false, 300)]
static void Init()
{
MaterialEditorWindow window = (MaterialEditorWindow)GetWindow(typeof(MaterialEditorWindow));
Expand Down
15 changes: 12 additions & 3 deletions FMDL-Studio-v2/Assets/Fmdl Studio/Scripts/Classes/Fmdl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,6 @@ private void GetFmdlData(GameObject gameObject)
} //if
else
{
texturePath = texturePath + textureName + ".ftex";

fmdlTexture.nameIndex = (ushort)strCode64s.Count;

ulong nameHash;
Expand All @@ -1612,13 +1610,24 @@ private void GetFmdlData(GameObject gameObject)

fmdlTexture.pathIndex = (ushort)pathCode64s.Count;

Debug.Log($"Path: {texturePath}, Name: {textureName}");

ulong pathHash;
ulong.TryParse(textureName, NumberStyles.HexNumber, new CultureInfo("en-US"), out pathHash);

if (texturePath == "/")
ulong.TryParse(textureName, NumberStyles.HexNumber, new CultureInfo("en-US"), out pathHash);
else
pathHash = 0;

if (pathHash == 0)
{
texturePath = texturePath + textureName + ".ftex";
pathHash = Hashing.HashFileNameWithExtension(texturePath);
} //if
else
{
pathHash += 0x1568000000000000; //Add extension bytes.
} //else

pathCode64s.Add(pathHash);
} //else
Expand Down
9 changes: 7 additions & 2 deletions FMDL-Studio-v2/Assets/Fmdl Studio/Scripts/Static/Hashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ public static class Hashing

static Hashing()
{
ReadStringDictionary("Assets/Fmdl Studio/fmdl_dictionary.txt");
ReadPathDictionary("Assets/Fmdl Studio/qar_dictionary.txt");
LoadDictionaries();
} //constructor

public static ulong HashFileExtension(string fileExtension) //from private to public
Expand Down Expand Up @@ -291,6 +290,12 @@ public static void ReadPathDictionary(string path)
} //foreach
} //ReadPathDictionary

public static void LoadDictionaries()
{
ReadStringDictionary("Assets/Fmdl Studio/fmdl_dictionary.txt");
ReadPathDictionary("Assets/Fmdl Studio/qar_dictionary.txt");
} //LoadDictionaries

public static string TryGetStringName(ulong hash)
{
for (int i = 0; i < stringHashDictionary.Count; i++)
Expand Down

0 comments on commit f33f928

Please sign in to comment.