From 28886253b9ea693b42b4e89325c4643a1c8baca4 Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Wed, 8 Jan 2020 20:51:09 +1100
Subject: [PATCH] xaudio2_7: Dont cast interface pointers

---
 dlls/xaudio2_7/xact_dll.c | 51 ++++++++++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 17 deletions(-)

diff --git a/dlls/xaudio2_7/xact_dll.c b/dlls/xaudio2_7/xact_dll.c
index 2bf6eaf374..6ed67c3a67 100644
--- a/dlls/xaudio2_7/xact_dll.c
+++ b/dlls/xaudio2_7/xact_dll.c
@@ -763,7 +763,7 @@ static HRESULT WINAPI IXACT3WaveBankImpl_Prepare(IXACT3WaveBank *iface,
 
     wave->IXACT3Wave_iface.lpVtbl = &XACT3Wave_Vtbl;
     wave->fact_wave = fwave;
-    *ppWave = (IXACT3Wave*)wave;
+    *ppWave = &wave->IXACT3Wave_iface;
 
     TRACE("Created Wave: %p\n", wave);
 
@@ -804,7 +804,9 @@ static HRESULT WINAPI IXACT3WaveBankImpl_Play(IXACT3WaveBank *iface,
 
         wave->IXACT3Wave_iface.lpVtbl = &XACT3Wave_Vtbl;
         wave->fact_wave = fwave;
-        *ppWave = (IXACT3Wave*)wave;
+        *ppWave = &wave->IXACT3Wave_iface;
+
+        TRACE("Created Wave: %p\n", wave);
     }
 
     return hr;
@@ -1025,7 +1027,7 @@ static HRESULT WINAPI IXACT3EngineImpl_CreateSoundBank(IXACT3Engine *iface,
 
     sb->IXACT3SoundBank_iface.lpVtbl = &XACT3SoundBank_Vtbl;
     sb->fact_soundbank = fsb;
-    *ppSoundBank = (IXACT3SoundBank*)sb;
+    *ppSoundBank = &sb->IXACT3SoundBank_iface;
 
     TRACE("Created SoundBank: %p\n", sb);
 
@@ -1060,7 +1062,7 @@ static HRESULT WINAPI IXACT3EngineImpl_CreateInMemoryWaveBank(IXACT3Engine *ifac
 
     wb->IXACT3WaveBank_iface.lpVtbl = &XACT3WaveBank_Vtbl;
     wb->fact_wavebank = fwb;
-    *ppWaveBank = (IXACT3WaveBank*)wb;
+    *ppWaveBank = &wb->IXACT3WaveBank_iface;
 
     TRACE("Created in-memory WaveBank: %p\n", wb);
 
@@ -1104,7 +1106,7 @@ static HRESULT WINAPI IXACT3EngineImpl_CreateStreamingWaveBank(IXACT3Engine *ifa
 
     wb->IXACT3WaveBank_iface.lpVtbl = &XACT3WaveBank_Vtbl;
     wb->fact_wavebank = fwb;
-    *ppWaveBank = (IXACT3WaveBank*)wb;
+    *ppWaveBank = &wb->IXACT3WaveBank_iface;
 
     TRACE("Created streaming WaveBank: %p\n", wb);
 
@@ -1145,7 +1147,11 @@ static HRESULT WINAPI IXACT3EngineImpl_PrepareStreamingWave(IXACT3Engine *iface,
 static inline void unwrap_notificationdesc(FACTNotificationDescription *fd,
         const XACT_NOTIFICATION_DESCRIPTION *xd)
 {
+    memset(fd, 0, sizeof(*fd));
     /* We have to unwrap the FACT object first! */
+
+    FIXME("Type %d\n", xd->type);
+
     fd->type = xd->type;
     fd->flags = xd->flags;
     fd->cueIndex = xd->cueIndex;
@@ -1153,24 +1159,35 @@ static inline void unwrap_notificationdesc(FACTNotificationDescription *fd,
     fd->pvContext = xd->pvContext;
 
     if (xd->pCue != NULL)
-        fd->pCue = ((XACT3CueImpl*) xd->pCue)->fact_cue;
-    else
-        fd->pCue = NULL;
+    {
+        XACT3CueImpl *cur = impl_from_IXACT3Cue(xd->pCue);
+        if (cur)
+            fd->pCue = cur->fact_cue;
+    }
 
     if (xd->pSoundBank != NULL)
-        fd->pSoundBank = ((XACT3SoundBankImpl*) xd->pSoundBank)->fact_soundbank;
-    else
-        fd->pSoundBank = NULL;
+    {
+        XACT3SoundBankImpl *sound = impl_from_IXACT3SoundBank(xd->pSoundBank);
+        if (sound)
+            fd->pSoundBank = sound->fact_soundbank;
+    }
 
     if (xd->pWaveBank != NULL)
-        fd->pWaveBank = ((XACT3WaveBankImpl*) xd->pWaveBank)->fact_wavebank;
-    else
-        fd->pWaveBank = NULL;
+    {
+        XACT3WaveBankImpl *bank = impl_from_IXACT3WaveBank(xd->pWaveBank);
+        if (bank)
+            fd->pWaveBank = bank->fact_wavebank;
+    }
 
     if (xd->pWave != NULL)
-        fd->pWave = ((XACT3WaveImpl*) xd->pWave)->fact_wave;
-    else
-        fd->pWave = NULL;
+    {
+        XACT3WaveImpl *wave = impl_from_IXACT3Wave(xd->pWave);
+        FIXME("Wave %p\n", wave);
+        if (wave)
+        {
+            fd->pWave = wave->fact_wave;
+        }
+    }
 }
 
 static HRESULT WINAPI IXACT3EngineImpl_RegisterNotification(IXACT3Engine *iface,
-- 
2.25.1

