├── AVIWrapper.cpp ├── AVIWrapper.h ├── AnimationInfo.cpp ├── AnimationInfo.h ├── BaseReader.h ├── ButtonLink.h ├── COPYING ├── DirectReader.cpp ├── DirectReader.h ├── DirtyRect.cpp ├── DirtyRect.h ├── FontInfo.cpp ├── FontInfo.h ├── LUAHandler.cpp ├── LUAHandler.h ├── Makefile.ARMLinux ├── Makefile.GP2X ├── Makefile.Linux ├── Makefile.MacOSX ├── Makefile.PSP ├── Makefile.Pandora ├── Makefile.Win ├── Makefile.WinCE ├── Makefile.iPhone ├── Makefile.iPodLinux ├── Makefile.onscripter ├── NsaReader.cpp ├── NsaReader.h ├── ONScripter.cpp ├── ONScripter.h ├── ONScripter_animation.cpp ├── ONScripter_command.cpp ├── ONScripter_effect.cpp ├── ONScripter_effect_breakup.cpp ├── ONScripter_event.cpp ├── ONScripter_file.cpp ├── ONScripter_file2.cpp ├── ONScripter_image.cpp ├── ONScripter_lut.cpp ├── ONScripter_rmenu.cpp ├── ONScripter_sound.cpp ├── ONScripter_text.cpp ├── README ├── SarReader.cpp ├── SarReader.h ├── ScriptHandler.cpp ├── ScriptHandler.h ├── ScriptParser.cpp ├── ScriptParser.h ├── ScriptParser_command.cpp ├── conv_shared.cpp ├── nsaconv.cpp ├── nsadec.cpp ├── nscriptdecode.cpp ├── onscripter_main.cpp ├── resize_image.cpp ├── resize_image.h ├── sarconv.cpp ├── sardec.cpp ├── simple_aviplay.cpp ├── sjis2utf16.cpp ├── version.h └── www ├── ogapee.css └── onscripter.html /AVIWrapper.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * AVIWrapper.cpp - avifile library wrapper class to play AVI video & audio stream 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include "AVIWrapper.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #define DEFAULT_AUDIOBUF 4096 36 | #define AVI_FINISH_EVENT 12345 37 | 38 | #define AVIFILE_VERSION 747 39 | 40 | AVIWrapper::AVIWrapper() 41 | { 42 | screen_overlay = NULL; 43 | i_avi = NULL; 44 | v_stream = NULL; 45 | a_stream = NULL; 46 | remaining_buffer = new char[DEFAULT_AUDIOBUF*4]; 47 | remaining_count = 0; 48 | } 49 | 50 | AVIWrapper::~AVIWrapper() 51 | { 52 | if ( v_stream ) 53 | v_stream->StopStreaming(); 54 | if ( a_stream ) 55 | a_stream->StopStreaming(); 56 | if ( i_avi ) delete i_avi; 57 | if ( screen_overlay ) SDL_FreeYUVOverlay( screen_overlay ); 58 | if ( remaining_buffer ) delete[] remaining_buffer; 59 | } 60 | 61 | int AVIWrapper::init( char *filename, bool debug_flag ) 62 | { 63 | this->debug_flag = debug_flag; 64 | #if AVIFILE_VERSION >= 747 65 | if ( !debug_flag ) avm::AvmOutput::singleton()->resetDebugLevels(-1); 66 | #else 67 | if ( !debug_flag ) avm::out.resetDebugLevels(-1); 68 | #endif 69 | 70 | i_avi = CreateIAviReadFile( filename ); 71 | if ( i_avi == NULL || i_avi->IsValid() == false ){ 72 | fprintf( stderr, "can't CreateIAviReadFile from %s\n", filename ); 73 | return -1; 74 | } 75 | 76 | v_stream = i_avi->GetStream(0, AviStream::Video ); 77 | if ( v_stream == NULL ){ 78 | fprintf( stderr, "Video Stream is NULL\n" ); 79 | return -1; 80 | } 81 | 82 | width = v_stream->GetStreamInfo()->GetVideoWidth(); 83 | height = v_stream->GetStreamInfo()->GetVideoHeight(); 84 | if ( debug_flag ) fprintf( stderr, "width %d height %d\n", width, height ); 85 | 86 | return 0; 87 | } 88 | 89 | int AVIWrapper::initAV( SDL_Surface *surface, bool audio_open_flag ) 90 | { 91 | screen_rect.x = screen_rect.y = 0; 92 | screen_rect.w = surface->w; 93 | screen_rect.h = surface->h; 94 | 95 | v_stream->StartStreaming(); 96 | if ( v_stream->GetVideoDecoder() == NULL ){ 97 | if ( debug_flag ) fprintf( stderr, "GetVideoDecoder() return 0.\n" ); 98 | return -1; 99 | } 100 | avm::IVideoDecoder::CAPS cap = v_stream->GetVideoDecoder()->GetCapabilities(); 101 | if ( debug_flag ) printf("cap %x\n", cap ); 102 | 103 | if ( cap & avm::IVideoDecoder::CAP_YV12 ){ 104 | v_stream->GetVideoDecoder()->SetDestFmt( 0, fccYV12 ); 105 | screen_overlay = SDL_CreateYUVOverlay( width, height, SDL_YV12_OVERLAY, surface ); 106 | } 107 | else if ( cap & avm::IVideoDecoder::CAP_YUY2 ){ 108 | v_stream->GetVideoDecoder()->SetDestFmt( 0, fccYUY2 ); 109 | screen_overlay = SDL_CreateYUVOverlay( width, height, SDL_YUY2_OVERLAY, surface ); 110 | } 111 | else{ 112 | screen_overlay = SDL_CreateYUVOverlay( width, height, SDL_YV12_OVERLAY, surface ); 113 | } 114 | 115 | if ( !audio_open_flag ) return 0; 116 | a_stream = i_avi->GetStream(0, AviStream::Audio); 117 | if ( a_stream == NULL ){ 118 | if ( debug_flag ) fprintf( stderr, "Audio Stream is NULL\n" ); 119 | return 0; 120 | } 121 | 122 | a_stream->StartStreaming(); 123 | WAVEFORMATEX wave_fmt; 124 | a_stream->GetAudioDecoder()->GetOutputFormat( &wave_fmt ); 125 | if ( debug_flag ) printf(" format %d ch %d sample %d bit %d avg Bps %d\n", wave_fmt.wFormatTag, wave_fmt.nChannels, wave_fmt.nSamplesPerSec, wave_fmt.wBitsPerSample, wave_fmt.nAvgBytesPerSec ); 126 | 127 | if ( Mix_OpenAudio( wave_fmt.nSamplesPerSec, MIX_DEFAULT_FORMAT, wave_fmt.nChannels, DEFAULT_AUDIOBUF ) < 0 ){ 128 | fprintf( stderr, "can't open audio device\n" ); 129 | a_stream->StopStreaming(); 130 | delete a_stream; 131 | a_stream = NULL; 132 | } 133 | 134 | return 0; 135 | } 136 | 137 | static void audioCallback( void *userdata, Uint8 *stream, int len ) 138 | { 139 | AVIWrapper &avi = *(AVIWrapper*)userdata; 140 | avi.audioCallback( userdata, stream, len ); 141 | } 142 | 143 | void AVIWrapper::audioCallback( void *userdata, Uint8 *stream, int len ) 144 | { 145 | if ( len == 0 ) 146 | status = AVI_STOP; 147 | 148 | size_t ocnt; 149 | size_t samples; 150 | size_t count = 0; 151 | 152 | if ( remaining_count > 0 ){ 153 | if ( remaining_count <= len ){ 154 | memcpy( stream, remaining_buffer, remaining_count ); 155 | count = remaining_count; 156 | len -= remaining_count; 157 | remaining_count = 0; 158 | } 159 | else{ 160 | memmove( stream, remaining_buffer, len ); 161 | count = len; 162 | len = 0; 163 | remaining_count -= len; 164 | return; 165 | } 166 | } 167 | 168 | while ( len > 0 && !a_stream->Eof() ){ 169 | a_stream->ReadFrames( remaining_buffer, (size_t)len, (size_t)len, samples, ocnt ); 170 | if ( (int)ocnt <= len ){ 171 | memcpy( stream+count, remaining_buffer, ocnt ); 172 | len -= ocnt; 173 | } 174 | else{ 175 | memcpy( stream+count, remaining_buffer, len ); 176 | if ( (int)ocnt-len < DEFAULT_AUDIOBUF*4 - len ){ 177 | memmove( remaining_buffer, remaining_buffer+len, ocnt-len ); 178 | remaining_count = ocnt-len; 179 | } 180 | else{ 181 | remaining_count = 0; 182 | } 183 | len = 0; 184 | } 185 | count += ocnt; 186 | } 187 | } 188 | 189 | double AVIWrapper::getAudioTime() 190 | { 191 | if ( time_start == 0 ) 192 | { 193 | frame_start = (v_stream) ? v_stream->GetTime() : 0.; 194 | #if AVIFILE_VERSION >= 747 195 | time_start = avm_get_time_us(); 196 | #else 197 | time_start = longcount(); 198 | #endif 199 | } 200 | 201 | if ( a_stream ) 202 | return a_stream->GetTime(); 203 | else 204 | #if AVIFILE_VERSION >= 747 205 | return frame_start + to_float(avm_get_time_us(), time_start); 206 | #else 207 | return frame_start + to_float(longcount(), time_start); 208 | #endif 209 | } 210 | 211 | static int playVideo( void *userdata ) 212 | { 213 | AVIWrapper &avi = *(AVIWrapper*)userdata; 214 | return avi.playVideo( userdata ); 215 | } 216 | 217 | #define NUM_CACHES 3 218 | int AVIWrapper::playVideo( void *userdata ) 219 | { 220 | int i; 221 | 222 | struct{ 223 | bool valid; 224 | avm::CImage *image; 225 | double time; 226 | } cache[NUM_CACHES]; 227 | for ( i=0 ; iEof() ){ 233 | avm::CImage *image = v_stream->GetFrame( true ); 234 | if ( image == NULL ) break; 235 | 236 | double current_time = v_stream->GetTime(); 237 | double minimum_time = current_time; 238 | 239 | // look for the nearest in the cache 240 | int nearest_cache=-1; 241 | for ( i=0 ; i= 0 && 245 | cache[i].time < cache[nearest_cache].time) ){ 246 | nearest_cache = i; 247 | if ( minimum_time > cache[nearest_cache].time ) 248 | minimum_time = cache[nearest_cache].time; 249 | } 250 | } 251 | } 252 | 253 | double async = getAudioTime() - minimum_time; 254 | //printf("audio %f (%f - %f) minimum %d %f cur %f\n", async, getAudioTime(), minimum_time, nearest_cache, minimum_time, current_time ); 255 | if ( async < -0.01 ){ 256 | if ( remaining_cache == 0 ){ 257 | //printf("sync0 %f %f %f %f\n", async, (a_stream)?a_stream->GetTime():0.0, v_stream->GetTime(), minimum_time ); 258 | SDL_Delay( (int)(-async*1000) ); 259 | } 260 | } 261 | if ( (async < -0.01 && remaining_cache > 0) || 262 | nearest_cache >= 0 ){ 263 | // add cache 264 | for ( i=0 ; iRelease(); 275 | continue; 276 | } 277 | } 278 | 279 | if ( nearest_cache >= 0 && minimum_time == cache[nearest_cache].time ){ 280 | //printf("draw cache %d %f\n", nearest_cache, cache[nearest_cache].time ); 281 | //if ( async <= 0.033 ) // drop frame if necessary 282 | drawFrame( cache[nearest_cache].image ); 283 | cache[nearest_cache].image->Release(); 284 | cache[nearest_cache].valid = false; 285 | remaining_cache++; 286 | } 287 | else{ 288 | //printf("draw real %f\n", current_time ); 289 | //if ( async <= 0.033 ) // drop frame if necessary 290 | drawFrame( image ); 291 | } 292 | image->Release(); 293 | } 294 | status = AVI_STOP; 295 | 296 | for ( i=0 ; iRelease(); 298 | 299 | return 0; 300 | } 301 | 302 | int AVIWrapper::play( bool click_flag ) 303 | { 304 | int ret = 0; 305 | time_start = 0; 306 | status = AVI_PLAYING; 307 | if ( v_stream ) 308 | thread_id = SDL_CreateThread( ::playVideo, this ); 309 | if ( a_stream ) 310 | Mix_HookMusic( ::audioCallback, this ); 311 | 312 | bool done_flag = false; 313 | while( !(done_flag & click_flag) && status == AVI_PLAYING ){ 314 | SDL_Event event; 315 | 316 | while( SDL_PollEvent( &event ) ){ 317 | switch (event.type){ 318 | case SDL_KEYUP: 319 | if ( ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_RETURN || 320 | ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_KP_ENTER || 321 | ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_SPACE || 322 | ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_ESCAPE ) 323 | done_flag = true; 324 | break; 325 | case SDL_QUIT: 326 | ret = 1; 327 | case SDL_MOUSEBUTTONUP: 328 | done_flag = true; 329 | break; 330 | default: 331 | break; 332 | } 333 | } 334 | SDL_Delay( 10 ); 335 | } 336 | 337 | status = AVI_STOP; 338 | if ( v_stream ) 339 | SDL_WaitThread( thread_id, NULL ); 340 | if ( a_stream ) 341 | Mix_HookMusic( NULL, NULL ); 342 | 343 | return ret; 344 | } 345 | 346 | int AVIWrapper::drawFrame( avm::CImage *image ) 347 | { 348 | if ( image == NULL ) return -1; 349 | 350 | unsigned int i, j; 351 | uint32_t comp = image->GetFmt()->biCompression; 352 | 353 | unsigned char *buf = image->Data(); 354 | SDL_LockYUVOverlay( screen_overlay ); 355 | Uint8 *dst_y = screen_overlay->pixels[0]; 356 | Uint8 *dst_u = screen_overlay->pixels[1]; 357 | Uint8 *dst_v = screen_overlay->pixels[2]; 358 | 359 | if ( comp == 0 ){ // BGR 360 | image->ToYUV(); 361 | for ( i=0 ; i 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class AVIWrapper 34 | { 35 | public: 36 | enum { AVI_STOP = 0, 37 | AVI_PLAYING = 1 38 | }; 39 | AVIWrapper(); 40 | ~AVIWrapper(); 41 | 42 | int init( char *filename, bool debug_flag ); 43 | int initAV( SDL_Surface *surface, bool audio_open_flag ); 44 | int play( bool click_flag ); 45 | 46 | void audioCallback( void *userdata, Uint8 *stream, int len ); 47 | int playVideo( void *userdata ); 48 | 49 | unsigned int getWidth(){ return width; }; 50 | unsigned int getHeight(){ return height; }; 51 | 52 | private: 53 | double getAudioTime(); 54 | int drawFrame( avm::CImage *image ); 55 | 56 | SDL_Overlay *screen_overlay; 57 | SDL_Rect screen_rect; 58 | unsigned int width; 59 | unsigned int height; 60 | 61 | IAviReadFile *i_avi; 62 | IAviReadStream *v_stream; 63 | IAviReadStream *a_stream; 64 | int remaining_count; 65 | char *remaining_buffer; 66 | 67 | bool debug_flag; 68 | int status; 69 | SDL_Thread *thread_id; 70 | int64_t time_start; 71 | double frame_start; 72 | }; 73 | 74 | #endif // __AVI_WRAPPER_H__ 75 | -------------------------------------------------------------------------------- /AnimationInfo.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * AnimationInfo.h - General image storage class of ONScripter 4 | * 5 | * Copyright (c) 2001-2013 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifndef __ANIMATION_INFO_H__ 25 | #define __ANIMATION_INFO_H__ 26 | 27 | #include 28 | #include 29 | 30 | #ifndef _SDL_pixels_h 31 | #define SDL_PIXELFORMAT_RGB565 0 32 | #define SDL_PIXELFORMAT_ABGR8888 1 33 | #define SDL_PIXELFORMAT_ARGB8888 2 34 | #endif 35 | 36 | typedef unsigned char uchar3[3]; 37 | 38 | class AnimationInfo{ 39 | public: 40 | #if defined(BPP16) 41 | typedef Uint16 ONSBuf; 42 | #else 43 | typedef Uint32 ONSBuf; 44 | #endif 45 | enum { TRANS_ALPHA = 1, 46 | TRANS_TOPLEFT = 2, 47 | TRANS_COPY = 3, 48 | TRANS_STRING = 4, 49 | TRANS_DIRECT = 5, 50 | TRANS_PALLETTE = 6, 51 | TRANS_TOPRIGHT = 7, 52 | TRANS_MASK = 8 53 | }; 54 | 55 | bool is_copy; // allocated buffers should not be deleted from a copied instance 56 | 57 | /* variables set from the image tag */ 58 | int trans_mode; 59 | uchar3 direct_color; 60 | int pallette_number; 61 | uchar3 color; 62 | SDL_Rect orig_pos; // position and size of the image before resizing 63 | SDL_Rect pos; // position and size of the current cell 64 | 65 | int num_of_cells; 66 | int current_cell; 67 | int direction; 68 | int *duration_list; 69 | uchar3 *color_list; 70 | int loop_mode; 71 | bool is_animatable; 72 | bool is_single_line; 73 | bool is_tight_region; // valid under TRANS_STRING, if false, ruby is parsed 74 | bool is_ruby_drawable; 75 | 76 | char *file_name; 77 | char *mask_file_name; 78 | 79 | /* Variables from AnimationInfo */ 80 | bool visible; 81 | bool abs_flag; 82 | bool affine_flag; 83 | int trans; 84 | char *image_name; 85 | char *surface_name; // used to avoid reloading images 86 | char *mask_surface_name; // used to avoid reloading images 87 | SDL_Surface *image_surface; 88 | unsigned char *alpha_buf; 89 | /* Variables for extended sprite (lsp2, drawsp2, etc.) */ 90 | int scale_x, scale_y, rot; 91 | int mat[2][2], inv_mat[2][2]; 92 | int corner_xy[4][2]; 93 | SDL_Rect bounding_rect; 94 | 95 | enum { BLEND_NORMAL = 0, 96 | BLEND_ADD = 1, 97 | BLEND_SUB = 2 98 | }; 99 | int blending_mode; 100 | int cos_i, sin_i; 101 | 102 | int font_size_xy[2]; // used by prnum and lsp string 103 | int font_pitch[2]; // used by lsp string 104 | int remaining_time; 105 | 106 | int param; // used by prnum and bar 107 | int max_param; // used by bar 108 | int max_width; // used by bar 109 | 110 | AnimationInfo(); 111 | AnimationInfo(const AnimationInfo &anim); 112 | ~AnimationInfo(); 113 | 114 | AnimationInfo& operator =(const AnimationInfo &anim); 115 | 116 | void scalePosXY(int screen_ratio1, int screen_ratio2){ 117 | pos.x = orig_pos.x * screen_ratio1 / screen_ratio2; 118 | pos.y = orig_pos.y * screen_ratio1 / screen_ratio2; 119 | }; 120 | void scalePosWH(int screen_ratio1, int screen_ratio2){ 121 | pos.w = orig_pos.w * screen_ratio1 / screen_ratio2; 122 | pos.h = orig_pos.h * screen_ratio1 / screen_ratio2; 123 | }; 124 | 125 | void reset(); 126 | 127 | void deleteImageName(); 128 | void setImageName( const char *name ); 129 | void deleteSurface(bool delete_surface_name=true); 130 | void remove(); 131 | void removeTag(); 132 | 133 | void stepAnimation(int t); 134 | bool proceedAnimation(); 135 | 136 | void setCell(int cell); 137 | static int doClipping( SDL_Rect *dst, SDL_Rect *clip, SDL_Rect *clipped=NULL ); 138 | void blendOnSurface( SDL_Surface *dst_surface, int dst_x, int dst_y, 139 | SDL_Rect &clip, int alpha=255 ); 140 | void blendOnSurface2( SDL_Surface *dst_surface, int dst_x, int dst_y, 141 | SDL_Rect &clip, int alpha=255 ); 142 | void blendText( SDL_Surface *surface, int dst_x, int dst_y, 143 | SDL_Color &color, SDL_Rect *clip, bool rotate_flag ); 144 | void calcAffineMatrix(); 145 | 146 | static SDL_Surface *allocSurface( int w, int h, Uint32 texture_format ); 147 | static SDL_Surface *alloc32bitSurface( int w, int h, Uint32 texture_format ); 148 | void allocImage( int w, int h, Uint32 texture_format ); 149 | void copySurface( SDL_Surface *surface, SDL_Rect *src_rect, SDL_Rect *dst_rect = NULL ); 150 | void fill( Uint8 r, Uint8 g, Uint8 b, Uint8 a ); 151 | SDL_Surface *setupImageAlpha( SDL_Surface *surface, SDL_Surface *surface_m, bool has_alpha ); 152 | void setImage( SDL_Surface *surface, Uint32 texture_format ); 153 | unsigned char getAlpha(int x, int y); 154 | }; 155 | 156 | #endif // __ANIMATION_INFO_H__ 157 | -------------------------------------------------------------------------------- /BaseReader.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * BaseReader.h - Base class of archive reader 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifndef __BASE_READER_H__ 25 | #define __BASE_READER_H__ 26 | 27 | #include 28 | 29 | #ifndef SEEK_END 30 | #define SEEK_END 2 31 | #endif 32 | 33 | #if defined(LINUX) || defined(MACOSX) 34 | #define DELIMITER '/' 35 | #elif defined(WIN32) 36 | #define DELIMITER '\\' 37 | #elif defined(MACOS9) 38 | #define DELIMITER ':' 39 | #define RELATIVEPATH ":" 40 | #define RELATIVEPATHLENGTH 1 41 | #else 42 | #define DELIMITER '/' 43 | #endif 44 | #ifndef RELATIVEPATH 45 | #define RELATIVEPATH "" 46 | #define RELATIVEPATHLENGTH 0 47 | #endif 48 | 49 | struct BaseReader 50 | { 51 | enum { 52 | NO_COMPRESSION = 0, 53 | SPB_COMPRESSION = 1, 54 | LZSS_COMPRESSION = 2, 55 | NBZ_COMPRESSION = 4 56 | }; 57 | 58 | enum { 59 | ARCHIVE_TYPE_NONE = 0, 60 | ARCHIVE_TYPE_SAR = 1, 61 | ARCHIVE_TYPE_NSA = 2, 62 | ARCHIVE_TYPE_NS2 = 4 //new format since NScr2.91, uses ext ".ns2" 63 | }; 64 | 65 | struct FileInfo{ 66 | char name[256]; 67 | int compression_type; 68 | size_t offset; 69 | size_t length; 70 | size_t original_length; 71 | }; 72 | 73 | struct ArchiveInfo{ 74 | ArchiveInfo *next; 75 | FILE *file_handle; 76 | int power_resume_number; // currently only for PSP 77 | char *file_name; 78 | FileInfo *fi_list; 79 | unsigned int num_of_files; 80 | unsigned long base_offset; 81 | 82 | ArchiveInfo(){ 83 | next = NULL; 84 | file_handle = NULL; 85 | power_resume_number = 0; 86 | file_name = NULL; 87 | fi_list = NULL; 88 | num_of_files = 0; 89 | } 90 | ~ArchiveInfo(){ 91 | if (file_handle) fclose( file_handle ); 92 | if (file_name) delete[] file_name; 93 | if (fi_list) delete[] fi_list; 94 | } 95 | }; 96 | 97 | virtual ~BaseReader(){}; 98 | 99 | virtual int open( const char *name=NULL ) = 0; 100 | virtual int close() = 0; 101 | 102 | virtual const char *getArchiveName() const = 0; 103 | virtual int getNumFiles() = 0; 104 | virtual void registerCompressionType( const char *ext, int type ) = 0; 105 | 106 | virtual FileInfo getFileByIndex( unsigned int index ) = 0; 107 | virtual size_t getFileLength( const char *file_name ) = 0; 108 | virtual size_t getFile( const char *file_name, unsigned char *buffer, int *location=NULL ) = 0; 109 | }; 110 | 111 | #endif // __BASE_READER_H__ 112 | -------------------------------------------------------------------------------- /ButtonLink.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * ButtonLink.h - Base button class 4 | * 5 | * Copyright (c) 2001-2013 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifndef __BUTTON_LINK_H__ 25 | #define __BUTTON_LINK_H__ 26 | 27 | #include "AnimationInfo.h" 28 | 29 | struct ButtonLink{ 30 | enum { NORMAL_BUTTON = 0, 31 | SPRITE_BUTTON = 1, 32 | LOOKBACK_BUTTON = 2, 33 | TMP_SPRITE_BUTTON = 3 34 | }; 35 | 36 | ButtonLink *next; 37 | int button_type; 38 | int no; 39 | int sprite_no; 40 | char *exbtn_ctl[3]; 41 | SDL_Rect select_rect; 42 | SDL_Rect image_rect; 43 | AnimationInfo *anim[2]; 44 | int show_flag; // 0...show nothing, 1... show anim[0], 2 ... show anim[1] 45 | 46 | ButtonLink(){ 47 | button_type = NORMAL_BUTTON; 48 | next = NULL; 49 | exbtn_ctl[0] = exbtn_ctl[1] = exbtn_ctl[2] = NULL; 50 | anim[0] = anim[1] = NULL; 51 | show_flag = 0; 52 | }; 53 | 54 | ~ButtonLink(){ 55 | if ( (button_type == NORMAL_BUTTON || button_type == TMP_SPRITE_BUTTON) && 56 | anim[0] ) delete anim[0]; 57 | for (int i=0 ; i<3 ; i++) 58 | if ( exbtn_ctl[i] ) delete[] exbtn_ctl[i]; 59 | }; 60 | 61 | void insert( ButtonLink *button ){ 62 | button->next = this->next; 63 | this->next = button; 64 | }; 65 | 66 | void removeSprite( int no ){ 67 | ButtonLink *bl = this; 68 | while( bl->next ){ 69 | if ( bl->next->sprite_no == no && 70 | bl->next->button_type == SPRITE_BUTTON ){ 71 | ButtonLink *bl2 = bl->next; 72 | bl->next = bl->next->next; 73 | delete bl2; 74 | } 75 | else{ 76 | bl = bl->next; 77 | } 78 | } 79 | }; 80 | }; 81 | 82 | #endif // __BUTTON_LINK_H__ 83 | -------------------------------------------------------------------------------- /DirectReader.h: -------------------------------------------------------------------------------- 1 | //$Id:$ -*- C++ -*- 2 | /* 3 | * DirectReader.h - Reader from independent files 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * (C) 2014 jh10001 7 | * 8 | * ogapee@aqua.dti2.ne.jp 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #ifndef __DIRECT_READER_H__ 26 | #define __DIRECT_READER_H__ 27 | 28 | #include "BaseReader.h" 29 | #include 30 | 31 | #define MAX_FILE_NAME_LENGTH 256 32 | 33 | class DirectReader : public BaseReader 34 | { 35 | public: 36 | DirectReader( const char *path=NULL, const unsigned char *key_table=NULL ); 37 | ~DirectReader(); 38 | 39 | int open( const char *name=NULL ); 40 | int close(); 41 | 42 | const char *getArchiveName() const; 43 | int getNumFiles(); 44 | void registerCompressionType( const char *ext, int type ); 45 | 46 | struct FileInfo getFileByIndex(unsigned int index); 47 | size_t getFileLength( const char *file_name ); 48 | size_t getFile( const char *file_name, unsigned char *buffer, int *location=NULL ); 49 | 50 | static void convertFromSJISToEUC( char *buf ); 51 | static void convertFromSJISToUTF8( char *dst_buf, const char *src_buf ); 52 | 53 | protected: 54 | char *file_full_path; 55 | char *file_sub_path; 56 | size_t file_path_len; 57 | char *capital_name; 58 | char *capital_name_tmp; 59 | 60 | char *archive_path; 61 | unsigned char key_table[256]; 62 | bool key_table_flag; 63 | int getbit_mask; 64 | size_t getbit_len, getbit_count; 65 | unsigned char *read_buf; 66 | unsigned char *decomp_buffer; 67 | size_t decomp_buffer_len; 68 | 69 | struct RegisteredCompressionType{ 70 | RegisteredCompressionType *next; 71 | char *ext; 72 | int type; 73 | RegisteredCompressionType(){ 74 | ext = NULL; 75 | next = NULL; 76 | }; 77 | RegisteredCompressionType( const char *ext, int type ){ 78 | this->ext = new char[ strlen(ext)+1 ]; 79 | for ( unsigned int i=0 ; iext[i] = ext[i]; 81 | if ( this->ext[i] >= 'a' && this->ext[i] <= 'z' ) 82 | this->ext[i] += 'A' - 'a'; 83 | } 84 | this->type = type; 85 | this->next = NULL; 86 | }; 87 | ~RegisteredCompressionType(){ 88 | if (ext) delete[] ext; 89 | }; 90 | } root_registered_compression_type, *last_registered_compression_type; 91 | 92 | FILE *fopen(const char *path, const char *mode); 93 | unsigned char readChar( FILE *fp ); 94 | unsigned short readShort( FILE *fp ); 95 | unsigned long readLong( FILE *fp ); 96 | void writeChar( FILE *fp, unsigned char ch ); 97 | void writeShort( FILE *fp, unsigned short ch ); 98 | void writeLong( FILE *fp, unsigned long ch ); 99 | static unsigned short swapShort( unsigned short ch ); 100 | static unsigned long swapLong( unsigned long ch ); 101 | size_t decodeNBZ( FILE *fp, size_t offset, unsigned char *buf ); 102 | size_t encodeNBZ( FILE *fp, size_t length, unsigned char *buf ); 103 | int getbit( FILE *fp, int n ); 104 | size_t decodeSPB( FILE *fp, size_t offset, unsigned char *buf ); 105 | size_t decodeLZSS( struct ArchiveInfo *ai, int no, unsigned char *buf ); 106 | int getRegisteredCompressionType( const char *file_name ); 107 | size_t getDecompressedFileLength( int type, FILE *fp, size_t offset ); 108 | 109 | private: 110 | FILE *getFileHandle( const char *file_name, int &compression_type, size_t *length ); 111 | }; 112 | 113 | #endif // __DIRECT_READER_H__ 114 | -------------------------------------------------------------------------------- /DirtyRect.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * DirtyRect.cpp - Invalid region on text_surface which should be updated 4 | * 5 | * Copyright (c) 2001-2012 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include "DirtyRect.h" 25 | 26 | DirtyRect::DirtyRect() 27 | { 28 | screen_width = screen_height = 0; 29 | bounding_box.w = bounding_box.h = 0; 30 | } 31 | 32 | DirtyRect::DirtyRect( const DirtyRect &d ) 33 | { 34 | screen_width = d.screen_width; 35 | screen_height = d.screen_height; 36 | bounding_box = d.bounding_box; 37 | } 38 | 39 | DirtyRect& DirtyRect::operator =( const DirtyRect &d ) 40 | { 41 | screen_width = d.screen_width; 42 | screen_height = d.screen_height; 43 | bounding_box = d.bounding_box; 44 | 45 | return *this; 46 | } 47 | 48 | DirtyRect::~DirtyRect() 49 | { 50 | } 51 | 52 | void DirtyRect::setDimension(int w, int h) 53 | { 54 | screen_width = w; 55 | screen_height = h; 56 | } 57 | 58 | void DirtyRect::add( SDL_Rect src ) 59 | { 60 | //printf("add %d %d %d %d\n", src.x, src.y, src.w, src.h ); 61 | if ( src.w == 0 || src.h == 0 ) return; 62 | 63 | if (src.x < 0){ 64 | if (src.w < -src.x) return; 65 | src.w += src.x; 66 | src.x = 0; 67 | } 68 | if (src.y < 0){ 69 | if (src.h < -src.y) return; 70 | src.h += src.y; 71 | src.y = 0; 72 | } 73 | 74 | if (src.x >= screen_width) return; 75 | if (src.x+src.w >= screen_width) 76 | src.w = screen_width-src.x; 77 | 78 | if (src.y >= screen_height) return; 79 | if (src.y+src.h >= screen_height) 80 | src.h = screen_height-src.y; 81 | 82 | bounding_box = calcBoundingBox( bounding_box, src ); 83 | } 84 | 85 | SDL_Rect DirtyRect::calcBoundingBox( SDL_Rect src1, SDL_Rect &src2 ) 86 | { 87 | if ( src2.w == 0 || src2.h == 0 ){ 88 | return src1; 89 | } 90 | if ( src1.w == 0 || src1.h == 0 ){ 91 | return src2; 92 | } 93 | 94 | if ( src1.x > src2.x ){ 95 | src1.w += src1.x - src2.x; 96 | src1.x = src2.x; 97 | } 98 | if ( src1.y > src2.y ){ 99 | src1.h += src1.y - src2.y; 100 | src1.y = src2.y; 101 | } 102 | if ( src1.x + src1.w < src2.x + src2.w ){ 103 | src1.w = src2.x + src2.w - src1.x; 104 | } 105 | if ( src1.y + src1.h < src2.y + src2.h ){ 106 | src1.h = src2.y + src2.h - src1.y; 107 | } 108 | 109 | return src1; 110 | } 111 | 112 | void DirtyRect::clear() 113 | { 114 | bounding_box.w = bounding_box.h = 0; 115 | } 116 | 117 | void DirtyRect::fill( int w, int h ) 118 | { 119 | bounding_box.x = bounding_box.y = 0; 120 | bounding_box.w = w; 121 | bounding_box.h = h; 122 | } 123 | -------------------------------------------------------------------------------- /DirtyRect.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * DirtyRect.h - Invalid region on text_surface which should be updated 4 | * 5 | * Copyright (c) 2001-2012 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifndef __DIRTY_RECT__ 25 | #define __DIRTY_RECT__ 26 | 27 | #include 28 | 29 | struct DirtyRect 30 | { 31 | DirtyRect(); 32 | DirtyRect( const DirtyRect &d ); 33 | DirtyRect& operator =( const DirtyRect &d ); 34 | ~DirtyRect(); 35 | 36 | void setDimension(int w, int h); 37 | void add( SDL_Rect src ); 38 | void clear(); 39 | void fill( int w, int h ); 40 | 41 | SDL_Rect calcBoundingBox( SDL_Rect src1, SDL_Rect &src2 ); 42 | 43 | int screen_width, screen_height; 44 | SDL_Rect bounding_box; 45 | }; 46 | 47 | #endif // __DIRTY_RECT__ 48 | -------------------------------------------------------------------------------- /FontInfo.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * FontInfo.cpp - Font information storage class of ONScripter 4 | * 5 | * Copyright (c) 2001-2013 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include "FontInfo.h" 25 | #include 26 | #include 27 | 28 | #if defined(PSP) 29 | #include 30 | #include 31 | extern int psp_power_resume_number; 32 | #endif 33 | 34 | static struct FontContainer{ 35 | FontContainer *next; 36 | int size; 37 | TTF_Font *font[2]; 38 | #if defined(PSP) 39 | SDL_RWops *rw_ops; 40 | int power_resume_number; 41 | char name[256]; 42 | #endif 43 | 44 | FontContainer(){ 45 | size = 0; 46 | next = NULL; 47 | font[0] = font[1] = NULL; 48 | #if defined(PSP) 49 | rw_ops = NULL; 50 | power_resume_number = 0; 51 | #endif 52 | }; 53 | } root_font_container; 54 | 55 | FontInfo::FontInfo() 56 | { 57 | ttf_font[0] = ttf_font[1] = NULL; 58 | 59 | color[0] = color[1] = color[2] = 0xff; 60 | on_color[0] = on_color[1] = on_color[2] = 0xff; 61 | off_color[0] = off_color[1] = off_color[2] = 0xaa; 62 | nofile_color[0] = 0x55; 63 | nofile_color[1] = 0x55; 64 | nofile_color[2] = 0x99; 65 | rubyon_flag = false; 66 | 67 | reset(); 68 | } 69 | 70 | void FontInfo::reset() 71 | { 72 | tateyoko_mode = YOKO_MODE; 73 | clear(); 74 | 75 | is_bold = true; 76 | is_shadow = true; 77 | is_transparent = true; 78 | is_newline_accepted = false; 79 | } 80 | 81 | void *FontInfo::openFont( char *font_file, int ratio1, int ratio2 ) 82 | { 83 | int font_size; 84 | if ( font_size_xy[0] < font_size_xy[1] ) 85 | font_size = font_size_xy[0]; 86 | else 87 | font_size = font_size_xy[1]; 88 | 89 | FontContainer *fc = &root_font_container; 90 | while( fc->next ){ 91 | if ( fc->next->size == font_size ) break; 92 | fc = fc->next; 93 | } 94 | if ( !fc->next ){ 95 | fc->next = new FontContainer(); 96 | fc->next->size = font_size; 97 | FILE *fp = fopen( font_file, "r" ); 98 | if ( fp == NULL ) return NULL; 99 | fclose( fp ); 100 | #if defined(PSP) 101 | fc->next->rw_ops = SDL_RWFromFile(font_file, "r"); 102 | fc->next->font[0] = TTF_OpenFontRW( fc->next->rw_ops, SDL_TRUE, font_size * ratio1 / ratio2 ); 103 | #if (SDL_TTF_MAJOR_VERSION>=2) && (SDL_TTF_MINOR_VERSION>=0) && (SDL_TTF_PATCHLEVEL>=10) 104 | fc->next->font[1] = TTF_OpenFontRW( fc->next->rw_ops, SDL_TRUE, font_size * ratio1 / ratio2 ); 105 | TTF_SetFontOutline(fc->next->font[1], 1); 106 | #endif 107 | fc->next->power_resume_number = psp_power_resume_number; 108 | strcpy(fc->next->name, font_file); 109 | #else 110 | fc->next->font[0] = TTF_OpenFont( font_file, font_size * ratio1 / ratio2 ); 111 | #if (SDL_TTF_MAJOR_VERSION>=2) && (SDL_TTF_MINOR_VERSION>=0) && (SDL_TTF_PATCHLEVEL>=10) 112 | fc->next->font[1] = TTF_OpenFont( font_file, font_size * ratio1 / ratio2 ); 113 | TTF_SetFontOutline(fc->next->font[1], 1); 114 | #endif 115 | #endif 116 | } 117 | #if defined(PSP) 118 | else if (fc->next->power_resume_number != psp_power_resume_number){ 119 | FILE *fp = fopen(fc->next->name, "r"); 120 | fc->next->rw_ops->hidden.stdio.fp = fp; 121 | fc->next->power_resume_number = psp_power_resume_number; 122 | } 123 | #endif 124 | 125 | ttf_font[0] = (void*)fc->next->font[0]; 126 | ttf_font[1] = (void*)fc->next->font[1]; 127 | 128 | return fc->next->font; 129 | } 130 | 131 | void FontInfo::setTateyokoMode( int tateyoko_mode ) 132 | { 133 | this->tateyoko_mode = tateyoko_mode; 134 | clear(); 135 | } 136 | 137 | int FontInfo::getTateyokoMode() 138 | { 139 | return tateyoko_mode; 140 | } 141 | 142 | int FontInfo::getRemainingLine() 143 | { 144 | if (tateyoko_mode == YOKO_MODE) 145 | return num_xy[1] - xy[1]/2; 146 | else 147 | return num_xy[1] - num_xy[0] + xy[0]/2 + 1; 148 | } 149 | 150 | int FontInfo::x(bool use_ruby_offset) 151 | { 152 | int x = xy[0]*pitch_xy[0]/2 + top_xy[0] + line_offset_xy[0]; 153 | if (use_ruby_offset && rubyon_flag && tateyoko_mode == TATE_MODE) 154 | x += font_size_xy[0] - pitch_xy[0]; 155 | return x; 156 | } 157 | 158 | int FontInfo::y(bool use_ruby_offset) 159 | { 160 | int y = xy[1]*pitch_xy[1]/2 + top_xy[1] + line_offset_xy[1]; 161 | if (use_ruby_offset && rubyon_flag && tateyoko_mode == YOKO_MODE) 162 | y += pitch_xy[1] - font_size_xy[1]; 163 | return y; 164 | } 165 | 166 | void FontInfo::setXY( int x, int y ) 167 | { 168 | if ( x != -1 ) xy[0] = x*2; 169 | if ( y != -1 ) xy[1] = y*2; 170 | } 171 | 172 | void FontInfo::clear() 173 | { 174 | if (tateyoko_mode == YOKO_MODE) 175 | setXY(0, 0); 176 | else 177 | setXY(num_xy[0]-1, 0); 178 | line_offset_xy[0] = line_offset_xy[1] = 0; 179 | } 180 | 181 | void FontInfo::newLine() 182 | { 183 | if (tateyoko_mode == YOKO_MODE){ 184 | xy[0] = 0; 185 | xy[1] += 2; 186 | } 187 | else{ 188 | xy[0] -= 2; 189 | xy[1] = 0; 190 | } 191 | line_offset_xy[0] = line_offset_xy[1] = 0; 192 | } 193 | 194 | void FontInfo::setLineArea(int num) 195 | { 196 | num_xy[tateyoko_mode] = num; 197 | num_xy[1-tateyoko_mode] = 1; 198 | } 199 | 200 | bool FontInfo::isEndOfLine(int margin) 201 | { 202 | if (xy[tateyoko_mode] + margin >= num_xy[tateyoko_mode]*2) return true; 203 | 204 | return false; 205 | } 206 | 207 | bool FontInfo::isLineEmpty() 208 | { 209 | if (xy[tateyoko_mode] == 0) return true; 210 | 211 | return false; 212 | } 213 | 214 | void FontInfo::advanceCharInHankaku(int offset) 215 | { 216 | xy[tateyoko_mode] += offset; 217 | } 218 | 219 | void FontInfo::addLineOffset(int offset) 220 | { 221 | line_offset_xy[tateyoko_mode] += offset; 222 | } 223 | 224 | SDL_Rect FontInfo::calcUpdatedArea(int start_xy[2], int ratio1, int ratio2) 225 | { 226 | SDL_Rect rect; 227 | 228 | if (tateyoko_mode == YOKO_MODE){ 229 | if (start_xy[1] == xy[1]){ 230 | rect.x = top_xy[0] + pitch_xy[0]*start_xy[0]/2; 231 | rect.w = pitch_xy[0]*(xy[0]-start_xy[0])/2+1; 232 | } 233 | else{ 234 | rect.x = top_xy[0]; 235 | rect.w = pitch_xy[0]*num_xy[0]; 236 | } 237 | rect.y = top_xy[1] + start_xy[1]*pitch_xy[1]/2; 238 | rect.h = font_size_xy[1] + pitch_xy[1]*(xy[1]-start_xy[1])/2; 239 | if (rubyon_flag) rect.h += pitch_xy[1] - font_size_xy[1]; 240 | } 241 | else{ 242 | rect.x = top_xy[0] + pitch_xy[0]*xy[0]/2; 243 | rect.w = font_size_xy[0] + pitch_xy[0]*(start_xy[0]-xy[0])/2; 244 | if (rubyon_flag) rect.w += font_size_xy[0]-pitch_xy[0]; 245 | if (start_xy[0] == xy[0]){ 246 | rect.y = top_xy[1] + pitch_xy[1]*start_xy[1]/2; 247 | rect.h = pitch_xy[1]*(xy[1]-start_xy[1])/2+1; 248 | } 249 | else{ 250 | rect.y = top_xy[1]; 251 | rect.h = pitch_xy[1]*num_xy[1]; 252 | } 253 | num_xy[0] = (xy[0]-start_xy[0])/2+1; 254 | } 255 | 256 | return rect; 257 | } 258 | 259 | void FontInfo::addShadeArea(SDL_Rect &rect, int dx, int dy, int dw, int dh) 260 | { 261 | rect.x += dx; 262 | rect.y += dy; 263 | rect.w += dw; 264 | rect.h += dh; 265 | } 266 | 267 | int FontInfo::initRuby(FontInfo &body_info, int body_count, int ruby_count) 268 | { 269 | if ((tateyoko_mode == YOKO_MODE && 270 | body_count + body_info.xy[0]/2 >= body_info.num_xy[0]-1) || 271 | (tateyoko_mode == TATE_MODE && 272 | body_count + body_info.xy[1]/2 > body_info.num_xy[1])) 273 | body_info.newLine(); 274 | 275 | top_xy[0] = body_info.x(); 276 | top_xy[1] = body_info.y(); 277 | pitch_xy[0] = font_size_xy[0]; 278 | pitch_xy[1] = font_size_xy[1]; 279 | 280 | int margin=0; 281 | 282 | if (tateyoko_mode == YOKO_MODE){ 283 | top_xy[1] -= font_size_xy[1]; 284 | num_xy[0] = ruby_count; 285 | num_xy[1] = 1; 286 | } 287 | else{ 288 | top_xy[0] += body_info.font_size_xy[0]; 289 | num_xy[0] = 1; 290 | num_xy[1] = ruby_count; 291 | } 292 | 293 | if (ruby_count*font_size_xy[tateyoko_mode] >= body_count*body_info.pitch_xy[tateyoko_mode]){ 294 | margin = (ruby_count*font_size_xy[tateyoko_mode] - body_count*body_info.pitch_xy[tateyoko_mode] + 1)/2; 295 | } 296 | else{ 297 | int offset = 0; 298 | if (ruby_count > 0) 299 | offset = (body_count*body_info.pitch_xy[tateyoko_mode] - ruby_count*font_size_xy[tateyoko_mode] + ruby_count) / (ruby_count*2); 300 | top_xy[tateyoko_mode] += offset; 301 | pitch_xy[tateyoko_mode] += offset*2; 302 | } 303 | body_info.line_offset_xy[tateyoko_mode] += margin; 304 | 305 | clear(); 306 | 307 | return margin; 308 | } 309 | -------------------------------------------------------------------------------- /FontInfo.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * FontInfo.h - Font information storage class of ONScripter 4 | * 5 | * Copyright (c) 2001-2012 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifndef __FONT_INFO_H__ 25 | #define __FONT_INFO_H__ 26 | 27 | #include 28 | 29 | typedef unsigned char uchar3[3]; 30 | 31 | class FontInfo{ 32 | public: 33 | enum { YOKO_MODE = 0, 34 | TATE_MODE = 1 35 | }; 36 | void *ttf_font[2]; // 0...normal rendering, 1...outline rendering 37 | uchar3 color; 38 | uchar3 on_color, off_color, nofile_color; 39 | int font_size_xy[2]; 40 | int top_xy[2]; // Top left origin 41 | int num_xy[2]; // Row and column of the text windows 42 | int xy[2]; // Current position 43 | int old_xy[2]; 44 | int pitch_xy[2]; // Width and height of a character 45 | int wait_time; 46 | bool is_bold; 47 | bool is_shadow; 48 | bool is_transparent; 49 | bool is_newline_accepted; 50 | uchar3 window_color; 51 | 52 | int line_offset_xy[2]; // ruby offset for each line 53 | bool rubyon_flag; 54 | int tateyoko_mode; 55 | 56 | FontInfo(); 57 | void reset(); 58 | void *openFont( char *font_file, int ratio1, int ratio2 ); 59 | void setTateyokoMode( int tateyoko_mode ); 60 | int getTateyokoMode(); 61 | int getRemainingLine(); 62 | 63 | int x(bool use_ruby_offset=true); 64 | int y(bool use_ruby_offset=true); 65 | void setXY( int x=-1, int y=-1 ); 66 | void clear(); 67 | void newLine(); 68 | void setLineArea(int num); 69 | 70 | bool isEndOfLine(int margin=0); 71 | bool isLineEmpty(); 72 | void advanceCharInHankaku(int offest); 73 | void addLineOffset(int margin); 74 | void setRubyOnFlag(bool flag); 75 | 76 | SDL_Rect calcUpdatedArea(int start_xy[2], int ratio1, int ratio2); 77 | void addShadeArea(SDL_Rect &rect, int dx, int dy, int dw, int dh); 78 | int initRuby(FontInfo &body_info, int body_count, int ruby_count); 79 | }; 80 | 81 | #endif // __FONT_INFO_H__ 82 | -------------------------------------------------------------------------------- /LUAHandler.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * LUAHandler.h - LUA handler for ONScripter 4 | * 5 | * Copyright (c) 2001-2013 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #if !defined(__LUA_HANDLER_H__) && defined(USE_LUA) 25 | #define __LUA_HANDLER_H__ 26 | 27 | #include 28 | 29 | class ONScripter; 30 | class ScriptHandler; 31 | 32 | class LUAHandler{ 33 | public: 34 | enum { LUA_TAG, 35 | LUA_TEXT0, 36 | LUA_TEXT, 37 | LUA_ANIMATION, 38 | LUA_CLOSE, 39 | LUA_END, 40 | LUA_SAVEPOINT, 41 | LUA_SAVE, 42 | LUA_LOAD, 43 | LUA_RESET, 44 | MAX_CALLBACK 45 | }; 46 | 47 | LUAHandler(); 48 | ~LUAHandler(); 49 | 50 | void init(ONScripter *ons, ScriptHandler *sh); 51 | void addCallback(const char *label); 52 | 53 | int callFunction(bool is_callback, const char *cmd); 54 | 55 | bool isCallbackEnabled(int val); 56 | 57 | bool is_animatable; 58 | int duration_time; 59 | int remaining_time; 60 | 61 | //private: 62 | ONScripter *ons; 63 | lua_State *state; 64 | ScriptHandler *sh; 65 | 66 | char error_str[256]; 67 | 68 | bool callback_state[MAX_CALLBACK]; 69 | }; 70 | 71 | #endif // __LUA_HANDLER_H__ 72 | -------------------------------------------------------------------------------- /Makefile.ARMLinux: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.ARMLinux - Makefile rules for linux on Zaurus 4 | # 5 | 6 | INCS = `sdl-config --cflags` 7 | 8 | # for Qtopia 9 | LIBS = -lSDL -lSDL_ttf -lSDL_image -lSDL_mixer -lbz2 -lfreetype -ljpeg -lm `sdl-config --libs` -lvorbisidec 10 | # for SL-5500, SL-A300, SL-B500, SL-C700 and SL-C750 11 | DEFS = -DLINUX -DPDA_WIDTH=640 -DBPP16 -DQWS -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS 12 | 13 | EXESUFFIX = 14 | OBJSUFFIX = .o 15 | 16 | .SUFFIXES: 17 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 18 | 19 | CC = arm-linux-g++ 20 | LD = arm-linux-g++ -o 21 | 22 | CFLAGS = -O3 -Wall -fno-exceptions -fno-rtti -fno-check-new -fomit-frame-pointer -pipe -c $(INCS) $(DEFS) 23 | RM = rm -f 24 | 25 | TARGET = onscripter$(EXESUFFIX) sarconv$(EXESUFFIX) nsaconv$(EXESUFFIX) 26 | EXT_OBJS = 27 | 28 | include Makefile.onscripter 29 | -------------------------------------------------------------------------------- /Makefile.GP2X: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.GP2X - Makefile rules for GP2X 4 | # 5 | 6 | PREF = /usr/local/devkitPro/devkitGP2X 7 | 8 | INCS = `$(PREF)/bin/sdl-config --cflags` `$(PREF)/bin/freetype-config --cflags` 9 | 10 | LIBS = -static `$(PREF)/bin/sdl-config --static-libs` -lSDL_ttf -lSDL_image -lSDL_mixer -lSDL -lmikmod -lfreetype -ljpeg -lpng -lz -lbz2 -lvorbisidec 11 | 12 | DEFS = -DGP2X -DLINUX -DPDA_WIDTH=320 -DBPP16 -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS 13 | 14 | EXESUFFIX = .gpe 15 | OBJSUFFIX = .o 16 | 17 | .SUFFIXES: 18 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 19 | 20 | CC = arm-linux-g++ 21 | LD = arm-linux-g++ -o 22 | 23 | CFLAGS = -O3 -Wall -fno-exceptions -fno-rtti -fno-check-new -fomit-frame-pointer -pipe -c $(INCS) $(DEFS) 24 | RM = rm -f 25 | 26 | TARGET = onscripter$(EXESUFFIX) nsaconv$(EXESUFFIX) sarconv$(EXESUFFIX) nsadec$(EXESUFFIX) sardec$(EXESUFFIX) 27 | EXT_OBJS = 28 | 29 | include Makefile.onscripter 30 | -------------------------------------------------------------------------------- /Makefile.Linux: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.Linux - Makefile rules for linux 4 | # 5 | 6 | EXESUFFIX = 7 | OBJSUFFIX = .o 8 | 9 | .SUFFIXES: 10 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 11 | 12 | TARGET = onscripter$(EXESUFFIX) \ 13 | sardec$(EXESUFFIX) \ 14 | nsadec$(EXESUFFIX) \ 15 | sarconv$(EXESUFFIX) \ 16 | nsaconv$(EXESUFFIX) 17 | EXT_OBJS = 18 | 19 | # mandatory: SDL, SDL_ttf, SDL_image, SDL_mixer, bzip2, libjpeg 20 | DEFS = -DLINUX 21 | INCS = `sdl-config --cflags` 22 | LIBS = `sdl-config --libs` -lSDL_ttf -lSDL_image -lSDL_mixer -lbz2 -ljpeg -lm 23 | 24 | # recommended: smpeg 25 | DEFS += -DUSE_SMPEG 26 | INCS += `smpeg-config --cflags` 27 | LIBS += `smpeg-config --libs` 28 | 29 | # recommended: fontconfig (to get default font) 30 | DEFS += -DUSE_FONTCONFIG 31 | LIBS += -lfontconfig 32 | 33 | # recommended: OggVorbis 34 | DEFS += -DUSE_OGG_VORBIS 35 | LIBS += -logg -lvorbis -lvorbisfile 36 | 37 | # optional: Integer OggVorbis 38 | #DEFS += -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS 39 | #LIBS += -lvorbisidec 40 | 41 | # optional: support CD audio 42 | DEFS += -DUSE_CDROM 43 | 44 | # optional: avifile 45 | DEFS += -DUSE_AVIFILE 46 | INCS += `avifile-config --cflags` 47 | LIBS += `avifile-config --libs` 48 | TARGET += simple_aviplay$(EXESUFFIX) 49 | EXT_OBJS += AVIWrapper$(OBJSUFFIX) 50 | 51 | # optional: lua 52 | DEFS += -DUSE_LUA 53 | INCS += -I/usr/include/lua5.1 54 | LIBS += -llua5.1 55 | EXT_OBJS += LUAHandler$(OBJSUFFIX) 56 | 57 | # optional: force screen width for PDA 58 | #DEFS += -DPDA_WIDTH=640 59 | 60 | # optional: enable English mode 61 | #DEFS += -DENABLE_1BYTE_CHAR -DFORCE_1BYTE_CHAR 62 | 63 | 64 | # for GNU g++ 65 | CC = g++ 66 | LD = g++ -o 67 | 68 | #CFLAGS = -g -Wall -pipe -c $(INCS) $(DEFS) 69 | CFLAGS = -O3 -Wall -fomit-frame-pointer -pipe -c $(INCS) $(DEFS) 70 | 71 | # for GCC on PowerPC specfied 72 | #CC = powerpc-unknown-linux-gnu-g++ 73 | #LD = powerpc-unknown-linux-gnu-g++ -o 74 | 75 | #CFLAGS = -O3 -mtune=G4 -maltivec -mabi=altivec -mpowerpc-gfxopt -mmultiple -mstring -Wall -fomit-frame-pointer -pipe -c $(INCS) $(DEFS) 76 | 77 | # for Intel compiler 78 | #CC = icc 79 | #LD = icc -o 80 | 81 | #CFLAGS = -O3 -tpp6 -xK -c $(INCS) $(DEFS) 82 | 83 | RM = rm -f 84 | 85 | include Makefile.onscripter 86 | -------------------------------------------------------------------------------- /Makefile.MacOSX: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.MacOSX - Makefile rules for MacOS X 4 | # Thanks adas-san, Takano-san and tmkk-san 5 | # 6 | 7 | INCS = `sdl-config --cflags` `smpeg-config --cflags` 8 | 9 | LIBS = `sdl-config --libs` `smpeg-config --libs` `freetype-config --libs` -lSDL_ttf -lSDL_image -lSDL_mixer -lbz2 -lm -ljpeg -framework QuickTime -framework CoreFoundation 10 | DEFS = -DMACOSX -DUSE_CDROM -DUTF8_CAPTION -DUTF8_FILESYSTEM 11 | 12 | EXESUFFIX = 13 | OBJSUFFIX = .o 14 | 15 | .SUFFIXES: 16 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 17 | 18 | CC = c++ 19 | LD = c++ -o 20 | 21 | #CFLAGS = -g -Wall -Wpointer-arith -pipe -c $(INCS) $(DEFS) 22 | CFLAGS = -O3 -Wall -Wpointer-arith -pipe -c $(INCS) $(DEFS) 23 | RM = rm -f 24 | 25 | TARGET = onscripter$(EXESUFFIX) sardec$(EXESUFFIX) nsadec$(EXESUFFIX) sarconv$(EXESUFFIX) nsaconv$(EXESUFFIX) 26 | 27 | include Makefile.onscripter 28 | -------------------------------------------------------------------------------- /Makefile.PSP: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.PSP - Makefile rules for Sony Play Station Portable Firmware version 1.0 4 | # Thanks Shiikuru-san 5 | # 6 | 7 | PSPPRE = $(shell psp-config --psp-prefix) 8 | PSPDEV = $(shell psp-config --pspdev-path) 9 | PSPSDK = $(shell psp-config --pspsdk-path) 10 | 11 | INCS = $(shell $(PSPPRE)/bin/sdl-config --cflags) $(shell $(PSPPRE)/bin/freetype-config --cflags) 12 | LIBS = $(shell $(PSPPRE)/bin/sdl-config --libs) 13 | LIBS += -lSDL_ttf -lfreetype -lSDL_mixer -lSDL_image -lSDL -lSDLmain -lbz2 -ljpeg -lpng -lz -lmad -lvorbisidec 14 | 15 | # Include PSPSDK and Libc Headers 16 | INCS += -I$(PSPSDK)/include -I$(PSPDEV)/include -I$(PSPPRE)/include 17 | 18 | # Link PSPSDK and Libc Libraries 19 | LIBS += -L$(PSPSDK)/lib -L$(PSPDEV)/lib -lstdc++ -lc -lm -lpsppower -lpspnet_inet 20 | 21 | 22 | # with OggVorbis (Tremor) in PDA size (QVGA) 23 | #DEFS = -DPSP -DPDA_WIDTH=320 -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS -DUSE_RWOPS 24 | # with OggVorbis (Tremor) in PSP size (360x270) 25 | DEFS = -DPSP -DPDA_WIDTH=360 -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS -DUSE_RWOPS 26 | # with OggVorbis (Tremor) in PSP size (384x288) 27 | #DEFS = -DPSP -DPDA_WIDTH=384 -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS -DUSE_RWOPS 28 | 29 | EXESUFFIX = .elf 30 | OBJSUFFIX = .o 31 | 32 | .SUFFIXES: 33 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 34 | 35 | CC = psp-gcc 36 | LD = psp-gcc -o 37 | 38 | CFLAGS = -g -G0 -O3 -Wall -Wpointer-arith -fno-exceptions -fno-rtti -fno-check-new -pipe -c $(INCS) $(DEFS) 39 | RM = rm -f 40 | 41 | TARGET = EBOOT.PBP 42 | EXT_OBJS = MadWrapper$(OBJSUFFIX) 43 | 44 | 45 | # onscripter.elf -> EBOOT.PBP for PSP Firmware version 1.0 46 | 47 | FIXUP_IMPORTS = psp-fixup-imports 48 | STRIP = psp-strip 49 | MKSFO = mksfo 50 | PACK_PBP = pack-pbp 51 | 52 | PSP_TARGET = onscripter$(EXESUFFIX) 53 | PSP_TARGET_FIXUP = onscripter_fixup$(EXESUFFIX) 54 | PSP_TARGET_STRIP = onscripter_strip$(EXESUFFIX) 55 | PSP_EBOOT_TITLE = ONScripter for PSP 56 | PSP_EBOOT_SFO = PARAM.SFO 57 | PSP_EBOOT_ICON = NULL 58 | PSP_EBOOT_ICON1 = NULL 59 | PSP_EBOOT_UNKPNG = NULL 60 | PSP_EBOOT_PIC1 = NULL 61 | PSP_EBOOT_SND0 = NULL 62 | PSP_EBOOT_PSAR = NULL 63 | 64 | EBOOT.PBP : $(PSP_TARGET_STRIP) $(PSP_EBOOT_SFO) 65 | $(PACK_PBP) EBOOT.PBP $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON) \ 66 | $(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1) \ 67 | $(PSP_EBOOT_SND0) $(PSP_TARGET_STRIP) $(PSP_EBOOT_PSAR) 68 | 69 | $(PSP_EBOOT_SFO) : 70 | $(MKSFO) '$(PSP_EBOOT_TITLE)' $(PSP_EBOOT_SFO) 71 | 72 | $(PSP_TARGET_FIXUP) : $(PSP_TARGET) 73 | $(FIXUP_IMPORTS) $(PSP_TARGET) -o $(PSP_TARGET_FIXUP) 74 | 75 | $(PSP_TARGET_STRIP) : $(PSP_TARGET_FIXUP) 76 | $(STRIP) $(PSP_TARGET_FIXUP) -o $(PSP_TARGET_STRIP) 77 | 78 | include Makefile.onscripter 79 | 80 | # overriding 81 | clean : 82 | $(RM) $(TARGET) 83 | $(RM) $(PSP_TARGET) $(PSP_TARGET_FIXUP) $(PSP_TARGET_STRIP) $(PSP_EBOOT_SFO) 84 | $(RM) *.o 85 | -------------------------------------------------------------------------------- /Makefile.Pandora: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.Pandora - Makefile rules for Pandora 4 | # 5 | 6 | PNDSDK = $(HOME)/pandora-dev/arm-2011.09 7 | 8 | EXESUFFIX = 9 | OBJSUFFIX = .o 10 | 11 | .SUFFIXES: 12 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 13 | 14 | TARGET = onscripter$(EXESUFFIX) 15 | EXT_OBJS = 16 | 17 | # mandatory: SDL, SDL_ttf, SDL_image, SDL_mixer, bzip2, libjpeg 18 | DEFS = -DPANDORA -DLINUX -DBPP16 19 | INCS = -I$(PNDSDK)/usr/include -I$(PNDSDK)/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT 20 | LIBS = -L$(PNDSDK)/usr/lib -Wl,-rpath-link,$(PNDSDK)/usr/lib -lSDL -lpthread -lSDL_ttf -lSDL_image -lSDL_mixer -lbz2 -ljpeg -lm 21 | 22 | # recommended: smpeg 23 | DEFS += -DUSE_SMPEG 24 | INCS += -I$(PNDSDK)/usr/include/smpeg 25 | LIBS += -lsmpeg 26 | 27 | # recommended: fontconfig (to get default font) 28 | DEFS += -DUSE_FONTCONFIG 29 | LIBS += -lfontconfig 30 | 31 | # recommended: OggVorbis 32 | #DEFS += -DUSE_OGG_VORBIS 33 | #LIBS += -logg -lvorbis -lvorbisfile 34 | 35 | # optional: Integer OggVorbis 36 | DEFS += -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS 37 | LIBS += -lvorbisidec 38 | 39 | # optional: support CD audio 40 | DEFS += -DUSE_CDROM 41 | 42 | # optional: avifile 43 | #DEFS += -DUSE_AVIFILE 44 | #INCS += `avifile-config --cflags` 45 | #LIBS += `avifile-config --libs` 46 | #TARGET += simple_aviplay$(EXESUFFIX) 47 | #EXT_OBJS += AVIWrapper$(OBJSUFFIX) 48 | 49 | # optional: lua 50 | DEFS += -DUSE_LUA 51 | INCS += -I$(PNDSDK)/usr/include 52 | LIBS += -llua -ldl 53 | EXT_OBJS += LUAHandler$(OBJSUFFIX) 54 | 55 | # optional: force screen width for PDA 56 | #DEFS += -DPDA_WIDTH=640 57 | DEFS += -DPDA_AUTOSIZE 58 | 59 | # optional: enable English mode 60 | #DEFS += -DENABLE_1BYTE_CHAR -DFORCE_1BYTE_CHAR 61 | 62 | 63 | # for GNU g++ 64 | CC = $(PNDSDK)/bin/arm-none-linux-gnueabi-g++ 65 | LD = $(PNDSDK)/bin/arm-none-linux-gnueabi-g++ -o 66 | 67 | MFLAGS = -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -fassociative-math -funsafe-math-optimizations 68 | #CFLAGS = -g -Wall $(MFLAGS) -pipe -c $(INCS) $(DEFS) 69 | CFLAGS = -Os -Wall -fomit-frame-pointer $(MFLAGS) -pipe -c $(INCS) $(DEFS) 70 | 71 | # for GCC on PowerPC specfied 72 | #CC = powerpc-unknown-linux-gnu-g++ 73 | #LD = powerpc-unknown-linux-gnu-g++ -o 74 | 75 | #CFLAGS = -O3 -mtune=G4 -maltivec -mabi=altivec -mpowerpc-gfxopt -mmultiple -mstring -Wall -fomit-frame-pointer -pipe -c $(INCS) $(DEFS) 76 | 77 | # for Intel compiler 78 | #CC = icc 79 | #LD = icc -o 80 | 81 | #CFLAGS = -O3 -tpp6 -xK -c $(INCS) $(DEFS) 82 | 83 | RM = rm -f 84 | 85 | include Makefile.onscripter 86 | -------------------------------------------------------------------------------- /Makefile.Win: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.Win - Makefile rules for windows 4 | # 5 | 6 | INCS = /I"c:\usr\include" /I"c:\usr\include\sdl" /I"c:\usr\include\smpeg" 7 | 8 | # to SDL 1.2.9 9 | #LIBS = /libpath:"c:\usr\lib" SDL.lib SDLmain.lib smpeg.lib SDL_ttf.lib SDL_image.lib SDL_mixer.lib libbz2.lib libjpeg.lib vorbisfile.lib 10 | #DEFS = /D "WIN32" /D "USE_CDROM" /D "USE_OGG_VORBIS" 11 | 12 | # from SDL 1.2.10 13 | LIBS = /libpath:"c:\usr\lib" SDL.lib SDLmain.lib smpeg.lib SDL_ttf.lib SDL_image.lib SDL_mixer.lib libbz2.lib libjpeg.lib vorbisfile.lib iconv.lib 14 | DEFS = /D "WIN32" /D "USE_CDROM" /D "USE_OGG_VORBIS" /D "UTF8_CAPTION" /D "USE_SMPEG" 15 | 16 | EXESUFFIX = .exe 17 | OBJSUFFIX = .obj 18 | 19 | .SUFFIXES: 20 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 21 | 22 | CC = cl 23 | LD = link /nologo /subsystem:console /incremental:no /machine:I386 /nodefaultlib:libc /nodefaultlib:msvcrt 24 | LDOUT = /out: 25 | 26 | CFLAGS = /nologo /MT /W3 /EHsc /c /O2 $(INCS) $(DEFS) 27 | RM = del 28 | 29 | TARGET = onscripter$(EXESUFFIX) sarconv$(EXESUFFIX) nsaconv$(EXESUFFIX) 30 | 31 | !include Makefile.onscripter 32 | -------------------------------------------------------------------------------- /Makefile.WinCE: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.WinCE - Makefile rules for WindowsCE 4 | # 5 | 6 | PREF = /usr/local/mingw32ce/arm-wince-mingw32ce 7 | 8 | INCS = `$(PREF)/bin/sdl-config --cflags` `$(PREF)/bin/freetype-config --cflags` 9 | 10 | LIBS = -static `$(PREF)/bin/sdl-config --libs` -lSDL_ttf -lSDL_image -lSDL_mixer -lSDL -lfreetype -ljpeg -lpng -lz -lbz2 11 | 12 | # QVGA (320x240) 13 | #DEFS = -DWINCE -DWIN32 -DPDA_WIDTH=320 -DBPP16 14 | 15 | # VGA (640x480) 16 | DEFS = -DWINCE -DWIN32 -DPDA_WIDTH=640 -DBPP16 17 | 18 | EXESUFFIX = .exe 19 | OBJSUFFIX = .o 20 | 21 | .SUFFIXES: 22 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 23 | 24 | CC = arm-wince-mingw32ce-g++ -finput-charset=cp932 -fexec-charset=cp932 25 | LD = arm-wince-mingw32ce-g++ -finput-charset=cp932 -fexec-charset=cp932 -o 26 | 27 | CFLAGS = -O3 -Wall -fno-exceptions -fno-rtti -fno-check-new -fomit-frame-pointer -pipe -c $(INCS) $(DEFS) 28 | RM = rm -f 29 | 30 | TARGET = onscripter$(EXESUFFIX) 31 | EXT_OBJS = 32 | 33 | include Makefile.onscripter 34 | -------------------------------------------------------------------------------- /Makefile.iPhone: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.iPhone - Makefile rules for iPhone & iPod touch 4 | # 5 | 6 | PREF = /usr/local/arm-apple-darwin 7 | 8 | INCS = `$(PREF)/bin/sdl-config --cflags` `$(PREF)/bin/freetype-config --cflags` 9 | #LIBS = `$(PREF)/bin/sdl-config --libs` -lSDL_ttf -lSDL_image -lSDL_mixer -lSDL -lvorbisidec -lfreetype -ljpeg -lpng -lbz2 -lz 10 | LIBS = `$(PREF)/bin/sdl-config --libs` \ 11 | $(PREF)/lib/libSDL_ttf.a \ 12 | $(PREF)/lib/libSDL_image.a \ 13 | $(PREF)/lib/libSDL_mixer.a \ 14 | $(PREF)/lib/libSDL.a \ 15 | $(PREF)/lib/libvorbisidec.a \ 16 | $(PREF)/lib/libfreetype.a \ 17 | $(PREF)/lib/libjpeg.a \ 18 | $(PREF)/lib/libpng.a \ 19 | -lz -lbz2 20 | 21 | DEFS = -DIPHONE -DMACOSX -DPDA_WIDTH=424 -DBPP16 -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS -DUTF8_CAPTION -DUTF8_FILESYSTEM 22 | 23 | EXESUFFIX = 24 | OBJSUFFIX = .o 25 | 26 | .SUFFIXES: 27 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 28 | 29 | CC = arm-apple-darwin-g++ 30 | LD = arm-apple-darwin-g++ -o 31 | 32 | #CFLAGS = -g -Wall -Wpointer-arith -pipe -c $(INCS) $(DEFS) 33 | CFLAGS = -O3 -Wall -Wpointer-arith -pipe -c $(INCS) $(DEFS) 34 | RM = rm -f 35 | 36 | TARGET = onscripter$(EXESUFFIX) sardec$(EXESUFFIX) nsadec$(EXESUFFIX) sarconv$(EXESUFFIX) nsaconv$(EXESUFFIX) 37 | EXT_OBJS = 38 | 39 | include Makefile.onscripter 40 | -------------------------------------------------------------------------------- /Makefile.iPodLinux: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.iPodLinux - Makefile rules for uCLinux on iPod (photo/nano/video) 4 | # Thanks Shiikuru-san 5 | # 6 | # Playing movie and audio is not supported. 7 | # 8 | 9 | PREF = /usr/local/arm-uclinux-tools/arm-uclinux-elf 10 | 11 | INCS = `$(PREF)/bin/sdl-config --cflags` `$(PREF)/bin/freetype-config --cflags` 12 | 13 | LIBS = `$(PREF)/bin/sdl-config --libs` -lSDL_ttf -lSDL_image -lSDL_mixer -lSDL -lfreetype -ljpeg -lbz2 14 | 15 | # for iPod 5G (video) : 320x240 16 | #DEFS = -DIPODLINUX -DLINUX -DPDA_WIDTH=320 -DBPP16 17 | # for iPod photo : 220x176 -> 220x165 18 | #DEFS = -DIPODLINUX -DLINUX -DPDA_WIDTH=220 -DBPP16 19 | # for iPod nano : 176x132 20 | #DEFS = -DIPODLINUX -DLINUX -DPDA_WIDTH=176 -DBPP16 21 | 22 | # for iPod (nano, photo, 4G color, 5G) : Auto 23 | DEFS = -DIPODLINUX -DLINUX -DPDA_AUTOSIZE -DBPP16 24 | 25 | EXESUFFIX = 26 | OBJSUFFIX = .o 27 | 28 | .SUFFIXES: 29 | .SUFFIXES: $(OBJSUFFIX) .cpp .h 30 | 31 | CC = arm-uclinux-elf-g++ 32 | LD = arm-uclinux-elf-g++ -Wl,-elf2flt -o 33 | 34 | CFLAGS = -O3 -Wall -fno-exceptions -fno-rtti -fno-check-new -fomit-frame-pointer -pipe -c $(INCS) $(DEFS) 35 | RM = rm -f 36 | 37 | TARGET = onscripter$(EXESUFFIX) nsaconv$(EXESUFFIX) sarconv$(EXESUFFIX) nsadec$(EXESUFFIX) sardec$(EXESUFFIX) 38 | EXT_OBJS = 39 | 40 | include Makefile.onscripter 41 | -------------------------------------------------------------------------------- /Makefile.onscripter: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | # 3 | # Makefile.onscripter - General makefile rules for ONScripter 4 | # 5 | 6 | GUI_OBJS = ONScripter$(OBJSUFFIX) \ 7 | ONScripter_animation$(OBJSUFFIX) \ 8 | ONScripter_command$(OBJSUFFIX) \ 9 | ONScripter_effect$(OBJSUFFIX) \ 10 | ONScripter_effect_breakup$(OBJSUFFIX) \ 11 | ONScripter_event$(OBJSUFFIX) \ 12 | ONScripter_file$(OBJSUFFIX) \ 13 | ONScripter_file2$(OBJSUFFIX) \ 14 | ONScripter_image$(OBJSUFFIX) \ 15 | ONScripter_lut$(OBJSUFFIX) \ 16 | ONScripter_rmenu$(OBJSUFFIX) \ 17 | ONScripter_sound$(OBJSUFFIX) \ 18 | ONScripter_text$(OBJSUFFIX) \ 19 | AnimationInfo$(OBJSUFFIX) \ 20 | FontInfo$(OBJSUFFIX) \ 21 | DirtyRect$(OBJSUFFIX) \ 22 | resize_image$(OBJSUFFIX) 23 | 24 | DECODER_OBJS = DirectReader$(OBJSUFFIX) \ 25 | SarReader$(OBJSUFFIX) \ 26 | NsaReader$(OBJSUFFIX) \ 27 | sjis2utf16$(OBJSUFFIX) 28 | 29 | SARDEC_OBJS = sardec$(OBJSUFFIX) \ 30 | DirectReader$(OBJSUFFIX) \ 31 | SarReader$(OBJSUFFIX) \ 32 | sjis2utf16$(OBJSUFFIX) 33 | 34 | SARCONV_OBJS = sarconv$(OBJSUFFIX) \ 35 | conv_shared$(OBJSUFFIX) \ 36 | resize_image$(OBJSUFFIX) \ 37 | DirectReader$(OBJSUFFIX) \ 38 | SarReader$(OBJSUFFIX) \ 39 | sjis2utf16$(OBJSUFFIX) 40 | 41 | NSADEC_OBJS = nsadec$(OBJSUFFIX) \ 42 | $(DECODER_OBJS) 43 | 44 | NSACONV_OBJS = nsaconv$(OBJSUFFIX) \ 45 | conv_shared$(OBJSUFFIX) \ 46 | resize_image$(OBJSUFFIX) \ 47 | $(DECODER_OBJS) 48 | 49 | ONSCRIPTER_OBJS = onscripter_main$(OBJSUFFIX) \ 50 | $(DECODER_OBJS) \ 51 | ScriptHandler$(OBJSUFFIX) \ 52 | ScriptParser$(OBJSUFFIX) \ 53 | ScriptParser_command$(OBJSUFFIX) \ 54 | $(GUI_OBJS) $(EXT_OBJS) 55 | 56 | PARSER_HEADER = BaseReader.h \ 57 | ButtonLink.h \ 58 | DirectReader.h \ 59 | SarReader.h \ 60 | NsaReader.h \ 61 | ScriptHandler.h \ 62 | ScriptParser.h \ 63 | AnimationInfo.h \ 64 | FontInfo.h \ 65 | DirtyRect.h \ 66 | LUAHandler.h 67 | 68 | ONSCRIPTER_HEADER = ONScripter.h $(PARSER_HEADER) 69 | 70 | ALL: $(TARGET) 71 | 72 | sardec$(EXESUFFIX): $(SARDEC_OBJS) 73 | $(LD) $(LDOUT)$@ $(SARDEC_OBJS) $(LIBS) 74 | 75 | sarconv$(EXESUFFIX): $(SARCONV_OBJS) 76 | $(LD) $(LDOUT)$@ $(SARCONV_OBJS) $(LIBS) 77 | 78 | nsadec$(EXESUFFIX): $(NSADEC_OBJS) 79 | $(LD) $(LDOUT)$@ $(NSADEC_OBJS) $(LIBS) 80 | 81 | nsaconv$(EXESUFFIX): $(NSACONV_OBJS) 82 | $(LD) $(LDOUT)$@ $(NSACONV_OBJS) $(LIBS) 83 | 84 | simple_aviplay$(EXESUFFIX): simple_aviplay$(OBJSUFFIX) AVIWrapper$(OBJSUFFIX) 85 | $(LD) $(LDOUT)$@ simple_aviplay$(OBJSUFFIX) AVIWrapper$(OBJSUFFIX) $(LIBS) 86 | 87 | onscripter$(EXESUFFIX): $(ONSCRIPTER_OBJS) 88 | $(LD) $(LDOUT)$@ $(ONSCRIPTER_OBJS) $(LIBS) 89 | 90 | clean: 91 | -$(RM) $(TARGET) 92 | -$(RM) *$(OBJSUFFIX) 93 | 94 | .cpp$(OBJSUFFIX): 95 | $(CC) $(CFLAGS) $< 96 | 97 | SarReader$(OBJSUFFIX): BaseReader.h SarReader.h 98 | NsaReader$(OBJSUFFIX): BaseReader.h SarReader.h NsaReader.h 99 | DirectReader$(OBJSUFFIX): BaseReader.h DirectReader.h 100 | ScriptHandler$(OBJSUFFIX): ScriptHandler.h 101 | ScriptParser$(OBJSUFFIX): $(PARSER_HEADER) 102 | ScriptParser_command$(OBJSUFFIX): $(PARSER_HEADER) 103 | 104 | sardec$(OBJSUFFIX): BaseReader.h SarReader.h 105 | sarconv$(OBJSUFFIX): BaseReader.h SarReader.h 106 | nsadec$(OBJSUFFIX): BaseReader.h SarReader.h NsaReader.h 107 | nsaconv$(OBJSUFFIX): BaseReader.h SarReader.h NsaReader.h 108 | simple_aviplay$(OBJSUFFIX): AVIWrapper.h 109 | conv_shared$(OBJSUFFIX): resize_image.h 110 | 111 | onscripter_main$(OBJSUFFIX): $(ONSCRIPTER_HEADER) version.h 112 | ONScripter$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 113 | ONScripter_command$(OBJSUFFIX): $(ONSCRIPTER_HEADER) version.h 114 | ONScripter_text$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 115 | ONScripter_effect$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 116 | ONScripter_effect_breakup$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 117 | ONScripter_event$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 118 | ONScripter_rmenu$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 119 | ONScripter_animation$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 120 | ONScripter_sound$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 121 | ONScripter_file$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 122 | ONScripter_file2$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 123 | ONScripter_image$(OBJSUFFIX): $(ONSCRIPTER_HEADER) resize_image.h 124 | ONScripter_lut$(OBJSUFFIX): $(ONSCRIPTER_HEADER) 125 | AnimationInfo$(OBJSUFFIX): AnimationInfo.h 126 | FontInfo$(OBJSUFFIX): FontInfo.h 127 | DirtyRect$(OBJSUFFIX) : DirtyRect.h 128 | AVIWrapper$(OBJSUFFIX): AVIWrapper.h 129 | LUAHandler$(OBJSUFFIX): $(ONSCRIPTER_HEADER) LUAHandler.h 130 | -------------------------------------------------------------------------------- /NsaReader.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * NsaReader.cpp - Reader from a NSA archive 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include "NsaReader.h" 25 | #include 26 | #define NSA_ARCHIVE_NAME "arc" 27 | #define NSA_ARCHIVE_NAME2 "arc%d" 28 | 29 | NsaReader::NsaReader( unsigned int nsa_offset, char *path, int archive_type, const unsigned char *key_table ) 30 | :SarReader( path, key_table ) 31 | { 32 | sar_flag = true; 33 | this->nsa_offset = nsa_offset; 34 | this->archive_type = archive_type; 35 | num_of_nsa_archives = 0; 36 | num_of_ns2_archives = 0; 37 | 38 | if (key_table) 39 | nsa_archive_ext = "___"; 40 | else 41 | nsa_archive_ext = "nsa"; 42 | 43 | ns2_archive_ext = "ns2"; 44 | } 45 | 46 | NsaReader::~NsaReader() 47 | { 48 | } 49 | 50 | int NsaReader::open( const char *nsa_path ) 51 | { 52 | int i; 53 | bool archive_found = false; 54 | char archive_name[256], archive_name2[256]; 55 | 56 | if ( !SarReader::open( "arc.sar" ) ) return 0; 57 | 58 | sar_flag = false; 59 | 60 | if (archive_type & ARCHIVE_TYPE_NS2){ 61 | for ( i=0 ; ifile_handle = fopen( archive_name, "rb" ) ) == NULL ) break; 88 | 89 | archive_found = true; 90 | ai->file_name = new char[strlen(archive_name)+1]; 91 | memcpy(ai->file_name, archive_name, strlen(archive_name)+1); 92 | readArchive( ai, ARCHIVE_TYPE_NSA, nsa_offset ); 93 | num_of_nsa_archives = i+1; 94 | } 95 | } 96 | 97 | if (!archive_found) return -1; 98 | 99 | return 0; 100 | } 101 | 102 | int NsaReader::openForConvert( char *nsa_name, int archive_type, unsigned int nsa_offset ) 103 | { 104 | sar_flag = false; 105 | if ( ( archive_info.file_handle = ::fopen( nsa_name, "rb" ) ) == NULL ){ 106 | fprintf( stderr, "can't open file %s\n", nsa_name ); 107 | return -1; 108 | } 109 | 110 | readArchive( &archive_info, archive_type, nsa_offset ); 111 | 112 | return 0; 113 | } 114 | 115 | int NsaReader::writeHeader( FILE *fp, int archive_type, int nsa_offset ) 116 | { 117 | ArchiveInfo *ai = &archive_info; 118 | return writeHeaderSub( ai, fp, archive_type, nsa_offset ); 119 | } 120 | 121 | size_t NsaReader::putFile( FILE *fp, int no, size_t offset, size_t length, size_t original_length, int compression_type, bool modified_flag, unsigned char *buffer ) 122 | { 123 | ArchiveInfo *ai = &archive_info; 124 | return putFileSub( ai, fp, no, offset, length, original_length , compression_type, modified_flag, buffer ); 125 | } 126 | 127 | const char *NsaReader::getArchiveName() const 128 | { 129 | return "nsa"; 130 | } 131 | 132 | int NsaReader::getNumFiles(){ 133 | int total = archive_info.num_of_files, i; 134 | 135 | for ( i=0 ; inum_of_files ) return 0; 146 | 147 | if ( ai->fi_list[i].original_length != 0 ) 148 | return ai->fi_list[i].original_length; 149 | 150 | int type = ai->fi_list[i].compression_type; 151 | if ( type == NO_COMPRESSION ) 152 | type = getRegisteredCompressionType( file_name ); 153 | if ( type == NBZ_COMPRESSION || type == SPB_COMPRESSION ) { 154 | ai->fi_list[i].original_length = getDecompressedFileLength( type, ai->file_handle, ai->fi_list[i].offset ); 155 | } 156 | 157 | return ai->fi_list[i].original_length; 158 | } 159 | 160 | size_t NsaReader::getFileLength( const char *file_name ) 161 | { 162 | if ( sar_flag ) return SarReader::getFileLength( file_name ); 163 | 164 | size_t ret; 165 | int i; 166 | 167 | if ( ( ret = DirectReader::getFileLength( file_name ) ) ) return ret; 168 | 169 | for ( i=0 ; ipixels; 84 | ONSBuf *buffer2 = (ONSBuf *)effect_dst_surface->pixels; 85 | SDL_PixelFormat *fmt = effect_dst_surface->format; 86 | int surf_w = effect_src_surface->w; 87 | int surf_h = effect_src_surface->h; 88 | int x1=w, y1=-1, x2=0, y2=0; 89 | for (int i=0; i= surf_w) || (i >= surf_h)) { 92 | breakup_mask[i*w+j] = false; 93 | continue; 94 | } 95 | ONSBuf pix1 = buffer1[i*surf_w+j]; 96 | ONSBuf pix2 = buffer2[i*surf_w+j]; 97 | int pix1c = ((pix1 & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss; 98 | int pix2c = ((pix2 & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss; 99 | breakup_mask[i*w+j] = true; 100 | if (abs(pix1c - pix2c) > 8) { 101 | if (y1 < 0) y1 = i; 102 | if (j < x1) x1 = j; 103 | if (j > x2) x2 = j; 104 | y2 = i; 105 | continue; 106 | } 107 | pix1c = ((pix1 & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss; 108 | pix2c = ((pix2 & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss; 109 | if (abs(pix1c - pix2c) > 8) { 110 | if (y1 < 0) y1 = i; 111 | if (j < x1) x1 = j; 112 | if (j > x2) x2 = j; 113 | y2 = i; 114 | continue; 115 | } 116 | pix1c = ((pix1 & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss; 117 | pix2c = ((pix2 & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss; 118 | if (abs(pix1c - pix2c) > 8) { 119 | if (y1 < 0) y1 = i; 120 | if (j < x1) x1 = j; 121 | if (j > x2) x2 = j; 122 | y2 = i; 123 | continue; 124 | } 125 | pix1c = ((pix1 & fmt->Amask) >> fmt->Ashift) << fmt->Aloss; 126 | pix2c = ((pix2 & fmt->Amask) >> fmt->Ashift) << fmt->Aloss; 127 | if (abs(pix1c - pix2c) > 8) { 128 | if (y1 < 0) y1 = i; 129 | if (j < x1) x1 = j; 130 | if (j > x2) x2 = j; 131 | y2 = i; 132 | continue; 133 | } 134 | breakup_mask[i*w+j] = false; 135 | } 136 | } 137 | if (breakup_mode & BREAKUP_MODE_LEFT) 138 | x1 = 0; 139 | else 140 | x2 = surf_w-1; 141 | if (breakup_mode & BREAKUP_MODE_LOWER) 142 | y2 = surf_h-1; 143 | else 144 | y1 = 0; 145 | breakup_window.x = x1 / BREAKUP_CELLWIDTH; 146 | breakup_window.y = y1 / BREAKUP_CELLWIDTH; 147 | breakup_window.w = x2/BREAKUP_CELLWIDTH - breakup_window.x + 1; 148 | breakup_window.h = y2/BREAKUP_CELLWIDTH - breakup_window.y + 1; 149 | 150 | SDL_UnlockSurface( effect_dst_surface ); 151 | SDL_UnlockSurface( effect_src_surface ); 152 | } 153 | 154 | void ONScripter::initBreakup( char *params ) 155 | { 156 | while (*params != 0 && *params != '/') params++; 157 | if (*params == '/') params++; 158 | 159 | buildBreakupCellforms(); 160 | 161 | breakup_mode = 0; 162 | if (params[0] == 'l') 163 | breakup_mode |= BREAKUP_MODE_LOWER; 164 | if (params[1] == 'l') 165 | breakup_mode |= BREAKUP_MODE_LEFT; 166 | if ((params[2] >= 'A') && (params[2] <= 'Z')) 167 | breakup_mode |= BREAKUP_MODE_JUMBLE; 168 | if ((params[2] == 'p') || (params[2] == 'P')) 169 | breakup_mode |= BREAKUP_MODE_PILEUP; 170 | 171 | if (!breakup_cells) 172 | breakup_cells = new BreakupCell[BREAKUP_MAX_CELLS]; 173 | buildBreakupMask(); 174 | int n_cell_x = breakup_window.w; 175 | int n_cell_y = breakup_window.h; 176 | int n_cell_diags = n_cell_x + n_cell_y; 177 | n_cells = n_cell_x * n_cell_y; 178 | tot_frames = BREAKUP_MOVE_FRAMES + n_cell_diags + BREAKUP_CELLFORMS - BREAKUP_CELLWIDTH/2 + 1; 179 | last_frame = 0; 180 | 181 | int n = 0, dir = 1, i = 0, diag_n = 0; 182 | for (i=0; i=0) && (k=0); j--, k++) { 206 | breakup_cells[n].cell_x = j + breakup_window.x; 207 | breakup_cells[n].cell_y = k + breakup_window.y; 208 | if (!(breakup_mode & BREAKUP_MODE_LEFT)) 209 | breakup_cells[n].cell_x = breakup_window.x + n_cell_x - j - 1; 210 | if (breakup_mode & BREAKUP_MODE_LOWER) 211 | breakup_cells[n].cell_y = breakup_window.y + n_cell_y - k - 1; 212 | breakup_cells[n].dir = dir; 213 | breakup_cells[n].state = state; 214 | breakup_cells[n].radius = 0; 215 | ++dir &= (BREAKUP_DIRECTIONS-1); 216 | ++n; 217 | } 218 | ++diag_n; 219 | } 220 | } 221 | 222 | void ONScripter::effectBreakup( char *params, int duration ) 223 | { 224 | while (*params != 0 && *params != '/') params++; 225 | if (*params == '/') params++; 226 | 227 | int x_dir = -1; 228 | int y_dir = -1; 229 | 230 | int frame = tot_frames * effect_counter / duration; 231 | int frame_diff = frame - last_frame; 232 | if (frame_diff == 0) 233 | return; 234 | 235 | SDL_Surface *bg = effect_dst_surface; 236 | SDL_Surface *chr = effect_src_surface; 237 | last_frame += frame_diff; 238 | frame_diff = -frame_diff; 239 | if (breakup_mode & BREAKUP_MODE_PILEUP) { 240 | bg = effect_src_surface; 241 | chr = effect_dst_surface; 242 | frame_diff = -frame_diff; 243 | x_dir = -x_dir; 244 | y_dir = -y_dir; 245 | } 246 | SDL_BlitSurface(bg, NULL, accumulation_surface, NULL); 247 | SDL_Surface *dst = accumulation_surface; 248 | 249 | if (breakup_mode & BREAKUP_MODE_JUMBLE) { 250 | x_dir = -x_dir; 251 | y_dir = -y_dir; 252 | } 253 | if (!(breakup_mode & BREAKUP_MODE_LEFT)) { 254 | x_dir = -x_dir; 255 | } 256 | if (breakup_mode & BREAKUP_MODE_LOWER) { 257 | y_dir = -y_dir; 258 | } 259 | 260 | SDL_LockSurface( chr ); 261 | SDL_LockSurface( dst ); 262 | ONSBuf *chr_buf = (ONSBuf *)chr->pixels; 263 | ONSBuf *buffer = (ONSBuf *)dst->pixels; 264 | bool *msk_buf = breakup_cellforms; 265 | 266 | for (int n=0; n= (BREAKUP_MOVE_FRAMES + BREAKUP_STILL_STATE)) { 274 | for (int i=0; i= dst->w) || (x >= chr->w) || 279 | (y < 0) || (y >= dst->h) || (y >= chr->h)) 280 | continue; 281 | if ( breakup_mask[y*BREAKUP_CELLWIDTH*BREAKUP_MAX_CELL_X + x] ) 282 | buffer[y*dst->w + x] = chr_buf[y*chr->w + x]; 283 | } 284 | } 285 | } 286 | else if (breakup_cells[n].state >= BREAKUP_MOVE_FRAMES) { 287 | breakup_cells[n].radius = breakup_cells[n].state - (BREAKUP_MOVE_FRAMES*3/4) + 1; 288 | for (int i=0; i= dst->w) || (x >= chr->w) || 293 | (y < 0) || (y >= dst->h) || (y >= chr->h)) 294 | continue; 295 | int msk_off = BREAKUP_CELLWIDTH*breakup_cells[n].radius; 296 | if ( msk_buf[BREAKUP_CELLWIDTH * BREAKUP_CELLFORMS * i + msk_off + j] && 297 | breakup_mask[y*BREAKUP_CELLWIDTH*BREAKUP_MAX_CELL_X + x] ) 298 | buffer[y*dst->w + x] = chr_buf[y*chr->w + x]; 299 | } 300 | } 301 | } 302 | else if (breakup_cells[n].state >= 0) { 303 | int state = breakup_cells[n].state; 304 | int disp_x = x_dir * breakup_disp_x[breakup_cells[n].dir] * (state-BREAKUP_MOVE_FRAMES); 305 | int disp_y = y_dir * breakup_disp_y[breakup_cells[n].dir] * (BREAKUP_MOVE_FRAMES-state); 306 | 307 | breakup_cells[n].radius = 0; 308 | if (breakup_cells[n].state >= (BREAKUP_MOVE_FRAMES/2)) 309 | breakup_cells[n].radius = (breakup_cells[n].state/2) - (BREAKUP_MOVE_FRAMES/4) + 1; 310 | for (int i=0; i= dst->w) || 315 | (y < 0) || (y >= dst->h)) 316 | continue; 317 | if (((rect.x+j)<0) || ((rect.x+j) >= chr->w) || 318 | ((rect.y+i)<0) || ((rect.y+i) >= chr->h)) 319 | continue; 320 | int msk_off = BREAKUP_CELLWIDTH*breakup_cells[n].radius; 321 | if ( msk_buf[BREAKUP_CELLWIDTH * BREAKUP_CELLFORMS * i + msk_off + j] && 322 | breakup_mask[(rect.y+i)*BREAKUP_CELLWIDTH*BREAKUP_MAX_CELL_X + rect.x + j] ) 323 | buffer[y*dst->w + x] = 324 | chr_buf[(rect.y+i)*chr->w + rect.x + j]; 325 | } 326 | } 327 | } 328 | } 329 | 330 | SDL_UnlockSurface( accumulation_surface ); 331 | SDL_UnlockSurface( chr ); 332 | } 333 | -------------------------------------------------------------------------------- /ONScripter_file.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * ONScripter_file.cpp - FILE I/O of ONScripter 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * (C) 2014 jh10001 7 | * 8 | * ogapee@aqua.dti2.ne.jp 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | */ 24 | 25 | #include "ONScripter.h" 26 | 27 | #if defined(LINUX) || defined(MACOSX) || defined(IOS) 28 | #include 29 | #include 30 | #include 31 | #include 32 | #elif defined(_WIN32) 33 | #include 34 | #elif defined(MACOS9) 35 | #include 36 | #include 37 | extern "C" void c2pstrcpy(Str255 dst, const char *src); //#include 38 | #elif defined(PSP) 39 | #include 40 | #endif 41 | 42 | #define SAVEFILE_MAGIC_NUMBER "ONS" 43 | #define SAVEFILE_VERSION_MAJOR 2 44 | #define SAVEFILE_VERSION_MINOR 8 45 | 46 | #define READ_LENGTH 4096 47 | 48 | void ONScripter::searchSaveFile( SaveFileInfo &save_file_info, int no ) 49 | { 50 | char file_name[256]; 51 | 52 | script_h.getStringFromInteger( save_file_info.sjis_no, no, (num_save_file >= 10)?2:1 ); 53 | #if defined(LINUX) || defined(MACOSX) || defined(IOS) 54 | sprintf( file_name, "%ssave%d.dat", save_dir?save_dir:archive_path, no ); 55 | struct stat buf; 56 | struct tm *tm; 57 | if ( stat( file_name, &buf ) != 0 ){ 58 | save_file_info.valid = false; 59 | return; 60 | } 61 | time_t mtime = buf.st_mtime; 62 | tm = localtime( &mtime ); 63 | 64 | save_file_info.month = tm->tm_mon + 1; 65 | save_file_info.day = tm->tm_mday; 66 | save_file_info.hour = tm->tm_hour; 67 | save_file_info.minute = tm->tm_min; 68 | #elif defined(WIN32) 69 | sprintf( file_name, "%ssave%d.dat", save_dir?save_dir:archive_path, no ); 70 | HANDLE handle; 71 | FILETIME tm, ltm; 72 | SYSTEMTIME stm; 73 | 74 | #if defined(WINCE) 75 | WCHAR file_nameW[256]; 76 | MultiByteToWideChar(CP_ACP, 0, file_name, -1, file_nameW, 256); 77 | handle = CreateFile( file_nameW, GENERIC_READ, 0, NULL, 78 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); 79 | #else 80 | handle = CreateFile( file_name, GENERIC_READ, 0, NULL, 81 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); 82 | #endif 83 | if ( handle == INVALID_HANDLE_VALUE ){ 84 | save_file_info.valid = false; 85 | return; 86 | } 87 | 88 | GetFileTime( handle, NULL, NULL, &tm ); 89 | FileTimeToLocalFileTime( &tm, <m ); 90 | FileTimeToSystemTime( <m, &stm ); 91 | CloseHandle( handle ); 92 | 93 | save_file_info.month = stm.wMonth; 94 | save_file_info.day = stm.wDay; 95 | save_file_info.hour = stm.wHour; 96 | save_file_info.minute = stm.wMinute; 97 | #elif defined(MACOS9) 98 | sprintf( file_name, "%ssave%d.dat", save_dir?save_dir:archive_path, no ); 99 | CInfoPBRec pb; 100 | Str255 p_file_name; 101 | FSSpec file_spec; 102 | DateTimeRec tm; 103 | c2pstrcpy( p_file_name, file_name ); 104 | if ( FSMakeFSSpec(0, 0, p_file_name, &file_spec) != noErr ){ 105 | save_file_info.valid = false; 106 | return; 107 | } 108 | pb.hFileInfo.ioNamePtr = file_spec.name; 109 | pb.hFileInfo.ioVRefNum = file_spec.vRefNum; 110 | pb.hFileInfo.ioFDirIndex = 0; 111 | pb.hFileInfo.ioDirID = file_spec.parID; 112 | if (PBGetCatInfoSync(&pb) != noErr) { 113 | save_file_info.valid = false; 114 | return; 115 | } 116 | SecondsToDate( pb.hFileInfo.ioFlMdDat, &tm ); 117 | save_file_info.month = tm.month; 118 | save_file_info.day = tm.day; 119 | save_file_info.hour = tm.hour; 120 | save_file_info.minute = tm.minute; 121 | #elif defined(PSP) 122 | sprintf( file_name, "%ssave%d.dat", save_dir?save_dir:archive_path, no ); 123 | SceIoStat buf; 124 | if ( sceIoGetstat(file_name, &buf)<0 ){ 125 | save_file_info.valid = false; 126 | return; 127 | } 128 | 129 | save_file_info.month = buf.st_mtime.month; 130 | save_file_info.day = buf.st_mtime.day; 131 | save_file_info.hour = buf.st_mtime.hour; 132 | save_file_info.minute = buf.st_mtime.minute; 133 | #else 134 | sprintf( file_name, "save%d.dat", no ); 135 | FILE *fp; 136 | if ( (fp = fopen( file_name, "rb", true )) == NULL ){ 137 | save_file_info.valid = false; 138 | return; 139 | } 140 | fclose( fp ); 141 | 142 | save_file_info.month = 1; 143 | save_file_info.day = 1; 144 | save_file_info.hour = 0; 145 | save_file_info.minute = 0; 146 | #endif 147 | save_file_info.valid = true; 148 | script_h.getStringFromInteger( save_file_info.sjis_month, save_file_info.month, 2 ); 149 | script_h.getStringFromInteger( save_file_info.sjis_day, save_file_info.day, 2 ); 150 | script_h.getStringFromInteger( save_file_info.sjis_hour, save_file_info.hour, 2 ); 151 | script_h.getStringFromInteger( save_file_info.sjis_minute, save_file_info.minute, 2, true ); 152 | } 153 | 154 | char *ONScripter::readSaveStrFromFile( int no ) 155 | { 156 | char filename[32]; 157 | sprintf( filename, "save%d.dat", no ); 158 | size_t len = loadFileIOBuf( filename ); 159 | if (len == 0){ 160 | fprintf( stderr, "readSaveStrFromFile: can't open save file %s\n", filename ); 161 | return NULL; 162 | } 163 | 164 | int p = len - 1; 165 | if ( p < 3 || file_io_buf[p] != '*' || file_io_buf[p-1] != '"' ) return NULL; 166 | p -= 2; 167 | 168 | while( file_io_buf[p] != '"' && p>0 ) p--; 169 | if ( file_io_buf[p] != '"' ) return NULL; 170 | 171 | len = len - p - 3; 172 | char *buf = new char[len+1]; 173 | 174 | unsigned int i; 175 | for (i=0 ; i SAVEFILE_VERSION_MAJOR*100 + SAVEFILE_VERSION_MINOR ){ 207 | fprintf( stderr, "Save file is newer than %d.%d, please use the latest ONScripter.\n", SAVEFILE_VERSION_MAJOR, SAVEFILE_VERSION_MINOR ); 208 | return -1; 209 | } 210 | 211 | if ( file_version >= 200 ) 212 | return loadSaveFile2( file_version ); 213 | 214 | fprintf( stderr, "Save file is too old.\n"); 215 | 216 | return -1; 217 | } 218 | 219 | void ONScripter::saveMagicNumber( bool output_flag ) 220 | { 221 | for ( unsigned int i=0 ; i 26 | #if defined(LINUX) 27 | #include 28 | #endif 29 | 30 | #ifdef ANDROID 31 | extern "C" 32 | { 33 | #include 34 | #include 35 | static JavaVM *jniVM = NULL; 36 | static jobject JavaONScripter = NULL; 37 | static jmethodID JavaPlayVideo = NULL; 38 | 39 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) 40 | { 41 | jniVM = vm; 42 | return JNI_VERSION_1_2; 43 | }; 44 | 45 | JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) 46 | { 47 | jniVM = vm; 48 | }; 49 | 50 | #ifndef SDL_JAVA_PACKAGE_PATH 51 | #error You have to define SDL_JAVA_PACKAGE_PATH to your package path with dots replaced with underscores, for example "com_example_SanAngeles" 52 | #endif 53 | #define JAVA_EXPORT_NAME2(name,package) Java_##package##_##name 54 | #define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package) 55 | #define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH) 56 | 57 | JNIEXPORT jint JNICALL JAVA_EXPORT_NAME(ONScripter_nativeInitJavaCallbacks) (JNIEnv * jniEnv, jobject thiz) 58 | { 59 | JavaONScripter = jniEnv->NewGlobalRef(thiz); 60 | jclass JavaONScripterClass = jniEnv->GetObjectClass(JavaONScripter); 61 | JavaPlayVideo = jniEnv->GetMethodID(JavaONScripterClass, "playVideo", "([C)V"); 62 | } 63 | } 64 | 65 | void playVideoAndroid(const char *filename) 66 | { 67 | JNIEnv * jniEnv = NULL; 68 | jniVM->AttachCurrentThread(&jniEnv, NULL); 69 | 70 | if (!jniEnv){ 71 | __android_log_print(ANDROID_LOG_ERROR, "ONS", "ONScripter::playVideoAndroid: Java VM AttachCurrentThread() failed"); 72 | return; 73 | } 74 | 75 | jchar *jc = new jchar[strlen(filename)]; 76 | for (int i=0 ; iNewCharArray(strlen(filename)); 79 | jniEnv->SetCharArrayRegion(jca, 0, strlen(filename), jc); 80 | jniEnv->CallVoidMethod( JavaONScripter, JavaPlayVideo, jca ); 81 | delete[] jc; 82 | } 83 | #endif 84 | 85 | #if defined(IOS) 86 | extern "C" void playVideoIOS(const char *filename, bool click_flag, bool loop_flag); 87 | #endif 88 | 89 | #if defined(USE_AVIFILE) 90 | #include "AVIWrapper.h" 91 | #endif 92 | 93 | #if defined(USE_SMPEG) 94 | #include 95 | extern "C" void mp3callback( void *userdata, Uint8 *stream, int len ) 96 | { 97 | SMPEG_playAudio( (SMPEG*)userdata, stream, len ); 98 | } 99 | #endif 100 | 101 | extern bool ext_music_play_once_flag; 102 | 103 | extern "C"{ 104 | extern void musicFinishCallback(); 105 | extern Uint32 SDLCALL cdaudioCallback( Uint32 interval, void *param ); 106 | } 107 | extern void midiCallback( int sig ); 108 | extern SDL_TimerID timer_cdaudio_id; 109 | 110 | extern SDL_TimerID timer_bgmfade_id; 111 | extern "C" Uint32 SDLCALL bgmfadeCallback( Uint32 interval, void *param ); 112 | 113 | #define TMP_MUSIC_FILE "tmp.mus" 114 | 115 | int ONScripter::playSound(const char *filename, int format, bool loop_flag, int channel) 116 | { 117 | if ( !audio_open_flag ) return SOUND_NONE; 118 | 119 | long length = script_h.cBR->getFileLength( filename ); 120 | if (length == 0) return SOUND_NONE; 121 | 122 | unsigned char *buffer; 123 | 124 | if (format & SOUND_MUSIC && 125 | length == music_buffer_length && 126 | music_buffer ){ 127 | buffer = music_buffer; 128 | } 129 | else{ 130 | buffer = new(std::nothrow) unsigned char[length]; 131 | if (buffer == NULL){ 132 | fprintf( stderr, "failed to load [%s] because file size [%lu] is too large.\n", filename, length); 133 | return SOUND_NONE; 134 | } 135 | script_h.cBR->getFile( filename, buffer ); 136 | } 137 | 138 | if (format & SOUND_MUSIC){ 139 | music_info = Mix_LoadMUS_RW( SDL_RWFromMem( buffer, length ) ); 140 | Mix_VolumeMusic( music_volume ); 141 | Mix_HookMusicFinished( musicFinishCallback ); 142 | if ( Mix_PlayMusic( music_info, (music_play_loop_flag&&music_loopback_offset==0.0)?-1:0 ) == 0 ){ 143 | music_buffer = buffer; 144 | music_buffer_length = length; 145 | return SOUND_MUSIC; 146 | } 147 | } 148 | 149 | if (format & SOUND_CHUNK){ 150 | Mix_Chunk *chunk = Mix_LoadWAV_RW(SDL_RWFromMem(buffer, length), 1); 151 | if (playWave(chunk, format, loop_flag, channel) == 0){ 152 | delete[] buffer; 153 | return SOUND_CHUNK; 154 | } 155 | } 156 | 157 | /* check WMA */ 158 | if ( buffer[0] == 0x30 && buffer[1] == 0x26 && 159 | buffer[2] == 0xb2 && buffer[3] == 0x75 ){ 160 | delete[] buffer; 161 | return SOUND_OTHER; 162 | } 163 | 164 | if (format & SOUND_MIDI){ 165 | FILE *fp; 166 | if ( (fp = fopen(TMP_MUSIC_FILE, "wb", true)) == NULL){ 167 | fprintf(stderr, "can't open temporaly MIDI file %s\n", TMP_MUSIC_FILE); 168 | } 169 | else{ 170 | fwrite(buffer, 1, length, fp); 171 | fclose( fp ); 172 | ext_music_play_once_flag = !loop_flag; 173 | if (playMIDI(loop_flag) == 0){ 174 | delete[] buffer; 175 | return SOUND_MIDI; 176 | } 177 | } 178 | } 179 | 180 | delete[] buffer; 181 | 182 | return SOUND_OTHER; 183 | } 184 | 185 | void ONScripter::playCDAudio() 186 | { 187 | if ( cdaudio_flag ){ 188 | #ifdef USE_CDROM 189 | if ( cdrom_info ){ 190 | int length = cdrom_info->track[current_cd_track - 1].length / 75; 191 | SDL_CDPlayTracks( cdrom_info, current_cd_track - 1, 0, 1, 0 ); 192 | timer_cdaudio_id = SDL_AddTimer( length * 1000, cdaudioCallback, NULL ); 193 | } 194 | #endif 195 | } 196 | else{ 197 | char filename[256]; 198 | sprintf( filename, "cd\\track%2.2d.mp3", current_cd_track ); 199 | int ret = playSound( filename, SOUND_MUSIC, cd_play_loop_flag ); 200 | if (ret == SOUND_MUSIC) return; 201 | 202 | sprintf( filename, "cd\\track%2.2d.ogg", current_cd_track ); 203 | ret = playSound( filename, SOUND_MUSIC, cd_play_loop_flag ); 204 | if (ret == SOUND_MUSIC) return; 205 | 206 | sprintf( filename, "cd\\track%2.2d.wav", current_cd_track ); 207 | ret = playSound( filename, SOUND_MUSIC|SOUND_CHUNK, cd_play_loop_flag, MIX_BGM_CHANNEL ); 208 | } 209 | } 210 | 211 | int ONScripter::playWave(Mix_Chunk *chunk, int format, bool loop_flag, int channel) 212 | { 213 | if (!chunk) return -1; 214 | 215 | Mix_Pause( channel ); 216 | if ( wave_sample[channel] ) Mix_FreeChunk( wave_sample[channel] ); 217 | wave_sample[channel] = chunk; 218 | 219 | if (channel == 0) Mix_Volume( channel, voice_volume * MIX_MAX_VOLUME / 100 ); 220 | else if (channel == MIX_BGM_CHANNEL) Mix_Volume( channel, music_volume * MIX_MAX_VOLUME / 100 ); 221 | else Mix_Volume( channel, se_volume * MIX_MAX_VOLUME / 100 ); 222 | 223 | if ( !(format & SOUND_PRELOAD) ) 224 | Mix_PlayChannel( channel, wave_sample[channel], loop_flag?-1:0 ); 225 | 226 | return 0; 227 | } 228 | 229 | int ONScripter::playMIDI(bool loop_flag) 230 | { 231 | Mix_SetMusicCMD(midi_cmd); 232 | 233 | char midi_filename[256]; 234 | sprintf(midi_filename, "%s%s", save_dir?save_dir:archive_path, TMP_MUSIC_FILE); 235 | if ((midi_info = Mix_LoadMUS(midi_filename)) == NULL) return -1; 236 | 237 | int midi_looping = loop_flag ? -1 : 0; 238 | 239 | #if defined(LINUX) 240 | signal(SIGCHLD, midiCallback); 241 | if (midi_cmd) midi_looping = 0; 242 | #endif 243 | 244 | Mix_VolumeMusic(music_volume); 245 | Mix_PlayMusic(midi_info, midi_looping); 246 | current_cd_track = -2; 247 | 248 | return 0; 249 | } 250 | 251 | int ONScripter::playMPEG(const char *filename, bool click_flag, bool loop_flag) 252 | { 253 | unsigned long length = script_h.cBR->getFileLength( filename ); 254 | if (length == 0){ 255 | fprintf( stderr, " *** can't find file [%s] ***\n", filename ); 256 | return 0; 257 | } 258 | 259 | #ifdef ANDROID 260 | playVideoAndroid(filename); 261 | return 0; 262 | #endif 263 | 264 | #ifdef IOS 265 | char *absolute_filename = new char[ strlen(archive_path) + strlen(filename) + 1 ]; 266 | sprintf( absolute_filename, "%s%s", archive_path, filename ); 267 | playVideoIOS(absolute_filename, click_flag, loop_flag); 268 | delete[] absolute_filename; 269 | return 0; 270 | #endif 271 | 272 | int ret = 0; 273 | #if defined(USE_SMPEG) && !defined(USE_SDL_RENDERER) 274 | unsigned char *mpeg_buffer = new unsigned char[length]; 275 | script_h.cBR->getFile( filename, mpeg_buffer ); 276 | SMPEG *mpeg_sample = SMPEG_new_rwops( SDL_RWFromMem( mpeg_buffer, length ), NULL, 0 ); 277 | 278 | if ( !SMPEG_error( mpeg_sample ) ){ 279 | SMPEG_enableaudio( mpeg_sample, 0 ); 280 | 281 | if ( audio_open_flag ){ 282 | SMPEG_actualSpec( mpeg_sample, &audio_format ); 283 | SMPEG_enableaudio( mpeg_sample, 1 ); 284 | } 285 | SMPEG_enablevideo( mpeg_sample, 1 ); 286 | SMPEG_setdisplay( mpeg_sample, screen_surface, NULL, NULL ); 287 | SMPEG_setvolume( mpeg_sample, music_volume ); 288 | SMPEG_loop(mpeg_sample, loop_flag); 289 | 290 | Mix_HookMusic( mp3callback, mpeg_sample ); 291 | SMPEG_play( mpeg_sample ); 292 | 293 | bool done_flag = false; 294 | while( !(done_flag & click_flag) && SMPEG_status(mpeg_sample) == SMPEG_PLAYING ){ 295 | SDL_Event event; 296 | 297 | while( SDL_PollEvent( &event ) ){ 298 | switch (event.type){ 299 | case SDL_KEYUP: 300 | if ( ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_RETURN || 301 | ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_SPACE || 302 | ((SDL_KeyboardEvent *)&event)->keysym.sym == SDLK_ESCAPE ) 303 | done_flag = true; 304 | break; 305 | case SDL_QUIT: 306 | ret = 1; 307 | case SDL_MOUSEBUTTONUP: 308 | done_flag = true; 309 | break; 310 | default: 311 | break; 312 | } 313 | } 314 | SDL_Delay( 10 ); 315 | } 316 | 317 | SMPEG_stop( mpeg_sample ); 318 | Mix_HookMusic( NULL, NULL ); 319 | SMPEG_delete( mpeg_sample ); 320 | 321 | } 322 | delete[] mpeg_buffer; 323 | #else 324 | fprintf( stderr, "mpegplay command is disabled.\n" ); 325 | #endif 326 | 327 | return ret; 328 | } 329 | 330 | int ONScripter::playAVI( const char *filename, bool click_flag ) 331 | { 332 | unsigned long length = script_h.cBR->getFileLength( filename ); 333 | if (length == 0){ 334 | fprintf( stderr, " *** can't find file [%s] ***\n", filename ); 335 | return 0; 336 | } 337 | 338 | #ifdef ANDROID 339 | playVideoAndroid(filename); 340 | return 0; 341 | #endif 342 | 343 | #if defined(USE_AVIFILE) && !defined(USE_SDL_RENDERER) 344 | char *absolute_filename = new char[ strlen(archive_path) + strlen(filename) + 1 ]; 345 | sprintf( absolute_filename, "%s%s", archive_path, filename ); 346 | for ( unsigned int i=0 ; iinit( absolute_filename, false ) == 0 && 355 | avi->initAV( screen_surface, audio_open_flag ) == 0 ){ 356 | if (avi->play( click_flag )) return 1; 357 | } 358 | delete avi; 359 | delete[] absolute_filename; 360 | 361 | if ( audio_open_flag ){ 362 | Mix_CloseAudio(); 363 | openAudio(); 364 | } 365 | #else 366 | fprintf( stderr, "avi command is disabled.\n" ); 367 | #endif 368 | 369 | return 0; 370 | } 371 | 372 | void ONScripter::stopBGM( bool continue_flag ) 373 | { 374 | removeBGMFadeEvent(); 375 | if (timer_bgmfade_id) SDL_RemoveTimer( timer_bgmfade_id ); 376 | timer_bgmfade_id = NULL; 377 | mp3fadeout_duration_internal = 0; 378 | 379 | #ifdef USE_CDROM 380 | if ( cdaudio_flag && cdrom_info ){ 381 | extern SDL_TimerID timer_cdaudio_id; 382 | 383 | if ( timer_cdaudio_id ){ 384 | SDL_RemoveTimer( timer_cdaudio_id ); 385 | timer_cdaudio_id = NULL; 386 | } 387 | if (SDL_CDStatus( cdrom_info ) >= CD_PLAYING ) 388 | SDL_CDStop( cdrom_info ); 389 | } 390 | #endif 391 | 392 | if ( wave_sample[MIX_BGM_CHANNEL] ){ 393 | Mix_Pause( MIX_BGM_CHANNEL ); 394 | Mix_FreeChunk( wave_sample[MIX_BGM_CHANNEL] ); 395 | wave_sample[MIX_BGM_CHANNEL] = NULL; 396 | } 397 | 398 | if ( music_info ){ 399 | ext_music_play_once_flag = true; 400 | Mix_HaltMusic(); 401 | Mix_FreeMusic( music_info ); 402 | music_info = NULL; 403 | } 404 | 405 | if ( midi_info ){ 406 | ext_music_play_once_flag = true; 407 | Mix_HaltMusic(); 408 | Mix_FreeMusic( midi_info ); 409 | midi_info = NULL; 410 | } 411 | 412 | if ( !continue_flag ){ 413 | setStr( &music_file_name, NULL ); 414 | music_play_loop_flag = false; 415 | if (music_buffer){ 416 | delete[] music_buffer; 417 | music_buffer = NULL; 418 | } 419 | 420 | setStr( &midi_file_name, NULL ); 421 | midi_play_loop_flag = false; 422 | 423 | current_cd_track = -1; 424 | } 425 | } 426 | 427 | void ONScripter::stopAllDWAVE() 428 | { 429 | for (int ch=0; chfile_handle = fopen( name, "rb" ) ) == NULL ){ 48 | delete info; 49 | return -1; 50 | } 51 | 52 | info->file_name = new char[strlen(name)+1]; 53 | memcpy(info->file_name, name, strlen(name)+1); 54 | 55 | readArchive( info ); 56 | 57 | last_archive_info->next = info; 58 | last_archive_info = last_archive_info->next; 59 | num_of_sar_archives++; 60 | 61 | return 0; 62 | } 63 | 64 | void SarReader::readArchive( ArchiveInfo *ai, int archive_type, unsigned int offset ) 65 | { 66 | unsigned int i; 67 | 68 | /* Read header */ 69 | for (i=0; ifile_handle ); // for commands "ns2" and "ns3" 71 | 72 | if ( archive_type == ARCHIVE_TYPE_NS2 ) { 73 | // new archive type since NScr2.91 74 | // - header starts with base_offset (byte-swapped), followed by 75 | // filename data - doesn't tell how many files! 76 | // - filenames are surrounded by ""s 77 | // - new NS2 filename def: "filename", length (4bytes, swapped) 78 | // - no compression type? really, no compression. 79 | // - not sure if NS2 uses key_table or not, using default funcs for now 80 | ai->base_offset = swapLong( readLong( ai->file_handle ) ); 81 | ai->base_offset += offset; 82 | 83 | // need to parse the whole header to see how many files there are 84 | ai->num_of_files = 0; 85 | long unsigned int cur_offset = offset + 4; 86 | // there's an extra byte at the end of the header, not sure what for 87 | while(1){ 88 | unsigned char ch = key_table[fgetc( ai->file_handle )]; 89 | if (ch != '"') break; 90 | cur_offset++; 91 | do cur_offset++; 92 | while( (ch = key_table[fgetc( ai->file_handle )] ) != '"' ); 93 | cur_offset += 4; 94 | readLong( ai->file_handle ); 95 | ai->num_of_files++; 96 | } 97 | ai->fi_list = new FileInfo[ ai->num_of_files ]; 98 | 99 | // now go back to the beginning and read the file info 100 | cur_offset = ai->base_offset; 101 | fseek( ai->file_handle, 4 + offset, SEEK_SET ); 102 | for ( i=0 ; inum_of_files ; i++ ){ 103 | unsigned int count = 0; 104 | //skip the beginning double-quote 105 | unsigned char ch = key_table[fgetc( ai->file_handle )]; 106 | while( (ch = key_table[fgetc( ai->file_handle )] ) != '"' ){ 107 | if ( 'a' <= ch && ch <= 'z' ) ch += 'A' - 'a'; 108 | ai->fi_list[i].name[count++] = ch; 109 | } 110 | ai->fi_list[i].name[count] = '\0'; 111 | ai->fi_list[i].compression_type = getRegisteredCompressionType( ai->fi_list[i].name ); 112 | ai->fi_list[i].offset = cur_offset; 113 | ai->fi_list[i].length = swapLong( readLong( ai->file_handle ) ); 114 | ai->fi_list[i].original_length = ai->fi_list[i].length; 115 | cur_offset += ai->fi_list[i].length; 116 | } 117 | } else { 118 | // old NSA filename def: filename, ending '\0' byte , compr-type byte, 119 | // start (4byte), length (4byte)) 120 | ai->num_of_files = readShort( ai->file_handle ); 121 | ai->fi_list = new FileInfo[ ai->num_of_files ]; 122 | 123 | ai->base_offset = readLong( ai->file_handle ); 124 | ai->base_offset += offset; 125 | 126 | for ( i=0 ; inum_of_files ; i++ ){ 127 | unsigned char ch; 128 | int count = 0; 129 | 130 | while( (ch = key_table[fgetc( ai->file_handle )] ) ){ 131 | if ( 'a' <= ch && ch <= 'z' ) ch += 'A' - 'a'; 132 | ai->fi_list[i].name[count++] = ch; 133 | } 134 | ai->fi_list[i].name[count] = ch; 135 | 136 | if ( archive_type == ARCHIVE_TYPE_NSA ) 137 | ai->fi_list[i].compression_type = readChar( ai->file_handle ); 138 | else 139 | ai->fi_list[i].compression_type = NO_COMPRESSION; 140 | ai->fi_list[i].offset = readLong( ai->file_handle ) + ai->base_offset; 141 | ai->fi_list[i].length = readLong( ai->file_handle ); 142 | 143 | if ( archive_type == ARCHIVE_TYPE_NSA ){ 144 | ai->fi_list[i].original_length = readLong( ai->file_handle ); 145 | } 146 | else{ 147 | ai->fi_list[i].original_length = ai->fi_list[i].length; 148 | } 149 | 150 | /* Registered Plugin check */ 151 | if ( ai->fi_list[i].compression_type == NO_COMPRESSION ) 152 | ai->fi_list[i].compression_type = getRegisteredCompressionType( ai->fi_list[i].name ); 153 | 154 | if ( ai->fi_list[i].compression_type == NBZ_COMPRESSION || 155 | ai->fi_list[i].compression_type == SPB_COMPRESSION ){ 156 | // Delaying checking decompressed file length to prevent 157 | // massive random access in the archives at the start-up. 158 | ai->fi_list[i].original_length = 0; 159 | } 160 | } 161 | } 162 | } 163 | 164 | int SarReader::writeHeaderSub( ArchiveInfo *ai, FILE *fp, int archive_type, int nsa_offset ) 165 | { 166 | unsigned int i, j; 167 | 168 | fseek( fp, 0L, SEEK_SET ); 169 | for (int k=0 ; knum_of_files ); 172 | writeLong( fp, ai->base_offset-nsa_offset ); 173 | 174 | for ( i=0 ; inum_of_files ; i++ ){ 175 | 176 | for ( j=0 ; ai->fi_list[i].name[j] ; j++ ) 177 | fputc( ai->fi_list[i].name[j], fp ); 178 | fputc( ai->fi_list[i].name[j], fp ); 179 | 180 | if ( archive_type >= ARCHIVE_TYPE_NSA ) 181 | writeChar( fp, ai->fi_list[i].compression_type ); 182 | 183 | writeLong( fp, ai->fi_list[i].offset - ai->base_offset ); 184 | writeLong( fp, ai->fi_list[i].length ); 185 | 186 | if ( archive_type >= ARCHIVE_TYPE_NSA ){ 187 | writeLong( fp, ai->fi_list[i].original_length ); 188 | } 189 | } 190 | 191 | return 0; 192 | } 193 | 194 | int SarReader::writeHeader( FILE *fp ) 195 | { 196 | ArchiveInfo *ai = archive_info.next; 197 | return writeHeaderSub( ai, fp ); 198 | } 199 | 200 | size_t SarReader::putFileSub( ArchiveInfo *ai, FILE *fp, int no, size_t offset, size_t length, size_t original_length, int compression_type, bool modified_flag, unsigned char *buffer ) 201 | { 202 | ai->fi_list[no].compression_type = compression_type; 203 | ai->fi_list[no].length = length; 204 | ai->fi_list[no].original_length = original_length; 205 | 206 | fseek( fp, offset, SEEK_SET ); 207 | if ( modified_flag ){ 208 | if ( ai->fi_list[no].compression_type == NBZ_COMPRESSION ){ 209 | writeLong( fp, ai->fi_list[no].original_length ); 210 | fseek( ai->file_handle, ai->fi_list[no].offset+2, SEEK_SET ); 211 | if ( readChar( ai->file_handle ) != 'B' || readChar( ai->file_handle ) != 'Z' ){ // in case the original is not compressed in NBZ 212 | ai->fi_list[no].length = encodeNBZ( fp, length, buffer ) + 4; 213 | ai->fi_list[no].offset = offset; 214 | return ai->fi_list[no].length; 215 | } 216 | } 217 | else{ 218 | ai->fi_list[no].compression_type = NO_COMPRESSION; 219 | } 220 | } 221 | else{ 222 | fseek( ai->file_handle, ai->fi_list[no].offset, SEEK_SET ); 223 | fread( buffer, 1, ai->fi_list[no].length, ai->file_handle ); 224 | } 225 | 226 | size_t len = ai->fi_list[no].length, c; 227 | while( len > 0 ){ 228 | if ( len > WRITE_LENGTH ) c = WRITE_LENGTH; 229 | else c = len; 230 | len -= c; 231 | fwrite( buffer, 1, c, fp ); 232 | buffer += c; 233 | } 234 | 235 | ai->fi_list[no].offset = offset; 236 | 237 | return ai->fi_list[no].length; 238 | } 239 | 240 | size_t SarReader::putFile( FILE *fp, int no, size_t offset, size_t length, size_t original_length, bool modified_flag, unsigned char *buffer ) 241 | { 242 | ArchiveInfo *ai = archive_info.next; 243 | return putFileSub( ai, fp, no, offset, length, original_length, ai->fi_list[no].compression_type, modified_flag, buffer ); 244 | } 245 | 246 | int SarReader::close() 247 | { 248 | ArchiveInfo *info = archive_info.next; 249 | 250 | for ( int i=0 ; inext; 253 | delete last_archive_info; 254 | } 255 | return 0; 256 | } 257 | 258 | const char *SarReader::getArchiveName() const 259 | { 260 | return "sar"; 261 | } 262 | 263 | int SarReader::getNumFiles(){ 264 | ArchiveInfo *info = archive_info.next; 265 | int num = 0; 266 | 267 | for ( int i=0 ; inum_of_files; 269 | info = info->next; 270 | } 271 | 272 | return num; 273 | } 274 | 275 | int SarReader::getIndexFromFile( ArchiveInfo *ai, const char *file_name ) 276 | { 277 | unsigned int i, len; 278 | 279 | len = strlen( file_name ); 280 | if ( len > MAX_FILE_NAME_LENGTH ) len = MAX_FILE_NAME_LENGTH; 281 | memcpy( capital_name, file_name, len ); 282 | capital_name[ len ] = '\0'; 283 | 284 | for ( i=0 ; inum_of_files ; i++ ){ 289 | if ( !strcmp( capital_name, ai->fi_list[i].name ) ) break; 290 | } 291 | 292 | return i; 293 | } 294 | 295 | size_t SarReader::getFileLength( const char *file_name ) 296 | { 297 | size_t ret; 298 | if ( ( ret = DirectReader::getFileLength( file_name ) ) ) return ret; 299 | 300 | ArchiveInfo *info = archive_info.next; 301 | unsigned int j = 0; 302 | for ( int i=0 ; inum_of_files ) break; 305 | info = info->next; 306 | } 307 | if ( !info ) return 0; 308 | 309 | if ( info->fi_list[j].original_length != 0 ) 310 | return info->fi_list[j].original_length; 311 | 312 | int type = info->fi_list[j].compression_type; 313 | if ( type == NO_COMPRESSION ) 314 | type = getRegisteredCompressionType( file_name ); 315 | if ( type == NBZ_COMPRESSION || type == SPB_COMPRESSION ) { 316 | info->fi_list[j].original_length = getDecompressedFileLength( type, info->file_handle, info->fi_list[j].offset ); 317 | } 318 | 319 | return info->fi_list[j].original_length; 320 | } 321 | 322 | size_t SarReader::getFileSub( ArchiveInfo *ai, const char *file_name, unsigned char *buf ) 323 | { 324 | unsigned int i = getIndexFromFile( ai, file_name ); 325 | if ( i == ai->num_of_files ) return 0; 326 | 327 | #if defined(PSP) 328 | if (ai->power_resume_number != psp_power_resume_number){ 329 | FILE *fp = fopen(ai->file_name, "rb"); 330 | ai->file_handle = fp; 331 | ai->power_resume_number = psp_power_resume_number; 332 | } 333 | #endif 334 | 335 | int type = ai->fi_list[i].compression_type; 336 | if ( type == NO_COMPRESSION ) type = getRegisteredCompressionType( file_name ); 337 | 338 | if ( type == NBZ_COMPRESSION ){ 339 | return decodeNBZ( ai->file_handle, ai->fi_list[i].offset, buf ); 340 | } 341 | else if ( type == LZSS_COMPRESSION ){ 342 | return decodeLZSS( ai, i, buf ); 343 | } 344 | else if ( type == SPB_COMPRESSION ){ 345 | return decodeSPB( ai->file_handle, ai->fi_list[i].offset, buf ); 346 | } 347 | 348 | fseek( ai->file_handle, ai->fi_list[i].offset, SEEK_SET ); 349 | size_t ret = fread( buf, 1, ai->fi_list[i].length, ai->file_handle ); 350 | if (key_table_flag) 351 | for (size_t j=0 ; j 0 ) break; 364 | info = info->next; 365 | } 366 | if ( location ) *location = ARCHIVE_TYPE_SAR; 367 | 368 | return j; 369 | } 370 | 371 | SarReader::FileInfo SarReader::getFileByIndex( unsigned int index ) 372 | { 373 | ArchiveInfo *info = archive_info.next; 374 | for ( int i=0 ; inum_of_files ) return info->fi_list[index]; 376 | index -= info->num_of_files; 377 | info = info->next; 378 | } 379 | fprintf( stderr, "SarReader::getFileByIndex Index %d is out of range\n", index ); 380 | 381 | return archive_info.fi_list[index]; 382 | } 383 | -------------------------------------------------------------------------------- /SarReader.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * SarReader.h - Reader from a SAR archive 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifndef __SAR_READER_H__ 25 | #define __SAR_READER_H__ 26 | 27 | #include "DirectReader.h" 28 | 29 | class SarReader : public DirectReader 30 | { 31 | public: 32 | SarReader( const char *path=NULL, const unsigned char *key_table=NULL ); 33 | ~SarReader(); 34 | 35 | int open( const char *name=NULL ); 36 | int close(); 37 | const char *getArchiveName() const; 38 | int getNumFiles(); 39 | 40 | size_t getFileLength( const char *file_name ); 41 | size_t getFile( const char *file_name, unsigned char *buf, int *location=NULL ); 42 | FileInfo getFileByIndex( unsigned int index ); 43 | 44 | int writeHeader( FILE *fp ); 45 | size_t putFile( FILE *fp, int no, size_t offset, size_t length, size_t original_length, bool modified_flag, unsigned char *buffer ); 46 | 47 | protected: 48 | ArchiveInfo archive_info; 49 | ArchiveInfo *root_archive_info, *last_archive_info; 50 | int num_of_sar_archives; 51 | 52 | void readArchive( ArchiveInfo *ai, int archive_type = ARCHIVE_TYPE_SAR, unsigned int offset=0 ); 53 | int readArchiveSub( ArchiveInfo *ai, int archive_type = ARCHIVE_TYPE_SAR, bool check_size = true ); 54 | int getIndexFromFile( ArchiveInfo *ai, const char *file_name ); 55 | size_t getFileSub( ArchiveInfo *ai, const char *file_name, unsigned char *buf ); 56 | 57 | int writeHeaderSub( ArchiveInfo *ai, FILE *fp, int archive_type = ARCHIVE_TYPE_SAR, int nsa_offset=0 ); 58 | size_t putFileSub( ArchiveInfo *ai, FILE *fp, int no, size_t offset, size_t length, size_t original_length, int compression_type, bool modified_flag, unsigned char *buffer ); 59 | }; 60 | 61 | #endif // __SAR_READER_H__ 62 | -------------------------------------------------------------------------------- /ScriptHandler.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LasmGratel/onscripter-jh/fe5e7d94cb12c1ec48ac423b83322d48ac430549/ScriptHandler.cpp -------------------------------------------------------------------------------- /ScriptHandler.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * ScriptHandler.h - Script manipulation class 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifndef __SCRIPT_HANDLER_H__ 25 | #define __SCRIPT_HANDLER_H__ 26 | 27 | #include 28 | #include 29 | #include 30 | #include "BaseReader.h" 31 | 32 | #define IS_TWO_BYTE(x) \ 33 | ( ((unsigned char)(x) > (unsigned char)0x80) && ((unsigned char)(x) !=(unsigned char) 0xff) ) 34 | 35 | typedef unsigned char uchar3[3]; 36 | 37 | class ScriptHandler 38 | { 39 | public: 40 | enum { END_NONE = 0, 41 | END_COMMA = 1, 42 | END_1BYTE_CHAR = 2, 43 | END_COMMA_READ = 4 // for LUA 44 | }; 45 | struct LabelInfo{ 46 | char *name; 47 | char *label_header; 48 | char *start_address; 49 | int start_line; 50 | int num_of_lines; 51 | }; 52 | 53 | struct ArrayVariable{ 54 | struct ArrayVariable* next; 55 | int no; 56 | int num_dim; 57 | int dim[20]; 58 | int *data; 59 | ArrayVariable(){ 60 | next = NULL; 61 | data = NULL; 62 | }; 63 | ~ArrayVariable(){ 64 | if (data) delete[] data; 65 | }; 66 | ArrayVariable& operator=(const ArrayVariable& av){ 67 | no = av.no; 68 | num_dim = av.num_dim; 69 | 70 | int total_dim = 1; 71 | for (int i=0 ; i<20 ; i++){ 72 | dim[i] = av.dim[i]; 73 | total_dim *= dim[i]; 74 | } 75 | 76 | if (data) delete[] data; 77 | data = NULL; 78 | if (av.data){ 79 | data = new int[total_dim]; 80 | memcpy(data, av.data, sizeof(int)*total_dim); 81 | } 82 | 83 | return *this; 84 | }; 85 | }; 86 | 87 | enum { VAR_NONE = 0, 88 | VAR_INT = 1, // integer 89 | VAR_ARRAY = 2, // array 90 | VAR_STR = 4, // string 91 | VAR_CONST = 8, // direct value or alias, not variable 92 | VAR_PTR = 16 // pointer to a variable, e.g. i%0, s%0 93 | }; 94 | struct VariableInfo{ 95 | int type; 96 | int var_no; // for integer(%), array(?), string($) variable 97 | ArrayVariable array; // for array(?) 98 | }; 99 | 100 | ScriptHandler(); 101 | ~ScriptHandler(); 102 | 103 | void reset(); 104 | void setSaveDir(const char *path); 105 | FILE *fopen( const char *path, const char *mode, bool use_save_dir=false ); 106 | void setKeyTable( const unsigned char *key_table ); 107 | 108 | // basic parser function 109 | const char *readToken(); 110 | const char *readLabel(); 111 | const char *readStr(); 112 | int readInt(); 113 | void skipToken(); 114 | int parseInt( char **buf ); 115 | int parseIntExpression( char **buf ); 116 | void readVariable( bool reread_flag=false ); 117 | 118 | // function for string access 119 | inline char *getStringBuffer(){ return string_buffer; }; 120 | char *saveStringBuffer(); 121 | void addStringBuffer( char ch ); 122 | 123 | // function for direct manipulation of script address 124 | inline char *getCurrent(bool use_script=false){ return (use_script && internal_current_script)?internal_current_script:current_script; }; 125 | inline char *getNext(){ return next_script; }; 126 | inline char *getWait(){ return wait_script; }; 127 | void setCurrent(char *pos); 128 | void pushCurrent( char *pos ); 129 | void popCurrent(); 130 | 131 | void enterExternalScript(char *pos); // LUA 132 | void leaveExternalScript(); 133 | bool isExternalScript(); 134 | 135 | int getOffset( char *pos ); 136 | char *getAddress( int offset ); 137 | int getLineByAddress( char *address ); 138 | char *getAddressByLine( int line ); 139 | LabelInfo getLabelByAddress( char *address ); 140 | LabelInfo getLabelByLine( int line ); 141 | 142 | bool isName( const char *name ); 143 | bool isText(); 144 | bool compareString( const char *buf ); 145 | void setEndStatus(int val){ end_status |= val; }; 146 | inline int getEndStatus(){ return end_status; }; 147 | void skipLine( int no=1 ); 148 | void setLinepage( bool val ); 149 | void setEnglishMode( bool val ){ english_mode = val; }; 150 | 151 | // function for kidoku history 152 | bool isKidoku(); 153 | void markAsKidoku( char *address=NULL ); 154 | void setKidokuskip( bool kidokuskip_flag ); 155 | void saveKidokuData(); 156 | void loadKidokuData(); 157 | 158 | void addStrVariable(char **buf); 159 | void addIntVariable(char **buf); 160 | void declareDim(); 161 | 162 | void enableTextgosub(bool val); 163 | void setClickstr( const char *list ); 164 | int checkClickstr(const char *buf, bool recursive_flag=false); 165 | 166 | void setInt( VariableInfo *var_info, int val, int offset=0 ); 167 | void setNumVariable( int no, int val ); 168 | void pushVariable(); 169 | int getIntVariable( VariableInfo *var_info=NULL ); 170 | 171 | int getStringFromInteger( char *buffer, int no, int num_column, bool is_zero_inserted=false ); 172 | 173 | int openScript( char *path ); 174 | 175 | LabelInfo lookupLabel( const char* label ); 176 | LabelInfo lookupLabelNext( const char* label ); 177 | void errorAndExit( const char *str ); 178 | 179 | ArrayVariable *getRootArrayVariable(); 180 | void loadArrayVariable( FILE *fp ); 181 | 182 | void addNumAlias( const char *str, int no ); 183 | void addStrAlias( const char *str1, const char *str2 ); 184 | 185 | enum { LABEL_LOG = 0, 186 | FILE_LOG = 1 187 | }; 188 | struct LogLink{ 189 | LogLink *next; 190 | char *name; 191 | 192 | LogLink(){ 193 | next = NULL; 194 | name = NULL; 195 | }; 196 | ~LogLink(){ 197 | if ( name ) delete[] name; 198 | }; 199 | }; 200 | struct LogInfo{ 201 | LogLink root_log; 202 | LogLink *current_log; 203 | int num_logs; 204 | const char *filename; 205 | } log_info[2]; 206 | LogLink *findAndAddLog( LogInfo &info, const char *name, bool add_flag ); 207 | void resetLog( LogInfo &info ); 208 | 209 | /* ---------------------------------------- */ 210 | /* Variable */ 211 | struct VariableData{ 212 | int num; 213 | bool num_limit_flag; 214 | int num_limit_upper; 215 | int num_limit_lower; 216 | char *str; 217 | 218 | VariableData(){ 219 | str = NULL; 220 | reset(true); 221 | }; 222 | void reset(bool limit_reset_flag){ 223 | num = 0; 224 | if (limit_reset_flag) 225 | num_limit_flag = false; 226 | if (str){ 227 | delete[] str; 228 | str = NULL; 229 | } 230 | }; 231 | }; 232 | VariableData &getVariableData(int no); 233 | 234 | VariableInfo current_variable, pushed_variable; 235 | 236 | int screen_width; 237 | int screen_height; 238 | int variable_range; 239 | int global_variable_border; 240 | 241 | BaseReader *cBR; 242 | 243 | private: 244 | enum { OP_INVALID = 0, // 000 245 | OP_PLUS = 2, // 010 246 | OP_MINUS = 3, // 011 247 | OP_MULT = 4, // 100 248 | OP_DIV = 5, // 101 249 | OP_MOD = 6 // 110 250 | }; 251 | 252 | struct Alias{ 253 | struct Alias *next; 254 | char *alias; 255 | int num; 256 | char *str; 257 | 258 | Alias(){ 259 | next = NULL; 260 | alias = NULL; 261 | str = NULL; 262 | }; 263 | Alias( const char *name, int num ){ 264 | next = NULL; 265 | alias = new char[ strlen(name) + 1]; 266 | strcpy( alias, name ); 267 | str = NULL; 268 | this->num = num; 269 | }; 270 | Alias( const char *name, const char *str ){ 271 | next = NULL; 272 | alias = new char[ strlen(name) + 1]; 273 | strcpy( alias, name ); 274 | this->str = new char[ strlen(str) + 1]; 275 | strcpy( this->str, str ); 276 | }; 277 | ~Alias(){ 278 | if (alias) delete[] alias; 279 | if (str) delete[] str; 280 | }; 281 | }; 282 | 283 | int readScript(char *path); 284 | int readScriptSub(FILE *fp, char **buf, int encrypt_mode); 285 | void readConfiguration(); 286 | int labelScript(); 287 | 288 | int findLabel( const char* label ); 289 | 290 | char *checkComma( char *buf ); 291 | void parseStr( char **buf ); 292 | void readNextOp( char **buf, int *op, int *num ); 293 | int calcArithmetic( int num1, int op, int num2 ); 294 | int parseArray( char **buf, ArrayVariable &array ); 295 | int *getArrayPtr( int no, ArrayVariable &array, int offset ); 296 | 297 | /* ---------------------------------------- */ 298 | /* Variable */ 299 | struct VariableData *variable_data; 300 | struct ExtendedVariableData{ 301 | int no; 302 | VariableData vd; 303 | } *extended_variable_data; 304 | int num_extended_variable_data; 305 | int max_extended_variable_data; 306 | 307 | Alias root_num_alias, *last_num_alias; 308 | Alias root_str_alias, *last_str_alias; 309 | 310 | ArrayVariable *root_array_variable, *current_array_variable; 311 | 312 | char *archive_path; 313 | char *save_dir; 314 | int script_buffer_length; 315 | char *script_buffer; 316 | unsigned char *tmp_script_buf; 317 | 318 | char *string_buffer; // update only be readToken 319 | int string_counter; 320 | char *saved_string_buffer; // updated only by saveStringBuffer 321 | char *str_string_buffer; // updated only by readStr 322 | 323 | LabelInfo *label_info; 324 | int num_of_labels; 325 | 326 | bool skip_enabled; 327 | bool kidokuskip_flag; 328 | char *kidoku_buffer; 329 | 330 | bool text_flag; // true if the current token is text 331 | int end_status; 332 | bool linepage_flag; 333 | bool textgosub_flag; 334 | char *clickstr_list; 335 | bool english_mode; 336 | 337 | char *current_script; 338 | char *next_script; 339 | char *wait_script; // address where '@' or '//' appears 340 | 341 | char *pushed_current_script; 342 | char *pushed_next_script; 343 | 344 | char *internal_current_script; 345 | char *internal_next_script; 346 | int internal_end_status; 347 | VariableInfo internal_current_variable, internal_pushed_variable; 348 | 349 | unsigned char key_table[256]; 350 | bool key_table_flag; 351 | }; 352 | 353 | #endif // __SCRIPT_HANDLER_H__ 354 | -------------------------------------------------------------------------------- /ScriptParser.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LasmGratel/onscripter-jh/fe5e7d94cb12c1ec48ac423b83322d48ac430549/ScriptParser.cpp -------------------------------------------------------------------------------- /ScriptParser.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LasmGratel/onscripter-jh/fe5e7d94cb12c1ec48ac423b83322d48ac430549/ScriptParser.h -------------------------------------------------------------------------------- /conv_shared.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * conv_shared.cpp - Shared code of sarconv and nsaconv 4 | * 5 | * Copyright (c) 2001-2006 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | extern "C"{ 28 | #include 29 | }; 30 | #include 31 | #include "resize_image.h" 32 | 33 | int scale_ratio_upper; 34 | int scale_ratio_lower; 35 | 36 | unsigned char *rescaled_tmp2_buffer = NULL; 37 | size_t rescaled_tmp2_length = 0; 38 | unsigned char *rescaled_tmp_buffer = NULL; 39 | size_t rescaled_tmp_length = 0; 40 | 41 | static unsigned char *restored_buffer = NULL; 42 | static size_t restored_length = 0; 43 | 44 | #define INPUT_BUFFER_SIZE 4096 45 | typedef struct { 46 | struct jpeg_source_mgr pub; 47 | 48 | unsigned char *buf; 49 | size_t left; 50 | } my_source_mgr; 51 | 52 | typedef struct { 53 | struct jpeg_destination_mgr pub; 54 | 55 | unsigned char *buf; 56 | size_t left; 57 | } my_destination_mgr; 58 | 59 | 60 | void rescaleImage( unsigned char *original_buffer, int width, int height, int byte_per_pixel, 61 | bool src_pad_flag, bool dst_pad_flag, bool palette_flag ) 62 | { 63 | size_t width_pad = 0; 64 | if ( src_pad_flag ) width_pad = (4 - width * byte_per_pixel % 4) % 4; 65 | 66 | size_t w = (int)(width * scale_ratio_upper / scale_ratio_lower); 67 | size_t h = (int)(height * scale_ratio_upper / scale_ratio_lower); 68 | if ( w==0 ) w=1; 69 | if ( h==0 ) h=1; 70 | size_t w_pad = 0; 71 | if ( dst_pad_flag ) w_pad = (4 - w * byte_per_pixel % 4) % 4; 72 | 73 | if ( (w * byte_per_pixel + w_pad) * h > rescaled_tmp_length ){ 74 | int len = (w * byte_per_pixel + w_pad) * h; 75 | if ( rescaled_tmp_buffer ) delete[] rescaled_tmp_buffer; 76 | rescaled_tmp_buffer = new unsigned char[ len ]; 77 | rescaled_tmp_length = len; 78 | } 79 | 80 | size_t len = (width * byte_per_pixel + width_pad) * (height+1) + byte_per_pixel; 81 | if ( len<16 ) len = 16; 82 | if ( len > rescaled_tmp2_length ){ 83 | if ( rescaled_tmp2_buffer ) delete[] rescaled_tmp2_buffer; 84 | rescaled_tmp2_buffer = new unsigned char[ len ]; 85 | rescaled_tmp2_length = len; 86 | } 87 | 88 | resizeImage( rescaled_tmp_buffer, w, h, w*byte_per_pixel+w_pad, 89 | original_buffer, width, height, width*byte_per_pixel+width_pad, 90 | byte_per_pixel, rescaled_tmp2_buffer, width*byte_per_pixel+width_pad, palette_flag ); 91 | } 92 | 93 | 94 | void init_source (j_decompress_ptr cinfo) 95 | { 96 | } 97 | 98 | boolean fill_input_buffer (j_decompress_ptr cinfo) 99 | { 100 | my_source_mgr *src = (my_source_mgr *)cinfo->src; 101 | 102 | src->pub.next_input_byte = src->buf; 103 | src->pub.bytes_in_buffer = src->left; 104 | 105 | return TRUE; 106 | } 107 | 108 | void skip_input_data (j_decompress_ptr cinfo, long num_bytes) 109 | { 110 | my_source_mgr *src = (my_source_mgr *)cinfo->src; 111 | 112 | src->pub.next_input_byte += (size_t) num_bytes; 113 | src->pub.bytes_in_buffer -= (size_t) num_bytes; 114 | } 115 | 116 | void term_source (j_decompress_ptr cinfo) 117 | { 118 | } 119 | 120 | void init_destination (j_compress_ptr cinfo) 121 | { 122 | my_destination_mgr * dest = (my_destination_mgr *) cinfo->dest; 123 | 124 | dest->pub.next_output_byte = dest->buf; 125 | dest->pub.free_in_buffer = dest->left; 126 | } 127 | 128 | boolean empty_output_buffer (j_compress_ptr cinfo) 129 | { 130 | my_destination_mgr * dest = (my_destination_mgr *) cinfo->dest; 131 | 132 | dest->pub.next_output_byte = dest->buf; 133 | dest->pub.free_in_buffer = dest->left; 134 | 135 | return TRUE; 136 | } 137 | 138 | void term_destination (j_compress_ptr cinfo) 139 | { 140 | } 141 | 142 | size_t rescaleJPEGWrite( unsigned int width, unsigned int height, int byte_per_pixel, unsigned char **rescaled_buffer, 143 | int quality, bool bmp2jpeg_flag ) 144 | { 145 | jpeg_error_mgr jerr; 146 | struct jpeg_compress_struct cinfo2; 147 | JSAMPROW row_pointer[1]; 148 | 149 | cinfo2.err = jpeg_std_error(&jerr); 150 | jpeg_create_compress(&cinfo2); 151 | 152 | cinfo2.dest = (struct jpeg_destination_mgr *) 153 | (*cinfo2.mem->alloc_small) ((j_common_ptr) &cinfo2, JPOOL_PERMANENT, 154 | sizeof(my_destination_mgr)); 155 | my_destination_mgr * dest = (my_destination_mgr *) cinfo2.dest; 156 | 157 | dest->buf = *rescaled_buffer; 158 | dest->left = restored_length; 159 | 160 | dest->pub.init_destination = init_destination; 161 | dest->pub.empty_output_buffer = empty_output_buffer; 162 | dest->pub.term_destination = term_destination; 163 | 164 | cinfo2.image_width = (int)(width * scale_ratio_upper / scale_ratio_lower); 165 | if ( cinfo2.image_width == 0 ) cinfo2.image_width = 1; 166 | cinfo2.image_height = (int)(height * scale_ratio_upper / scale_ratio_lower); 167 | if ( cinfo2.image_height == 0 ) cinfo2.image_height = 1; 168 | cinfo2.input_components = byte_per_pixel; 169 | if ( cinfo2.input_components == 1 ) 170 | cinfo2.in_color_space = JCS_GRAYSCALE; 171 | else 172 | cinfo2.in_color_space = JCS_RGB; 173 | 174 | jpeg_set_defaults(&cinfo2); 175 | jpeg_set_quality(&cinfo2, quality, TRUE ); 176 | cinfo2.optimize_coding = true; 177 | //jpeg_simple_progression (&cinfo2); 178 | jpeg_start_compress(&cinfo2, TRUE); 179 | 180 | int row_stride = cinfo2.image_width * byte_per_pixel; 181 | 182 | while (cinfo2.next_scanline < cinfo2.image_height) { 183 | if (bmp2jpeg_flag){ 184 | unsigned char *src = row_pointer[0] = &rescaled_tmp_buffer[(cinfo2.image_height - 1 - cinfo2.next_scanline) * row_stride]; 185 | for(unsigned int i=0 ; ileft - dest->pub.free_in_buffer; 199 | 200 | jpeg_destroy_compress(&cinfo2); 201 | 202 | return datacount; 203 | } 204 | 205 | size_t rescaleJPEG( unsigned char *original_buffer, size_t length, unsigned char **rescaled_buffer, int quality ) 206 | { 207 | struct jpeg_decompress_struct cinfo; 208 | jpeg_error_mgr jerr; 209 | 210 | cinfo.err = jpeg_std_error(&jerr); 211 | jpeg_create_decompress(&cinfo); 212 | 213 | cinfo.src = (struct jpeg_source_mgr *) 214 | (*cinfo.mem->alloc_small) ((j_common_ptr) &cinfo, JPOOL_PERMANENT, 215 | sizeof(my_source_mgr)); 216 | my_source_mgr * src = (my_source_mgr *) cinfo.src; 217 | 218 | src->buf = original_buffer; 219 | src->left = length; 220 | 221 | src->pub.init_source = init_source; 222 | src->pub.fill_input_buffer = fill_input_buffer; 223 | src->pub.skip_input_data = skip_input_data; 224 | src->pub.resync_to_restart = jpeg_resync_to_restart; 225 | src->pub.term_source = term_source; 226 | 227 | src->pub.bytes_in_buffer = 0; 228 | src->pub.next_input_byte = NULL; 229 | 230 | jpeg_read_header(&cinfo, TRUE); 231 | jpeg_start_decompress(&cinfo); 232 | 233 | if ( cinfo.output_width * cinfo.output_height * cinfo.output_components + 0x400 > restored_length ){ 234 | restored_length = cinfo.output_width * cinfo.output_height * cinfo.output_components + 0x400; 235 | if ( restored_buffer ) delete[] restored_buffer; 236 | restored_buffer = new unsigned char[ restored_length ]; 237 | if ( *rescaled_buffer ) delete[] *rescaled_buffer; 238 | *rescaled_buffer = new unsigned char[ restored_length ]; 239 | } 240 | int row_stride = cinfo.output_width * cinfo.output_components; 241 | 242 | JSAMPARRAY buf = (*cinfo.mem->alloc_sarray) 243 | ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); 244 | 245 | unsigned char *buf_p = restored_buffer; 246 | while (cinfo.output_scanline < cinfo.output_height) { 247 | jpeg_read_scanlines(&cinfo, buf, 1); 248 | memcpy( buf_p, buf[0], row_stride ); 249 | buf_p += cinfo.output_width * cinfo.output_components; 250 | } 251 | 252 | rescaleImage( restored_buffer, cinfo.output_width, cinfo.output_height, cinfo.output_components, false, false, false ); 253 | 254 | size_t datacount = rescaleJPEGWrite(cinfo.output_width, cinfo.output_height, cinfo.output_components, rescaled_buffer, quality, false); 255 | jpeg_destroy_decompress(&cinfo); 256 | 257 | return datacount; 258 | } 259 | 260 | void rescaleBMPWrite( unsigned char *original_buffer, size_t total_size, int width, int height, unsigned char **rescaled_buffer ) 261 | { 262 | int buffer_offset = original_buffer[10] + (original_buffer[11] << 8); 263 | memcpy( *rescaled_buffer, original_buffer, buffer_offset ); 264 | memcpy( *rescaled_buffer + buffer_offset, rescaled_tmp_buffer, total_size - buffer_offset ); 265 | 266 | *(*rescaled_buffer + 2) = total_size & 0xff; 267 | *(*rescaled_buffer + 3) = (total_size >> 8) & 0xff; 268 | *(*rescaled_buffer + 4) = (total_size >> 16) & 0xff; 269 | *(*rescaled_buffer + 5) = (total_size >> 24) & 0xff; 270 | *(*rescaled_buffer + 18) = width & 0xff; 271 | *(*rescaled_buffer + 19) = (width >> 8) & 0xff; 272 | *(*rescaled_buffer + 20) = (width >> 16) & 0xff; 273 | *(*rescaled_buffer + 21) = (width >> 24) & 0xff; 274 | *(*rescaled_buffer + 22) = height & 0xff; 275 | *(*rescaled_buffer + 23) = (height >> 8) & 0xff; 276 | *(*rescaled_buffer + 24) = (height >> 16) & 0xff; 277 | *(*rescaled_buffer + 25) = (height >> 24) & 0xff; 278 | *(*rescaled_buffer + 34) = 0; 279 | *(*rescaled_buffer + 35) = 0; 280 | *(*rescaled_buffer + 36) = 0; 281 | *(*rescaled_buffer + 37) = 0; 282 | 283 | #if 0 284 | FILE *fp = fopen( "test.bmp", "wb" ); 285 | fwrite( *rescaled_buffer, 1, width2 * height2 * byte_per_pixel + 54 + color_num*4, fp ); 286 | fclose(fp); 287 | getchar(); 288 | #endif 289 | } 290 | 291 | size_t rescaleBMP( unsigned char *original_buffer, unsigned char **rescaled_buffer, 292 | bool output_jpeg_flag, int quality ) 293 | { 294 | if (original_buffer[14] != 40){ 295 | if (original_buffer[14] == 12) 296 | fprintf( stderr, " OS/2 format is not supported.\n"); 297 | else 298 | fprintf( stderr, " this bitmap can't be handled.\n"); 299 | exit(-1); 300 | } 301 | 302 | int buffer_offset = original_buffer[10] + (original_buffer[11] << 8); 303 | int width = original_buffer[18] + (original_buffer[19] << 8); 304 | int height = original_buffer[22] + (original_buffer[23] << 8); 305 | 306 | int bit_per_pixel = original_buffer[28]; 307 | if (bit_per_pixel == 1 || bit_per_pixel == 4){ 308 | fprintf( stderr, " bit_per_pixel %d is not supported.\n", bit_per_pixel); 309 | exit(-1); 310 | } 311 | int byte_per_pixel = bit_per_pixel / 8; 312 | int color_num = original_buffer[46] + ((int)original_buffer[47] << 8) + (original_buffer[48] << 16) + (original_buffer[49] << 24); 313 | if (bit_per_pixel == 8 && color_num == 0) color_num = 256; 314 | 315 | bool palette_flag = false; 316 | if (bit_per_pixel == 8) palette_flag = true; 317 | if (palette_flag) output_jpeg_flag = false; 318 | 319 | size_t width2 = (int)(width * scale_ratio_upper / scale_ratio_lower); 320 | if ( width2 == 0 ) width2 = 1; 321 | size_t width2_pad = (4 - width2 * byte_per_pixel % 4) % 4; 322 | 323 | size_t height2 = (int)(height * scale_ratio_upper / scale_ratio_lower); 324 | if ( height2 == 0 ) height2 = 1; 325 | 326 | size_t total_size = (width2 * byte_per_pixel + width2_pad) * height2 + buffer_offset; 327 | if ( total_size+0x400 > restored_length ){ 328 | restored_length = total_size+0x400; 329 | if ( restored_buffer ) delete[] restored_buffer; 330 | restored_buffer = new unsigned char[ restored_length ]; 331 | if ( *rescaled_buffer ) delete[] *rescaled_buffer; 332 | *rescaled_buffer = new unsigned char[ restored_length ]; 333 | } 334 | 335 | if (output_jpeg_flag){ 336 | rescaleImage( original_buffer+buffer_offset, width, height, byte_per_pixel, true, false, palette_flag ); 337 | total_size = rescaleJPEGWrite(width, height, byte_per_pixel, rescaled_buffer, quality, true); 338 | } 339 | else { 340 | rescaleImage( original_buffer+buffer_offset, width, height, byte_per_pixel, true, true, palette_flag ); 341 | rescaleBMPWrite(original_buffer, total_size, width2, height2, rescaled_buffer); 342 | } 343 | 344 | return total_size; 345 | } 346 | -------------------------------------------------------------------------------- /nsaconv.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * nsaconv.cpp - Images in NSA archive are re-scaled to 320x240 size 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "NsaReader.h" 30 | 31 | extern int scale_ratio_upper; 32 | extern int scale_ratio_lower; 33 | 34 | extern size_t rescaleJPEG( unsigned char *original_buffer, size_t length, unsigned char **rescaled_buffer, 35 | int quality ); 36 | extern size_t rescaleBMP( unsigned char *original_buffer, unsigned char **rescaled_buffer, 37 | bool output_jpeg_flag, int quality ); 38 | 39 | #ifdef main 40 | #undef main 41 | #endif 42 | 43 | void help() 44 | { 45 | fprintf(stderr, "Usage: nsaconv [-e] [-j] [-ns2] [-ns3] [-q quality] src_width dst_width src_archive_file dst_archive_file\n"); 46 | fprintf(stderr, " quality ... 0 to 100\n"); 47 | fprintf(stderr, " src_width ... 640 or 800\n"); 48 | fprintf(stderr, " dst_width ... 176, 220, 320, 360, 384, 640, etc.\n"); 49 | exit(-1); 50 | } 51 | 52 | int main( int argc, char **argv ) 53 | { 54 | NsaReader cSR; 55 | unsigned int nsa_offset = 0; 56 | unsigned long length, offset = 0, buffer_length = 0; 57 | unsigned char *buffer = NULL, *rescaled_buffer = NULL; 58 | unsigned int i, count; 59 | int archive_type = BaseReader::ARCHIVE_TYPE_NSA; 60 | bool enhanced_flag = false; 61 | bool bmp2jpeg_flag = false; 62 | int quality = 75; 63 | FILE *fp; 64 | 65 | argc--; // skip command name 66 | argv++; 67 | while (argc > 4){ 68 | if ( !strcmp( argv[0], "-e" ) ) enhanced_flag = true; 69 | else if ( !strcmp( argv[0], "-j" ) ) bmp2jpeg_flag = true; 70 | else if ( !strcmp( argv[0], "-ns2" ) ) nsa_offset = 1; 71 | else if ( !strcmp( argv[0], "-ns3" ) ) nsa_offset = 2; 72 | else if ( !strcmp( argv[0], "-q" ) ){ 73 | argc--; 74 | argv++; 75 | quality = atoi(argv[0]); 76 | } 77 | argc--; 78 | argv++; 79 | } 80 | if (argc != 4) help(); 81 | if (bmp2jpeg_flag) enhanced_flag = false; 82 | 83 | scale_ratio_lower = atoi(argv[0]); // src width 84 | if (scale_ratio_lower!=640 && scale_ratio_lower!=800) help(); 85 | 86 | scale_ratio_upper = atoi(argv[1]); // dst width 87 | 88 | if ( (fp = fopen( argv[3], "wb" ) ) == NULL ){ 89 | fprintf( stderr, "can't open file %s for writing.\n", argv[3] ); 90 | exit(-1); 91 | } 92 | cSR.openForConvert( argv[2], archive_type, nsa_offset ); 93 | count = cSR.getNumFiles(); 94 | 95 | SarReader::FileInfo sFI; 96 | 97 | for ( i=0 ; i buffer_length ){ 103 | if ( buffer ) delete[] buffer; 104 | buffer = new unsigned char[length]; 105 | buffer_length = length; 106 | } 107 | 108 | sFI.offset = offset; 109 | if ( (strlen( sFI.name ) > 3 && !strcmp( sFI.name + strlen( sFI.name ) - 3, "JPG")) || 110 | (strlen( sFI.name ) > 4 && !strcmp( sFI.name + strlen( sFI.name ) - 4, "JPEG")) ){ 111 | if ( cSR.getFile( sFI.name, buffer ) != length ){ 112 | fprintf( stderr, "file %s can't be retrieved %ld\n", sFI.name, length ); 113 | continue; 114 | } 115 | sFI.length = rescaleJPEG( buffer, length, &rescaled_buffer, quality ); 116 | cSR.putFile( fp, i, sFI.offset, sFI.length, sFI.length, sFI.compression_type, true, rescaled_buffer ); 117 | } 118 | else if ( strlen( sFI.name ) > 3 && !strcmp( sFI.name + strlen( sFI.name ) - 3, "BMP") ){ 119 | if ( cSR.getFile( sFI.name, buffer ) != length ){ 120 | fprintf( stderr, "file %s can't be retrieved %ld\n", sFI.name, length ); 121 | continue; 122 | } 123 | sFI.length = rescaleBMP( buffer, &rescaled_buffer, bmp2jpeg_flag, quality ); 124 | cSR.putFile( fp, i, sFI.offset, sFI.length, sFI.length, enhanced_flag?BaseReader::NBZ_COMPRESSION:sFI.compression_type, true, rescaled_buffer ); 125 | } 126 | else if ( enhanced_flag && strlen( sFI.name ) > 3 && !strcmp( sFI.name + strlen( sFI.name ) - 3, "WAV") ){ 127 | if ( cSR.getFile( sFI.name, buffer ) != length ){ 128 | fprintf( stderr, "file %s can't be retrieved %ld\n", sFI.name, length ); 129 | continue; 130 | } 131 | sFI.length = cSR.putFile( fp, i, sFI.offset, sFI.length, length, BaseReader::NBZ_COMPRESSION, true, buffer ); 132 | } 133 | else{ 134 | cSR.putFile( fp, i, sFI.offset, sFI.length, sFI.original_length, sFI.compression_type, false, buffer ); 135 | } 136 | 137 | offset += sFI.length; 138 | } 139 | cSR.writeHeader( fp, archive_type, nsa_offset ); 140 | 141 | fclose(fp); 142 | 143 | if ( rescaled_buffer ) delete[] rescaled_buffer; 144 | if ( buffer ) delete[] buffer; 145 | 146 | return 0; 147 | } 148 | -------------------------------------------------------------------------------- /nsadec.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * nsadec.cpp - NSA archive decoder 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "NsaReader.h" 31 | 32 | extern int errno; 33 | 34 | int main( int argc, char **argv ) 35 | { 36 | NsaReader cNR; 37 | unsigned int nsa_offset = 0; 38 | unsigned long length; 39 | unsigned char *buffer; 40 | char file_name[256], dir_name[256]; 41 | unsigned int i, j, count; 42 | int archive_type = BaseReader::ARCHIVE_TYPE_NSA; 43 | FILE *fp; 44 | struct stat file_stat; 45 | 46 | if ( argc >= 2 ){ 47 | while ( argc > 2 ){ 48 | if ( !strcmp( argv[1], "-ns2" ) ) nsa_offset = 1; 49 | else if ( !strcmp( argv[1], "-ns3" ) ) nsa_offset = 2; 50 | argc--; 51 | argv++; 52 | } 53 | } 54 | if ( argc != 2 ){ 55 | fprintf( stderr, "Usage: nsadec [-ns2] [-ns3] arc_file\n"); 56 | exit(-1); 57 | } 58 | cNR.openForConvert( argv[1], archive_type, nsa_offset ); 59 | count = cNR.getNumFiles(); 60 | 61 | SarReader::FileInfo sFI; 62 | 63 | for ( i=0 ; i 2 | main(){int ch; while ((ch = getchar()) != EOF) putchar(ch ^ 0x84);} 3 | 4 | -------------------------------------------------------------------------------- /onscripter_main.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * onscripter_main.cpp -- main function of ONScripter 4 | * 5 | * Copyright (c) 2001-2014 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include "ONScripter.h" 25 | #include "version.h" 26 | 27 | ONScripter ons; 28 | 29 | #if defined(IOS) 30 | #import 31 | #import 32 | #import "DataCopier.h" 33 | #import "DataDownloader.h" 34 | #import "ScriptSelector.h" 35 | #import "MoviePlayer.h" 36 | #endif 37 | 38 | #if defined(PSP) 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | PSP_HEAP_SIZE_KB(-1); 45 | 46 | int psp_power_resume_number = 0; 47 | 48 | int exit_callback(int arg1, int arg2, void *common) 49 | { 50 | ons.endCommand(); 51 | sceKernelExitGame(); 52 | return 0; 53 | } 54 | 55 | int power_callback(int unknown, int pwrflags, void *common) 56 | { 57 | if (pwrflags & PSP_POWER_CB_RESUMING) psp_power_resume_number++; 58 | return 0; 59 | } 60 | 61 | int CallbackThread(SceSize args, void *argp) 62 | { 63 | int cbid; 64 | cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); 65 | sceKernelRegisterExitCallback(cbid); 66 | cbid = sceKernelCreateCallback("Power Callback", power_callback, NULL); 67 | scePowerRegisterCallback(0, cbid); 68 | sceKernelSleepThreadCB(); 69 | return 0; 70 | } 71 | 72 | int SetupCallbacks(void) 73 | { 74 | int thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); 75 | if (thid >= 0) sceKernelStartThread(thid, 0, 0); 76 | return thid; 77 | } 78 | #endif 79 | 80 | void optionHelp() 81 | { 82 | printf( "Usage: onscripter [option ...]\n" ); 83 | printf( " --cdaudio\t\tuse CD audio if available\n"); 84 | printf( " --cdnumber no\tchoose the CD-ROM drive number\n"); 85 | printf( " -f, --font file\tset a TTF font file\n"); 86 | printf( " --registry file\tset a registry file\n"); 87 | printf( " --dll file\tset a dll file\n"); 88 | printf( " -r, --root path\tset the root path to the archives\n"); 89 | printf( " --fullscreen\tstart in fullscreen mode\n"); 90 | printf( " --window\t\tstart in windowed mode\n"); 91 | printf( " --force-button-shortcut\tignore useescspc and getenter command\n"); 92 | printf( " --enable-wheeldown-advance\tadvance the text on mouse wheel down\n"); 93 | printf( " --disable-rescale\tdo not rescale the images in the archives\n"); 94 | printf( " --render-font-outline\trender the outline of a text instead of casting a shadow\n"); 95 | printf( " --edit\t\tenable online modification of the volume and variables when 'z' is pressed\n"); 96 | printf( " --key-exe file\tset a file (*.EXE) that includes a key table\n"); 97 | printf( " -h, --help\t\tshow this help and exit\n"); 98 | printf( " -v, --version\t\tshow the version information and exit\n"); 99 | exit(0); 100 | } 101 | 102 | void optionVersion() 103 | { 104 | printf("Written by Ogapee \n\n"); 105 | printf("Copyright (c) 2001-2014 Ogapee.\n"); 106 | printf("This is free software; see the source for copying conditions.\n"); 107 | exit(0); 108 | } 109 | 110 | #ifdef ANDROID 111 | extern "C" 112 | { 113 | #include 114 | 115 | #ifndef SDL_JAVA_PACKAGE_PATH 116 | #error You have to define SDL_JAVA_PACKAGE_PATH to your package path with dots replaced with underscores, for example "com_example_SanAngeles" 117 | #endif 118 | #define JAVA_EXPORT_NAME2(name,package) Java_##package##_##name 119 | #define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package) 120 | #define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH) 121 | 122 | JNIEXPORT jint JNICALL 123 | JAVA_EXPORT_NAME(ONScripter_nativeGetWidth) ( JNIEnv* env, jobject thiz ) 124 | { 125 | return ons.getWidth(); 126 | } 127 | 128 | JNIEXPORT jint JNICALL 129 | JAVA_EXPORT_NAME(ONScripter_nativeGetHeight) ( JNIEnv* env, jobject thiz ) 130 | { 131 | return ons.getHeight(); 132 | } 133 | } 134 | #endif 135 | 136 | #if defined(IOS) 137 | extern "C" void playVideoIOS(const char *filename, bool click_flag, bool loop_flag) 138 | { 139 | NSString *str = [[NSString alloc] initWithUTF8String:filename]; 140 | id obj = [MoviePlayer alloc]; 141 | [[obj init] play:str click:click_flag loop:loop_flag]; 142 | [obj release]; 143 | } 144 | #endif 145 | 146 | #if defined(QWS) || defined(ANDROID) 147 | int SDL_main( int argc, char **argv ) 148 | #elif defined(PSP) 149 | extern "C" int main( int argc, char **argv ) 150 | #else 151 | int main( int argc, char **argv ) 152 | #endif 153 | { 154 | printf("ONScripter version %s(%d.%02d)\n", ONS_VERSION, NSC_VERSION/100, NSC_VERSION%100 ); 155 | 156 | #if defined(PSP) 157 | ons.disableRescale(); 158 | ons.enableButtonShortCut(); 159 | SetupCallbacks(); 160 | #elif defined(WINCE) 161 | char currentDir[256]; 162 | strcpy(currentDir, argv[0]); 163 | char* cptr = currentDir; 164 | int i, len = strlen(currentDir); 165 | for(i=len-1; i>0; i--){ 166 | if(cptr[i] == '\\' || cptr[i] == '/') 167 | break; 168 | } 169 | cptr[i] = '\0'; 170 | ons.setArchivePath(currentDir); 171 | ons.disableRescale(); 172 | ons.enableButtonShortCut(); 173 | #elif defined(ANDROID) 174 | ons.enableButtonShortCut(); 175 | #endif 176 | 177 | #if defined(IOS) 178 | #if defined(HAVE_CONTENTS) 179 | if ([[[DataCopier alloc] init] copy]) exit(-1); 180 | #endif 181 | 182 | // scripts and archives are stored under /Library/Caches 183 | NSArray* cpaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 184 | NSString* cpath = [[cpaths objectAtIndex:0] stringByAppendingPathComponent:@"ONS"]; 185 | char filename[256]; 186 | strcpy(filename, [cpath UTF8String]); 187 | ons.setArchivePath(filename); 188 | 189 | // output files are stored under /Documents 190 | NSArray* dpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 191 | NSString* dpath = [[dpaths objectAtIndex:0] stringByAppendingPathComponent:@"ONS"]; 192 | strcpy(filename, [dpath UTF8String]); 193 | ons.setSaveDir(filename); 194 | 195 | #if defined(ZIP_URL) 196 | if ([[[DataDownloader alloc] init] download]) exit(-1); 197 | #endif 198 | 199 | #if defined(USE_SELECTOR) 200 | // scripts and archives are stored under /Library/Caches 201 | cpath = [[[ScriptSelector alloc] initWithStyle:UITableViewStylePlain] select]; 202 | strcpy(filename, [cpath UTF8String]); 203 | ons.setArchivePath(filename); 204 | 205 | // output files are stored under /Documents 206 | dpath = [[dpaths objectAtIndex:0] stringByAppendingPathComponent:[cpath lastPathComponent]]; 207 | strcpy(filename, [dpath UTF8String]); 208 | ons.setSaveDir(filename); 209 | #endif 210 | 211 | #if defined(RENDER_FONT_OUTLINE) 212 | ons.renderFontOutline(); 213 | #endif 214 | #endif 215 | 216 | // ---------------------------------------- 217 | // Parse options 218 | argv++; 219 | while( argc > 1 ){ 220 | if ( argv[0][0] == '-' ){ 221 | if ( !strcmp( argv[0]+1, "h" ) || !strcmp( argv[0]+1, "-help" ) ){ 222 | optionHelp(); 223 | } 224 | else if ( !strcmp( argv[0]+1, "v" ) || !strcmp( argv[0]+1, "-version" ) ){ 225 | optionVersion(); 226 | } 227 | else if ( !strcmp( argv[0]+1, "-cdaudio" ) ){ 228 | ons.enableCDAudio(); 229 | } 230 | else if ( !strcmp( argv[0]+1, "-cdnumber" ) ){ 231 | argc--; 232 | argv++; 233 | ons.setCDNumber(atoi(argv[0])); 234 | } 235 | else if ( !strcmp( argv[0]+1, "f" ) || !strcmp( argv[0]+1, "-font" ) ){ 236 | argc--; 237 | argv++; 238 | ons.setFontFile(argv[0]); 239 | } 240 | else if ( !strcmp( argv[0]+1, "-registry" ) ){ 241 | argc--; 242 | argv++; 243 | ons.setRegistryFile(argv[0]); 244 | } 245 | else if ( !strcmp( argv[0]+1, "-dll" ) ){ 246 | argc--; 247 | argv++; 248 | ons.setDLLFile(argv[0]); 249 | } 250 | else if ( !strcmp( argv[0]+1, "r" ) || !strcmp( argv[0]+1, "-root" ) ){ 251 | argc--; 252 | argv++; 253 | ons.setArchivePath(argv[0]); 254 | } 255 | else if ( !strcmp( argv[0]+1, "-fullscreen" ) ){ 256 | ons.setFullscreenMode(); 257 | } 258 | else if ( !strcmp( argv[0]+1, "-window" ) ){ 259 | ons.setWindowMode(); 260 | } 261 | else if ( !strcmp( argv[0]+1, "-force-button-shortcut" ) ){ 262 | ons.enableButtonShortCut(); 263 | } 264 | else if ( !strcmp( argv[0]+1, "-enable-wheeldown-advance" ) ){ 265 | ons.enableWheelDownAdvance(); 266 | } 267 | else if ( !strcmp( argv[0]+1, "-disable-rescale" ) ){ 268 | ons.disableRescale(); 269 | } 270 | else if ( !strcmp( argv[0]+1, "-render-font-outline" ) ){ 271 | ons.renderFontOutline(); 272 | } 273 | else if ( !strcmp( argv[0]+1, "-edit" ) ){ 274 | ons.enableEdit(); 275 | } 276 | else if ( !strcmp( argv[0]+1, "-key-exe" ) ){ 277 | argc--; 278 | argv++; 279 | ons.setKeyEXE(argv[0]); 280 | } 281 | #if defined(ANDROID) 282 | else if ( !strcmp( argv[0]+1, "-open-only" ) ){ 283 | argc--; 284 | argv++; 285 | if (ons.openScript()) exit(-1); 286 | return 0; 287 | } 288 | #endif 289 | else{ 290 | printf(" unknown option %s\n", argv[0] ); 291 | } 292 | } 293 | else{ 294 | optionHelp(); 295 | } 296 | argc--; 297 | argv++; 298 | } 299 | 300 | // ---------------------------------------- 301 | // Run ONScripter 302 | 303 | if (ons.openScript()) exit(-1); 304 | if (ons.init()) exit(-1); 305 | ons.executeLabel(); 306 | 307 | exit(0); 308 | } 309 | -------------------------------------------------------------------------------- /resize_image.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * resize_image.cpp - resize image using smoothing and resampling 4 | * 5 | * Copyright (c) 2001-2012 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | static unsigned long *pixel_accum=NULL; 28 | static unsigned long *pixel_accum_num=NULL; 29 | static int pixel_accum_size=0; 30 | static unsigned long tmp_acc[4]; 31 | static unsigned long tmp_acc_num[4]; 32 | 33 | static void calcWeightedSumColumnInit(unsigned char **src, 34 | int interpolation_height, 35 | int image_width, int image_height, int image_pixel_width, int byte_per_pixel) 36 | { 37 | int y_end = -interpolation_height/2+interpolation_height; 38 | 39 | memset(pixel_accum, 0, image_width*byte_per_pixel*sizeof(unsigned long)); 40 | memset(pixel_accum_num, 0, image_width*byte_per_pixel*sizeof(unsigned long)); 41 | for (int s=0 ; s= image_height) break; 44 | unsigned long *pa = pixel_accum + image_width*s; 45 | unsigned long *pan = pixel_accum_num + image_width*s; 46 | unsigned char *p = *src+image_pixel_width*i+s; 47 | for (int j=image_width ; j!=0 ; j--, p+=byte_per_pixel){ 48 | *pa++ += *p; 49 | (*pan++)++; 50 | } 51 | } 52 | } 53 | } 54 | 55 | static void calcWeightedSumColumn(unsigned char **src, int y, 56 | int interpolation_height, 57 | int image_width, int image_height, int image_pixel_width, int byte_per_pixel) 58 | { 59 | int y_start = y-interpolation_height/2; 60 | int y_end = y-interpolation_height/2+interpolation_height; 61 | 62 | for (int s=0 ; s=0 && (y_start-1)=0 && (y_end-1)=0 && (x_start-1)=0 && (x_end-1) 1 ) mx = 1; 120 | else mx = 0; 121 | if ( src_height > 1 ) my = 1; 122 | else my = 0; 123 | 124 | int interpolation_width = src_width / dst_width; 125 | if ( interpolation_width == 0 ) interpolation_width = 1; 126 | int interpolation_height = src_height / dst_height; 127 | if ( interpolation_height == 0 ) interpolation_height = 1; 128 | 129 | if (pixel_accum_size < src_width*byte_per_pixel){ 130 | pixel_accum_size = src_width*byte_per_pixel; 131 | if (pixel_accum) delete[] pixel_accum; 132 | pixel_accum = new unsigned long[pixel_accum_size]; 133 | if (pixel_accum_num) delete[] pixel_accum_num; 134 | pixel_accum_num = new unsigned long[pixel_accum_size]; 135 | } 136 | /* smoothing */ 137 | if ( byte_per_pixel >= 3 ){ 138 | calcWeightedSumColumnInit(&src_buf, interpolation_height, 139 | src_width, src_height, src_total_width, byte_per_pixel ); 140 | for ( i=0 ; i= src_width) break; 148 | tmp_acc[s] += pixel_accum[src_width*s+j]; 149 | tmp_acc_num[s] += pixel_accum_num[src_width*s+j]; 150 | } 151 | } 152 | 153 | for ( j=0 ; j>= 3; 172 | for ( j=0 ; j>= 3; 176 | 177 | int k = tmp_total_width * y + x * byte_per_pixel; 178 | 179 | if (palette_flag){ //assuming byte_per_pixel=1 180 | *dst_buf++ = tmp_buffer[k]; 181 | } 182 | else{ 183 | for ( s=0 ; s>6); 190 | } 191 | } 192 | } 193 | for ( j=0 ; j 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "SarReader.h" 30 | 31 | extern int scale_ratio_upper; 32 | extern int scale_ratio_lower; 33 | 34 | extern size_t rescaleJPEG( unsigned char *original_buffer, size_t length, unsigned char **rescaled_buffer, 35 | int quality ); 36 | extern size_t rescaleBMP( unsigned char *original_buffer, unsigned char **rescaled_buffer, 37 | bool output_jpeg_flag, int quality ); 38 | 39 | #ifdef main 40 | #undef main 41 | #endif 42 | 43 | void help() 44 | { 45 | fprintf(stderr, "Usage: sarconv [-j] [-q quality] src_width dst_width src_archive_file dst_archive_file\n"); 46 | fprintf(stderr, " quality ... 0 to 100\n"); 47 | fprintf(stderr, " src_width ... 640 or 800\n"); 48 | fprintf(stderr, " dst_width ... 176, 220, 320, 360, 384, 640, etc.\n"); 49 | exit(-1); 50 | } 51 | 52 | int main( int argc, char **argv ) 53 | { 54 | SarReader cSR; 55 | unsigned long length, offset = 0, buffer_length = 0; 56 | unsigned char *buffer = NULL, *rescaled_buffer = NULL; 57 | unsigned int i, count; 58 | bool bmp2jpeg_flag = false; 59 | int quality = 75; 60 | FILE *fp; 61 | 62 | argc--; // skip command name 63 | argv++; 64 | while (argc > 4){ 65 | if ( !strcmp( argv[0], "-j" ) ) bmp2jpeg_flag = true; 66 | else if ( !strcmp( argv[0], "-q" ) ){ 67 | argc--; 68 | argv++; 69 | quality = atoi(argv[0]); 70 | } 71 | argc--; 72 | argv++; 73 | } 74 | if (argc != 4) help(); 75 | 76 | scale_ratio_lower = atoi(argv[0]); // src width 77 | if (scale_ratio_lower!=640 && scale_ratio_lower!=800) help(); 78 | 79 | scale_ratio_upper = atoi(argv[1]); // dst width 80 | 81 | if ( (fp = fopen( argv[3], "wb" ) ) == NULL ){ 82 | fprintf( stderr, "can't open file %s for writing.\n", argv[3] ); 83 | exit(-1); 84 | } 85 | if (cSR.open( argv[2] ) != 0){ 86 | fprintf( stderr, "can't open file %s\n", argv[2] ); 87 | exit(-1); 88 | } 89 | count = cSR.getNumFiles(); 90 | 91 | SarReader::FileInfo sFI; 92 | 93 | for ( i=0 ; i buffer_length ){ 99 | if ( buffer ) delete[] buffer; 100 | buffer = new unsigned char[length]; 101 | buffer_length = length; 102 | } 103 | 104 | sFI.offset = offset; 105 | if ( (strlen( sFI.name ) > 3 && !strcmp( sFI.name + strlen( sFI.name ) - 3, "JPG")) || 106 | (strlen( sFI.name ) > 4 && !strcmp( sFI.name + strlen( sFI.name ) - 4, "JPEG")) ){ 107 | if ( cSR.getFile( sFI.name, buffer ) != length ){ 108 | fprintf( stderr, "file %s can't be retrieved %ld\n", sFI.name, length ); 109 | continue; 110 | } 111 | sFI.length = rescaleJPEG( buffer, length, &rescaled_buffer, quality ); 112 | cSR.putFile( fp, i, sFI.offset, sFI.length, sFI.length, true, rescaled_buffer ); 113 | } 114 | else if ( strlen( sFI.name ) > 3 && !strcmp( sFI.name + strlen( sFI.name ) - 3, "BMP") ){ 115 | if ( cSR.getFile( sFI.name, buffer ) != length ){ 116 | fprintf( stderr, "file %s can't be retrieved %ld\n", sFI.name, length ); 117 | continue; 118 | } 119 | sFI.length = rescaleBMP( buffer, &rescaled_buffer, bmp2jpeg_flag, quality ); 120 | cSR.putFile( fp, i, sFI.offset, sFI.length, sFI.length, true, rescaled_buffer ); 121 | } 122 | else{ 123 | cSR.putFile( fp, i, sFI.offset, sFI.length, sFI.original_length, false, buffer ); 124 | } 125 | 126 | offset += sFI.length; 127 | } 128 | cSR.writeHeader( fp ); 129 | 130 | fclose(fp); 131 | 132 | if ( rescaled_buffer ) delete[] rescaled_buffer; 133 | if ( buffer ) delete[] buffer; 134 | 135 | return 0; 136 | } 137 | -------------------------------------------------------------------------------- /sardec.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- 2 | * 3 | * sardec.cpp - SAR archive decoder 4 | * 5 | * Copyright (c) 2001-2004 Ogapee. All rights reserved. 6 | * 7 | * ogapee@aqua.dti2.ne.jp 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "SarReader.h" 31 | 32 | extern int errno; 33 | 34 | int main( int argc, char **argv ) 35 | { 36 | SarReader cSR; 37 | unsigned long length, buffer_length = 0; 38 | unsigned char *buffer = NULL; 39 | char file_name[256], dir_name[256]; 40 | unsigned int i, j, count; 41 | FILE *fp; 42 | struct stat file_stat; 43 | 44 | if ( argc != 2 ){ 45 | fprintf( stderr, "Usage: sardec arc_file\n"); 46 | exit(-1); 47 | } 48 | if (cSR.open( argv[1] ) != 0){ 49 | fprintf( stderr, "can't open file %s\n", argv[1] ); 50 | exit(-1); 51 | } 52 | count = cSR.getNumFiles(); 53 | 54 | SarReader::FileInfo sFI; 55 | 56 | for ( i=0 ; i buffer_length ){ 62 | if ( buffer ) delete[] buffer; 63 | buffer = new unsigned char[length]; 64 | buffer_length = length; 65 | } 66 | if ( cSR.getFile( sFI.name, buffer ) != length ){ 67 | fprintf( stderr, "file %s can't be retrieved\n", sFI.name ); 68 | continue; 69 | } 70 | 71 | strcpy( file_name, sFI.name ); 72 | for ( j=0 ; j 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "AVIWrapper.h" 31 | 32 | #define DEFAULT_AUDIOBUF 4096 33 | #define ONS_MIX_CHANNELS 50 34 | 35 | int main( int argc, char **argv ) 36 | { 37 | if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO ) < 0 ){ 38 | fprintf( stderr, "Couldn't initialize SDL: %s\n", SDL_GetError() ); 39 | exit(-1); 40 | } 41 | 42 | AVIWrapper avi; 43 | if ( avi.init( argv[1], true ) ) exit(-1); 44 | SDL_Surface *screen_surface = SDL_SetVideoMode( avi.getWidth(), avi.getHeight(), 32, SDL_SWSURFACE ); 45 | if ( avi.initAV( screen_surface, true ) ) exit(-1); 46 | avi.play( true ); 47 | 48 | exit(0); 49 | } 50 | -------------------------------------------------------------------------------- /version.h: -------------------------------------------------------------------------------- 1 | #define ONS_VERSION "20140817" 2 | #define NSC_VERSION 296 3 | -------------------------------------------------------------------------------- /www/ogapee.css: -------------------------------------------------------------------------------- 1 | /* 2 | * CSS resource file for ONScripter web page 3 | * Copyright (c) 2001-2010 Ogapee. All rights reserved. 4 | * ogapee@aqua.dti2.ne.jp 5 | */ 6 | 7 | a { text-decoration: none; } 8 | a:link { color: #000080; } 9 | a:visited { color: #800000; } 10 | a:active{ color: #FF0000; text-decoration: underline; } 11 | a:hover{ background-color: #ccffcc; } 12 | 13 | body{ 14 | text-align: left; 15 | font-size: 100%; 16 | line-height: 1.4; 17 | color: black; 18 | background-color: gray; 19 | } 20 | 21 | p{ 22 | margin: 10px; 23 | text-indent: 1em; 24 | } 25 | 26 | p.noindent{ 27 | margin: 10px; 28 | text-indent: 0em; 29 | } 30 | 31 | /* -------------------- */ 32 | /* general page */ 33 | 34 | #body{ 35 | position: absolute; 36 | left: 50%; 37 | width: 800px; 38 | margin-left: -400px; 39 | background-color: white; 40 | } 41 | 42 | #header{ 43 | text-align: left; 44 | margin: 5px; 45 | padding: 5px; 46 | border-bottom: solid 1px #888; 47 | background-image: url(ons.png); 48 | background-repeat: no-repeat; 49 | color: #112244; 50 | /*background-color: #cc4400;*/ 51 | /*background-color: #cc0044;*/ 52 | /*background-color: #44cc00;*/ 53 | /*background-color: #448800;*/ 54 | background-color: white; 55 | } 56 | 57 | #header h1{ 58 | font-size: 167%; 59 | text-align: center; 60 | } 61 | 62 | /*#header a {background-color: #ddffdd; }*/ 63 | #header a:link{ color: #4444ff; } 64 | #header a:visited{ color: #ff4444; } 65 | #header a:active{ color: #cc8888; text-decoration: underline; } 66 | #header a:hover{ background-color: #ff8844; } 67 | 68 | /* -------------------- */ 69 | /* toc */ 70 | #toc-container{ 71 | float: left; 72 | width: 180px; 73 | font-size: 90%; 74 | } 75 | 76 | #toc{ 77 | padding: 5px; 78 | text-align: left; 79 | } 80 | 81 | #toc h3{ 82 | margin: 0px; 83 | padding: 5px; 84 | font-size: 100%; 85 | text-align: center; 86 | border-top: solid 1px #eef; 87 | border-bottom: solid 1px #eef; 88 | background-color: #f5f5ff; 89 | } 90 | 91 | #toc ul{ 92 | margin: 0px; 93 | margin-bottom: 15px; 94 | padding: 5px; 95 | text-align: left; 96 | list-style: none; 97 | } 98 | 99 | #toc ul li{ 100 | margin: 0px; 101 | padding-bottom:15px; 102 | } 103 | 104 | #toc ul li a{ 105 | display: block; 106 | border-bottom: dotted 1px #888; 107 | padding: 0px; 108 | } 109 | 110 | #toc ul li ul{ 111 | margin: 0px; 112 | margin-left: 1em; 113 | margin-bottom: 1em; 114 | padding: 0px; 115 | } 116 | 117 | #toc ul li ul li{ 118 | display: list-item; 119 | margin: 0px; 120 | padding: 0px; 121 | padding-bottom: 5px; 122 | border-bottom: solid 1px #ffffff; 123 | } 124 | 125 | #toc ul li ul li a{ 126 | border: none; 127 | } 128 | 129 | /* -------------------- */ 130 | /* main page */ 131 | #main-container{ 132 | margin-left: 180px; 133 | } 134 | 135 | #main{ 136 | text-align: left; 137 | font-size: 100%; 138 | } 139 | 140 | #main h2{ 141 | margin: 0px; 142 | padding: 5px; 143 | /*border: solid 1px #0000ff;*/ 144 | font-family: sans-selif; 145 | } 146 | 147 | #main .content{ 148 | margin: 0px 0px 20px; 149 | padding: 0px; 150 | /*border-bottom: solid 1px black;*/ 151 | } 152 | 153 | #main .content h2{ 154 | margin: 0px; 155 | margin-bottom: 5px; 156 | padding: 15px 30px; 157 | font-size: 110%; 158 | font-weight: bold; 159 | color: black; 160 | border-top: solid 1px #eef; 161 | border-bottom: solid 1px #eef; 162 | background-color: #f5f5ff; 163 | } 164 | 165 | #main .content h3{ 166 | margin: 5px; 167 | margin-top: 15px; 168 | padding: 0px; 169 | padding-left: 10px; 170 | font-size: 100%; 171 | border-left: solid 5px #0000aa; 172 | border-bottom: dotted 1px gray; 173 | } 174 | 175 | #main .content h4{ 176 | margin: 5px; 177 | text-decoration: underline; 178 | } 179 | 180 | .content dl{ 181 | margin: 0px; 182 | padding: 0px 5px 0px 10px; 183 | } 184 | 185 | .sub-content{ 186 | margin: 5pt; 187 | padding: 0px; 188 | /*border-top: dashed 1px gray;*/ 189 | } 190 | 191 | /* -------------------- */ 192 | /* diary page */ 193 | #diary-container{ 194 | margin-left: 180px; 195 | } 196 | 197 | #diary{ 198 | text-align: left; 199 | font-size: 100%; 200 | } 201 | 202 | #diary h2{ 203 | margin: 0px; 204 | padding: 5px; 205 | text-align: center; 206 | /*border: solid 1px #0000ff;*/ 207 | } 208 | 209 | #diary .diary-day{ 210 | margin: 5px; 211 | margin-bottom: 25px; 212 | padding: 0px; 213 | font-size: 100%; 214 | /*border-top: dashed 1px gray;*/ 215 | } 216 | 217 | #diary .diary-day h3{ 218 | display: block; 219 | margin: 5px; 220 | padding: 0px; 221 | padding-left: 5px; 222 | /*border-left: solid 5px #0000aa;*/ 223 | border-bottom: dashed 1px gray; 224 | } 225 | 226 | #diary .diary-day h4{ 227 | margin: 5px; 228 | text-decoration: underline; 229 | } 230 | 231 | /* -------------------- */ 232 | /* misc */ 233 | table { 234 | text-align: left; 235 | color: black; 236 | background-color: #fcfcff; 237 | margin: 5px; 238 | margin-bottom: 10pt; 239 | padding: 2pt; 240 | } 241 | 242 | th { 243 | padding: 2pt; 244 | border: solid 1px #888; 245 | font-weight: bold; 246 | color: black; 247 | background: white; 248 | text-align: center; 249 | } 250 | 251 | td { 252 | padding: 2pt; 253 | font-weight: normal; 254 | color: black; 255 | border: 0pt; 256 | border-bottom: 1px solid #888; 257 | text-indent: 1em; 258 | } 259 | 260 | td.span { 261 | border-bottom: 1pt dotted; 262 | } 263 | 264 | hr { 265 | width: 80%; 266 | text-align: center; 267 | } 268 | 269 | pre { 270 | white-space: -moz-pre-wrap; /* Mozilla */ 271 | white-space: -pre-wrap; /* Opera 4-6 */ 272 | white-space: -o-pre-wrap; /* Opera 7 */ 273 | white-space: pre-wrap; /* CSS3 */ 274 | word-wrap: break-word; /* IE 5.5+ */ 275 | margin: 0.5em; 276 | padding: 0.5em; 277 | color: black; 278 | background: #f5f5f5; 279 | text-indent: 0; 280 | border-width: 1pt 1pt 1pt 1pt; 281 | border-color: #888888; 282 | border-style: solid; 283 | font-family: monospace; 284 | } 285 | 286 | /* -------------------- */ 287 | /* footer */ 288 | 289 | #footer{ 290 | clear: both; 291 | text-align: center; 292 | margin: 5px; 293 | padding: 5px; 294 | border-top: solid 1px #888; 295 | } 296 | 297 | div.figure{ 298 | /*float: right;*/ 299 | width: 80%; 300 | border: thin silver solid; 301 | margin: 0.2em; 302 | padding: 0.2em; 303 | } 304 | 305 | div.figure p{ 306 | text-align: center; 307 | text-indent: 0; 308 | } -------------------------------------------------------------------------------- /www/onscripter.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LasmGratel/onscripter-jh/fe5e7d94cb12c1ec48ac423b83322d48ac430549/www/onscripter.html --------------------------------------------------------------------------------