查看: 3125|回复: 3

[已经解决] 想了解下RGSS3究竟是如何判断调试模式的

[复制链接]
梦石
0
星屑
155
在线时间
129 小时
注册时间
2014-2-22
回帖
206
发表于 2015-7-10 23:38:13 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
我在开发过程中可以通过编辑器里面可以运行游戏,也可以直接运行game.exe运行游戏,不过前者可以进入debug模式后者却不行,我得到一个比较模糊的答案是运行时附加一个命令行,我比较想了解下这个命令行究竟是怎样的命令行,又是如何传递的,以及在脚本中是如何获取这个命令行的…………

最近开始填坑,准备入手个普耐尔9W,专门肝船和填坑……………………
很多年了呢,坑还是没填完…………(草

梦石
1
星屑
23246
在线时间
9564 小时
注册时间
2012-6-19
回帖
7018

开拓者短篇九导演组冠军

发表于 2015-7-11 01:06:46 | 显示全部楼层
调试模式下,全局变量$TEST值为真,你可以在脚本中全局搜索这个关键词,看到的便是调试模式下提供的全部便利功能

具体是如何让其设为真的等楼下高人……虽然对我自己来说知道了也没啥意义就是了…………

点评

我知道了!谢谢!  发表于 2015-7-11 13:51

评分

参与人数 1星屑 +150 收起 理由
VIPArcher + 150 认可答案

查看全部评分

回复

使用道具 举报

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2015-7-11 08:21:47 | 显示全部楼层
本帖最后由 taroxd 于 2015-7-11 08:30 编辑
喵呜喵5 发表于 2015-7-11 01:06
调试模式下,全局变量$TEST值为真,你可以在脚本中全局搜索这个关键词,看到的便是调试模式下提供的全部便 ...


最简单的方式:点测试游戏的时候用 RGSSEval 运行脚本 $TEST = true。当然,这个用命令行参数很容易做到。似乎就是 Game.exe test 或者 Game.exe btest。以后加密游戏有必要把脚本里的 $TEST 功能全部删掉

下面是远古大神的一个实现:
[pre lang="cpp"]/**
* @file  Main.cpp
*
* @desc  第三方 RGSS3 Player
*
* @author  灼眼的夏娜
*
* @history 2011/12/02 初版
*/
#include <windows.h>
#include <stdio.h>
static const wchar_t* pWndClassName = L"RGSSX Player";
static const wchar_t* pDefaultLibrary = L"RGSS300.dll";
static const wchar_t* pDefaultTitle = L"Untitled";
static const wchar_t* pDefaultScripts = L"Data\\Scripts.rvdata2";
static const int nScreenWidth = 544;
static const int nScreenHeight = 416;
static const int nEvalErrorCode = 6;
static HWND  g_hWnd = NULL;
extern "C" __declspec(dllexport) HWND __rgssx_get_hwnd()
{
        return g_hWnd;
}
static void ShowErrorMsg(HWND hWnd, const wchar_t* szTitle, const wchar_t* szFormat, ...)
{
        static wchar_t szError[1024];
        va_list ap;
        va_start(ap, szFormat);
        vswprintf_s(szError, szFormat, ap);
        va_end(ap);
        MessageBoxW(hWnd, szError, szTitle, MB_ICONERROR);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
        wchar_t szAppPath[MAX_PATH], szIniPath[MAX_PATH], szRgssadPath[MAX_PATH];
        wchar_t szLibrary[MAX_PATH], szTitle[MAX_PATH], szScripts[MAX_PATH];
        wchar_t* pRgssad = 0;
        HMODULE hRgssCore = NULL;
        // app路径
        DWORD len = ::GetModuleFileNameW(hInstance, szAppPath, MAX_PATH);
        for (--len; len > 0; --len)
        {
                if (szAppPath[len] == L'\\' || szAppPath[len] == L'/')
                {
                        szAppPath[len] = 0;
                        break;
                }
        }
        ::SetCurrentDirectoryW(szAppPath);
        // ini文件路径
        len = ::GetModuleFileNameW(hInstance, szIniPath, MAX_PATH);
        szIniPath[len - 1] = L'i';
        szIniPath[len - 2] = L'n';
        szIniPath[len - 3] = L'i';
        // 加密包路径
        len = ::GetModuleFileNameW(hInstance, szRgssadPath, MAX_PATH);
        for (--len; len > 0; --len)
        {
                if (szRgssadPath[len] == L'.')
                {
                        szRgssadPath[len + 1] = L'r';
                        szRgssadPath[len + 2] = L'g';
                        szRgssadPath[len + 3] = L's';
                        szRgssadPath[len + 4] = L's';
                        szRgssadPath[len + 5] = L'3';
                        szRgssadPath[len + 6] = L'a';
                        szRgssadPath[len + 7] = 0;
                        break;
                }
        }
        // ini文件存在
        if (GetFileAttributesW(szIniPath) != INVALID_FILE_ATTRIBUTES)
        {
                GetPrivateProfileStringW(L"Game", L"Library", pDefaultLibrary, szLibrary, MAX_PATH, szIniPath);
                GetPrivateProfileStringW(L"Game", L"Title", pDefaultTitle, szTitle, MAX_PATH, szIniPath);
                GetPrivateProfileStringW(L"Game", L"Scripts", pDefaultScripts, szScripts, MAX_PATH, szIniPath);
        }
        else
        {
                wcscpy_s(szLibrary, pDefaultLibrary);
                wcscpy_s(szTitle, pDefaultTitle);
                wcscpy_s(szScripts, pDefaultScripts);
        }
        if (GetFileAttributesW(szRgssadPath) != INVALID_FILE_ATTRIBUTES)
                pRgssad = szRgssadPath;
        // 创建窗口
        WNDCLASSW winclass;
        winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
        winclass.lpfnWndProc = DefWindowProc;
        winclass.cbClsExtra = 0;
        winclass.cbWndExtra = 0;
        winclass.hInstance = hInstance;
        winclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(101));
        winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        winclass.lpszMenuName = NULL;
        winclass.lpszClassName = pWndClassName;
        if (!RegisterClassW(&winclass))
        {
                ShowErrorMsg(g_hWnd, szTitle, L"注册窗口类失败 %s。", pWndClassName);
                return 0;
        }
        int width = nScreenWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
        int height = nScreenHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION);
        RECT rt;
        {
                rt.left = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
                //rt.top = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
                rt.top = (GetSystemMetrics(SM_CYMAXIMIZED) - nScreenHeight) / 2 - GetSystemMetrics(SM_CYCAPTION);
                rt.right = rt.left + width;
                rt.bottom = rt.top + height;
        }
        DWORD dwStyle = WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE;
        g_hWnd = ::CreateWindowEx(WS_EX_WINDOWEDGE, pWndClassName, szTitle, dwStyle,
                rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, 0, 0, hInstance, 0);
        if (!g_hWnd)
        {
                ShowErrorMsg(g_hWnd, szTitle, L"创建窗口失败 %s。", szTitle);
                goto __exit;
        }
        // 控制台
        if (strcmp(lpCmdLine, "console") == 0)
        {
                if (AllocConsole())
                {
                        SetConsoleTitle(L"RGSS Console");
                        FILE* frw = NULL;
                        freopen_s(&frw, "conout$", "w", stdout);
                }
        }
        ShowWindow(g_hWnd, SW_SHOW);
        // 加载RGSS核心库
        hRgssCore = ::LoadLibraryW(szLibrary);
        if (!hRgssCore)
        {
                DWORD e = ::GetLastError();
                ShowErrorMsg(g_hWnd, szTitle, L"加载RGSS核心库失败 %s。", szLibrary);
                goto __exit;
        }
        typedef BOOL(*RGSSSetupRTP)(const wchar_t* pIniPath, wchar_t* pErrorMsgBuffer, int iBufferLength);
        typedef void(*RGSSSetupFonts)();
        typedef void(*RGSSInitialize3)(HMODULE hRgssDll);
        typedef int(*RGSSEval)(const char* pScripts);
        typedef void(*RGSSGameMain)(HWND hWnd, const wchar_t* pScriptNames, wchar_t** pRgssadName);
        typedef BOOL(*RGSSExInitialize)(HWND hWnd);
        RGSSSetupRTP  pRGSSSetupRTP = NULL;
        RGSSSetupFonts  pRGSSSetupFonts = NULL;
        RGSSInitialize3  pRGSSInitialize3 = NULL;
        RGSSEval   pRGSSEval = NULL;
        RGSSGameMain  pRGSSGameMain = NULL;
        RGSSExInitialize pRGSSExInitialize = (RGSSExInitialize)::GetProcAddress(hRgssCore, "RGSSExInitialize");
#define __get_check(fn)                \
do                    \
   {                    \
  p##fn = (fn)::GetProcAddress(hRgssCore, #fn);        \
  if (!p##fn)                 \
      {                   \
   ShowErrorMsg(g_hWnd, szTitle, L"获取RGSS核心库导出函数失败 %s。", #fn); \
   goto __exit;               \
      }                   \
   } while (0)
        {
                __get_check(RGSSSetupRTP);
                __get_check(RGSSSetupFonts);
                __get_check(RGSSInitialize3);
                __get_check(RGSSEval);
                __get_check(RGSSGameMain);
        }
#undef __get_check
        // 1、设置RTP
        wchar_t szRtpName[1024];
        if (!pRGSSSetupRTP(szIniPath, szRtpName, 1024))
        {
                ShowErrorMsg(g_hWnd, szTitle, L"没有发现 RGSS-RTP %s。", szRtpName);
                goto __exit;
        }
        // 2、初始化
        pRGSSInitialize3(hRgssCore);
        // 2.1、扩展库初始化(补丁模式)
        if (pRGSSExInitialize)
        {
                if (!pRGSSExInitialize(g_hWnd))
                {
                        ShowErrorMsg(g_hWnd, szTitle, L"RGSS扩展库初始化失败 %s。", L"RGSSExInitialize");
                        goto __exit;
                }
        }
        pRGSSSetupFonts();
        // 3、设置运行时变量
        if (strcmp(lpCmdLine, "btest") == 0)
        {
                pRgssad = 0;
                pRGSSEval("$TEST = true");
                pRGSSEval("$BTEST = true");
        }
        else
        {
                if (strcmp(lpCmdLine, "test") == 0)
                {
                        pRgssad = 0;
                        pRGSSEval("$TEST = true");
                }
                else
                        pRGSSEval("$TEST = false");
                pRGSSEval("$BTEST = false");
        }
        // 4、主逻辑
        pRGSSGameMain(g_hWnd, szScripts, (pRgssad ? (wchar_t**)pRgssad : &pRgssad)); // ???
__exit:
        if (hRgssCore)
        {
                FreeLibrary(hRgssCore);
                hRgssCore = NULL;
        }
        if (g_hWnd)
        {
                DestroyWindow(g_hWnd);
                g_hWnd = NULL;
        }
        UnregisterClassW(pWndClassName, hInstance);
        return 0;
}[/pre]

点评

原来如此,谢谢!  发表于 2015-7-11 13:50
exit if $TEST  发表于 2015-7-11 11:17

评分

参与人数 1梦石 +1 收起 理由
VIPArcher + 1 认可答案

查看全部评分

回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2015-7-11 09:22:50 | 显示全部楼层
本帖最后由 tseyik 于 2015-7-11 09:32 编辑

Scene_Map中
  def update_call_debug
    SceneManager.call(Scene_Debug) if $TEST && Input.press?(:F9)
  end
改成
Scene_Map中
  def update_call_debug
   # SceneManager.call(Scene_Debug) if $TEST && Input.press?(:F9)
   SceneManager.call(Scene_Debug) if Input.press?(:F9)
  end
就可运行game.exe进入debug模式
不過在公用事用SceneManager.call(Scene_Debug)也是叧一種方法



超级DEBUG脚本
https://rpg.blue/forum.php?mod=viewthread&tid=379201

点评

谢谢!受教了!  发表于 2015-7-11 13:49

评分

参与人数 1星屑 +150 收起 理由
VIPArcher + 150 认可答案

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部