alexop1000

typescript

Jan 25th, 2021
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* eslint-disable roblox-ts/no-any */
  2. import { ReplicatedStorage } from "@rbxts/services";
  3.  
  4. function upper(STRING: string) {
  5.     return STRING.upper();
  6. }
  7. type gunData = {
  8.     rarities: {};
  9. };
  10. interface tableData {
  11.     [key: string]: [];
  12. }
  13.  
  14. const base64 = (require(ReplicatedStorage.FindFirstChild("Modules")?.FindFirstChild(
  15.     "base64",
  16. ) as ModuleScript) as unknown) as { decode: Function };
  17.  
  18. export function fixgundata(DATA: Array<string>, PLAYER: Player) {
  19.     const GUNS = game.GetService("ReplicatedStorage").WaitForChild("Guns");
  20.     const UNPACKED = new Array(0);
  21.     for (const [ID, STRING] of pairs(DATA)) {
  22.         let gunName = "",
  23.             gunRarity = "",
  24.             extraGundata = "";
  25.         let i = 0;
  26.         for (let [capture] of STRING.gmatch("([^_]+)")) {
  27.             i++;
  28.             if (i === 1 && GUNS.FindFirstChild(capture)) {
  29.                 gunName = capture as string;
  30.             } else if (i === 2) {
  31.                 capture = ((capture as string).lower().gsub("^%l", upper) as unknown) as string;
  32.                 const FOUND_MODULE = ReplicatedStorage.FindFirstChild("GunData")?.FindFirstChild(
  33.                     gunName as string,
  34.                 ) as ModuleScript;
  35.                 let requiredModule: gunData;
  36.                 if (FOUND_MODULE) {
  37.                     requiredModule = require(FOUND_MODULE) as gunData;
  38.                     let rarityStored;
  39.                     for (const [RARITY] of pairs(requiredModule.rarities)) {
  40.                         if (RARITY === capture) {
  41.                             rarityStored = RARITY;
  42.                         }
  43.                     }
  44.                     if (rarityStored !== capture) {
  45.                         PLAYER.Kick("Something went wrong and the gun rarity was not found.");
  46.                     }
  47.                     gunRarity = (rarityStored as unknown) as string;
  48.                 }
  49.             } else if (i === 3) {
  50.                 extraGundata = base64.decode(capture);
  51.             }
  52.         }
  53.         const TABLEDATA: tableData = {};
  54.         for (const [formatString] of extraGundata.gmatch("([^|]+)")) {
  55.             const INDEX = ((formatString as string)
  56.                 .sub(0, ((formatString as string).find("=") as unknown) as number)
  57.                 .gsub("=", "") as unknown) as string;
  58.             const VALUE = (formatString as string).sub(
  59.                 (((formatString as string).find("=") as unknown) as number) + 1,
  60.                 (formatString as string).size(),
  61.             );
  62.             if (VALUE.find(",")[0] !== undefined) {
  63.                 TABLEDATA[INDEX] = [];
  64.                 for (const [_, SPLIT] of pairs(VALUE.split(","))) {
  65.                     TABLEDATA[INDEX].push(SPLIT as never);
  66.                 }
  67.             } else if (VALUE.find('"')[0] !== undefined) {
  68.                 TABLEDATA[INDEX] = [];
  69.             } else {
  70.                 if (INDEX === "attachments") {
  71.                     TABLEDATA[INDEX] = [];
  72.                     TABLEDATA[INDEX].push(VALUE as never);
  73.                 } else {
  74.                     TABLEDATA[INDEX] = (VALUE as unknown) as [];
  75.                 }
  76.             }
  77.         }
  78.         UNPACKED[ID - 1] = {
  79.             rarity: gunRarity,
  80.             extra: extraGundata,
  81.             unpackedExtra: TABLEDATA,
  82.             name: gunName,
  83.             fullname: STRING,
  84.         };
  85.     }
  86.     return UNPACKED;
  87. }
  88.  
Add Comment
Please, Sign In to add comment