From a5a72f9536d9eccc47670ec689d3bb738db74133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Tue, 10 Jun 2025 13:16:14 -0500 Subject: [PATCH] feat: some more ffi communication --- .csharpierrc | 3 ++ .gitignore | 7 ++- .vscode/settings.json | 3 +- .../src/components/Internal/FFIEcho.tsx | 11 +++++ .../src/components/Internal/FFIFileCount.tsx | 10 ++++ packages/website-ue/src/core/blitzkit/ffi.ts | 13 +++++ .../website-ue/src/pages/internal/_index.tsx | 47 +++---------------- .../src/pages/internal/ffi/_index.tsx | 11 ----- .../src/pages/internal/ffi/index.astro | 8 ---- src/BlitzKit.FFI/BlitzKit.FFI.csproj | 4 ++ src/BlitzKit.FFI/FFI.cs | 20 +++++++- src/BlitzKit.FFI/Models/BlitzProvider.cs | 22 +++++++++ 12 files changed, 95 insertions(+), 64 deletions(-) create mode 100644 .csharpierrc create mode 100644 packages/website-ue/src/components/Internal/FFIEcho.tsx create mode 100644 packages/website-ue/src/components/Internal/FFIFileCount.tsx create mode 100644 packages/website-ue/src/core/blitzkit/ffi.ts delete mode 100644 packages/website-ue/src/pages/internal/ffi/_index.tsx delete mode 100644 packages/website-ue/src/pages/internal/ffi/index.astro create mode 100644 src/BlitzKit.FFI/Models/BlitzProvider.cs diff --git a/.csharpierrc b/.csharpierrc new file mode 100644 index 000000000..2eae6bf63 --- /dev/null +++ b/.csharpierrc @@ -0,0 +1,3 @@ +{ + "indentSize": 2 +} diff --git a/.gitignore b/.gitignore index 513cc372b..5db5c98ec 100644 --- a/.gitignore +++ b/.gitignore @@ -119,6 +119,8 @@ _ReSharper*/ _TeamCity* *.dotCover .axoCover/* + + !.axoCover/settings.json coverage*.json coverage*.xml @@ -137,6 +139,7 @@ DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc + DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 @@ -147,13 +150,13 @@ publish/ *.pubxml *.publishproj PublishScripts/ + *.nupkg *.snupkg -**/[Pp]ackages/* -!**/[Pp]ackages/build/ *.nuget.props *.nuget.targets csx/ + *.build.csdef ecf/ rcf/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 395a3610c..80f5f5d66 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -229,5 +229,6 @@ "deno.unstable": false, "cSpell.enableFiletypes": ["glsl", "proto3"], "typescript.tsdk": "node_modules\\typescript\\lib", - "liveServer.settings.multiRootWorkspaceName": "blitzkit" + "liveServer.settings.multiRootWorkspaceName": "blitzkit", + "git.ignoreLimitWarning": true } diff --git a/packages/website-ue/src/components/Internal/FFIEcho.tsx b/packages/website-ue/src/components/Internal/FFIEcho.tsx new file mode 100644 index 000000000..7f6004d1b --- /dev/null +++ b/packages/website-ue/src/components/Internal/FFIEcho.tsx @@ -0,0 +1,11 @@ +import { Flex, Text } from '@radix-ui/themes'; +import { ffi } from '../../core/blitzkit/ffi'; + +export function FFIEcho() { + return ( + + {ffi.debug_echo(new Date().toLocaleString())} + + + ); +} diff --git a/packages/website-ue/src/components/Internal/FFIFileCount.tsx b/packages/website-ue/src/components/Internal/FFIFileCount.tsx new file mode 100644 index 000000000..61c5b5d37 --- /dev/null +++ b/packages/website-ue/src/components/Internal/FFIFileCount.tsx @@ -0,0 +1,10 @@ +import { Code, Text } from '@radix-ui/themes'; +import { ffi } from '../../core/blitzkit/ffi'; + +export function FFIFileCount() { + return ( + + {ffi.debug_get_file_count().toLocaleString()} files loaded + + ); +} diff --git a/packages/website-ue/src/core/blitzkit/ffi.ts b/packages/website-ue/src/core/blitzkit/ffi.ts new file mode 100644 index 000000000..784d49b97 --- /dev/null +++ b/packages/website-ue/src/core/blitzkit/ffi.ts @@ -0,0 +1,13 @@ +import { Library, types } from 'ffi-napi'; +import { assertSecret } from 'packages/core/src'; + +export const FFI_PATH = + '../../src/BlitzKit.FFI/bin/Release/net9.0/win-x64/publish/BlitzKit.FFI.dll'; + +export const ffi = Library(FFI_PATH, { + debug_echo: [types.CString, [types.CString]], + mount_game: ['void', [types.CString]], + debug_get_file_count: [types.int, []], +}); + +ffi.mount_game(assertSecret(import.meta.env.GAME_MOUNT_POINT)); diff --git a/packages/website-ue/src/pages/internal/_index.tsx b/packages/website-ue/src/pages/internal/_index.tsx index 3b93d6e01..f82a2bda4 100644 --- a/packages/website-ue/src/pages/internal/_index.tsx +++ b/packages/website-ue/src/pages/internal/_index.tsx @@ -1,47 +1,14 @@ -import { Link, Table } from '@radix-ui/themes'; +import { Heading } from '@radix-ui/themes'; +import { FFIEcho } from '../../components/Internal/FFIEcho'; +import { FFIFileCount } from '../../components/Internal/FFIFileCount'; import { PageWrapper } from '../../components/PageWrapper'; export function Page() { return ( - - - - - Name - Memo - - - - - - - FFI - - - Status of BlitzKit's currently mounted foreign function interface - - - - - - Client - - - Location and information of the currently mounted client - - - - - - Bindings - - - Exhaustive list of all bindings and preference of currently - mounted client - - - - + + BlitzKit FFI + + ); } diff --git a/packages/website-ue/src/pages/internal/ffi/_index.tsx b/packages/website-ue/src/pages/internal/ffi/_index.tsx deleted file mode 100644 index ce63d776a..000000000 --- a/packages/website-ue/src/pages/internal/ffi/_index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { PageWrapper } from 'packages/website-ue/src/components/PageWrapper'; -import { ffi } from 'packages/website-ue/src/core/blitzkit/ffi'; - -export function Page() { - return ( - - 🟢 {ffi.echo(new Date().toLocaleString())} - - - ); -} diff --git a/packages/website-ue/src/pages/internal/ffi/index.astro b/packages/website-ue/src/pages/internal/ffi/index.astro deleted file mode 100644 index dc56143d6..000000000 --- a/packages/website-ue/src/pages/internal/ffi/index.astro +++ /dev/null @@ -1,8 +0,0 @@ ---- -import InternalBaseLayout from 'packages/website-ue/src/layouts/InternalBaseLayout.astro'; -import { Page } from './_index'; ---- - - - - diff --git a/src/BlitzKit.FFI/BlitzKit.FFI.csproj b/src/BlitzKit.FFI/BlitzKit.FFI.csproj index d2f72c49d..d393bab71 100644 --- a/src/BlitzKit.FFI/BlitzKit.FFI.csproj +++ b/src/BlitzKit.FFI/BlitzKit.FFI.csproj @@ -7,4 +7,8 @@ win-x64 true + + + + diff --git a/src/BlitzKit.FFI/FFI.cs b/src/BlitzKit.FFI/FFI.cs index 84446b30c..ff07e1c73 100644 --- a/src/BlitzKit.FFI/FFI.cs +++ b/src/BlitzKit.FFI/FFI.cs @@ -1,15 +1,31 @@ using System; using System.Runtime.InteropServices; +using BlitzKit.FFI.Models; namespace BlitzKit.FFI; public static class FFI { - [UnmanagedCallersOnly(EntryPoint = "echo")] - public static IntPtr Echo(IntPtr inputPtr) + static BlitzProvider provider; + + [UnmanagedCallersOnly(EntryPoint = "debug_echo")] + public static IntPtr DebugEcho(IntPtr inputPtr) { var input = Marshal.PtrToStringAnsi(inputPtr); var result = $"BlitzKit FFI echo: {input}"; return Marshal.StringToHGlobalAnsi(result); } + + [UnmanagedCallersOnly(EntryPoint = "mount_game")] + public static void DebugGetGameMountPoint(IntPtr pointPtr) + { + var point = Marshal.PtrToStringAnsi(pointPtr); + provider = new(point); + } + + [UnmanagedCallersOnly(EntryPoint = "debug_get_file_count")] + public static int DebugGetFileCount() + { + return provider.Files.Count; + } } diff --git a/src/BlitzKit.FFI/Models/BlitzProvider.cs b/src/BlitzKit.FFI/Models/BlitzProvider.cs new file mode 100644 index 000000000..5d2543c81 --- /dev/null +++ b/src/BlitzKit.FFI/Models/BlitzProvider.cs @@ -0,0 +1,22 @@ +using System; +using System.IO; +using CUE4Parse.FileProvider; +using CUE4Parse.UE4.Versions; + +namespace BlitzKit.FFI.Models +{ + public class BlitzProvider : DefaultFileProvider + { + public BlitzProvider(string directory) + : base( + directory: directory, + searchOption: SearchOption.AllDirectories, + versions: new(EGame.GAME_UE5_3), + pathComparer: StringComparer.OrdinalIgnoreCase + ) + { + Initialize(); + Mount(); + } + } +}