klattmose

Cookie Clicker Script Extender (CCSE)

Current version : 2.035

CCSE is a modding framework for the game https://orteil.dashnet.org/cookieclicker/. On its own, it makes no changes to the game. Instead, it makes modding the game much easier.

The vanilla game has a couple mod hooks in it already. However, they are labelled as primitive and according to the changelog have been that way since they were introduced in 2014. This plus the innate silliness in having every add-on backup and replace the Game.UpdateMenu function led to the inspiration for this mod.

How to use it

If you want to make an add-on that uses CCSE, just put this line at the top of your mod:

if(typeof CCSE == 'undefined') Game.LoadMod('https://klattmose.github.io/CookieClicker/CCSE.js');

To wait for CCSE to finish loading before continuing to load your mod, frame your mod in this general style:

if(MyMod === undefined) var MyMod = {};
if(typeof CCSE == 'undefined') Game.LoadMod('https://klattmose.github.io/CookieClicker/CCSE.js');

MyMod.launch = function(){
	/**
	
	All the code you want to delay goes here
	Put "MyMod.isLoaded = 1;" somewhere within
	
	**/
}

if(!MyMod.isLoaded){
	if(CCSE && CCSE.isLoaded){
		MyMod.launch();
	}
	else{
		if(!CCSE) var CCSE = {};
		if(!CCSE.postLoadHooks) CCSE.postLoadHooks = [];
		CCSE.postLoadHooks.push(MyMod.launch);
	}
}

What can you do with CCSE?

More like what can’t you do? Seriously, tell me if it can’t do something you want it to do. Just make an issue here.

CCSE puts mod hooks in most of the functions in the game, as well as adds some helper functions to make soem things a little easier. Here’s a quick and incomplete list of some of the features.

There are four separate hooks into Game.UpdateMenu.

Game.customMenu
Game.customOptionsMenu
Game.customStatsMenu
Game.customInfoMenu

To use these, just push your menu function into the array you choose, like so:

Game.customMenu.push(MyMod.menuFunction);

Functions in the Game.customMenu will be called whenerver Game.UpdateMenu is called. The other three arrays are used when their particular menu is in focus (i.e. Game.customOptionsMenu functions are only called when the Options menu is open)

There are several functions in CCSE that make menu functions easier.

An example of how these functions might be used:

Game.customOptionsMenu.push(function(){
	CCSE.AppendCollapsibleOptionsMenu(MyMod.name, MyMod.getMenuString());
});

Game.customStatsMenu.push(function(){
	CCSE.AppendStatsVersionNumber(MyMod.name, MyMod.version);
});

Of course, MyMod.name, MyMod.version, and MyMod.getMenuString must be declared elsewhere in your add-on.

Saving data

If your mod or add-on has configuration choices or other data you’d like to persist between sessions, you’ll have to save it at some point and load it later. You could write your own functions for that, or you could let CCSE handle that for you. How?

CCSE.customSave.push(function(){
	CCSE.config.OtherMods.MyMod = MyMod.config;
});
CCSE.customLoad.push(function(){
	if(CCSE.config.OtherMods.MyMod) MyMod.config = CCSE.config.OtherMods.MyMod; else MyMod.config = {};
	// Do other things if you want
});

This data gets saved very time the game is saved, and loaded every time the game is loaded. the CCSE section of the Options menu has buttons that let you export and import the custom save. If you desire to change the save manually you can use the following functions through the console:

CCSE.ExportEditableSave();
CCSE.ImportEditableSave();

Custom upgrades, achievements, buffs, and buildings

CCSE has functions to ease the creation of the above game items.

If you use these functions, CCSE will know to save the created items automatically, with no extrea effort needed. In addition, the following base game functions have been altered so CCSE will know to save the resultant items:

Miscellaneous functions

Use this function to delay the execution of code to after a minigame has loaded, or run it immediately if the minigame already is loaded.

CCSE.MinigameReplacer(MyMod.AlterGrimoire, 'Wizard tower');

Wrinklers are stored in an array. Use this function to add more.

Special objects are Krumblor and Santa in the bottom left corner. You can totally make your own.

Use any one of these to preform a version check before loading the code. If the expected version is different from the current version, it shows a prompt allowing the user to cancel loading the mod.

if(CCSE.ConfirmGameVersion(MyMod.name, MyMod.version, MyMod.GameVersion)) MyMod.init();

Demo mods

I made a few quick mods to show off the capability of CCSE and provide example code of some of its features.

Timer Widget

javascript: (function(){
	Game.LoadMod('https://klattmose.github.io/CookieClicker/CCSE-POCs/TimerWidget.js');
}());

If any part of this reminds you of the Timer Bar in Cookie Monster, there’s a very good reason for that: large chunks of code were copied from Cookie Monster.

Provides examples of:

Hurricane Sugar

javascript: (function(){
	Game.LoadMod('https://klattmose.github.io/CookieClicker/CCSE-POCs/HurricaneSugar.js');
}());

This adds a Golden Cookie effect that briefly shortens the time for sugar lumps to ripen to 1 second.

Provides examples of:

Black Hole Inverter

javascript: (function(){
	Game.LoadMod('https://klattmose.github.io/CookieClicker/CCSE-POCs/BlackholeInverter.js');
}());

This adds a new building and an appropriate amount of upgrades and achievments

Provides examples of:

Compatibility

CCSE sinks its grabby hooks into a huge number of the game’s functions. I haven’t done extensive testing with every single Cookie Clicker add-on in existence, so I can’t give any definitives. Tell me of any conflicts you find and I’ll add them to the list.

Bugs and suggestions

Any bug or suggestion should be opened as an issue in the repository for easier tracking. This allows me to close issues once they’re fixed.

Version History

05/16/2023 - (2.035)

03/13/2023 - (2.034)

10/04/2021 - (2.031)

09/26/2021 - (2.030)

09/18/2021 - (2.029)

09/11/2021 - (2.028)

09/09/2021 - (2.027)

09/01/2021 - (2.025)

02/06/2021 - (2.023)

11/01/2020 - (2.020)

10/22/2019 - (2.016)

05/14/2019 - parallel processing (2.015)

05/11/2019 - take two (2.003)

05/05/2019 - initial release (1.0)

Special thanks

Anyone who gives a suggestion or bugfix, especially code that gets implemented into CCSE, will be listed here along with their contribution.