Kogama Console

kogama console

  1. // ==UserScript==
  2. // @name Kogama Console
  3. // @run-at document-start
  4. // @version 0.1 alpha
  5. // @description kogama console
  6. // @author Exnonull
  7. // @match https://www.kogama.com/page/webgl-frame/*
  8. // @match https://kogama.com.br/page/webgl-frame/*
  9. // @match https://friends.kogama.com/page/webgl-frame/*
  10. // @grant none
  11. // @namespace https://greasyfork.org/users/668500
  12. // ==/UserScript==
  13.  
  14. /*sniffers*/
  15. WS_Original = WebSocket;
  16. WebSocket = function(url, type){
  17. let ws = new WS_Original(url, type);
  18. kcc.ws = ws;
  19.  
  20. ws._send = ws.send;
  21. ws.send = kcc.injectClient;
  22. kcc.logClient('injected client');
  23. function waitServer(e){
  24. kcc.injectServer(e);
  25. if(!this.editServer){
  26. this.removeEventListener('message', waitServer);
  27. this._msg = this.onmessage;
  28. this.onmessage = kcc.injectServer;
  29. }
  30. kcc.logServer('injected server');
  31. }
  32. ws.addEventListener('message', waitServer);
  33.  
  34. return ws;
  35. };
  36.  
  37. /*Utils*/
  38. Uint8Array.prototype.equals=
  39. Array.prototype.equals=function(array){
  40. if(!(array&&this.length==array.length))return false;
  41. for(var i=0,l=this.length;i<l;i++){
  42. if(this[i] instanceof Array&&array[i] instanceof Array){
  43. if(!this[i].equals(array[i]))return false;
  44. }else if(this[i]!=array[i]){return false;}
  45. }
  46. return true;
  47. }
  48. Object.defineProperty(window.Uint8Array.prototype,"equals",{enumerable:false});
  49. Object.defineProperty(window.Array.prototype,"equals",{enumerable:false});
  50. decode=d=>new TextDecoder().decode(d);
  51. encode=d=>new TextEncoder().encode(d);
  52. top.toByte16=toByte16=num=>new Uint8Array(new Uint16Array([num]).buffer).reverse();
  53. top.toNum16Sign=toNum16Sign=nums=>new Int16Array(new Uint8Array(nums).reverse().buffer)[0];
  54. top.toNum16=toNum16=nums=>new Uint16Array(new Uint8Array(nums).reverse().buffer)[0];
  55. top.unsign16=unsign16=num=>new Uint16Array([num])[0];
  56. top.toByte32=toByte32=num=>new Uint8Array(num?new Uint32Array([num]).buffer:[]).reverse();
  57. top.toNum32=toNum32=nums=>new Uint32Array(nums?new Uint8Array(nums).reverse().buffer:0)[0];
  58. getJSON=str=>{
  59. let pos=0,left=0,i=0,arr=[];
  60. while(i++<str.length){
  61. if(str[i]=='{'&&str[i+1]=='"'){
  62. if(!left)pos=i;
  63. left++;
  64. }
  65. if(str[i]=='}'){
  66. if(left>0){
  67. left--;
  68. if(!left)arr.push(str.slice(pos,i+1));
  69. }
  70. }
  71. }
  72. return arr.map(a=>JSON.parse(a));
  73. }
  74. top.format=format=str=>{//ff0011->[255,0,17]
  75. let rez=[];
  76. let n=0;
  77. for(let i=0;i<str.length;i++){
  78. rez.push(str[i]);
  79. if((i+2-n)%3==0){n+=2;rez.push(" ");}
  80. }
  81. rez.pop();
  82. return new Uint8Array(rez.join('').split(' ').map(n=>parseInt(n,16)))
  83. };
  84.  
  85. /*kogama console*/
  86. {
  87. window.html=top.html=id=>top.document.getElementById(id);
  88. window.make=top.make=tag=>top.document.createElement(tag);
  89. window.kc=top.kc={green:'#43B581',red:'#F04747',blue:'#72A9DA',
  90. cubegun:()=>{
  91. kcc.ws._send(new Uint8Array([
  92. 243,2,25,0,2,22,105,...toByte32(kcc.self),70,68,0,0,0,1,115,0,11,99,117,114,114,101,110,116,73,116,101,109,68,0,0,0,4,115,0,4,116,121,112,101,105,0,0,0,11,115,0,9,118,97,114,105,97,110,116,73,100,105,0,0,0,0,115,0,15,117,112,100,97,116,101,73,116,101,109,83,116,97,116,101,105,0,0,0,4,115,0,8,105,116,101,109,68,97,116,97,68,0,0,0,1,115,0,8,109,97,116,101,114,105,97,108,98,20
  93. ]));
  94. kcc.ws._msg({data:new Uint8Array([
  95. 243,4,29,0,3,22,105,...toByte32(kcc.self),70,68,0,0,0,1,115,0,11,99,117,114,114,101,110,116,73,116,101,109,68,0,0,0,4,115,0,4,116,121,112,101,105,0,0,0,11,115,0,9,118,97,114,105,97,110,116,73,100,105,0,0,0,0,115,0,15,117,112,100,97,116,101,73,116,101,109,83,116,97,116,101,105,0,0,0,4,115,0,8,105,116,101,109,68,97,116,97,68,0,0,0,1,115,0,8,109,97,116,101,114,105,97,108,98,20,254,105,0,0,0,0
  96. ]).buffer});
  97. },
  98. action:(actionId,PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,2,27,0,2,22,105,...toByte32(PID),83,68,0,0,0,1,98,0,120,0,0,0,2,1,actionId])),
  99. freeze:(PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,2,27,0,2,22,105,...toByte32(PID),83,68,0,0,0,1,98,0,120,0,0,0,2,1,11])),
  100. damadge:(PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,2,27,0,2,22,105,...toByte32(PID),83,68,0,0,0,1,98,0,120,0,0,0,2,1,10])),
  101. heal:(PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,2,27,0,2,22,105,...toByte32(PID),83,68,0,0,0,1,98,0,120,0,0,0,2,1,27])),
  102. big:(PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,2,27,0,2,22,105,...toByte32(PID),83,68,0,0,0,1,98,0,120,0,0,0,2,1,17])),
  103. small:(PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,2,27,0,2,22,105,...toByte32(PID),83,68,0,0,0,1,98,0,120,0,0,0,2,1,16])),
  104. mutant_kill:(PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,2,27,0,2,22,105,...toByte32(PID),83,68,0,0,0,1,98,0,120,0,0,0,2,1,6])),
  105. rail_kill:(PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,2,27,0,2,22,105,...toByte32(PID),83,68,0,0,0,1,98,0,120,0,0,0,2,1,4])),
  106. invisible:(PID=kcc.self)=>kcc.ws.send(new Uint8Array([243,4,2,0,8,22,105,0,3,...toByte32(PID),70,68,0,0,0,1,115,0,17,115,112,97,119,110,82,111,108,101,77,111,100,101,84,121,112,101,105,0,0,0,4])),
  107. finish:()=>kcc.ws.send(new Uint8Array([243,2,23,0,1,191,105,0,3,0,0])),
  108. log:(msg,clr='#FFF')=>{
  109. if(html('console_log').lastChild&&msg==html('console_log').lastChild.textContent){
  110. let counter=html('console_log').lastChild.children[0];
  111. if(counter){
  112. counter.value=1+Number(counter.value);
  113. }else{
  114. counter=make('input');
  115. counter.style=`height:20px;width:20px;
  116. text-align:center;padding:0px;
  117. background:${kc.green};color:#FFFA;
  118. border:none;border-radius:100%;cursor:default;`;
  119. counter.value=2;
  120. counter.disabled=true;
  121. html('console_log').lastChild.appendChild(counter)
  122. }
  123. return;
  124. }
  125. let scroll=html('console_log').scrollTop/(html('console_log').scrollHeight-html('console_log').offsetHeight);
  126. if(isNaN(scroll)||scroll>0.9)scroll=true;
  127. else scroll=false;
  128. let el=make('div');
  129. el.style='padding:2% 1% 0px 2%;width:100%;color:'+clr+';';
  130. el.textContent=msg;
  131. html('console_log').appendChild(el);
  132. if(scroll)html('console_log').scrollTop=html('console_log').scrollHeight-html('console_log').offsetHeight;
  133. },
  134. command:str=>{
  135. kc.log(str,'#FFF8');
  136. }
  137. };
  138. window.makeCheat=top.makeCheat=(name='unknown',clr='#888',func=()=>{})=>{
  139. let el=make('input');
  140. el.id=name;
  141. el.value=name;
  142. el.className='cheat_element';
  143. el.type='button';
  144. el.style=`color:${clr};background-color:#4f545c;border-radius:10px;border:none;padding:2px;`;
  145. el.addEventListener('click',func);
  146. html('cheat_box').appendChild(el);
  147. };
  148. window.addBB=top.addBB=(name='unknown',id='unknown',box='unknown_box',choosen=0)=>{
  149. let el=make('div');
  150. el.id=box;
  151. el.style=`
  152. position:absolute;
  153. display:${choosen?'block':'none'};
  154. width:75%;height:90%;
  155. top:10%;
  156. right:0px;
  157. `;
  158. html('console').appendChild(el);
  159. el=make('div');
  160. el.id='console_bar_'+id;
  161. el.className='bar_element bar_element_'+(choosen?'on':'off');
  162. el.textContent=name;
  163. el.addEventListener('click',function(e){
  164. if(this!=html('console_bar').cur){
  165. html(box).style.display='block';
  166. html('console').cur.style.display='none';
  167. html('console').cur=html(box);
  168. this.className='bar_element bar_element_on';
  169. html('console_bar').cur.className='bar_element bar_element_off';
  170. html('console_bar').cur=this;
  171. }
  172. });
  173. html('console_bar').appendChild(el);
  174. };
  175. var sheet=top.document.head.appendChild(make('style')).sheet;
  176. sheet.insertRules=rules=>rules.replace(/\}/g,'}^').split('^').map(r=>(r.indexOf('{')+1)&&sheet.insertRule(r));
  177. sheet.insertRules(`
  178. .scroller{overflow-y:auto;}
  179. .scroller::-webkit-scrollbar{
  180. width:10px;
  181. }
  182. .scroller::-webkit-scrollbar-thumb{
  183. background-color:rgba(0,0,0,.4);
  184. -webkit-box-shadow:inset 0 0 2px rgba(0,0,0,.5);
  185. box-shadow:inset 0 0 2px rgba(0,0,0,.5);
  186. }
  187. .scroller::-webkit-scrollbar-track{
  188. background-color:rgba(0,0,0,.3);
  189. }
  190. .scroller::-webkit-scrollbar-thumb{
  191. background:#000;
  192. }
  193. .bar_element:hover{
  194. opacity:0.9;
  195. background:#40444bAA;
  196. transition-duration: 0.3s;
  197. }
  198. .bar_element{
  199. color:#FFF;
  200. line-height: 200%;
  201. cursor:pointer;
  202. height:10%;
  203. width:100%;
  204. }
  205. .cheat_element:hover{
  206. color:#FFF !important;
  207. }
  208. .bar_element_off{
  209. opacity:0.5;
  210. background:#0000;
  211. }
  212. .bar_element_on{
  213. opacity:1;
  214. background:#40444b;
  215. }
  216. `);
  217. let el=make('div');
  218. top.document.body.appendChild(el);
  219. el.id='console';
  220. el.style=`
  221. position:fixed;
  222. display:none;
  223. z-index:9999;
  224. background-color:#36393f;
  225. text-align:center;
  226. border-radius:10px;
  227. border:3px #36393F solid;
  228. `;
  229. top.addEventListener('resize',function(){
  230. html('console').style.width=top.outerWidth*0.35+'px';
  231. html('console').style.height=top.outerHeight*0.35+'px';
  232. });
  233. top.dispatchEvent(new Event('resize'));
  234. top.document.addEventListener('mouseup',e=>{
  235. if(html('console').movement){
  236. html('console').movement=false;
  237. e.preventDefault();
  238. e.stopPropagation();
  239. }
  240. })
  241. top.document.addEventListener('mousemove',e=>{
  242. if(html('console').movement){
  243. html('console').style.left=(html('console').startPos.x+e.x-html('console').startPos.mx)+'px';
  244. html('console').style.top=(html('console').startPos.y+e.y-html('console').startPos.my)+'px';
  245. if(html('console').offsetTop<0)html('console').style.top='0px';
  246. e.preventDefault();
  247. e.stopPropagation();
  248. }
  249. });
  250. top.document.addEventListener('contextmenu', e=>{
  251. if(e.target==top.document.querySelector('#profile-extended-toggle>a>i')){
  252. html('console').style.display='block';
  253. e.preventDefault();
  254. }
  255. });
  256. el=make('div');
  257. el.id='console_head';
  258. el.innerHTML='KoGaMa Cheat Console by Exnonull';
  259. el.style=`
  260. width:100%;height:10%;
  261. background-color:#202225;
  262. cursor:default;
  263. border-top-left-radius:10px;
  264. border-top-right-radius:10px;
  265. `;
  266. html('console').appendChild(el);
  267. html('console_head').addEventListener('mousedown',e=>{
  268. html('console').movement=true;
  269. html('console').startPos={x:html('console').offsetLeft,y:html('console').offsetTop,mx:e.x,my:e.y};
  270. e.preventDefault();
  271. e.stopPropagation();
  272. });
  273. el=make('input');
  274. el.id='console_close';
  275. el.type='button';
  276. el.value='X';
  277. el.style=`
  278. position:absolute;
  279. height:10%;width:10%;
  280. right:0px;
  281. background-color:${kc.red};
  282. color:#FFF;line-height:0.5;
  283. border:none;
  284. border-top-right-radius:10px;
  285. `;
  286. html('console_head').appendChild(el);
  287. html('console_close').addEventListener('mousedown',e=>{
  288. if(e.which==1){
  289. pos={x:html('console').offsetLeft,y:html('console').offsetTop};
  290. html('console').style.display='none';
  291. html('console').style.left=pos.x+'px';
  292. html('console').style.top=pos.y+'px';
  293. }
  294. e.preventDefault();
  295. e.stopPropagation();
  296. });
  297. el=make('div');
  298. el.id='console_bar';
  299. el.style=`
  300. position:absolute;
  301. top:10%;left:0px;
  302. width:25%;height:90%;
  303. background-color:#2f3136;
  304. `;
  305. html('console').appendChild(el);
  306.  
  307. addBB('Console','console','console_box',1);
  308. html('console').appendChild(el);
  309. el=make('input');
  310. el.id='console_input';
  311. el.placeholder='Enter command...';
  312. el.style=`
  313. position:absolute;
  314. width:95%;height:10%;
  315. bottom:2.5%;right:2.5%;
  316. background-color:#4f545c;
  317. border:none;color:#FFF8;
  318. border-radius:15px;
  319. text-align:center;
  320. cursor:text;
  321. `;
  322. html('console_box').appendChild(el);
  323. html('console_input').index=-1;
  324. html('console_input').old=[];
  325. html('console_input').addEventListener('keydown',function(e){
  326. switch(e.keyCode){
  327. case 13:
  328. if(this.value){
  329. kc.command(this.value);
  330. if(this.old[this.old.length-1]!=this.value)this.old.push(this.value);
  331. if(this.old>30)this.old.splice(0,1);
  332. this.was=undefined;
  333. this.index=this.old.length;
  334. this.value='';
  335. }
  336. break;
  337. case 38://up
  338. this.index-=2;
  339. case 40://down
  340. this.index++;
  341. if(this.index>this.old.length-1)this.index=this.old.length;
  342. if(this.index<0)this.index=0;
  343. if(this.index>this.old.length-1){
  344. if(this.was!==undefined)this.value=this.was;
  345. this.was=undefined;
  346. }else{
  347. if(this.was===undefined)this.was=this.value;
  348. this.value=this.old[this.index];
  349. }
  350. break;
  351. }
  352. });
  353. el=make('div');
  354. el.id='console_log';
  355. el.className='scroller';
  356. el.style=`
  357. position:absolute;
  358. text-align:left;
  359. width:100%;height:85%;
  360. word-break:break-all;
  361. `;
  362. html('console_box').appendChild(el);
  363.  
  364. html('console').cur=html('console_box');
  365. html('console_bar').cur=html('console_bar_console');
  366.  
  367. addBB('Cheat List','list','cheat_box');
  368. html('cheat_box').className='scroller';
  369. makeCheat('finish',kc.blue,()=>kc.finish());
  370. makeCheat('mutant kill',kc.red,()=>Object.keys(kcc.names).map(n=>kcc.self!=kcc.names[n]&&kc.mutant_kill(kcc.names[n])));
  371. makeCheat('rail kill',kc.red,()=>Object.keys(kcc.names).map(n=>kcc.self!=kcc.names[n]&&kc.rail_kill(kcc.names[n])));
  372. makeCheat('autodamadge',kc.red,()=>{
  373. if(kc.idDamadge){clearInterval(kc.idDamadge);kc.idDamadge=0;}
  374. else kc.idDamadge=setInterval(()=>Object.keys(kcc.names).map(n=>kc.damadge(kcc.names[n])),5e2);
  375. });
  376. makeCheat('autofreeze',kc.green,()=>{
  377. if(kc.idFreeze){clearInterval(kc.idFreeze);kc.idFreeze=0;}
  378. else kc.idFreeze=setInterval(()=>Object.keys(kcc.names).map(n=>kc.freeze(kcc.names[n])),5e2);
  379. });
  380. makeCheat('autoheal',kc.green,()=>{
  381. if(kc.idHeal){clearInterval(kc.idHeal);kc.idHeal=0;}
  382. else kc.idHeal=setInterval(()=>Object.keys(kcc.names).map(n=>kc.heal(kcc.names[n])),2e2);
  383. });
  384. makeCheat('autobig',kc.green,()=>{
  385. if(kc.idBig){clearInterval(kc.idBig);kc.idBig=0;}
  386. else kc.idBig=setInterval(()=>Object.keys(kcc.names).map(n=>kc.big(kcc.names[n])),5e2);
  387. });
  388. makeCheat('autosmall',kc.green,()=>{
  389. if(kc.idSmall){clearInterval(kc.idSmall);kc.idSmall=0;}
  390. else kc.idSmall=setInterval(()=>Object.keys(kcc.names).map(n=>kc.small(kcc.names[n])),5e2);
  391. });
  392. makeCheat('heal',kc.green,()=>kc.heal());
  393. document.addEventListener('keydown',e=>{
  394. switch(e.key){
  395. case '`':
  396. kc.cubegun();
  397. break;
  398. case '-':
  399. kc.small();
  400. break;
  401. case '+':
  402. kc.big();
  403. break;
  404. }
  405. });
  406. makeCheat('big',kc.green,()=>kc.big());
  407. makeCheat('small',kc.green,()=>kc.small());
  408. makeCheat('cubegun',kc.blue,()=>kc.cubegun());
  409. makeCheat('cubenormal',kc.blue,()=>kcc.cubeMode=0);
  410. makeCheat('cubeplane',kc.blue,()=>kcc.cubeMode=1);
  411. makeCheat('cubegiant',kc.blue,()=>kcc.cubeMode=2);
  412. makeCheat('cuberoom',kc.blue,()=>kcc.cubeMode=3);
  413. makeCheat('cubexm',kc.blue,()=>kcc.cubeMode=4);
  414. makeCheat('cubexp',kc.blue,()=>kcc.cubeMode=5);
  415. makeCheat('cubezm',kc.blue,()=>kcc.cubeMode=6);
  416. makeCheat('cubezp',kc.blue,()=>kcc.cubeMode=7);
  417. makeCheat('normal',kc.blue,()=>kcc.cubeId=0);
  418. makeCheat('superbounce',kc.blue,()=>kcc.cubeId=kcc.superbounce);
  419. makeCheat('ice',kc.blue,()=>kcc.cubeId=kcc.ice);
  420. makeCheat('poison',kc.blue,()=>kcc.cubeId=kcc.poison);
  421. makeCheat('magma',kc.blue,()=>kcc.cubeId=kcc.magma);
  422. makeCheat('bounce',kc.blue,()=>kcc.cubeId=kcc.bounce);
  423. makeCheat('blackice',kc.blue,()=>kcc.cubeId=kcc.blackice);
  424. }
  425.  
  426. /*Kogama Cheat Client*/
  427. window.kcc=top.kcc={
  428. ws:{},
  429. self:0,
  430. pos:[0,0,0],
  431. names:{},
  432. parts:[],
  433. cubeSize:4,
  434. cubeD:1812,
  435. superbounce:1846,
  436. poison:1820,
  437. blackice:1835,
  438. ice:1817,
  439. magma:1818,
  440. bounce:1819,
  441. cubeId:0,
  442. cubeXZ:10,
  443. roomSize:4,
  444. cubeMode:0,
  445. cubeWay:50,
  446. cubeServer:(randomId=kcc.self,x=0,y=0,z=0,material)=>new Uint8Array([243,4,10,0,3,47,105,...toByte32(randomId),49,120,0,0,0,...(material?[9,2]:[7,0]),...toByte16(x),...toByte16(y),...toByte16(z),...(material?toByte16(material):[]),254,105,0,0,0,material?3:1]),
  447. cube:(randomId=kcc.self,x=0,y=0,z=0,material)=>new Uint8Array([243,2,7,0,2,47,105,...toByte32(randomId),49,120,0,0,0,...(material?[9,2]:[7,0]),...toByte16(x),...toByte16(y),...toByte16(z),...(material?toByte16(material):[])]),
  448. logClient:(msg,...items)=>{
  449. console.log.apply(console,['%c'+msg,"background-color:#0808;",...items]);
  450. },
  451. logServer:(msg,...items)=>{
  452. console.log.apply(console,['%c'+msg,"background-color:#F808;",...items]);
  453. },
  454. injectClient:function(data){
  455. data = new Uint8Array(data);
  456. data = kcc.separator(data);
  457. if(data)this._send(data);
  458. },
  459. injectServer:function(e){
  460. let data = new Uint8Array(e.data);
  461. if(this != kcc.ws){
  462. kcc.logServer(`wait injection: [${data.toString()}]`);
  463. return;
  464. }
  465. data = kcc.separator(data);
  466. if(data)this._msg({data:data.buffer});
  467. }
  468. };
  469.  
  470. /*requests separating*/
  471. kcc.no_sense=data=>{
  472. if(data.length<7)return true;//not action
  473. return false;
  474. /*
  475. if(data.equals([243,4,81,0,0])){//each tick
  476. //kcc.logServer('short_ping');
  477. return true;
  478. }else if(data.equals([243,2,58,0,0])){//1 time
  479. //kcc.logClient('short_ping(1)');
  480. return true;
  481. }else if(data.equals([243,2,102,0,0])){//1 time
  482. //kcc.logClient('short_ping(2)');
  483. return true;
  484. }else if(data.equals([243,2,95,0,0])){//1 time
  485. //kcc.logClient('short_ping(3)');//build->game, once
  486. return true;
  487. }else if(data.equals([243,1,0])){//1 time
  488. kcc.logServer('open connection');
  489. return true;
  490. }
  491. */
  492. }
  493.  
  494. kcc.separator=data=>{
  495. if(kcc.no_sense(data))return data;
  496.  
  497. head = data.slice(0,7);//[243, (client:2|6, server:4|7), actionId(u32), 105]
  498. reqId = head.slice(2,6);
  499. /*
  500. 2,6 - client
  501. 4,7 - server
  502. */
  503. source = (head[1]==2||head[1]==6)?"client":"server";
  504.  
  505. return new Uint8Array([...head, ...kcc[source+"Separator"](toNum32(reqId), data.slice(7))]);
  506. }
  507.  
  508. kcc.clientSeparator=(reqId,data)=>{
  509. switch(reqId){
  510. case 117441071://[7,0,2,47] 26->19 bytes
  511. let id=toNum32(data.slice(0,4));
  512. let material=toNum16(data.slice(17,19));
  513. let x=toNum16Sign(data.slice(11,13));
  514. let y=toNum16Sign(data.slice(13,15));
  515. let z=toNum16Sign(data.slice(15,17));
  516. //kc.log(`cubegun:{id:${id},x:${x},y:${y},z:${z},material:${material}}`,'#080');
  517. if(kcc.cubeMode){
  518. let arr=[];
  519. if(kcc.cubeMode==1){//plane
  520. for(let i=x-kcc.cubeXZ;i<=x+kcc.cubeXZ;i++)
  521. for(let i2=y-1;i2<=y-1;i2++)
  522. for(let i3=z-kcc.cubeXZ;i3<=z+kcc.cubeXZ;i3++){
  523. arr.push({x:unsign16(i),y:unsign16(i2),z:unsign16(i3)});
  524. }
  525. }else if(kcc.cubeMode==2){//giant
  526. for(let i=x-kcc.cubeSize;i<=x+kcc.cubeSize;i++)
  527. for(let i2=y-kcc.cubeSize;i2<=y+kcc.cubeSize;i2++)
  528. for(let i3=z-kcc.cubeSize;i3<=z+kcc.cubeSize;i3++){
  529. arr.push({x:unsign16(i),y:unsign16(i2),z:unsign16(i3)});
  530. }
  531. }else if(kcc.cubeMode==3){//room
  532. for(let i=x-kcc.roomSize;i<=x+kcc.roomSize;i++)
  533. for(let i2=y-1;i2<=y+kcc.roomSize*2-1;i2++)
  534. for(let i3=z-kcc.roomSize;i3<=z+kcc.roomSize;i3++){
  535. if(i==x-kcc.roomSize||i==x+kcc.roomSize||
  536. i2==y+kcc.roomSize*2-1||i2==y-1||
  537. i3==z-kcc.roomSize||i3==z+kcc.roomSize){
  538. arr.push({x:unsign16(i),y:unsign16(i2),z:unsign16(i3)});
  539. }
  540. }
  541. }else if(kcc.cubeMode==4){//xm
  542. for(let i=x-kcc.cubeWay;i<=x;i++)
  543. for(let i2=y-1;i2<=y-1;i2++)
  544. for(let i3=z-2;i3<=z+2;i3++){
  545. arr.push({x:unsign16(i),y:unsign16(i2),z:unsign16(i3)});
  546. }
  547. }else if(kcc.cubeMode==5){//xp
  548. for(let i=x;i<=x+kcc.cubeWay;i++)
  549. for(let i2=y-1;i2<=y-1;i2++)
  550. for(let i3=z-2;i3<=z+2;i3++){
  551. arr.push({x:unsign16(i),y:unsign16(i2),z:unsign16(i3)});
  552. }
  553. }else if(kcc.cubeMode==6){//zm
  554. for(let i=x-2;i<=x+2;i++)
  555. for(let i2=y-1;i2<=y-1;i2++)
  556. for(let i3=z-kcc.cubeWay;i3<=z;i3++){
  557. arr.push({x:unsign16(i),y:unsign16(i2),z:unsign16(i3)});
  558. }
  559. }else if(kcc.cubeMode==7){//zp
  560. for(let i=x-2;i<=x+2;i++)
  561. for(let i2=y-1;i2<=y-1;i2++)
  562. for(let i3=z;i3<=z+kcc.cubeWay;i3++){
  563. arr.push({x:unsign16(i),y:unsign16(i2),z:unsign16(i3)});
  564. }
  565. }
  566. arr.map((pos,i)=>{
  567. kcc.ws._msg({data:kcc.cubeServer(id,pos.x,pos.y,pos.z,kcc.cubeId?kcc.cubeId:material).buffer});
  568. kcc.ws._send(kcc.cube(id,pos.x,pos.y,pos.z,kcc.cubeId?kcc.cubeId:material));
  569. });
  570. }
  571. break;
  572. case 33556246://[2,0,7,22], 47->40 bytes
  573. //kc.log('moving','#080');
  574. //let PID=data.slice(0,4);//36 bytes
  575. kcc.pos=data.slice(4);
  576.  
  577. break;
  578. case 16777473://[1,0,1,1]
  579. //kcc.logClient('ping time');//(11)
  580. break;
  581. case 4278192982://toNum32([255,0,11,86]):
  582. kc.log('login','#080');
  583. break;
  584. case 1040188095://toNum32([62,0,2,191]):
  585. kc.log('[image part]','#080');
  586. break;
  587. case 385876415://toNum32([23,0,1,191]):
  588. kc.log('finish','#080');
  589. break;
  590. case 419430934://toNum32([25,0,2,22]):
  591. //kcc.self=toNum32(data.slice(0,4));
  592. break;
  593. case 654311702://toNum32([39,0,1,22]):
  594. //kcc.logClient('add model to inventory');
  595. break;
  596. case 738198312://toNum32([44,0,3,40]):
  597. //kcc.logClient('push model to the marketplace');
  598. break;
  599. case 218104104://toNum32([13,0,1,40]):
  600. //kcc.logClient('delete model from inventory');
  601. break;
  602. case 452985366://toNum32([27,0,2,22]):
  603. //kcc.logClient('use effect on player');
  604. break;
  605. }
  606. return data;
  607. }
  608. kcc.serverSeparator=(reqId,data)=>{
  609. //server:243,4,10,0,3,47,105,...toByte32(randomId),49,120,0,0,0,9,2,...toNum16(x),...toNum16(y),...toNum16(z),7,material,254,105,0,0,0,3
  610.  
  611. //client:243,2,7,0,2,47,105, 0,0,5,196,49,120,0,0,0,9,2,255,211,0,4,255,225
  612. // 243,4,10,0,3,47,105,0,0,5,207,49,120,0,0,0,7,0,255,229,0,4,255,213,254,105,0,0,0,1
  613.  
  614. //243,4,86,0,5,220,105,0,0,41,254,219,98,2,209,105,0,0,0,0,85,105,0,0,0,10,254,105,0,0,0,1
  615. switch(reqId){
  616. case toNum32([10,0,3,47])://case toNum32([86,0,5,220]):
  617. //kc.log('cubegun another');
  618. break;
  619. case toNum32([1,0,0,42]):
  620. //kcc.logServer('ping time');//(20)
  621. break;
  622. case toNum32([255,0,6,89]):
  623. {
  624. top.keks=top.keks?top.keks:[];
  625. let info=getJSON(decode(data))[0];
  626. top.keks.push(info);
  627. //kc.log(`[${info.UserName}]->joining`,'#F80');
  628. kcc.parts.push(info.UserName);
  629. }
  630. break;
  631. case toNum32([104,0,2,245]):
  632. {
  633. top.keks=top.keks?top.keks:[];
  634. let info=getJSON(decode(data))[0];
  635. top.keks.push(info);
  636. let pid=info.SpawnRolesRuntimeData.activeSpawnRole;//.spawnRoleAvatarIds[0];
  637. let name=kcc.parts.pop();
  638. kc.log(`[${name},${pid}]->joined`,'#F80');
  639. kcc.names[name]=pid;
  640. }
  641. break;
  642. case toNum32([102,0,10,245]):case toNum32([61,0,10,245]):
  643. {
  644. kc.log('joined','#F80');
  645. let info=getJSON(decode(data));
  646. top.kek=info;
  647. kcc.self=info[info.length-1].spawnRolesDefaultTypeWoIDMap;
  648. kcc.self=kcc.self?kcc.self.DefaultPlayModeSpawnRole:info[info.length-1].DefaultPlayModeSpawnRole;
  649. info=info.slice(1,info.length-1);
  650. for(let k=0;k<info.length;k+=3){
  651. kcc.names[info[k].UserName]=info[k+2].activeSpawnRole;
  652. }
  653. kc.log(`Player List:${JSON.stringify(kcc.names)}`,'#F80');
  654. }
  655. break;
  656. case toNum32([6,0,11,22]):
  657. {
  658. let id=toNum32(data.slice(0,4))-1;
  659. for(let k in kcc.names)if(kcc.names[k]==id){
  660. kc.log(`[${k},${id}]->left`,'#F80');
  661. delete kcc.names[k];break;
  662. }
  663. }
  664. break;
  665. }
  666. return data;
  667. }