-
Notifications
You must be signed in to change notification settings - Fork 41
/
NS_0100325012B70000_Sugar_Style.js
130 lines (115 loc) · 4.86 KB
/
NS_0100325012B70000_Sugar_Style.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// ==UserScript==
// @name [0100325012B70000] Sugar * Style (シュガー*スタイル)
// @version 1.0.0
// @author [DC]
// @description
// * ENTERGRAM
// *
// ==/UserScript==
const gameVer = '1.0.0';
const { setHook } = require('./libYuzu.js');
const mainHandler = trans.send(handler, '200+');
setHook({
// BL sub_
// LDR W8, [X19,#8] <--
// pattern: ? ? ? 97 ? 0A 40 B9 | F4 4F 43 A9 ? ? ? ? FF 43 01 91 C0 03 5F D6 ? ? ? F8
'1.0.0': {
[0x800ccbc8 - 0x80004000]: mainHandler, // ret x0 name + text (readShiftJisString)
//[0x8009c308 - 0x80004000]: mainHandler, // x0 name + text (readUtf8String) - E0 ? 03 91 ? 43 04 91
}
}[globalThis.gameVer = globalThis.gameVer ?? gameVer]);
function handler(regs) {
const address = regs[0].value;
console.log('onEnter 0x' + this.context.pc.toString(16));
//console.log(hexdump(address));
/* processString */
let original = address.readShiftJisString();
let s = remap(original);
//console.log('Debug: ' + s);
// O[A]#0542
// https://github.com/ooa113y/kaleido/blob/2624a79ed6cd5a6126002035ce605144d447db21/rom-repack/layout.rb#L62
// `右代宮 金蔵@r「裸一貫@v01/11500029.「裸一貫で生マレタ。@k@v01/11500030.ソシテ裸一貫で死ヌ゙@k@v01/11500031.馬鹿息子どモニ残シタイモノナど何一ツナイワッ゙゙@k@v01/11500032.モシモ訪レル最期が今日だ右代宮 真里亞@r@v13/10400173.「ウー゙@k@v13/10400174.真里亞モオ子様゙@k@v13/10400175.真里亞モオ子様ー゙」ああ@bタシナ.@<嗜@>あああ`.split(/(?=@.)/)
const parts = s.split(/(?=@.)/g);
s = '';
for (const part of parts) {
if (part.startsWith('@') === false) {
s += part;
continue;
}
const tag = part.substring(0, 2);
const content = part.substring(2);
switch (tag) {
case '@r':
s === '' ? s = content : s += '\n' + content;
continue;
case '@u':
const splited = content.split('.', 2); // param, text
s += String.fromCharCode(splited[0]) + splited[1];
continue;
case '@b': // rubi begin: @bRUBY.
console.log('rubi ' + content.slice(0, -1));
continue;
case '@<':
console.log('rube ' + content);
s += content;
continue;
case '@v':
case '@w':
case '@o':
case '@a':
case '@z':
case '@c':
case '@s':
s += content.split('.', 2)[1];
continue;
case '@>': // rubi end
s += content;
continue;
// TODO: test
//case '@k':
case '@[':
case '@]':
case '@{':
case '@}':
case '@|':
//case '@y':
case '@e':
case '@t':
case '@-':
//console.log('Debug: `' + tag + ' ' + content + '`');
s += content;
continue;
case '@k':
case '@y':
s += content;
continue;
default:
console.log('Unrecognised dialogue tag: ' + tag);
s += content;
continue;
}
}
// Patch: show whole line (remove animated & voice)
//if (this.context.pc === 0x80b4560) address.writeUtf8String(original.replace(/\@k[^\@]*/g, '').replace(/\@v[^\.]+./g, ''));
return s;
}
// https://github.com/ooa113y/kaleido/blob/91d5333f38fd6541be3db1ee7d4539dcbd7ef900/utils.rb#L38
const katakanaMap = {
'「': '「', '」': '」', 'ァ': 'ぁ', 'ィ': 'ぃ', 'ゥ': 'ぅ', 'ェ': 'ぇ', 'ォ': 'ぉ', 'ャ': 'ゃ',
'ュ': 'ゅ', 'ョ': 'ょ', 'ア': 'あ', 'イ': 'い', 'ウ': 'う', 'エ': 'え', 'オ': 'お', 'カ': 'か',
'キ': 'き', 'ク': 'く', 'ケ': 'け', 'コ': 'こ', 'サ': 'さ', 'シ': 'し', 'ス': 'す', 'セ': 'せ',
'ソ': 'そ', 'タ': 'た', 'チ': 'ち', 'ツ': 'つ', 'テ': 'て', 'ト': 'と', 'ナ': 'な', 'ニ': 'に',
'ヌ': 'ぬ', 'ネ': 'ね', 'ノ': 'の', 'ハ': 'は', 'ヒ': 'ひ', 'フ': 'ふ', 'ヘ': 'へ', 'ホ': 'ほ',
'マ': 'ま', 'ミ': 'み', 'ム': 'む', 'メ': 'め', 'モ': 'も', 'ヤ': 'や', 'ユ': 'ゆ', 'ヨ': 'よ',
'ラ': 'ら', 'リ': 'り', 'ル': 'る', 'レ': 'れ', 'ロ': 'ろ', 'ワ': 'わ', 'ヲ': 'を', 'ン': 'ん',
'ー': 'ー', 'ッ': 'っ', '、': '、', '゚': '?', '゙': '!', '・': '…', '?': ' ', '。': '。',
'\uF8F0': '', '\uFFFD': '' // invalid (shift_jis A0 <=> EF A3 B0) | FF FD - F8 F0)
};
function remap(s) {
let result = '';
for (const c of s) {
const r = katakanaMap[c];
result += r !== undefined ? r : c;
}
return result;
}