RE7 Fixes

This commit is contained in:
Scobalula 2019-11-23 00:27:50 +00:00
parent a545324002
commit 38dae7b9f2
6 changed files with 237 additions and 128 deletions

View file

@ -46,3 +46,14 @@ Greyhound is distributed with an automatic updater that will check for updates e
## Reporting Bugs ## Reporting Bugs
Bugs can be reported through the Github issues or through the Discord server. Please make sure to provide a log when reporting bugs and any info you can possibly give. Bugs can be reported through the Github issues or through the Discord server. Please make sure to provide a log when reporting bugs and any info you can possibly give.
## FAQ
* **Q**: I can't find some models?
* **A**: Not all assets have names as entries within the archives are hashed, currently you can enable the setting to show all assets and in the future the tool will attempt to convert these if they are supported, however currently they are dumped raw.
* **Q**: Some models export with no images?
* **A**: The tool attempts to locate the material files based off the model name, this works for most models, but not all, in the future material defs will be exportable on their own to aid with models where the materials cannot be located.
* **Q**: Some models export with incorrect UVs?
* **A**: A lot of materials rely on UV scales and offsets, currently it is unknown what data defines this. Usually this easy to fix by shifting the UVs yourself, or spliting the images, as it is usually used where 1 image contains multiple variants.

View file

@ -33,6 +33,27 @@ namespace Tyrant.Logic
/// Resident Evil 7 Material Entry /// Resident Evil 7 Material Entry
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct MaterialEntryRE7
{
public long NamePointer;
public uint Hash; // MurMur3
public uint Unk01;
public uint Unk02;
public int SettingsBufferSize;
public int SettingsInfoCount;
public int TextureCount;
public int Unk03;
public int Unk04;
public long SettingsInfoPointer;
public long TexturesPointer;
public long SettingsBufferPointer;
public long ShaderNamePointer;
}
/// <summary>
/// Resident Evil 2 Material Entry
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct MaterialEntryRE2 internal struct MaterialEntryRE2
{ {
public long NamePointer; public long NamePointer;
@ -76,23 +97,40 @@ namespace Tyrant.Logic
/// <summary> /// <summary>
/// Converts the given material file /// Converts the given material file
/// </summary> /// </summary>
public static Dictionary<string, Model.Material> Convert(byte[] buffer) public static Dictionary<string, Model.Material> ConvertRE7(BinaryReader reader)
{ {
using (var stream = new MemoryStream(buffer)) var results = new Dictionary<string, Model.Material>();
{ {
return Convert(stream); reader.BaseStream.Position = 0;
var header = reader.ReadStruct<MaterialHeaderRE7>();
var materials = reader.ReadArray<MaterialEntryRE7>(header.MaterialCount);
foreach (var material in materials)
{
var result = new Model.Material(reader.ReadUTF16NullTerminatedString(material.NamePointer));
foreach (var texture in reader.ReadArray<MaterialTextureEntryRE7>(material.TexturesPointer, material.TextureCount))
result.Images[reader.ReadUTF16NullTerminatedString(texture.TypePointer)] = reader.ReadUTF16NullTerminatedString(texture.TextureNamePointer).ToLower();
foreach (var setting in reader.ReadArray<MaterialSettingsInfoRE7>(material.SettingsInfoPointer, material.SettingsInfoCount))
result.Settings[reader.ReadUTF16NullTerminatedString(setting.NamePointer)] = reader.ReadArray<float>(material.SettingsBufferPointer + setting.DataOffset, setting.DataCount);
results[result.Name] = result;
} }
} }
return results;
}
/// <summary> /// <summary>
/// Converts the given material file /// Converts the given material file
/// </summary> /// </summary>
public static Dictionary<string, Model.Material> Convert(Stream stream) public static Dictionary<string, Model.Material> ConvertRE2(BinaryReader reader)
{ {
var results = new Dictionary<string, Model.Material>(); var results = new Dictionary<string, Model.Material>();
using (var reader = new BinaryReader(stream))
{ {
reader.BaseStream.Position = 0;
var header = reader.ReadStruct<MaterialHeaderRE7>(); var header = reader.ReadStruct<MaterialHeaderRE7>();
var materials = reader.ReadArray<MaterialEntryRE2>(header.MaterialCount); var materials = reader.ReadArray<MaterialEntryRE2>(header.MaterialCount);
@ -111,5 +149,37 @@ namespace Tyrant.Logic
return results; return results;
} }
/// <summary>
/// Converts the given material file
/// </summary>
public static Dictionary<string, Model.Material> Convert(byte[] buffer)
{
using (var stream = new MemoryStream(buffer))
{
return Convert(stream);
}
}
/// <summary>
/// Converts the given material file
/// </summary>
public static Dictionary<string, Model.Material> Convert(Stream stream)
{
using (var reader = new BinaryReader(stream))
{
reader.BaseStream.Position = 28;
// Check size of buffer
if(reader.ReadUInt32() != 0)
{
return ConvertRE2(reader);
}
else
{
return ConvertRE7(reader);
}
}
}
} }
} }

View file

@ -325,9 +325,7 @@ namespace Tyrant.Logic
foreach (var boneNameIndex in reader.ReadArray<ushort>(header.BoneNamesPointer, boneDataHeader.BoneCount)) foreach (var boneNameIndex in reader.ReadArray<ushort>(header.BoneNamesPointer, boneDataHeader.BoneCount))
boneNames.Add(strings[boneNameIndex]); boneNames.Add(strings[boneNameIndex]);
Model model = new Model(); var bones = new List<Model.Bone>(boneDataHeader.BoneCount);
if (header.BoneDataHeaderPointer > 0) if (header.BoneDataHeaderPointer > 0)
{ {
@ -341,22 +339,40 @@ namespace Tyrant.Logic
boneMatrices[i].W.Y, boneMatrices[i].W.Y,
boneMatrices[i].W.Z), boneMatrices[i].ToQuaternion()); boneMatrices[i].W.Z), boneMatrices[i].ToQuaternion());
model.Bones.Add(bone); bones.Add(bone);
} }
} }
var modelHeader = reader.ReadStruct<ModelHeaderRE7>(header.ModelPointers[0]); bool firstMdlProcessed = false;
for (int mdl = 0; mdl < 3; mdl++)
{
if (header.ModelPointers[mdl] == 0)
continue;
if (firstMdlProcessed)
break;
var lods = new List<Model>();
var modelHeader = reader.ReadStruct<ModelHeaderRE7>(header.ModelPointers[mdl]);
var vertexSize = 20 + (modelHeader.UVCount * 4) + (boneDataHeader.BoneCount > 0 ? 16 : 0); var vertexSize = 20 + (modelHeader.UVCount * 4) + (boneDataHeader.BoneCount > 0 ? 16 : 0);
reader.BaseStream.Position = header.ModelPointers[0] + 64; reader.BaseStream.Position = header.ModelPointers[mdl] + (firstMdlProcessed ? 16 : 64);
var materialIndices = reader.ReadArray<short>(header.MaterialNamesPointer, modelHeader.MaterialCount); var materialIndices = reader.ReadArray<short>(header.MaterialNamesPointer, modelHeader.MaterialCount);
firstMdlProcessed = true;
var lodPointers = reader.ReadArray<long>(reader.ReadInt64(), modelHeader.LODCount); var lodPointers = reader.ReadArray<long>(reader.ReadInt64(), modelHeader.LODCount);
var uniqueMaterials = new List<string>(modelHeader.MaterialCount);
foreach (var lodPointer in lodPointers) foreach (var lodPointer in lodPointers)
{ {
var model = new Model()
{
Bones = bones
};
var uniqueMaterials = new List<string>(modelHeader.MaterialCount);
var lodHeader = reader.ReadStruct<LODHeaderRE7>(lodPointer); var lodHeader = reader.ReadStruct<LODHeaderRE7>(lodPointer);
var boneIndices = reader.ReadArray<short>(lodPointer + 16, lodHeader.BoneCount); var boneIndices = reader.ReadArray<short>(lodPointer + 16, lodHeader.BoneCount);
@ -468,16 +484,14 @@ namespace Tyrant.Logic
foreach (var materialName in uniqueMaterials) foreach (var materialName in uniqueMaterials)
{ {
var material = new Model.Material(materialName); model.Materials.Add(new Model.Material(materialName));
} }
break; lods.Add(model);
} }
results.Add(new List<Model> results.Add(lods);
{ }
model
});
return results; return results;
} }
@ -548,6 +562,9 @@ namespace Tyrant.Logic
if (header.ModelPointers[mdl] == 0) if (header.ModelPointers[mdl] == 0)
continue; continue;
if (firstMdlProcessed)
break;
var lods = new List<Model>(); var lods = new List<Model>();
var modelHeader = reader.ReadStruct<ModelHeaderRE7>(header.ModelPointers[mdl]); var modelHeader = reader.ReadStruct<ModelHeaderRE7>(header.ModelPointers[mdl]);

View file

@ -51,5 +51,5 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.1")]

View file

@ -79,8 +79,11 @@ namespace Tyrant
{ {
".mdf2.10", ".mdf2.10",
"_mat.mdf2.10", "_mat.mdf2.10",
".mdf2.6",
"_mat.mdf2.6",
".10", ".10",
".11", ".11",
".8",
}; };
/// <summary> /// <summary>
@ -361,6 +364,13 @@ namespace Tyrant
} }
} }
private void ExportUnknownFile(Package.Entry entry, string name)
{
Directory.CreateDirectory(Path.GetDirectoryName(name));
File.WriteAllBytes(name, ActivePackage.LoadEntry(entry));
}
/// <summary> /// <summary>
/// Exports a Model Asset /// Exports a Model Asset
/// </summary> /// </summary>
@ -468,6 +478,7 @@ namespace Tyrant
ExportMotionList(asset.PackageEntry, Path.Combine("exported_files", asset.Name)); ExportMotionList(asset.PackageEntry, Path.Combine("exported_files", asset.Name));
break; break;
default: default:
ExportUnknownFile(asset.PackageEntry, Path.Combine("exported_files", asset.Name));
break; break;
} }