Barclay's Library

Import whatever model URLs you need - library that does the heavy lifting

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greatest.deepsurf.us/scripts/526336/1540964/Barclay%27s%20Library.js

  1. // ==UserScript==
  2. // @name Barclay's Library
  3. // @namespace https://github.com/onlypuppy7/BarclaysShellShockers/
  4. // @grant none
  5. // @version 1.1.2
  6. // @author onlypuppy7
  7. // @description Import whatever model URLs you need - library that does the heavy lifting
  8. // @match *://*/*
  9. // ==/UserScript==
  10.  
  11. //this library is based off LibertyMutual by onlypuppy7
  12.  
  13. const BARCLAYS = {
  14. modelURLs: [],
  15. ss: null,
  16. H: {},
  17. log: function (...args) { //yeah, i got inspired. what about it?
  18. console.log(
  19. "%c%s",
  20. `color: white; font-weight: bold; background:rgb(0, 85, 128); padding: 2px 6px; border-radius: 5px; margin-right: 5px;`,
  21. `Barclay's`,
  22. ...args
  23. );
  24. },
  25. init: function () { //setup the script injection. separated out to enable users to put the injection code into their own scripts with different loading mechanisms.
  26. let originalReplace = String.prototype.replace;
  27. String.prototype.originalReplace = function() {
  28. return originalReplace.apply(this, arguments);
  29. };
  30.  
  31. const originalXHROpen = XMLHttpRequest.prototype.open;
  32. const originalXHRGetResponse = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, 'response');
  33. let shellshockjs
  34. XMLHttpRequest.prototype.open = function(...args) {
  35. const url = args[1];
  36. if (url && url.includes("js/shellshock.js")) {
  37. shellshockjs = this;
  38. };
  39. originalXHROpen.apply(this, args);
  40. };
  41. Object.defineProperty(XMLHttpRequest.prototype, 'response', {
  42. get: function() {
  43. if (this===shellshockjs) {
  44. BARCLAYS.log("shellshock.js intercepted");
  45. return BARCLAYS.applyBarclays(originalXHRGetResponse.get.call(this));
  46. };
  47. return originalXHRGetResponse.get.call(this);
  48. }
  49. });
  50. },
  51. applyBarclays: function (js) {
  52. try {
  53. //VAR STUFF
  54. let F=[];
  55. let functionNames=[];
  56. //scrambled... geddit????
  57. const getScrambled=function(){return Array.from({length: 10}, () => String.fromCharCode(97 + Math.floor(Math.random() * 26))).join('')}
  58. const createAnonFunction=function(name,func){
  59. const funcName=getScrambled();
  60. window[funcName]=func;
  61. F[name]=window[funcName];
  62. functionNames[name]=funcName
  63. };
  64. const fetchTextContent = function(url) {
  65. var xhr = new XMLHttpRequest();
  66. xhr.open('GET', url, false); // make the request synchronous
  67. xhr.send();
  68. if (xhr.status === 200) {
  69. return xhr.responseText;
  70. } else {
  71. console.error("Error fetching text content. Status:", xhr.status);
  72. return null;
  73. };
  74. };
  75. createAnonFunction("BARCLAYS", function(ss) {
  76. BARCLAYS.log("BARCLAYS ACTIVE!");
  77. BARCLAYS.ss = ss;
  78. // window.globalBarclays = ss;
  79. BARCLAYS.replaceModels();
  80. });
  81. let clientKeys;
  82. onlineClientKeys = fetchTextContent("https://raw.githubusercontent.com/StateFarmNetwork/client-keys/main/barclays_latest.json"); //credit: me :D
  83. if (onlineClientKeys == "value_undefined" || onlineClientKeys == null) {
  84. let userInput = prompt('Valid keys could not be retrieved online. Enter keys if you have them. Join the SFNetwork Discord server to generate keys! https://discord.gg/HYJG3jXVJF', '');
  85. if (userInput !== null && userInput !== '') {
  86. alert('Aight, let\'s try this. If it is invalid, it will just crash.');
  87. clientKeys = JSON.parse(userInput);
  88. } else {
  89. alert('You did not enter anything, this is gonna crash lmao.');
  90. };
  91. } else {
  92. clientKeys = JSON.parse(onlineClientKeys);
  93. };
  94. BARCLAYS.H = clientKeys.vars;
  95. BARCLAYS.log(BARCLAYS.H);
  96. let injectionString="";
  97. const modifyJS = function(find,replace) {
  98. let oldJS = js;
  99. js = js.originalReplace(find,replace);
  100. if (oldJS !== js) {
  101. console.log("%c[BARCLAYS] Replacement successful! Injected code: "+replace, 'color: green; font-weight: bold; font-size: 0.6em; text-decoration: italic;');
  102. } else {
  103. console.log("%c[BARCLAYS] Replacement failed! Attempted to replace "+find+" with: "+replace, 'color: red; font-weight: bold; font-size: 0.6em; text-decoration: italic;');
  104. };
  105. };
  106. BARCLAYS.log('%c[BARCLAYS] ATTEMPTING TO START BARCLAYS', 'color: magenta; font-weight: bold; font-size: 1.5em; text-decoration: underline;');
  107. const variableNameRegex = /^[a-zA-Z0-9_$,"]*$/; //prevent adding spooky code
  108. for (let name in BARCLAYS.H) {
  109. deobf = BARCLAYS.H[name];
  110. if (variableNameRegex.test(deobf)) {
  111. injectionString = `${injectionString}${name}: (() => { try { return ${deobf}; } catch (error) { return "value_undefined"; } })(),`;
  112. } else {
  113. alert("Message from the Barclays Devs: WARNING! The keys inputted contain non-variable characters! There is a possibility that this could run code unintended by the Barclays team, although possibly there is also a mistake. Do NOT proceed with using this, and report to the Barclays developers what is printed in the console.");
  114. BARCLAYS.log("REPORT THIS IN THE DISCORD SERVER:", clientKeys);
  115. const crashplease = "balls";
  116. crashplease = "balls2";
  117. };
  118. };
  119. BARCLAYS.log("Barclay's injectionString:", injectionString);
  120. modifyJS(`"Object meshes loaded"),`, `"Object meshes loaded"),window["${functionNames.BARCLAYS}"]({${injectionString}}),`);
  121. // BARCLAYS.log(js);
  122. return js;
  123. } catch (error) {
  124. console.error("Error applying Barclay's:", error);
  125. return js;
  126. };
  127. },
  128. replaceModels: function (modelURLs = BARCLAYS.modelURLs, noLog = false) {
  129. //you can call this function later if you want to replace models again
  130. //if you need to reinstate the original models, you will need to pass in the original mesh URLs
  131. //eg: /models/full/egg.glb
  132.  
  133. function replaceMesh(sourceMesh, targetMesh) {
  134. if (sourceMesh && targetMesh) {
  135. const vertexData = BARCLAYS.ss.VertexData.ExtractFromMesh(sourceMesh);
  136. vertexData.applyToMesh(targetMesh);
  137. if (!noLog) BARCLAYS.log("Mesh geometry replaced successfully!", sourceMesh.id);
  138. } else {
  139. console.error("One of the meshes was not found!");
  140. };
  141. };
  142.  
  143. BARCLAYS.log("Preparing to replace models...", modelURLs);
  144. modelURLs.forEach(function(url) {
  145. BARCLAYS.log("Loading model from URL:", url);
  146. BARCLAYS.ss.SceneLoader.ImportMesh(
  147. "", // Empty string imports all meshes
  148. "", // Empty root URL uses the path provided
  149. url, // Path to GLB file
  150. undefined, // Scene to import into
  151. function (meshes, particleSystems, skeletons, animationGroups) {
  152. BARCLAYS.log(
  153. "meshes loaded:",
  154. meshes
  155. .filter(mesh => mesh.id !== "__root__")
  156. .map(mesh => mesh.id)
  157. );
  158. console.log("particleSystems loaded:", particleSystems);
  159. console.log("skeletons loaded:", skeletons);
  160. console.log("animationGroups loaded:", animationGroups);
  161.  
  162. for (var m = 0; m < meshes.length; m++) {
  163. var mesh2 = meshes[m];
  164. if (mesh2.id !== "__root__") {
  165. mesh2.setEnabled(false);
  166. mesh2.isPickable = false;
  167. mesh2.animations = animationGroups;
  168. let meshInGlobalScene = BARCLAYS.ss.globalScene.getMeshByID(mesh2.id);
  169. if (meshInGlobalScene) {
  170. replaceMesh(mesh2, meshInGlobalScene);
  171. mesh2.animations.forEach((anim, index) => {
  172. let animName = anim.name;
  173. let animInGlobalScene = meshInGlobalScene.getAnimationByName(animName);
  174. if (animInGlobalScene) {
  175. let tempTargeted = anim._targetedAnimations;
  176. tempTargeted.forEach((targeted, index) => {
  177. tempTargeted[index].target = targeted.target;
  178. });
  179. animInGlobalScene._targetedAnimations = tempTargeted;
  180. BARCLAYS.log(`Animation ${index + 1} (${animName}) replaced successfully!`);
  181. };
  182. });
  183. };
  184.  
  185. mesh2.dispose(false, true);
  186. };
  187. };
  188.  
  189. BARCLAYS.log("Meshes replaced successfully!");
  190. },
  191. );
  192. });
  193. },
  194. restoreModels: function () {
  195. BARCLAYS.log("Restoring models...");
  196.  
  197. const models = BARCLAYS.H.meshesToLoad.split(",");
  198.  
  199. //add /models/full/ to the start of each model
  200. const modelURLs = models.map(model => `/models/full/${model.replaceAll('"','')}.glb`);
  201.  
  202. modelURLs.push("/models/map.glb"); //add the map back in, as it's not in full
  203.  
  204. BARCLAYS.replaceModels(modelURLs, true);
  205. },
  206. };
  207.  
  208. BARCLAYS.log("Barclay's Library loaded. Built by onlypuppy7 :>");