Sharing WME Code changes

Discussion for the unofficial, community-developed addons, extensions and scripts built for the Waze Map Editor.

The official index of these tools is the Community Plugins, Extensions and Tools wiki page.

Moderators: Unholy, bextein, Glodenox, JustinS83

Forum rules
Discussion for the unofficial, community-developed addons, extensions and scripts built for the Waze Map Editor.

DO NOT START a new thread unless it is about a new idea. Keep discussion of existing tools within the main thread for that tool.

The official index of these tools is the Community Plugins, Extensions and Tools wiki page.

Re: Sharing WME Code changes

Postby dummyd2 » Sun Nov 13, 2016 2:26 pm

Hi,

since Waze devs confirm that the new way of making edit was not intended to kill script, here is a piece of code to get the "require" stuff working again:
Code: Select all
// setup one global var and put all in
var WMEAPI = {};


// detect URL of WME source code
WMEAPI.scripts = document.getElementsByTagName('script');
WMEAPI.url=null;
for (i=0;i<WMEAPI.scripts.length;i++)
{
    if (WMEAPI.scripts[i].src.indexOf('/assets-editor/js/app')!=-1)
    {
        WMEAPI.url=WMEAPI.scripts[i].src;
        break;
    }
}
if (WMEAPI.url==null)
{
    throw new Error("WME Hack: can't detect WME main JS");
}



// setup a fake require and require.define
WMEAPI.require=function (e) {
    if (WMEAPI.require.define.modules.hasOwnProperty(e))
        return WMEAPI.require.define.modules[e];
    else
        console.error('Require failed on ' + e, WMEAPI.require.define.modules);
    return null;
};

WMEAPI.require.define=function (m) {
    if (WMEAPI.require.define.hasOwnProperty('modules')==false)
        WMEAPI.require.define.modules={};
    for (var p in m)
    {
        WMEAPI.require.define.modules[p]=m[p];
    }
};

// save the original webpackJsonp function
WMEAPI.tmp = window.webpackJsonp;

// taken from WME code: this function is a wrapper that setup the API and may call recursively other functions
WMEAPI.t = function (n) {
    if (WMEAPI.s[n]) return WMEAPI.s[n].exports;
    var r = WMEAPI.s[n] = {
        exports: {},
        id: n,
        loaded: !1
    };
    return WMEAPI.e[n].call(r.exports, r, r.exports, WMEAPI.t), r.loaded = !0, r.exports;
};

// e is a copy of all WME funcs because function t need to access to this list
WMEAPI.e=[];

// the patch
window.webpackJsonp = function(a, i) {
    // our API but we will use it only to build the require stuffs
    var api={};
    // taken from WME code. a is [1], so...
    for (var o, d, u = 0, l = []; u < a.length; u++) d = a[u], WMEAPI.r[d] && l.push.apply(l, WMEAPI.r[d]), WMEAPI.r[d] = 0;
   
    var unknownCount=0;
    var classname, funcStr;
   
    // copy i in e and keep a link from classname to index in e
    for (o in i)
    {
        WMEAPI.e[o] = i[o];
        funcStr = i[o].toString();
        classname = funcStr.match(/CLASS_NAME:\"([^\"]*)\"/);
        if (classname)
        {
            // keep the link.
            api[classname[1].replace(/\./g,'/').replace(/^W\//, 'Waze/')]={index: o, func: WMEAPI.e[o]};
        }
        else
        {
            api['Waze/Unknown/' + unknownCount]={index: o, func: WMEAPI.e[o]};
            unknownCount++;
        }
       
    }
   
    // taken from WME code: it calls the original webpackJsonp and do something else, but I don't really know what.
    // removed the call to the original webpackJsonp: still works...
    //for (tmp && tmp(a, i); l.length;) l.shift().call(null, t);
    for (; l.length;) l.shift().call(null, WMEAPI.t);
    WMEAPI.s[0] = 0;
   
    // run the first func of WME. This first func will call recusrsively all funcs needed to setup the API.
    // After this call, s will contain all instanciables classes.
    //var ret = WMEAPI.t(0);
   
    // now, build the requires thanks to the link we've built in var api.
    var module={};
    var apiFuncName;
    unknownCount=0;
   
    for (o in i)
    {
        funcStr = i[o].toString();
        classname = funcStr.match(/CLASS_NAME:\"([^\"]*)\"/);
        if (classname)
        {
            module={};
            apiFuncName = classname[1].replace(/\./g,'/').replace(/^W\//, 'Waze/');
            module[apiFuncName]=WMEAPI.t(api[apiFuncName].index);
            WMEAPI.require.define(module);
        }
        else
        {
            var matches = funcStr.match(/SEGMENT:"segment",/);
            if (matches)
            {
                module={};
                apiFuncName='Waze/Model/ObjectType';
                module[apiFuncName]=WMEAPI.t(api['Waze/Unknown/' + unknownCount].index);
                WMEAPI.require.define(module);
            }
            unknownCount++;
        }
    }
     

    // restore the original func
    window.webpackJsonp=WMEAPI.tmp;

    // set the require public if needed
    // if so: others scripts must wait for the window.require to be available before using it.
    window.require=WMEAPI.require;
    // all available functions are in WMEAPI.require.define.modules
    // console.debug this variable to read it:
    // console.debug('Modules: ', WMEAPI.require.define.modules);
   
    // run your script here:
    // setTimeout(yourscript);
   
    // again taken from WME code. Not sure about what it does.
    //if (i[0]) return ret;
};

// some kind of global vars and init
WMEAPI.s = {};
WMEAPI.r = {
    0: 0
};

// hacking finished

// load again WME through our patched func
WMEAPI.WMEHACK_Injected_script = document.createElement("script");
WMEAPI.WMEHACK_Injected_script.setAttribute("type", "application/javascript");
WMEAPI.WMEHACK_Injected_script.src = WMEAPI.url;
document.body.appendChild(WMEAPI.WMEHACK_Injected_script);



What it does:
  1. Detects the WME code URL
  2. Creates a require command
  3. Creates a patch on "webpackJsonp". This patch will detect classes previously available in "require" and add it in our custom "require" command.
  4. Loads the WME code, but in our patched function

Then, you can do a "require(...)" like before.

Note that some functions are not available in the new WME. As stated in the code, you can log modules to see what classes are available.

Also stated in the code, you can make the require command global. But other scripts can call the "require" command before our patch, so it will not work.
So, I recommend to use this patch in all script that need "require", and not making your "require" global.
Dummyd2 AKA D2.
Retired - retraité de Waze
dummyd2
Experts
Experts
 
Posts: 1319
Joined: Wed Oct 23, 2013 12:01 pm
Location: Mentoring Bordeaux + CUB, Lot-et-Garonne
Has thanked: 321 times
Been thanked: 1115 times

Re: Sharing WME Code changes

Postby gertbroos » Sun Nov 13, 2016 2:37 pm

Thanks! My scripts are now working again :D

Now we have to just wait for the 2 big ones...
gertbroos
Waze Local Champs
Waze Local Champs
 
Posts: 357
Joined: Mon Jan 19, 2015 4:04 pm
Location: Belgium
Has thanked: 87 times
Been thanked: 246 times

Re: Sharing WME Code changes

Postby JustinS83 » Sun Nov 13, 2016 3:21 pm

Tried it in one of my scripts and it is working great!

Thank you d2!
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Re: Sharing WME Code changes

Postby gertbroos » Sun Nov 13, 2016 4:03 pm

Spoke too soon... the new UpdateObject() functionality is also changed...

Why oh why :roll:
gertbroos
Waze Local Champs
Waze Local Champs
 
Posts: 357
Joined: Mon Jan 19, 2015 4:04 pm
Location: Belgium
Has thanked: 87 times
Been thanked: 246 times

Re: Sharing WME Code changes

Postby WC40WC » Sun Nov 13, 2016 4:09 pm

Hi, How do i use the patch code?? Some manual for me pls.
WC40WC
 
Posts: 45
Joined: Tue Jun 21, 2016 10:11 am
Has thanked: 0 time
Been thanked: 8 times

Re: Sharing WME Code changes

Postby Twister-UK » Mon Nov 14, 2016 2:07 pm

dummyd2 wrote:here is a piece of code to get the "require" stuff working again


If ever there was a time when we really need to be able to give a post multiple thumbs-up, this surely qualifies...

I'd just found a workaround for the require() I was using to delete unwanted cameras, but was struggling to find a similar one for adding new UR markers. And despite your code looking almost as terrifying as some of the stuff the devteam generate, getting it up and running in URO+ took all of about 5 minutes. 4m30s of which was just reformatting the code into the same style as the rest of the script :D

Still got a lot of other work to do to workaround the other changes the devteam have introduced, but you've provided a massive step forwards here, so many many thanks indeed.

Regards,
Chris
Chris (not to be confused with Chris or Chris...)
AM SE England & Shetland Islands, UK Local Champ, WME Beta Tester & ScriptMangler
WME/Livemap enhancement scripts @ GreasyFork and Chrome Web Store


[ img ][ img ][ img ]
Twister-UK
Waze Local Champs
Waze Local Champs
 
Posts: 3608
Joined: Sat Jan 07, 2012 12:00 am
Location: NW London
Has thanked: 590 times
Been thanked: 3368 times

Re: Sharing WME Code changes

Postby bz2012 » Mon Nov 14, 2016 5:15 pm

It would be nice if that code and any other necessary to support it could be written into a new 'script'.
That script could be called something like "WME global fix patches" and it would make it unnecessary to patch each script. Is there a way to force such a script to load first?

Well, I can wish, can't I?
Last edited by bz2012 on Mon Nov 14, 2016 5:18 pm, edited 1 time in total.
State Manager, Louisiana
bz2012
Map Raider
Map Raider
 
Posts: 1595
Joined: Wed Nov 23, 2011 4:32 pm
Location: Baton Rouge, La
Has thanked: 1908 times
Been thanked: 310 times

Re: Sharing WME Code changes

Postby JustinS83 » Mon Nov 14, 2016 5:16 pm

bz2012 wrote:It would be nice if that code and any other necessary to support it could be written into a new 'script'.
That script could be called something like "WME global fix patches" and it would make it unnecessary to patch each script.

Well, I can wish, can't I?


Stay tuned...
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Re: Sharing WME Code changes

Postby turbomkt » Mon Nov 14, 2016 7:22 pm

bz2012 wrote:It would be nice if that code and any other necessary to support it could be written into a new 'script'.
That script could be called something like "WME global fix patches" and it would make it unnecessary to patch each script. Is there a way to force such a script to load first?

Well, I can wish, can't I?


Tampermonkey can change the order of loading, IIRC...
turbomkt
Country Manager
Country Manager
 
Posts: 1072
Joined: Thu Jan 22, 2015 1:05 am
Location: San Diego, Ca
Has thanked: 446 times
Been thanked: 294 times

Re: Sharing WME Code changes

Postby n4dog » Mon Nov 14, 2016 8:33 pm

Seeing how I am script dumb. How do I put it in my scripts to see if it would work
Griff - N4DOG
Alabama State Manager
n4dog
State Manager
State Manager
 
Posts: 550
Joined: Fri Apr 03, 2015 3:24 pm
Location: Tallahassee, Fl.
Has thanked: 458 times
Been thanked: 162 times

PreviousNext

Return to Addons, Extensions, and Scripts

Who is online

Users browsing this forum: jmbox, RichardPyne