Skip to content

Commit

Permalink
amxxmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
CeSun committed Oct 4, 2024
1 parent 6e6c522 commit 751c56e
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Source/Amxmodx.Module/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Module;

static class ModuleConfig
{
public const string Name = "";
public const string Name = "AmxmodxModule";
public const string Version = "";
public const string Author = "";
public const string Url = "";
Expand Down
29 changes: 13 additions & 16 deletions Source/Amxmodx.Module/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public unsafe static class Module
{
static Module()
{
g_EntityAPI_Table.pfnThink = &Test.Think;

g_EntityAPI_Post_Table.pfnThink = &Test.Think;
g_MetaFunctions_Table.pfnGetEntityAPI2 = &GetEntityAPI2;
g_MetaFunctions_Table.pfnGetEntityAPI2_Post = &GetEntityAPI2_Post;
g_MetaFunctions_Table.pfnGetNewDLLFunctions = &GetNewDLLFunctions;
g_MetaFunctions_Table.pfnGetNewDLLFunctions_Post = &GetNewDLLFunctions_Post;
g_MetaFunctions_Table.pfnGetEngineFunctions = &GetEngineFunctions;
g_MetaFunctions_Table.pfnGetEngineFunctions_Post = &GetEngineFunctions_Post;
}

[UnmanagedCallersOnly(EntryPoint = "GetEntityAPI2", CallConvs = [typeof(CallConvCdecl)])]
Expand Down Expand Up @@ -150,6 +151,7 @@ public static int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS* pFunctionTable,
return False;
*pFunctionTable = g_MetaFunctions_Table;
gpGamedllFuncs = pGamedllFuncs;
Plugin.FN_META_ATTACH();
return True;
}

Expand All @@ -158,6 +160,7 @@ public static int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
if (now > Plugin_info->unloadable && reason != PL_UNLOAD_REASON.PNL_CMD_FORCED)
return False;
Plugin.FN_META_DETACH();
return True;
}

Expand All @@ -179,13 +182,14 @@ public static int AMXX_Query(int* interfaceVersion, amxx_module_info_t* moduleIn
return AMXX_IFVERS;
}
*moduleInfo = g_ModuleInfo;

Plugin.FN_AMXX_QUERY();
return AMXX_OK;
}

[UnmanagedCallersOnly(EntryPoint = "AMXX_CheckGame", CallConvs = [typeof(CallConvCdecl)])]
public static int AMXX_CheckGame(nint game)
{
Plugin.FN_AMXX_CHECKGAME((sbyte*)game);
return AMXX_GAME_OK;
}

Expand Down Expand Up @@ -460,41 +464,34 @@ public static int AMXX_Attach(delegate* unmanaged[Cdecl]<sbyte*, void*> reqFnptr
{
g_fn_MessageBlock = (delegate* unmanaged[Cdecl]<int, int, int*, void>)reqFnptrFunc(funName);
}



Plugin.FN_AMXX_ATTACH();
return AMXX_OK;
}

static void REQFUNC<T>(string name, out T* t) where T : unmanaged
{
using (var funName = name.GetNativeString())
{
t = (T*)g_fn_RequestFunction(funName);
}
}

[UnmanagedCallersOnly(EntryPoint = "AMXX_Detach", CallConvs = [typeof(CallConvCdecl)])]
public static int AMXX_Detach()
{
Plugin.FN_AMXX_DETACH();
return AMXX_OK;
}

[UnmanagedCallersOnly(EntryPoint = "AMXX_PluginsLoaded", CallConvs = [typeof(CallConvCdecl)])]
public static int AMXX_PluginsLoaded()
{
Plugin.FN_AMXX_PLUGINSLOADED();
return AMXX_OK;
}

[UnmanagedCallersOnly(EntryPoint = "AMXX_PluginsUnloaded", CallConvs = [typeof(CallConvCdecl)])]
public static void AMXX_PluginsUnloaded()
{
Plugin.FN_AMXX_PLUGINSUNLOADED();
}

[UnmanagedCallersOnly(EntryPoint = "AMXX_PluginsUnloading", CallConvs = [typeof(CallConvCdecl)])]
public static void AMXX_PluginsUnloading()
{

Plugin.FN_AMXX_PLUGINSUNLOADING();
}

}
86 changes: 86 additions & 0 deletions Source/Amxmodx.Module/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using GoldSrc.Amxmodx.Native;
using GoldSrc.HLSDK;
using GoldSrc.HLSDK.Native;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static Module.Global;
#pragma warning disable CS8981
using cell = int;
#pragma warning restore CS8981


namespace Module;

public unsafe class Plugin
{
public static AMX_NATIVE_INFO* nativeInfo = null;
static Plugin()
{
nativeInfo = (AMX_NATIVE_INFO*)Marshal.AllocHGlobal(sizeof(AMX_NATIVE_INFO) * 2);

nativeInfo[0].name = "TestHelloModule".GetNativeString();
nativeInfo[0].func = (nint)(delegate* unmanaged[Cdecl]<AMX*, int*, int>)&Plugin.TestHelloModule;


nativeInfo[1].name = null;
nativeInfo[1].func = nint.Zero;
}

public static void FN_META_QUERY()
{

}

public static void FN_META_ATTACH()
{

}

public static void FN_META_DETACH()
{

}

public static void FN_AMXX_QUERY()
{

}

public static int FN_AMXX_CHECKGAME(sbyte* game)
{
return AMXX_GAME_OK;
}

public static void FN_AMXX_ATTACH()
{
// 测试注册函数
g_fn_AddNatives(Plugin.nativeInfo);
}

public static void FN_AMXX_DETACH()
{
}

public static void FN_AMXX_PLUGINSLOADED()
{
}

public static void FN_AMXX_PLUGINSUNLOADING()
{

}
public static void FN_AMXX_PLUGINSUNLOADED()
{

}



[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
public static cell TestHelloModule(AMX* amx, cell* @params)
{
using var s = "TestHelloModule\n".GetNativeString();
g_engfuncs.pfnServerPrint(s);
return 1;
}
}
17 changes: 0 additions & 17 deletions Source/Amxmodx.Module/Test.cs

This file was deleted.

9 changes: 9 additions & 0 deletions Source/Sdk/Amxmodx.Net/Amxmodx.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
<Nullable>enable</Nullable>
<RootNamespace>GoldSrc.Amxmodx</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<Title>$(AssemblyName)</Title>
<Version>$(NugetVersion)</Version>
<Authors>CeSun</Authors>
<Description>Amxmodx for .Net</Description>
<PackageProjectUrl>https://github.com/CeSun/GoldSrcMod.Net</PackageProjectUrl>
<RepositoryUrl>https://github.com/CeSun/GoldSrcMod.Net</RepositoryUrl>
<PackageTags>Amxmodx;MetaMod;HLSDK;GoldSrc</PackageTags>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Source/Sdk/HLSDK.Net/HLSDK.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Description>HLSDK for .Net</Description>
<PackageProjectUrl>https://github.com/CeSun/GoldSrcMod.Net</PackageProjectUrl>
<RepositoryUrl>https://github.com/CeSun/GoldSrcMod.Net</RepositoryUrl>
<PackageTags>hlsdk</PackageTags>
<PackageTags>MetaHook;HLSDK;GoldSrc</PackageTags>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down
10 changes: 10 additions & 0 deletions Source/Sdk/MetaMod.Net/MetaMod.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
<Nullable>enable</Nullable>
<RootNamespace>GoldSrc.MetaMod</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>


<Title>$(AssemblyName)</Title>
<Version>$(NugetVersion)</Version>
<Authors>CeSun</Authors>
<Description>MetaMod for .Net</Description>
<PackageProjectUrl>https://github.com/CeSun/GoldSrcMod.Net</PackageProjectUrl>
<RepositoryUrl>https://github.com/CeSun/GoldSrcMod.Net</RepositoryUrl>
<PackageTags>MetaMod;HLSDK;GoldSrc</PackageTags>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
Expand Down
15 changes: 9 additions & 6 deletions Source/Sdk/Metahook.Net/Metahook.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
<RootNamespace>GoldSrc.Metahook</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>

<Title>$(AssemblyName)</Title>
<Version>$(NugetVersion)</Version>
<Authors>CeSun</Authors>
<Authors>CeSun</Authors>
<Description>Metahook for .Net</Description>
<RepositoryUrl>https://github.com/CeSun/GoldSrcMod.Net</RepositoryUrl>
<PackageProjectUrl>https://github.com/CeSun/GoldSrcMod.Net</PackageProjectUrl>
</PropertyGroup>
<PackageProjectUrl>https://github.com/CeSun/GoldSrcMod.Net</PackageProjectUrl>
<RepositoryUrl>https://github.com/CeSun/GoldSrcMod.Net</RepositoryUrl>
<PackageTags>MetaHook;HLSDK;GoldSrc</PackageTags>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HLSDK.Net\HLSDK.Net.csproj" />
<ProjectReference Include="..\HLSDK.Net\HLSDK.Net.csproj" />
</ItemGroup>

</Project>
</Project>

0 comments on commit 751c56e

Please sign in to comment.