void checkFile(const char *filename) { printf("Checking for %s...", filename); if (fileexists(filename)) { printf("[ok]\n"); } else { printf("[no]\n"); std::string fetcherfn = ""; if ((fetcherfn=yatc_findfile("tdffetcher"))=="") { if ((fetcherfn=yatc_findfile("tdffetcher.exe"))=="") { std::string forreplace; #ifndef WIN32 forreplace = gettext("Loading the data file '$$FILENAME$$' has failed.\n" "Please place '$$FILENAME$$' in the same folder as $$PRODUCTSHORT$$.\n" "If you are a Debian user, you may have forgotten to install\n" "the 'tibia-data' or 'yatc-data' package."); #else forreplace = gettext("Loading the data file '$$FILENAME$$' has failed.\n" "Please place '$$FILENAME$$' in the same folder as $$PRODUCTSHORT$$.\n"); #endif forreplace = str_replace("$$FILENAME$$", filename, forreplace); forreplace = str_replace("$$PRODUCTSHORT$$", PRODUCTSHORT, forreplace); NativeGUIError(forreplace.c_str(), str_replace("$$PRODUCTSHORT$$", PRODUCTSHORT, gettext("$$PRODUCTSHORT$$ Fatal Error")).c_str()); printf("EXITING\n"); exit(1); } } std::string forreplace; forreplace = gettext("You are missing '$$FILENAME$$'.\n" "We will launch Tibia Data File Fetcher which should automatically install\n" "data files required for $$PRODUCTSHORT$$.\n" "\n" "You will have to manually restart $$PRODUCTSHORT$$ afterwards.\n" "\n"); #ifndef WIN32 forreplace += gettext("If you are a Debian user, you may have forgotten to install\n" "the 'tibia-data' or 'yatc-data' package."); #endif forreplace = str_replace("$$FILENAME$$", filename, forreplace); forreplace = str_replace("$$PRODUCTSHORT$$", PRODUCTSHORT, forreplace); NativeGUIError(forreplace.c_str(), str_replace("$$PRODUCTSHORT$$", PRODUCTSHORT, gettext("$$PRODUCTSHORT$$ Fatal Error")).c_str()); // hack to make the cmdline box disappear if (fetcherfn == "tdffetcher.exe") fetcherfn = "start tdffetcher.exe"; int dummy = system(fetcherfn.c_str()); dummy = 0; exit(1); } }
void Engine::initFont(glictFont **fnt, const char *fontname) { *fnt = glictCreateFont(fontname); if(!*fnt){ std::stringstream s; s << "Cannot load font '" << fontname << "'."; NativeGUIError(s.str().c_str(), "Error loading font"); } (*fnt)->SetRenderFunc(Engine::font_render); (*fnt)->SetSizeFunc(Engine::font_size); #if (GLICT_APIREV >= 85) (*fnt)->SetColorFunc(Engine::font_color); #else #warning GLICT font coloring is not available. Upgrade to GLICT APIREV 85+. #endif }
GM_Debug::GM_Debug() { desktop.SetWidth(options.w); desktop.SetHeight(options.h); desktop.ResetTransformations(); desktop.AddObject(&btnButton); btnButton.SetPos(100,100); btnButton.SetWidth(128); btnButton.SetHeight(16); btnButton.SetCaption("Button"); btnButton.SetBGColor(.75,.75,.75,1); btnButton.SetOnClick(GM_Debug::ButtonOnClick); desktop.AddObject(&btnExit); btnExit.SetPos(100,116); btnExit.SetWidth(128); btnExit.SetHeight(16); btnExit.SetCaption("Exit"); btnExit.SetBGColor(1,0,0,1); btnExit.SetOnClick(GM_Debug::ExitOnClick); desktop.AddObject(&txtSprite); txtSprite.SetPos(100,132); txtSprite.SetWidth(128); txtSprite.SetHeight(16); txtSprite.SetCaption("200"); desktop.AddObject(&txtItem); txtItem.SetPos(100,148); txtItem.SetWidth(128); txtItem.SetHeight(16); txtItem.SetCaption("100"); desktop.AddObject(&btnUpdate); btnUpdate.SetPos(100,164); btnUpdate.SetWidth(128); btnUpdate.SetHeight(16); btnUpdate.SetCaption("Update gfx"); btnUpdate.SetBGColor(1,0,0,1); btnUpdate.SetOnClick(GM_Debug::UpdateOnClick); desktop.AddObject(&txtLocX); desktop.AddObject(&txtLocY); desktop.AddObject(&txtLocZ); txtLocX.SetWidth(50); txtLocY.SetWidth(50); txtLocZ.SetWidth(50); txtLocX.SetCaption("32600"); txtLocY.SetCaption("31750"); txtLocZ.SetCaption("7"); txtLocX.SetHeight(16); txtLocY.SetHeight(16); txtLocZ.SetHeight(16); txtLocX.SetPos(50,190); txtLocY.SetPos(100,190); txtLocZ.SetPos(150,190); desktop.AddObject(&btnUpdateMap); btnUpdateMap.SetPos(200,190); btnUpdateMap.SetHeight(16); btnUpdateMap.SetWidth(120); btnUpdateMap.SetCaption("Update map"); btnUpdateMap.SetOnClick(GM_Debug::UpdateMapOnClick); desktop.AddObject(grid.getGrid()); grid.getGrid()->SetPos(0, 0); grid.setRows(3); grid.setItemSize(100,20); grid.setPadding(5,5); grid.addItem("Hello world", NULL, NULL); grid.addItem("Testing grid", NULL, NULL); grid.addItem("How about this", NULL, NULL); grid.addItem("This rox", NULL, NULL); grid.addItem("Sure?", NULL, NULL); grid.setOnClick(cb3); #ifdef GMDEBUG_STACKPANEL_TEST desktop.AddObject(&yatcstackpanel); yatcstackpanel.SetPos(400,100); yatcstackpanel.SetHeight(200); yatcstackpanel.SetWidth(100); yatcstackpanel.SetBGActiveness(false); for (int i = 0; i < YSPWINDOWS; i++) { std::stringstream s; s << "yspwTest[" << i << "]"; yspwTest[i].SetHeight(15); yspwTest[i].SetCaption(s.str().c_str()); yatcstackpanel.AddObject(&yspwTest[i]); } #endif outfit = new winOutfit_t; desktop.AddObject(&outfit->window); Outfit_t outfitcurr; std::list<AvailOutfit_t> olist; AvailOutfit_t avail; avail.name = "Citizen"; outfitcurr.m_looktype = avail.id = 128; outfitcurr.m_addons = avail.addons = 0; outfitcurr.m_lookhead = 50; outfitcurr.m_lookbody = 60; outfitcurr.m_looklegs = 70; outfitcurr.m_lookfeet = 80; outfitcurr.m_lookitem = 0; olist.push_back(avail); avail.name = "Another One"; avail.id = 129; avail.addons = 0; olist.push_back(avail); outfit->openSelf(outfitcurr,olist); popup = NULL; killpopup = false; map[0] = map[1] = map[2] = map[3] = NULL; mapcount = 0; mapw = 256; maph = 256; if(g_engine){ background = g_engine->createSprite("Tibia.pic", 0); spr = g_engine->createSprite("Tibia.spr", 200); //thing = new ItemUI(6401, 1); thing = NULL; //background->addColor(.5, 1., 1.); } else{ // i think that if g_engine does not exist, we might as well crash. what do you think, guys? ivucica NativeGUIError("Somehow, engine managed to not initialize.", PRODUCTSHORT " Fatal Error"); exit(1); } printf("2\n"); #ifdef SDLTTF_EXPERIMENT { int ptsize=11; char fontname[]="arial.ttf"; TTF_Init(); font = TTF_OpenFont(fontname,ptsize); if ( font == NULL ) { fprintf(stderr, "Couldn't load %d pt font from %s: %s\n", ptsize, fontname, SDL_GetError()); } int renderstyle=0; renderstyle |= TTF_STYLE_BOLD; TTF_SetFontStyle(font, renderstyle); } #endif }
/// \brief Main program function /// /// This function does very little on its own. It manages some output to /// player's console, directs subsystems to initialize themselves and makes /// choice of rendering engine. Then it runs the main game loop, processing /// events and sending them further into the game. int main(int argc, char *argv[]) { #if !defined(WIN32) && !defined(__APPLE__) #ifdef _GLIBCXX_DEBUG /*#if __WORDSIZE != 64*/ /* Install our signal handler */ struct sigaction sa; sa.sa_sigaction = /*(void *)*/crashhndl; sigemptyset (&sa.sa_mask); sa.sa_flags = SA_RESTART | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGFPE, &sa, NULL); /*#endif*/ #endif #endif #ifdef WIN32 WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD( 2, 2 ); if(WSAStartup(wVersionRequested, &wsaData) != 0){ DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Winsock startup failed!!"); return -1; } if((LOBYTE(wsaData.wVersion) != 2) || (HIBYTE(wsaData.wVersion) != 2)){ WSACleanup( ); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "No Winsock 2.2 found!"); return -1; } #endif //setenv("SDL_VIDEODRIVER", "aalib", 0); //setenv("AAOPTS","-width 200 -height 70 -dim -reverse -bold -normal -boldfont -eight -extended ",0); //setenv("AAFont","-*-fixed-bold-*-*-*-*-55-*-*-*-*-*-*",0); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, PRODUCTLONG "\n"); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "================================\n"); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "version " PRODUCTVERSION "\n"); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "compiled on " __DATE__ " " __TIME__ "\n"); #ifdef BUILDVERSION DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "build %s\n", BUILDVERSION); #endif DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, " This is free software: you are free to change and redistribute it.\n" " There is NO WARRANTY, to the extent permitted by law. \n" " Review LICENSE in " PRODUCTSHORT " distribution for details.\n"); yatc_fopen_init(argv[0]); options.Load(); MAXFPS = options.maxfps; #if HAVE_LIBINTL_H // set up i18n stuff if(options.lang.size()) { std::string l("LANG="); l+=options.lang; putenv((char*)l.c_str()); } setlocale( LC_ALL, "");//options.lang.c_str() ); setlocale( LC_NUMERIC, "C"); #if !BAZEL_BUILD bindtextdomain( "yatc", "./translations" ); #else bindtextdomain( "yatc", (yatc_path_to_binary() + "yatc.runfiles/yatc/translations").c_str()); #endif textdomain( "yatc" ); bind_textdomain_codeset("yatc","windows-1252"); #endif DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Checking graphics files existence...\n"); checkFiles(); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "All graphics files were found.\n"); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Initializing windowing...\n"); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0){ std::stringstream out; out << "Couldn't initialize SDL: " << SDL_GetError() << std::endl; DEBUGPRINT(DEBUGPRINT_ERROR, DEBUGPRINT_LEVEL_OBLIGATORY, out.str().c_str()); NativeGUIError(out.str().c_str(), PRODUCTSHORT " Fatal Error"); exit(1); } // We are no longer dependant on .dat for this! // ivucica asks: nate, not dependant for what? why is this removed? // because of .ico? disagree. DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Loading data...\n"); if(!Objects::getInstance()->loadDat("Tibia.dat")){ DEBUGPRINT(DEBUGPRINT_ERROR, DEBUGPRINT_LEVEL_OBLIGATORY, gettext("Loading data file failed!")); std::string forreplace = gettext("Loading the data file '$$FILENAME$$' has failed.\nPlease place '$$FILENAME$$' in the same folder as $$PRODUCTSHORT$$.\n"); forreplace = str_replace("$$FILENAME$$", "Tibia.dat", forreplace); forreplace = str_replace("$$PRODUCTSHORT$$", PRODUCTSHORT, forreplace); NativeGUIError(forreplace.c_str(), str_replace("$$PRODUCTSHORT$$", PRODUCTSHORT, gettext("$$PRODUCTSHORT$$ Fatal Error")).c_str()); exit(1); } setIcon(); // must be called prior to first call to SDL_SetVideoMode() (currently done in engine) SDL_EnableKeyRepeat(200, 50); SDL_EnableUNICODE(1); try{ g_engine = NULL; // set to null, in case anything that happens inside engine constructor wants to know we're just constructing switch(options.engine){ #ifdef USE_OPENGL case ENGINE_OPENGL: g_engine = new EngineGL; break; #endif default: DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_WARNING, "Unknown engine was selected. Falling back to SDL."); options.engine = ENGINE_SDL; case ENGINE_SDL: g_engine = new EngineSDL; break; } if(!g_engine->isSupported()){ DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_WARNING, "The selected graphics engine is not supported. Falling back to SDL."); delete g_engine; g_engine = NULL; // set to null, in case anything that happens inside engine constructor wants to know we're just constructing options.engine = ENGINE_SDL; g_engine = new EngineSDL; } // NOTE (nfries88): Make sure the window is sized as per the options int w = MAX(options.w, 656); int h = MAX(options.h, 352+options.consoleh); g_engine->doResize(w, h); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Loading skin...\n"); g_skin.loadSkin(); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Skin has been loaded\n"); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Constructing gamemode...\n"); resetDefaultCursor(); if (argc == 1) { g_game = new GM_MainMenu(); //g_game = new GM_Debug(); // ivucica: this is for testing -- choice should be a cmd line option } else { g_game = new GM_MainMenu(); ProtocolGame* protocol = ProtocolConfig::createGameProtocol(854,"","","",false); g_connection = new ConnectionReplay(argv[1], protocol); if (argc==3) { sscanf(argv[2], "%f", &g_replayspeed); } } DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Initializing framerate manager...\n"); SDL_initFramerate(&g_fpsmgr); SDL_setFramerate(&g_fpsmgr,MAXFPS); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Running\n"); g_running = true; #ifdef WIN32 SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); #endif SDL_Event event; while(g_running){ //g_engine->fpsMutexLock(); //int beginticks = SDL_GetTicks(); g_engine->performFpsCalc(); //first process sdl events while(SDL_PollEvent(&event)){ switch (event.type){ case SDL_VIDEORESIZE: g_engine->doResize(event.resize.w, event.resize.h); g_game->doResize(event.resize.w, event.resize.h); break; case SDL_QUIT: g_game->onExitAttempt(); break; case SDL_KEYDOWN: onKeyDown(event); break; case SDL_KEYUP: if((event.key.keysym.sym == SDLK_LSUPER) || (event.key.keysym.sym == SDLK_RSUPER)) superkey_state = false; break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: #ifdef WINCE if (ptrx < 5 && ptry < 5) SDL_WM_IconifyWindow(); // appears to crash the application?! ah nevermind #endif g_game->mouseEvent(event); break; case SDL_MOUSEMOTION: ptrx = event.motion.x; ptry = event.motion.y; g_game->mouseEvent(event); break; default: break; } } //update current frame time g_frameDiff = SDL_GetTicks() - g_frameTime; g_frameTime = SDL_GetTicks(); if (MAXFPS) { SDL_framerateDelay(&g_fpsmgr); } //check connection if(g_connection){ g_connection->executeNetwork(); } if (!(SDL_GetAppState() & SDL_APPACTIVE)) {// if the application is minimized #ifdef WIN32 Sleep(100); // sleep a while, and don't paint #else usleep(100 * 1000); #endif } else { //otherwise update scene g_game->updateScene(); g_engine->Flip(); } g_frames ++; //g_engine->fpsMutexUnlock(); } } catch(std::string errtext){ DEBUGPRINT(DEBUGPRINT_ERROR, DEBUGPRINT_LEVEL_OBLIGATORY, "%s", errtext.c_str()); } DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Game over\n"); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Terminating protocol connection from main...\n"); delete g_connection; g_connection = NULL; DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Destroying map...\n"); Map::getInstance().clear(); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Destroying creature cache...\n"); Creatures::getInstance().clear(); Creatures::destroyInstance(); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Destroying inventory...\n"); Inventory::getInstance().clear(); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Unloading data...\n"); Objects::getInstance()->unloadDat(); Objects::destroyInstance(); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Unloading skin...\n"); g_skin.unloadSkin(); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Saving options...\n"); options.Save(); DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Finishing engine...\n"); delete g_engine; DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Ending game...\n"); delete g_game; DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Shutting down SDL...\n"); SDL_Quit(); #ifdef WIN32 WSACleanup(); #endif DEBUGPRINT(DEBUGPRINT_LEVEL_OBLIGATORY, DEBUGPRINT_NORMAL, "Thanks for playing!\n"); return 0; }
void ProtocolConfig::setVersion(ClientOS_t os, ClientVersion_t version) { m_os = os; switch(version){ case CLIENT_VERSION_740: NativeGUIError("Support for this client version is only experimental.", "Warning"); m_clientVersion = CLIENT_VERSION_740; break; case CLIENT_VERSION_760: NativeGUIError("Support for this client version is only experimental.", "Warning"); m_clientVersion = CLIENT_VERSION_760; break; case CLIENT_VERSION_780: NativeGUIError("Support for this client version is only experimental.", "Warning"); m_clientVersion = CLIENT_VERSION_780; break; case CLIENT_VERSION_800: m_clientVersion = CLIENT_VERSION_800; break; case CLIENT_VERSION_810: m_clientVersion = CLIENT_VERSION_810; break; case CLIENT_VERSION_811: m_clientVersion = CLIENT_VERSION_811; break; case CLIENT_VERSION_820: m_clientVersion = CLIENT_VERSION_820; break; case CLIENT_VERSION_821: m_clientVersion = CLIENT_VERSION_821; break; case CLIENT_VERSION_822: m_clientVersion = CLIENT_VERSION_822; break; case CLIENT_VERSION_830: m_clientVersion = CLIENT_VERSION_830; break; case CLIENT_VERSION_831: m_clientVersion = CLIENT_VERSION_831; break; case CLIENT_VERSION_840: m_clientVersion = CLIENT_VERSION_840; break; case CLIENT_VERSION_841: m_clientVersion = CLIENT_VERSION_841; break; case CLIENT_VERSION_842: m_clientVersion = CLIENT_VERSION_842; break; case CLIENT_VERSION_850: m_clientVersion = CLIENT_VERSION_850; break; case CLIENT_VERSION_853: m_clientVersion = CLIENT_VERSION_853; break; case CLIENT_VERSION_854: m_clientVersion = CLIENT_VERSION_854; break; case CLIENT_VERSION_AUTO: m_clientVersion = detectVersion(); break; default: //ASSERT(0); NativeGUIError("This client version is not currently supported.", "Sorry"); return; } m_datSignature = this->readSignature("Tibia.dat"); m_sprSignature = this->readSignature("Tibia.spr"); m_picSignature = this->readSignature("Tibia.pic"); }