Skip to content

Commit

Permalink
Update 0.18 (Files)
Browse files Browse the repository at this point in the history
  • Loading branch information
1nf1n1t3Sm4sh3r committed Nov 16, 2024
1 parent ace512c commit de98cb1
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You'll need a userscript manager to run The MegaMod on your browser. I recommend
- **[Violentmonkey](https://violentmonkey.github.io/)** (Recommended)

### Step 2: Install The MegaMod Script
1. After installing the userscript manager, click [here](https://1nf1n1t3sm4sh3r.github.io/mmTest/js/script.user.js) to install **The MegaMod**
1. After installing the userscript manager, [click here](https://1nf1n1t3sm4sh3r.github.io/mmTest/js/script.user.js) to install **The MegaMod**
2. Follow the prompts to add the script to your userscript manager.

### Step 3: Enable the MegaMod
Expand Down
24 changes: 21 additions & 3 deletions data/changelog.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
{
"current": [
{
"version": "0.18",
"date": "November 16 2024",
"content": [
"Fixed loading issue caused by Update 0.50.4",
"Fixed \"Yolky Merch\" Badge not showing up",
"Restyled \"Overeggchiever\" V Badge",
"Restyled \"Eggspenditure\" V Badge",
"Restyled \"Shell Scrambler\" IV and V Badges",
"Restyled \"Master of Arms\" V Badge",
"Restyled \"Splattered Yolk\" V Badge",
"Restyled \"Rooster Royalty\" V Badge",
"Restyled \"Coop King\" V Badge",
"Restyled \"Poached Promoter\" V Badge",
"Tier badges now have alerts for when they level down, are gained, or are lost!",
"Core badges now have an alert for when you gain or lose them!"
]
}
],
"old": [
{
"version": "0.17",
"date": "November 8 2024",
Expand All @@ -10,9 +30,7 @@
"Buffed tier requirements for \"Eggstra Spender\" Badge",
"Buffed tier requirements for \"Eggspenditure\" Badge"
]
}
],
"old": [
},
{
"version": "0.16",
"date": "November 2 2024",
Expand Down
17 changes: 12 additions & 5 deletions data/info.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"announcement": "<b>October 16th, 2024</b> <br><br>Attention All Playtesters!<br>Welcome to The MegaMod playtest!<br>Explore all the mods and have fun :)<br><br>-Infinite",
"updateInfo": [
"Shell now automatically reloads after you update The MegaMod!",
"Fixed tier badge level up alert showing when badges level down",
"Fixed stamps not being sorted correctly in the inventory",
"Buffed tier requirements for \"Eggstra Spender\" Badge",
"Buffed tier requirements for \"Eggspenditure\" Badge"
"Fixed loading issue caused by Update 0.50.4",
"Fixed \"Yolky Merch\" Badge not showing up",
"Restyled \"Overeggchiever\" V Badge",
"Restyled \"Eggspenditure\" V Badge",
"Restyled \"Shell Scrambler\" IV and V Badges",
"Restyled \"Master of Arms\" V Badge",
"Restyled \"Splattered Yolk\" V Badge",
"Restyled \"Rooster Royalty\" V Badge",
"Restyled \"Coop King\" V Badge",
"Restyled \"Poached Promoter\" V Badge",
"Tier badges now have alerts for when they level down, are gained, or are lost!",
"Core badges now have an alert for when you gain or lose them!"
]
}
6 changes: 5 additions & 1 deletion data/loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
"megaMod_betterUI_badgePopup_header_badge": "",
"megaMod_betterUI_badgePopup_header_name": "Name",
"megaMod_betterUI_badgePopup_header_desc": "Description / Requirements",
"megaMod_betterUI_badgeLvlUp_title": "Tier Badge Level Up!",
"megaMod_betterUI_coreBadgeGained_title": "Core Badge Gained!",
"megaMod_betterUI_coreBadgeLost_title": "Core Badge Lost :(",
"megaMod_betterUI_tierBadgeLvlUp_title": "Tier Badge Level Up!",
"megaMod_betterUI_tierBadgeLvlDown_title": "Tier Badge Level Down :(",
"megaMod_betterUI_tierBadgeLost_title": "Tier Badge Lost :(",

"megaMod_betterUI_badge_vip_title": "VIP Subscriber",
"megaMod_betterUI_badge_vip_desc": "Have an active VIP subscription",
Expand Down
3 changes: 2 additions & 1 deletion data/sfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"modTab",
"settingsTab",
"settingsTabHover",
"badgeLevelUp"
"badgeLevelUp",
"badgeLevelDown"
]
153 changes: 116 additions & 37 deletions js/megaMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,36 +545,80 @@ class MegaMod {
main: [],
tier: []
},
updateBadges(ignoreTierLevels = false) {
updateBadges(ignoreNotif = false) {
const CORE_KEY = `${extern.account.id}-coreBadges`;
const oldCoreBadgeTitles = JSON.parse(localStore.getItem(CORE_KEY));
const TIER_KEY = `${extern.account.id}-tierBadges`;
const oldTierBadgeDict = JSON.parse(localStore.getItem(TIER_KEY));

if (extern.account.id) {
const ANON_KEY = "anonAccountId";
const anonId = localStore.getItem(ANON_KEY);
if (extern.account.isAnonymous && !anonId) {
localStore.setItem(ANON_KEY, extern.account.id);
} else if (!extern.account.isAnonymous && anonId) {
[CORE_KEY, TIER_KEY].forEach(key =>
localStore.removeItem(key.replace(extern.account.id, anonId))
);
localStore.removeItem(ANON_KEY);
}
}

const newBadges = this.getBadges();
if (!ignoreTierLevels) {
const getTierBadges = badges => badges.flatMap(row => row.tier || []);
const newTierBadges = getTierBadges(newBadges.rows);
const oldTierBadges = getTierBadges(this.badges.rows);

const getBadgeClass = badge => badge.styleClass.replace(` tier${badge.tier}`, "");
const oldBadgeDict = oldTierBadges.reduce((dict, badge) => {
dict[getBadgeClass(badge)] = badge.tier;
return dict;
}, {});

const removeHoverClass = style => style.replace(/\bbadge-hover(-alt)?\b/g, '');
newTierBadges.forEach(newBadge => {
const oldTier = oldBadgeDict[getBadgeClass(newBadge)];
if (oldTier === undefined || newBadge.tier > oldTier) {
const newCoreBadges = newBadges.rows.flatMap(row => row.main || []);
const newCoreBadgeTitles = newCoreBadges.map(badge => badge.title);
localStore.setItem(CORE_KEY, JSON.stringify(newCoreBadgeTitles));

const getBadgeClass = badge => badge.styleClass.replace(/\btier\d+\b|\bbadge-hover(-alt)?\b/g, '').trim();
const newTierBadges = newBadges.rows.flatMap(row => row.tier || []);
const newTierBadgeDict = newTierBadges.reduce((dict, badge) => ((dict[getBadgeClass(badge)] = badge.tier), dict), {});
localStore.setItem(TIER_KEY, JSON.stringify(newTierBadgeDict));

if (!ignoreNotif) {
const allBadges = this.getBadges(true);
const processBadges = (badges, type, filterFn = () => true) => {
const removeHover = style => style.replace(/\bbadge-hover(-alt)?\b/g, '').trim();
badges.filter(filterFn).forEach(badge => {
vueApp.addBadgeMsg({
badgeClass: removeHoverClass(newBadge.styleClass),
iconClass: removeHoverClass(newBadge.classList),
badgeName: newBadge.title
type,
badgeClass: removeHover(badge.styleClass),
iconClass: removeHover(badge.classList),
badgeName: badge.title
});
}
});
};
});
};


if (oldCoreBadgeTitles) {
processBadges(newCoreBadges, BadgeMsgType.coreGained, badge => !oldCoreBadgeTitles.includes(badge.title));
processBadges(allBadges.main.filter(b => oldCoreBadgeTitles.includes(b.title)), BadgeMsgType.coreLost, badge => !newCoreBadgeTitles.includes(badge.title));
}

if (oldTierBadgeDict) {
newTierBadges.forEach(badge => {
const oldTier = oldTierBadgeDict[getBadgeClass(badge)];
if (oldTier === undefined || badge.tier > oldTier) {
processBadges([badge], BadgeMsgType.tierUpgrade);
} else if (badge.tier < oldTier) {
processBadges([badge], BadgeMsgType.tierDowngrade);
}
});

const lostTierBadges = Object.keys(oldTierBadgeDict).filter(badgeClass => !(badgeClass in newTierBadgeDict));
lostTierBadges.forEach(badgeClass => {
const lostBadge = allBadges.tier.find(b => badgeClass === getBadgeClass(b) && b.tier === oldTierBadgeDict[badgeClass]);
if (lostBadge) processBadges([lostBadge], BadgeMsgType.tierLost);
});
}
}

// Update the current badges
this.badges = newBadges;
},
badgeMsg: {
showing: false,
msgs: [],
titleLocKey: '',
badgeClass: '',
iconClass: '',
badgeName: ''
Expand Down Expand Up @@ -1236,7 +1280,7 @@ class MegaMod {

const badgeNotifPopup = `
<div id="badgeLevelUp" v-show="badgeMsg.showing" class="centered_x in-game-notification">
<h2 id="badgeTitle" class="text_white nospace">{{ loc.megaMod_betterUI_badgeLvlUp_title }}</h2>
<h2 id="badgeTitle" class="text_white nospace">{{ loc[badgeMsg.titleLocKey] }}</h2>
<i id="badgeIcon" :class="badgeMsg.iconClass"></i>
<p id="badgeName" :class="badgeMsg.badgeClass" class="nospace">{{ badgeMsg.badgeName }}</p>
</div>
Expand Down Expand Up @@ -1286,6 +1330,8 @@ class MegaMod {
this.log("editSource() -", "Editing shellshock.js");
// Minified Variable Regex
const v = `[a-zA-Z_$][a-zA-Z0-9_$]*`;

const cleanVar = v => v.replaceAll(`\\`, "");

// Match Grenade Pickups
let itemManagerClass = new RegExp(`(${v})\\.Constructors`).safeExec(src, "matchGrenades");
Expand All @@ -1294,7 +1340,7 @@ class MegaMod {
itemManagerClass = itemManagerClass[1];
let itemManagerMatch = new RegExp(`(${v})\\=new\\s${itemManagerClass}`).safeExec(src, "matchGrenades");
if (itemManagerMatch?.length > 1) {
itemManagerInst = itemManagerMatch[1];
itemManagerInst = cleanVar(itemManagerMatch[1]);
let meshVar = new RegExp(`this\\.(${v})\\.rotation\\.y\\+\\=\\.[0-9]+\\*${v}`).safeExec(src, "matchGrenades");
if (meshVar?.length > 1) {
meshVar = meshVar[1];
Expand All @@ -1315,6 +1361,7 @@ class MegaMod {
}

// ItemManager Class Modifications
itemManagerClass = cleanVar(itemManagerClass);
const updateGrenadesFunc = `,
${itemManagerClass}.prototype.updateGrenades = function() {
const grenadeData = [];
Expand Down Expand Up @@ -1613,10 +1660,10 @@ class MegaMod {
const teamText = document.createElement("span");
teamText.style.color = nameDiv.style.color;
teamText.textContent = vueApp.loc[teamLocs[player.team - 1]];
msgContent.innerHTML = vueApp.loc[ChatEventData[type].loc].format(teamText.outerHTML);
msgContent.innerHTML = vueApp.loc[ChatEventData[type].locKey].format(teamText.outerHTML);
break;
default:
msgContent.textContent = vueApp.loc[ChatEventData[type].loc];
msgContent.textContent = vueApp.loc[ChatEventData[type].locKey];
}
chatItem.append(nameDiv, msgContent);
Expand Down Expand Up @@ -2627,6 +2674,7 @@ class BetterUI {
loggedOut(...args) {
oldLoggedOut.apply(this, args);
vueApp.equip.updateShowingItemTotal();
this.challengesClaimed = [];
}
});

Expand Down Expand Up @@ -2769,20 +2817,23 @@ class BetterUI {
},
showBadgeMsg() {
if (!this.badgeMsg.msgs.length) return;
BAWK.play('badgeLevelUp');

// Destructure the first message directly, avoiding repetitive access
const { badgeClass, iconClass, badgeName } = this.badgeMsg.msgs.shift();
const { type, badgeClass, iconClass, badgeName } = this.badgeMsg.msgs.shift();
const { locKey, sfx } = BadgeMsgTypeData[type];
BAWK.play(sfx);

this.badgeMsg.titleLocKey = locKey;
this.badgeMsg.badgeClass = badgeClass;
this.badgeMsg.iconClass = iconClass;
this.badgeMsg.badgeName = badgeName;
this.badgeMsg.showing = true;

// Use an arrow function to maintain the context of `this` naturally
setTimeout(() => {
this.badgeMsg.showing = false;
this.showBadgeMsg(); // Recursive call to process the next message
}, 2900);
}, BAWK.sounds[sfx].buffer.duration * 1000);
},
addBadgeMsg(msg) {
// Add the new message
Expand Down Expand Up @@ -2813,11 +2864,11 @@ class BetterUI {
Object.assign(playerAccount.prototype, {
signedIn(...args) {
oldSignedIn.apply(this, args);
setTimeout(vueApp.updateBadges.bind(vueApp), 500, true);
setTimeout(vueApp.updateBadges.bind(vueApp), 500);
},
loggedOut(...args) {
oldLoggedOut.apply(this, args);
vueApp.updateBadges();
vueApp.updateBadges(true);
},
scoreKill(...args) {
oldScoreKill.apply(this, args);
Expand All @@ -2832,8 +2883,7 @@ class BetterUI {
vueApp.updateBadges();
}
});
setTimeout(vueApp.updateBadges.bind(vueApp), 1000, true);

setTimeout(vueApp.updateBadges.bind(vueApp), 1000);
}

randomizeSkin() {
Expand Down Expand Up @@ -3430,23 +3480,52 @@ Object.assign(unsafeWindow, {
switchTeam: 2,
},
teamLocs: ['team_blue', 'team_red'],
BadgeMsgType: {
coreGained: 0,
coreLost: 1,
tierUpgrade: 2,
tierDowngrade: 3,
tierLost: 4
},
rawPath: "https://raw.githubusercontent.com/1nf1n1t3Sm4sh3r/mmTest/main", // https://raw.githubusercontent.com/1nf1n1t3Sm4sh3r/mmTest/main
cdnPath: "https://1nf1n1t3sm4sh3r.github.io/mmTest", // https://1nf1n1t3sm4sh3r.github.io/mmTest
});
unsafeWindow.ChatEventData = {
[ChatEvent.joinGame]: {
loc: 'megaMod_betterUI_chatEvent_joinGame',
locKey: 'megaMod_betterUI_chatEvent_joinGame',
setting: 'betterUI_chatEvent_joinGame'
},
[ChatEvent.leaveGame]: {
loc: 'megaMod_betterUI_chatEvent_leaveGame',
locKey: 'megaMod_betterUI_chatEvent_leaveGame',
setting: 'betterUI_chatEvent_leaveGame'
},
[ChatEvent.switchTeam]: {
loc: 'megaMod_betterUI_chatEvent_switchTeam',
locKey: 'megaMod_betterUI_chatEvent_switchTeam',
setting: 'betterUI_chatEvent_switchTeam'
}
};
unsafeWindow.BadgeMsgTypeData = {
[BadgeMsgType.coreGained]: {
locKey: 'megaMod_betterUI_coreBadgeGained_title',
sfx: 'badgeLevelUp'
},
[BadgeMsgType.coreLost]: {
locKey: 'megaMod_betterUI_coreBadgeLost_title',
sfx: 'badgeLevelDown'
},
[BadgeMsgType.tierUpgrade]: {
locKey: 'megaMod_betterUI_tierBadgeLvlUp_title',
sfx: 'badgeLevelUp'
},
[BadgeMsgType.tierDowngrade]: {
locKey: 'megaMod_betterUI_tierBadgeLvlDown_title',
sfx: 'badgeLevelDown'
},
[BadgeMsgType.tierLost]: {
locKey: 'megaMod_betterUI_tierBadgeLost_title',
sfx: 'badgeLevelDown'
}
};
MegaMod.setDebug(true);
unsafeWindow.megaMod = new MegaMod();

Expand Down
Loading

0 comments on commit de98cb1

Please sign in to comment.