kone
소미소프트
소미소프트

비월선행록 v1.2933 한글 패치버전 특정 이벤트 오버플로우 현상 고치는 방법

정보
28,447 views · 16 points

한글 패치하고 나서 특정 이벤트 불러올 때, 아래의 화면 노출되는 경우가 있을 거임

1

한패한다고 들어간 플러그인이 textWidthEx 호출할 때 재귀 가드를 안 넣어놔서 생긴 버그로 추정됨.

콘솔모드로 원인 찾아서 반복하는 원인 중 하나인 autoLine.js 비활성화 해봤다가 오버플로우 증상은 고쳐졌지만,

대사 자동 줄바꿈이 안되는 문제가 생기면서 이게 원초적인 문제가 아님을 깨닫고

제대로 뜯어보니까

FlyCat_TextCenter가 텍스트 정렬하려면 너비 알아야해서 → textWidthEx() 호출 → convertEscapeCharacters() 호출 → Admin_LanguageCore가 여기 훅 걸려있음 → autoLine.js의 convertEscapeCharacters 호출 → 너비 재려고 this.textWidth() 호출 → 또 convertEscapeCharacters() 호출→ 또 Admin_LanguageCore 훅 → 또 autoLine.js의 convertEscapeCharacters 호출...(이하 반복) 꼬라지라서 오버플로우 지12랄 난거임

핵심은 autoLine이 너비를 재면서 내부적으로 다시 텍스트 처리를 부른 게 문제라 너비 계산이 텍스트 처리를 부르고, 텍스트 처리가 다시 너비 계산을 부르는 거지 같은 순환 구조가 생김

그래서 textWidthEx에 ‘이미 계산 중이면 그냥 0 반환하고 꺼져’라는 가드를 넣은 스크립트가 아래임

게임폴더\js\plugins 에서 autoLine.js 메모장이나 notepad++로 열고 컨트롤 a 누르고 아래의 내용 복붙하고 저장하셈

그냥 혼자 두고 쓰려다가 똑같은 증상 겪을 사람들 많을 거 같아서 공유함

자동 서식 변환때문에 소스코드 망가져서 코드블록에 넣어서 다시 함

/*:
 * @plugindesc 自动换行(英文)
 * @author FlyRoc
 * @target MZ
 */
 (function() {
    const _textWidthEx = Window_Base.prototype.textWidthEx;
    Window_Base.prototype.textWidthEx = function(text) {
        if (this._calcingWidth) return 0;
        this._calcingWidth = true;
        const result = _textWidthEx.call(this, text);
        this._calcingWidth = false;
        return result;
    };
})();
function validUpperCase(str) {
    const reg = /^[A-Z]+$/
    return reg.test(str)
}

Window_Message.prototype.convertEscapeCharacters = function (text) {
    if (this._autoLineProcessing) {
        text = text.replace(/\\/g, "\x1b");
        text = text.replace(/\x1b\x1b/g, "\\");
        text = text.replace(/\x1bV\[(\d+)\]/gi, (_, p1) =>
            $gameVariables.value(parseInt(p1))
        );
        text = text.replace(/\x1bV\[(\d+)\]/gi, (_, p1) =>
            $gameVariables.value(parseInt(p1))
        );
        text = text.replace(/\x1bN\[(\d+)\]/gi, (_, p1) =>
            this.actorName(parseInt(p1))
        );
        text = text.replace(/\x1bP\[(\d+)\]/gi, (_, p1) =>
            this.partyMemberName(parseInt(p1))
        );
        text = text.replace(/\x1bG/gi, TextManager.currencyUnit);
        return text;
    }
    this._autoLineProcessing = true;
    const regex = /[\r\n]/g;
    let match;
    const newLineIndices = [];
    while ((match = regex.exec(text))) {
        newLineIndices.push(match.index);
    }
    var textWidth = 0;
    var newText = [];
    for (let i = 0; i < text.length; i++) {
        var value = this.textWidth(text[i]);
        newText.push(text[i]);
        if (newLineIndices.includes(i)) {
            textWidth = 0;
        }
        textWidth += value;
        if (textWidth >= (this.width - 60)) {
            newText.push('\n');
            textWidth = 0;
        };
    };
    text = newText.join('')
    text = text.replace(/\\/g, "\x1b");
    text = text.replace(/\x1b\x1b/g, "\\");
    text = text.replace(/\x1bV\[(\d+)\]/gi, (_, p1) =>
        $gameVariables.value(parseInt(p1))
    );
    text = text.replace(/\x1bV\[(\d+)\]/gi, (_, p1) =>
        $gameVariables.value(parseInt(p1))
    );
    text = text.replace(/\x1bN\[(\d+)\]/gi, (_, p1) =>
        this.actorName(parseInt(p1))
    );
    text = text.replace(/\x1bP\[(\d+)\]/gi, (_, p1) =>
        this.partyMemberName(parseInt(p1))
    );
    text = text.replace(/\x1bG/gi, TextManager.currencyUnit);
    text = text.replace(/\x1bCT\[(\d+)\]/gi, function () {
        $gameMessage.setAlign(Number(arguments[1] || 0));
        return "";
    }.bind(this));
    this._autoLineProcessing = false;
    return text;
};

16
6 comments
역자에게 제보하는데스웅
[deleted] (edited )

Deleted comment.

ReferenceError WindowBase is not defined 적용하면 안켜짐
(edited )
아예 안켜짐? 에러 메시지 보니까 Window_Base는 RPG Maker MZ의 기본 클래스 이름임 언더 스코어 없으면 그냥 존재하지 않는 변수 이름이 되니까 바로 ReferenceError 뜨는 거임. Window_Base의 언더스코어가 빠진 거일듯 autoLine.js 열고 WindowBase.prototype.textWidthEx 이런식으로 저장되어 있는지 보셈 그러고 난뒤 Window_Base.prototype.textWidthEx으로 수정해서 저장해보셈 아니 이제보니까 이거 자동 서식 변경이 소스코드 날린거네 아오 그럼에도 안켜지면, 게임 폴더 안에 있는 js폴더 말고 게임 실행 아이콘 있는 위치의 package.json 수정해서 추가 댓글로 다는 거로 내용 수정한다음에 게임 키고 f12 누르고 elements 옆에 있는 console 화면 캡처 해주셈
{ "name": "rmmz-game", "main": "index.html", "chromium-args": "--force-color-profile=srgb", "window": { "title": "绯月仙行录V1.2931(含DLC)", "width": 1280, "height": 720, "position": "center", "icon": "icon/icon.png", "toolbar": true } }
All
Title
Body