Updates to latest pkmnlib, fixes issues.

This commit is contained in:
Deukhoofd 2020-12-23 12:27:58 +01:00
parent 506f10b085
commit 8d5f7f318f
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
22 changed files with 80 additions and 44 deletions

View File

@ -6,15 +6,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PkmnLibSharpTests", "PkmnLi
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Debug|x64 = Debug|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Debug|x64.ActiveCfg = Debug|x64
{0D15FD33-1AEA-44F4-8211-AA8AF97EA534}.Debug|x64.Build.0 = Debug|x64
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Debug|x64.ActiveCfg = Debug|x64
{4CB6DA3C-017B-4AE0-B889-3DFE6B969CD0}.Debug|x64.Build.0 = Debug|x64
EndGlobalSection
EndGlobal

View File

@ -16,7 +16,7 @@ namespace PkmnLibSharp.Battling
var ptr = IntPtr.Zero;
var arr = parties.Select(x => x.Ptr).ToArray();
Pkmnlib.Generated.Battle.Construct(ref ptr, library.Ptr, arr.ArrayPtr(), (ulong) arr.Length,
canFlee.ToNative(), numberOfSides, pokemonPerSide, randomSeed);
canFlee.ToNative(), numberOfSides, pokemonPerSide, randomSeed).Assert();
Initialize(ptr);
}

View File

@ -38,14 +38,24 @@ namespace PkmnLibSharp.Battling
IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs, StatisticSet<byte> evs,
Nature nature)
{
return Pkmnlib.Generated.Pokemon.Construct(library.Ptr, species.Ptr, forme.Ptr, level, experience,
uid, (Pkmnlib.Gender) gender, coloring, heldItem?.Ptr ?? IntPtr.Zero, nickname.ToPtr(),
var movesArr = moves.Select(x => x?.Ptr ?? IntPtr.Zero).ToArray();
var libraryPtr = library.Ptr;
var speciesPtr = species.Ptr;
var formePtr = forme.Ptr;
var heldItemPtr = heldItem?.Ptr;
var nicknamePtr = nickname.ToPtr();
var naturePtr = nature.Ptr;
var ptr = IntPtr.Zero;
Pkmnlib.Generated.Pokemon.Construct(ref ptr, libraryPtr, speciesPtr, formePtr, level, experience,
uid, (Pkmnlib.Gender) gender, coloring, heldItemPtr ?? IntPtr.Zero, nicknamePtr,
hiddenAbility.ToNative(), abilityIndex,
moves.Select(x => x?.Ptr ?? IntPtr.Zero).ToArray().ArrayPtr(),
(ulong) moves.Count,
movesArr.ArrayPtr(), (ulong) moves.Count,
ivs.HP, ivs.Attack, ivs.Defense, ivs.SpecialAttack,
ivs.SpecialDefense, ivs.Speed, evs.HP, evs.Attack, evs.Defense,
evs.SpecialAttack, evs.SpecialDefense, evs.Speed, nature.Ptr);
evs.SpecialAttack, evs.SpecialDefense, evs.Speed, naturePtr).Assert();
return ptr;
}
public BattleLibrary Library { get; private set; }

View File

@ -10,10 +10,10 @@ namespace Arbutils.Generated
[DllImport("libArbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_C_GetLastException")]
internal static extern IntPtr GetLastException();
/// <param name="">Function *</param>
/// <param name="callback">Function *</param>
/// <returns>void</returns>
[DllImport("libArbutils", CallingConvention = CallingConvention.Cdecl, EntryPoint= "Arbutils_C_SetSignalCallback")]
internal static extern void SetSignalCallback(IntPtr _);
internal static extern void SetSignalCallback(IntPtr callback);
}
}

View File

@ -149,6 +149,12 @@ namespace Creaturelib.Generated
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_GetNickname")]
internal static extern IntPtr GetNickname(IntPtr p);
/// <param name="p">Creature *</param>
/// <param name="nickname">const char *</param>
/// <returns>void</returns>
[DllImport("libCreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_SetNickname")]
internal static extern void SetNickname(IntPtr p, IntPtr nickname);
/// <param name="p">Creature *</param>
/// <param name="type">unsigned char</param>
/// <returns>bool</returns>

View File

@ -6,6 +6,7 @@ namespace Pkmnlib.Generated
{
internal static class Pokemon
{
/// <param name="out">Pokemon * &</param>
/// <param name="library">const BattleLibrary *</param>
/// <param name="species">const PokemonSpecies *</param>
/// <param name="forme">const PokemonForme *</param>
@ -33,9 +34,9 @@ namespace Pkmnlib.Generated
/// <param name="sDeEv">unsigned char</param>
/// <param name="spEv">unsigned char</param>
/// <param name="nature">const Nature *</param>
/// <returns>Pokemon *</returns>
/// <returns>unsigned char</returns>
[DllImport("libpkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Pokemon_Construct")]
internal static extern IntPtr Construct(IntPtr library, IntPtr species, IntPtr forme, byte level, uint experience, uint uid, Gender gender, byte coloring, IntPtr heldItem, IntPtr nickname, byte hiddenAbility, byte abilityIndex, IntPtr moves, ulong moveCount, byte hpIv, byte attIv, byte defIv, byte sAtIv, byte sDeIv, byte spIv, byte hpEv, byte attEv, byte defEv, byte sAtEv, byte sDeEv, byte spEv, IntPtr nature);
internal static extern byte Construct(ref IntPtr @out, IntPtr library, IntPtr species, IntPtr forme, byte level, uint experience, uint uid, Gender gender, byte coloring, IntPtr heldItem, IntPtr nickname, byte hiddenAbility, byte abilityIndex, IntPtr moves, ulong moveCount, byte hpIv, byte attIv, byte defIv, byte sAtIv, byte sDeIv, byte spIv, byte hpEv, byte attEv, byte defEv, byte sAtEv, byte sDeEv, byte spEv, IntPtr nature);
/// <param name="p">const Pokemon *</param>
/// <returns>void</returns>

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

Binary file not shown.

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

Binary file not shown.

Binary file not shown.

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

Binary file not shown.

View File

@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<Configurations>Debug</Configurations>
<Platforms>AnyCPU</Platforms>
<Platforms>x64</Platforms>
<Nullable>enable</Nullable>
<WarningsAsErrors>CS8600;CS8601;CS8602;CS8603;CS8604;CS8618</WarningsAsErrors>
<LangVersion>8</LangVersion>
<LangVersion>9</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
@ -19,7 +19,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nullable" Version="1.2.1">
<PackageReference Include="Nullable" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@ -23,8 +23,8 @@ namespace PkmnLibSharp.Utilities
private bool _isDeleted = false;
private static readonly ConcurrentDictionary<IntPtr, WeakReference<object>> Cached =
new ConcurrentDictionary<IntPtr, WeakReference<object>>();
private static readonly ConcurrentDictionary<IntPtr, WeakReference<PointerWrapper>> Cached =
new ConcurrentDictionary<IntPtr, WeakReference<PointerWrapper>>();
private protected PointerWrapper()
{
@ -37,8 +37,12 @@ namespace PkmnLibSharp.Utilities
protected internal virtual void Initialize(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
{
throw new NullReferenceException("Initializing pointer was nullptr");
}
_ptr = ptr;
var weakRef = new WeakReference<object>(this);
var weakRef = new WeakReference<PointerWrapper>(this);
Cached.AddOrUpdate(ptr, weakRef, (intPtr, reference) => weakRef);
}

View File

@ -1,3 +1,5 @@
using System;
namespace PkmnLibSharp.Utilities
{
public class Random : PointerWrapper

View File

@ -1 +1 @@
{"enums":[{"byteSize":4,"filename":"libArbutils","name":"float_denorm_style","values":{"-1":"denorm_indeterminate","0":"denorm_absent","1":"denorm_present"}},{"byteSize":4,"filename":"libArbutils","name":"float_round_style","values":{"-1":"round_indeterminate","0":"round_toward_zero","1":"round_to_nearest","2":"round_toward_infinity","3":"round_toward_neg_infinity"}}],"functions":[{"filename":"libArbutils","name":"Arbutils_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"libArbutils","name":"Arbutils_C_SetSignalCallback","parameters":[{"name":"","type":"Function *"}],"returns":"void"},{"filename":"libArbutils","name":"Arbutils_Random_Construct","parameters":[],"returns":"Random *"},{"filename":"libArbutils","name":"Arbutils_Random_ConstructWithSeed","parameters":[{"name":"seed","type":"long unsigned int"}],"returns":"Random *"},{"filename":"libArbutils","name":"Arbutils_Random_Destruct","parameters":[{"name":"p","type":"Random *"}],"returns":"void"},{"filename":"libArbutils","name":"Arbutils_Random_GetFloat","parameters":[{"name":"p","type":"Random *"}],"returns":"float"},{"filename":"libArbutils","name":"Arbutils_Random_GetDouble","parameters":[{"name":"p","type":"Random *"}],"returns":"double"},{"filename":"libArbutils","name":"Arbutils_Random_Get","parameters":[{"name":"p","type":"Random *"}],"returns":"int"},{"filename":"libArbutils","name":"Arbutils_Random_GetWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"libArbutils","name":"Arbutils_Random_GetInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"int"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"libArbutils","name":"Arbutils_Random_GetUnsigned","parameters":[{"name":"p","type":"Random *"}],"returns":"unsigned int"},{"filename":"libArbutils","name":"Arbutils_Random_GetUnsignedWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"libArbutils","name":"Arbutils_Random_GetUnsignedInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"unsigned int"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"libArbutils","name":"Arbutils_Random_GetSeed","parameters":[{"name":"p","type":"Random *"}],"returns":"long unsigned int"}]}
{"enums":[{"byteSize":4,"filename":"libArbutils","name":"float_denorm_style","values":{"-1":"denorm_indeterminate","0":"denorm_absent","1":"denorm_present"}},{"byteSize":4,"filename":"libArbutils","name":"float_round_style","values":{"-1":"round_indeterminate","0":"round_toward_zero","1":"round_to_nearest","2":"round_toward_infinity","3":"round_toward_neg_infinity"}}],"functions":[{"filename":"libArbutils","name":"Arbutils_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"libArbutils","name":"Arbutils_C_SetSignalCallback","parameters":[{"name":"callback","type":"Function *"}],"returns":"void"},{"filename":"libArbutils","name":"Arbutils_Random_Construct","parameters":[],"returns":"Random *"},{"filename":"libArbutils","name":"Arbutils_Random_ConstructWithSeed","parameters":[{"name":"seed","type":"long unsigned int"}],"returns":"Random *"},{"filename":"libArbutils","name":"Arbutils_Random_Destruct","parameters":[{"name":"p","type":"Random *"}],"returns":"void"},{"filename":"libArbutils","name":"Arbutils_Random_GetFloat","parameters":[{"name":"p","type":"Random *"}],"returns":"float"},{"filename":"libArbutils","name":"Arbutils_Random_GetDouble","parameters":[{"name":"p","type":"Random *"}],"returns":"double"},{"filename":"libArbutils","name":"Arbutils_Random_Get","parameters":[{"name":"p","type":"Random *"}],"returns":"int"},{"filename":"libArbutils","name":"Arbutils_Random_GetWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"libArbutils","name":"Arbutils_Random_GetInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"int"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"libArbutils","name":"Arbutils_Random_GetUnsigned","parameters":[{"name":"p","type":"Random *"}],"returns":"unsigned int"},{"filename":"libArbutils","name":"Arbutils_Random_GetUnsignedWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"libArbutils","name":"Arbutils_Random_GetUnsignedInLimits","parameters":[{"name":"p","type":"Random *"},{"name":"min","type":"unsigned int"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"libArbutils","name":"Arbutils_Random_GetSeed","parameters":[{"name":"p","type":"Random *"}],"returns":"long unsigned int"}]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
using System.Linq;
using NUnit.Framework;
using PkmnLibSharp.Battling;
using PkmnLibSharp.Library;
using PkmnLibSharp.Library.GrowthRates;
@ -10,16 +11,24 @@ namespace PkmnLibSharpTests.Battling
public static class BattleLibraryHelper
{
private static BattleLibrary _cache;
private static readonly object Lock = new object();
public static BattleLibrary GetLibrary()
{
if (_cache != null) return _cache;
lock (Lock)
{
if (_cache != null)
return _cache;
TestContext.WriteLine("Building battle library");
var scriptLibrary = new AngelScriptResolver();
_cache = new BattleLibrary(BuildStatic(), new StatCalculator(), new DamageLibrary(),
new ExperienceLibrary(),
new AngelScriptResolver(), new MiscLibrary());
scriptLibrary, new MiscLibrary());
scriptLibrary.Initialize(_cache);
return _cache;
}
}
private static PokemonLibrary BuildStatic()
{

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using PkmnLibSharp.Battling;
using PkmnLibSharp.Library;
@ -15,7 +16,7 @@ namespace PkmnLibSharpTests.Battling
protected override Pokemon Finalize(Species species, Forme forme, Item? heldItem, IReadOnlyCollection<LearnedMove> moves, Nature nature)
{
var pkmn = new Pokemon(Library, species, forme!, Level, Experience, Uid, Gender, Coloring,
var pkmn = new Pokemon(Library, species, forme, Level, Experience, Uid, Gender, Coloring,
heldItem, Nickname, HiddenAbility, (byte) AbilityIndex, moves, IVs, EVs, nature);
return pkmn;
}

View File

@ -1,3 +1,4 @@
using System;
using NUnit.Framework;
using PkmnLibSharp.Battling;
using PkmnLibSharp.Library;

View File

@ -7,13 +7,13 @@
<Configurations>Debug</Configurations>
<Platforms>AnyCPU</Platforms>
<Platforms>x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>

View File

@ -4,6 +4,7 @@ using System.Runtime.InteropServices;
using NUnit.Framework;
using PkmnLibSharp.Battling;
using PkmnLibSharp.Utilities;
using PkmnLibSharpTests.Battling;
namespace PkmnLibSharpTests
{
@ -15,6 +16,7 @@ namespace PkmnLibSharpTests
{
NativeLibrary.Load("Arbutils", Assembly.GetCallingAssembly(), DllImportSearchPath.AssemblyDirectory);
NativeLibrary.Load("CreatureLib", Assembly.GetCallingAssembly(), DllImportSearchPath.AssemblyDirectory);
NativeLibrary.Load("libangelscript.so.2.35.0", Assembly.GetCallingAssembly(), DllImportSearchPath.AssemblyDirectory);
NativeLibrary.Load("pkmnLib", Assembly.GetCallingAssembly(), DllImportSearchPath.AssemblyDirectory);
LogHandler.RegisterListener((level, s) =>
@ -24,5 +26,6 @@ namespace PkmnLibSharpTests
SignalHandler.SetSignalListener(s => throw new Exception("Encountered a catastrophic signal. \n" + s));
}
}
}