diff --git a/src/collar/oc_rlvsuite.lsl b/src/collar/oc_rlvsuite.lsl index d4515395c..1de7c3e6b 100644 --- a/src/collar/oc_rlvsuite.lsl +++ b/src/collar/oc_rlvsuite.lsl @@ -55,10 +55,14 @@ medea (medea destiny) - Removed double menu for (prefix) restrictions Jun 2024 - Extended chat command function above to allow for capitalization of individual restriction names. Nikki Lacrima - Sept 2024 - Remove superflous llOwnerSay commands and replace g_lMenuIDs (Yosty patch PR #963) + Sept 2024 - Remove superflous llOwnerSay commands and replace g_lMenuIDs (Yosty patch PR #963) + Oct 2024 - Correct off by one bitshift and improve bitpos and bitvalue handling for restriction bitmaps. + Removed float llPow and llLog10 from bitmask calculations and use bitshift operators instead. + Consistently use bit numberings starting from 0, bit number always equals bitshift, corresponding to a value of 1<=31){ Flag1=0; - Flag2 = llRound(llPow(2, (i/3)-30)); + Flag2 = 1 << ((i/3)-31); } if(iAuth==CMD_OWNER || iAuth==CMD_TRUSTED){ if((g_iRestrictions1 & Flag1) || (g_iRestrictions2 & Flag2)) lMenu+= [Checkbox(TRUE, llList2String(g_lRLVList, i))]; @@ -343,22 +350,6 @@ MenuDelete(key kID, integer iAuth) } } -list bitpos (integer flag1,integer flag2){ - list ret=[0,0]; - - if(flag1>0){ - ret=llListReplaceList(ret,[llRound(llLog10(flag1)/llLog10(2))],0,0); - } - - if(flag2>0){ - ret = llListReplaceList(ret,[llRound(llLog10(flag2)/llLog10(2))],1,1); - } - - - return ret; -} - - string FormatCommand(string sCommand,integer bEnable) { string sMod; @@ -390,31 +381,27 @@ string FormatCommand(string sCommand,integer bEnable) ApplyAll(integer iMask1, integer iMask2, integer iBoot) { + if ( iMask1 == g_iRestrictions1 && iMask2 == g_iRestrictions2) { + return; + } list lResult = []; - integer iMax1 = 1073741824; - integer iMax2 = 1073741824; - while (iMax1 > 0) { - list pos = bitpos(iMax1, 0); - integer iIndex = (llList2Integer(pos,0)*3)+2; - - - if (iIndex > -1 && bool(iMax1 & iMask1) != bool(iMax1 & g_iRestrictions1)) { - lResult += [FormatCommand(llList2String(g_lRLVList,iIndex), bool(iMax1 & iMask1))]; + integer iBitValue = 0x40000000; + integer iBitNumber = 30; + + while (iBitValue > 0) { + integer iIndex = (iBitNumber*3)+2; + if (bool(iBitValue & iMask1) != bool(iBitValue & g_iRestrictions1)) { + lResult += [FormatCommand(llList2String(g_lRLVList,iIndex), bool(iBitValue & iMask1))]; // llSay(0, "lRLVListPart1.\npos: "+(string)pos+"\niIndex: "+(string)iIndex+"\nlResult[-1]: "+llList2String(lResult,-1)); } - iMax1 = iMax1 >> 1; - } - - while (iMax2 > 0) { - list pos = bitpos(0,iMax2); - integer iIndex = ((llList2Integer(pos,1)+30)*3)+2; - if (iIndex > -1 && bool(iMax2 & iMask2) != bool(iMax2 & g_iRestrictions2)) { - lResult += [FormatCommand(llList2String(g_lRLVList,iIndex),bool(iMax2 & iMask2))]; + + iIndex = (iBitNumber+31)*3+2; + if (bool(iBitValue & iMask2) != bool(iBitValue & g_iRestrictions2)) { + lResult += [FormatCommand(llList2String(g_lRLVList,iIndex),bool(iBitValue & iMask2))]; // llSay(0, "lRLVListPart2.\npos: "+(string)pos+"\niIndex: "+(string)iIndex+"\nlResult[-1]: "+llList2String(lResult,-1)); } - iMax2 = iMax2 >> 1; - - + iBitValue = iBitValue >> 1; + iBitNumber = iBitNumber-1; } string sCommandList = llDumpList2String(lResult,","); lResult=[]; @@ -449,11 +436,11 @@ ApplyCommand(string sCommand, integer iAdd,key kID, integer iAuth) integer iActualIndex=iMenuIndex; integer iMenuIndex2; if(iMenuIndex/3>=31){ - iMenuIndex2 =(integer) llPow(2, (iMenuIndex/3)-30); + iMenuIndex2 = 1<<((iMenuIndex/3)-31); // (integer)llPow(2, ((iMenuIndex/3)-31); iMenuIndex=0; }else { iMenuIndex2=0; - iMenuIndex = (integer)llPow(2, iMenuIndex/3); + iMenuIndex = 1<<(iMenuIndex/3); // (integer)llPow(2, iMenuIndex/3); } // llSay(0, "Apply CMD "+sCommand+"|"+(string)iAdd+"|actual="+(string)iActualIndex+"|"+(string)iMenuIndex+","+(string)iMenuIndex2); if (iActualIndex > -1) { @@ -692,7 +679,8 @@ state active if(sMsg=="Yes") { if(iAuth!=CMD_OWNER) llMessageLinked(LINK_SET,NOTIFY,"0Only an owner can restore buttons.",kAv); else { - g_lMacros = ["Hear", 4, 0, "Talk" , 3, 0, "Touch", 0, 16384, "Stray", 29360128, 524288, "Inventory", 1342179328, 96, "Dress", 0, 30, "IM", 384, 0, "Names/Map", 323584, 0, "Blur", 0, 33554432]; + g_lMacros = ["Hear", 4, 0, "Talk" , 3, 0, "Touch", 0, 8192 /*0x2000*/, "Stray", 62914560 /*0x3C00000*/, 524288 /*0x80000*/, + "Inventory", 1342179328 /*0x50000800*/, 48 /*0x30*/, "Dress", 0, 15 /*0xF*/, "IM", 384 /*0x180*/, 0, "Names/Map", 323584 /*0x4F000*/, 0, "Blur", 0, 16777216 /*0x1000000*/]; llMessageLinked(LINK_SET, LM_SETTING_SAVE, "rlvsuite_macros=" + llDumpList2String(g_lMacros,"^"), ""); } }MenuManage(kAv,iAuth); @@ -775,17 +763,11 @@ state active } else if (iNum == LM_SETTING_RESPONSE) { list lParams = llParseString2List(sStr, ["="], []); - //integer ind = llListFindList(g_lSettingsReqs, [llList2String(lParams,0)]); - //if(ind!=-1)g_lSettingsReqs = llDeleteSubList(g_lSettingsReqs, ind,ind); - - if (llList2String(lParams, 0) == "rlvsuite_masks") { list lMasks = llParseString2List(llList2String(lParams, 1),[","],[]); if (g_iRLV) { // bad timing, RLV_ON was already called integer iMask1 = (integer)llList2String(lMasks, 0); integer iMask2 = (integer)llList2String(lMasks, 1); - g_iRestrictions1 = 0; - g_iRestrictions2 = 0; ApplyAll(iMask1,iMask2,TRUE); } else { // Just save the masks, they will be applied when RLV_ON or RLV_REFRESH is received g_iRestrictions1 = llList2Integer(lMasks, 0); @@ -808,33 +790,23 @@ state active ApplyAll(iMask1,iMask2,TRUE); } else if (iNum == REBOOT && sStr == "reboot") { llResetScript(); - /*}else if(iNum == LINK_CMD_DEBUG){ - integer onlyver=0; - if(sStr == "ver")onlyver=1; - llInstantMessage(kID, llGetScriptName() +" SCRIPT VERSION: "+g_sScriptVersion); - if(onlyver)return; // basically this command was: versions - - llInstantMessage(kID, llGetScriptName() +" MEMORY USED: "+(string)llGetUsedMemory()); - llInstantMessage(kID, llGetScriptName() +" MEMORY FREE: "+(string)llGetFreeMemory()); - //Commenting this out for general release 'cos memory is tight. - */ } else if (iNum == LINK_CMD_RESTRICTIONS) { list lCMD = llParseString2List(sStr,["="],[]); if (llList2Integer(lCMD,2) > -1) ApplyCommand(llList2String(lCMD,0),llList2Integer(lCMD,1),kID,llList2Integer(lCMD,2)); } else if (iNum == LINK_CMD_RESTDATA) { list lCMD = llParseString2List(sStr, ["="], []); if (llList2String(lCMD,0) == "BlurAmount") { - integer bWasTrue = g_iRestrictions2 & (integer)(llPow(2,25)); + integer bWasTrue = g_iRestrictions2 & 1<<24; if (bWasTrue) ApplyCommand("Blur View",FALSE, NULL_KEY, 500); g_iBlurAmount = llList2Integer(lCMD,1); if (bWasTrue) ApplyCommand("Blur View",TRUE, NULL_KEY, 500); } else if (llList2String(lCMD,0) == "MaxCamDist") { - integer bWasTrue = g_iRestrictions2 & (integer)(llPow(2,26)); + integer bWasTrue = g_iRestrictions2 & 1<<25; if (bWasTrue) ApplyCommand("MaxDistance",FALSE, NULL_KEY, 500); g_fMaxCamDist = llList2Float(lCMD,1); if (bWasTrue) ApplyCommand("MaxDistance",TRUE, NULL_KEY, 500); } else if (llList2String(lCMD,0) == "MinCamDist") { - integer bWasTrue = g_iRestrictions2 & (integer)(llPow(2,27)); + integer bWasTrue = g_iRestrictions2 & 1<<26; if (bWasTrue) ApplyCommand("MinDistance",FALSE, NULL_KEY, 500); g_fMinCamDist = llList2Float(lCMD,1); if (bWasTrue) ApplyCommand("MinDistance",TRUE, NULL_KEY, 500);