Created
April 17, 2020 11:18
-
-
Save scotchi/5b07056855220f9170bda5afeac5b64c to your computer and use it in GitHub Desktop.
A demonstration of the hack needed to pull a (not-always-going-to-be-valid) pointer out of P_SRCTRACK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct { | |
int foo; | |
int bar; | |
} MediaTrack; | |
typedef union { | |
long l; | |
double d; | |
void *p; | |
} ReaperReturn; | |
double what_reaper_actually_does() | |
{ | |
MediaTrack *track = malloc(sizeof(MediaTrack)); | |
return (long) track; | |
} | |
ReaperReturn what_reaper_should_do() | |
{ | |
ReaperReturn ret; | |
MediaTrack *track = malloc(sizeof(MediaTrack)); | |
ret.p = track; | |
return ret; | |
} | |
int main(int argc, const char *argv[]) | |
{ | |
double d = what_reaper_actually_does(); | |
ReaperReturn r = what_reaper_should_do(); | |
printf("what_reaper_actually_does: %ld, %f, %p\n" | |
"what_reaper_should_do: %ld, %f, %p\n", | |
(long) d, d, *(void **)(&d), | |
r.l, r.d, r.p); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's the undocumented function
GetSetTrackSendInfo
which returns avoid *
which should absolutely be used instead of this insanity.