Compare commits

..

5 Commits

5 changed files with 115 additions and 3 deletions

View File

@ -93,3 +93,21 @@ public class PropRenderType : Property
mode = (Mode)reader.ReadUInt32();
}
}
public class PropString : Property
{
public int stringLength;
public string value;
public override void Read(BinaryReader reader)
{
base.Read(reader);
stringLength = reader.ReadInt32();
var tmpName = Encoding.UTF8.GetString(reader.ReadBytes(stringLength));
var idx = tmpName.IndexOf('\0');
if (idx >= 0) tmpName = tmpName[..idx];
value = tmpName;
// var tmpName = Encoding.UTF8.GetString(reader.ReadBytes(length)).Replace("\0", string.Empty);
// value = tmpName[..Math.Min(length - 1, tmpName.Length)];
}
}

View File

@ -105,6 +105,10 @@ public class DbFile
"P$ModelName" => new PropertyChunk<PropModelName>(),
"P$Scale" => new PropertyChunk<PropScale>(),
"P$RenderTyp" => new PropertyChunk<PropRenderType>(),
"P$OTxtRepr0" => new PropertyChunk<PropString>(),
"P$OTxtRepr1" => new PropertyChunk<PropString>(),
"P$OTxtRepr2" => new PropertyChunk<PropString>(),
"P$OTxtRepr3" => new PropertyChunk<PropString>(),
"LD$MetaProp" => new LinkDataMetaProp(),
_ when entryName.StartsWith("L$") => new LinkChunk(),
_ when entryName.StartsWith("P$") => new PropertyChunk<PropGeneric>(),

View File

@ -38,12 +38,20 @@ public class ObjectHierarchy
if (db.Chunks.TryGetValue("P$ModelName", out var modelNamesRaw) &&
db.Chunks.TryGetValue("P$Scale", out var scalesRaw) &&
db.Chunks.TryGetValue("P$RenderTyp", out var renderTypesRaw) &&
db.Chunks.TryGetValue("P$OTxtRepr0", out var txtRepl0Raw) &&
db.Chunks.TryGetValue("P$OTxtRepr1", out var txtRepl1Raw) &&
db.Chunks.TryGetValue("P$OTxtRepr2", out var txtRepl2Raw) &&
db.Chunks.TryGetValue("P$OTxtRepr3", out var txtRepl3Raw) &&
db.Chunks.TryGetValue("L$MetaProp", out var metaPropLinksRaw) &&
db.Chunks.TryGetValue("LD$MetaProp", out var metaPropLinkDataRaw))
{
var modelNames = (PropertyChunk<PropModelName>)modelNamesRaw;
var scales = (PropertyChunk<PropScale>)scalesRaw;
var renderTypes = (PropertyChunk<PropRenderType>)renderTypesRaw;
var txtRepl0s = (PropertyChunk<PropString>)txtRepl0Raw;
var txtRepl1s = (PropertyChunk<PropString>)txtRepl1Raw;
var txtRepl2s = (PropertyChunk<PropString>)txtRepl2Raw;
var txtRepl3s = (PropertyChunk<PropString>)txtRepl3Raw;
var metaPropLinks = (LinkChunk)metaPropLinksRaw;
var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw;
@ -52,12 +60,20 @@ public class ObjectHierarchy
gam.Chunks.TryGetValue("P$ModelName", out var gamModelNames) &&
gam.Chunks.TryGetValue("P$Scale", out var gamScales) &&
gam.Chunks.TryGetValue("P$RenderTyp", out var gamRenderTypes) &&
gam.Chunks.TryGetValue("P$OTxtRepr0", out var gamTxtRepl0s) &&
gam.Chunks.TryGetValue("P$OTxtRepr1", out var gamTxtRepl1s) &&
gam.Chunks.TryGetValue("P$OTxtRepr2", out var gamTxtRepl2s) &&
gam.Chunks.TryGetValue("P$OTxtRepr3", out var gamTxtRepl3s) &&
gam.Chunks.TryGetValue("L$MetaProp", out var gamLinks) &&
gam.Chunks.TryGetValue("LD$MetaProp", out var gamLinkData))
{
modelNames.properties.AddRange(((PropertyChunk<PropModelName>)gamModelNames).properties);
scales.properties.AddRange(((PropertyChunk<PropScale>)gamScales).properties);
renderTypes.properties.AddRange(((PropertyChunk<PropRenderType>)gamRenderTypes).properties);
txtRepl0s.properties.AddRange(((PropertyChunk<PropString>)gamTxtRepl0s).properties);
txtRepl1s.properties.AddRange(((PropertyChunk<PropString>)gamTxtRepl1s).properties);
txtRepl2s.properties.AddRange(((PropertyChunk<PropString>)gamTxtRepl2s).properties);
txtRepl3s.properties.AddRange(((PropertyChunk<PropString>)gamTxtRepl3s).properties);
metaPropLinks.links.AddRange(((LinkChunk)gamLinks).links);
metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamLinkData).linkData);
}
@ -108,6 +124,22 @@ public class ObjectHierarchy
{
TryAddProp("P$RenderTyp", prop);
}
foreach (var prop in txtRepl0s.properties)
{
TryAddProp("P$OTxtRepr0", prop);
}
foreach (var prop in txtRepl1s.properties)
{
TryAddProp("P$OTxtRepr1", prop);
}
foreach (var prop in txtRepl2s.properties)
{
TryAddProp("P$OTxtRepr2", prop);
}
foreach (var prop in txtRepl3s.properties)
{
TryAddProp("P$OTxtRepr3", prop);
}
}
}

View File

@ -232,6 +232,10 @@ public partial class Mission : Node3D
var modelNameProp = objHierarchy.GetProperty<PropModelName>(id, "P$ModelName");
var scaleProp = objHierarchy.GetProperty<PropScale>(id, "P$Scale");
var renderTypeProp = objHierarchy.GetProperty<PropRenderType>(id, "P$RenderTyp");
var txtRepl0 = objHierarchy.GetProperty<PropString>(id, "P$OTxtRepr0");
var txtRepl1 = objHierarchy.GetProperty<PropString>(id, "P$OTxtRepr1");
var txtRepl2 = objHierarchy.GetProperty<PropString>(id, "P$OTxtRepr2");
var txtRepl3 = objHierarchy.GetProperty<PropString>(id, "P$OTxtRepr3");
var renderMode = renderTypeProp == null ? PropRenderType.Mode.Normal : renderTypeProp.mode;
if (modelNameProp == null || renderMode == PropRenderType.Mode.NotRendered)
@ -251,6 +255,50 @@ public partial class Mission : Node3D
model.Position = pos;
model.RotationDegrees = rot;
model.Scale = scale;
bool GetTextReplPath(PropString prop, out string path)
{
path = "";
if (prop == null)
{
return false;
}
path = prop.value;
if (path.StartsWith("fam", StringComparison.OrdinalIgnoreCase))
{
path = _installPaths.GetTexturePath(_campaignName, path);
return path != null;
}
// gonna assume obj lol
path = _installPaths.GetObjectTexturePath(_campaignName, path);
return path != null;
}
var repls = new PropString[] { txtRepl0, txtRepl1, txtRepl2, txtRepl3 };
for (var i = 0; i < 4; i++)
{
if (GetTextReplPath(repls[i], out var path))
{
var overrideMat = new StandardMaterial3D
{
AlbedoTexture = TextureLoader.LoadTexture(path)
};
var surfaceCount = model.Mesh.GetSurfaceCount();
for (var idx = 0; idx < surfaceCount; idx++)
{
var surfaceMat = model.Mesh.SurfaceGetMaterial(idx);
if (surfaceMat.HasMeta($"TxtRepl{i}"))
{
model.SetSurfaceOverrideMaterial(idx, overrideMat);
}
}
}
}
AddChild(model);
}
}

View File

@ -34,7 +34,7 @@ public class ModelLoader
// We don't care if this is null actually, we'll still cache that it's null lol
var model = Timing.TimeStage("Load Models", () => { return LoadModel(_pathManager, ref campaignName, modelName); });
_cache[(campaignName, modelName)] = model;
return model;
return model?.Duplicate() as MeshInstance3D;
}
public static MeshInstance3D LoadModel(ResourcePathManager pathManager, ref string campaignName, string modelName)
@ -63,10 +63,20 @@ public class ModelLoader
GD.Print($"Failed to load model texture: {material.Name}");
}
materials.Add(new StandardMaterial3D
var mat = new StandardMaterial3D
{
AlbedoTexture = TextureLoader.LoadTexture(path)
});
};
var name = material.Name.ToLower();
for (var i = 0; i < 4; i++)
{
if (name.Contains($"replace{i}"))
{
mat.SetMeta($"TxtRepl{i}", true);
}
}
materials.Add(mat);
}
else
{