mirror of
https://github.com/Scobalula/Tyrant
synced 2024-11-10 06:24:14 +00:00
RE7 Fixes
This commit is contained in:
parent
a545324002
commit
38dae7b9f2
6 changed files with 237 additions and 128 deletions
11
README.md
11
README.md
|
@ -46,3 +46,14 @@ Greyhound is distributed with an automatic updater that will check for updates e
|
|||
## 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.
|
||||
|
||||
## 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.
|
Binary file not shown.
|
@ -33,6 +33,27 @@ namespace Tyrant.Logic
|
|||
/// Resident Evil 7 Material Entry
|
||||
/// </summary>
|
||||
[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
|
||||
{
|
||||
public long NamePointer;
|
||||
|
@ -76,23 +97,40 @@ namespace Tyrant.Logic
|
|||
/// <summary>
|
||||
/// Converts the given material file
|
||||
/// </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>
|
||||
/// Converts the given material file
|
||||
/// </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>();
|
||||
|
||||
using (var reader = new BinaryReader(stream))
|
||||
{
|
||||
reader.BaseStream.Position = 0;
|
||||
var header = reader.ReadStruct<MaterialHeaderRE7>();
|
||||
var materials = reader.ReadArray<MaterialEntryRE2>(header.MaterialCount);
|
||||
|
||||
|
@ -111,5 +149,37 @@ namespace Tyrant.Logic
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -325,9 +325,7 @@ namespace Tyrant.Logic
|
|||
foreach (var boneNameIndex in reader.ReadArray<ushort>(header.BoneNamesPointer, boneDataHeader.BoneCount))
|
||||
boneNames.Add(strings[boneNameIndex]);
|
||||
|
||||
Model model = new Model();
|
||||
|
||||
|
||||
var bones = new List<Model.Bone>(boneDataHeader.BoneCount);
|
||||
|
||||
if (header.BoneDataHeaderPointer > 0)
|
||||
{
|
||||
|
@ -341,22 +339,40 @@ namespace Tyrant.Logic
|
|||
boneMatrices[i].W.Y,
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
firstMdlProcessed = true;
|
||||
|
||||
var lodPointers = reader.ReadArray<long>(reader.ReadInt64(), modelHeader.LODCount);
|
||||
|
||||
var uniqueMaterials = new List<string>(modelHeader.MaterialCount);
|
||||
|
||||
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 boneIndices = reader.ReadArray<short>(lodPointer + 16, lodHeader.BoneCount);
|
||||
|
@ -468,16 +484,14 @@ namespace Tyrant.Logic
|
|||
|
||||
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>
|
||||
{
|
||||
model
|
||||
});
|
||||
results.Add(lods);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
@ -548,6 +562,9 @@ namespace Tyrant.Logic
|
|||
if (header.ModelPointers[mdl] == 0)
|
||||
continue;
|
||||
|
||||
if (firstMdlProcessed)
|
||||
break;
|
||||
|
||||
var lods = new List<Model>();
|
||||
|
||||
var modelHeader = reader.ReadStruct<ModelHeaderRE7>(header.ModelPointers[mdl]);
|
||||
|
|
|
@ -51,5 +51,5 @@ using System.Windows;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.0.0.1")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.1")]
|
||||
|
|
|
@ -79,8 +79,11 @@ namespace Tyrant
|
|||
{
|
||||
".mdf2.10",
|
||||
"_mat.mdf2.10",
|
||||
".mdf2.6",
|
||||
"_mat.mdf2.6",
|
||||
".10",
|
||||
".11",
|
||||
".8",
|
||||
};
|
||||
|
||||
/// <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>
|
||||
/// Exports a Model Asset
|
||||
/// </summary>
|
||||
|
@ -468,6 +478,7 @@ namespace Tyrant
|
|||
ExportMotionList(asset.PackageEntry, Path.Combine("exported_files", asset.Name));
|
||||
break;
|
||||
default:
|
||||
ExportUnknownFile(asset.PackageEntry, Path.Combine("exported_files", asset.Name));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue