Several fixes and improvements.

This commit is contained in:
Deukhoofd 2020-08-17 18:51:07 +02:00
parent 00cfd3c469
commit 743c63a99c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
44 changed files with 378 additions and 419 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using PkmnLibSharp.Battling.ChoiceTurn;
using PkmnLibSharp.Battling.Events;
using PkmnLibSharp.Battling.History;
using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Battling
@ -88,6 +89,19 @@ namespace PkmnLibSharp.Battling
public string? WeatherName => Pkmnlib.Generated.Battle.GetWeatherName(Ptr).PtrString();
public HistoryHandler History
{
get
{
if (_history != null) return _history;
var ptr = Creaturelib.Generated.Battle.GetHistory(Ptr);
if (TryResolvePointer(ptr, out _history))
return _history!;
_history = new HistoryHandler(ptr);
return _history;
}
}
public bool CanUse(BaseTurnChoice turnChoice)
{
@ -201,6 +215,7 @@ namespace PkmnLibSharp.Battling
private BattleRandom? _random;
private ReadOnlyNativePtrArray<BattleSide>? _sides;
private ReadOnlyNativePtrArray<BattleParty>? _parties;
private HistoryHandler? _history;
protected override void DeletePtr()
{

View File

@ -1,12 +1,72 @@
using System;
using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Battling
{
public class ExecutingMove : PointerWrapper
{
internal ExecutingMove(IntPtr ptr) : base(ptr){}
public LearnedMove Move
{
get
{
if (_move != null) return _move;
var ptr = Creaturelib.Generated.ExecutingAttack.GetAttack(Ptr);
if (TryResolvePointer(ptr, out _move))
return _move!;
_move = new LearnedMove(ptr);
return _move;
}
}
public Pokemon User
{
get
{
if (_user != null) return _user;
var ptr = Creaturelib.Generated.ExecutingAttack.GetUser(Ptr);
if (TryResolvePointer(ptr, out _user))
return _user!;
_user = new Pokemon(ptr);
return _user;
}
}
/// <summary>
/// Get the first hit for the first target. Honestly just here so I can quickly read hit info from my debugger.
/// </summary>
public HitData FirstHit => GetHitData(Targets[0], 0);
public ReadOnlyNativePtrArray<Pokemon> Targets
{
get
{
if (_targets != null) return _targets;
var size = Creaturelib.Generated.ExecutingAttack.GetTargetCount(Ptr);
var ptr = Creaturelib.Generated.ExecutingAttack.GetTargets(Ptr);
_targets = new ReadOnlyNativePtrArray<Pokemon>(ptr, size);
return _targets;
}
}
public HitData GetHitData(Pokemon target, byte index)
{
var ptr = IntPtr.Zero;
Creaturelib.Generated.ExecutingAttack.GetHitData(ref ptr, Ptr, target.Ptr, index).Assert();
return new HitData(ptr);
}
public bool IsPokemonTarget(Pokemon pokemon)
{
return Creaturelib.Generated.ExecutingAttack.IsCreatureTarget(Ptr, pokemon.Ptr) == 1;
}
private LearnedMove? _move;
private Pokemon? _user;
private ReadOnlyNativePtrArray<Pokemon>? _targets;
protected override void DeletePtr()
{
throw new System.NotImplementedException();
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Battling
{
public class HitData : PointerWrapper
{
internal HitData(IntPtr ptr) : base(ptr){}
public byte BasePower => Creaturelib.Generated.HitData.GetBasePower(Ptr);
public bool IsCritical => Creaturelib.Generated.HitData.IsCritical(Ptr) == 1;
public float Effectiveness => Creaturelib.Generated.HitData.GetEffectiveness(Ptr);
public uint Damage => Creaturelib.Generated.HitData.GetDamage(Ptr);
public byte Type => Creaturelib.Generated.HitData.GetType(Ptr);
protected override void DeletePtr()
{
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Battling.History
{
public abstract class HistoryElement : PointerWrapper
{
internal HistoryElement(IntPtr ptr) : base(ptr){}
public HistoryElementKind Kind => (HistoryElementKind) Creaturelib.Generated.HistoryElement.GetKind(Ptr);
public HistoryElement? GetPrevious()
{
if (_previous != null) return _previous;
var ptr = Creaturelib.Generated.HistoryElement.GetPrevious(Ptr);
_previous = Construct(ptr);
return _previous;
}
internal static HistoryElement? Construct(IntPtr ptr)
{
if (ptr == IntPtr.Zero) return null;
var kind = (HistoryElementKind) Creaturelib.Generated.HistoryElement.GetKind(ptr);
switch (kind)
{
case HistoryElementKind.MoveUse:
return new MoveUseHistory(ptr);
default:
throw new ArgumentOutOfRangeException();
}
}
private HistoryElement? _previous;
protected override void DeletePtr()
{
}
}
}

View File

@ -0,0 +1,7 @@
namespace PkmnLibSharp.Battling.History
{
public enum HistoryElementKind : byte
{
MoveUse = 0,
}
}

View File

@ -0,0 +1,43 @@
using System;
using System.Collections;
using System.Collections.Generic;
using PkmnLibSharp.Utilities;
namespace PkmnLibSharp.Battling.History
{
public class HistoryHandler : PointerWrapper
{
internal HistoryHandler(IntPtr ptr) : base(ptr){}
public HistoryElement? TopElement
{
get
{
var ptr = Creaturelib.Generated.HistoryHandler.GetTopElement(Ptr);
return HistoryElement.Construct(ptr);
}
}
public HistoryElement? GetLastUsedMove()
{
var ptr = Creaturelib.Generated.HistoryHandler.GetLastUsedAttack(Ptr);
return HistoryElement.Construct(ptr);
}
public IEnumerable<HistoryElement> GetIterator()
{
var top = TopElement;
if (top == null) yield break;
while (top != null)
{
yield return top;
top = top.GetPrevious();
}
}
protected override void DeletePtr()
{
}
}
}

View File

@ -0,0 +1,24 @@
using System;
namespace PkmnLibSharp.Battling.History
{
public class MoveUseHistory : HistoryElement
{
internal MoveUseHistory(IntPtr ptr) : base(ptr)
{
}
public ExecutingMove Move
{
get
{
if (_move != null) return _move;
var ptr = Creaturelib.Generated.AttackUseHistory.GetAttack(Ptr);
_move = new ExecutingMove(ptr);
return _move;
}
}
private ExecutingMove? _move;
}
}

View File

@ -32,6 +32,7 @@ namespace PkmnLibSharp.Battling
evs.SpecialAttack, evs.SpecialDefense, evs.Speed, nature.Ptr))
{
Library = library;
Initialize();
}
public BattleLibrary Library { get; private set; }
@ -274,6 +275,11 @@ namespace PkmnLibSharp.Battling
public string? StatusName => Pkmnlib.Generated.Pokemon.GetStatusName(Ptr).PtrString();
public void Initialize()
{
Creaturelib.Generated.Creature.Initialize(Ptr).Assert();
}
public void ChangeForme(Forme forme)
{
_forme = null;

View File

@ -183,6 +183,12 @@ namespace PkmnLibSharp.Battling
}
var nature = Library.StaticLibrary.NatureLibrary.GetNature(Nature);
if (Gender == (Gender) (-1))
{
Gender = species.GetRandomGender(random);
}
return Finalize(species, forme!, heldItem, moves, nature);
}
}

View File

@ -0,0 +1,15 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace Creaturelib.Generated
{
internal static class AttackUseHistory
{
/// <param name="p">const AttackUseHistory *</param>
/// <returns>const ExecutingAttack *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_AttackUseHistory_GetAttack")]
internal static extern IntPtr GetAttack(IntPtr p);
}
}

View File

@ -192,5 +192,10 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Battle_RegisterEventListener")]
internal static extern byte RegisterEventListener(IntPtr p, IntPtr func);
/// <param name="p">Battle *</param>
/// <returns>const HistoryHolder *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Battle_GetHistory")]
internal static extern IntPtr GetHistory(IntPtr p);
}
}

View File

@ -10,5 +10,9 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_C_GetLastException")]
internal static extern IntPtr GetLastException();
/// <returns>const char *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_C_GetLastExceptionStacktrace")]
internal static extern IntPtr GetLastExceptionStacktrace();
}
}

View File

@ -31,6 +31,11 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_Destruct")]
internal static extern void Destruct(IntPtr p);
/// <param name="p">Creature *</param>
/// <returns>unsigned char</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_Initialize")]
internal static extern byte Initialize(IntPtr p);
/// <param name="p">const Creature *</param>
/// <returns>const BattleLibrary *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_Creature_GetLibrary")]

View File

@ -36,6 +36,16 @@ namespace Creaturelib.Generated
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ExecutingAttack_IsCreatureTarget")]
internal static extern byte IsCreatureTarget(IntPtr p, IntPtr target);
/// <param name="p">ExecutingAttack *</param>
/// <returns>unsigned char</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ExecutingAttack_GetTargetCount")]
internal static extern byte GetTargetCount(IntPtr p);
/// <param name="p">ExecutingAttack *</param>
/// <returns>const const Creature * *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ExecutingAttack_GetTargets")]
internal static extern IntPtr GetTargets(IntPtr p);
/// <param name="p">ExecutingAttack *</param>
/// <returns>Creature *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_ExecutingAttack_GetUser")]

View File

@ -0,0 +1,20 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace Creaturelib.Generated
{
internal static class HistoryElement
{
/// <param name="p">const HistoryElement *</param>
/// <returns>HistoryElementKind</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_HistoryElement_GetKind")]
internal static extern HistoryElementKind GetKind(IntPtr p);
/// <param name="p">const HistoryElement *</param>
/// <returns>const HistoryElement *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_HistoryElement_GetPrevious")]
internal static extern IntPtr GetPrevious(IntPtr p);
}
}

View File

@ -1,13 +1,11 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
namespace Creaturelib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asEMsgType : int
internal enum HistoryElementKind : byte
{
asMSGTYPE_ERROR = 0,
asMSGTYPE_WARNING = 1,
asMSGTYPE_INFORMATION = 2,
AttackUse = 0,
}
}

View File

@ -0,0 +1,20 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace Creaturelib.Generated
{
internal static class HistoryHandler
{
/// <param name="p">const HistoryHolder *</param>
/// <returns>const HistoryElement *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_HistoryHandler_GetTopElement")]
internal static extern IntPtr GetTopElement(IntPtr p);
/// <param name="p">const HistoryHolder *</param>
/// <returns>const HistoryElement *</returns>
[DllImport("CreatureLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "CreatureLib_HistoryHandler_GetLastUsedAttack")]
internal static extern IntPtr GetLastUsedAttack(IntPtr p);
}
}

View File

@ -1,88 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace Pkmnlib.Generated
{
internal static class Evolution
{
/// <param name="time">TimeOfDay</param>
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateTimeEvolution")]
internal static extern IntPtr CreateTimeEvolution(TimeOfDay time, IntPtr into);
/// <param name="item">const Item *</param>
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateItemEvolution")]
internal static extern IntPtr CreateItemEvolution(IntPtr item, IntPtr into);
/// <param name="gender">Gender</param>
/// <param name="level">unsigned char</param>
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateGenderBasedEvolution")]
internal static extern IntPtr CreateGenderBasedEvolution(Gender gender, byte level, IntPtr into);
/// <param name="item">const Item *</param>
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateItemUseEvolution")]
internal static extern IntPtr CreateItemUseEvolution(IntPtr item, IntPtr into);
/// <param name="item">const Item *</param>
/// <param name="gender">Gender</param>
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateItemUseWithGenderEvolution")]
internal static extern IntPtr CreateItemUseWithGenderEvolution(IntPtr item, Gender gender, IntPtr into);
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateTradeEvolution")]
internal static extern IntPtr CreateTradeEvolution(IntPtr into);
/// <param name="item">const Item *</param>
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateTradeWithItemEvolution")]
internal static extern IntPtr CreateTradeWithItemEvolution(IntPtr item, IntPtr into);
/// <param name="traded">const PokemonSpecies *</param>
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateTradeWithSpeciesEvolution")]
internal static extern IntPtr CreateTradeWithSpeciesEvolution(IntPtr traded, IntPtr into);
/// <param name="data">const EffectParameter * *</param>
/// <param name="dataLength">long unsigned int</param>
/// <param name="into">const PokemonSpecies *</param>
/// <returns>const EvolutionData *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_CreateCustomEvolution")]
internal static extern IntPtr CreateCustomEvolution(IntPtr data, ulong dataLength, IntPtr into);
/// <param name="data">const EvolutionData *</param>
/// <returns>EvolutionMethod</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_GetMethod")]
internal static extern EvolutionMethod GetMethod(IntPtr data);
/// <param name="data">const EvolutionData *</param>
/// <returns>const PokemonSpecies *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_GetNewSpecies")]
internal static extern IntPtr GetNewSpecies(IntPtr data);
/// <param name="data">const EvolutionData *</param>
/// <returns>long unsigned int</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_GetDataCount")]
internal static extern ulong GetDataCount(IntPtr data);
/// <param name="data">const EvolutionData *</param>
/// <param name="index">long unsigned int</param>
/// <param name="out">const EffectParameter * &</param>
/// <returns>unsigned char</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_Evolution_GetData")]
internal static extern byte GetData(IntPtr data, ulong index, ref IntPtr @out);
}
}

View File

@ -0,0 +1,33 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System;
using System.Runtime.InteropServices;
namespace Pkmnlib.Generated
{
internal static class PokemonForme
{
/// <param name="name">const char *</param>
/// <param name="height">float</param>
/// <param name="weight">float</param>
/// <param name="baseExperience">unsigned int</param>
/// <param name="types">unsigned char *</param>
/// <param name="typeLength">long unsigned int</param>
/// <param name="baseHealth">unsigned short</param>
/// <param name="baseAttack">unsigned short</param>
/// <param name="baseDefense">unsigned short</param>
/// <param name="baseMagicalAttack">unsigned short</param>
/// <param name="baseMagicalDefense">unsigned short</param>
/// <param name="baseSpeed">unsigned short</param>
/// <param name="talents">const char * *</param>
/// <param name="talentsLength">long unsigned int</param>
/// <param name="secretTalents">const char * *</param>
/// <param name="secretTalentsLength">long unsigned int</param>
/// <param name="attacks">const LearnableMoves *</param>
/// <param name="flags">const char * *</param>
/// <param name="flagsCount">long unsigned int</param>
/// <returns>PokemonForme *</returns>
[DllImport("pkmnLib", CallingConvention = CallingConvention.Cdecl, EntryPoint= "PkmnLib_PokemonForme_Construct")]
internal static extern IntPtr Construct(IntPtr name, float height, float weight, uint baseExperience, IntPtr types, ulong typeLength, ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseMagicalAttack, ushort baseMagicalDefense, ushort baseSpeed, IntPtr talents, ulong talentsLength, IntPtr secretTalents, ulong secretTalentsLength, IntPtr attacks, IntPtr flags, ulong flagsCount);
}
}

View File

@ -1,25 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asEBehaviours : int
{
asBEHAVE_CONSTRUCT = 0,
asBEHAVE_LIST_CONSTRUCT = 1,
asBEHAVE_DESTRUCT = 2,
asBEHAVE_FACTORY = 3,
asBEHAVE_LIST_FACTORY = 4,
asBEHAVE_ADDREF = 5,
asBEHAVE_RELEASE = 6,
asBEHAVE_GET_WEAKREF_FLAG = 7,
asBEHAVE_TEMPLATE_CALLBACK = 8,
asBEHAVE_FIRST_GC = 9,
asBEHAVE_SETGCFLAG = 10,
asBEHAVE_GETGCFLAG = 11,
asBEHAVE_ENUMREFS = 12,
asBEHAVE_RELEASEREFS = 13,
asBEHAVE_MAX = 14,
}
}

View File

@ -1,19 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asECallConvTypes : int
{
asCALL_CDECL = 0,
asCALL_STDCALL = 1,
asCALL_THISCALL_ASGLOBAL = 2,
asCALL_THISCALL = 3,
asCALL_CDECL_OBJLAST = 4,
asCALL_CDECL_OBJFIRST = 5,
asCALL_GENERIC = 6,
asCALL_THISCALL_OBJLAST = 7,
asCALL_THISCALL_OBJFIRST = 8,
}
}

View File

@ -1,18 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asEContextState : int
{
asEXECUTION_FINISHED = 0,
asEXECUTION_SUSPENDED = 1,
asEXECUTION_ABORTED = 2,
asEXECUTION_EXCEPTION = 3,
asEXECUTION_PREPARED = 4,
asEXECUTION_UNINITIALIZED = 5,
asEXECUTION_ACTIVE = 6,
asEXECUTION_ERROR = 7,
}
}

View File

@ -1,42 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asEEngineProp : int
{
asEP_ALLOW_UNSAFE_REFERENCES = 1,
asEP_OPTIMIZE_BYTECODE = 2,
asEP_COPY_SCRIPT_SECTIONS = 3,
asEP_MAX_STACK_SIZE = 4,
asEP_USE_CHARACTER_LITERALS = 5,
asEP_ALLOW_MULTILINE_STRINGS = 6,
asEP_ALLOW_IMPLICIT_HANDLE_TYPES = 7,
asEP_BUILD_WITHOUT_LINE_CUES = 8,
asEP_INIT_GLOBAL_VARS_AFTER_BUILD = 9,
asEP_REQUIRE_ENUM_SCOPE = 10,
asEP_SCRIPT_SCANNER = 11,
asEP_INCLUDE_JIT_INSTRUCTIONS = 12,
asEP_STRING_ENCODING = 13,
asEP_PROPERTY_ACCESSOR_MODE = 14,
asEP_EXPAND_DEF_ARRAY_TO_TMPL = 15,
asEP_AUTO_GARBAGE_COLLECT = 16,
asEP_DISALLOW_GLOBAL_VARS = 17,
asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT = 18,
asEP_COMPILER_WARNINGS = 19,
asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE = 20,
asEP_ALTER_SYNTAX_NAMED_ARGS = 21,
asEP_DISABLE_INTEGER_DIVISION = 22,
asEP_DISALLOW_EMPTY_LIST_ELEMENTS = 23,
asEP_PRIVATE_PROP_AS_PROTECTED = 24,
asEP_ALLOW_UNICODE_IDENTIFIERS = 25,
asEP_HEREDOC_TRIM_MODE = 26,
asEP_MAX_NESTED_CALLS = 27,
asEP_GENERIC_CALL_MODE = 28,
asEP_INIT_STACK_SIZE = 29,
asEP_INIT_CALL_STACK_SIZE = 30,
asEP_MAX_CALL_STACK_SIZE = 31,
asEP_LAST_PROPERTY = 32,
}
}

View File

@ -1,18 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asEFuncType : int
{
asFUNC_DUMMY = -1,
asFUNC_SYSTEM = 0,
asFUNC_SCRIPT = 1,
asFUNC_INTERFACE = 2,
asFUNC_VIRTUAL = 3,
asFUNC_FUNCDEF = 4,
asFUNC_IMPORTED = 5,
asFUNC_DELEGATE = 6,
}
}

View File

@ -1,13 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asEGMFlags : int
{
asGM_ONLY_IF_EXISTS = 0,
asGM_CREATE_IF_NOT_EXISTS = 1,
asGM_ALWAYS_CREATE = 2,
}
}

View File

@ -1,57 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asEObjTypeFlags : int
{
asOBJ_REF = 1,
asOBJ_VALUE = 2,
asOBJ_GC = 4,
asOBJ_POD = 8,
asOBJ_NOHANDLE = 16,
asOBJ_SCOPED = 32,
asOBJ_TEMPLATE = 64,
asOBJ_ASHANDLE = 128,
asOBJ_APP_CLASS = 256,
asOBJ_APP_CLASS_CONSTRUCTOR = 512,
asOBJ_APP_CLASS_C = 768,
asOBJ_APP_CLASS_DESTRUCTOR = 1024,
asOBJ_APP_CLASS_D = 1280,
asOBJ_APP_CLASS_CD = 1792,
asOBJ_APP_CLASS_ASSIGNMENT = 2048,
asOBJ_APP_CLASS_A = 2304,
asOBJ_APP_CLASS_CA = 2816,
asOBJ_APP_CLASS_DA = 3328,
asOBJ_APP_CLASS_CDA = 3840,
asOBJ_APP_CLASS_COPY_CONSTRUCTOR = 4096,
asOBJ_APP_CLASS_K = 4352,
asOBJ_APP_CLASS_CK = 4864,
asOBJ_APP_CLASS_DK = 5376,
asOBJ_APP_CLASS_CDK = 5888,
asOBJ_APP_CLASS_AK = 6400,
asOBJ_APP_CLASS_CAK = 6912,
asOBJ_APP_CLASS_DAK = 7424,
asOBJ_APP_CLASS_CDAK = 7936,
asOBJ_APP_PRIMITIVE = 8192,
asOBJ_APP_FLOAT = 16384,
asOBJ_APP_ARRAY = 32768,
asOBJ_APP_CLASS_ALLINTS = 65536,
asOBJ_APP_CLASS_ALLFLOATS = 131072,
asOBJ_NOCOUNT = 262144,
asOBJ_APP_CLASS_ALIGN8 = 524288,
asOBJ_IMPLICIT_HANDLE = 1048576,
asOBJ_MASK_VALID_FLAGS = 2097151,
asOBJ_SCRIPT_OBJECT = 2097152,
asOBJ_SHARED = 4194304,
asOBJ_NOINHERIT = 8388608,
asOBJ_FUNCDEF = 16777216,
asOBJ_LIST_PATTERN = 33554432,
asOBJ_ENUM = 67108864,
asOBJ_TEMPLATE_SUBTYPE = 134217728,
asOBJ_TYPEDEF = 268435456,
asOBJ_ABSTRACT = 536870912,
asOBJ_APP_ALIGN16 = 1073741824,
}
}

View File

@ -1,39 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asERetCodes : int
{
asMODULE_IS_IN_USE = -28,
asOUT_OF_MEMORY = -27,
asINIT_GLOBAL_VARS_FAILED = -26,
asBUILD_IN_PROGRESS = -25,
asWRONG_CALLING_CONV = -24,
asILLEGAL_BEHAVIOUR_FOR_TYPE = -23,
asCONFIG_GROUP_IS_IN_USE = -22,
asWRONG_CONFIG_GROUP = -21,
asLOWER_ARRAY_DIMENSION_NOT_REGISTERED = -20,
asCANT_BIND_ALL_FUNCTIONS = -19,
asINVALID_INTERFACE = -18,
asINVALID_CONFIGURATION = -17,
asNO_GLOBAL_VAR = -16,
asNO_MODULE = -15,
asMULTIPLE_FUNCTIONS = -14,
asALREADY_REGISTERED = -13,
asINVALID_TYPE = -12,
asINVALID_OBJECT = -11,
asINVALID_DECLARATION = -10,
asNAME_TAKEN = -9,
asINVALID_NAME = -8,
asNOT_SUPPORTED = -7,
asNO_FUNCTION = -6,
asINVALID_ARG = -5,
asCONTEXT_NOT_PREPARED = -4,
asCONTEXT_NOT_FINISHED = -3,
asCONTEXT_ACTIVE = -2,
asERROR = -1,
asSUCCESS = 0,
}
}

View File

@ -1,16 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asETokenClass : int
{
asTC_UNKNOWN = 0,
asTC_KEYWORD = 1,
asTC_VALUE = 2,
asTC_IDENTIFIER = 3,
asTC_COMMENT = 4,
asTC_WHITESPACE = 5,
}
}

View File

@ -1,29 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asETypeIdFlags : int
{
asTYPEID_VOID = 0,
asTYPEID_BOOL = 1,
asTYPEID_INT8 = 2,
asTYPEID_INT16 = 3,
asTYPEID_INT32 = 4,
asTYPEID_INT64 = 5,
asTYPEID_UINT8 = 6,
asTYPEID_UINT16 = 7,
asTYPEID_UINT32 = 8,
asTYPEID_UINT64 = 9,
asTYPEID_FLOAT = 10,
asTYPEID_DOUBLE = 11,
asTYPEID_MASK_SEQNBR = 67108863,
asTYPEID_APPOBJECT = 67108864,
asTYPEID_SCRIPTOBJECT = 134217728,
asTYPEID_TEMPLATE = 268435456,
asTYPEID_MASK_OBJECT = 469762048,
asTYPEID_HANDLETOCONST = 536870912,
asTYPEID_OBJHANDLE = 1073741824,
}
}

View File

@ -1,15 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum asETypeModifiers : int
{
asTM_NONE = 0,
asTM_INREF = 1,
asTM_OUTREF = 2,
asTM_INOUTREF = 3,
asTM_CONST = 4,
}
}

View File

@ -1,16 +0,0 @@
// AUTOMATICALLY GENERATED, DO NOT EDIT
using System.Diagnostics.CodeAnalysis;
namespace Pkmnlib
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal enum memory_order : int
{
memory_order_relaxed = 0,
memory_order_consume = 1,
memory_order_acquire = 2,
memory_order_release = 3,
memory_order_acq_rel = 4,
memory_order_seq_cst = 5,
}
}

View File

@ -1,6 +1,6 @@
namespace PkmnLibSharp.Library.Moves
{
public enum MoveTarget
public enum MoveTarget : byte
{
Adjacent = 0,
AdjacentAlly = 1,

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Creaturelib.Generated;
using Pkmnlib.Generated;
using PkmnLibSharp.Utilities;
using Random = PkmnLibSharp.Utilities.Random;
@ -28,7 +29,7 @@ namespace PkmnLibSharp.Library
var hab = hiddenAbilitiesConverted.ArrayPtr();
var tagsPtr = tagsConverted.ArrayPtr();
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
var ptr = PokemonForme.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
baseSpecialDefense, baseSpeed, ab, (ulong) abilities.Count, hab,
(ulong) hiddenAbilities.Count, moves.Ptr, tagsPtr, (ulong) tags.Count);

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.

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

Binary file not shown.

View File

@ -4,8 +4,21 @@ namespace PkmnLibSharp.Utilities
{
public class NativeException : Exception
{
public NativeException(string library, string message) : base($"[{library}] - '{message}'")
public string? Stack { get; }
public NativeException(string library, string message, string? stack) : base($"[{library}] - '{message}'")
{
Stack = stack;
}
public override string ToString()
{
var s = base.ToString();
if (Stack != null)
{
s += Environment.NewLine + Stack;
}
return s;
}
}
}

View File

@ -10,13 +10,14 @@ namespace PkmnLibSharp.Utilities
{
case 0: return;
case 1:
throw new NativeException("Arbutils", C.GetLastException().PtrString()!);
throw new NativeException("Arbutils", C.GetLastException().PtrString()!, null);
case 2:
throw new NativeException("CreatureLibLibrary",
Creaturelib.Generated.C.GetLastException().PtrString()!);
var message = Creaturelib.Generated.C.GetLastException().PtrString()!;
var stack = Creaturelib.Generated.C.GetLastExceptionStacktrace().PtrString();
throw new NativeException("CreatureLibLibrary", message, stack);
case 4:
throw new NativeException("PkmnLib",
Pkmnlib.Generated.C.GetLastException().PtrString()!);
Pkmnlib.Generated.C.GetLastException().PtrString()!, null);
}
}
}

View File

@ -1 +1 @@
{"enums":[],"functions":[{"filename":"Arbutils","name":"Arbutils_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"Arbutils","name":"Arbutils_Random_Construct","parameters":[],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_ConstructWithSeed","parameters":[{"name":"seed","type":"long unsigned int"}],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_Destruct","parameters":[{"name":"p","type":"Random *"}],"returns":"void"},{"filename":"Arbutils","name":"Arbutils_Random_GetFloat","parameters":[{"name":"p","type":"Random *"}],"returns":"float"},{"filename":"Arbutils","name":"Arbutils_Random_GetDouble","parameters":[{"name":"p","type":"Random *"}],"returns":"double"},{"filename":"Arbutils","name":"Arbutils_Random_Get","parameters":[{"name":"p","type":"Random *"}],"returns":"int"},{"filename":"Arbutils","name":"Arbutils_Random_GetWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"Arbutils","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":"Arbutils","name":"Arbutils_Random_GetUnsigned","parameters":[{"name":"p","type":"Random *"}],"returns":"unsigned int"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"Arbutils","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":"Arbutils","name":"Arbutils_Random_GetSeed","parameters":[{"name":"p","type":"Random *"}],"returns":"long unsigned int"}]}
{"enums":[{"byteSize":4,"filename":"Arbutils","name":"float_denorm_style","values":{"-1":"denorm_indeterminate","0":"denorm_absent","1":"denorm_present"}},{"byteSize":4,"filename":"Arbutils","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":"Arbutils","name":"Arbutils_C_GetLastException","parameters":[],"returns":"const char *"},{"filename":"Arbutils","name":"Arbutils_Random_Construct","parameters":[],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_ConstructWithSeed","parameters":[{"name":"seed","type":"long unsigned int"}],"returns":"Random *"},{"filename":"Arbutils","name":"Arbutils_Random_Destruct","parameters":[{"name":"p","type":"Random *"}],"returns":"void"},{"filename":"Arbutils","name":"Arbutils_Random_GetFloat","parameters":[{"name":"p","type":"Random *"}],"returns":"float"},{"filename":"Arbutils","name":"Arbutils_Random_GetDouble","parameters":[{"name":"p","type":"Random *"}],"returns":"double"},{"filename":"Arbutils","name":"Arbutils_Random_Get","parameters":[{"name":"p","type":"Random *"}],"returns":"int"},{"filename":"Arbutils","name":"Arbutils_Random_GetWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"int"},{"name":"out","type":"int &"}],"returns":"unsigned char"},{"filename":"Arbutils","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":"Arbutils","name":"Arbutils_Random_GetUnsigned","parameters":[{"name":"p","type":"Random *"}],"returns":"unsigned int"},{"filename":"Arbutils","name":"Arbutils_Random_GetUnsignedWithMax","parameters":[{"name":"p","type":"Random *"},{"name":"max","type":"unsigned int"},{"name":"out","type":"unsigned int &"}],"returns":"unsigned char"},{"filename":"Arbutils","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":"Arbutils","name":"Arbutils_Random_GetSeed","parameters":[{"name":"p","type":"Random *"}],"returns":"long unsigned int"}]}

File diff suppressed because one or more lines are too long

View File

@ -10,6 +10,12 @@ def resolve_enum_size(size):
def write_enum(enum, enumNames):
namespace = str.capitalize(enum["filename"])
if (enum["name"].startswith("bfd_")):
return
if (enum["name"].startswith("float_")):
return
if (enum["name"].startswith("as")):
return
filename = "Generated/{}/{}.cs".format(namespace, enum["name"])
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, "w") as f:

File diff suppressed because one or more lines are too long

View File

@ -14,8 +14,9 @@ namespace PkmnLibSharpTests.Battling
protected override Pokemon Finalize(Species species, Forme forme, Item? heldItem, IReadOnlyCollection<LearnedMove> moves, Nature nature)
{
return 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

@ -51,7 +51,7 @@ namespace PkmnLibSharpTests.Library
{
var p = new EffectParameter(10);
var ex = Assert.Throws<NativeException>(() => { p.AsString(); });
Assert.AreEqual("[CreatureLibLibrary] - '[CreatureLib_EffectParameter_AsString] [EffectParameter.hpp:54] Cast effect parameter to string, but was Int'", ex.Message);
Assert.AreEqual("[CreatureLibLibrary] - '[CreatureLib_EffectParameter_AsString] [EffectParameter.hpp:52] Cast effect parameter to string, but was Int'", ex.Message);
p.Dispose();
}
}