🏠 Home 

Barclay's Library

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

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