@@ -11,7 +11,7 @@ const debug = false;
1111/**
1212 * The CDN to fetch the GDAPI files from
1313 */
14- const CDN = "https://cdn.jsdelivr.net/gh/arthuro555/gdmod@latest /API/" ;
14+ const CDN = "https://cdn.jsdelivr.net/gh/arthuro555/gdmod/API/" ;
1515
1616/**
1717 * Flag telling if that page got patched already.
@@ -88,6 +88,30 @@ function patchSceneCode() {
8888 }
8989}
9090
91+ /** From https://stackoverflow.com/a/12300351/10994662 */
92+ function dataURItoBlob ( dataURI ) {
93+ var byteString = atob ( dataURI . split ( ',' ) [ 1 ] ) ;
94+
95+ // separate out the mime component
96+ var mimeString = dataURI . split ( ',' ) [ 0 ] . split ( ':' ) [ 1 ] . split ( ';' ) [ 0 ]
97+
98+ // write the bytes of the string to an ArrayBuffer
99+ var ab = new ArrayBuffer ( byteString . length ) ;
100+
101+ // create a view into the buffer
102+ var ia = new Uint8Array ( ab ) ;
103+
104+ // set the bytes of the buffer to the correct values
105+ for ( var i = 0 ; i < byteString . length ; i ++ ) {
106+ ia [ i ] = byteString . charCodeAt ( i ) ;
107+ }
108+
109+ // write the ArrayBuffer to a blob, and you're done
110+ var blob = new Blob ( [ ab ] , { type : mimeString } ) ;
111+ return blob ;
112+
113+ }
114+
91115
92116// First we verify if the game is a GDevelop game
93117if ( window . gdjs !== undefined ) {
@@ -115,6 +139,9 @@ if(window.gdjs !== undefined) {
115139 } else if ( event . data [ "message" ] === "changeScene" ) {
116140 if ( typeof GDAPI === "undefined" ) return ;
117141 GDAPI . currentScene . getGame ( ) . _sceneStack . replace ( event . data . scene , true ) ;
142+ } else if ( event . data [ "message" ] === "loadMod" ) {
143+ const mod = dataURItoBlob ( event . data [ "mod" ] ) ;
144+ GDAPI . loadZipMod ( mod ) ;
118145 }
119146 }
120147 } ) ;
0 commit comments