Last active
October 30, 2025 07:07
-
-
Save UserUnknownFactor/07c6b1fffa67ef16e02c03740221ce84 to your computer and use it in GitHub Desktop.
Nagato's automatic word wrapper for KiriKiri Z games (added to MainWindow.tjs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // inside MainWindow.tjs right after: | |
| // class KAGWindow extends Window | |
| // { | |
| var wrapNum = 0; | |
| var wrapPos = 0; | |
| var wrapPosHist = 0; | |
| var wrapOldLine = void; | |
| var wrapSplitLine = void; | |
| var wrapBreakWrap = 0; | |
| var wrapNewPage = 0; | |
| var wrapLabel = void; | |
| var wrapComp = void; | |
| var spaceChar = " "; | |
| var newlineTag = "[r]"; | |
| function needsToBeWrapped(text) { | |
| var textHist = text; | |
| if(conductor.curLineStr[0] == "*" || conductor.curLineStr[0] == "[" || conductor.curLineStr[0] == ";" || | |
| conductor.curLineStr[0] == "\t") return false; | |
| if(conductor.curLineStr.indexOf(newlineTag)!=-1) return false; | |
| if(conductor.curLineStr.indexOf(spaceChar)!=-1) | |
| { | |
| var cleanStr = void; | |
| for(var i=0,depth=0; i<conductor.curLineStr.length; i++) | |
| { | |
| if(conductor.curLineStr[i]!='[') | |
| { | |
| if(conductor.curLineStr[i]!='\\') | |
| cleanStr += conductor.curLineStr[i]; | |
| } else { | |
| for(var depth=0; i<conductor.curLineStr.length; i++) | |
| { | |
| if(conductor.curLineStr[i]=='[') | |
| { | |
| depth++; | |
| } | |
| else if(conductor.curLineStr[i]==']') | |
| { | |
| depth--; | |
| if(depth<=0) break; | |
| } | |
| } | |
| } | |
| } | |
| if(wrapLabel != currentLabel || wrapComp != cleanStr) | |
| { | |
| wrapLabel = currentLabel; | |
| wrapOldLine = conductor.curLineStr; | |
| wrapBreakWrap = 0; | |
| if(cleanStr===void || cleanStr.indexOf(spaceChar)==-1) | |
| { | |
| wrapBreakWrap = 1; | |
| } else { | |
| wrapSplitLine = cleanStr.split(spaceChar); | |
| wrapPos = current.vertical ? current.y+current.lineLayer.font.getTextWidth(spaceChar) : current.x; | |
| wrapPosHist = historyLayer.font.getTextWidth(historyLayer.currentLine); | |
| wrapNum = 0; | |
| } | |
| wrapComp = wrapSplitLine.join(spaceChar); | |
| } | |
| if(!wrapBreakWrap) | |
| { | |
| if(text==spaceChar) | |
| { | |
| if(wrapNewPage != 1) wrapNum++; | |
| wrapSplitLine[wrapNum] += spaceChar; | |
| wrapPos = current.vertical ? current.y+current.lineLayer.font.getTextWidth(spaceChar) : current.x; | |
| wrapPosHist = historyLayer.font.getTextWidth(historyLayer.currentLine); | |
| } | |
| if(historyWriteEnabled && wrapPosHist+historyLayer.font.getTextWidth(wrapSplitLine[wrapNum]) >= historyLayer.relinePos) | |
| { | |
| if(historyLayer.font.getTextWidth(wrapSplitLine[wrapNum])<=historyLayer.relinePos) | |
| { | |
| textHist = ""; | |
| historyLayer.reline(); | |
| wrapPosHist = historyLayer.font.getTextWidth(historyLayer.currentLine); | |
| } | |
| } | |
| if(wrapPos+current.lineLayer.font.getTextWidth(wrapSplitLine[wrapNum])>=current.relinexpos) | |
| { | |
| if(current.lineLayer.font.getTextWidth(wrapSplitLine[wrapNum])<=current.relinexpos) | |
| { | |
| text = ""; | |
| if(current.processReturn()) wrapNewPage = 1; | |
| } | |
| wrapPos = current.vertical ? current.y+current.lineLayer.font.getTextWidth(spaceChar) : current.x; | |
| if(wrapNewPage==1) return true; | |
| } | |
| } | |
| } | |
| return false; | |
| } | |
| // inside | |
| // ch : function(elm) | |
| // somewhere just before | |
| // if(autoWCEnabled): | |
| if (needsToBeWrapped(elm.text)) return showPageBreakAndClear(); |
Author
How am I supposed to decrypt Krkrz MainWIndow.tjs? I can't even decrypt it using Krkrextract or anything.
Author
Each game uses its own protection but most of them boil down to XORs.
The word wrapping seems to break when you have a text that is longer than the dialogue window, or when you insert a [r] into the script. Any solution?
Author
It's supposed to ignore lines with [r] because they're considered pre-formatted there.
The solution to the second problem is either hard-coded re-wrap or use other script because some games don't work with this one.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is rather slow but whatever.