Debian Codegraph @

modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotPluginsInitializerGenerator.cs

raw symbols SCIP
1 using System.Text;
2 using Microsoft.CodeAnalysis;
3 using Microsoft.CodeAnalysis.Text;
4
5 namespace Godot.SourceGenerators
6 {
7 [Generator]
8 public class GodotPluginsInitializerGenerator : ISourceGenerator
9 {
10 public void Initialize(GeneratorInitializationContext context)
11 {
12 }
13
14 public void Execute(GeneratorExecutionContext context)
15 {
16 if (context.IsGodotToolsProject() || context.IsGodotSourceGeneratorDisabled("GodotPluginsInitializer"))
17 return;
18
19 string source =
20 @"using System;
21 using System.Runtime.InteropServices;
22 using Godot.Bridge;
23 using Godot.NativeInterop;
24
25 namespace GodotPlugins.Game
26 {
27 internal static partial class Main
28 {
29 [UnmanagedCallersOnly(EntryPoint = ""godotsharp_game_main_init"")]
30 private static godot_bool InitializeFromGameProject(IntPtr godotDllHandle, IntPtr outManagedCallbacks,
31 IntPtr unmanagedCallbacks, int unmanagedCallbacksSize)
32 {
33 try
34 {
35 DllImportResolver dllImportResolver = new GodotDllImportResolver(godotDllHandle).OnResolveDllImport;
36
37 var coreApiAssembly = typeof(global::Godot.GodotObject).Assembly;
38
39 NativeLibrary.SetDllImportResolver(coreApiAssembly, dllImportResolver);
40
41 NativeFuncs.Initialize(unmanagedCallbacks, unmanagedCallbacksSize);
42
43 ManagedCallbacks.Create(outManagedCallbacks);
44
45 ScriptManagerBridge.LookupScriptsInAssembly(typeof(global::GodotPlugins.Game.Main).Assembly);
46
47 return godot_bool.True;
48 }
49 catch (Exception e)
50 {
51 global::System.Console.Error.WriteLine(e);
52 return false.ToGodotBool();
53 }
54 }
55 }
56 }
57 ";
58
59 context.AddSource("GodotPlugins.Game.generated",
60 SourceText.From(source, Encoding.UTF8));
61 }
62 }
63 }