Rework misclibrary gettime to not segfault

This commit is contained in:
Deukhoofd 2021-07-09 18:20:01 +02:00
parent c2d846c2f6
commit a59f73b2f6
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 18 additions and 19 deletions

View File

@ -11,22 +11,16 @@ namespace PkmnLibSharp.Battling
{ {
public class MiscLibrary : PointerWrapper public class MiscLibrary : PointerWrapper
{ {
private delegate TimeOfDay GetTimeDelegate(); public delegate TimeOfDay GetTimeDelegate();
internal MiscLibrary(IntPtr ptr) : base(ptr) internal MiscLibrary(IntPtr ptr) : base(ptr)
{ {
} }
public MiscLibrary() public MiscLibrary(GetTimeDelegate @delegate)
{ {
GetTimeDelegate getTime = GetTime; Initialize(Pkmnlib.Generated.MiscLibrary.Construct(Marshal.GetFunctionPointerForDelegate(@delegate)));
Initialize(Pkmnlib.Generated.MiscLibrary.Construct(Marshal.GetFunctionPointerForDelegate(getTime)));
} }
public virtual TimeOfDay GetTime()
{
return TimeOfDay.Morning;
}
public bool IsCritical(IntPtr move, Pokemon target, byte hitNumber) public bool IsCritical(IntPtr move, Pokemon target, byte hitNumber)
{ {
byte b = 0; byte b = 0;

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

Binary file not shown.

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

View File

@ -24,12 +24,17 @@ namespace PkmnLibSharpTests.Battling
var scriptLibrary = new AngelScriptResolver(); var scriptLibrary = new AngelScriptResolver();
_cache = new BattleLibrary(BuildStatic(), new StatCalculator(), new DamageLibrary(), _cache = new BattleLibrary(BuildStatic(), new StatCalculator(), new DamageLibrary(),
new ExperienceLibrary(), new ExperienceLibrary(),
scriptLibrary, new MiscLibrary()); scriptLibrary, new MiscLibrary(GetTime));
scriptLibrary.Initialize(_cache); scriptLibrary.Initialize(_cache);
return _cache; return _cache;
} }
} }
public static TimeOfDay GetTime()
{
return TimeOfDay.Morning;
}
private static PokemonLibrary BuildStatic() private static PokemonLibrary BuildStatic()
{ {
var settings = new LibrarySettings(100, 4, 4096); var settings = new LibrarySettings(100, 4, 4096);