Use fancy C# 8 Nullable Reference pattern.
This commit is contained in:
parent
e0f4a38309
commit
01e622c22c
|
@ -32,7 +32,7 @@ namespace PkmnLibSharp.Battling
|
||||||
var ptr = Creaturelib.Generated.Battle.GetLibrary(Ptr);
|
var ptr = Creaturelib.Generated.Battle.GetLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _library))
|
if (TryResolvePointer(ptr, out _library))
|
||||||
{
|
{
|
||||||
return _library;
|
return _library!;
|
||||||
}
|
}
|
||||||
_library = new BattleLibrary(ptr);
|
_library = new BattleLibrary(ptr);
|
||||||
return _library;
|
return _library;
|
||||||
|
@ -47,7 +47,7 @@ namespace PkmnLibSharp.Battling
|
||||||
var ptr = Creaturelib.Generated.Battle.GetRandom(Ptr);
|
var ptr = Creaturelib.Generated.Battle.GetRandom(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _random))
|
if (TryResolvePointer(ptr, out _random))
|
||||||
{
|
{
|
||||||
return _random;
|
return _random!;
|
||||||
}
|
}
|
||||||
_random = new BattleRandom(ptr);
|
_random = new BattleRandom(ptr);
|
||||||
return _random;
|
return _random;
|
||||||
|
@ -85,7 +85,7 @@ namespace PkmnLibSharp.Battling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string WeatherName => Pkmnlib.Generated.Battle.GetWeatherName(Ptr).PtrString();
|
public string? WeatherName => Pkmnlib.Generated.Battle.GetWeatherName(Ptr).PtrString();
|
||||||
|
|
||||||
|
|
||||||
public bool CanUse(BaseTurnChoice turnChoice)
|
public bool CanUse(BaseTurnChoice turnChoice)
|
||||||
|
@ -118,7 +118,7 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
Creaturelib.Generated.Battle.GetCreature(ref ptr, Ptr, side, index).Assert();
|
Creaturelib.Generated.Battle.GetCreature(ref ptr, Ptr, side, index).Assert();
|
||||||
return TryResolvePointer(ptr, out Pokemon pokemon) ? pokemon : new Pokemon(ptr);
|
return TryResolvePointer(ptr, out Pokemon? pokemon) ? pokemon! : new Pokemon(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ForceRecall(byte side, byte index)
|
public void ForceRecall(byte side, byte index)
|
||||||
|
@ -146,9 +146,9 @@ namespace PkmnLibSharp.Battling
|
||||||
public Script GetVolatileScript(string key)
|
public Script GetVolatileScript(string key)
|
||||||
{
|
{
|
||||||
var ptr = Creaturelib.Generated.Battle.GetVolatileScript(Ptr, key.ToPtr());
|
var ptr = Creaturelib.Generated.Battle.GetVolatileScript(Ptr, key.ToPtr());
|
||||||
if (TryResolvePointer(ptr, out Script script))
|
if (TryResolvePointer(ptr, out Script? script))
|
||||||
{
|
{
|
||||||
return script;
|
return script!;
|
||||||
}
|
}
|
||||||
// TODO: Handle with different script providers.
|
// TODO: Handle with different script providers.
|
||||||
return new AngelscriptScript(ptr);
|
return new AngelscriptScript(ptr);
|
||||||
|
@ -196,10 +196,10 @@ namespace PkmnLibSharp.Battling
|
||||||
Pkmnlib.Generated.Battle.ClearWeather(Ptr);
|
Pkmnlib.Generated.Battle.ClearWeather(Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BattleLibrary _library;
|
private BattleLibrary? _library;
|
||||||
private BattleRandom _random;
|
private BattleRandom? _random;
|
||||||
private ReadOnlyNativePtrArray<BattleSide> _sides;
|
private ReadOnlyNativePtrArray<BattleSide>? _sides;
|
||||||
private ReadOnlyNativePtrArray<BattleParty> _parties;
|
private ReadOnlyNativePtrArray<BattleParty>? _parties;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace PkmnLibSharp.Battling
|
||||||
Initialize(ptr);
|
Initialize(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PokemonParty _party;
|
private PokemonParty? _party;
|
||||||
public PokemonParty Party
|
public PokemonParty Party
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -23,7 +23,7 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_party != null) return _party;
|
if (_party != null) return _party;
|
||||||
var ptr = Creaturelib.Generated.BattleParty.GetParty(Ptr);
|
var ptr = Creaturelib.Generated.BattleParty.GetParty(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _party))
|
if (TryResolvePointer(ptr, out _party))
|
||||||
return _party;
|
return _party!;
|
||||||
_party = new PokemonParty(ptr);
|
_party = new PokemonParty(ptr);
|
||||||
return _party;
|
return _party;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,12 @@ namespace PkmnLibSharp.Battling.ChoiceTurn
|
||||||
if (_user != null) return _user;
|
if (_user != null) return _user;
|
||||||
var ptr = Creaturelib.Generated.BaseTurnChoice.GetUser(Ptr);
|
var ptr = Creaturelib.Generated.BaseTurnChoice.GetUser(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _user))
|
if (TryResolvePointer(ptr, out _user))
|
||||||
return _user;
|
return _user!;
|
||||||
_user = new Pokemon(ptr);
|
_user = new Pokemon(ptr);
|
||||||
return _user;
|
return _user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pokemon _user;
|
private Pokemon? _user;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ namespace PkmnLibSharp.Battling.ChoiceTurn
|
||||||
if (_move != null) return _move;
|
if (_move != null) return _move;
|
||||||
var ptr = Creaturelib.Generated.AttackTurnChoice.GetAttack(Ptr);
|
var ptr = Creaturelib.Generated.AttackTurnChoice.GetAttack(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _move))
|
if (TryResolvePointer(ptr, out _move))
|
||||||
return _move;
|
return _move!;
|
||||||
_move = new LearnedMove(ptr);
|
_move = new LearnedMove(ptr);
|
||||||
return _move;
|
return _move;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ namespace PkmnLibSharp.Battling.ChoiceTurn
|
||||||
|
|
||||||
// TODO: Move Script getter
|
// TODO: Move Script getter
|
||||||
|
|
||||||
private LearnedMove _move;
|
private LearnedMove? _move;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||||
private readonly BattleEventPtrDelegate _innerDel;
|
private readonly BattleEventPtrDelegate _innerDel;
|
||||||
internal readonly IntPtr FunctionPtr;
|
internal readonly IntPtr FunctionPtr;
|
||||||
private Task _currentTask;
|
private Task? _currentTask;
|
||||||
|
|
||||||
public BattleEventListener(BattleEventDelegate del)
|
public BattleEventListener(BattleEventDelegate del)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
if (_pokemon != null) return _pokemon;
|
if (_pokemon != null) return _pokemon;
|
||||||
var ptr = Creaturelib.Generated.DamageEvent.GetCreature(Ptr);
|
var ptr = Creaturelib.Generated.DamageEvent.GetCreature(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _pokemon))
|
if (TryResolvePointer(ptr, out _pokemon))
|
||||||
return _pokemon;
|
return _pokemon!;
|
||||||
_pokemon = new Pokemon(ptr);
|
_pokemon = new Pokemon(ptr);
|
||||||
return _pokemon;
|
return _pokemon;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
public uint OriginalHealth => Creaturelib.Generated.DamageEvent.GetOriginalHealth(Ptr);
|
public uint OriginalHealth => Creaturelib.Generated.DamageEvent.GetOriginalHealth(Ptr);
|
||||||
public uint NewHealth => Creaturelib.Generated.DamageEvent.GetNewHealth(Ptr);
|
public uint NewHealth => Creaturelib.Generated.DamageEvent.GetNewHealth(Ptr);
|
||||||
|
|
||||||
private Pokemon _pokemon;
|
private Pokemon? _pokemon;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
if (_pokemon != null) return _pokemon;
|
if (_pokemon != null) return _pokemon;
|
||||||
var ptr = Creaturelib.Generated.ExperienceGainEvent.GetCreature(Ptr);
|
var ptr = Creaturelib.Generated.ExperienceGainEvent.GetCreature(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _pokemon))
|
if (TryResolvePointer(ptr, out _pokemon))
|
||||||
return _pokemon;
|
return _pokemon!;
|
||||||
_pokemon = new Pokemon(ptr);
|
_pokemon = new Pokemon(ptr);
|
||||||
return _pokemon;
|
return _pokemon;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
private uint NewExperience => Creaturelib.Generated.ExperienceGainEvent.GetNewExperience(Ptr);
|
private uint NewExperience => Creaturelib.Generated.ExperienceGainEvent.GetNewExperience(Ptr);
|
||||||
|
|
||||||
|
|
||||||
private Pokemon _pokemon;
|
private Pokemon? _pokemon;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,14 +15,14 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
if (_pokemon != null) return _pokemon;
|
if (_pokemon != null) return _pokemon;
|
||||||
var ptr = Creaturelib.Generated.DamageEvent.GetCreature(Ptr);
|
var ptr = Creaturelib.Generated.DamageEvent.GetCreature(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _pokemon))
|
if (TryResolvePointer(ptr, out _pokemon))
|
||||||
return _pokemon;
|
return _pokemon!;
|
||||||
_pokemon = new Pokemon(ptr);
|
_pokemon = new Pokemon(ptr);
|
||||||
return _pokemon;
|
return _pokemon;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pokemon _pokemon;
|
private Pokemon? _pokemon;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
if (_pokemon != null) return _pokemon;
|
if (_pokemon != null) return _pokemon;
|
||||||
var ptr = Creaturelib.Generated.HealEvent.GetCreature(Ptr);
|
var ptr = Creaturelib.Generated.HealEvent.GetCreature(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _pokemon))
|
if (TryResolvePointer(ptr, out _pokemon))
|
||||||
return _pokemon;
|
return _pokemon!;
|
||||||
_pokemon = new Pokemon(ptr);
|
_pokemon = new Pokemon(ptr);
|
||||||
return _pokemon;
|
return _pokemon;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
public uint OriginalHealth => Creaturelib.Generated.HealEvent.GetOriginalHealth(Ptr);
|
public uint OriginalHealth => Creaturelib.Generated.HealEvent.GetOriginalHealth(Ptr);
|
||||||
public uint NewHealth => Creaturelib.Generated.HealEvent.GetNewHealth(Ptr);
|
public uint NewHealth => Creaturelib.Generated.HealEvent.GetNewHealth(Ptr);
|
||||||
|
|
||||||
private Pokemon _pokemon;
|
private Pokemon? _pokemon;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
if (_newPokemon != null) return _newPokemon;
|
if (_newPokemon != null) return _newPokemon;
|
||||||
var ptr = Creaturelib.Generated.SwitchEvent.GetNewCreature(Ptr);
|
var ptr = Creaturelib.Generated.SwitchEvent.GetNewCreature(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _newPokemon))
|
if (TryResolvePointer(ptr, out _newPokemon))
|
||||||
return _newPokemon;
|
return _newPokemon!;
|
||||||
_newPokemon = new Pokemon(ptr);
|
_newPokemon = new Pokemon(ptr);
|
||||||
return _newPokemon;
|
return _newPokemon;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace PkmnLibSharp.Battling.Events
|
||||||
public byte Index => Creaturelib.Generated.SwitchEvent.GetIndex(Ptr);
|
public byte Index => Creaturelib.Generated.SwitchEvent.GetIndex(Ptr);
|
||||||
|
|
||||||
|
|
||||||
private Pokemon _newPokemon;
|
private Pokemon? _newPokemon;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_move != null) return _move;
|
if (_move != null) return _move;
|
||||||
var ptr = LearnedAttack.GetAttack(Ptr);
|
var ptr = LearnedAttack.GetAttack(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _move))
|
if (TryResolvePointer(ptr, out _move))
|
||||||
return _move;
|
return _move!;
|
||||||
_move = new MoveData(ptr);
|
_move = new MoveData(ptr);
|
||||||
return _move;
|
return _move;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ namespace PkmnLibSharp.Battling
|
||||||
public MoveLearnMethod LearnMethod =>
|
public MoveLearnMethod LearnMethod =>
|
||||||
(MoveLearnMethod) Creaturelib.Generated.LearnedAttack.GetLearnMethod(Ptr);
|
(MoveLearnMethod) Creaturelib.Generated.LearnedAttack.GetLearnMethod(Ptr);
|
||||||
|
|
||||||
private MoveData _move;
|
private MoveData? _move;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,11 +6,11 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
public class BattleLibrary : PointerWrapper
|
public class BattleLibrary : PointerWrapper
|
||||||
{
|
{
|
||||||
private PokemonLibrary _static;
|
private PokemonLibrary? _static;
|
||||||
private StatCalculator _statCalculator;
|
private StatCalculator? _statCalculator;
|
||||||
private DamageLibrary _damageLibrary;
|
private DamageLibrary? _damageLibrary;
|
||||||
private MiscLibrary _miscLibrary;
|
private MiscLibrary? _miscLibrary;
|
||||||
private ExperienceLibrary _experienceLibrary;
|
private ExperienceLibrary? _experienceLibrary;
|
||||||
|
|
||||||
public PokemonLibrary StaticLibrary
|
public PokemonLibrary StaticLibrary
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_static != null) return _static;
|
if (_static != null) return _static;
|
||||||
var ptr = Creaturelib.Generated.BattleLibrary.GetStaticLib(Ptr);
|
var ptr = Creaturelib.Generated.BattleLibrary.GetStaticLib(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _static))
|
if (TryResolvePointer(ptr, out _static))
|
||||||
return _static;
|
return _static!;
|
||||||
_static = new PokemonLibrary(ptr);
|
_static = new PokemonLibrary(ptr);
|
||||||
return _static;
|
return _static;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_statCalculator != null) return _statCalculator;
|
if (_statCalculator != null) return _statCalculator;
|
||||||
var ptr = Creaturelib.Generated.BattleLibrary.GetStatCalculator(Ptr);
|
var ptr = Creaturelib.Generated.BattleLibrary.GetStatCalculator(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _statCalculator))
|
if (TryResolvePointer(ptr, out _statCalculator))
|
||||||
return _statCalculator;
|
return _statCalculator!;
|
||||||
_statCalculator = new StatCalculator(ptr);
|
_statCalculator = new StatCalculator(ptr);
|
||||||
return _statCalculator;
|
return _statCalculator;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_damageLibrary != null) return _damageLibrary;
|
if (_damageLibrary != null) return _damageLibrary;
|
||||||
var ptr = Creaturelib.Generated.BattleLibrary.GetDamageLibrary(Ptr);
|
var ptr = Creaturelib.Generated.BattleLibrary.GetDamageLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _damageLibrary))
|
if (TryResolvePointer(ptr, out _damageLibrary))
|
||||||
return _damageLibrary;
|
return _damageLibrary!;
|
||||||
_damageLibrary = new DamageLibrary(ptr);
|
_damageLibrary = new DamageLibrary(ptr);
|
||||||
return _damageLibrary;
|
return _damageLibrary;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_miscLibrary != null) return _miscLibrary;
|
if (_miscLibrary != null) return _miscLibrary;
|
||||||
var ptr = Creaturelib.Generated.BattleLibrary.GetMiscLibrary(Ptr);
|
var ptr = Creaturelib.Generated.BattleLibrary.GetMiscLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _miscLibrary))
|
if (TryResolvePointer(ptr, out _miscLibrary))
|
||||||
return _miscLibrary;
|
return _miscLibrary!;
|
||||||
_miscLibrary = new MiscLibrary(ptr);
|
_miscLibrary = new MiscLibrary(ptr);
|
||||||
return _miscLibrary;
|
return _miscLibrary;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_experienceLibrary != null) return _experienceLibrary;
|
if (_experienceLibrary != null) return _experienceLibrary;
|
||||||
var ptr = Creaturelib.Generated.BattleLibrary.GetExperienceLibrary(Ptr);
|
var ptr = Creaturelib.Generated.BattleLibrary.GetExperienceLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _experienceLibrary))
|
if (TryResolvePointer(ptr, out _experienceLibrary))
|
||||||
return _experienceLibrary;
|
return _experienceLibrary!;
|
||||||
_experienceLibrary = new ExperienceLibrary(ptr);
|
_experienceLibrary = new ExperienceLibrary(ptr);
|
||||||
return _experienceLibrary;
|
return _experienceLibrary;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,23 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
public class Pokemon : PointerWrapper
|
public class Pokemon : PointerWrapper
|
||||||
{
|
{
|
||||||
public Pokemon(){}
|
public Pokemon()
|
||||||
|
{
|
||||||
|
// Just here so BattleLibrary can be initialized
|
||||||
|
Library = new BattleLibrary(IntPtr.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
internal Pokemon(IntPtr ptr) : base(ptr)
|
internal Pokemon(IntPtr ptr) : base(ptr)
|
||||||
{
|
{
|
||||||
Initialize(ptr);
|
Library = new BattleLibrary(Creaturelib.Generated.Creature.GetLibrary(ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pokemon([NotNull] BattleLibrary library, [NotNull] Species species, [NotNull] Forme forme,
|
public Pokemon(BattleLibrary library, Species species, Forme forme,
|
||||||
byte level, uint experience, uint uid,
|
byte level, uint experience, uint uid,
|
||||||
Gender gender, byte coloring, [MaybeNull] Item heldItem, [MaybeNull] string nickname, bool hiddenAbility,
|
Gender gender, byte coloring, Item? heldItem, string? nickname, bool hiddenAbility,
|
||||||
byte abilityIndex,
|
byte abilityIndex,
|
||||||
[NotNull] IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs, StatisticSet<byte> evs,
|
IReadOnlyCollection<LearnedMove> moves, StatisticSet<byte> ivs, StatisticSet<byte> evs,
|
||||||
[NotNull] Nature nature)
|
Nature nature)
|
||||||
: base(Pkmnlib.Generated.Pokemon.Construct(
|
: base(Pkmnlib.Generated.Pokemon.Construct(
|
||||||
library.Ptr, species.Ptr, forme.Ptr, level, experience,
|
library.Ptr, species.Ptr, forme.Ptr, level, experience,
|
||||||
uid, (Pkmnlib.Gender) gender, coloring, heldItem?.Ptr ?? IntPtr.Zero, nickname.ToPtr(),
|
uid, (Pkmnlib.Gender) gender, coloring, heldItem?.Ptr ?? IntPtr.Zero, nickname.ToPtr(),
|
||||||
|
@ -36,13 +40,7 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
Library = library;
|
Library = library;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal override void Initialize(IntPtr ptr)
|
|
||||||
{
|
|
||||||
base.Initialize(ptr);
|
|
||||||
Library = new BattleLibrary(Creaturelib.Generated.Creature.GetLibrary(Ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
public BattleLibrary Library { get; private set; }
|
public BattleLibrary Library { get; private set; }
|
||||||
public Species Species
|
public Species Species
|
||||||
{
|
{
|
||||||
|
@ -51,7 +49,7 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_species != null) return _species;
|
if (_species != null) return _species;
|
||||||
var ptr = Creaturelib.Generated.Creature.GetSpecies(Ptr);
|
var ptr = Creaturelib.Generated.Creature.GetSpecies(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _species))
|
if (TryResolvePointer(ptr, out _species))
|
||||||
return _species;
|
return _species!;
|
||||||
_species = new Species(ptr);
|
_species = new Species(ptr);
|
||||||
return _species;
|
return _species;
|
||||||
}
|
}
|
||||||
|
@ -63,12 +61,12 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_forme != null) return _forme;
|
if (_forme != null) return _forme;
|
||||||
var ptr = Creaturelib.Generated.Creature.GetVariant(Ptr);
|
var ptr = Creaturelib.Generated.Creature.GetVariant(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _forme))
|
if (TryResolvePointer(ptr, out _forme))
|
||||||
return _forme;
|
return _forme!;
|
||||||
_forme = new Forme(ptr);
|
_forme = new Forme(ptr);
|
||||||
return _forme;
|
return _forme;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Species DisplaySpecies
|
public Species? DisplaySpecies
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -79,9 +77,9 @@ namespace PkmnLibSharp.Battling
|
||||||
_displaySpecies = new Species(ptr);
|
_displaySpecies = new Species(ptr);
|
||||||
return _displaySpecies;
|
return _displaySpecies;
|
||||||
}
|
}
|
||||||
set => Creaturelib.Generated.Creature.SetDisplaySpecies(Ptr, value.Ptr);
|
set => Creaturelib.Generated.Creature.SetDisplaySpecies(Ptr, value?.Ptr ?? IntPtr.Zero);
|
||||||
}
|
}
|
||||||
public Forme DisplayForme
|
public Forme? DisplayForme
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -92,7 +90,7 @@ namespace PkmnLibSharp.Battling
|
||||||
_displayForme = new Forme(ptr);
|
_displayForme = new Forme(ptr);
|
||||||
return _displayForme;
|
return _displayForme;
|
||||||
}
|
}
|
||||||
set => Creaturelib.Generated.Creature.SetDisplayVariant(Ptr, value.Ptr);
|
set => Creaturelib.Generated.Creature.SetDisplayVariant(Ptr, value?.Ptr ?? IntPtr.Zero);
|
||||||
}
|
}
|
||||||
public byte Level => Creaturelib.Generated.Creature.GetLevel(Ptr);
|
public byte Level => Creaturelib.Generated.Creature.GetLevel(Ptr);
|
||||||
public uint Experience => Creaturelib.Generated.Creature.GetExperience(Ptr);
|
public uint Experience => Creaturelib.Generated.Creature.GetExperience(Ptr);
|
||||||
|
@ -102,7 +100,7 @@ namespace PkmnLibSharp.Battling
|
||||||
public uint CurrentHealth => Creaturelib.Generated.Creature.GetCurrentHealth(Ptr);
|
public uint CurrentHealth => Creaturelib.Generated.Creature.GetCurrentHealth(Ptr);
|
||||||
public uint MaxHealth => Creaturelib.Generated.Creature.GetMaxHealth(Ptr);
|
public uint MaxHealth => Creaturelib.Generated.Creature.GetMaxHealth(Ptr);
|
||||||
|
|
||||||
public string ActiveAbility
|
public string? ActiveAbility
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -111,7 +109,7 @@ namespace PkmnLibSharp.Battling
|
||||||
return ptr.PtrString();
|
return ptr.PtrString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Battle Battle
|
public Battle? Battle
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -123,7 +121,7 @@ namespace PkmnLibSharp.Battling
|
||||||
return _battle;
|
return _battle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public BattleSide BattleSide
|
public BattleSide? BattleSide
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -136,13 +134,13 @@ namespace PkmnLibSharp.Battling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool IsOnBattleField => Creaturelib.Generated.Creature.IsOnBattleField(Ptr) == 1;
|
public bool IsOnBattleField => Creaturelib.Generated.Creature.IsOnBattleField(Ptr) == 1;
|
||||||
public Item HeldItem
|
public Item? HeldItem
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var ptr = Creaturelib.Generated.Creature.GetHeldItem(Ptr);
|
var ptr = Creaturelib.Generated.Creature.GetHeldItem(Ptr);
|
||||||
if (ptr == IntPtr.Zero) return null;
|
if (ptr == IntPtr.Zero) return null;
|
||||||
if (!TryResolvePointer(ptr, out Item item))
|
if (!TryResolvePointer(ptr, out Item? item))
|
||||||
{
|
{
|
||||||
item = new Item(ptr);
|
item = new Item(ptr);
|
||||||
}
|
}
|
||||||
|
@ -152,7 +150,7 @@ namespace PkmnLibSharp.Battling
|
||||||
Creaturelib.Generated.Creature.SetHeldItemFromItem(Ptr,
|
Creaturelib.Generated.Creature.SetHeldItemFromItem(Ptr,
|
||||||
value?.Ptr ?? IntPtr.Zero);
|
value?.Ptr ?? IntPtr.Zero);
|
||||||
}
|
}
|
||||||
public string Nickname
|
public string? Nickname
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -222,13 +220,13 @@ namespace PkmnLibSharp.Battling
|
||||||
if (_nature != null) return _nature;
|
if (_nature != null) return _nature;
|
||||||
var ptr = Pkmnlib.Generated.Pokemon.GetNature(Ptr);
|
var ptr = Pkmnlib.Generated.Pokemon.GetNature(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _nature))
|
if (TryResolvePointer(ptr, out _nature))
|
||||||
return _nature;
|
return _nature!;
|
||||||
_nature = new Nature(ptr);
|
_nature = new Nature(ptr);
|
||||||
return _nature;
|
return _nature;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string StatusName => Pkmnlib.Generated.Pokemon.GetStatusName(Ptr).PtrString();
|
public string? StatusName => Pkmnlib.Generated.Pokemon.GetStatusName(Ptr).PtrString();
|
||||||
|
|
||||||
public void ChangeForme(Forme forme)
|
public void ChangeForme(Forme forme)
|
||||||
{
|
{
|
||||||
|
@ -339,15 +337,15 @@ namespace PkmnLibSharp.Battling
|
||||||
Pkmnlib.Generated.Pokemon.ClearStatus(Ptr);
|
Pkmnlib.Generated.Pokemon.ClearStatus(Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Species _displaySpecies;
|
private Species? _displaySpecies;
|
||||||
private Forme _displayForme;
|
private Forme? _displayForme;
|
||||||
private Species _species;
|
private Species? _species;
|
||||||
private Forme _forme;
|
private Forme? _forme;
|
||||||
private string _nickname;
|
private string? _nickname;
|
||||||
private ReadOnlyNativePtrArray<LearnedMove> _moves;
|
private ReadOnlyNativePtrArray<LearnedMove>? _moves;
|
||||||
private Nature _nature;
|
private Nature? _nature;
|
||||||
private Battle _battle;
|
private Battle? _battle;
|
||||||
private BattleSide _battleSide;
|
private BattleSide? _battleSide;
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace PkmnLibSharp.Battling
|
||||||
public StatisticSet<byte> EVs;
|
public StatisticSet<byte> EVs;
|
||||||
|
|
||||||
public bool? IsForceShiny { get; private set; }
|
public bool? IsForceShiny { get; private set; }
|
||||||
public string HeldItem { get; private set; }
|
public string? HeldItem { get; private set; }
|
||||||
|
|
||||||
public List<(string moveName, MoveLearnMethod learnMethod)> LearnedMoves { get; } =
|
public List<(string moveName, MoveLearnMethod learnMethod)> LearnedMoves { get; } =
|
||||||
new List<(string moveName, MoveLearnMethod learnMethod)>();
|
new List<(string moveName, MoveLearnMethod learnMethod)>();
|
||||||
|
@ -81,7 +81,7 @@ namespace PkmnLibSharp.Battling
|
||||||
throw new Exception($"Species '{Species}' was not found.");
|
throw new Exception($"Species '{Species}' was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!species.TryGetForme(Forme, out var forme))
|
if (!species!.TryGetForme(Forme, out var forme))
|
||||||
{
|
{
|
||||||
throw new Exception($"Forme '{Forme}' was not found on species '{Species}'");
|
throw new Exception($"Forme '{Forme}' was not found on species '{Species}'");
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ namespace PkmnLibSharp.Battling
|
||||||
coloring = 1;
|
coloring = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item heldItem = null;
|
Item? heldItem = null;
|
||||||
if (HeldItem != null)
|
if (HeldItem != null)
|
||||||
{
|
{
|
||||||
if (!_library.StaticLibrary.ItemLibrary.TryGet(HeldItem, out heldItem))
|
if (!_library.StaticLibrary.ItemLibrary.TryGet(HeldItem, out heldItem))
|
||||||
|
@ -117,11 +117,11 @@ namespace PkmnLibSharp.Battling
|
||||||
var isHiddenAbility = false;
|
var isHiddenAbility = false;
|
||||||
if (string.IsNullOrEmpty(Ability))
|
if (string.IsNullOrEmpty(Ability))
|
||||||
{
|
{
|
||||||
abilityIndex = forme.GetRandomAbility(random);
|
abilityIndex = forme!.GetRandomAbility(random);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
abilityIndex = forme.Abilities.IndexOf(Ability);
|
abilityIndex = forme!.Abilities.IndexOf(Ability);
|
||||||
if (abilityIndex == -1)
|
if (abilityIndex == -1)
|
||||||
{
|
{
|
||||||
abilityIndex = forme.HiddenAbilities.IndexOf(Ability);
|
abilityIndex = forme.HiddenAbilities.IndexOf(Ability);
|
||||||
|
@ -143,7 +143,7 @@ namespace PkmnLibSharp.Battling
|
||||||
throw new Exception($"Move '{LearnedMoves[i].moveName}' was not found.");
|
throw new Exception($"Move '{LearnedMoves[i].moveName}' was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
moves[i] = new LearnedMove(move, move.BaseUsages, LearnedMoves[i].learnMethod);
|
moves[i] = new LearnedMove(move!, move!.BaseUsages, LearnedMoves[i].learnMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(Nature))
|
if (string.IsNullOrEmpty(Nature))
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
public class PokemonParty : PointerWrapper
|
public class PokemonParty : PointerWrapper
|
||||||
{
|
{
|
||||||
private ReadOnlyNativePtrArray<Pokemon> _party;
|
private ReadOnlyNativePtrArray<Pokemon>? _party;
|
||||||
|
|
||||||
internal PokemonParty(IntPtr ptr) : base(ptr){}
|
internal PokemonParty(IntPtr ptr) : base(ptr){}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace PkmnLibSharp.Battling
|
||||||
{
|
{
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
Creaturelib.Generated.CreatureParty.GetAtIndex(ref ptr, Ptr, index).Assert();
|
Creaturelib.Generated.CreatureParty.GetAtIndex(ref ptr, Ptr, index).Assert();
|
||||||
return TryResolvePointer(ptr, out Pokemon pkmn) ? pkmn : new Pokemon(ptr);
|
return TryResolvePointer(ptr, out Pokemon? pkmn) ? pkmn! : new Pokemon(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Switch(ulong indexA, ulong indexB)
|
public void Switch(ulong indexA, ulong indexB)
|
||||||
|
@ -31,10 +31,8 @@ namespace PkmnLibSharp.Battling
|
||||||
public Pokemon SwapInto(ulong indexA, Pokemon pokemon)
|
public Pokemon SwapInto(ulong indexA, Pokemon pokemon)
|
||||||
{
|
{
|
||||||
var ptr = Creaturelib.Generated.CreatureParty.SwapInto(Ptr, indexA, pokemon.Ptr);
|
var ptr = Creaturelib.Generated.CreatureParty.SwapInto(Ptr, indexA, pokemon.Ptr);
|
||||||
if (TryResolvePointer(ptr, out Pokemon newPokemon))
|
if (TryResolvePointer(ptr, out Pokemon? newPokemon))
|
||||||
{
|
return newPokemon!;
|
||||||
return newPokemon;
|
|
||||||
}
|
|
||||||
return new Pokemon(ptr);
|
return new Pokemon(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace PkmnLibSharp.Library
|
||||||
{
|
{
|
||||||
var p = IntPtr.Zero;
|
var p = IntPtr.Zero;
|
||||||
Creaturelib.Generated.EffectParameter.AsString(Ptr, ref p).Assert();
|
Creaturelib.Generated.EffectParameter.AsString(Ptr, ref p).Assert();
|
||||||
return p.PtrString();
|
return p.PtrString()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,17 @@ namespace PkmnLibSharp.Library
|
||||||
{
|
{
|
||||||
public class Forme : PointerWrapper
|
public class Forme : PointerWrapper
|
||||||
{
|
{
|
||||||
private ReadOnlyArray<string> _abilities;
|
private ReadOnlyArray<string>? _abilities;
|
||||||
private ReadOnlyArray<string> _hiddenAbilities;
|
private ReadOnlyArray<string>? _hiddenAbilities;
|
||||||
private LearnableMoves _moves;
|
private LearnableMoves? _moves;
|
||||||
private string _name;
|
private string? _name;
|
||||||
private ReadOnlyArray<byte> _types;
|
private ReadOnlyArray<byte>? _types;
|
||||||
|
|
||||||
internal Forme(IntPtr parent) : base(parent)
|
internal Forme(IntPtr parent) : base(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => _name ??= SpeciesVariant.GetName(Ptr).PtrString();
|
public string Name => _name ??= SpeciesVariant.GetName(Ptr).PtrString()!;
|
||||||
public float Height => SpeciesVariant.GetHeight(Ptr);
|
public float Height => SpeciesVariant.GetHeight(Ptr);
|
||||||
public float Weight => SpeciesVariant.GetWeight(Ptr);
|
public float Weight => SpeciesVariant.GetWeight(Ptr);
|
||||||
public float BaseExperience => SpeciesVariant.GetBaseExperience(Ptr);
|
public float BaseExperience => SpeciesVariant.GetBaseExperience(Ptr);
|
||||||
|
@ -66,7 +66,7 @@ namespace PkmnLibSharp.Library
|
||||||
{
|
{
|
||||||
var s = IntPtr.Zero;
|
var s = IntPtr.Zero;
|
||||||
SpeciesVariant.GetTalent(Ptr, MarshalHelper.False, i, ref s).Assert();
|
SpeciesVariant.GetTalent(Ptr, MarshalHelper.False, i, ref s).Assert();
|
||||||
abilities[i] = s.PtrString();
|
abilities[i] = s.PtrString()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
_abilities = abilities.ToReadOnly();
|
_abilities = abilities.ToReadOnly();
|
||||||
|
@ -87,7 +87,7 @@ namespace PkmnLibSharp.Library
|
||||||
{
|
{
|
||||||
var s = IntPtr.Zero;
|
var s = IntPtr.Zero;
|
||||||
SpeciesVariant.GetTalent(Ptr, MarshalHelper.True, i, ref s).Assert();
|
SpeciesVariant.GetTalent(Ptr, MarshalHelper.True, i, ref s).Assert();
|
||||||
abilities[i] = s.PtrString();
|
abilities[i] = s.PtrString()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
_hiddenAbilities = abilities.ToReadOnly();
|
_hiddenAbilities = abilities.ToReadOnly();
|
||||||
|
@ -101,9 +101,10 @@ namespace PkmnLibSharp.Library
|
||||||
{
|
{
|
||||||
if (_moves != null) return _moves;
|
if (_moves != null) return _moves;
|
||||||
var movesPtr = SpeciesVariant.GetLearnableAttacks(Ptr);
|
var movesPtr = SpeciesVariant.GetLearnableAttacks(Ptr);
|
||||||
if (!TryResolvePointer(movesPtr, out _moves)) _moves = new LearnableMoves(movesPtr);
|
if (!TryResolvePointer(movesPtr, out _moves))
|
||||||
|
_moves = new LearnableMoves(movesPtr);
|
||||||
|
|
||||||
return _moves;
|
return _moves!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +115,8 @@ namespace PkmnLibSharp.Library
|
||||||
|
|
||||||
public Forme(string name, float height, float weight, uint baseExperience, byte[] types,
|
public Forme(string name, float height, float weight, uint baseExperience, byte[] types,
|
||||||
ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseSpecialAttack,
|
ushort baseHealth, ushort baseAttack, ushort baseDefense, ushort baseSpecialAttack,
|
||||||
ushort baseSpecialDefense, ushort baseSpeed, string[] abilities, string[] hiddenAbilities,
|
ushort baseSpecialDefense, ushort baseSpeed, IReadOnlyCollection<string> abilities,
|
||||||
|
IReadOnlyCollection<string> hiddenAbilities,
|
||||||
LearnableMoves moves)
|
LearnableMoves moves)
|
||||||
{
|
{
|
||||||
var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray();
|
var abilitiesConverted = abilities.Select(x => x.ToPtr()).ToArray();
|
||||||
|
@ -123,8 +125,8 @@ namespace PkmnLibSharp.Library
|
||||||
var hab = hiddenAbilitiesConverted.ArrayPtr();
|
var hab = hiddenAbilitiesConverted.ArrayPtr();
|
||||||
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
|
var ptr = SpeciesVariant.Construct(name.ToPtr(), height, weight, baseExperience, types.ArrayPtr(),
|
||||||
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
|
(ulong) types.Length, baseHealth, baseAttack, baseDefense, baseSpecialAttack,
|
||||||
baseSpecialDefense, baseSpeed, ab, (ulong) abilities.Length, hab,
|
baseSpecialDefense, baseSpeed, ab, (ulong) abilities.Count, hab,
|
||||||
(ulong) hiddenAbilities.Length, moves.Ptr);
|
(ulong) hiddenAbilities.Count, moves.Ptr);
|
||||||
var f = new Forme(ptr);
|
var f = new Forme(ptr);
|
||||||
foreach (var intPtr in abilitiesConverted)
|
foreach (var intPtr in abilitiesConverted)
|
||||||
Marshal.FreeHGlobal(intPtr);
|
Marshal.FreeHGlobal(intPtr);
|
||||||
|
|
|
@ -6,13 +6,13 @@ namespace PkmnLibSharp.Library.Items
|
||||||
{
|
{
|
||||||
public class Item : PointerWrapper
|
public class Item : PointerWrapper
|
||||||
{
|
{
|
||||||
private string _name;
|
private string? _name;
|
||||||
|
|
||||||
internal Item(IntPtr ptr) : base(ptr)
|
internal Item(IntPtr ptr) : base(ptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => _name ??= Creaturelib.Generated.Item.GetName(Ptr).PtrString();
|
public string Name => _name ??= Creaturelib.Generated.Item.GetName(Ptr).PtrString()!;
|
||||||
public ItemCategory Category => (ItemCategory) Creaturelib.Generated.Item.GetCategory(Ptr);
|
public ItemCategory Category => (ItemCategory) Creaturelib.Generated.Item.GetCategory(Ptr);
|
||||||
|
|
||||||
public BattleItemCategory BattleCategory =>
|
public BattleItemCategory BattleCategory =>
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace PkmnLibSharp.Library.Items
|
||||||
_cache.Remove(key);
|
_cache.Remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGet(string key, out Item item)
|
public bool TryGet(string key, out Item? item)
|
||||||
{
|
{
|
||||||
if (_cache.TryGetValue(key, out item))
|
if (_cache.TryGetValue(key, out item))
|
||||||
return true;
|
return true;
|
||||||
|
@ -41,7 +41,7 @@ namespace PkmnLibSharp.Library.Items
|
||||||
return false;
|
return false;
|
||||||
if (TryResolvePointer(ptr, out item))
|
if (TryResolvePointer(ptr, out item))
|
||||||
{
|
{
|
||||||
_cache.Add(key, item);
|
_cache.Add(key, item!);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,10 +56,10 @@ namespace PkmnLibSharp.Library.Items
|
||||||
return item;
|
return item;
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
Creaturelib.Generated.ItemLibrary.Get(Ptr, key.ToPtr(), ref ptr).Assert();
|
Creaturelib.Generated.ItemLibrary.Get(Ptr, key.ToPtr(), ref ptr).Assert();
|
||||||
if (TryResolvePointer(ptr, out item))
|
if (TryResolvePointer(ptr, out Item? i))
|
||||||
{
|
{
|
||||||
_cache.Add(key, item);
|
_cache.Add(key, i!);
|
||||||
return item;
|
return i!;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = new Item(ptr);
|
item = new Item(ptr);
|
||||||
|
|
|
@ -8,14 +8,14 @@ namespace PkmnLibSharp.Library.Moves
|
||||||
{
|
{
|
||||||
public class MoveData : PointerWrapper
|
public class MoveData : PointerWrapper
|
||||||
{
|
{
|
||||||
private string _name;
|
private string? _name;
|
||||||
private string _secondaryEffectName;
|
private string? _secondaryEffectName;
|
||||||
|
|
||||||
internal MoveData(IntPtr ptr) : base(ptr)
|
internal MoveData(IntPtr ptr) : base(ptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => _name ??= AttackData.GetName(Ptr).PtrString();
|
public string Name => _name ??= AttackData.GetName(Ptr).PtrString()!;
|
||||||
public byte Type => AttackData.GetType(Ptr);
|
public byte Type => AttackData.GetType(Ptr);
|
||||||
public MoveCategory Category => (MoveCategory) AttackData.GetCategory(Ptr);
|
public MoveCategory Category => (MoveCategory) AttackData.GetCategory(Ptr);
|
||||||
public byte BasePower => AttackData.GetBasePower(Ptr);
|
public byte BasePower => AttackData.GetBasePower(Ptr);
|
||||||
|
@ -27,7 +27,7 @@ namespace PkmnLibSharp.Library.Moves
|
||||||
public float SecondaryEffectChance => AttackData.GetSecondaryEffectChance(Ptr);
|
public float SecondaryEffectChance => AttackData.GetSecondaryEffectChance(Ptr);
|
||||||
|
|
||||||
public string SecondaryEffectName =>
|
public string SecondaryEffectName =>
|
||||||
_secondaryEffectName ??= AttackData.GetSecondaryEffectName(Ptr).PtrString();
|
_secondaryEffectName ??= AttackData.GetSecondaryEffectName(Ptr).PtrString()!;
|
||||||
|
|
||||||
public bool HasFlag(string s)
|
public bool HasFlag(string s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace PkmnLibSharp.Library.Moves
|
||||||
_cache.Remove(key);
|
_cache.Remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGet(string key, out MoveData move)
|
public bool TryGet(string key, out MoveData? move)
|
||||||
{
|
{
|
||||||
if (_cache.TryGetValue(key, out move))
|
if (_cache.TryGetValue(key, out move))
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,7 +37,7 @@ namespace PkmnLibSharp.Library.Moves
|
||||||
return false;
|
return false;
|
||||||
if (TryResolvePointer(ptr, out move))
|
if (TryResolvePointer(ptr, out move))
|
||||||
{
|
{
|
||||||
_cache.Add(key, move);
|
_cache.Add(key, move!);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +52,10 @@ namespace PkmnLibSharp.Library.Moves
|
||||||
return move;
|
return move;
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
AttackLibrary.Get(Ptr, key.ToPtr(), ref ptr).Assert();
|
AttackLibrary.Get(Ptr, key.ToPtr(), ref ptr).Assert();
|
||||||
if (TryResolvePointer(ptr, out move))
|
if (TryResolvePointer(ptr, out MoveData? m))
|
||||||
{
|
{
|
||||||
_cache.Add(key, move);
|
_cache.Add(key, m!);
|
||||||
return move;
|
return m!;
|
||||||
}
|
}
|
||||||
|
|
||||||
move = new MoveData(ptr);
|
move = new MoveData(ptr);
|
||||||
|
|
|
@ -33,11 +33,11 @@ namespace PkmnLibSharp.Library
|
||||||
return nature;
|
return nature;
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
Pkmnlib.Generated.NatureLibrary.GetNatureByName(Ptr, name.ToPtr(), ref ptr).Assert();
|
Pkmnlib.Generated.NatureLibrary.GetNatureByName(Ptr, name.ToPtr(), ref ptr).Assert();
|
||||||
if (TryResolvePointer(ptr, out nature))
|
if (TryResolvePointer(ptr, out Nature? n))
|
||||||
{
|
{
|
||||||
_cache.Add(name, nature);
|
_cache.Add(name, n!);
|
||||||
_natureNames.Add(ptr, name);
|
_natureNames.Add(ptr, name);
|
||||||
return nature;
|
return n!;
|
||||||
}
|
}
|
||||||
|
|
||||||
nature = new Nature(ptr);
|
nature = new Nature(ptr);
|
||||||
|
@ -52,14 +52,14 @@ namespace PkmnLibSharp.Library
|
||||||
return s;
|
return s;
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
Pkmnlib.Generated.NatureLibrary.GetNatureName(Ptr, nature.Ptr, ref ptr).Assert();
|
Pkmnlib.Generated.NatureLibrary.GetNatureName(Ptr, nature.Ptr, ref ptr).Assert();
|
||||||
return ptr.PtrString();
|
return ptr.PtrString()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetRandomNatureName(Random random)
|
public string GetRandomNatureName(Random random)
|
||||||
{
|
{
|
||||||
IntPtr val = IntPtr.Zero;
|
IntPtr val = IntPtr.Zero;
|
||||||
Pkmnlib.Generated.NatureLibrary.GetRandomNatureName(Ptr, random.Ptr, ref val).Assert();
|
Pkmnlib.Generated.NatureLibrary.GetRandomNatureName(Ptr, random.Ptr, ref val).Assert();
|
||||||
return val.PtrString();
|
return val.PtrString()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeletePtr()
|
protected override void DeletePtr()
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace PkmnLibSharp.Library
|
||||||
{
|
{
|
||||||
public class PokemonLibrary : PointerWrapper
|
public class PokemonLibrary : PointerWrapper
|
||||||
{
|
{
|
||||||
private LibrarySettings _settings;
|
private LibrarySettings? _settings;
|
||||||
|
|
||||||
public LibrarySettings Settings
|
public LibrarySettings Settings
|
||||||
{
|
{
|
||||||
|
@ -18,13 +18,13 @@ namespace PkmnLibSharp.Library
|
||||||
if (_settings != null) return _settings;
|
if (_settings != null) return _settings;
|
||||||
var ptr = DataLibrary.GetSettings(Ptr);
|
var ptr = DataLibrary.GetSettings(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _settings))
|
if (TryResolvePointer(ptr, out _settings))
|
||||||
return _settings;
|
return _settings!;
|
||||||
_settings = new LibrarySettings(ptr);
|
_settings = new LibrarySettings(ptr);
|
||||||
return _settings;
|
return _settings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SpeciesLibrary _species;
|
private SpeciesLibrary? _species;
|
||||||
|
|
||||||
public SpeciesLibrary SpeciesLibrary
|
public SpeciesLibrary SpeciesLibrary
|
||||||
{
|
{
|
||||||
|
@ -33,13 +33,13 @@ namespace PkmnLibSharp.Library
|
||||||
if (_species != null) return _species;
|
if (_species != null) return _species;
|
||||||
var ptr = DataLibrary.GetSpeciesLibrary(Ptr);
|
var ptr = DataLibrary.GetSpeciesLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _species))
|
if (TryResolvePointer(ptr, out _species))
|
||||||
return _species;
|
return _species!;
|
||||||
_species = new SpeciesLibrary(ptr);
|
_species = new SpeciesLibrary(ptr);
|
||||||
return _species;
|
return _species;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MoveLibrary _moves;
|
private MoveLibrary? _moves;
|
||||||
|
|
||||||
public MoveLibrary MoveLibrary
|
public MoveLibrary MoveLibrary
|
||||||
{
|
{
|
||||||
|
@ -48,13 +48,13 @@ namespace PkmnLibSharp.Library
|
||||||
if (_moves != null) return _moves;
|
if (_moves != null) return _moves;
|
||||||
var ptr = DataLibrary.GetAttackLibrary(Ptr);
|
var ptr = DataLibrary.GetAttackLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _moves))
|
if (TryResolvePointer(ptr, out _moves))
|
||||||
return _moves;
|
return _moves!;
|
||||||
_moves = new MoveLibrary(ptr);
|
_moves = new MoveLibrary(ptr);
|
||||||
return _moves;
|
return _moves;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemLibrary _items;
|
private ItemLibrary? _items;
|
||||||
|
|
||||||
public ItemLibrary ItemLibrary
|
public ItemLibrary ItemLibrary
|
||||||
{
|
{
|
||||||
|
@ -63,13 +63,13 @@ namespace PkmnLibSharp.Library
|
||||||
if (_items != null) return _items;
|
if (_items != null) return _items;
|
||||||
var ptr = DataLibrary.GetItemLibrary(Ptr);
|
var ptr = DataLibrary.GetItemLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _items))
|
if (TryResolvePointer(ptr, out _items))
|
||||||
return _items;
|
return _items!;
|
||||||
_items = new ItemLibrary(ptr);
|
_items = new ItemLibrary(ptr);
|
||||||
return _items;
|
return _items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private GrowthRateLibrary _growthRateLibrary;
|
private GrowthRateLibrary? _growthRateLibrary;
|
||||||
|
|
||||||
public GrowthRateLibrary GrowthRateLibrary
|
public GrowthRateLibrary GrowthRateLibrary
|
||||||
{
|
{
|
||||||
|
@ -78,13 +78,13 @@ namespace PkmnLibSharp.Library
|
||||||
if (_growthRateLibrary != null) return _growthRateLibrary;
|
if (_growthRateLibrary != null) return _growthRateLibrary;
|
||||||
var ptr = DataLibrary.GetGrowthRates(Ptr);
|
var ptr = DataLibrary.GetGrowthRates(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _growthRateLibrary))
|
if (TryResolvePointer(ptr, out _growthRateLibrary))
|
||||||
return _growthRateLibrary;
|
return _growthRateLibrary!;
|
||||||
_growthRateLibrary = new GrowthRateLibrary(ptr);
|
_growthRateLibrary = new GrowthRateLibrary(ptr);
|
||||||
return _growthRateLibrary;
|
return _growthRateLibrary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TypeLibrary _typeLibrary;
|
private TypeLibrary? _typeLibrary;
|
||||||
|
|
||||||
public TypeLibrary TypeLibrary
|
public TypeLibrary TypeLibrary
|
||||||
{
|
{
|
||||||
|
@ -93,13 +93,13 @@ namespace PkmnLibSharp.Library
|
||||||
if (_typeLibrary != null) return _typeLibrary;
|
if (_typeLibrary != null) return _typeLibrary;
|
||||||
var ptr = DataLibrary.GetTypeLibrary(Ptr);
|
var ptr = DataLibrary.GetTypeLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _typeLibrary))
|
if (TryResolvePointer(ptr, out _typeLibrary))
|
||||||
return _typeLibrary;
|
return _typeLibrary!;
|
||||||
_typeLibrary = new TypeLibrary(ptr);
|
_typeLibrary = new TypeLibrary(ptr);
|
||||||
return _typeLibrary;
|
return _typeLibrary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NatureLibrary _natureLibrary;
|
private NatureLibrary? _natureLibrary;
|
||||||
|
|
||||||
public NatureLibrary NatureLibrary
|
public NatureLibrary NatureLibrary
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@ namespace PkmnLibSharp.Library
|
||||||
if (_natureLibrary != null) return _natureLibrary;
|
if (_natureLibrary != null) return _natureLibrary;
|
||||||
var ptr = Pkmnlib.Generated.PokemonLibrary.GetNatureLibrary(Ptr);
|
var ptr = Pkmnlib.Generated.PokemonLibrary.GetNatureLibrary(Ptr);
|
||||||
if (TryResolvePointer(ptr, out _natureLibrary))
|
if (TryResolvePointer(ptr, out _natureLibrary))
|
||||||
return _natureLibrary;
|
return _natureLibrary!;
|
||||||
_natureLibrary = new NatureLibrary(ptr);
|
_natureLibrary = new NatureLibrary(ptr);
|
||||||
return _natureLibrary;
|
return _natureLibrary;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ namespace PkmnLibSharp.Library
|
||||||
{
|
{
|
||||||
public class Species : PointerWrapper
|
public class Species : PointerWrapper
|
||||||
{
|
{
|
||||||
private string _name;
|
private string? _name;
|
||||||
private string _growthRate;
|
private string? _growthRate;
|
||||||
|
|
||||||
private readonly Dictionary<string, Forme> _formes =
|
private readonly Dictionary<string, Forme> _formes =
|
||||||
new Dictionary<string, Forme>(StringComparer.InvariantCultureIgnoreCase);
|
new Dictionary<string, Forme>(StringComparer.InvariantCultureIgnoreCase);
|
||||||
|
@ -20,15 +20,15 @@ namespace PkmnLibSharp.Library
|
||||||
public ushort Id => CreatureSpecies.GetId(Ptr);
|
public ushort Id => CreatureSpecies.GetId(Ptr);
|
||||||
public float GenderRate => CreatureSpecies.GetGenderRate(Ptr);
|
public float GenderRate => CreatureSpecies.GetGenderRate(Ptr);
|
||||||
public byte CaptureRate => CreatureSpecies.GetCaptureRate(Ptr);
|
public byte CaptureRate => CreatureSpecies.GetCaptureRate(Ptr);
|
||||||
public string Name => _name ??= CreatureSpecies.GetName(Ptr).PtrString();
|
public string Name => _name ??= CreatureSpecies.GetName(Ptr).PtrString()!;
|
||||||
public string GrowthRate => _growthRate ??= CreatureSpecies.GetGrowthRate(Ptr).PtrString();
|
public string GrowthRate => _growthRate ??= CreatureSpecies.GetGrowthRate(Ptr).PtrString()!;
|
||||||
|
|
||||||
public bool HasForme(string s)
|
public bool HasForme(string s)
|
||||||
{
|
{
|
||||||
return CreatureSpecies.HasVariant(Ptr, s.ToPtr()) == MarshalHelper.True;
|
return CreatureSpecies.HasVariant(Ptr, s.ToPtr()) == MarshalHelper.True;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetForme(string s, out Forme forme)
|
public bool TryGetForme(string s, out Forme? forme)
|
||||||
{
|
{
|
||||||
if (_formes.TryGetValue(s, out forme))
|
if (_formes.TryGetValue(s, out forme))
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,7 +37,7 @@ namespace PkmnLibSharp.Library
|
||||||
{
|
{
|
||||||
if (TryResolvePointer(ptr, out forme))
|
if (TryResolvePointer(ptr, out forme))
|
||||||
{
|
{
|
||||||
_formes.Add(s, forme);
|
_formes.Add(s, forme!);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,10 +55,10 @@ namespace PkmnLibSharp.Library
|
||||||
return forme;
|
return forme;
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
CreatureSpecies.GetVariant(ref ptr, Ptr, s.ToPtr()).Assert();
|
CreatureSpecies.GetVariant(ref ptr, Ptr, s.ToPtr()).Assert();
|
||||||
if (TryResolvePointer(ptr, out forme))
|
if (TryResolvePointer(ptr, out Forme? f))
|
||||||
{
|
{
|
||||||
_formes.Add(s, forme);
|
_formes.Add(s, f!);
|
||||||
return forme;
|
return f!;
|
||||||
}
|
}
|
||||||
forme = new Forme(ptr);
|
forme = new Forme(ptr);
|
||||||
_formes.Add(s, forme);
|
_formes.Add(s, forme);
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace PkmnLibSharp.Library
|
||||||
_cache.Remove(key);
|
_cache.Remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGet(string key, out Species species)
|
public bool TryGet(string key, out Species? species)
|
||||||
{
|
{
|
||||||
if (_cache.TryGetValue(key, out species))
|
if (_cache.TryGetValue(key, out species))
|
||||||
return true;
|
return true;
|
||||||
|
@ -30,7 +30,7 @@ namespace PkmnLibSharp.Library
|
||||||
return false;
|
return false;
|
||||||
if (TryResolvePointer(ptr, out species))
|
if (TryResolvePointer(ptr, out species))
|
||||||
{
|
{
|
||||||
_cache.Add(key, species);
|
_cache.Add(key, species!);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
species = new Species(ptr);
|
species = new Species(ptr);
|
||||||
|
@ -44,10 +44,10 @@ namespace PkmnLibSharp.Library
|
||||||
return species;
|
return species;
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
Creaturelib.Generated.SpeciesLibrary.Get(Ptr, key.ToPtr(), ref ptr).Assert();
|
Creaturelib.Generated.SpeciesLibrary.Get(Ptr, key.ToPtr(), ref ptr).Assert();
|
||||||
if (TryResolvePointer(ptr, out species))
|
if (TryResolvePointer(ptr, out Species? s))
|
||||||
{
|
{
|
||||||
_cache.Add(key, species);
|
_cache.Add(key, s!);
|
||||||
return species;
|
return s!;
|
||||||
}
|
}
|
||||||
species = new Species(ptr);
|
species = new Species(ptr);
|
||||||
_cache.Add(key, species);
|
_cache.Add(key, species);
|
||||||
|
|
|
@ -66,7 +66,7 @@ namespace PkmnLibSharp.Library
|
||||||
|
|
||||||
var ptr = IntPtr.Zero;
|
var ptr = IntPtr.Zero;
|
||||||
Creaturelib.Generated.TypeLibrary.GetTypeName(ref ptr, Ptr, typeId).Assert();
|
Creaturelib.Generated.TypeLibrary.GetTypeName(ref ptr, Ptr, typeId).Assert();
|
||||||
var s = ptr.PtrString();
|
var s = ptr.PtrString()!;
|
||||||
_cache[s] = typeId;
|
_cache[s] = typeId;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
<TargetFramework>netstandard2.1</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<Configurations>Debug</Configurations>
|
<Configurations>Debug</Configurations>
|
||||||
<Platforms>AnyCPU</Platforms>
|
<Platforms>AnyCPU</Platforms>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<WarningsAsErrors>CS8600;CS8601;CS8602;CS8603;CS8604;CS8618</WarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
|
|
@ -6,13 +6,13 @@ namespace PkmnLibSharp.Utilities
|
||||||
{
|
{
|
||||||
internal static class MarshalHelper
|
internal static class MarshalHelper
|
||||||
{
|
{
|
||||||
internal static IntPtr ToPtr(this string s)
|
internal static IntPtr ToPtr(this string? s)
|
||||||
{
|
{
|
||||||
if (s == null) return IntPtr.Zero;
|
if (s == null) return IntPtr.Zero;
|
||||||
return Marshal.StringToHGlobalAnsi(s);
|
return Marshal.StringToHGlobalAnsi(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string PtrString(this IntPtr i)
|
internal static string? PtrString(this IntPtr i)
|
||||||
{
|
{
|
||||||
if (i == IntPtr.Zero) return null;
|
if (i == IntPtr.Zero) return null;
|
||||||
return Marshal.PtrToStringAnsi(i);
|
return Marshal.PtrToStringAnsi(i);
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace PkmnLibSharp.Utilities
|
||||||
Cached.TryRemove(Ptr, out _);
|
Cached.TryRemove(Ptr, out _);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryResolvePointer<T>(IntPtr p, out T result) where T : PointerWrapper
|
public static bool TryResolvePointer<T>(IntPtr p, out T? result) where T : PointerWrapper
|
||||||
{
|
{
|
||||||
if (p == IntPtr.Zero)
|
if (p == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
|
|
|
@ -67,8 +67,8 @@ namespace PkmnLibSharp.Utilities
|
||||||
// Where's your god now?
|
// Where's your god now?
|
||||||
// (We add the offset of the index to the pointer, then dereference the pointer pointer to get the actual pointer to the object we want.)
|
// (We add the offset of the index to the pointer, then dereference the pointer pointer to get the actual pointer to the object we want.)
|
||||||
var p = new IntPtr(*(void**)IntPtr.Add(_ptr, index * IntPtr.Size).ToPointer());
|
var p = new IntPtr(*(void**)IntPtr.Add(_ptr, index * IntPtr.Size).ToPointer());
|
||||||
if (PointerWrapper.TryResolvePointer(p, out T t))
|
if (PointerWrapper.TryResolvePointer(p, out T? t))
|
||||||
return t;
|
return t!;
|
||||||
t = new T();
|
t = new T();
|
||||||
t.Initialize(p);
|
t.Initialize(p);
|
||||||
return t;
|
return t;
|
||||||
|
|
|
@ -10,13 +10,13 @@ namespace PkmnLibSharp.Utilities
|
||||||
{
|
{
|
||||||
case 0: return;
|
case 0: return;
|
||||||
case 1:
|
case 1:
|
||||||
throw new NativeException("Arbutils", C.GetLastException().PtrString());
|
throw new NativeException("Arbutils", C.GetLastException().PtrString()!);
|
||||||
case 2:
|
case 2:
|
||||||
throw new NativeException("CreatureLibLibrary",
|
throw new NativeException("CreatureLibLibrary",
|
||||||
Creaturelib.Generated.C.GetLastException().PtrString());
|
Creaturelib.Generated.C.GetLastException().PtrString()!);
|
||||||
case 4:
|
case 4:
|
||||||
throw new NativeException("PkmnLib",
|
throw new NativeException("PkmnLib",
|
||||||
Pkmnlib.Generated.C.GetLastException().PtrString());
|
Pkmnlib.Generated.C.GetLastException().PtrString()!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue