Skip to content

Commit

Permalink
Support: Scavenger Hunt on MHCT Map Helper (auto)
Browse files Browse the repository at this point in the history
  • Loading branch information
u-nel committed Jun 20, 2023
1 parent 06ec8d0 commit faaf685
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 48 deletions.
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"build": "webpack --config webpack/webpack.prod.js",
"build:dev": "webpack --config webpack/webpack.dev.js",
"build:watch": "webpack --config webpack/webpack.dev.js --watch",
"dev": "npm run build:dev && concurrently \"npm run web-run\" \"npm run build:watch\"",
"dev:firefox": "npm run build:dev && concurrently \"npm run web-run:firefox\" \"npm run build:watch\"",
"dev": "cross-env TARGET=chrome npm run build:dev && concurrently \"npm run web-run\" \"cross-env TARGET=chrome npm run build:watch\"",
"dev:firefox": "cross-env TARGET=firefox npm run build:dev && concurrently \"npm run web-run:firefox\" \"cross-env TARGET=firefox npm run build:watch\"",
"lint": "eslint .",
"test": "jest"
},
Expand All @@ -59,6 +59,7 @@
"@typescript-eslint/parser": "^5.59.8",
"concurrently": "^8.0.1",
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.41.0",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"got-cjs": "^12.5.4",
Expand Down
2 changes: 2 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"default_popup": "popup.html"
},

"incognito": "split",

"permissions": [
"tabs",
"*://www.mousehuntgame.com/*",
Expand Down
114 changes: 70 additions & 44 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as detailingFuncs from './modules/details/legacy';
'use strict';

let base_domain_url = "https://www.mhct.win";
let main_intake_url, map_intake_url, convertible_intake_url, map_helper_url, rh_intake_url, rejection_intake_url;
let main_intake_url, map_intake_url, convertible_intake_url, map_helper_url, rh_intake_url, rejection_intake_url,scav_helper_url;

let mhhh_version = 0;
let hunter_id_hash = '0';
Expand Down Expand Up @@ -110,6 +110,7 @@ import * as detailingFuncs from './modules/details/legacy';
map_helper_url = base_domain_url + "/maphelper.php";
rh_intake_url = base_domain_url + "/rh_intake.php";
rejection_intake_url = base_domain_url + "/rejection_intake.php";
scav_helper_url = base_domain_url + "/scavhelper.php";

await createHunterIdHash();
}
Expand Down Expand Up @@ -192,61 +193,86 @@ import * as detailingFuncs from './modules/details/legacy';
let glue = '';
let method = '';
let input_name ='';
if (solver === 'mhmh') {
url = map_helper_url;
glue = '\n';
method = 'POST';
input_name = 'mice';
} else if (solver === 'ryonn') {
url = 'http://dbgames.info/mousehunt/tavern';
glue = ';';
method = 'GET';
input_name = 'q';
} else {

if(!['mhmh', 'ryonn'].includes(solver)) return;

let treasure_map = user.quests.QuestRelicHunter.maps;

if(!treasure_map.length) {
alert('Please make sure you are logged in into MH and are currently member of a treasure map.');
return;
}

const payload = {
map_id: user.quests.QuestRelicHunter.default_map_id,
action: "map_info",
uh: user.unique_hash,
last_read_journal_entry_id: lastReadJournalEntryId,
};
$.post('https://www.mousehuntgame.com/managers/ajax/users/treasuremap.php', payload, null, 'json')
.done(data => {
if (data) {
if (!data.treasure_map || data.treasure_map.view_state === "noMap") {
alert('Please make sure you are logged in into MH and are currently member of a treasure map.');
return;
}
if (!['treasure', 'event'].includes(data.treasure_map.map_class)) {
alert('This seems to be a new kind of map and not yet supported.');
return;
treasure_map = treasure_map.filter(map => ['treasure', 'event'].includes(map.map_class));

if(!treasure_map.length) {
alert('This seems to be a new kind of map and not yet supported.');
return;
}


for(const i in treasure_map) {

const payload = {
map_id: treasure_map[i].map_id,
action: "map_info",
uh: user.unique_hash,
last_read_journal_entry_id: lastReadJournalEntryId,
};

$.post('https://www.mousehuntgame.com/managers/ajax/users/treasuremap.php', payload, null, 'json')
.done(data => {
if (data) {

if(solver === 'mhmh') {
url = data.treasure_map.is_scavenger_hunt? scav_helper_url : map_helper_url;
glue = '\n';
method = 'POST';
input_name = data.treasure_map.is_scavenger_hunt? 'items' : 'mice';
}

if(solver === 'ryonn') {
url = 'http://dbgames.info/mousehunt/tavern';
glue = ';';
method = 'GET';
input_name = 'q';
}

const goals = getMapGoals(data, true);

$('<form method="' + method + '" action="' + url + '" target="_blank">' +
'<input type="hidden" name="' + input_name + '" value="' + goals.join(glue) +
'"></form>').appendTo('body').submit().remove();
}
const mice = getMapMice(data, true);
$('<form method="' + method + '" action="' + url + '" target="_blank">' +
'<input type="hidden" name="' + input_name + '" value="' + mice.join(glue) +
'"></form>').appendTo('body').submit().remove();
}
});
});
}


}

// Extract map mice from a map
function getMapMice(data, uncaught_only) {
const mice = {};
$.each(data.treasure_map.goals.mouse, (key, mouse) => {
mice[mouse.unique_id] = mouse.name;
/**
* Extract goals from map (can be scav or treasure)
* @param {Object} data Data response from managers/ajax/users/treasuremap.php
* @param {boolean} remaining_only Boolean, if true, to filter out completed goals
* @returns {string[]} Goal names. If on treasure map, it will be mice names and if
* on scavenger it will be item names.
*/
function getMapGoals(data, remaining_only) {
const goalCategory = data.treasure_map.is_scavenger_hunt ? 'item' : 'mouse';
const goals = {};
$.each(data.treasure_map.goals[goalCategory], (key, goal) => {
goals[goal.unique_id] = goal.name;
});

if (uncaught_only) {
if (remaining_only) {
$.each(data.treasure_map.hunters, (key, hunter) => {
$.each(hunter.completed_goal_ids.mouse, (key, mouse_id) => {
delete mice[mouse_id];
$.each(hunter.completed_goal_ids[goalCategory], (key, goal_id) => {
delete goals[goal_id];
});
});
}

return Object.values(mice);
return Object.values(goals);
}

/**
Expand Down Expand Up @@ -496,7 +522,7 @@ import * as detailingFuncs from './modules/details/legacy';
return;
}
const map = {
mice: getMapMice(resp),
mice: getMapGoals(resp),
id: map_id,
name: name.replace(/ treasure/i, '')
.replace(/rare /i, '')
Expand Down
4 changes: 3 additions & 1 deletion src/scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
function findOpenMHTab(callback, button_id, silent) {
chrome.tabs.query({'url': ['*://www.mousehuntgame.com/*', '*://apps.facebook.com/mousehunt/*']}, tabs => {
if (tabs.length > 0) {
callback(tabs[0].id, button_id);
const isPrivate = typeof browser !== 'undefined' ? browser.extension.inIncognitoContext : chrome.extension.inIncognitoContext;
const tf = tabs.filter(t => t.incognito === isPrivate);
callback(tf[0].id, button_id);
}
else if (!silent) {
displayErrorPopup("Please navigate to MouseHunt page first.");
Expand Down
26 changes: 25 additions & 1 deletion webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ const RemoteDownloadFileWebpackPlugin = require('./RemoteDownloadFileWebpackPlug
const srcScripts = path.resolve(__dirname, '../src/scripts/');
const outpath = path.resolve(__dirname, '../dist/');

function modify(buffer) {
// copy-webpack-plugin passes a buffer
var manifest = JSON.parse(buffer.toString());

// make any modifications you like, such as
// manifest.version = package.version;
if(process.env.TARGET == 'firefox') {
delete manifest.incognito;
}

// pretty print to JSON with two spaces
manifest_JSON = JSON.stringify(manifest, null, 2);

return manifest_JSON;
}

module.exports = {
entry: {
background: path.join(srcScripts, 'background.js'),
Expand Down Expand Up @@ -43,10 +59,18 @@ module.exports = {
from: './',
to: outpath,
globOptions: {
ignore: ['**/scripts'],
ignore: ['**/scripts', '**/manifest.json'],
},
context: 'src/',
},
{
from: "./manifest.json",
to: outpath,
transform(content, absoluteFrom) {
return modify(content);
},
context: 'src/',
},
],
}),
new RemoteDownloadFileWebpackPlugin([
Expand Down

0 comments on commit faaf685

Please sign in to comment.