Skip to content

Commit 22f5d28

Browse files
committed
Add Cheats menu to the Title Menu, add animations to make the menu feel like the other menus, change all quotes to double to follow CrossCode js style
1 parent 3a01089 commit 22f5d28

File tree

2 files changed

+91
-45
lines changed

2 files changed

+91
-45
lines changed

cheats.js

Lines changed: 90 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ig.module("cheats").requires("game.feature.player.player-level", "game.feature.p
4747
function noOp() {}
4848
// END: Utilities
4949
// START: Cheats
50-
replaceProp(sc.PlayerLevelTools, 'computeExp', (originalComputeExp) => {
50+
replaceProp(sc.PlayerLevelTools, "computeExp", (originalComputeExp) => {
5151
return (...args) => {
5252
const exp = originalComputeExp.apply(sc.PlayerLevelTools, args);
5353
// If xpcheat is enabled we multiple the exp by xpmultiplier and minimally add xpmingain experience.
@@ -64,7 +64,7 @@ ig.module("cheats").requires("game.feature.player.player-level", "game.feature.p
6464
sc.ARENA_BONUS_OBJECTIVE.CHAIN,
6565
sc.ARENA_BONUS_OBJECTIVE.ITEMS_USED,
6666
].forEach(function (bonus) {
67-
replaceProp(bonus, 'check', (originalCheck) => {
67+
replaceProp(bonus, "check", (originalCheck) => {
6868
return (...args) => {
6969
// If arenaalwaysbonuses is enabled the checks always returns true.
7070
return arenaalwaysbonuses || originalCheck.apply(this, args);
@@ -148,7 +148,7 @@ ig.module("cheats").requires("game.feature.player.player-level", "game.feature.p
148148
}
149149
},
150150
addScore(a, b) {
151-
if (!arenanodamagepenalty || a !== 'DAMAGE_TAKEN') {
151+
if (!arenanodamagepenalty || a !== "DAMAGE_TAKEN") {
152152
// If arenanodamagepenalty is enabled we don't add damage taken.
153153
this.parent.apply(this, arguments);
154154
}
@@ -161,8 +161,8 @@ ig.module("cheats").requires("game.feature.player.player-level", "game.feature.p
161161
return this.parent.apply(this, arguments);
162162
},
163163
});
164-
const getSpReplacer = toggleReplacer(sc.CombatParams.prototype, 'getSp', () => function() {return this.maxSp});
165-
const cancelActionReplacer = toggleReplacer(ig.ENTITY.Player.prototype, 'cancelAction', () => noOp);
164+
const getSpReplacer = toggleReplacer(sc.CombatParams.prototype, "getSp", () => function() {return this.maxSp});
165+
const cancelActionReplacer = toggleReplacer(ig.ENTITY.Player.prototype, "cancelAction", () => noOp);
166166
ig.ENTITY.Player.inject({
167167
startCharge() {
168168
// If ignorespcheat is enabled we replace the getSp function to return the max sp instead of current sp.
@@ -195,7 +195,7 @@ ig.module("cheats").requires("game.feature.player.player-level", "game.feature.p
195195
this.parent.apply(this, arguments);
196196
},
197197
});
198-
const removeItemReplacer = toggleReplacer(sc.PlayerModel.prototype, 'removeItem', () => noOp);
198+
const removeItemReplacer = toggleReplacer(sc.PlayerModel.prototype, "removeItem", () => noOp);
199199
sc.TradeModel.inject({
200200
doTrade() {
201201
// If tradecheat is enabled we replace the removeItem function with one that does nothing.
@@ -205,16 +205,16 @@ ig.module("cheats").requires("game.feature.player.player-level", "game.feature.p
205205
return returnValue;
206206
},
207207
});
208-
const getCombatRankByLabelReplacer = toggleReplacer(sc.GameModel.prototype, 'getCombatRankByLabel', () => () => 0);
209-
const mathRandomReplacer = toggleReplacer(Math, 'random', () => () => 0);
208+
const getCombatRankByLabelReplacer = toggleReplacer(sc.GameModel.prototype, "getCombatRankByLabel", () => () => 0);
209+
const mathRandomReplacer = toggleReplacer(Math, "random", () => () => 0);
210210
sc.EnemyType.inject({
211211
resolveItemDrops(a) {
212212
enemydropcheat && getCombatRankByLabelReplacer.replace() && mathRandomReplacer.replace() && (a.boosterState = sc.ENEMY_BOOSTER_STATE.BOOSTED);
213213
this.parent.apply(this, arguments);
214214
enemydropcheat && getCombatRankByLabelReplacer.restore() && mathRandomReplacer.restore();
215215
},
216216
});
217-
const getModifierReplacer = toggleReplacer(sc.CombatParams.prototype, 'getModifier', () => () => 1000);
217+
const getModifierReplacer = toggleReplacer(sc.CombatParams.prototype, "getModifier", () => () => 1000);
218218
ig.ENTITY.ItemDestruct.inject({
219219
dropItem(a) {
220220
plantdropcheat && mathRandomReplacer.replace() && getModifierReplacer.replace();
@@ -225,7 +225,7 @@ ig.module("cheats").requires("game.feature.player.player-level", "game.feature.p
225225
// END: Cheats
226226
});
227227
ig.baked = !0;
228-
ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.feature.menu.gui.base-menu", "game.feature.menu.menu-model", "impact.base.lang", "impact.feature.gui.gui", "game.feature.interact.button-group", "game.feature.menu.gui.menu-misc", "game.feature.menu.gui.options.options-misc", "game.feature.gui.base.text", "game.feature.gui.base.button", "impact.feature.interact.press-repeater", "game.feature.gui.base.numbers").defines(function () {
228+
ig.module("cheats-gui").requires("game.feature.gui.screen.title-screen", "game.feature.gui.screen.pause-screen", "game.feature.menu.gui.base-menu", "game.feature.menu.menu-model", "impact.base.lang", "impact.feature.gui.gui", "game.feature.interact.button-group", "game.feature.menu.gui.menu-misc", "game.feature.menu.gui.options.options-misc", "game.feature.gui.base.text", "game.feature.gui.base.button", "impact.feature.interact.press-repeater", "game.feature.gui.base.numbers").defines(function () {
229229
// START: Lang Extension
230230
// If this code is changed into a real mod/extension this can be moved into a separate lang JSON.
231231
const LANG_EXTENSION = {
@@ -264,7 +264,7 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
264264
this.parent.apply(this, arguments);
265265
function setProperties(from, to) {
266266
for (const [key, value] of Object.entries(from)) {
267-
if (typeof value === 'object') {
267+
if (typeof value === "object") {
268268
setProperties(value, to[key] = to[key] || {});
269269
} else {
270270
to[key] = value;
@@ -278,28 +278,28 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
278278
// END: Lang Extension
279279
// START: Cheats Menu
280280
const CHEAT_CONFIG = [
281-
['xpcheat', {type: 'CHECKBOX'}],
282-
['xpmultiplier', {type: 'SLIDER', min: 0, max: 100}],
283-
['xpmingain', {type: 'SLIDER', min: 0, max: 1000}],
284-
['creditcheat', {type: 'CHECKBOX'}],
285-
['creditmultiplier', {type: 'SLIDER', min: 0, max: 100}],
286-
['donotremovecredit', {type: 'CHECKBOX'}],
287-
['donotremovearenacoins', {type: 'CHECKBOX'}],
288-
['arenaalwaysbonuses', {type: 'CHECKBOX'}],
289-
['arenaperfectchain', {type: 'CHECKBOX'}],
290-
['arenanodamagepenalty', {type: 'CHECKBOX'}],
291-
['arenaalwaysplat', {type: 'CHECKBOX'}],
292-
['ignorespcheat', {type: 'CHECKBOX'}],
293-
['overheatelim', {type: 'CHECKBOX'}],
294-
['invincible', {type: 'CHECKBOX'}],
295-
['cpcheat', {type: 'CHECKBOX'}],
296-
['consumableinfinite', {type: 'CHECKBOX'}],
297-
['consumablenocooldown', {type: 'CHECKBOX'}],
298-
['noknockbackonhit', {type: 'CHECKBOX'}],
299-
['noactioncancelonhit', {type: 'CHECKBOX'}],
300-
['tradecheat', {type: 'CHECKBOX'}],
301-
['enemydropcheat', {type: 'CHECKBOX'}],
302-
['plantdropcheat', {type: 'CHECKBOX'}],
281+
["xpcheat", {type: "CHECKBOX"}],
282+
["xpmultiplier", {type: "SLIDER", min: 0, max: 100}],
283+
["xpmingain", {type: "SLIDER", min: 0, max: 1000}],
284+
["creditcheat", {type: "CHECKBOX"}],
285+
["creditmultiplier", {type: "SLIDER", min: 0, max: 100}],
286+
["donotremovecredit", {type: "CHECKBOX"}],
287+
["donotremovearenacoins", {type: "CHECKBOX"}],
288+
["arenaalwaysbonuses", {type: "CHECKBOX"}],
289+
["arenaperfectchain", {type: "CHECKBOX"}],
290+
["arenanodamagepenalty", {type: "CHECKBOX"}],
291+
["arenaalwaysplat", {type: "CHECKBOX"}],
292+
["ignorespcheat", {type: "CHECKBOX"}],
293+
["overheatelim", {type: "CHECKBOX"}],
294+
["invincible", {type: "CHECKBOX"}],
295+
["cpcheat", {type: "CHECKBOX"}],
296+
["consumableinfinite", {type: "CHECKBOX"}],
297+
["consumablenocooldown", {type: "CHECKBOX"}],
298+
["noknockbackonhit", {type: "CHECKBOX"}],
299+
["noactioncancelonhit", {type: "CHECKBOX"}],
300+
["tradecheat", {type: "CHECKBOX"}],
301+
["enemydropcheat", {type: "CHECKBOX"}],
302+
["plantdropcheat", {type: "CHECKBOX"}],
303303
];
304304
function getCheatValue(cheat) {
305305
return window[cheat];
@@ -330,6 +330,24 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
330330
this.list.setSize(400, 240);
331331
this.list.setPos(0, 0);
332332
this.list.setAlign(ig.GUI_ALIGN.X_CENTER, ig.GUI_ALIGN.Y_CENTER);
333+
// Setup animations so that the list slides in like the other lists do (ex: Save, Options, etc).
334+
this.list.hook.transitions = {
335+
DEFAULT: {
336+
state: {},
337+
time: 0.2,
338+
timeFunction: KEY_SPLINES.LINEAR,
339+
},
340+
HIDDEN: {
341+
state: {
342+
alpha: 0,
343+
offsetX: 218,
344+
},
345+
time: 0.2,
346+
timeFunction: KEY_SPLINES.LINEAR,
347+
}
348+
};
349+
// List starts hidden.
350+
this.list.doStateTransition("HIDDEN", true);
333351

334352
// Add press callback so we can react when checkboxes are changed.
335353
this.buttonGroup.addPressCallback((control) => {
@@ -352,7 +370,7 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
352370
this.contents.addChildGui(label);
353371

354372
switch (data.type) {
355-
case 'CHECKBOX': {
373+
case "CHECKBOX": {
356374
const button = new sc.CheckboxGui(cheatValue, 30);
357375
button.setAlign(ig.GUI_ALIGN.X_LEFT, ig.GUI_ALIGN.Y_TOP);
358376
button.setPos(200, rowYPos);
@@ -361,7 +379,7 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
361379
this.buttonGroup.addFocusGui(button, 0, row);
362380
break;
363381
}
364-
case 'SLIDER': {
382+
case "SLIDER": {
365383
const slider = new sc.OptionFocusSlider((newValue) => {
366384
setCheatValue(cheat, newValue);
367385
updateNumberDisplay();
@@ -413,7 +431,7 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
413431
const control = this.buttonGroup.getCurrentElement();
414432
const repeaterValue = this.getRepeaterValue();
415433
// Handle keyboard up and down keys.
416-
if (repeaterValue === 'up' || repeaterValue === 'down') {
434+
if (repeaterValue === "up" || repeaterValue === "down") {
417435
const controlTopY = control.hook.pos.y;
418436
const controlBottomY = controlTopY + control.hook.size.y;
419437
const scrollTopY = this.list.getScrollY();
@@ -428,12 +446,12 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
428446
}
429447
// Handle left and right for sliders.
430448
if (control instanceof sc.OptionFocusSlider) {
431-
// The value we update by varies based on whether we're holding certain buttons for A11Y.
449+
// The value we update by varies based on whether we"re holding certain buttons for A11Y.
432450
const changeValue = sc.control.dashHold() ? 100 : sc.control.quickmenu() ? 10 : 1;
433451
switch (repeaterValue) {
434-
case 'right':
435-
case 'left': {
436-
const direction = repeaterValue === 'left' ? -1 : 1;
452+
case "right":
453+
case "left": {
454+
const direction = repeaterValue === "left" ? -1 : 1;
437455
const newValue = control.getValue() + (changeValue * direction);
438456
const clamped = Math.max(control.slider.minValue, Math.min(control.slider.maxValue, newValue));
439457
control.setValue(clamped);
@@ -446,13 +464,13 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
446464
},
447465
getRepeaterValue: function () {
448466
if (sc.control.rightDown()) {
449-
this.repeater.setDown('right');
467+
this.repeater.setDown("right");
450468
} else if (sc.control.leftDown()) {
451-
this.repeater.setDown('left');
469+
this.repeater.setDown("left");
452470
} else if (sc.control.downDown()) {
453-
this.repeater.setDown('down');
471+
this.repeater.setDown("down");
454472
} else if (sc.control.upDown()) {
455-
this.repeater.setDown('up');
473+
this.repeater.setDown("up");
456474
}
457475
return this.repeater.getPressed();
458476
},
@@ -468,6 +486,7 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
468486
sc.menu.moveLeaSprite(0, 0, sc.MENU_LEA_STATE.HIDDEN); // No idea what this is.
469487
sc.menu.buttonInteract.pushButtonGroup(this.buttonGroup); // Make our button group active.
470488
ig.interact.setBlockDelay(0.2); // Don't let the user interact while the menu is animating into place.
489+
this.list.doStateTransition("DEFAULT"); // Animation the list.
471490
},
472491
hideMenu() {
473492
this.removeObservers();
@@ -477,6 +496,7 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
477496
exitMenu() {
478497
sc.menu.buttonInteract.removeButtonGroup(this.buttonGroup); // Make our button group inactive.
479498
sc.menu.popBackCallback(); // Unregister the back button handling.
499+
this.list.doStateTransition("HIDDEN"); // Animation the list.
480500
},
481501
onBackButtonPress() {
482502
// Pop our menu to go back up to the menu that created ours.
@@ -502,6 +522,32 @@ ig.module("cheats-gui").requires("game.feature.gui.screen.pause-screen", "game.f
502522
return this.parent.apply(this, arguments);
503523
},
504524
});
525+
sc.TitleScreenButtonGui.inject({
526+
cheatsButton: null,
527+
init() {
528+
this.parent();
529+
this.cheatsButton = new sc.ButtonGui(ig.lang.get("sc.cheats.title"), this.gameCodeButton.hook.size.x);
530+
this.cheatsButton.setAlign(this.gameCodeButton.hook.align.x, this.gameCodeButton.hook.align.y);
531+
this.cheatsButton.setPos(this.gameCodeButton.hook.pos.x, this.gameCodeButton.hook.pos.y + 28);
532+
this.cheatsButton.onButtonPress = () => {
533+
// What menu should be entered when clicked.
534+
sc.menu.setDirectMode(true, sc.MENU_SUBMENU.CHEATS);
535+
sc.model.enterMenu(true);
536+
};
537+
this.cheatsButton.hook.transitions = this.gameCodeButton.hook.transitions;
538+
this.cheatsButton.doStateTransition("HIDDEN", true);
539+
this.buttonGroup.insertFocusGui(this.cheatsButton, 1, 0);
540+
this.insertChildGui(this.cheatsButton);
541+
},
542+
show() {
543+
this.parent();
544+
this.cheatsButton.doStateTransition("DEFAULT");
545+
},
546+
hide(a) {
547+
this.parent.apply(this, arguments);
548+
this.cheatsButton.doStateTransition("HIDDEN", a);
549+
},
550+
});
505551
sc.PauseScreenGui.inject({
506552
cheatsButton: null,
507553
init() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Cheats",
33
"postload": "cheats.js",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"homepage": "https://github.com/ZeikJT/CrossCodeCheats",
66
"description": "This mod adds cheats to CrossCode.",
77
"ccmodDependencies": {

0 commit comments

Comments
 (0)