-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScriptParser.h
620 lines (555 loc) · 17.1 KB
/
ScriptParser.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/* -*- C++ -*-
*
* ScriptParser.h - Define block parser of ONScripter-EN
*
* Copyright (c) 2001-2009 Ogapee. All rights reserved.
* (original ONScripter, of which this is a fork).
*
* ogapee@aqua.dti2.ne.jp
*
* Copyright (c) 2007-2010 "Uncle" Mion Sonozaki
*
* UncleMion@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Modified by Haeleth, Autumn 2006, to better support OS X/Linux packaging;
// and since then numerous other times (see SVN changelog for full details)
// Modified by Mion of Sonozaki Futago-tachi, March 2008, to update from
// Ogapee's 20080121 release source code.
#ifndef __SCRIPT_PARSER_H__
#define __SCRIPT_PARSER_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <SDL_mixer.h>
#include "DirPaths.h"
#include "ScriptHandler.h"
#include "NsaReader.h"
#include "DirectReader.h"
#include "AnimationInfo.h"
#include "FontInfo.h"
#include "Layer.h"
#ifdef USE_LUA
#include "LUAHandler.h"
#endif
#if defined(USE_OGG_VORBIS)
#if defined(INTEGER_OGG_VORBIS)
#include <tremor/ivorbisfile.h>
#else
#include <vorbis/vorbisfile.h>
#endif
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define DEFAULT_FONT_SIZE 26
#define DEFAULT_LOOKBACK_NAME0 "uoncur.bmp"
#define DEFAULT_LOOKBACK_NAME1 "uoffcur.bmp"
#define DEFAULT_LOOKBACK_NAME2 "doncur.bmp"
#define DEFAULT_LOOKBACK_NAME3 "doffcur.bmp"
// Mion: kinsoku
#define DEFAULT_START_KINSOKU "」』)]}、。,.・?!ヽヾゝゞ々ー"
#define DEFAULT_END_KINSOKU "「『([{"
typedef unsigned char uchar3[3];
struct OVInfo{
SDL_AudioCVT cvt;
int cvt_len;
int mult1;
int mult2;
unsigned char *buf;
long decoded_length;
#if defined(USE_OGG_VORBIS)
ogg_int64_t length;
ogg_int64_t pos;
OggVorbis_File ovf;
#endif
};
class ScriptParser
{
public:
struct MusicStruct{
OVInfo *ovi;
int volume;
bool is_mute;
Mix_Chunk **voice_sample; //Mion: for bgmdownmode
MusicStruct()
: ovi(NULL), volume(0), is_mute(false), voice_sample(NULL) {}
};
ScriptParser();
virtual ~ScriptParser();
void reset();
void resetDefineFlags(); // for resetting (non-pointer) variables
int open();
int parseLine();
void setCurrentLabel( const char *label );
void gosubReal( const char *label, char *next_script, bool textgosub_flag=false, int rgosub_state=CLICK_NONE, bool rgosub_1byte=false );
FILE *fopen(const char *path, const char *mode, const bool save = false, const bool usesavedir = false);
void saveGlovalData();
void setArchivePath(const char *path);
void setSavePath(const char *path);
void setNsaOffset(const char *off);
#ifdef MACOSX
void checkBundled();
bool isBundled() {return is_bundled; }
char *bundleResPath() { return bundle_res_path; }
char *bundleAppPath() { return bundle_app_path; }
char *bundleAppName() { return bundle_app_name; }
#endif
/* Command */
int zenkakkoCommand();
int windowchipCommand();
int windowbackCommand();
int versionstrCommand();
int usewheelCommand();
int useescspcCommand();
int underlineCommand();
int transmodeCommand();
int timeCommand();
int textgosubCommand();
int tanCommand();
int subCommand();
int straliasCommand();
int soundpressplginCommand();
int skipCommand();
int sinCommand();
int shadedistanceCommand();
int setlayerCommand();
int setkinsokuCommand();
int selectvoiceCommand();
int selectcolorCommand();
int savenumberCommand();
int savenameCommand();
int savedirCommand();
int rubyonCommand();
int rubyoffCommand();
int roffCommand();
int rmenuCommand();
int rgosubCommand();
int returnCommand();
int pretextgosubCommand();
int pagetagCommand();
int numaliasCommand();
int nsadirCommand();
int nsaCommand();
int nextCommand();
int mulCommand();
int movCommand();
int mode_wave_demoCommand();
int mode_sayaCommand();
int mode_extCommand();
int modCommand();
int midCommand();
int menusetwindowCommand();
int menuselectvoiceCommand();
int menuselectcolorCommand();
int maxkaisoupageCommand();
int luasubCommand();
int luacallCommand();
int lookbackspCommand();
int lookbackcolorCommand();
//int lookbackbuttonCommand();
int loadgosubCommand();
int linepageCommand();
int lenCommand();
int labellogCommand();
int labelexistCommand();
int kidokuskipCommand();
int kidokumodeCommand();
int itoaCommand();
int intlimitCommand();
int incCommand();
int ifCommand();
int humanzCommand();
int humanposCommand();
int gotoCommand();
int gosubCommand();
int globalonCommand();
int getparamCommand();
//int gameCommand();
int forCommand();
int filelogCommand();
int errorsaveCommand();
int englishCommand();
int effectcutCommand();
int effectblankCommand();
int effectCommand();
int dsoundCommand();
int divCommand();
int dimCommand();
int defvoicevolCommand();
int defsubCommand();
int defsevolCommand();
int defmp3volCommand();
int defaultspeedCommand();
int defaultfontCommand();
int decCommand();
int dateCommand();
int cosCommand();
int cmpCommand();
int clickvoiceCommand();
int clickstrCommand();
int clickskippageCommand();
int btnnowindoweraseCommand();
int breakCommand();
int atoiCommand();
int arcCommand();
int addnsadirCommand();
int addkinsokuCommand();
int addCommand();
void add_debug_level();
void errorAndExit( const char *str, const char *reason=NULL, const char *title=NULL, bool is_simple=false );
void errorAndCont( const char *str, const char *reason=NULL, const char *title=NULL, bool is_simple=false );
//Mion: syntax flags
bool allow_color_type_only; // only allow color type (#RRGGBB) for args of color type,
// i.e. not string variables
bool set_tag_page_origin_to_1; // 'gettaglog' will consider the current page as 1, not 0
bool answer_dialog_with_yes_ok;// give 'yesnobox' and 'okcancelbox' 'yes/ok' results
inline const char *readColorStr() {
if (allow_color_type_only)
return script_h.readColor();
else
return script_h.readStr();
}
protected:
struct UserFuncLUT{
struct UserFuncLUT *next;
char *command;
bool lua_flag;
UserFuncLUT(): next(NULL), command(NULL), lua_flag(false){}
~UserFuncLUT(){
if (command) delete[] command;
};
};
struct UserFuncHash{
UserFuncLUT root;
UserFuncLUT *last;
} user_func_hash['z'-'a'+1];
struct NestInfo{
enum { LABEL = 0,
FOR = 1 };
struct NestInfo *previous, *next;
int nest_mode;
char *next_script; // points into script_buffer; used in gosub and for
int var_no, to, step; // used in for
bool textgosub_flag; // used in textgosub and pretextgosub
int rgosub_click_state; // used for rgosub
bool rgosub_1byte_mode; // used for rgosub
NestInfo()
: previous(NULL), next(NULL), nest_mode(LABEL),
next_script(NULL), var_no(0), to(0), step(0),
textgosub_flag(false),
rgosub_click_state(CLICK_NONE), rgosub_1byte_mode(false) {}
//pointers previous, next, & next_script do not need to be freed
} last_tilde;
enum { SYSTEM_NULL = 0,
SYSTEM_SKIP = 1,
SYSTEM_RESET = 2,
SYSTEM_SAVE = 3,
SYSTEM_LOAD = 4,
SYSTEM_LOOKBACK = 5,
SYSTEM_WINDOWERASE = 6,
SYSTEM_MENU = 7,
SYSTEM_YESNO = 8,
SYSTEM_AUTOMODE = 9,
SYSTEM_END = 10
};
enum { RET_NOMATCH = 0,
RET_SKIP_LINE = 1,
RET_CONTINUE = 2,
RET_NO_READ = 4,
RET_EOL = 8, // end of line (0x0a is found)
RET_EOT = 16 // end of text (the end of string_buffer is reached)
};
enum { CLICK_NONE = 0,
CLICK_WAIT = 1,
CLICK_NEWPAGE = 2,
CLICK_WAITEOL = 4
};
enum{ NORMAL_MODE, DEFINE_MODE };
int current_mode;
int debug_level;
#ifdef MACOSX
bool is_bundled;
char *bundle_res_path;
char *bundle_app_path;
char *bundle_app_name;
#endif
char *cmdline_game_id;
DirPaths archive_path;
DirPaths nsa_path;
int nsa_offset;
bool globalon_flag;
bool labellog_flag;
bool filelog_flag;
bool kidokuskip_flag;
bool kidokumode_flag;
bool clickskippage_flag;
int z_order;
bool rmode_flag;
bool windowback_flag;
bool btnnowindowerase_flag;
bool usewheel_flag;
bool useescspc_flag;
bool mode_wave_demo_flag;
bool mode_saya_flag;
bool mode_ext_flag;
bool force_button_shortcut_flag;
bool rubyon_flag;
bool rubyon2_flag;
bool pagetag_flag;
int windowchip_sprite_no;
int string_buffer_offset;
NestInfo root_nest_info, *last_nest_info;
ScriptHandler::LabelInfo current_label_info;
int current_line;
#ifdef USE_LUA
LUAHandler lua_handler;
#endif
/* ---------------------------------------- */
/* Global definitions */
#ifndef NO_LAYER_EFFECTS
bool use_layers;
#endif
#ifdef RCA_SCALE
float scr_stretch_x, scr_stretch_y;
#endif
int preferred_width;
int script_width, script_height;
int screen_ratio1, screen_ratio2;
int screen_width, screen_height;
int screen_texture_width, screen_texture_height;
int screen_bpp;
char *version_str;
int underline_value;
int humanpos[3]; // l,c,r
char *savedir;
void deleteNestInfo();
void setStr( char **dst, const char *src, int num=-1 );
/* ---------------------------------------- */
/* Effect related variables */
struct EffectLink{
struct EffectLink *next;
int no;
int effect;
int duration;
AnimationInfo anim;
EffectLink(){
next = NULL;
effect = 10;
duration = 0;
};
};
EffectLink root_effect_link, *last_effect_link, window_effect, tmp_effect;
int effect_blank;
bool effect_cut_flag;
int readEffect( EffectLink *effect );
EffectLink *parseEffect(bool init_flag);
/* ---------------------------------------- */
#ifndef NO_LAYER_EFFECTS
/* Layer related variables */ //Mion
struct LayerInfo{
struct LayerInfo *next;
Layer *handler;
int num;
Uint32 interval;
Uint32 last_update;
LayerInfo(){
num = -1;
interval = last_update = 0;
handler = NULL;
next = NULL;
}
~LayerInfo(){
if (handler) {
delete handler;
handler = NULL;
}
}
} *layer_info;
void deleteLayerInfo();
#endif
/* ---------------------------------------- */
/* Lookback related variables */
//char *lookback_image_name[4];
int lookback_sp[2];
uchar3 lookback_color;
/* ---------------------------------------- */
/* For loop related variables */
bool break_flag;
/* ---------------------------------------- */
/* Transmode related variables */
int trans_mode;
/* ---------------------------------------- */
/* Save/Load related variables */
struct SaveFileInfo{
bool valid;
int month, day, hour, minute;
char sjis_no[5];
char sjis_month[5];
char sjis_day[5];
char sjis_hour[5];
char sjis_minute[5];
};
unsigned int num_save_file;
char *save_menu_name;
char *load_menu_name;
char *save_item_name;
void setDefaultMenuLabels();
unsigned char *save_data_buf;
unsigned char *file_io_buf;
size_t file_io_buf_ptr;
size_t file_io_buf_len;
size_t save_data_len;
bool errorsave;
/* ---------------------------------------- */
/* Text related variables */
char *default_env_font;
int default_text_speed[3];
struct Page{
struct Page *next, *previous;
char *text;
int max_text;
int text_count;
char *tag;
Page(): next(NULL), previous(NULL),
text(NULL), max_text(0), text_count(0), tag(NULL){}
~Page(){
if (text) delete[] text; text = NULL;
if (tag) delete[] tag; tag = NULL;
next = previous = NULL;
}
int add(unsigned char ch){
if (text_count >= max_text) return -1;
text[text_count++] = ch;
return 0;
};
} *page_list, *start_page, *current_page; // ring buffer
int max_page_list;
int clickstr_line;
int clickstr_state;
int linepage_mode;
int num_chars_in_sentence;
bool english_mode;
struct Kinsoku {
char chr[2];
} *start_kinsoku, *end_kinsoku; //Mion: for kinsoku chars
int num_start_kinsoku, num_end_kinsoku;
void setKinsoku(const char *start_chrs, const char *end_chrs, bool add); //Mion
bool isStartKinsoku(const char *str);
bool isEndKinsoku(const char *str);
/* ---------------------------------------- */
/* Sound related variables */
MusicStruct music_struct;
int music_volume;
int voice_volume;
int se_volume;
bool use_default_volume;
enum { CLICKVOICE_NORMAL = 0,
CLICKVOICE_NEWPAGE = 1,
CLICKVOICE_NUM = 2
};
char *clickvoice_file_name[CLICKVOICE_NUM];
enum { SELECTVOICE_OPEN = 0,
SELECTVOICE_OVER = 1,
SELECTVOICE_SELECT = 2,
SELECTVOICE_NUM = 3
};
char *selectvoice_file_name[SELECTVOICE_NUM];
enum { MENUSELECTVOICE_OPEN = 0,
MENUSELECTVOICE_CANCEL = 1,
MENUSELECTVOICE_OVER = 2,
MENUSELECTVOICE_CLICK = 3,
MENUSELECTVOICE_WARN = 4,
MENUSELECTVOICE_YES = 5,
MENUSELECTVOICE_NO = 6,
MENUSELECTVOICE_NUM = 7
};
char *menuselectvoice_file_name[MENUSELECTVOICE_NUM];
/* ---------------------------------------- */
/* Font related variables */
Fontinfo *current_font, sentence_font, menu_font, ruby_font;
struct RubyStruct{
enum { NONE,
BODY,
RUBY };
int stage;
int body_count;
char *ruby_start;
char *ruby_end;
int ruby_count;
int margin;
int font_size_xy[2];
char *font_name;
RubyStruct(){
stage = NONE;
font_size_xy[0] = 0;
font_size_xy[1] = 0;
font_name = NULL;
};
~RubyStruct(){
if ( font_name ) delete[] font_name;
};
} ruby_struct;
int shade_distance[2];
/* ---------------------------------------- */
/* RMenu related variables */
struct RMenuLink{
RMenuLink *next;
char *label;
int system_call_no;
RMenuLink(){
next = NULL;
label = NULL;
};
~RMenuLink(){
if (label) delete[] label;
};
} root_rmenu_link;
unsigned int rmenu_link_num, rmenu_link_width;
void deleteRMenuLink();
int getSystemCallNo( const char *buffer );
unsigned char convHexToDec( char ch );
void setColor( uchar3 &dstcolor, uchar3 srccolor );
void readColor( uchar3 *color, const char *buf );
void allocFileIOBuf();
int saveFileIOBuf( const char *filename, int offset=0, const char *savestr=NULL );
int loadFileIOBuf( const char *filename );
void writeChar( char c, bool output_flag );
char readChar();
void writeInt( int i, bool output_flag );
int readInt();
void writeStr( char *s, bool output_flag );
void readStr( char **s );
void writeVariables( int from, int to, bool output_flag );
void readVariables( int from, int to );
void writeArrayVariable( bool output_flag );
void readArrayVariable();
void writeLog( ScriptHandler::LogInfo &info );
void readLog( ScriptHandler::LogInfo &info );
/* ---------------------------------------- */
/* System customize related variables */
char *textgosub_label;
char *pretextgosub_label;
char *loadgosub_label;
char *rgosub_label;
ScriptHandler script_h;
unsigned char *key_table;
void createKeyTable( const char *key_exe );
};
#endif // __SCRIPT_PARSER_H__