G_lander

Only Cppkies

Mar 17th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function (global, factory) {
  2.     typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3.     typeof define === 'function' && define.amd ? define(factory) :
  4.     (global = global || self, global.Cppkies = factory());
  5. }(this, (function () { 'use strict';
  6.  
  7.     /**
  8.      * A helper function which converts a common string to a string.
  9.      * @param value The common string to convert
  10.      * @helper
  11.      */
  12.     function getValue(value) {
  13.         if (value instanceof Function)
  14.             return value();
  15.         return value;
  16.     }
  17.     /**
  18.      * A helper function which escapes special regex characters.
  19.      * @param str The string to escape
  20.      * @helper
  21.      */
  22.     function escapeRegExp(str) {
  23.         // eslint-disable-next-line no-useless-escape
  24.         return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
  25.     }
  26.     /**
  27.      * A helper function which replaces(or appends) code in a function, returning the new function, and it's eval free!
  28.      * @param func The source function
  29.      * @param source What to replace(or act as a anchor where to plane), can be null for slicing
  30.      * @param target What to put instead(or before/after) the source
  31.      * @param where Where to insert or replace your injection
  32.      * @helper
  33.      */
  34.     function injectCode(func, source, target, where) {
  35.         var newFuncStr = func.toString();
  36.         var sliceMode = source === null;
  37.         var regex;
  38.         if (!sliceMode) {
  39.             source = getValue(source);
  40.             regex = new RegExp(escapeRegExp(source), "g");
  41.         }
  42.         target = getValue(target);
  43.         var findStart = /(\)[^{]*{)/;
  44.         var findEnd = /}?$/;
  45.         if (!sliceMode && !regex.test(newFuncStr))
  46.             console.warn("Nothing to inject.");
  47.         switch (where) {
  48.             case "before":
  49.                 if (sliceMode)
  50.                     newFuncStr = newFuncStr.replace(findStart, "$1" + target);
  51.                 else
  52.                     newFuncStr = newFuncStr.replace(regex, "" + target + source);
  53.                 break;
  54.             case "replace":
  55.                 if (sliceMode)
  56.                     newFuncStr = "" + target;
  57.                 else
  58.                     newFuncStr = newFuncStr.replace(regex, "" + target);
  59.                 break;
  60.             case "after":
  61.                 if (sliceMode)
  62.                     newFuncStr = newFuncStr.replace(findEnd, target + "$1");
  63.                 else
  64.                     newFuncStr = newFuncStr.replace(regex, "" + source + target);
  65.                 break;
  66.             default:
  67.                 throw new Error('where Parameter must be "before", "replace" or "after"');
  68.         }
  69.         var newFunc = new Function("return (" + newFuncStr + ")")();
  70.         newFunc.prototype = func.prototype;
  71.         return newFunc;
  72.     }
  73.  
  74.     /**
  75.      * Injects functions for basegame
  76.      * @returns A promise
  77.      */
  78.     function main() {
  79.         return new Promise(function (resolve) {
  80.             var Injection = /** @class */ (function () {
  81.                 function Injection(value, defValue, func) {
  82.                     this.value = value;
  83.                     this.defValue = defValue;
  84.                     this.func = func;
  85.                 }
  86.                 return Injection;
  87.             }());
  88.             var dummy = {};
  89.             var injections = [
  90.                 //// -- Custom menus -- ////
  91.                 /*
  92.                 Hooks that allow you to add new stuff do the menu
  93.  
  94.                 customOptionsMenu()
  95.                 Allows you to add entries to the options menu
  96.  
  97.                 customStatsMenu()
  98.                 Allows you to add entries to the stats menu
  99.  
  100.                 customInfoMenu()
  101.                 Allows you to add entries to the info menu
  102.  
  103.                 customMenu()
  104.                 Allows you to add entries to all menus
  105.                 */
  106.                 new Injection("customMenu", [], function () {
  107.                     window.Game.UpdateMenu = injectCode(window.Game.UpdateMenu, null, "\n\t\t\t\t\t// Cppkies injection\n\t\t\t\t\tswitch (Game.onMenu) {\n\t\t\t\t\t\tcase \"prefs\":\n\t\t\t\t\t\t\tfor(const i in Cppkies.hooks.customOptionsMenu) Cppkies.hooks.customOptionsMenu[i]();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"stats\":\n\t\t\t\t\t\t\tfor(const i in Cppkies.hooks.customStatsMenu) Cppkies.hooks.customStatsMenu[i]();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"log\":\n\t\t\t\t\t\t\tfor(const i in Cppkies.hooks.customInfoMenu) Cppkies.hooks.customInfoMenu[i]();\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tfor(const i in Cppkies.hooks.customMenu) Cppkies.hooks.customMenu[i]();\n\t\t\t\t\t", "before");
  108.                 }),
  109.                 new Injection("customOptionsMenu", []),
  110.                 new Injection("customStatsMenu", []),
  111.                 new Injection("customInfoMenu", []),
  112.                 //// -- Data manipulation -- ////
  113.                 /*
  114.                 General Description
  115.  
  116.                 customLoad()
  117.                 Allows you to execute a function on data load, useful for custom data loading
  118.  
  119.                 customReset(hard)
  120.                 Allows you to execute a function on data load, useful for custom data resetting
  121.                 hard: bool - whether or not this is a hard reset
  122.                 */
  123.                 new Injection("customLoad", [], function () {
  124.                     window.Game.LoadSave = injectCode(window.Game.LoadSave, "if (Game.prefs.showBackupWarning==1)", "\n\t\t\t\t\t// Cppkies injection\n\t\t\t\t\tfor(const i in Cppkies.hooks.customLoad) Cppkies.hooks.customLoad[i](); \n\t\t\t\t\t", "before");
  125.                 }),
  126.                 new Injection("customReset", [], function () {
  127.                     window.Game.Reset = injectCode(window.Game.Reset, null, "\n\t\t\t\t\t// Cppkies injection\n\t\t\t\t\tfor(const i in Cppkies.hooks.customReset) Cppkies.hooks.customReset[i](hard);\n\t\t\t\t\t", "before");
  128.                 }),
  129.                 //// -- Misc -- ////
  130.                 /**
  131.                 General Description
  132.  
  133.                 customBeautify(value, floats, ret)
  134.                 Allows you to "Insert Text Here" should return the new string of a beautied
  135.                 value - original value
  136.                 floats - The floating value
  137.                 ret - current value
  138.  
  139.                 */
  140.                 new Injection("customBeautify", [], function () {
  141.                     window.Beautify = injectCode(window.Beautify, "return negative?'-'+output:output+decimal;", "\n\t\t\t\t\t// Cppkies injection\n\t\t\t\t\tlet ret = negative?'-'+output:output+decimal;\n\t\t\t\t\tfor(const i in Cppkies.hooks.customBeautify) {\n\t\t\t\t\t\tlet returnedValue = Cppkies.hooks.customBeautify[i](value, floats, ret)\n\t\t\t\t\t\tret = returnedValue ? returnedValue : ret\n\t\t\t\t\t};\n\t\t\t\t\treturn ret;\n\t\t\t\t\t", "replace");
  142.                 }),
  143.                 //// -- Tooltips -- ////
  144.                 /*
  145.                 General Description
  146.                
  147.                 customTooltipDraw(from, text, origin)
  148.                 Allows you to "Insert Text Here"
  149.                 from -
  150.                 text -
  151.                 origin -
  152.  
  153.                 customTooltipUpdate()
  154.                 Allows you to "Insert Text Here"
  155.  
  156.                 */
  157.                 new Injection("customTooltipDraw", [], function () {
  158.                     window.Game.tooltip.draw = injectCode(window.Game.tooltip.draw, null, "\n\t\t\t\t\t// Cppkies injection\n\t\t\t\t\tfor(const i in Cppkies.hooks.customTooltipDraw) Cppkies.hooks.customTooltipDraw[i](from, text, origin);\n\t\t\t\t\t", "before");
  159.                 }),
  160.                 new Injection("customTooltipUpdate", [], function () {
  161.                     window.Game.tooltip.update = injectCode(window.Game.tooltip.update, null, "\n\t\t\t\t\t// Cppkies injection\n\t\t\t\t\tfor(const i in Cppkies.hooks.customTooltipUpdate) Cppkies.hooks.customTooltipUpdate[i]();\n\t\t\t\t\t", "before");
  162.                 }),
  163.                 //// -- Ascension -- ////
  164.                 /**
  165.                 General Description
  166.                
  167.                 customHowMuchPrestige(chips, ret)
  168.                 Allows you to "Insert Text Here" should return "value"
  169.                 chips - How many chips
  170.                 ret -
  171.  
  172.                 customHeavenlyMultiplier() // TODO
  173.                 Allows you to "Insert Text Here"
  174.  
  175.                 UpdateAscensionModePrompt() // TODO
  176.                 Allows you to "Insert Text Here"
  177.  
  178.                 */
  179.                 new Injection("customHowMuchPrestige", [], function () {
  180.                     window.Game.HowMuchPrestige = injectCode(injectCode(window.Game.HowMuchPrestige, "return", "let ret =", "replace"), ";", "\n\t\t\t\t\t// Cppkies injection\n\t\t\t\t\tfor(const i in Cppkies.hooks.customHowManyCookiesReset){ \n\t\t\t\t\t\treturnedValue = Cppkies.hooks.customHowManyCookiesReset[i](chips, ret);\n\t\t\t\t\t\tret = returnedValue ? returnedValue : ret\n\t\t\t\t\t}\n\t\t\t\t\treturn ret;\n\t\t\t\t\t", "after");
  181.                 }),
  182.                 new Injection("customHeavenlyMultiplier", []),
  183.                 new Injection("UpdateAscensionModePrompt", []),
  184.                 new Injection("customReincarnate", []),
  185.                 new Injection("customAscend", []),
  186.                 new Injection("customUpdateAscend", []),
  187.                 new Injection("customBuildAscendTree", []),
  188.                 new Injection("customAscend", []),
  189.                 //TODO: Everything else
  190.                 //Should I declare functions in this file or in another place entirely? - Bob
  191.                 //I have to go so just dm me the answer to the question when you have the time
  192.                 //// -- Sugar Lump -- ////
  193.                 //// -- Economics -- ////
  194.                 //// -- Shimmers -- ////
  195.                 //// -- Particles -- ////
  196.                 //// -- Notifications -- ////
  197.                 //// -- Prompts -- ////
  198.                 //// -- Menus -- ////
  199.                 //// -- Buildings -- ////
  200.                 new Injection("customGrandmaPic", [], function () {
  201.                     window.Game.Objects.Grandma.art.pic = injectCode(window.Game.Objects.Grandma.art.pic, "return choose(list)+'.png'", "// Cppkies injection\n\t\t\t\t\tlist = list.concat(Cppkies.hooks.customGrandmaPic.map(val=>val() || null).filter(val=>val !== null))\n\t\t\t\t\t", "before");
  202.                 }),
  203.                 //// -- Unsorted, for quick injections -- ////
  204.                 new Injection("postBuildStore", [], function () {
  205.                     var oldString = window.Game.BuildStore.toString();
  206.                     window.Game.BuildStore = new Proxy(window.Game.BuildStore, {
  207.                         apply: function (target, _this, args) {
  208.                             target.apply(_this, args);
  209.                             for (var i in window.Cppkies.hooks.postBuildStore)
  210.                                 window.Cppkies.hooks.postBuildStore[i]();
  211.                         },
  212.                     });
  213.                     window.Game.BuildStore.toString = function () { return oldString; };
  214.                 }),
  215.             ];
  216.             injections.forEach(function (inject) {
  217.                 dummy[inject.value] = inject.defValue;
  218.                 if (inject.func)
  219.                     inject.func();
  220.             });
  221.             //Misc stuff
  222.             window.Game.Loader.Load = injectCode(window.Game.Loader.Load, "img.src=this.domain", "img.src=(assets[i].indexOf('http') !== -1 ? \"\" : this.domain)", "replace");
  223.             resolve(dummy);
  224.         });
  225.     }
  226.  
  227.     /*! *****************************************************************************
  228.     Copyright (c) Microsoft Corporation. All rights reserved.
  229.     Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  230.     this file except in compliance with the License. You may obtain a copy of the
  231.     License at http://www.apache.org/licenses/LICENSE-2.0
  232.  
  233.     THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  234.     KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  235.     WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  236.     MERCHANTABLITY OR NON-INFRINGEMENT.
  237.  
  238.     See the Apache Version 2.0 License for specific language governing permissions
  239.     and limitations under the License.
  240.     ***************************************************************************** */
  241.     /* global Reflect, Promise */
  242.  
  243.     var extendStatics = function(d, b) {
  244.         extendStatics = Object.setPrototypeOf ||
  245.             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  246.             function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  247.         return extendStatics(d, b);
  248.     };
  249.  
  250.     function __extends(d, b) {
  251.         extendStatics(d, b);
  252.         function __() { this.constructor = d; }
  253.         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  254.     }
  255.  
  256.     var Building = /** @class */ (function (_super) {
  257.         __extends(Building, _super);
  258.         function Building(name, commonName, desc, icon, art, cpsFunc, buyFunction, foolObject, buildingSpecial) {
  259.             var _this = _super.call(this, name, commonName, desc, icon[0], icon[1], art, 0, //Game automatically calculates Price and BaseCps
  260.             cpsFunc, buyFunction) || this;
  261.             var localBuildingLink = Cppkies.buildingLink + "", localIconLink = Cppkies.iconLink + "";
  262.             // This is the name, description, and icon used during Business Season
  263.             if (foolObject)
  264.                 Game.foolObjects[name] = foolObject;
  265.             // The name of this building's golden cookie buff and debuff
  266.             if (buildingSpecial)
  267.                 Game.goldenCookieBuildingBuffs[name] = buildingSpecial;
  268.             //CCSE.ReplaceBuilding(name)
  269.             if (localIconLink) {
  270.                 Cppkies.buildingHooksById[_this.id].tooltip.push(function (obj, ret) {
  271.                     if (this.locked)
  272.                         return ret;
  273.                     else
  274.                         return ret.replace("background-position", "background-image:url(" + localIconLink + ");background-position");
  275.                 });
  276.             }
  277.             /*if (CCSE.save.Buildings[name]) {
  278.                 var saved = CCSE.save.Buildings[name]
  279.                 me.amount = saved.amount
  280.                 me.bought = saved.bought
  281.                 me.totalCookies = saved.totalCookies
  282.                 me.level = saved.level
  283.                 me.muted = saved.muted
  284.                 me.free = saved.free ? saved.free : 0 // Left this out earlier, can't expect it to be there
  285.                 me.minigameSave = saved.minigameSave
  286.  
  287.                 Game.BuildingsOwned += me.amount
  288.             } else {
  289.                 var saved = {}
  290.                 saved.amount = 0
  291.                 saved.bought = 0
  292.                 saved.totalCookies = 0
  293.                 saved.level = 0
  294.                 saved.muted = 0
  295.                 saved.minigameSave = ""
  296.  
  297.                 CCSE.save.Buildings[name] = saved
  298.             }*/
  299.             Game.BuildStore();
  300.             if (localBuildingLink) {
  301.                 Cppkies.hooks.postBuildStore.push(function () {
  302.                     l("productIcon" + _this.id).style.backgroundImage = "url(" + localBuildingLink + ")";
  303.                     l("productIconOff" + _this.id).style.backgroundImage = "url(" + localBuildingLink + ")";
  304.                 });
  305.             }
  306.             Game.BuildStore();
  307.             _this.canvas = l("rowCanvas" + _this.id);
  308.             _this.ctx = _this.canvas.getContext("2d");
  309.             _this.context = _this.ctx;
  310.             _this.pics = [];
  311.             var muteDiv = document.createElement("div");
  312.             muteDiv.className = "tinyProductIcon";
  313.             muteDiv.id = "mutedProduct" + _this.id;
  314.             muteDiv.style.display = "none";
  315.             if (localBuildingLink)
  316.                 muteDiv.style.backgroundImage = "url(" + localBuildingLink + ")";
  317.             muteDiv.style.backgroundPositionX = "-" + icon[0] + "px";
  318.             muteDiv.style.backgroundPositionY = "-" + icon[1] + "px";
  319.             muteDiv.addEventListener("click", function () {
  320.                 _this.mute(0);
  321.                 PlaySound(_this.muted ? "snd/clickOff.mp3" : "snd/clickOn.mp3");
  322.             });
  323.             AddEvent(_this.canvas, "mouseover", function () {
  324.                 _this.mouseOn = true;
  325.             });
  326.             AddEvent(_this.canvas, "mouseout", function () {
  327.                 _this.mouseOn = false;
  328.             });
  329.             AddEvent(_this.canvas, "mousemove", function (e) {
  330.                 var box = _this.canvas.getBoundingClientRect();
  331.                 _this.mousePos[0] = e.pageX - box.left;
  332.                 _this.mousePos[1] = e.pageY - box.top;
  333.             });
  334.             l("buildingsMute").appendChild(muteDiv);
  335.             Game.recalculateGains = 1;
  336.             var _loop_1 = function (i) {
  337.                 if (parseInt(i) > 0) {
  338.                     var me_1 = Game.ObjectsById[i];
  339.                     me_1.canvas = l("rowCanvas" + i);
  340.                     me_1.ctx = me_1.canvas.getContext("2d");
  341.                     //Relink their events too
  342.                     AddEvent(me_1.canvas, "mouseover", function () {
  343.                         me_1.mouseOn = true;
  344.                     });
  345.                     AddEvent(me_1.canvas, "mouseout", function () {
  346.                         me_1.mouseOn = false;
  347.                     });
  348.                     AddEvent(me_1.canvas, "mousemove", function (e) {
  349.                         var box = me_1.canvas.getBoundingClientRect();
  350.                         me_1.mousePos[0] = e.pageX - box.left;
  351.                         me_1.mousePos[1] = e.pageY - box.top;
  352.                     });
  353.                 }
  354.             };
  355.             //Manually relink canvases and contexts because Orteil made it so new buildings break the old canvas and context links
  356.             for (var i in Game.ObjectsById) {
  357.                 _loop_1(i);
  358.             }
  359.             return _this;
  360.         }
  361.         return Building;
  362.     }(Game.Object));
  363.  
  364.     if (window.Cppkies)
  365.         throw new Error("Duplicate Cppkies import");
  366.     main().then(function (answer) {
  367.         window.Cppkies.hooks = answer;
  368.         window.Game.Note.call({}, "Cppkies loaded!", "", [32, 17], true);
  369.         window.Game.Win("Third-party");
  370.     });
  371.     var master = {
  372.         hooks: {},
  373.         injectCode: injectCode,
  374.         iconLink: "",
  375.         buildingLink: "",
  376.         buildingHooks: {},
  377.         buildingHooksById: [],
  378.         Building: Building,
  379.     };
  380.  
  381.     return master;
  382.  
  383. })));
  384. //# sourceMappingURL=index.js.map
Advertisement
Add Comment
Please, Sign In to add comment