diff options
| author | 2026-04-02 21:16:55 -0400 | |
|---|---|---|
| committer | 2026-04-02 21:58:31 -0400 | |
| commit | 9bebe7aa2ea80df948338e8b8cee256f7b6454d9 (patch) | |
| tree | ab2df8cc6f6978c8edfc2786f0ffcd1de85502f2 /Animal.cs | |
| parent | c95b23e637fa1545a3ab2de0ec9b73d67332b4ad (diff) | |
| download | NewCamera-9bebe7aa2ea80df948338e8b8cee256f7b6454d9.tar.gz NewCamera-9bebe7aa2ea80df948338e8b8cee256f7b6454d9.tar.bz2 NewCamera-9bebe7aa2ea80df948338e8b8cee256f7b6454d9.zip | |
Gut graphics stuff, misc additions
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'Animal.cs')
| -rw-r--r-- | Animal.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Animal.cs b/Animal.cs new file mode 100644 index 0000000..1d27650 --- /dev/null +++ b/Animal.cs @@ -0,0 +1,58 @@ +using SharpPluginLoader.Core.Memory; + +namespace SharpPluginLoader.Core.Entities +{ + public class Animal : Entity + { + /// <summary> + /// The sAnimal singleton instance + /// </summary> + public static MtObject SingletonInstance => SingletonManager.GetSingleton("sAnimal")!; + + /// <summary> + /// Gets a list of all animals in the game + /// </summary> + /// <returns></returns> + public static Animal[] GetAllAnimals() + { + lock (_animals) + return _animals.ToArray(); + } + + /// <summary> + /// Constructs a new Animal from a native pointer + /// </summary> + /// <param name="instance">The native pointer</param> + public Animal(nint instance) : base(instance) { } + + // @TODO: Map to names. + public int Id => Get<int>(0x1AF8); // +0x294 + public int OtherId => Get<int>(0x1AF0); + + private static void AnimalAddHook(nint instance) + { + var animal = new Animal(instance); + lock (_animals) _animals.Add(animal); + _animalAddHook.Original(instance); + } + + private static nint AnimalRemoveHook(nint instance) + { + var animal = new Animal(instance); + lock(_animals) _animals.Remove(animal); + return _animalRemoveHook.Original(instance); + } + + internal static void Initialize() + { + _animalAddHook = Hook.Create<AnimalAddDelegate>(0x141D2F610, AnimalAddHook); + _animalRemoveHook = Hook.Create<AnimalRemoveDelegate>(0x141D289D0, AnimalRemoveHook); + } + + private delegate void AnimalAddDelegate(nint instance); + private delegate nint AnimalRemoveDelegate(nint instance); + private static Hook<AnimalAddDelegate> _animalAddHook = null!; + private static Hook<AnimalRemoveDelegate> _animalRemoveHook = null!; + private static readonly List<Animal> _animals = []; + } +} |