Skip to content

Commit 1a0eda2

Browse files
authored
Merge pull request #28 from swiftly-solution/beta
2 parents 0745b3c + 3599d62 commit 1a0eda2

File tree

11 files changed

+45
-14
lines changed

11 files changed

+45
-14
lines changed

managed/SwiftlyS2.PluginTemplate/SwiftlyS2.CS2.PluginTemplate.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<PackageId>SwiftlyS2.CS2.PluginTemplate</PackageId>
77
<Authors>SwiftlyS2 Team</Authors>
8-
<Version>0.0.7</Version>
8+
<Version>0.0.9</Version>
99
<Description>This is a template for creating a SwiftlyS2 plugin.</Description>
1010
<PackageType>Template</PackageType>
1111
<PackageIcon>icon.png</PackageIcon>
Binary file not shown.
Binary file not shown.
Binary file not shown.

managed/SwiftlyS2.PluginTemplate/templates/PluginId.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1010
<AssemblyName>PluginId</AssemblyName>
1111
<OutputPath>$(MSBuildThisFileDirectory)build/</OutputPath>
12-
<PublishDir>$(OutputPath)publish/name</PublishDir>
12+
<PublishDir>$(OutputPath)publish/PluginId</PublishDir>
1313
</PropertyGroup>
1414

1515
<ItemGroup>
@@ -18,7 +18,7 @@
1818
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" ExcludeAssets="runtime" PrivateAssets="all" />
1919
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" ExcludeAssets="runtime" PrivateAssets="all" />
2020
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" ExcludeAssets="runtime" PrivateAssets="all" />
21-
<PackageReference Include="SwiftlyS2.CS2" Version="0.2.18" ExcludeAssets="runtime" PrivateAssets="all" />
21+
<PackageReference Include="SwiftlyS2.CS2" Version="0.2.19" ExcludeAssets="runtime" PrivateAssets="all" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

managed/src/SwiftlyS2.Core/Modules/EntitySystem/EntitySystem.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public IEnumerable<T> GetAllEntitiesByDesignerName<T>(string designerName) where
7474
.Select(entity => T.From(entity.Address));
7575
}
7676

77+
public T? GetEntityByIndex<T>(uint index) where T : class, ISchemaClass<T> {
78+
var handle = NativeEntitySystem.GetEntityByIndex(index);
79+
if (handle == nint.Zero) {
80+
return null;
81+
}
82+
return T.From(handle);
83+
}
84+
7785
Guid IEntitySystemService.HookEntityOutput<T>(string outputName, IEntitySystemService.EntityOutputHandler callback)
7886
{
7987
var hook = new EntityOutputHookCallback(GetEntityDesignerName<T>() ?? "", outputName, callback, _loggerFactory, _profiler);

managed/src/SwiftlyS2.Generated/Natives/EntitySystem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,9 @@ public unsafe static ulong HookEntityOutput(string className, string outputName,
323323
public unsafe static void UnhookEntityOutput(ulong hookid) {
324324
_UnhookEntityOutput(hookid);
325325
}
326+
private unsafe static delegate* unmanaged<uint, nint> _GetEntityByIndex;
327+
public unsafe static nint GetEntityByIndex(uint index) {
328+
var ret = _GetEntityByIndex(index);
329+
return ret;
330+
}
326331
}

managed/src/SwiftlyS2.Shared/Modules/EntitySystem/IEntitySystem.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public interface IEntitySystemService {
6060
/// <returns>All entities by designer name.</returns>
6161
public IEnumerable<T> GetAllEntitiesByDesignerName<T>(string designerName) where T : class, ISchemaClass<T>;
6262

63+
/// <summary>
64+
/// Get an entity by index.
65+
/// </summary>
66+
/// <typeparam name="T">Entity type.</typeparam>
67+
/// <param name="index">Entity index.</param>
68+
/// <returns>Entity by index. Nullable.</returns>
69+
public T? GetEntityByIndex<T>(uint index) where T : class, ISchemaClass<T>;
70+
6371
/// <summary>
6472
/// Represents a method that handles an entity output event, allowing custom logic to be executed when an entity
6573
/// triggers an output.

managed/src/TestPlugin/TestPlugin.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@ public override void Load(bool hotReload) {
6262
.InitializeJsonWithModel<TestConfig>("test.jsonc", "Main")
6363
.Configure((builder) => {
6464
builder.AddJsonFile("test.jsonc", optional: false, reloadOnChange: true);
65-
// builder.AddYamlFile("test.yaml", optional: false, reloadOnChange: true);
6665
});
6766

6867
ServiceCollection services = new();
6968

7069
services
7170
.AddSwiftly(Core)
72-
.AddSingleton<TestService>()
71+
.AddSingleton<TestService>();
7372

74-
.AddOptionsWithValidateOnStart<TestConfig>()
75-
.BindConfiguration("Main");
7673

7774
var provider = services.BuildServiceProvider();
7875

@@ -242,10 +239,16 @@ public void TestCommand(ICommandContext context) {
242239
[Command("h1")]
243240
public void TestCommand2(ICommandContext context)
244241
{
245-
var dispatchspawn = Core.GameData.GetSignature("CBaseEntity::DispatchSpawn");
246-
_dispatchspawn = Core.Memory.GetUnmanagedFunctionByAddress<DispatchSpawnDelegate>(dispatchspawn);
242+
var token = Core.Scheduler.DelayAndRepeat(500, 1000, () => {
243+
244+
});
247245

248-
_dispatchspawn.AddHook((next) => {
246+
Core.Scheduler.StopOnMapChange(token);
247+
248+
var addres = Core.GameData.GetSignature("CBaseEntity::DispatchSpawn");
249+
var func = Core.Memory.GetUnmanagedFunctionByAddress<DispatchSpawnDelegate>(addres);
250+
251+
var guid = func.AddHook((next) => {
249252
return (pEntity, pKV) => {
250253
Console.WriteLine("TestPlugin DispatchSpawn " + order++);
251254
return next()(pEntity, pKV);
@@ -280,8 +283,6 @@ public void TestCommand3(ICommandContext context)
280283
[Command("tt3")]
281284
public void TestCommand33(ICommandContext context)
282285
{
283-
var ent = Core.EntitySystem.CreateEntity<CPointWorldText>();
284-
_dispatchspawn.CallOriginal(ent.Address, 0);
285286
}
286287

287288
[Command("tt4")]

natives/engine/entitysystem.native

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ ptr EntityHandleGet = uint32 handle
2727
uint32 GetEntityHandleFromEntity = ptr entity
2828
ptr GetFirstActiveEntity = void
2929
uint64 HookEntityOutput = string className, string outputName, ptr callback // CEntityIOOutput*, string outputName, CEntityInstance* activator, CEntityInstance* caller, float delay -> int (HookResult)
30-
void UnhookEntityOutput = uint64 hookid
30+
void UnhookEntityOutput = uint64 hookid
31+
ptr GetEntityByIndex = uint32 index

0 commit comments

Comments
 (0)