[Tutorial] Perfect Protection against invalid mods.
#20

Quote:

I downloaded it, and made big performance optimizations on it, so it will eat less CPU.

Mind elaborating? Also, sharing is caring.

Edit: Here's my shot at optimizing the function a little bit..

pawn Code:
stock IsVehicleComponentLegal(vehicleid, componentid) {
    new s_LegalMods[][] = {
        {54273792, 0, 16776704, 7, 0, 0},
        {35268602, 0, 16776704, 7, 245760, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {37431173, 0, 16776704, 7, 0, 0},
        {45893379, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {62531466, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {42862474, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {36767556, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {36177722, 0, 16776704, 7, 0, 0},
        {45958913, 0, 16776704, 7, 0, 0},
        {37365632, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {36177786, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {41560010, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {42084234, 0, 16776704, 7, 245760, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {37619648, 0, 16776704, 7, 0, 0},
        {57685808, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {52242293, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {46024584, 0, 16776704, 7, 245760, 0},
        {33621873, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {43651022, 0, 16776704, 7, 49152, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {54011648, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {37717909, 0, 16776704, 7, 0, 0},
        {43976588, 0, 16776704, 7, 245760, 0},
        {43395050, 0, 16776704, 7, 245760, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {37144450, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {43917258, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, -67107785, 0, 35389440},
        {33556224, 0, 16776704, 67002375, 0, 0},
        {33556224, 0, 16776704, 7047, 1, 31457280},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {60688338, 0, 16776704, 7, 245760, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {37537536, 0, 16776704, 7, 196608, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {59639766, 0, 16776704, 7, 245760, 0},
        {37553929, 0, 16776704, 7, 49152, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {43917194, 0, 16776704, 7, 245760, 0},
        {43779962, 0, 16776704, 7, 245760, 0},
        {45942636, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, -512, 7, 0, 504},
        {33556224, 0, 16777214, 7, -1073741824, 8199},
        {-33552640, 3, 16776704, 7, 15360, 1536},
        {-838859008, -8388608, 16776705, 7, 1006632960, 0},
        {33556224, 1020, 16776704, 7, 3932160, 6144},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 8380416, 16776704, 7, 62914560, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 71, 62, 1006632960},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 7168, 16776704, 15, 0, 245760},
        {33556224, 0, 16776704, 7, 960, -1073741824},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {43386818, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {51849201, 0, 16776704, 7, 196608, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {39200752, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {60688322, 0, 16776704, 7, 245760, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0},
        {33556224, 0, 16776704, 7, 0, 0}
    };
   
    // These is the only case with componentids > 1191 (saves ~1kb in the array)
    if (vehicleid == 576 && (componentid == 1192 || componentid == 1193))
        return true;
   
    if (1000 <= componentid <= 1191 && 400 <= vehicleid <= 611) {
        componentid -= 1000;
        vehicleid -= 400;
       
        return (s_LegalMods[vehicleid][componentid >>> 5] & 1 << (componentid & 31)) || false;
    }
   
    return false;
}
Reply


Messages In This Thread
Perfect Protection against invalid mods. - by JernejL - 10.02.2012, 23:07
Re: Perfect Protection against invalid mods. - by Face9000 - 10.02.2012, 23:09
Re: Perfect Protection against invalid mods. - by Hoborific - 11.02.2012, 02:44
Re: Perfect Protection against invalid mods. - by Sufyan - 11.02.2012, 02:52
Re: Perfect Protection against invalid mods. - by Nicholas. - 11.02.2012, 02:56
Re: Perfect Protection against invalid mods. - by KingHual - 11.02.2012, 06:14
Re: Perfect Protection against invalid mods. - by T0pAz - 11.02.2012, 06:17
Re: Perfect Protection against invalid mods. - by Unknownich - 11.02.2012, 07:00
Re: Perfect Protection against invalid mods. - by BMUK - 18.02.2012, 20:10
Re: Perfect Protection against invalid mods. - by toi - 19.02.2012, 22:19
Re: Perfect Protection against invalid mods. - by Kaperstone - 20.02.2012, 15:20
Re: Perfect Protection against invalid mods. - by Ricop522 - 20.02.2012, 16:25
Re: Perfect Protection against invalid mods. - by Danyal - 21.02.2012, 16:48
Re: Perfect Protection against invalid mods. - by Coffeemonster - 21.02.2012, 21:04
Re: Perfect Protection against invalid mods. - by JernejL - 22.02.2012, 18:48
Re: Perfect Protection against invalid mods. - by Ironboy. - 28.02.2012, 20:18
Re: Perfect Protection against invalid mods. - by jameskmonger - 28.02.2012, 22:54
Re: Perfect Protection against invalid mods. - by Lee_Percox - 10.03.2012, 10:21
Re: Perfect Protection against invalid mods. - by decondelite - 07.05.2012, 11:28
Re: Perfect Protection against invalid mods. - by Slice - 07.05.2012, 11:37
Re: Perfect Protection against invalid mods. - by Derek_Westbrook - 10.05.2012, 20:18
Re: Perfect Protection against invalid mods. - by Slice - 17.06.2012, 12:39
Re: Perfect Protection against invalid mods. - by CROSS_Hunter - 21.07.2012, 10:16
Re: Perfect Protection against invalid mods. - by $mooth - 21.07.2012, 15:36
Re: Perfect Protection against invalid mods. - by bye - 03.08.2012, 03:35
Re: Perfect Protection against invalid mods. - by Mishima - 13.08.2012, 12:34
Re: Perfect Protection against invalid mods. - by [MM]IKKE - 20.08.2012, 21:30
Re: Perfect Protection against invalid mods. - by skylive77 - 24.08.2012, 08:25
Re: Perfect Protection against invalid mods. - by RenSoprano - 24.08.2012, 09:07
Respuesta: Perfect Protection against invalid mods. - by Samp4lifes - 01.02.2013, 03:24
Re: Perfect Protection against invalid mods. - by Glossy42O - 22.11.2014, 09:24
Re: Perfect Protection against invalid mods. - by Glossy42O - 22.11.2014, 09:53
Respuesta: Perfect Protection against invalid mods. - by RcoNs! - 27.01.2015, 11:18
Re: Perfect Protection against invalid mods. - by TheRaGeLord - 28.01.2015, 11:20
Re: Perfect Protection against invalid mods. - by Arastair - 28.01.2015, 11:40
Re: Perfect Protection against invalid mods. - by ~Error - 25.05.2016, 16:14
Re: Perfect Protection against invalid mods. - by Bussyman - 11.05.2017, 04:43

Forum Jump:


Users browsing this thread: 5 Guest(s)