feat: some more ffi communication

This commit is contained in:
TrèsAbhi committed 2025-06-10 13:16:14 -05:00
1 parent fe3d029e74
commit a5a72f9536
12 files changed
+95 -64

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
{
"indentSize": 2
}
+5 -2
View File
@@ -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/
+2 -1
View File
@@ -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
}
@@ -0,0 +1,11 @@
import { Flex, Text } from '@radix-ui/themes';
import { ffi } from '../../core/blitzkit/ffi';
export function FFIEcho() {
return (
<Flex direction="column" align="start" gap="2">
<Text>{ffi.debug_echo(new Date().toLocaleString())}</Text>
<img src="https://i.imgflip.com/9wrr7u.gif" />
</Flex>
);
}
@@ -0,0 +1,10 @@
import { Code, Text } from '@radix-ui/themes';
import { ffi } from '../../core/blitzkit/ffi';
export function FFIFileCount() {
return (
<Text>
<Code>{ffi.debug_get_file_count().toLocaleString()}</Code> files loaded
</Text>
);
}
@@ -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));
@@ -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 (
<PageWrapper>
<Table.Root>
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell>Name</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>Memo</Table.ColumnHeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>
<Link href="internal/ffi">FFI</Link>
</Table.Cell>
<Table.Cell>
Status of BlitzKit's currently mounted foreign function interface
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
<Link href="internal/ffi">Client</Link>
</Table.Cell>
<Table.Cell>
Location and information of the currently mounted client
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
<Link href="/internal/bindings">Bindings</Link>
</Table.Cell>
<Table.Cell>
Exhaustive list of all bindings and preference of currently
mounted client
</Table.Cell>
</Table.Row>
</Table.Body>
</Table.Root>
<PageWrapper color="amber">
<Heading>BlitzKit FFI</Heading>
<FFIEcho />
<FFIFileCount />
</PageWrapper>
);
}
@@ -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 (
<PageWrapper align="center" justify="center">
🟢 {ffi.echo(new Date().toLocaleString())}
<img src="https://i.imgflip.com/9wrr7u.gif" />
</PageWrapper>
);
}
@@ -1,8 +0,0 @@
---
import InternalBaseLayout from 'packages/website-ue/src/layouts/InternalBaseLayout.astro';
import { Page } from './_index';
---
<InternalBaseLayout>
<Page />
</InternalBaseLayout>
+4
View File
@@ -7,4 +7,8 @@
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../submodules/CUE4Parse/CUE4Parse/CUE4Parse.csproj" />
</ItemGroup>
</Project>
+18 -2
View File
@@ -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;
}
}
+22
View File
@@ -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();
}
}
}