diff --git a/ZenKit.Test/Vobs/TestCamera.cs b/ZenKit.Test/Vobs/TestCamera.cs index be6c872..ed0f3df 100644 --- a/ZenKit.Test/Vobs/TestCamera.cs +++ b/ZenKit.Test/Vobs/TestCamera.cs @@ -37,7 +37,7 @@ public void TestLoadG2() Assert.That(vob.TargetCount, Is.EqualTo(1)); var frames = vob.Frames; - Assert.That(frames, Has.Count.EqualTo(3)); + Assert.That(frames, Has.Count.EqualTo(2)); Assert.That(frames[0].Time, Is.EqualTo(0.0f)); Assert.That(frames[0].RollAngle, Is.EqualTo(0.0f)); Assert.That(frames[0].FovScale, Is.EqualTo(1.0f)); diff --git a/ZenKit/DaedalusVm.cs b/ZenKit/DaedalusVm.cs index 3a89dda..35591b7 100644 --- a/ZenKit/DaedalusVm.cs +++ b/ZenKit/DaedalusVm.cs @@ -123,6 +123,51 @@ public void PrintStackTrace() { Native.ZkDaedalusVm_printStackTrace(Handle); } + + public T AllocInstance(string symbolName) + { + var sym = GetSymbolByName(symbolName); + if (sym == null) throw new Exception("Symbol not found"); + return AllocInstance(sym); + } + + public T AllocInstance(DaedalusSymbol symbol) + { + DaedalusInstanceType type; + + if (typeof(T) == typeof(GuildValuesInstance)) type = DaedalusInstanceType.GuildValues; + else if (typeof(T) == typeof(NpcInstance)) type = DaedalusInstanceType.Npc; + else if (typeof(T) == typeof(MissionInstance)) type = DaedalusInstanceType.Mission; + else if (typeof(T) == typeof(ItemInstance)) type = DaedalusInstanceType.Item; + else if (typeof(T) == typeof(FocusInstance)) type = DaedalusInstanceType.Focus; + else if (typeof(T) == typeof(InfoInstance)) type = DaedalusInstanceType.Info; + else if (typeof(T) == typeof(ItemReactInstance)) type = DaedalusInstanceType.ItemReact; + else if (typeof(T) == typeof(SpellInstance)) type = DaedalusInstanceType.Spell; + else if (typeof(T) == typeof(MenuInstance)) type = DaedalusInstanceType.Menu; + else if (typeof(T) == typeof(MenuItemInstance)) type = DaedalusInstanceType.MenuItem; + else if (typeof(T) == typeof(CameraInstance)) type = DaedalusInstanceType.Camera; + else if (typeof(T) == typeof(MusicSystemInstance)) type = DaedalusInstanceType.MusicSystem; + else if (typeof(T) == typeof(MusicThemeInstance)) type = DaedalusInstanceType.MusicTheme; + else if (typeof(T) == typeof(MusicJingleInstance)) type = DaedalusInstanceType.MusicJingle; + else if (typeof(T) == typeof(ParticleEffectInstance)) type = DaedalusInstanceType.ParticleEffect; + else if (typeof(T) == typeof(EffectBaseInstance)) type = DaedalusInstanceType.EffectBase; + else if (typeof(T) == typeof(ParticleEffectEmitKeyInstance)) + type = DaedalusInstanceType.ParticleEffectEmitKey; + else if (typeof(T) == typeof(FightAiInstance)) type = DaedalusInstanceType.FightAi; + else if (typeof(T) == typeof(SoundEffectInstance)) type = DaedalusInstanceType.SoundEffect; + else if (typeof(T) == typeof(SoundSystemInstance)) type = DaedalusInstanceType.SoundSystem; + else if (typeof(T) == typeof(InvalidOperationException)) type = DaedalusInstanceType.Svm; + else throw new NotSupportedException("Must be DaedalusInstance"); + + var ptr = DaedalusInstance.FromNative(Native.ZkDaedalusVm_allocInstance(Handle, symbol.Handle, type)) ?? + throw new InvalidOperationException(); + return (T)(object)ptr; + } + + public void InitInstance(DaedalusInstance instance) + { + Native.ZkDaedalusVm_initInstanceDirect(Handle, instance.Handle); + } public T InitInstance(string symbolName) { diff --git a/ZenKit/Native.cs b/ZenKit/Native.cs index c3eae6b..ba90a37 100644 --- a/ZenKit/Native.cs +++ b/ZenKit/Native.cs @@ -3205,8 +3205,15 @@ public static extern void ZkDaedalusScript_enumerateInstanceSymbols(UIntPtr slf, [DllImport(DllName)] public static extern void ZkDaedalusVm_callFunction(UIntPtr slf, UIntPtr sym); + [DllImport(DllName)] + public static extern UIntPtr ZkDaedalusVm_allocInstance(UIntPtr slf, UIntPtr sym, DaedalusInstanceType type); + [DllImport(DllName)] public static extern UIntPtr ZkDaedalusVm_initInstance(UIntPtr slf, UIntPtr sym, DaedalusInstanceType type); + + [DllImport(DllName)] + public static extern void ZkDaedalusVm_initInstanceDirect(UIntPtr slf, UIntPtr instance); + [DllImport(DllName)] public static extern void ZkDaedalusVm_registerExternal(UIntPtr slf, UIntPtr sym, diff --git a/ZenKit/runtimes/android-arm64/native/libzenkitcapi.so b/ZenKit/runtimes/android-arm64/native/libzenkitcapi.so index cddbb96..1a40f19 100644 Binary files a/ZenKit/runtimes/android-arm64/native/libzenkitcapi.so and b/ZenKit/runtimes/android-arm64/native/libzenkitcapi.so differ diff --git a/ZenKit/runtimes/linux-x64/native/libzenkitcapi.so b/ZenKit/runtimes/linux-x64/native/libzenkitcapi.so index d134e44..560fc8f 100644 Binary files a/ZenKit/runtimes/linux-x64/native/libzenkitcapi.so and b/ZenKit/runtimes/linux-x64/native/libzenkitcapi.so differ diff --git a/ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib b/ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib index 052e121..8ec4720 100644 Binary files a/ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib and b/ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib differ diff --git a/ZenKit/runtimes/win-x64/native/zenkitcapi.dll b/ZenKit/runtimes/win-x64/native/zenkitcapi.dll index cd2ca2c..9d62c1f 100644 Binary files a/ZenKit/runtimes/win-x64/native/zenkitcapi.dll and b/ZenKit/runtimes/win-x64/native/zenkitcapi.dll differ