Skip to content

Commit

Permalink
[Sdk] Hopefully fixed issues regarding types
Browse files Browse the repository at this point in the history
  • Loading branch information
wannkunstbeikor committed Oct 28, 2023
1 parent fb1c7df commit 77599f8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
Binary file removed FrostyCmd/Sdk/StarWarsIISDK.dll
Binary file not shown.
10 changes: 5 additions & 5 deletions FrostySdk/IO/EbxReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public EbxReader(Stream inStream)
Pad(16);
}

m_imports = new EbxImportReference[importCount];
m_imports = new EbxImportReference[importCount];
for (int i = 0; i < importCount; i++)
{
EbxImportReference import = new()
Expand Down Expand Up @@ -248,7 +248,7 @@ protected virtual void InternalReadObjects()
instanceGuid = ReadGuid();
}

if (typeDescriptor.Alignment != 0x04)
if (typeDescriptor.GetAlignment() != 0x04)
{
Position += 8;
}
Expand Down Expand Up @@ -466,7 +466,7 @@ protected FileRef ReadFileRef()
protected virtual PointerRef ReadPointerRef()
{
uint index = ReadUInt32();

if ((index >> 0x1F) == 1)
{
EbxImportReference import = m_imports[(int)(index & 0x7FFFFFFF)];
Expand All @@ -478,8 +478,8 @@ protected virtual PointerRef ReadPointerRef()
{
return new PointerRef();
}



return new PointerRef(m_objects[(int)(index - 1)]);
}
Expand Down
15 changes: 8 additions & 7 deletions FrostySdk/Sdk/FieldInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class FieldInfo : IComparable
private TypeFlags m_flags;
private ushort m_offset;
private long p_typeInfo;

public void Read(MemoryReader reader, uint classHash)
{
if (!ProfilesLibrary.HasStrippedTypeNames)
Expand All @@ -28,6 +28,10 @@ public void Read(MemoryReader reader, uint classHash)
{
m_nameHash = reader.ReadUInt();
}
else
{
m_nameHash = (uint)Utils.Utils.HashString(m_name);
}
m_flags = reader.ReadUShort();
m_offset = reader.ReadUShort();

Expand Down Expand Up @@ -62,7 +66,7 @@ public void CreateField(StringBuilder sb)
typeName = "PointerRef";
isClass = true;
}

if (type is ArrayInfo arrayInfo)
{
type = arrayInfo.GetTypeInfo();
Expand All @@ -76,11 +80,8 @@ public void CreateField(StringBuilder sb)
sb.AppendLine($"[{nameof(EbxArrayMetaAttribute)}({(ushort)type.GetFlags()})]");
}
sb.AppendLine($"[{nameof(EbxFieldMetaAttribute)}({(ushort)flags}, {m_offset}, {(isClass ? $"typeof({type.GetName()})" : "null")})]");
if (m_nameHash != 0)
{
sb.AppendLine($"[{nameof(NameHashAttribute)}({m_nameHash})]");
}

sb.AppendLine($"[{nameof(NameHashAttribute)}({m_nameHash})]");

sb.AppendLine($"private {typeName} _{m_name};");
}

Expand Down
11 changes: 6 additions & 5 deletions FrostySdk/Sdk/TypeInfoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public static TypeInfoData ReadTypeInfoData(MemoryReader reader)
{
nameHash = reader.ReadUInt();
}
else
{
nameHash = (uint)Utils.Utils.HashString(name);
}

TypeFlags flags = reader.ReadUShort();

Expand Down Expand Up @@ -145,15 +149,12 @@ public virtual void CreateType(StringBuilder sb)
sb.AppendLine($"[{nameof(EbxTypeMetaAttribute)}({(ushort)m_flags}, {m_alignment}, {m_size}, \"{m_nameSpace}\")]");

sb.AppendLine($"[{nameof(DisplayNameAttribute)}(\"{m_name}\")]");

sb.AppendLine($"[{nameof(NameHashAttribute)}({m_nameHash})]");

if (!m_guid.Equals(Guid.Empty))
{
sb.AppendLine($"[{nameof(GuidAttribute)}(\"{m_guid}\")]");
}
if (m_nameHash != 0)
{
sb.AppendLine($"[{nameof(NameHashAttribute)}({m_nameHash})]");
}
if (m_signature != 0)
{
sb.AppendLine($"[{nameof(SignatureAttribute)}({m_signature})]");
Expand Down
22 changes: 11 additions & 11 deletions FrostySdk/TypeLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Frosty.Sdk;
public static class TypeLibrary
{
public static bool IsInitialized { get; private set; }

private static readonly Dictionary<string, int> s_nameMapping = new();
private static readonly Dictionary<uint, int> s_nameHashMapping = new();
private static readonly Dictionary<Guid, int> s_guidMapping = new();
Expand All @@ -21,7 +21,7 @@ public static bool Initialize()
{
return true;
}

FileInfo fileInfo = new($"Sdk/{ProfilesLibrary.SdkFilename}.dll");
if (!fileInfo.Exists)
{
Expand All @@ -36,7 +36,7 @@ public static bool Initialize()
{
Type type = s_types[i];
string name = type.GetCustomAttribute<DisplayNameAttribute>()?.Name ?? type.Name;
uint nameHash = type.GetCustomAttribute<NameHashAttribute>()?.Hash ?? (uint)Utils.Utils.HashString(name);
uint nameHash = type.GetCustomAttribute<NameHashAttribute>()!.Hash; // every type should have that attribute
Guid? guid = type.GetCustomAttribute<GuidAttribute>()?.Guid;

s_nameMapping.Add(name, i);
Expand All @@ -50,7 +50,7 @@ public static bool Initialize()
IsInitialized = true;
return true;
}

public static Type? GetType(string name)
{
if (!s_nameMapping.TryGetValue(name, out int index))
Expand All @@ -59,7 +59,7 @@ public static bool Initialize()
}
return s_types[index];
}

public static Type? GetType(uint nameHash)
{
if (!s_nameHashMapping.TryGetValue(nameHash, out int index))
Expand All @@ -68,7 +68,7 @@ public static bool Initialize()
}
return s_types[index];
}

public static Type? GetType(Guid guid)
{
if (!s_guidMapping.TryGetValue(guid, out int index))
Expand All @@ -77,7 +77,7 @@ public static bool Initialize()
}
return s_types[index];
}

public static object? CreateObject(string name)
{
Type? type = GetType(name);
Expand All @@ -89,13 +89,13 @@ public static bool Initialize()
Type? type = GetType(nameHash);
return type == null ? null : Activator.CreateInstance(type);
}

public static object? CreateObject(Guid guid)
{
Type? type = GetType(guid);
return type == null ? null : Activator.CreateInstance(type);
}

public static object? CreateObject(Type type)
{
return Activator.CreateInstance(type);
Expand All @@ -104,7 +104,7 @@ public static bool Initialize()
public static bool IsSubClassOf(object obj, string name)
{
Type type = obj.GetType();

return IsSubClassOf(type, name);
}

Expand All @@ -122,7 +122,7 @@ public static bool IsSubClassOf(Type type, string name)
public static bool IsSubClassOf(string type, string name)
{
Type? sourceType = GetType(type);

return sourceType != null && IsSubClassOf(sourceType, name);
}
}

0 comments on commit 77599f8

Please sign in to comment.