Support getting type name.

This commit is contained in:
Deukhoofd 2020-08-08 13:15:17 +02:00
parent 26f8722fee
commit 1b025ea3cf
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 26 additions and 18 deletions

View File

@ -23,13 +23,6 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_TypeLibrary_GetTypeId")]
internal static extern byte GetTypeId(ref byte @out, IntPtr p, IntPtr type);
/// <param name="out">unsigned char &</param>
/// <param name="p">const TypeLibrary *</param>
/// <param name="type">unsigned int</param>
/// <returns>unsigned char</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_TypeLibrary_GetTypeIdWithHash")]
internal static extern byte GetTypeIdWithHash(ref byte @out, IntPtr p, uint type);
/// <param name="out">unsigned char &</param>
/// <param name="p">TypeLibrary *</param>
/// <param name="type">const char *</param>
@ -37,13 +30,6 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_TypeLibrary_RegisterType")]
internal static extern byte RegisterType(ref byte @out, IntPtr p, IntPtr type);
/// <param name="out">unsigned char &</param>
/// <param name="p">TypeLibrary *</param>
/// <param name="type">unsigned int</param>
/// <returns>unsigned char</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_TypeLibrary_RegisterTypeWithHash")]
internal static extern byte RegisterTypeWithHash(ref byte @out, IntPtr p, uint type);
/// <param name="p">TypeLibrary *</param>
/// <param name="attacking">unsigned char</param>
/// <param name="defensive">unsigned char</param>
@ -69,5 +55,12 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_TypeLibrary_GetEffectiveness")]
internal static extern byte GetEffectiveness(ref float @out, IntPtr p, byte attacking, IntPtr defensive, ulong defensiveCount);
/// <param name="out">const char * &</param>
/// <param name="p">TypeLibrary *</param>
/// <param name="type">unsigned char</param>
/// <returns>unsigned char</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_TypeLibrary_GetTypeName")]
internal static extern byte GetTypeName(ref IntPtr @out, IntPtr p, byte type);
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Library
@ -56,6 +57,20 @@ namespace PkmnLibSharp.Library
return f;
}
public string GetTypeName(byte typeId)
{
foreach (var kv in _cache.Where(kv => kv.Value == typeId))
{
return kv.Key;
}
var ptr = IntPtr.Zero;
Creaturelib.Generated.TypeLibrary.GetTypeName(ref ptr, Ptr, typeId).Assert();
var s = ptr.PtrString();
_cache[s] = typeId;
return s;
}
protected override void DeletePtr()
{
Creaturelib.Generated.TypeLibrary.Destruct(Ptr);

BIN
PkmnLibSharp/Native/libCreatureLib.so (Stored with Git LFS)

Binary file not shown.

BIN
PkmnLibSharp/Native/libpkmnLib.so (Stored with Git LFS)

Binary file not shown.

File diff suppressed because one or more lines are too long