1582 lines
73 KiB
C#
1582 lines
73 KiB
C#
// Engines/Nwjs/NwjsModService.cs — NW.js ゲーム向けスクリプト改造注入・復元サービス
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Text;
|
||
using GameLauncher.Engines.Tkool;
|
||
using GameLauncher.Helpers;
|
||
using GameLauncher.Models;
|
||
|
||
namespace GameLauncher.Engines.Nwjs
|
||
{
|
||
/// <summary>
|
||
/// NW.js エンジン製ゲーム(GameCreator 製・カスタム HTML5/JS 製・その他 NW.js 全般)に対して、
|
||
/// エントリ HTML への改造スクリプト(チートメニュー・倍速・全解放・F12開発者ツール)の注入および
|
||
/// バックアップからの完全復元を提供するサービスクラス。
|
||
/// </summary>
|
||
public static class NwjsModService
|
||
{
|
||
#region □定数(Private)
|
||
|
||
/// <summary>
|
||
/// 注入する改造 JavaScript ファイル名。
|
||
/// </summary>
|
||
private const string ModScriptFileName = "nwjs_launcher_mod.js";
|
||
|
||
/// <summary>
|
||
/// エントリ HTML に挿入する script タグ。
|
||
/// </summary>
|
||
private const string ModScriptTag = "<script src=\"./nwjs_launcher_mod.js\"></script>";
|
||
|
||
/// <summary>
|
||
/// バックアップファイルの拡張子サフィックス。
|
||
/// </summary>
|
||
private const string BackupFileSuffix = ".original_launcher_backup";
|
||
|
||
#endregion
|
||
|
||
#region □メソッド(Public)
|
||
|
||
/// <summary>
|
||
/// 指定されたエントリ HTML ファイルに改造スクリプトタグが適用済みかどうかを判定します。
|
||
/// </summary>
|
||
/// <param name="indexHtmlPath">判定対象の index.html 等のフルパス</param>
|
||
/// <returns>適用済みの場合は true、それ以外は false</returns>
|
||
public static bool CheckIsModded(string indexHtmlPath)
|
||
{
|
||
if (string.IsNullOrEmpty(indexHtmlPath) || !File.Exists(indexHtmlPath))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
try
|
||
{
|
||
string content = File.ReadAllText(indexHtmlPath, Encoding.UTF8);
|
||
return content.Contains(NwjsModService.ModScriptFileName, StringComparison.OrdinalIgnoreCase);
|
||
}
|
||
catch
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 選択されたプラグイン設定に基づいて NW.js ゲームへ改造スクリプトを生成・注入します。
|
||
/// </summary>
|
||
/// <param name="game">対象のゲームアイテム</param>
|
||
/// <param name="indexHtmlPath">エントリ HTML のパス</param>
|
||
/// <param name="plugins">プラグイン設定一覧</param>
|
||
public static void ApplyMod(TkoolGameItem game, string indexHtmlPath, IEnumerable<ModPluginOptionItem> plugins)
|
||
{
|
||
if (string.IsNullOrEmpty(indexHtmlPath) || !File.Exists(indexHtmlPath))
|
||
{
|
||
throw new FileNotFoundException("NW.js のエントリ HTML ファイルが見つかりません。", indexHtmlPath);
|
||
}
|
||
|
||
bool enableCheatMenu = false;
|
||
bool enableSpeedHack = false;
|
||
bool enableUnlockGallery = false;
|
||
bool enableDevTools = false;
|
||
|
||
if (plugins != null)
|
||
{
|
||
foreach (ModPluginOptionItem opt in plugins)
|
||
{
|
||
if (!opt.IsEnabled)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
switch (opt.Id)
|
||
{
|
||
case "NwjsCheatMenu":
|
||
enableCheatMenu = true;
|
||
break;
|
||
case "NwjsSpeedHack":
|
||
enableSpeedHack = true;
|
||
break;
|
||
case "NwjsUnlockGallery":
|
||
enableUnlockGallery = true;
|
||
break;
|
||
case "NwjsDevTools":
|
||
enableDevTools = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!enableCheatMenu && !enableSpeedHack && !enableUnlockGallery && !enableDevTools)
|
||
{
|
||
NwjsModService.RestoreOriginal(game, indexHtmlPath);
|
||
return;
|
||
}
|
||
|
||
string backupPath = NwjsModService.GetBackupFilePath(game, indexHtmlPath);
|
||
string legacyBackupPath = indexHtmlPath + NwjsModService.BackupFileSuffix;
|
||
|
||
if (!File.Exists(backupPath))
|
||
{
|
||
string? backupDir = Path.GetDirectoryName(backupPath);
|
||
if (!string.IsNullOrEmpty(backupDir) && !Directory.Exists(backupDir))
|
||
{
|
||
Directory.CreateDirectory(backupDir);
|
||
}
|
||
|
||
if (File.Exists(legacyBackupPath))
|
||
{
|
||
File.Copy(legacyBackupPath, backupPath, overwrite: true);
|
||
}
|
||
else
|
||
{
|
||
string currentHtml = File.ReadAllText(indexHtmlPath, Encoding.UTF8);
|
||
if (!currentHtml.Contains(NwjsModService.ModScriptFileName, StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
File.Copy(indexHtmlPath, backupPath, overwrite: true);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (File.Exists(legacyBackupPath))
|
||
{
|
||
try
|
||
{
|
||
File.Delete(legacyBackupPath);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
|
||
string baseHtml;
|
||
if (File.Exists(backupPath))
|
||
{
|
||
baseHtml = File.ReadAllText(backupPath, Encoding.UTF8);
|
||
}
|
||
else
|
||
{
|
||
baseHtml = File.ReadAllText(indexHtmlPath, Encoding.UTF8);
|
||
}
|
||
|
||
string htmlDir = Path.GetDirectoryName(indexHtmlPath) ?? game.RootDirectory;
|
||
string modJsPath = Path.Combine(htmlDir, NwjsModService.ModScriptFileName);
|
||
string jsContent = NwjsModService.GenerateModScriptContent(
|
||
enableCheatMenu,
|
||
enableSpeedHack,
|
||
enableUnlockGallery,
|
||
enableDevTools);
|
||
|
||
File.WriteAllText(modJsPath, jsContent, new UTF8Encoding(false));
|
||
|
||
if (!baseHtml.Contains(NwjsModService.ModScriptFileName, StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
int headCloseIdx = baseHtml.IndexOf("</head>", StringComparison.OrdinalIgnoreCase);
|
||
int bodyCloseIdx = baseHtml.IndexOf("</body>", StringComparison.OrdinalIgnoreCase);
|
||
string modifiedHtml;
|
||
|
||
if (headCloseIdx >= 0)
|
||
{
|
||
modifiedHtml = baseHtml.Insert(headCloseIdx, " " + NwjsModService.ModScriptTag + "\r\n");
|
||
}
|
||
else if (bodyCloseIdx >= 0)
|
||
{
|
||
modifiedHtml = baseHtml.Insert(bodyCloseIdx, " " + NwjsModService.ModScriptTag + "\r\n");
|
||
}
|
||
else
|
||
{
|
||
modifiedHtml = baseHtml + "\r\n" + NwjsModService.ModScriptTag + "\r\n";
|
||
}
|
||
|
||
File.WriteAllText(indexHtmlPath, modifiedHtml, new UTF8Encoding(false));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 注入した改造スクリプトと HTML の変更を破棄し、元の状態へ完全に復元します。
|
||
/// </summary>
|
||
/// <param name="game">対象のゲームアイテム</param>
|
||
/// <param name="indexHtmlPath">エントリ HTML のパス</param>
|
||
public static void RestoreOriginal(TkoolGameItem game, string indexHtmlPath)
|
||
{
|
||
if (string.IsNullOrEmpty(indexHtmlPath))
|
||
{
|
||
return;
|
||
}
|
||
|
||
string backupPath = NwjsModService.GetBackupFilePath(game, indexHtmlPath);
|
||
string legacyBackupPath = indexHtmlPath + NwjsModService.BackupFileSuffix;
|
||
|
||
if (File.Exists(backupPath))
|
||
{
|
||
File.Copy(backupPath, indexHtmlPath, overwrite: true);
|
||
}
|
||
else if (File.Exists(legacyBackupPath))
|
||
{
|
||
File.Copy(legacyBackupPath, indexHtmlPath, overwrite: true);
|
||
try
|
||
{
|
||
File.Delete(legacyBackupPath);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
else if (File.Exists(indexHtmlPath))
|
||
{
|
||
string content = File.ReadAllText(indexHtmlPath, Encoding.UTF8);
|
||
if (content.Contains(NwjsModService.ModScriptFileName, StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
content = content.Replace(" " + NwjsModService.ModScriptTag + "\r\n", string.Empty)
|
||
.Replace(" " + NwjsModService.ModScriptTag + "\n", string.Empty)
|
||
.Replace(NwjsModService.ModScriptTag + "\r\n", string.Empty)
|
||
.Replace(NwjsModService.ModScriptTag + "\n", string.Empty)
|
||
.Replace(NwjsModService.ModScriptTag, string.Empty);
|
||
File.WriteAllText(indexHtmlPath, content, new UTF8Encoding(false));
|
||
}
|
||
}
|
||
|
||
string? htmlDir = Path.GetDirectoryName(indexHtmlPath);
|
||
if (!string.IsNullOrEmpty(htmlDir))
|
||
{
|
||
string modJsPath = Path.Combine(htmlDir, NwjsModService.ModScriptFileName);
|
||
if (File.Exists(modJsPath))
|
||
{
|
||
try
|
||
{
|
||
File.Delete(modJsPath);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region □メソッド(Private)
|
||
|
||
/// <summary>
|
||
/// バックアップ先ファイルのフルパスを取得します。
|
||
/// </summary>
|
||
/// <param name="game">対象のゲームアイテム</param>
|
||
/// <param name="indexHtmlPath">エントリ HTML のパス</param>
|
||
/// <returns>バックアップファイルのフルパス</returns>
|
||
private static string GetBackupFilePath(TkoolGameItem game, string indexHtmlPath)
|
||
{
|
||
string backupDir = AppPathHelper.GetGameBackupDirectory(game.FolderName, game.RootDirectory);
|
||
string fileName = Path.GetFileName(indexHtmlPath);
|
||
if (string.IsNullOrEmpty(fileName))
|
||
{
|
||
fileName = "index.html";
|
||
}
|
||
|
||
return Path.Combine(backupDir, fileName + NwjsModService.BackupFileSuffix);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 有効化されたオプションに応じた JavaScript 改造コードを生成します。
|
||
/// </summary>
|
||
/// <param name="enableCheatMenu">チートメニューを有効化するかどうか</param>
|
||
/// <param name="enableSpeedHack">倍速機能を有効化するかどうか</param>
|
||
/// <param name="enableUnlockGallery">ギャラリー全解放を有効化するかどうか</param>
|
||
/// <param name="enableDevTools">F12開発者ツールを有効化するかどうか</param>
|
||
/// <returns>生成された JavaScript コード文字列</returns>
|
||
private static string GenerateModScriptContent(
|
||
bool enableCheatMenu,
|
||
bool enableSpeedHack,
|
||
bool enableUnlockGallery,
|
||
bool enableDevTools)
|
||
{
|
||
string flagsJson = string.Format(
|
||
"{{ cheatMenu: {0}, speedHack: {1}, unlockGallery: {2}, devTools: {3} }}",
|
||
enableCheatMenu ? "true" : "false",
|
||
enableSpeedHack ? "true" : "false",
|
||
enableUnlockGallery ? "true" : "false",
|
||
enableDevTools ? "true" : "false");
|
||
|
||
return @"// Generated by GameLauncher — NW.js Universal Mod & Cheat Script
|
||
(function() {
|
||
'use strict';
|
||
if (window.__NWJS_LAUNCHER_MOD_LOADED__) return;
|
||
window.__NWJS_LAUNCHER_MOD_LOADED__ = true;
|
||
|
||
const MOD_CONFIG = " + flagsJson + @";
|
||
|
||
// トースト通知表示ヘルパー
|
||
function showToast(msg, durationMs) {
|
||
durationMs = durationMs || 2200;
|
||
try {
|
||
let toast = document.getElementById('nwjs-mod-toast');
|
||
if (!toast) {
|
||
toast = document.createElement('div');
|
||
toast.id = 'nwjs-mod-toast';
|
||
toast.style.cssText = 'position:fixed;top:14px;left:50%;transform:translateX(-50%);background:rgba(15,23,42,0.92);color:#38bdf8;border:1px solid #0284c7;padding:8px 18px;border-radius:20px;font-family:sans-serif;font-size:13px;font-weight:bold;z-index:2147483647;pointer-events:none;box-shadow:0 4px 16px rgba(0,0,0,0.6);transition:opacity 0.25s;';
|
||
document.body.appendChild(toast);
|
||
}
|
||
toast.textContent = msg;
|
||
toast.style.opacity = '1';
|
||
if (toast._timer) clearTimeout(toast._timer);
|
||
toast._timer = setTimeout(function() {
|
||
toast.style.opacity = '0';
|
||
}, durationMs);
|
||
} catch (e) {}
|
||
}
|
||
|
||
// グローバルレキシカルスコープの定数・変数を安全に評価取得するヘルパー
|
||
function evalGlobal(expr) {
|
||
try {
|
||
return (0, eval)(expr);
|
||
} catch (e) {
|
||
return undefined;
|
||
}
|
||
}
|
||
|
||
// エンジン種別の動的判定 ('gc' = GameCreator, 'custom_state' = Game.state系, 'generic' = その他)
|
||
function detectRuntimeKind() {
|
||
if (evalGlobal('typeof SinglePlayerGame !== ""undefined"" && typeof Game !== ""undefined"" && Game && Game.player')) {
|
||
return 'gc';
|
||
}
|
||
if (evalGlobal('typeof Game !== ""undefined"" && Game && Game.state')) {
|
||
return 'custom_state';
|
||
}
|
||
return 'generic';
|
||
}
|
||
|
||
// =========================================================================
|
||
// 1. 開発者ツール (F12)
|
||
// =========================================================================
|
||
if (MOD_CONFIG.devTools) {
|
||
window.addEventListener('keydown', function(e) {
|
||
if (e.key === 'F12' || e.keyCode === 123) {
|
||
try {
|
||
if (typeof nw !== 'undefined' && nw.Window) {
|
||
nw.Window.get().showDevTools();
|
||
e.preventDefault();
|
||
} else if (typeof chrome !== 'undefined' && chrome.developerPrivate) {
|
||
e.preventDefault();
|
||
}
|
||
} catch (err) {
|
||
console.error(err);
|
||
}
|
||
}
|
||
}, true);
|
||
}
|
||
|
||
// =========================================================================
|
||
// 2. 倍速・高速化ハック ([F6] トグル / [Ctrl] 5倍速ブースト)
|
||
// =========================================================================
|
||
let currentSpeedScale = 1.0;
|
||
let toggledSpeedScale = 1.0;
|
||
let isCtrlBoost = false;
|
||
|
||
function applySpeedScale(scale) {
|
||
currentSpeedScale = scale;
|
||
try {
|
||
const laya = evalGlobal('typeof Laya !== ""undefined"" ? Laya : null');
|
||
if (laya && laya.timer) {
|
||
laya.timer.scale = scale;
|
||
}
|
||
} catch (e) {}
|
||
try {
|
||
const videos = document.querySelectorAll('video');
|
||
for (let i = 0; i < videos.length; i++) {
|
||
videos[i].playbackRate = Math.min(16, Math.max(0.25, scale));
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
|
||
if (MOD_CONFIG.speedHack) {
|
||
try {
|
||
const origPerfNow = performance.now.bind(performance);
|
||
let lastRealPerf = origPerfNow();
|
||
let virtualPerf = lastRealPerf;
|
||
performance.now = function() {
|
||
const now = origPerfNow();
|
||
const delta = now - lastRealPerf;
|
||
lastRealPerf = now;
|
||
virtualPerf += delta * currentSpeedScale;
|
||
return virtualPerf;
|
||
};
|
||
|
||
const origDateNow = Date.now.bind(Date);
|
||
let lastRealDate = origDateNow();
|
||
let virtualDate = lastRealDate;
|
||
Date.now = function() {
|
||
const now = origDateNow();
|
||
const delta = now - lastRealDate;
|
||
lastRealDate = now;
|
||
virtualDate += delta * currentSpeedScale;
|
||
return Math.floor(virtualDate);
|
||
};
|
||
|
||
const origRAF = window.requestAnimationFrame.bind(window);
|
||
window.requestAnimationFrame = function(callback) {
|
||
return origRAF(function(ts) {
|
||
const laya = evalGlobal('typeof Laya !== ""undefined"" ? Laya : null');
|
||
if (laya && laya.timer) {
|
||
laya.timer.scale = currentSpeedScale;
|
||
}
|
||
callback(performance.now());
|
||
});
|
||
};
|
||
} catch (e) {}
|
||
|
||
window.addEventListener('keydown', function(e) {
|
||
if (e.target && (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.tagName === 'SELECT')) return;
|
||
if (e.key === 'F6' || e.keyCode === 117) {
|
||
e.preventDefault();
|
||
if (toggledSpeedScale === 1.0) toggledSpeedScale = 2.0;
|
||
else if (toggledSpeedScale === 2.0) toggledSpeedScale = 3.0;
|
||
else if (toggledSpeedScale === 3.0) toggledSpeedScale = 5.0;
|
||
else toggledSpeedScale = 1.0;
|
||
applySpeedScale(isCtrlBoost ? 5.0 : toggledSpeedScale);
|
||
showToast('⚡ ゲーム速度: ' + toggledSpeedScale + '倍速');
|
||
} else if (e.key === 'Control' && !isCtrlBoost) {
|
||
isCtrlBoost = true;
|
||
applySpeedScale(5.0);
|
||
}
|
||
}, true);
|
||
|
||
window.addEventListener('keyup', function(e) {
|
||
if (e.key === 'Control' && isCtrlBoost) {
|
||
isCtrlBoost = false;
|
||
applySpeedScale(toggledSpeedScale);
|
||
}
|
||
}, true);
|
||
|
||
window.addEventListener('blur', function() {
|
||
if (isCtrlBoost) {
|
||
isCtrlBoost = false;
|
||
applySpeedScale(toggledSpeedScale);
|
||
}
|
||
});
|
||
}
|
||
|
||
// =========================================================================
|
||
// 3. 全CG・ギャラリー・回想フラグ解放処理
|
||
// =========================================================================
|
||
function executeUnlockAllGallery(showNotification) {
|
||
let unlockedCount = 0;
|
||
try {
|
||
// パターン1: カスタムHTML5 GalleryStore
|
||
const gs = evalGlobal('typeof GalleryStore !== ""undefined"" ? GalleryStore : null');
|
||
if (gs) {
|
||
if (typeof gs.setUserUnlockAll === 'function') {
|
||
gs.setUserUnlockAll(true);
|
||
unlockedCount++;
|
||
}
|
||
if (typeof gs.load === 'function' && typeof gs.save === 'function') {
|
||
const data = gs.load() || {};
|
||
data.userUnlockAll = true;
|
||
if (Array.isArray(gs.IMAGES)) {
|
||
data.unlockedImages = gs.IMAGES.slice();
|
||
}
|
||
if (Array.isArray(gs.SCENES)) {
|
||
data.unlockedScenes = gs.SCENES.map(function(s) { return s.id || s; });
|
||
}
|
||
gs.save(data);
|
||
unlockedCount++;
|
||
}
|
||
}
|
||
|
||
// パターン2: Game.state (陰キャ薬師など)
|
||
const gState = evalGlobal('typeof Game !== ""undefined"" && Game && Game.state ? Game.state : null');
|
||
if (gState) {
|
||
if (gs && Array.isArray(gs.IMAGES) && Array.isArray(gState.unlockedGalleryImages)) {
|
||
gs.IMAGES.forEach(function(img) {
|
||
if (!gState.unlockedGalleryImages.includes(img)) gState.unlockedGalleryImages.push(img);
|
||
});
|
||
unlockedCount++;
|
||
}
|
||
const herbsObj = evalGlobal('typeof Herbs !== ""undefined"" ? Herbs : null');
|
||
if (herbsObj && Array.isArray(gState.unlockedHerbs)) {
|
||
const allHerbs = herbsObj.ALL || herbsObj.LIST || Object.keys(herbsObj);
|
||
if (Array.isArray(allHerbs)) {
|
||
allHerbs.forEach(function(h) {
|
||
const id = (typeof h === 'object' && h) ? h.id : h;
|
||
if (typeof id === 'string' && !gState.unlockedHerbs.includes(id)) gState.unlockedHerbs.push(id);
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
// パターン3: GameCreator ClientWorld.variable (life.gcdata 永続スイッチ/変数)
|
||
const cw = evalGlobal('typeof ClientWorld !== ""undefined"" ? ClientWorld : null');
|
||
if (cw && cw.variable) {
|
||
const sw = cw.variable.switches || cw.variable.switchs;
|
||
if (Array.isArray(sw)) {
|
||
const maxIdx = Math.max(sw.length, 500);
|
||
for (let i = 1; i < maxIdx; i++) {
|
||
if (typeof cw.variable.setSwitch === 'function') {
|
||
cw.variable.setSwitch(i, 1);
|
||
} else {
|
||
sw[i] = 1;
|
||
}
|
||
}
|
||
unlockedCount++;
|
||
}
|
||
const spg = evalGlobal('typeof SinglePlayerGame !== ""undefined"" ? SinglePlayerGame : null');
|
||
if (spg && typeof spg.saveWorldData === 'function') {
|
||
spg.saveWorldData();
|
||
}
|
||
}
|
||
|
||
// パターン4: localStorage 内の gallery / cg / unlock 系キー
|
||
for (let i = 0; i < localStorage.length; i++) {
|
||
const k = localStorage.key(i);
|
||
if (k && /gallery|cg|recollection|memory|unlock/i.test(k)) {
|
||
try {
|
||
const val = JSON.parse(localStorage.getItem(k));
|
||
if (val && typeof val === 'object' && !Array.isArray(val)) {
|
||
if ('userUnlockAll' in val) val.userUnlockAll = true;
|
||
Object.keys(val).forEach(function(subKey) {
|
||
if (typeof val[subKey] === 'boolean') val[subKey] = true;
|
||
});
|
||
localStorage.setItem(k, JSON.stringify(val));
|
||
unlockedCount++;
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
}
|
||
} catch (err) {
|
||
console.warn('[NwjsMod] Gallery unlock error:', err);
|
||
}
|
||
|
||
if (showNotification) {
|
||
if (unlockedCount > 0) {
|
||
showToast('🔓 全CG・ギャラリー・回想フラグを解放しました!');
|
||
} else {
|
||
showToast('ℹ️ ゲームロード後に再度実行してください');
|
||
}
|
||
}
|
||
return unlockedCount;
|
||
}
|
||
|
||
if (MOD_CONFIG.unlockGallery) {
|
||
window.addEventListener('load', function() {
|
||
setTimeout(function() { executeUnlockAllGallery(false); }, 1500);
|
||
setTimeout(function() { executeUnlockAllGallery(false); }, 4500);
|
||
});
|
||
}
|
||
|
||
// =========================================================================
|
||
// 4. ゲーム内リアルタイム・チートメニュー ([F10] / 右上フローティングボタン)
|
||
// =========================================================================
|
||
if (!MOD_CONFIG.cheatMenu) return;
|
||
|
||
const JP_PROP_LABELS = {
|
||
money: '💰 所持金 (money)',
|
||
gold: '💰 所持金 (gold)',
|
||
debt: '🧾 借金残高 (debt)',
|
||
day: '📅 経過日数 (day)',
|
||
timeSlot: '⏰ 時間帯 (timeSlot)',
|
||
stamina: '❤️ 現在スタミナ (stamina)',
|
||
maxStamina: '💗 最大スタミナ (maxStamina)',
|
||
hp: '❤️ HP',
|
||
maxHp: '💗 最大HP',
|
||
mp: '💧 MP',
|
||
maxMp: '💠 最大MP',
|
||
sp: '⚡ SP',
|
||
atk: '⚔️ 攻撃力 (atk)',
|
||
def: '🛡️ 防御力 (def)',
|
||
level: '⭐ レベル (level)',
|
||
lv: '⭐ レベル (lv)',
|
||
exp: '✨ 経験値 (exp)',
|
||
debtClearedCount: '🏆 借金完済回数 (debtClearedCount)',
|
||
selectedHerb: '🌿 選択中の薬草 (selectedHerb)',
|
||
currentCostume: '👗 現在の衣装 (currentCostume)',
|
||
moveSpeed: '🏃 移動速度 (moveSpeed)'
|
||
};
|
||
|
||
function getPropLabel(key) {
|
||
return JP_PROP_LABELS[key] || key;
|
||
}
|
||
|
||
function refreshGameUI() {
|
||
try {
|
||
const ui = evalGlobal('typeof UI !== ""undefined"" ? UI : null');
|
||
if (ui) {
|
||
if (typeof ui.updateStatus === 'function') ui.updateStatus();
|
||
if (typeof ui.render === 'function') ui.render();
|
||
if (typeof ui.refresh === 'function') ui.refresh();
|
||
}
|
||
const g = evalGlobal('typeof Game !== ""undefined"" ? Game : null');
|
||
if (g) {
|
||
if (typeof g.updateUI === 'function') g.updateUI();
|
||
if (typeof g.refreshUI === 'function') g.refreshUI();
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
|
||
function initCheatUI() {
|
||
if (document.getElementById('nwjs-cheat-root')) return;
|
||
|
||
const style = document.createElement('style');
|
||
style.textContent = `
|
||
#nwjs-cheat-btn {
|
||
position: fixed; top: 10px; right: 10px; z-index: 2147483646;
|
||
background: rgba(15, 23, 42, 0.85); color: #38bdf8;
|
||
border: 1px solid rgba(56, 189, 248, 0.6); border-radius: 6px;
|
||
padding: 5px 10px; font-family: 'Segoe UI', 'Meiryo', sans-serif;
|
||
font-size: 12px; font-weight: bold; cursor: pointer;
|
||
user-select: none; box-shadow: 0 2px 10px rgba(0,0,0,0.5);
|
||
transition: background 0.15s, transform 0.1s;
|
||
}
|
||
#nwjs-cheat-btn:hover { background: rgba(30, 41, 59, 0.98); color: #7dd3fc; }
|
||
#nwjs-cheat-modal {
|
||
position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
|
||
width: min(820px, 94vw); height: min(620px, 90vh);
|
||
background: #0f172a; color: #f1f5f9;
|
||
border: 1px solid #334155; border-radius: 10px;
|
||
z-index: 2147483647; display: none; flex-direction: column;
|
||
font-family: 'Segoe UI', 'Meiryo', sans-serif; font-size: 13px;
|
||
box-shadow: 0 20px 50px rgba(0,0,0,0.85); overflow: hidden;
|
||
}
|
||
.nwjs-cm-header {
|
||
display: flex; align-items: center; justify-content: space-between;
|
||
background: #1e293b; padding: 10px 16px; border-bottom: 1px solid #334155;
|
||
user-select: none;
|
||
}
|
||
.nwjs-cm-title { font-size: 15px; font-weight: bold; color: #38bdf8; display: flex; align-items: center; gap: 8px; }
|
||
.nwjs-cm-badge { font-size: 11px; background: #0369a1; color: #e0f2fe; padding: 2px 8px; border-radius: 10px; }
|
||
.nwjs-cm-close {
|
||
background: #ef4444; color: #fff; border: none; border-radius: 5px;
|
||
padding: 4px 12px; font-weight: bold; cursor: pointer; font-size: 12px;
|
||
}
|
||
.nwjs-cm-close:hover { background: #dc2626; }
|
||
.nwjs-cm-tabs {
|
||
display: flex; background: #162032; border-bottom: 1px solid #334155; padding: 0 12px; gap: 4px;
|
||
}
|
||
.nwjs-cm-tab {
|
||
padding: 9px 14px; cursor: pointer; color: #94a3b8; font-weight: bold;
|
||
border-bottom: 2px solid transparent; transition: all 0.15s; user-select: none;
|
||
}
|
||
.nwjs-cm-tab:hover { color: #e2e8f0; }
|
||
.nwjs-cm-tab.active { color: #38bdf8; border-bottom-color: #38bdf8; background: rgba(56,189,248,0.08); }
|
||
.nwjs-cm-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
|
||
.nwjs-cm-section {
|
||
background: #1e293b; border: 1px solid #334155; border-radius: 8px;
|
||
padding: 12px; margin-bottom: 12px;
|
||
}
|
||
.nwjs-cm-section-title {
|
||
font-size: 13px; font-weight: bold; color: #7dd3fc; margin-bottom: 10px;
|
||
border-bottom: 1px solid #334155; padding-bottom: 5px;
|
||
}
|
||
.nwjs-cm-btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
|
||
.nwjs-cm-btn {
|
||
background: #2563eb; color: #fff; border: 1px solid #3b82f6; border-radius: 5px;
|
||
padding: 5px 11px; font-size: 12px; font-weight: bold; cursor: pointer;
|
||
}
|
||
.nwjs-cm-btn:hover { background: #1d4ed8; }
|
||
.nwjs-cm-btn.green { background: #059669; border-color: #10b981; }
|
||
.nwjs-cm-btn.green:hover { background: #047857; }
|
||
.nwjs-cm-btn.amber { background: #d97706; border-color: #f59e0b; }
|
||
.nwjs-cm-btn.amber:hover { background: #b45309; }
|
||
.nwjs-cm-btn.purple { background: #7c3aed; border-color: #8b5cf6; }
|
||
.nwjs-cm-btn.purple:hover { background: #6d28d9; }
|
||
.nwjs-cm-grid {
|
||
display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 8px;
|
||
}
|
||
.nwjs-cm-row {
|
||
display: flex; align-items: center; justify-content: space-between;
|
||
background: #0f172a; border: 1px solid #334155; border-radius: 6px;
|
||
padding: 6px 10px; gap: 8px;
|
||
}
|
||
.nwjs-cm-label {
|
||
flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||
color: #e2e8f0; font-size: 12px;
|
||
}
|
||
.nwjs-cm-input {
|
||
background: #1e293b; color: #38bdf8; border: 1px solid #475569;
|
||
border-radius: 4px; padding: 4px 8px; width: 120px; font-size: 12px;
|
||
font-family: Consolas, monospace;
|
||
}
|
||
.nwjs-cm-toolbar {
|
||
display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap;
|
||
}
|
||
.nwjs-cm-search {
|
||
background: #0f172a; color: #f8fafc; border: 1px solid #475569;
|
||
border-radius: 5px; padding: 6px 10px; font-size: 12px; flex: 1; min-width: 180px;
|
||
}
|
||
`;
|
||
document.head.appendChild(style);
|
||
|
||
const root = document.createElement('div');
|
||
root.id = 'nwjs-cheat-root';
|
||
|
||
const toggleBtn = document.createElement('div');
|
||
toggleBtn.id = 'nwjs-cheat-btn';
|
||
toggleBtn.textContent = '⚙ チート [F10]';
|
||
toggleBtn.title = 'クリックまたは F10 キーでチートメニューを開閉 (ドラッグで移動可能)';
|
||
|
||
// ドラッグ移動対応
|
||
let isDragging = false, dragStartX = 0, dragStartY = 0, btnStartRight = 10, btnStartTop = 10, moved = false;
|
||
toggleBtn.addEventListener('mousedown', function(e) {
|
||
isDragging = true; moved = false;
|
||
dragStartX = e.clientX; dragStartY = e.clientY;
|
||
const rect = toggleBtn.getBoundingClientRect();
|
||
btnStartRight = window.innerWidth - rect.right;
|
||
btnStartTop = rect.top;
|
||
e.stopPropagation();
|
||
});
|
||
window.addEventListener('mousemove', function(e) {
|
||
if (!isDragging) return;
|
||
const dx = e.clientX - dragStartX;
|
||
const dy = e.clientY - dragStartY;
|
||
if (Math.abs(dx) > 4 || Math.abs(dy) > 4) moved = true;
|
||
toggleBtn.style.right = Math.max(4, Math.min(window.innerWidth - 80, btnStartRight - dx)) + 'px';
|
||
toggleBtn.style.top = Math.max(4, Math.min(window.innerHeight - 36, btnStartTop + dy)) + 'px';
|
||
});
|
||
window.addEventListener('mouseup', function() { isDragging = false; });
|
||
|
||
const modal = document.createElement('div');
|
||
modal.id = 'nwjs-cheat-modal';
|
||
|
||
// モーダル内のイベントがゲームキャンバスへ伝播しないように遮断
|
||
['mousedown', 'mouseup', 'click', 'dblclick', 'wheel', 'keydown', 'keyup', 'keypress', 'contextmenu'].forEach(function(evName) {
|
||
modal.addEventListener(evName, function(e) { e.stopPropagation(); });
|
||
});
|
||
|
||
let activeTab = 'status';
|
||
let varSearchText = '';
|
||
let varValueFilter = '';
|
||
let gcVarCategory = 'player_var';
|
||
|
||
function toggleModal() {
|
||
if (modal.style.display === 'flex') {
|
||
modal.style.display = 'none';
|
||
} else {
|
||
modal.style.display = 'flex';
|
||
renderModal();
|
||
}
|
||
}
|
||
|
||
toggleBtn.addEventListener('click', function(e) {
|
||
e.stopPropagation();
|
||
if (!moved) toggleModal();
|
||
});
|
||
|
||
window.addEventListener('keydown', function(e) {
|
||
if (e.key === 'F10' || e.keyCode === 121) {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
toggleModal();
|
||
} else if (e.key === 'Escape' && modal.style.display === 'flex') {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
modal.style.display = 'none';
|
||
}
|
||
}, true);
|
||
|
||
function renderModal() {
|
||
const kind = detectRuntimeKind();
|
||
const kindLabel = kind === 'gc' ? 'GameCreator エンジン' : (kind === 'custom_state' ? 'HTML5 ステートエンジン' : '汎用 NW.js エンジン');
|
||
|
||
modal.innerHTML = '';
|
||
|
||
// Header
|
||
const header = document.createElement('div');
|
||
header.className = 'nwjs-cm-header';
|
||
header.innerHTML = '<div class=""nwjs-cm-title""><span>🎛 NW.js リアルタイム改造&チートメニュー</span><span class=""nwjs-cm-badge"">' + kindLabel + '</span></div>';
|
||
const closeBtn = document.createElement('button');
|
||
closeBtn.className = 'nwjs-cm-close';
|
||
closeBtn.textContent = '✕ 閉じる [F10 / ESC]';
|
||
closeBtn.onclick = function() { modal.style.display = 'none'; };
|
||
header.appendChild(closeBtn);
|
||
modal.appendChild(header);
|
||
|
||
// Tabs
|
||
const tabs = document.createElement('div');
|
||
tabs.className = 'nwjs-cm-tabs';
|
||
const tabDefs = [
|
||
{ id: 'status', label: '💎 ステータス・クイック改造' },
|
||
{ id: 'vars', label: '🔢 変数・スイッチ・数値検索' },
|
||
{ id: 'items', label: '🎒 アイテム・所持品' },
|
||
{ id: 'storage', label: '💾 ストレージ・システム' }
|
||
];
|
||
tabDefs.forEach(function(t) {
|
||
const tabEl = document.createElement('div');
|
||
tabEl.className = 'nwjs-cm-tab' + (activeTab === t.id ? ' active' : '');
|
||
tabEl.textContent = t.label;
|
||
tabEl.onclick = function() { activeTab = t.id; renderModal(); };
|
||
tabs.appendChild(tabEl);
|
||
});
|
||
modal.appendChild(tabs);
|
||
|
||
// Body
|
||
const body = document.createElement('div');
|
||
body.className = 'nwjs-cm-body';
|
||
|
||
if (activeTab === 'status') {
|
||
renderStatusTab(body, kind);
|
||
} else if (activeTab === 'vars') {
|
||
renderVarsTab(body, kind);
|
||
} else if (activeTab === 'items') {
|
||
renderItemsTab(body, kind);
|
||
} else if (activeTab === 'storage') {
|
||
renderStorageTab(body, kind);
|
||
}
|
||
|
||
modal.appendChild(body);
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// タブ1: ステータス・クイック改造
|
||
// ---------------------------------------------------------------------
|
||
function renderStatusTab(container, kind) {
|
||
// 共通クイック機能セクション
|
||
const quickSec = document.createElement('div');
|
||
quickSec.className = 'nwjs-cm-section';
|
||
quickSec.innerHTML = '<div class=""nwjs-cm-section-title"">⚡ クイックアクション・スピード変更・全解放</div>';
|
||
const quickRow = document.createElement('div');
|
||
quickRow.className = 'nwjs-cm-btn-row';
|
||
|
||
[1, 2, 3, 5].forEach(function(spd) {
|
||
const b = document.createElement('button');
|
||
b.className = 'nwjs-cm-btn' + (toggledSpeedScale === spd ? ' green' : '');
|
||
b.textContent = '⏩ ゲーム速度 ×' + spd;
|
||
b.onclick = function() {
|
||
toggledSpeedScale = spd;
|
||
applySpeedScale(spd);
|
||
showToast('⚡ ゲーム速度を ' + spd + '倍 に設定しました');
|
||
renderModal();
|
||
};
|
||
quickRow.appendChild(b);
|
||
});
|
||
|
||
const unlockBtn = document.createElement('button');
|
||
unlockBtn.className = 'nwjs-cm-btn purple';
|
||
unlockBtn.textContent = '🔓 全CG・ギャラリー・回想フラグを今すぐ解放';
|
||
unlockBtn.onclick = function() {
|
||
executeUnlockAllGallery(true);
|
||
renderModal();
|
||
};
|
||
quickRow.appendChild(unlockBtn);
|
||
|
||
const devBtn = document.createElement('button');
|
||
devBtn.className = 'nwjs-cm-btn amber';
|
||
devBtn.textContent = '🛠 DevTools (F12) を開く';
|
||
devBtn.onclick = function() {
|
||
try { nw.Window.get().showDevTools(); } catch (e) {}
|
||
};
|
||
quickRow.appendChild(devBtn);
|
||
|
||
quickSec.appendChild(quickRow);
|
||
container.appendChild(quickSec);
|
||
|
||
if (kind === 'gc') {
|
||
renderGcStatusSection(container);
|
||
} else if (kind === 'custom_state') {
|
||
renderCustomStateSection(container);
|
||
} else {
|
||
renderGenericStatusSection(container);
|
||
}
|
||
}
|
||
|
||
function renderGcStatusSection(container) {
|
||
const game = evalGlobal('Game');
|
||
const projectPlayer = evalGlobal('typeof ProjectPlayer !== ""undefined"" ? ProjectPlayer : null');
|
||
if (!game || !game.player || !game.player.data) {
|
||
const msg = document.createElement('div');
|
||
msg.className = 'nwjs-cm-section';
|
||
msg.textContent = 'ℹ️ セーブデータをロードするか、ゲーム本編を開始するとプレイヤーステータスが表示されます。';
|
||
container.appendChild(msg);
|
||
return;
|
||
}
|
||
|
||
const pData = game.player.data;
|
||
const sec = document.createElement('div');
|
||
sec.className = 'nwjs-cm-section';
|
||
sec.innerHTML = '<div class=""nwjs-cm-section-title"">💰 GameCreator プレイヤー基本ステータス・移動速度</div>';
|
||
|
||
const btnRow = document.createElement('div');
|
||
btnRow.className = 'nwjs-cm-btn-row';
|
||
|
||
const addGold10k = document.createElement('button');
|
||
addGold10k.className = 'nwjs-cm-btn green';
|
||
addGold10k.textContent = '💰 所持金 +10,000';
|
||
addGold10k.onclick = function() {
|
||
if (projectPlayer && typeof projectPlayer.increaseGold === 'function') projectPlayer.increaseGold(10000);
|
||
else pData.gold = (Number(pData.gold) || 0) + 10000;
|
||
showToast('💰 所持金 +10,000');
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(addGold10k);
|
||
|
||
const maxGoldBtn = document.createElement('button');
|
||
maxGoldBtn.className = 'nwjs-cm-btn green';
|
||
maxGoldBtn.textContent = '💰 所持金 9,999,999';
|
||
maxGoldBtn.onclick = function() {
|
||
pData.gold = 9999999;
|
||
showToast('💰 所持金を 9,999,999 に設定しました');
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(maxGoldBtn);
|
||
|
||
if (game.player.sceneObject) {
|
||
const so = game.player.sceneObject;
|
||
const throughBtn = document.createElement('button');
|
||
throughBtn.className = 'nwjs-cm-btn amber';
|
||
throughBtn.textContent = so.through ? '🧱 壁抜けモード: ON (クリックでOFF)' : '🧱 壁抜けモード: OFF (クリックでON)';
|
||
throughBtn.onclick = function() {
|
||
so.through = !so.through;
|
||
showToast('🧱 壁抜けモード: ' + (so.through ? 'ON' : 'OFF'));
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(throughBtn);
|
||
}
|
||
|
||
sec.appendChild(btnRow);
|
||
|
||
const grid = document.createElement('div');
|
||
grid.className = 'nwjs-cm-grid';
|
||
|
||
// pData のプリミティブプロパティ
|
||
Object.keys(pData).forEach(function(k) {
|
||
const v = pData[k];
|
||
if (typeof v === 'number' || typeof v === 'string' || typeof v === 'boolean') {
|
||
grid.appendChild(createPropertyEditorRow(getPropLabel(k), v, function(newVal) {
|
||
pData[k] = newVal;
|
||
showToast('✔ ' + k + ' = ' + newVal);
|
||
}));
|
||
}
|
||
});
|
||
|
||
// sceneObject の速度・座標・数値プロパティ
|
||
if (game.player.sceneObject) {
|
||
const so = game.player.sceneObject;
|
||
['moveSpeed', 'x', 'y', 'avatarFPS', 'avatarAlpha'].forEach(function(k) {
|
||
if (typeof so[k] === 'number') {
|
||
grid.appendChild(createPropertyEditorRow('🏃 キャラ: ' + getPropLabel(k), so[k], function(newVal) {
|
||
so[k] = newVal;
|
||
showToast('✔ ' + k + ' = ' + newVal);
|
||
}));
|
||
}
|
||
});
|
||
}
|
||
|
||
sec.appendChild(grid);
|
||
container.appendChild(sec);
|
||
|
||
// パーティメンバー (party) が存在する場合
|
||
if (Array.isArray(pData.party) && pData.party.length > 0) {
|
||
const partySec = document.createElement('div');
|
||
partySec.className = 'nwjs-cm-section';
|
||
partySec.innerHTML = '<div class=""nwjs-cm-section-title"">⚔️ パーティ・アクターステータス</div>';
|
||
const partyGrid = document.createElement('div');
|
||
partyGrid.className = 'nwjs-cm-grid';
|
||
|
||
pData.party.forEach(function(member, idx) {
|
||
if (!member || typeof member !== 'object') return;
|
||
const actor = member.actor || member;
|
||
const actorName = actor.name || ('メンバー #' + (idx + 1));
|
||
Object.keys(actor).forEach(function(k) {
|
||
if (typeof actor[k] === 'number') {
|
||
partyGrid.appendChild(createPropertyEditorRow('[' + actorName + '] ' + getPropLabel(k), actor[k], function(newVal) {
|
||
actor[k] = newVal;
|
||
}));
|
||
}
|
||
});
|
||
if (typeof member.lv === 'number') {
|
||
partyGrid.appendChild(createPropertyEditorRow('[' + actorName + '] Lv', member.lv, function(newVal) {
|
||
member.lv = newVal;
|
||
}));
|
||
}
|
||
});
|
||
|
||
partySec.appendChild(partyGrid);
|
||
container.appendChild(partySec);
|
||
}
|
||
}
|
||
|
||
function renderCustomStateSection(container) {
|
||
const game = evalGlobal('Game');
|
||
const gState = game ? game.state : null;
|
||
if (!gState) return;
|
||
|
||
const sec = document.createElement('div');
|
||
sec.className = 'nwjs-cm-section';
|
||
sec.innerHTML = '<div class=""nwjs-cm-section-title"">💎 プレイヤーステータス編集 (Game.state)</div>';
|
||
|
||
const btnRow = document.createElement('div');
|
||
btnRow.className = 'nwjs-cm-btn-row';
|
||
|
||
if ('money' in gState) {
|
||
const b1 = document.createElement('button');
|
||
b1.className = 'nwjs-cm-btn green';
|
||
b1.textContent = '💰 所持金 +100,000';
|
||
b1.onclick = function() {
|
||
gState.money = (Number(gState.money) || 0) + 100000;
|
||
refreshGameUI();
|
||
showToast('💰 所持金 +100,000');
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(b1);
|
||
|
||
const b2 = document.createElement('button');
|
||
b2.className = 'nwjs-cm-btn green';
|
||
b2.textContent = '💰 所持金 9,999,999';
|
||
b2.onclick = function() {
|
||
gState.money = 9999999;
|
||
refreshGameUI();
|
||
showToast('💰 所持金を 9,999,999 にしました');
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(b2);
|
||
}
|
||
|
||
if ('debt' in gState) {
|
||
const bDebt = document.createElement('button');
|
||
bDebt.className = 'nwjs-cm-btn amber';
|
||
bDebt.textContent = '🧾 借金を 0 にする';
|
||
bDebt.onclick = function() {
|
||
gState.debt = 0;
|
||
refreshGameUI();
|
||
showToast('🧾 借金を 0 にしました');
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(bDebt);
|
||
}
|
||
|
||
if ('stamina' in gState) {
|
||
const bStam = document.createElement('button');
|
||
bStam.className = 'nwjs-cm-btn purple';
|
||
bStam.textContent = '❤️ スタミナ全快&最大999';
|
||
bStam.onclick = function() {
|
||
if ('maxStamina' in gState) gState.maxStamina = Math.max(999, Number(gState.maxStamina) || 999);
|
||
gState.stamina = gState.maxStamina || 999;
|
||
refreshGameUI();
|
||
showToast('❤️ スタミナを 999 に強化・全回復しました');
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(bStam);
|
||
}
|
||
|
||
sec.appendChild(btnRow);
|
||
|
||
const grid = document.createElement('div');
|
||
grid.className = 'nwjs-cm-grid';
|
||
|
||
Object.keys(gState).forEach(function(k) {
|
||
const v = gState[k];
|
||
if (typeof v === 'number' || typeof v === 'string' || typeof v === 'boolean') {
|
||
grid.appendChild(createPropertyEditorRow(getPropLabel(k), v, function(newVal) {
|
||
gState[k] = newVal;
|
||
refreshGameUI();
|
||
showToast('✔ ' + k + ' = ' + newVal);
|
||
}));
|
||
}
|
||
});
|
||
|
||
sec.appendChild(grid);
|
||
container.appendChild(sec);
|
||
}
|
||
|
||
function renderGenericStatusSection(container) {
|
||
const sec = document.createElement('div');
|
||
sec.className = 'nwjs-cm-section';
|
||
sec.innerHTML = '<div class=""nwjs-cm-section-title"">🔍 自動検出されたグローバルステータス変数</div>';
|
||
const grid = document.createElement('div');
|
||
grid.className = 'nwjs-cm-grid';
|
||
|
||
const candidateNames = ['Game', 'game', 'player', 'Player', 'state', 'State', 'app', 'App', 'saveData', 'SaveData', 'userData'];
|
||
let count = 0;
|
||
candidateNames.forEach(function(rootName) {
|
||
const obj = evalGlobal('typeof ' + rootName + ' !== ""undefined"" ? ' + rootName + ' : null');
|
||
if (obj && typeof obj === 'object') {
|
||
Object.keys(obj).forEach(function(k) {
|
||
const v = obj[k];
|
||
if (typeof v === 'number' || typeof v === 'string' || typeof v === 'boolean') {
|
||
grid.appendChild(createPropertyEditorRow(rootName + '.' + getPropLabel(k), v, function(newVal) {
|
||
obj[k] = newVal;
|
||
showToast('✔ ' + rootName + '.' + k + ' = ' + newVal);
|
||
}));
|
||
count++;
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
if (count === 0) {
|
||
const info = document.createElement('div');
|
||
info.style.color = '#94a3b8';
|
||
info.textContent = '「🔢 変数・スイッチ・数値検索」タブまたは「💾 ストレージ」タブから任意のゲーム内データを検索・編集できます。';
|
||
sec.appendChild(info);
|
||
} else {
|
||
sec.appendChild(grid);
|
||
}
|
||
container.appendChild(sec);
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// タブ2: 変数・スイッチ・数値ピンポイント検索
|
||
// ---------------------------------------------------------------------
|
||
function renderVarsTab(container, kind) {
|
||
const toolbar = document.createElement('div');
|
||
toolbar.className = 'nwjs-cm-toolbar';
|
||
|
||
const searchInput = document.createElement('input');
|
||
searchInput.className = 'nwjs-cm-search';
|
||
searchInput.placeholder = '🔍 変数名・ID・文字列でフィルタ...';
|
||
searchInput.value = varSearchText;
|
||
searchInput.oninput = function() {
|
||
varSearchText = searchInput.value;
|
||
renderVarListArea(listHost, kind);
|
||
};
|
||
toolbar.appendChild(searchInput);
|
||
|
||
const valInput = document.createElement('input');
|
||
valInput.className = 'nwjs-cm-search';
|
||
valInput.style.maxWidth = '180px';
|
||
valInput.placeholder = '🎯 現在の値で一致検索 (例: 500)';
|
||
valInput.value = varValueFilter;
|
||
valInput.oninput = function() {
|
||
varValueFilter = valInput.value.trim();
|
||
renderVarListArea(listHost, kind);
|
||
};
|
||
toolbar.appendChild(valInput);
|
||
|
||
if (kind === 'gc') {
|
||
const catSelect = document.createElement('select');
|
||
catSelect.className = 'nwjs-cm-search';
|
||
catSelect.style.maxWidth = '230px';
|
||
[
|
||
{ id: 'player_var', label: '📊 プレイヤー数値変数 (variables)' },
|
||
{ id: 'player_sw', label: '🔘 プレイヤースイッチ (switches)' },
|
||
{ id: 'player_str', label: '📝 プレイヤー文字列 (strings)' },
|
||
{ id: 'world_var', label: '🌍 ワールド永続変数・スイッチ (CG/回想)' }
|
||
].forEach(function(c) {
|
||
const opt = document.createElement('option');
|
||
opt.value = c.id;
|
||
opt.textContent = c.label;
|
||
if (gcVarCategory === c.id) opt.selected = true;
|
||
catSelect.appendChild(opt);
|
||
});
|
||
catSelect.onchange = function() {
|
||
gcVarCategory = catSelect.value;
|
||
renderVarListArea(listHost, kind);
|
||
};
|
||
toolbar.appendChild(catSelect);
|
||
}
|
||
|
||
container.appendChild(toolbar);
|
||
|
||
// GameCreator の場合、任意の変数IDを指定して直接セットできるフォームを追加
|
||
if (kind === 'gc') {
|
||
const directBar = document.createElement('div');
|
||
directBar.className = 'nwjs-cm-toolbar';
|
||
directBar.innerHTML = '<span style=""color:#94a3b8;font-size:12px;"">➕ 指定IDの変数/スイッチを直接設定:</span>';
|
||
const idBox = document.createElement('input');
|
||
idBox.className = 'nwjs-cm-input';
|
||
idBox.placeholder = '変数ID (例: 2004)';
|
||
idBox.type = 'number';
|
||
const valBox = document.createElement('input');
|
||
valBox.className = 'nwjs-cm-input';
|
||
valBox.placeholder = '新しい値';
|
||
const setBtn = document.createElement('button');
|
||
setBtn.className = 'nwjs-cm-btn green';
|
||
setBtn.textContent = '設定・反映';
|
||
setBtn.onclick = function() {
|
||
const targetId = parseInt(idBox.value, 10);
|
||
if (isNaN(targetId) || targetId < 0) return;
|
||
const game = evalGlobal('Game');
|
||
if (!game || !game.player || !game.player.variable) return;
|
||
const pv = game.player.variable;
|
||
if (gcVarCategory === 'player_str') {
|
||
if (typeof pv.setString === 'function') pv.setString(targetId, valBox.value);
|
||
else pv.strings[targetId] = valBox.value;
|
||
} else if (gcVarCategory === 'player_sw') {
|
||
const sv = (valBox.value === '1' || valBox.value === 'true') ? 1 : 0;
|
||
if (typeof pv.setSwitch === 'function') pv.setSwitch(targetId, sv);
|
||
else (pv.switches || pv.switchs)[targetId] = sv;
|
||
} else {
|
||
const nv = Number(valBox.value) || 0;
|
||
if (typeof pv.setVariable === 'function') pv.setVariable(targetId, nv);
|
||
else pv.variables[targetId] = nv;
|
||
}
|
||
showToast('✔ ID ' + targetId + ' を更新しました');
|
||
renderVarListArea(listHost, kind);
|
||
};
|
||
directBar.appendChild(idBox);
|
||
directBar.appendChild(valBox);
|
||
directBar.appendChild(setBtn);
|
||
container.appendChild(directBar);
|
||
}
|
||
|
||
const listHost = document.createElement('div');
|
||
container.appendChild(listHost);
|
||
renderVarListArea(listHost, kind);
|
||
}
|
||
|
||
function renderVarListArea(listHost, kind) {
|
||
listHost.innerHTML = '';
|
||
const grid = document.createElement('div');
|
||
grid.className = 'nwjs-cm-grid';
|
||
const q = varSearchText.toLowerCase();
|
||
let shown = 0;
|
||
const MAX_SHOW = 250;
|
||
|
||
if (kind === 'gc') {
|
||
const game = evalGlobal('Game');
|
||
const cw = evalGlobal('typeof ClientWorld !== ""undefined"" ? ClientWorld : null');
|
||
const pv = (game && game.player) ? game.player.variable : null;
|
||
|
||
if (gcVarCategory === 'world_var' && cw && cw.variable) {
|
||
const wv = cw.variable;
|
||
const vars = wv.variables || [];
|
||
const sws = wv.switches || wv.switchs || [];
|
||
for (let i = 0; i < vars.length && shown < MAX_SHOW; i++) {
|
||
if (vars[i] === null || vars[i] === undefined) continue;
|
||
const label = '🌍 ワールド変数 [' + i + ']';
|
||
if (q && !label.toLowerCase().includes(q) && !String(vars[i]).toLowerCase().includes(q)) continue;
|
||
if (varValueFilter && String(vars[i]) !== varValueFilter) continue;
|
||
(function(idx) {
|
||
grid.appendChild(createPropertyEditorRow(label, vars[idx], function(nv) {
|
||
if (typeof wv.setVariable === 'function') wv.setVariable(idx, nv);
|
||
else vars[idx] = nv;
|
||
}));
|
||
})(i);
|
||
shown++;
|
||
}
|
||
for (let i = 0; i < sws.length && shown < MAX_SHOW; i++) {
|
||
if (sws[i] === null || sws[i] === undefined) continue;
|
||
const label = '🌍 ワールドスイッチ [' + i + ']';
|
||
if (q && !label.toLowerCase().includes(q)) continue;
|
||
if (varValueFilter && String(sws[i]) !== varValueFilter) continue;
|
||
(function(idx) {
|
||
grid.appendChild(createPropertyEditorRow(label, Boolean(sws[idx]), function(nv) {
|
||
const v = nv ? 1 : 0;
|
||
if (typeof wv.setSwitch === 'function') wv.setSwitch(idx, v);
|
||
else sws[idx] = v;
|
||
}));
|
||
})(i);
|
||
shown++;
|
||
}
|
||
} else if (pv) {
|
||
// 文字列配列にラベルヒントがあるか参照
|
||
const strs = pv.strings || [];
|
||
if (gcVarCategory === 'player_var') {
|
||
const vars = pv.variables || [];
|
||
for (let i = 0; i < vars.length && shown < MAX_SHOW; i++) {
|
||
if (vars[i] === null || vars[i] === undefined) continue;
|
||
const hint = (typeof strs[i] === 'string' && strs[i].length < 24) ? (' (' + strs[i] + ')') : '';
|
||
const label = '変数 [' + i + ']' + hint;
|
||
if (q && !label.toLowerCase().includes(q) && !String(vars[i]).toLowerCase().includes(q)) continue;
|
||
if (varValueFilter && String(vars[i]) !== varValueFilter) continue;
|
||
(function(idx) {
|
||
grid.appendChild(createPropertyEditorRow(label, vars[idx], function(nv) {
|
||
if (typeof pv.setVariable === 'function') pv.setVariable(idx, nv);
|
||
else vars[idx] = nv;
|
||
showToast('✔ 変数[' + idx + '] = ' + nv);
|
||
}));
|
||
})(i);
|
||
shown++;
|
||
}
|
||
} else if (gcVarCategory === 'player_sw') {
|
||
const sws = pv.switches || pv.switchs || [];
|
||
for (let i = 0; i < sws.length && shown < MAX_SHOW; i++) {
|
||
if (sws[i] === null || sws[i] === undefined) continue;
|
||
const label = 'スイッチ [' + i + ']';
|
||
if (q && !label.toLowerCase().includes(q)) continue;
|
||
if (varValueFilter && String(sws[i]) !== varValueFilter) continue;
|
||
(function(idx) {
|
||
grid.appendChild(createPropertyEditorRow(label, Boolean(sws[idx]), function(nv) {
|
||
const v = nv ? 1 : 0;
|
||
if (typeof pv.setSwitch === 'function') pv.setSwitch(idx, v);
|
||
else sws[idx] = v;
|
||
showToast('✔ スイッチ[' + idx + '] = ' + v);
|
||
}));
|
||
})(i);
|
||
shown++;
|
||
}
|
||
} else if (gcVarCategory === 'player_str') {
|
||
for (let i = 0; i < strs.length && shown < MAX_SHOW; i++) {
|
||
if (strs[i] === null || strs[i] === undefined) continue;
|
||
const label = '文字列 [' + i + ']';
|
||
if (q && !label.toLowerCase().includes(q) && !String(strs[i]).toLowerCase().includes(q)) continue;
|
||
if (varValueFilter && String(strs[i]) !== varValueFilter) continue;
|
||
(function(idx) {
|
||
grid.appendChild(createPropertyEditorRow(label, strs[idx], function(nv) {
|
||
if (typeof pv.setString === 'function') pv.setString(idx, nv);
|
||
else strs[idx] = nv;
|
||
showToast('✔ 文字列[' + idx + '] を更新');
|
||
}));
|
||
})(i);
|
||
shown++;
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
// カスタムHTML5 / 汎用: Game, window 内のオブジェクトツリーを深さ3まで走査
|
||
const roots = [];
|
||
const gObj = evalGlobal('typeof Game !== ""undefined"" ? Game : null');
|
||
if (gObj) roots.push({ name: 'Game', obj: gObj });
|
||
['state', 'player', 'app', 'saveData'].forEach(function(rn) {
|
||
const o = evalGlobal('typeof ' + rn + ' !== ""undefined"" ? ' + rn + ' : null');
|
||
if (o && typeof o === 'object' && o !== gObj) roots.push({ name: rn, obj: o });
|
||
});
|
||
|
||
const visited = new Set();
|
||
function walk(obj, prefix, depth) {
|
||
if (!obj || typeof obj !== 'object' || depth > 3 || shown >= MAX_SHOW) return;
|
||
if (visited.has(obj)) return;
|
||
visited.add(obj);
|
||
|
||
Object.keys(obj).forEach(function(k) {
|
||
if (shown >= MAX_SHOW) return;
|
||
if (k.startsWith('_') && depth > 1) return;
|
||
let val;
|
||
try { val = obj[k]; } catch (e) { return; }
|
||
const path = prefix + '.' + k;
|
||
if (typeof val === 'number' || typeof val === 'string' || typeof val === 'boolean') {
|
||
if (q && !path.toLowerCase().includes(q) && !String(val).toLowerCase().includes(q)) return;
|
||
if (varValueFilter && String(val) !== varValueFilter) return;
|
||
grid.appendChild(createPropertyEditorRow(path, val, function(nv) {
|
||
obj[k] = nv;
|
||
refreshGameUI();
|
||
showToast('✔ ' + path + ' = ' + nv);
|
||
}));
|
||
shown++;
|
||
} else if (val && typeof val === 'object' && !(val instanceof Node) && !(val instanceof Window)) {
|
||
walk(val, path, depth + 1);
|
||
}
|
||
});
|
||
}
|
||
|
||
roots.forEach(function(r) { walk(r.obj, r.name, 0); });
|
||
}
|
||
|
||
listHost.appendChild(grid);
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// タブ3: アイテム・インベントリ
|
||
// ---------------------------------------------------------------------
|
||
function renderItemsTab(container, kind) {
|
||
if (kind === 'gc') {
|
||
const game = evalGlobal('Game');
|
||
const gameData = evalGlobal('typeof GameData !== ""undefined"" ? GameData : null');
|
||
const projectPlayer = evalGlobal('typeof ProjectPlayer !== ""undefined"" ? ProjectPlayer : null');
|
||
if (!game || !game.player || !game.player.data) {
|
||
container.innerHTML = '<div class=""nwjs-cm-section"">ℹ️ ゲーム本編を開始すると所持品・全アイテムリストが表示されます。</div>';
|
||
return;
|
||
}
|
||
|
||
const pkg = game.player.data.package || [];
|
||
const curSec = document.createElement('div');
|
||
curSec.className = 'nwjs-cm-section';
|
||
curSec.innerHTML = '<div class=""nwjs-cm-section-title"">🎒 現在の所持アイテム (Game.player.data.package)</div>';
|
||
const curGrid = document.createElement('div');
|
||
curGrid.className = 'nwjs-cm-grid';
|
||
|
||
pkg.forEach(function(entry) {
|
||
if (!entry) return;
|
||
const itemId = entry.item ? entry.item.id : entry.id;
|
||
const itemName = (entry.item && entry.item.name) ? entry.item.name : ('アイテム #' + itemId);
|
||
curGrid.appendChild(createPropertyEditorRow('[' + itemId + '] ' + itemName, entry.number || 1, function(nv) {
|
||
entry.number = Math.max(0, Math.floor(Number(nv) || 0));
|
||
showToast('✔ ' + itemName + ' ×' + entry.number);
|
||
}));
|
||
});
|
||
curSec.appendChild(curGrid);
|
||
container.appendChild(curSec);
|
||
|
||
// 全登録アイテムリスト (module 1) から追加
|
||
const allSec = document.createElement('div');
|
||
allSec.className = 'nwjs-cm-section';
|
||
allSec.innerHTML = '<div class=""nwjs-cm-section-title"">✨ ゲーム内の全登録アイテムから入手・追加</div>';
|
||
|
||
const allGrid = document.createElement('div');
|
||
allGrid.className = 'nwjs-cm-grid';
|
||
|
||
const foundItems = [];
|
||
if (gameData && typeof gameData.getModuleData === 'function') {
|
||
// 代表的なIDレンジ (1..200, 1001..1100, 2001..2100, 3001..3100, 4001..4100, 5001..5100) をスキャン
|
||
const ranges = [[1, 100], [1001, 1050], [2001, 2050], [3001, 3050], [4001, 4050], [5001, 5050]];
|
||
ranges.forEach(function(r) {
|
||
for (let id = r[0]; id <= r[1]; id++) {
|
||
try {
|
||
const m = gameData.getModuleData(1, id);
|
||
if (m && m.name) {
|
||
foundItems.push({ id: id, name: m.name });
|
||
}
|
||
} catch (e) {}
|
||
}
|
||
});
|
||
}
|
||
|
||
foundItems.forEach(function(item) {
|
||
const row = document.createElement('div');
|
||
row.className = 'nwjs-cm-row';
|
||
row.innerHTML = '<div class=""nwjs-cm-label"">[' + item.id + '] ' + item.name + '</div>';
|
||
const b1 = document.createElement('button');
|
||
b1.className = 'nwjs-cm-btn green';
|
||
b1.textContent = '+1';
|
||
b1.onclick = function() {
|
||
if (projectPlayer && typeof projectPlayer.changeItemNumber === 'function') {
|
||
projectPlayer.changeItemNumber(item.id, 1, false);
|
||
}
|
||
showToast('🎒 ' + item.name + ' +1 入手!');
|
||
renderModal();
|
||
};
|
||
const b99 = document.createElement('button');
|
||
b99.className = 'nwjs-cm-btn purple';
|
||
b99.textContent = '+99';
|
||
b99.onclick = function() {
|
||
if (projectPlayer && typeof projectPlayer.changeItemNumber === 'function') {
|
||
projectPlayer.changeItemNumber(item.id, 99, false);
|
||
}
|
||
showToast('🎒 ' + item.name + ' +99 入手!');
|
||
renderModal();
|
||
};
|
||
row.appendChild(b1);
|
||
row.appendChild(b99);
|
||
allGrid.appendChild(row);
|
||
});
|
||
|
||
allSec.appendChild(allGrid);
|
||
container.appendChild(allSec);
|
||
} else {
|
||
// カスタムHTML5 (Game.state.inventory / unlockedHerbs / unlockedCostumes)
|
||
const gState = evalGlobal('typeof Game !== ""undefined"" && Game ? Game.state : null');
|
||
if (gState && gState.inventory && typeof gState.inventory === 'object') {
|
||
const invSec = document.createElement('div');
|
||
invSec.className = 'nwjs-cm-section';
|
||
invSec.innerHTML = '<div class=""nwjs-cm-section-title"">🎒 所持インベントリ (Game.state.inventory)</div>';
|
||
|
||
const btnRow = document.createElement('div');
|
||
btnRow.className = 'nwjs-cm-btn-row';
|
||
const all99Btn = document.createElement('button');
|
||
all99Btn.className = 'nwjs-cm-btn green';
|
||
all99Btn.textContent = '📦 現在の全所持アイテムを 99個 にする';
|
||
all99Btn.onclick = function() {
|
||
Object.keys(gState.inventory).forEach(function(k) { gState.inventory[k] = 99; });
|
||
refreshGameUI();
|
||
showToast('📦 全所持アイテムを 99個 にしました');
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(all99Btn);
|
||
|
||
// 新規アイテムID追加フォーム
|
||
const newKeyInput = document.createElement('input');
|
||
newKeyInput.className = 'nwjs-cm-input';
|
||
newKeyInput.placeholder = 'アイテムID';
|
||
const addKeyBtn = document.createElement('button');
|
||
addKeyBtn.className = 'nwjs-cm-btn purple';
|
||
addKeyBtn.textContent = '➕ 99個追加';
|
||
addKeyBtn.onclick = function() {
|
||
const k = newKeyInput.value.trim();
|
||
if (!k) return;
|
||
gState.inventory[k] = 99;
|
||
refreshGameUI();
|
||
showToast('✔ ' + k + ' ×99 を追加しました');
|
||
renderModal();
|
||
};
|
||
btnRow.appendChild(newKeyInput);
|
||
btnRow.appendChild(addKeyBtn);
|
||
invSec.appendChild(btnRow);
|
||
|
||
const invGrid = document.createElement('div');
|
||
invGrid.className = 'nwjs-cm-grid';
|
||
Object.keys(gState.inventory).forEach(function(k) {
|
||
invGrid.appendChild(createPropertyEditorRow('📦 ' + k, gState.inventory[k], function(nv) {
|
||
gState.inventory[k] = Number(nv) || 0;
|
||
refreshGameUI();
|
||
}));
|
||
});
|
||
invSec.appendChild(invGrid);
|
||
container.appendChild(invSec);
|
||
} else {
|
||
container.innerHTML = '<div class=""nwjs-cm-section"">ℹ️ このゲームのアイテムデータは「🔢 変数・スイッチ・数値検索」タブから検索・変更できます。</div>';
|
||
}
|
||
}
|
||
}
|
||
|
||
// ---------------------------------------------------------------------
|
||
// タブ4: ストレージ (localStorage)
|
||
// ---------------------------------------------------------------------
|
||
function renderStorageTab(container) {
|
||
const sec = document.createElement('div');
|
||
sec.className = 'nwjs-cm-section';
|
||
sec.innerHTML = '<div class=""nwjs-cm-section-title"">💾 localStorage データ一覧・直接編集</div>';
|
||
|
||
for (let i = 0; i < localStorage.length; i++) {
|
||
const k = localStorage.key(i);
|
||
if (!k) continue;
|
||
const val = localStorage.getItem(k);
|
||
const row = document.createElement('div');
|
||
row.className = 'nwjs-cm-row';
|
||
row.style.marginBottom = '6px';
|
||
const lbl = document.createElement('div');
|
||
lbl.className = 'nwjs-cm-label';
|
||
lbl.textContent = k;
|
||
const inp = document.createElement('input');
|
||
inp.className = 'nwjs-cm-input';
|
||
inp.style.width = '360px';
|
||
inp.value = val || '';
|
||
const saveB = document.createElement('button');
|
||
saveB.className = 'nwjs-cm-btn green';
|
||
saveB.textContent = '保存';
|
||
saveB.onclick = function() {
|
||
localStorage.setItem(k, inp.value);
|
||
showToast('💾 localStorage[' + k + '] を保存しました');
|
||
};
|
||
row.appendChild(lbl);
|
||
row.appendChild(inp);
|
||
row.appendChild(saveB);
|
||
sec.appendChild(row);
|
||
}
|
||
container.appendChild(sec);
|
||
}
|
||
|
||
function createPropertyEditorRow(label, currentValue, onCommit) {
|
||
const row = document.createElement('div');
|
||
row.className = 'nwjs-cm-row';
|
||
|
||
const lbl = document.createElement('div');
|
||
lbl.className = 'nwjs-cm-label';
|
||
lbl.title = label;
|
||
lbl.textContent = label;
|
||
row.appendChild(lbl);
|
||
|
||
if (typeof currentValue === 'boolean') {
|
||
const chk = document.createElement('input');
|
||
chk.type = 'checkbox';
|
||
chk.checked = currentValue;
|
||
chk.style.cursor = 'pointer';
|
||
chk.onchange = function() { onCommit(chk.checked); };
|
||
row.appendChild(chk);
|
||
} else {
|
||
const isNum = typeof currentValue === 'number';
|
||
const inp = document.createElement('input');
|
||
inp.className = 'nwjs-cm-input';
|
||
inp.type = isNum ? 'number' : 'text';
|
||
inp.value = String(currentValue);
|
||
inp.onchange = function() {
|
||
const v = isNum ? (Number(inp.value) || 0) : inp.value;
|
||
onCommit(v);
|
||
};
|
||
row.appendChild(inp);
|
||
}
|
||
|
||
return row;
|
||
}
|
||
|
||
root.appendChild(toggleBtn);
|
||
root.appendChild(modal);
|
||
document.body.appendChild(root);
|
||
}
|
||
|
||
if (document.readyState === 'loading') {
|
||
window.addEventListener('DOMContentLoaded', initCheatUI);
|
||
} else {
|
||
initCheatUI();
|
||
}
|
||
})();
|
||
";
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|