Skip to content

Commit

Permalink
[Sdk] Fixed missing Assembly for sdk compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
wannkunstbeikor committed Oct 28, 2023
1 parent 42d8852 commit c41c68d
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions FrostySdk/Sdk/TypeSdkGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -21,15 +22,15 @@ private long FindTypeInfoOffset(Process process)
{
// string[] patterns =
// {
// "488b05???????? 48894108 48890d???????? 48???? C3",
// "488b05???????? 48894108 48890d???????? C3",
// "488b05???????? 48894108 48890d????????",
// "488b05???????? 488905???????? 488d05???????? 488905???????? E9",
// "48391D???????? ???? 488b4310", // new games
// "48 8b 05 ?? ?? ?? ?? 48 89 41 08 48 89 0d ?? ?? ?? ?? 48 ?? ?? C3",
// "48 8b 05 ?? ?? ?? ?? 48 89 41 08 48 89 0d ?? ?? ?? ?? C3",
// "48 8b 05 ?? ?? ?? ?? 48 89 41 08 48 89 0d ?? ?? ?? ??",
// "48 8b 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? 48 8d 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? E9",
// "48 39 1D ?? ?? ?? ?? ?? ?? 48 8b 43 10", // new games
// };

long startAddress = process.MainModule?.BaseAddress.ToInt64() ?? 0;

using (MemoryReader reader = new(process, startAddress))
{
reader.Position = startAddress;
Expand All @@ -39,14 +40,14 @@ private long FindTypeInfoOffset(Process process)
{
return -1;
}
reader.Position = offsets![0] + 3;

reader.Position = offsets[0] + 3;
int newValue = reader.ReadInt(false);
reader.Position = offsets[0] + 3 + newValue + 4;
return reader.ReadLong(false);
}
}

public bool DumpTypes(Process process)
{
long typeInfoOffset = FindTypeInfoOffset(process);
Expand All @@ -72,7 +73,7 @@ public bool DumpTypes(Process process)
public bool CreateSdk(string filePath)
{
StringBuilder sb = new();

sb.AppendLine("using System;");
sb.AppendLine("using System.Collections.ObjectModel;");
sb.AppendLine("using Frosty.Sdk.Attributes;");
Expand All @@ -84,7 +85,6 @@ public bool CreateSdk(string filePath)
sb.AppendLine();
sb.AppendLine("namespace Frosty.Sdk.Ebx;");


foreach (TypeInfo typeInfo in TypeInfo.TypeInfoMapping.Values)
{
switch (typeInfo.GetFlags().GetTypeEnum())
Expand Down Expand Up @@ -125,8 +125,9 @@ public bool CreateSdk(string filePath)

SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source);

List<MetadataReference> references = new();

List<MetadataReference> references =
new() { MetadataReference.CreateFromFile(typeof(ObservableCollection<>).Assembly.Location) };

Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();

foreach (Assembly assembly in assemblies)
Expand All @@ -137,18 +138,18 @@ public bool CreateSdk(string filePath)
}
}


#if EBX_TYPE_SDK_DEBUG
OptimizationLevel level = OptimizationLevel.Debug;
#else
OptimizationLevel level = OptimizationLevel.Release;
#endif

CSharpCompilation compilation = CSharpCompilation.Create("EbxTypes", new[] { syntaxTree }, references,
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true, optimizationLevel: level));

List<AdditionalText> meta = new List<AdditionalText>();

if (Directory.Exists("Meta"))
{
foreach (string additionalTextPath in Directory.EnumerateFiles("Meta"))
Expand All @@ -160,7 +161,7 @@ public bool CreateSdk(string filePath)
GeneratorDriver driver = CSharpGeneratorDriver
.Create(new SourceGenerator())
.AddAdditionalTexts(ImmutableArray.CreateRange(meta));

driver.RunGeneratorsAndUpdateCompilation(
compilation,
out Compilation outputCompilation,
Expand All @@ -180,7 +181,7 @@ public bool CreateSdk(string filePath)
File.WriteAllText(tree.FilePath, tree.GetText().ToString());
}
#endif

using (FileStream stream = new(filePath, FileMode.Create, FileAccess.Write))
{
EmitResult result = outputCompilation.Emit(stream);
Expand All @@ -192,7 +193,7 @@ public bool CreateSdk(string filePath)
return false;
}
}

return true;
}
}

0 comments on commit c41c68d

Please sign in to comment.