Skip to content

Commit

Permalink
CharInterest, RndTransProxy, fix compile
Browse files Browse the repository at this point in the history
  • Loading branch information
ihatecompvir committed Jan 9, 2025
1 parent 2f83288 commit a9a4334
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 1 deletion.
Binary file added MiloEditor/Images/CharInterest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions MiloEditor/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private void LoadAssetClassImages()
imageList.Images.Add("UIListDir", Image.FromFile("Images/UIListDir.png"));
imageList.Images.Add("UIGuide", Image.FromFile("Images/UIGuide.png"));
imageList.Images.Add("InlineHelp", Image.FromFile("Images/InlineHelp.png"));
imageList.Images.Add("CharInterest", Image.FromFile("Images/CharInterest.png"));
imageList.Images.Add("", Image.FromFile("Images/NoDir.png"));

imageList.ColorDepth = ColorDepth.Depth32Bit;
Expand Down
4 changes: 4 additions & 0 deletions MiloEditor/MiloEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<None Remove="Images\Character.png" />
<None Remove="Images\CharClip.png" />
<None Remove="Images\CharClipGroup.png" />
<None Remove="Images\CharInterest.png" />
<None Remove="Images\CheckboxDisplay.png" />
<None Remove="Images\ColorPalette.png" />
<None Remove="Images\default.png" />
Expand Down Expand Up @@ -94,6 +95,9 @@
<Content Include="Images\CharClipGroup.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Images\CharInterest.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Images\ColorPalette.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
127 changes: 127 additions & 0 deletions MiloLib/Assets/Char/CharInterest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using MiloLib.Assets.Rnd;
using MiloLib.Classes;
using MiloLib.Utils;

namespace MiloLib.Assets.Char
{
[Name("CharInterest"), Description("An interest object for a character to look at")]
public class CharInterest : Object
{
private ushort altRevision;
private ushort revision;

public RndTrans trans = new();

[Name("Max View Angle"), Description("In degrees, the maximum view cone angle for this object to be 'seen'")]
public float maxViewAngle;
[Name("Priority"), Description("An extra weight applied during scoring of this interest - use this to make it more or less important overall")]
public float priority;
[Name("Min Look Time"), Description("The minimum time you have to look at this object when its selected")]
public float minLookTime;
[Name("Max Look Time"), Description("The maximum allowable time to look at this object")]
public float maxLookTime;
[Name("Refractory Period"), Description("In secs, how long until this object can be looked at again")]
public float refractoryPeriod;
[Name("Char Eye Dart Override"), Description("if set, this dart ruleset will override the default one when looking at this interest object")]
public Symbol charEyeDartOverride = new(0, "");
public int categoryFlags;
[Name("Override Min Target Distance"), Description("if true, we will override the minimum distance this target can be from the eyes using the value below")]
public bool overrideMinTargetDistance;
[Name("Min Target Distance Override"), Description("the minimum distance, in inches, that this interest can be from the eyes. only applied if overrides_min_target_dist is true...")]
public float minTargetDistanceOverride;
public float maxViewAngleCosine;

public Symbol unkSym = new(0, "");

public byte unkByte;

public CharInterest Read(EndianReader reader, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry entry)
{
uint combinedRevision = reader.ReadUInt32();
if (BitConverter.IsLittleEndian) (revision, altRevision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF));
else (altRevision, revision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF));

base.Read(reader, false, parent, entry);

trans = trans.Read(reader, false, parent, entry);

maxViewAngle = reader.ReadFloat();
priority = reader.ReadFloat();
minLookTime = reader.ReadFloat();
maxLookTime = reader.ReadFloat();
refractoryPeriod = reader.ReadFloat();

// ?
if (((short)((revision + 0x10000)) - 2 <= 3))
{
unkSym = Symbol.Read(reader);
}
else if (((short)((revision + 0x10000)) > 5))
{
charEyeDartOverride = Symbol.Read(reader);
}
if (revision > 2)
{
categoryFlags = reader.ReadInt32();
if (revision == 3)
{
unkByte = reader.ReadByte();
}
}
if (revision > 4)
{
overrideMinTargetDistance = reader.ReadBoolean();
minTargetDistanceOverride = reader.ReadFloat();
}

if (standalone)
if ((reader.Endianness == Endian.BigEndian ? 0xADDEADDE : 0xDEADDEAD) != reader.ReadUInt32()) throw new Exception("Got to end of standalone asset but didn't find the expected end bytes, read likely did not succeed");

return this;
}

public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

base.Write(writer, false, parent, entry);

trans.Write(writer, false, parent, entry);

writer.WriteFloat(maxViewAngle);
writer.WriteFloat(priority);
writer.WriteFloat(minLookTime);
writer.WriteFloat(maxLookTime);
writer.WriteFloat(refractoryPeriod);

// ?
if (((short)((revision + 0x10000)) - 2 <= 3))
{
Symbol.Write(writer, unkSym);
}
else if (((short)((revision + 0x10000)) > 5))
{
Symbol.Write(writer, charEyeDartOverride);
}

if (revision > 2)
{
writer.WriteInt32(categoryFlags);
if (revision == 3)
{
writer.WriteByte(unkByte);
}
}

if (revision > 4)
{
writer.WriteBoolean(overrideMinTargetDistance);
writer.WriteFloat(minTargetDistanceOverride);
}

if (standalone)
writer.WriteBlock(new byte[4] { 0xAD, 0xDE, 0xAD, 0xDE });
}

}
}
14 changes: 14 additions & 0 deletions MiloLib/Assets/DirectoryMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ public void ReadEntry(EndianReader reader, DirectoryMeta.Entry entry)
Debug.WriteLine("Reading entry CharGuitarString " + entry.name.value);
entry.obj = new CharGuitarString().Read(reader, true, this, entry);
break;
case "CharInterest":
Debug.WriteLine("Reading entry CharInterest " + entry.name.value);
entry.obj = new CharInterest().Read(reader, true, this, entry);
break;
case "CharMeshHide":
Debug.WriteLine("Reading entry CharMeshHide " + entry.name.value);
entry.obj = new CharMeshHide().Read(reader, true, this, entry);
Expand Down Expand Up @@ -882,6 +886,10 @@ public void ReadEntry(EndianReader reader, DirectoryMeta.Entry entry)
Debug.WriteLine("Reading entry Trans " + entry.name.value);
entry.obj = new RndTrans().Read(reader, true, this, entry);
break;
case "TransProxy":
Debug.WriteLine("Reading entry TransProxy " + entry.name.value);
entry.obj = new RndTransProxy().Read(reader, true, this, entry);
break;
case "UIColor":
Debug.WriteLine("Reading entry UIColor" + entry.name.value);
entry.obj = new UIColor().Read(reader, true, this, entry);
Expand Down Expand Up @@ -1135,6 +1143,9 @@ public void WriteEntry(EndianWriter writer, DirectoryMeta.Entry entry)
case "CharGuitarString":
((CharGuitarString)entry.obj).Write(writer, true, this, entry);
break;
case "CharInterest":
((CharInterest)entry.obj).Write(writer, true, this, entry);
break;
case "CharMeshHide":
((CharMeshHide)entry.obj).Write(writer, true, this, entry);
break;
Expand Down Expand Up @@ -1194,6 +1205,9 @@ public void WriteEntry(EndianWriter writer, DirectoryMeta.Entry entry)
case "Trans":
((RndTrans)entry.obj).Write(writer, true, false);
break;
case "TransProxy":
((RndTransProxy)entry.obj).Write(writer, true, this, entry);
break;
case "UIColor":
((UIColor)entry.obj).Write(writer, true, this, entry);
break;
Expand Down
2 changes: 1 addition & 1 deletion MiloLib/Assets/Rnd/RndSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override void Write(EndianWriter writer, bool standalone, DirectoryMeta p

base.Write(writer, false, parent, entry);

writer.WriteUInt32((uint)setObjects.Count));
writer.WriteUInt32((uint)setObjects.Count);
foreach (Symbol setObj in setObjects)
{
Symbol.Write(writer, setObj);
Expand Down
55 changes: 55 additions & 0 deletions MiloLib/Assets/Rnd/RndTransProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using MiloLib.Classes;
using MiloLib.Utils;

namespace MiloLib.Assets.Rnd
{
[Name("RndTransProxy"), Description("Stand-in for a RndTransformable inside of a proxy, so you can use it")]
public class RndTransProxy : Object
{
private ushort altRevision;
private ushort revision;

public RndTrans trans = new();
[Name("Proxy"), Description("Proxy object this will look into.")]
public Symbol proxy = new(0, "");
[Name("Part"), Description("The part inside it")]
public Symbol part = new(0, "");

public RndTransProxy Read(EndianReader reader, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry entry)
{
uint combinedRevision = reader.ReadUInt32();
if (BitConverter.IsLittleEndian) (revision, altRevision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF));
else (altRevision, revision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF));

base.Read(reader, false, parent, entry);

if (revision != 0)
trans = trans.Read(reader, false, parent, entry);

proxy = Symbol.Read(reader);
part = Symbol.Read(reader);

if (standalone)
if ((reader.Endianness == Endian.BigEndian ? 0xADDEADDE : 0xDEADDEAD) != reader.ReadUInt32()) throw new Exception("Got to end of standalone asset but didn't find the expected end bytes, read likely did not succeed");

return this;
}

public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

base.Write(writer, false, parent, entry);

if (revision != 0)
trans.Write(writer, false, parent, entry);

Symbol.Write(writer, proxy);
Symbol.Write(writer, part);

if (standalone)
writer.WriteBlock(new byte[4] { 0xAD, 0xDE, 0xAD, 0xDE });
}

}
}

0 comments on commit a9a4334

Please sign in to comment.