about summary refs log tree commit diff stats
path: root/src/libtools/sdl2rwops.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-02-13 12:02:37 +0100
committerptitSeb <sebastien.chev@gmail.com>2022-02-13 12:02:37 +0100
commit23709c09c7245272f3963f8fef457b67249c110d (patch)
treed1df549c75dc9fd04a15a4699c99633e4f4a1769 /src/libtools/sdl2rwops.c
parent547b97d4cb6d06104dc104458ac48fd91bca5e41 (diff)
downloadbox64-23709c09c7245272f3963f8fef457b67249c110d.tar.gz
box64-23709c09c7245272f3963f8fef457b67249c110d.zip
Added some code to detect if emulted program use old IMG_SavePNG_RW api instead of current one
Diffstat (limited to 'src/libtools/sdl2rwops.c')
-rwxr-xr-xsrc/libtools/sdl2rwops.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/libtools/sdl2rwops.c b/src/libtools/sdl2rwops.c
index bbe28414..f57dc567 100755
--- a/src/libtools/sdl2rwops.c
+++ b/src/libtools/sdl2rwops.c
@@ -53,6 +53,13 @@ typedef struct SDL2_RWops_s {
     } hidden;
 } SDL2_RWops_t;
 
+#define SUPER()         \
+    GO(size, IFp)       \
+    GO(seek, IFpIi)     \
+    GO(read, iFppii)    \
+    GO(write, iFppii)   \
+    GO(close, iFp)
+
 EXPORT int64_t my2_native_size(SDL2_RWops_t *context)
 {
     return context->hidden.my.orig->size(context->hidden.my.orig);
@@ -118,11 +125,7 @@ SDL2_RWops_t* AddNativeRW2(x64emu_t* emu, SDL2_RWops_t* ops)
     fnc = AddCheckBridge(system, W, my2_native_##A, 0, NULL); \
     newrw->A = (sdl2_##A)fnc;
 
-    GO(size, IFp)
-    GO(seek, IFpIi)
-    GO(read, iFppii)
-    GO(write, iFppii)
-    GO(close, iFp)
+    SUPER()
 
     #undef GO
 
@@ -149,11 +152,7 @@ SDL2_RWops_t* RWNativeStart2(x64emu_t* emu, SDL2_RWops_t* ops)
     #define GO(A, W) \
     newrw->A = my2_emulated_##A;
 
-    GO(size, IFp)
-    GO(seek, IFpIi)
-    GO(read, iFppii)
-    GO(write, iFppii)
-    GO(close, iFp)
+    SUPER()
 
     #undef GO
 
@@ -169,6 +168,25 @@ void RWNativeEnd2(SDL2_RWops_t* ops)
     ops->hidden.my.custom_free(ops);
 }
 
+int isRWops(SDL2_RWops_t* ops)
+{
+    if(!ops)
+        return 0;
+    #define GO(A, W)      \
+    if(!ops->A || (uintptr_t)ops->A < 0x1000) return 0;
+
+    SUPER()
+
+    #undef GO
+    // check if all then hidden content is just full of 0
+    if(ops->hidden.mem.base==NULL && ops->hidden.mem.here==NULL && ops->hidden.mem.stop==NULL)
+        return 0;
+    // check the type (not sure it's a good check here)
+    if (ops->type>5 && ops->type!=BOX64RW)
+        return 0;
+    return 1;
+}
+
 int64_t RWNativeSeek2(SDL2_RWops_t *ops, int64_t offset, int32_t whence)
 {
     return ops->seek(ops, offset, whence);