suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
authornemo
Sat, 11 May 2013 21:50:14 -0400
changeset 8978 e6ef8fe314bd
parent 8977 d424c7f8b342
child 8979 860836494821
suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
hedgewars/uPhysFSLayer.pas
hedgewars/uScript.pas
misc/libphyslayer/hwpacksmounter.c
misc/libphyslayer/hwpacksmounter.h
--- a/hedgewars/uPhysFSLayer.pas	Sat May 11 21:19:44 2013 -0400
+++ b/hedgewars/uPhysFSLayer.pas	Sat May 11 21:50:14 2013 -0400
@@ -46,6 +46,7 @@
 
 function  physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName;
 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
+procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName;
 
 implementation
 uses uUtils, uVariables, sysutils;
--- a/hedgewars/uScript.pas	Sat May 11 21:19:44 2013 -0400
+++ b/hedgewars/uScript.pas	Sat May 11 21:50:14 2013 -0400
@@ -2039,7 +2039,8 @@
     // call the script file
     lua_pcall(luaState, 0, 0, 0);
     ScriptLoaded:= true
-    end
+    end;
+    hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp'));
 end;
 
 procedure SetGlobals;
--- a/misc/libphyslayer/hwpacksmounter.c	Sat May 11 21:19:44 2013 -0400
+++ b/misc/libphyslayer/hwpacksmounter.c	Sat May 11 21:50:14 2013 -0400
@@ -33,3 +33,24 @@
 
     PHYSFS_freeList(filesList);
 }
+
+PHYSFS_DECL void hedgewarsMountPackage(char * fileName)
+{
+    int fileNameLength = strlen(fileName);
+    if (fileNameLength > 4)
+        if (strcmp(fileName + fileNameLength - 4, ".hwp") == 0)
+        {
+            const char * dir = PHYSFS_getRealDir(fileName);
+            if(dir)
+            {
+                char * fullPath = (char *)malloc(strlen(dir) + fileNameLength + 2);
+                strcpy(fullPath, dir);
+                strcat(fullPath, "/");
+                strcat(fullPath, fileName);
+
+                PHYSFS_mount(fullPath, NULL, 0);
+
+                free(fullPath);
+            }
+        }
+}
--- a/misc/libphyslayer/hwpacksmounter.h	Sat May 11 21:19:44 2013 -0400
+++ b/misc/libphyslayer/hwpacksmounter.h	Sat May 11 21:50:14 2013 -0400
@@ -8,7 +8,7 @@
 #endif
 
 PHYSFS_DECL void hedgewarsMountPackages();
-
+PHYSFS_DECL void hedgewarsMountPackage(char * fileName);
 
 #ifdef __cplusplus
 }