This commit is contained in:
2026-04-24 22:07:00 +03:00
parent 864f7d5a4f
commit 1dc96a53ee

View File

@@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Grepolis Remote Control // @name Grepolis Remote Control
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 3.6.6 // @version 3.6.7
// @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player) // @description Polls grepo.haunter-pets.top for remote commands and executes them in-game (Multi-Player)
// @author Dimitrios // @author Dimitrios
// @match https://*.grepolis.com/game/* // @match https://*.grepolis.com/game/*
@@ -818,60 +818,48 @@
if (farmSettings.bandit_camp_enabled) { if (farmSettings.bandit_camp_enabled) {
try { try {
// player_id already declared above in pollAndExecute scope // player_id already declared above in pollAndExecute scope
// Get any valid town_id — we just need one to make the request
const currentTownId = uw.ITowns?.getCurrentTown?.()?.id const currentTownId = uw.ITowns?.getCurrentTown?.()?.id
|| Object.keys(uw.ITowns?.towns || {})[0] || Object.keys(uw.ITowns?.towns || {})[0]
|| null; || null;
if (!player_id || !currentTownId) { if (!player_id || !currentTownId) {
log(`⚔️ Bandit Camp: Missing globals — player_id=${player_id} town_id=${currentTownId}`); log(`⚔️ Bandit Camp: Missing globals — player_id=${player_id} town_id=${currentTownId}`);
} else { } else {
// Build hash param — it's embedded in the page URL or game globals // First try: MM collection (works once camp was opened in-game)
const hash = uw.Game?.csrf_token || uw.Game?.h || uw.Game?.hash || ''; let spotData = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0]?.attributes || null;
// Direct fetch of the PlayerAttackSpot model state // Second try: use gpAjax with a callback — it handles auth/hash internally
const url = `/game/frontend_bridge?town_id=${currentTownId}&action=execute&h=${hash}`; if (!spotData) {
const body = new URLSearchParams({ spotData = await new Promise((resolve) => {
json: JSON.stringify({ try {
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
model_url: `PlayerAttackSpot/${player_id}`, model_url: `PlayerAttackSpot/${player_id}`,
action_name: 'get_state', action_name: 'get_own',
captcha: null, captcha: null,
arguments: {}, arguments: {},
town_id: currentTownId, town_id: currentTownId,
nl_init: true nl_init: true
}) }, false, {
}); success: function(data) {
// Response may contain the spot data directly
const resp = await fetch(url, { const d = data?.PlayerAttackSpot
method: 'POST', || data?.data?.PlayerAttackSpot?.[player_id]
headers: { || data?.[player_id]
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', || data;
'X-Requested-With': 'XMLHttpRequest' resolve((d && d.cooldown_at !== undefined) ? d : null);
}, },
body: body.toString() error: function() { resolve(null); }
});
} catch(e) { resolve(null); }
}); });
let spotData = null; // After the gpAjax call, MM might now have the model
if (resp.ok) {
try {
const raw = await resp.json();
// Try to find the spot data in the response
spotData = raw?.data?.PlayerAttackSpot?.[player_id]
|| raw?.data?.player_attack_spot
|| raw?.PlayerAttackSpot
|| (Array.isArray(raw?.data) ? raw.data[0] : null)
|| raw;
if (spotData?.cooldown_at === undefined) spotData = null;
} catch(e) {}
}
// Fallback: try the MM collection (works if camp was opened once)
if (!spotData) { if (!spotData) {
const mmModel = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0]; spotData = uw.MM.getOnlyCollectionByName('PlayerAttackSpot')?.models?.[0]?.attributes || null;
if (mmModel) spotData = mmModel.attributes; }
} }
if (!spotData) { if (!spotData) {
log(`⚔️ Bandit Camp: Could not load spot data. hash=${hash ? 'found' : 'MISSING'}. Try opening the camp window in-game once.`); log('⚔️ Bandit Camp: Could not load spot data. Open the Bandit Camp window in-game once to let the game load it.');
} else { } else {
const nowTs = Math.floor(Date.now() / 1000); const nowTs = Math.floor(Date.now() / 1000);
const spotId = spotData.id || player_id; const spotId = spotData.id || player_id;