int llCommands::SaveFile(const char *_file) { FILE * wfile = NULL; if (fopen_s(&wfile, _file, "w")) { mesg->WriteNextLine(LOG_ERROR, "Unable to open %s", _file); return 0; } if (_llUtils()->GetValue("_gamemode")) { fprintf(wfile, "[_gamemode]\n"); fprintf(wfile, "%s -name=\"%s\"\n", LLCOM_GAMEMODE_CMD, _llUtils()->GetValue("_gamemode")); } int save=1; for (unsigned int i=0; i<lines.size(); i++) { //Filter hidden sections: if (strlen(lines[i])>1 && _strnicmp(lines[i], "[_",2)==0) save = 0; else if (strlen(lines[i])>0 && _strnicmp(lines[i],"[",1)==0) save = 1; if (save) fprintf(wfile,"%s\n", lines[i]); } //save all variables which are not hidden: fprintf(wfile, "[_saved]\n"); utils->WriteFlags(wfile); fclose(wfile); return 1; };
int llWorker::AddValue(char *_value) { if (checked_value == 1) { char *dummy = new char[strlen(_value)+1]; strcpy_s(dummy, strlen(_value)+1, _value); _llUtils()->StripQuot(&dummy); sscanf_s(dummy, "%i", i_value[checked_pos]); delete dummy; } else if (checked_value == 2) { char *dummy = new char[strlen(_value)+1]; strcpy_s(dummy, strlen(_value)+1, _value); _llUtils()->StripQuot(&dummy); sscanf_s(dummy, "%f", f_value[checked_pos]); delete dummy; } else if (checked_value == 3) { char *dummy = new char[strlen(_value)+1]; strcpy_s(dummy, strlen(_value)+1, _value); _llUtils()->StripQuot(&dummy); sscanf_s(dummy, "%lf", d_value[checked_pos]); delete dummy; } else if (checked_value == 4) { char *dummy = new char[strlen(_value)+1]; strcpy_s(dummy, strlen(_value)+1, _value); _llUtils()->StripQuot(&dummy); *(s_value[checked_pos]) = dummy; } return checked_value; }
int llSelectAll::Exec(void) { llMapWorker::Exec(); _llUtils()->x00 = map->GetX1(); _llUtils()->x11 = map->GetX2(); _llUtils()->y00 = map->GetY1(); _llUtils()->y11 = map->GetY2(); return 1; }
int llSetGrid::Exec(void) { if (!llSet::Exec()) return 0; float minab = 0; if (_llUtils()->GetValueF("_mindistance")) minab = (float)(*_llUtils()->GetValueF("_mindistance")); if (!Used("-stepx")) stepx = -1; if (!Used("-stepy")) stepy = -1; for (float x=floor(_llUtils()->x00/gridx)*gridx; x<=(_llUtils()->x11+1); x+=gridx) { for (float y=floor(_llUtils()->y00/gridy)*gridy; y<=(_llUtils()->y11+1); y+=gridy) { float x1=x, y1=y; if (x >= _llUtils()->x11) x1 = _llUtils()->x11; if (y >= _llUtils()->y11) y1 = _llUtils()->y11; if (map->IsInMap(x1,y1) && points->IsNotTooClose(x1,y1,minab)) { points->AddPoint(x1, y1, map->GetZ(x1,y1)); //gen_npoints++; } if (stepx > 0) { for (float xx=x1; xx<(x1+gridx); xx+=stepx) { if (map->IsInMap(xx,y1) && points->IsNotTooClose(xx,y1,minab)) { points->AddPoint(xx, y1, map->GetZ(xx,y1)); } } } if (stepy > 0) { for (float yy=y1; yy<(y1+gridy); yy+=stepy) { if (map->IsInMap(x1,yy) && points->IsNotTooClose(x1,yy,minab)) { points->AddPoint(x1, yy, map->GetZ(x1,yy)); } } } } } return 1; }
int llInactivateAllVertices::Exec(void) { if (!llMapWorker::Exec()) return 0; if (!points) { _llLogger()->WriteNextLine(-LOG_ERROR, "%s: map [%s] has no point list", command_name, mapname); return 0; } int num = 0; for (int i=0; i<points->GetN(); i++) { if (points->GetActive(i) && points->GetX(i) >= _llUtils()->x00 && points->GetX(i) <= _llUtils()->x11 && points->GetY(i) >= _llUtils()->y00 && points->GetY(i) <= _llUtils()->y11) { points->SetInactive(i); num++; } } _llLogger()->WriteNextLine(LOG_INFO, "%s: %i vertices inactivated", command_name, num); return 1; }
int llSetHeight::Exec(void) { if (!llMapWorker::Exec()) return 0; llAlgCollection *algs = NULL; if (Used("-alg")) { algs = _llAlgList()->GetAlgCollection(alg_list); if (!algs) { _llLogger()->WriteNextLine(-LOG_FATAL, "%s: alg collection '%s' not found", command_name, alg_list); return 0; } } if (usegameunits) zmin /= map->GetZScale(); //convert to heightmap units int x1 = (int) map->GetRawX(_llUtils()->x00); int x2 = (int) map->GetRawX(_llUtils()->x11); int y1 = (int) map->GetRawY(_llUtils()->y00); int y2 = (int) map->GetRawY(_llUtils()->y11); for (int x=x1; x<=x2; x+=1) { for (int y=y1; y<=y2; y+=1) { double alg = 0.0; if (algs) { alg = algs->GetValue(map->GetCoordX(x), map->GetCoordY(y)); } if (min && map->GetElementRaw(x, y) < zmin) map->SetElementRaw(x, y, zmin + alg); else if (max && map->GetElementRaw(x, y) > zmin) map->SetElementRaw(x, y, zmin + alg); else if (!min && !max) map->SetElementRaw(x, y, zmin + alg); } } return 1; }
void llCommands::SetDefaults() { mesg = _llLogger(); utils = _llUtils(); logfile = NULL; skip_next_block = 0; lines.resize(0); worker_cache.resize(0); worker_flags.resize(0); worker_list.resize(0); sections.resize(0); CurrentCommand = ""; worker_pointer = 0; line_pointer = 0; block_level = 0; noworkerprint = 0; }
int llSetAtGridLine::Exec(void) { if (!llSet::Exec()) return 0; float minab = 0; if (_llUtils()->GetValueF("_mindistance")) minab = (float)(*_llUtils()->GetValueF("_mindistance")); int zused = 0; if (!Used("-zmin")) zused = 1; int gb_points=0; for (float x=floor(_llUtils()->x00/gridx)*gridx; x<=(_llUtils()->x11)-gridx; x+=gridx) { for (float y=floor(_llUtils()->y00/gridy)*gridy; y<=(_llUtils()->y11)-gridy; y+=gridy) { //List of segments float segstart[1000]; float segend[1000]; int segaktive[1000]; int segpointer=0; //fill the first segment segstart[segpointer] = x; segend[segpointer] = x + gridx; segaktive[segpointer] = 1; segpointer++; for (int i=0; i<segpointer; i++) { //is segment large enough? if (segend[i]-segstart[i]>2*minab && segaktive[i]) { float mymax = -1; float myx = segstart[i]+minab; float z = map->GetZ(segstart[i] + minab, y); float slope = (map->GetZ(segend[i]-minab,y) -z ) / (segend[i] - segstart[i] - 2*minab); for (float x1 = segstart[i]+minab ;x1 < segend[i]-minab; x1++) { float walldiff = (z + slope * (x1 - (segstart[i]+minab))) - map->GetZ(x1,y); if (walldiff > max && walldiff>mymax && (map->GetZ(x1,y)>zmin || zused)) { mymax = walldiff; myx = x1; } } if (mymax>0) { //Split segment points->AddPoint(myx, y, map->GetZ(myx,y)); //gen_npoints++; gb_points++; segaktive[i]=0; segstart[segpointer] = segstart[i]; segend[segpointer] = myx; segaktive[segpointer] = 1; segpointer++; segstart[segpointer] = myx; segend[segpointer] = segend[i]; segaktive[segpointer] = 1; segpointer++; i = 0; } else segaktive[i] = 0; } else segaktive[i] = 0; } segpointer=0; //fill the first segment segstart[segpointer] = y; segend[segpointer] = y + gridy; segaktive[segpointer] = 1; segpointer++; for (int i=0; i<segpointer; i++) { //is segment large enough? if (segend[i]-segstart[i]>2*minab && segaktive[i]) { float mymax = -1; float myy = segstart[i] + minab; float z = map->GetZ(x,segstart[i]+minab); float slope = (map->GetZ(x,segend[i]-minab) -z ) / (segend[i] - segstart[i] - 2*minab); for (float y1 = segstart[i]+minab ;y1 < segend[i]-minab; y1++) { float walldiff = (z + slope * (y1 - (segstart[i]+minab))) - map->GetZ(x,y1); if (walldiff > max && walldiff>mymax && (map->GetZ(x,y1)>zmin || zused)) { mymax = walldiff; myy = y1; } } if (mymax>0) { //Split segment points->AddPoint(x, myy, map->GetZ(x,myy)); //gen_npoints++; gb_points++; segaktive[i] = 0; segstart[segpointer] = segstart[i]; segend[segpointer] = myy; segaktive[segpointer] = 1; segpointer++; segstart[segpointer] = myy; segend[segpointer] = segend[i]; segaktive[segpointer] = 1; segpointer++; i = 0; } else segaktive[i] = 0; } else segaktive[i] = 0; } #if 0 if (points->GetMinDistance(x1,y1) > minab) { points->AddPoint(x1,y1,heightmap->GetZ(x1,y1)); gen_npoints++; } #endif } } _llLogger()->WriteNextLine(-LOG_INFO, "%i break vertices set", gb_points); return 1; }
int llExportMap::Init(void) { if (!llWorker::Init()) return 0; if (!Used("-mapname")) mapname = "_heightmap"; if (!Used("-filename")) filename = "world.bmp"; if (!Used("-depth")) bits = 24; llMap * map = _llMapList()->GetMap(mapname); if (!map) { _llLogger()->WriteNextLine(-LOG_ERROR,"%s: map '%s' not found", command_name, mapname); return 0; } FILE *fptr; if (fopen_s(&fptr, filename,"wb")) { _llLogger()->WriteNextLine(-LOG_ERROR,"Unable to open BMP file '%s'\n", filename); return 0; } int x1 = map->GetRawX(_llUtils()->x00); int y1 = map->GetRawY(_llUtils()->y00); int x2 = map->GetRawX(_llUtils()->x11); int y2 = map->GetRawY(_llUtils()->y11); INFOHEADER infoheader; infoheader.width = x2-x1+1; infoheader.height = y2-y1+1; infoheader.compression=0; infoheader.size = 40; infoheader.planes = 1; /* Number of colour planes */ int bytesPerLine; if (bits == 24) infoheader.bits = 24; /* Bits per pixel */ else infoheader.bits = 32; if (bits == 24) { bytesPerLine = infoheader.width * 3; /* (for 24 bit images) */ /* round up to a dword boundary */ //Thanks to //http://www.siggraph.org/education/materials/HyperVis/asp_data/compimag/bmpfile.htm //for the hint if (bytesPerLine & 0x0003) { bytesPerLine |= 0x0003; ++bytesPerLine; } } else bytesPerLine = infoheader.width * 4; infoheader.imagesize = (long)bytesPerLine*infoheader.height; /* Image size in bytes */ infoheader.xresolution=100; infoheader.yresolution=100; /* Pixels per meter */ infoheader.ncolours=0; /* Number of colours */ infoheader.importantcolours; /* Important colours */ HEADER header; header.type='M'*256+'B'; header.size = 14 + 40 + infoheader.imagesize; header.reserved1 = header.reserved2 = 0; WriteUShort(fptr, header.type, 0); WriteUInt (fptr, header.size, 0); WriteUShort(fptr, header.reserved1, 0); WriteUShort(fptr, header.reserved2, 0); header.offset = 14+40; WriteUInt(fptr, header.offset, 0); /* Read and check the information header */ if (fwrite(&infoheader, sizeof(INFOHEADER), 1, fptr) != 1) { _llLogger()->WriteNextLine(-LOG_ERROR,"Failed to write BMP info header"); return 0; } for (int y=y2; y>=y1; y--) { int my_bytesPerLine = bytesPerLine; for (int x=x2; x>=x1; x--) { unsigned char byte1; unsigned char byte2; unsigned char byte3; unsigned char byte4; if (map->GetTupel(x, y, &byte1, &byte2, &byte3, &byte4)) { if (bits == 24) { my_bytesPerLine -= 3; fwrite(&byte1, 1, 1, fptr); //blue fwrite(&byte2, 1, 1, fptr); //green fwrite(&byte3, 1, 1, fptr); //red } else { fwrite(&byte1, 1, 1, fptr); //blue fwrite(&byte2, 1, 1, fptr); //green fwrite(&byte3, 1, 1, fptr); //red fwrite(&byte4, 1, 1, fptr); //alpha my_bytesPerLine -= 4; } } #if 0 float val = map->GetElementRaw(x,y); if (bits == 24) { my_bytesPerLine -= 3; unsigned int trunk1 = int(val) & 0xff; unsigned int trunk2 = (int(val) & 0xff00) >> 8; unsigned int trunk3 = (int(val) & 0xff0000) >> 16; fwrite(&trunk1, 1, 1, fptr); //blue fwrite(&trunk2, 1, 1, fptr); //green fwrite(&trunk3, 1, 1, fptr); //red } else { WriteUInt(fptr,unsigned int(val), 0); my_bytesPerLine -= 4; } #endif }
int llAddDiscontinuityGrid::Exec(void) { if (!llSet::Exec()) return 0; llLineList *lines = _llMapList()->GetLineList(mapname); if (!lines) { _llLogger()->WriteNextLine(-LOG_FATAL, "%s: no line list in map [%s]", command_name, mapname); return 0; } for (float x=floor(_llUtils()->x00/gridy)*gridy; x<=(_llUtils()->x11); x+=gridy) { float x1=x; if (x >= _llUtils()->x11) x1 = _llUtils()->x11; lines->AddLine(x1, _llUtils()->y00, x1, _llUtils()->y11); } for (float y=floor(_llUtils()->y00/gridx)*gridx; y<=(_llUtils()->y11); y+=gridx) { float y1=y; if (y >= _llUtils()->y11) y1 = _llUtils()->y11; lines->AddLine(_llUtils()->x00, y1, _llUtils()->x11, y1); } return 1; }
int main(int argc, char **argv) { llLogger *mesg = _llLogger(); llUtils *utils = _llUtils(); llCommands *batch = new llCommands(); //Oblivion std-values: _llUtils()->SetValue("_gamemode", "Oblivion"); _llUtils()->SetValue("_mindistance", "256"); _llUtils()->SetValue("_cellsize_x", "4096"); _llUtils()->SetValue("_cellsize_y", "4096"); _llUtils()->SetValue("_quadsize_x", "131072"); _llUtils()->SetValue("_quadsize_y", "131072"); _llUtils()->SetValue("_quad_levels", "1"); _llUtils()->SetValue("_dds_tool", "s3tc.exe"); _llUtils()->SetValue("_worldspaceid", "60"); _llUtils()->SetValue("_worldspace", "Tamriel"); _llUtils()->SetValue("_density_threshold", "95"); std::cout << "Landscape LOD generator" << std::endl; std::cout << "Written by gruftikus@github" << std::endl; std::cout << "V5.14, 23.12.2015" << std::endl; std::cout << "***********************" << std::endl; char *list_string = NULL; //****************** //read the arguments //****************** if (_stricmp(argv[argc-1], "-h") == 0 || _stricmp(argv[argc-1], "--help") == 0) { usage(); DumpExit(); } char *batchname = NULL; //check if last option is a filename int has_eq=0, has_dot=0; if (argc > 1) { for (unsigned int i=0; i<strlen(argv[argc-1]); i++) { if (argv[argc-1][i] == '.') has_dot++; if (argv[argc-1][i] == '=') has_eq++; } } if (has_dot && !has_eq) batchname = argv[argc-1]; char *section = NULL; int num = argc; if (batchname) num--; for (int i=1; i<num; i++) { if (strcmp(argv[i],"-f")==0) { //flagliste holen char *ptr; char *saveptr1 = NULL; ptr = strtok_int(argv[i+1], ',', &saveptr1); while(ptr != NULL) { char *my_flag_list=new char[strlen(ptr)+2]; strcpy_s(my_flag_list,strlen(ptr)+1,ptr); ptr = strtok_int(NULL, ',', &saveptr1); utils->AddFlag(my_flag_list); mesg->WriteNextLine(-LOG_INFO, "Flag: %s", my_flag_list); } i++; } else if (strcmp(argv[i],"-l")==0) { list_string = argv[i+1]; mesg->WriteNextLine(-LOG_INFO, "Mod list: %s", list_string); i++; } else if (strcmp(argv[i],"-w")==0) { utils->SetValue("_worldspace", argv[i+1]); mesg->WriteNextLine(-LOG_INFO, "Worldspace: %s", utils->GetValue("_worldspace")); } else if (argv[i][0] != '[') { char *my_flag_list = new char[strlen(argv[i])+2]; strcpy_s(my_flag_list, strlen(argv[i])+1, argv[i]); utils->AddFlag(my_flag_list); mesg->WriteNextLine(LOG_INFO, "Flag: %s", my_flag_list); } else section = argv[i]; } if (batchname) mesg->WriteNextLine(-LOG_INFO, "Batchfile: %s", batchname); else mesg->WriteNextLine(-LOG_INFO, "No batchfile, will read from stdin (type @end for compilation)"); if (!section) section = "[tes4ll]"; mesg->Dump(); CreateWorkers(batch); mesg->Dump(); if (list_string) _llUtils()->SetValue("_modlist", list_string); //TES-specific stuff: batch->RegisterWorker(new llParseModList()); batch->RegisterWorker(new llExportMeshToNif()); batch->RegisterWorker(new llExportBS()); batch->RegisterWorker(new llImportMapFromModlist()); batch->RegisterWorker(new TES4qLOD()); batch->RegisterWorker(new llBsaIterator()); batch->RegisterWorker(new llReadLodSettings()); //****************** //open the batch //****************** if (batchname && _stricmp(batchname, "stdin") != 0) { if (!batch->Open(batchname, section)) DumpExit(); batch->ReadCache(); batch->CompileScript(0); } else { batch->ReadStdin(section); batch->ReadCache(); batch->CompileScript(0); } return batch->Loop(); }
int llCreateNormalMap::Exec(void) { if (!llMapWorker::Exec()) return 0; if (!Used("-name")) { targetname = new char[strlen(mapname)+10]; sprintf_s(targetname, strlen(mapname)+10, "%s_normal", mapname); } int widthx = map->GetWidthX(); int widthy = map->GetWidthY(); llMap *newmap = _llMapList()->GetMap(targetname); int hasnewmap = 0; if (newmap) { _llLogger()->WriteNextLine(-LOG_WARNING,"%s: map %s existing, going to re-use it", command_name, targetname); //_llMapList()->DeleteMap(targetname); } else { hasnewmap = 1; newmap = new llMap(widthx-1, widthy-1, MAP_COLOR); newmap->SetEven(); newmap->SetCoordSystem(map->GetX1(), map->GetY1(), map->GetX2(), map->GetY2(), map->GetZScale()); } if (lodshadows) _llLogger()->WriteNextLine(-LOG_INFO, "Adding fake LOD shadows, 'north flip boost=%f'", northboost); else _llLogger()->WriteNextLine(-LOG_INFO, "Contrast z-boost=%f", boost); unsigned int x1 = map->GetRawX(_llUtils()->x00); unsigned int y1 = map->GetRawY(_llUtils()->y00); unsigned int x2 = map->GetRawX(_llUtils()->x11); unsigned int y2 = map->GetRawY(_llUtils()->y11); float st_array[3] = {0, 0, 0}; for (unsigned int y=y1; y<=y2; y++) { for (unsigned int x=x1; x<=x2; x++) { float height = map->GetZ(x,y); /*************************************/ if (lodshadows) { for (int v=0; v<3; v++) { //loop over direction vectors int directx = -1; int directy = 0; if (v==1) directx = 1; if (v==2) { directx = 0; directy = -1; } unsigned int cur_x = x + directx * resolution; unsigned int cur_y = y + directy * resolution; float slope = 0.f; int xx = int(cur_x)-int(x); int yy = int(cur_y)-int(y); int xxyy = xx + yy; if (xxyy<0) xxyy = -xxyy; while(xxyy < total_range && map->IsInMap(cur_x,cur_y) ) { float cur_slope = 0; if (v<2) cur_slope = directx * (map->GetZ(cur_x,cur_y)-height) / (map->GetWidthXPerRaw() * float(xx)); else cur_slope = directy * (map->GetZ(cur_x,cur_y)-height) / (map->GetWidthYPerRaw() * float(yy)); if (cur_slope > slope) slope = cur_slope; int stepsize = resolution * 8; if (xxyy < range) stepsize = resolution; else if (xxyy < 2*range) stepsize = resolution * 2; else if (xxyy < 4*range) stepsize = resolution * 4; cur_x += stepsize*directx; cur_y += stepsize*directy; xx = int(cur_x)-int(x); yy = int(cur_y)-int(y); xxyy = xx + yy; if (xxyy<0) xxyy = -xxyy; } st_array[v] = slope; } } /*************************************/ float tilt = 0.; float tilt_morning = st_array[1]; float tilt_evening = -st_array[0]; float n_x00 = (map->GetZ(x+1,y) - map->GetZ(x,y)) / (map->GetWidthXPerRaw()/boost); float n_y00 = (map->GetZ(x,y+1) - map->GetZ(x,y)) / (map->GetWidthYPerRaw()/boost); float n_x11 = (map->GetZ(x+1,y+1) - map->GetZ(x,y+1)) / (map->GetWidthXPerRaw()/boost); float n_y11 = (map->GetZ(x+1,y+1) - map->GetZ(x+1,y)) / (map->GetWidthYPerRaw()/boost); float n_x = (n_x00 + n_x11)/2.f; float n_y = (n_y00 + n_y11)/2.f; if (lodshadows) { tilt = tilt_morning + tilt_evening; n_x += tilt; n_y -= sqrt(st_array[0]*st_array[1]) * northboost; if (n_y > -st_array[2]) n_y = -st_array[2]; } float norm = sqrt(n_x*n_x + n_y*n_y + 1.f); float n_x1a = ((-n_x/norm)*127.f*1.0f + 128.f); float n_y1a = ((-n_y/norm)*127.f*1.0f + 128.f); float n_z1a = ((1.f/norm) *127.f*1.0f + 128.f); //std::cout << n_x << ":" << n_x1a << std::endl; float angle = 0.; unsigned char n_x1 = (unsigned char)(n_x1a); unsigned char n_y1 = (unsigned char)(n_y1a*cos(angle) + n_z1a*sin(angle)); unsigned char n_z1 = (unsigned char)(-sin(angle)*n_y1a + n_z1a*cos(angle)); unsigned int xn = x; unsigned int yn = y; if (!hasnewmap) { xn = newmap->GetRawX(map->GetCoordX(x)); yn = newmap->GetRawY(map->GetCoordY(y)); } newmap->SetTupel(xn, yn, n_z1, n_y1, n_x1, 255); //newmap->SetBlue (xn, yn, n_z1); //newmap->SetGreen(xn, yn, n_y1); //newmap->SetRed (xn, yn, n_x1); //newmap->SetAlpha(xn, yn, 255); } } if (hasnewmap) _llMapList()->AddMap(targetname, newmap, NULL, NULL, NULL, NULL); return 1; }
int llCommands::Loop(void) { #ifdef _MSC_VER __int64 time_statistics[LLCOM_MAX_WORKERS]; int time_statistics_cmd[LLCOM_MAX_WORKERS]; char *time_statistics_cmdname[LLCOM_MAX_WORKERS]; unsigned int time_statistics_pointer = 0; #endif //****************** //batch loop //****************** int com = 0; mesg->WriteNextLine(LOG_INFO, "****** Go into batch mode in %s ******", section); while (com > -2) { #ifdef _MSC_VER FILETIME idleTime; FILETIME kernelTime; FILETIME userTime; BOOL res = GetSystemTimes( &idleTime, &kernelTime, &userTime ); #endif #ifdef USE_CATCH try { #endif com = GetCommand(); #ifdef USE_CATCH } catch (char *str) { if (CurrentCommand) mesg->WriteNextLine(-LOG_FATAL, "Catched exception [%s] in [%s]", str, CurrentCommand); else mesg->WriteNextLine(-LOG_FATAL, "Catched exception [%s]", str); } catch (int str) { if (CurrentCommand) mesg->WriteNextLine(LOG_FATAL, "Catched exception [%i] in [%s]", str, CurrentCommand); else mesg->WriteNextLine(LOG_FATAL, "Catched exception [%i]", str); } catch (...) { if (CurrentCommand) mesg->WriteNextLine(LOG_FATAL, "Catched exception in [%s]", CurrentCommand); else mesg->WriteNextLine(LOG_FATAL, "Catched exception"); } #endif mesg->Dump(); #ifdef _MSC_VER FILETIME userTime_old = userTime; res = GetSystemTimes( &idleTime, &kernelTime, &userTime ); BOOL found = false; for (unsigned int ii=0; ii<time_statistics_pointer; ii++) { if (com == time_statistics_cmd[ii]) { ULARGE_INTEGER u1 = { userTime.dwLowDateTime, userTime.dwHighDateTime }; ULARGE_INTEGER u2 = { userTime_old.dwLowDateTime, userTime_old.dwHighDateTime }; time_statistics[ii] += u1.QuadPart - u2.QuadPart; found = true; } } if (!found && CurrentCommand) { ULARGE_INTEGER u1 = { userTime.dwLowDateTime, userTime.dwHighDateTime }; ULARGE_INTEGER u2 = { userTime_old.dwLowDateTime, userTime_old.dwHighDateTime }; time_statistics[time_statistics_pointer] = u1.QuadPart - u2.QuadPart; time_statistics_cmd[time_statistics_pointer] = com; time_statistics_cmdname[time_statistics_pointer] = _llUtils()->NewString((char*) CurrentCommand); time_statistics_pointer++; } #endif } std::cout << "****** Batch loop done ******" << std::endl; #ifdef _MSC_VER for (unsigned int ii=0; ii<time_statistics_pointer; ii++) { for (unsigned int jj=0; jj<time_statistics_pointer-1; jj++) { if (time_statistics[jj] < time_statistics[jj+1]) { __int64 time_statistics_tmp = time_statistics[jj]; char * time_statistics_cmdname_tmp = time_statistics_cmdname[jj]; time_statistics[jj] = time_statistics[jj+1]; time_statistics_cmdname[jj] = time_statistics_cmdname[jj+1]; time_statistics[jj+1] = time_statistics_tmp; time_statistics_cmdname[jj+1] = time_statistics_cmdname_tmp; } } } std::cout << "User time per command (sorted):" << std::endl; for (unsigned int ii=0; ii<time_statistics_pointer; ii++) { if (time_statistics[ii] > 1000000) std::cout << time_statistics_cmdname[ii] << ": " << (((double)time_statistics[ii]) /10000000.)<< " s" << std::endl; } #endif return 0; }
int llCommands::CompileScript(int _compile_all_sections) { char *current_section = ""; for (unsigned int l=0; l<lines.size(); l++) { strcpy_s(dummyline, LLCOM_MAX_LINE, lines[l]); char *linex = dummyline; _llUtils()->StripSpaces(&linex); _llUtils()->StripComment(linex); _llUtils()->StripSpaces(&linex); //_llLogger()->WriteNextLine(LOG_INFO, "linex %s", linex); if (strlen(linex) > 0) { if (linex[0] == '[') { //avoid re-compiling of an existing section: int is_existing = 0; if (_compile_all_sections) { //dont care is_existing = 1; } else { if (_stricmp(linex, section) != 0) { //never create section if section is not used //_llLogger()->WriteNextLine(LOG_INFO, "sec skip %s", linex); is_existing = 1; } else { //_llLogger()->WriteNextLine(LOG_INFO, "sec todo %s", linex); for (int i=0; i<sections.size(); i++) { if (_stricmp(linex, sections[i]) == 0) is_existing = 1; } } } if (!is_existing) { char *sec = _llUtils()->NewString(linex); sections.push_back(sec); current_section = sec; //_llLogger()->WriteNextLine(LOG_INFO, "sec current %s", current_section); } else { current_section = "delme"; } } else if (_compile_all_sections || _stricmp(current_section, section) == 0) { ExtendWorkerCache(); //_llLogger()->WriteNextLine(LOG_INFO, "sec comp %s", section); //check for flags repeat: if (linex[0] == '@') { unsigned int i = _llUtils()->SeekNextSpace(linex); if (!i) i = strlen(linex); linex[i] = '\0'; char *delme = _llUtils()->NewString(linex); (worker_flags.back()).push_back(delme); linex = linex + i + 1; _llUtils()->StripSpaces(&linex); goto repeat; } _llUtils()->StripSpaces(&linex); if (linex[0] == '{') { ExtendWorkerCache(); bracket_cache[bracket_cache.size()-1] = LLCOM_OPEN_BLOCK; linex++; _llUtils()->StripSpaces(&linex); ExtendWorkerCache(); } else if (linex[0] == '}') { ExtendWorkerCache(); bracket_cache[bracket_cache.size()-1] = LLCOM_CLOSE_BLOCK; linex++; _llUtils()->StripSpaces(&linex); ExtendWorkerCache(); } int com = -1; char *ptr, *ptr2; char *saveptr1 = NULL, *saveptr2 = NULL; ptr = strtok_int(linex, ' ', &saveptr1); if (ptr && strlen(ptr)>0) { if (_stricmp(ptr, "{") == 0) { ExtendWorkerCache(); bracket_cache[bracket_cache.size()-1] = LLCOM_OPEN_BLOCK; if (saveptr1) linex = saveptr1; else linex = (char *)""; _llUtils()->StripSpaces(&linex); ExtendWorkerCache(); goto repeat; } if (_stricmp(ptr, "}") == 0) { ExtendWorkerCache(); bracket_cache[bracket_cache.size()-1] = LLCOM_CLOSE_BLOCK; if (saveptr1) linex = saveptr1; else linex = (char *)""; _llUtils()->StripSpaces(&linex); ExtendWorkerCache(); goto repeat; } llWorker *worker = NULL; for (unsigned int i=0; i<worker_list.size(); i++) { if (_stricmp(ptr, worker_list[i]->GetCommandName() ) == 0) { com = i; CurrentCommand = worker_list[i]->GetCommandName(); worker = worker_list[i]->Clone(); worker ->SetCommandIndex(com); worker ->RegisterOptions(); worker ->Prepare(); worker_cache[worker_cache.size()-1] = worker; ptr = strtok_int(NULL,' ', &saveptr1); while(ptr != NULL) { if (_stricmp(ptr, "{") == 0) { ExtendWorkerCache(); bracket_cache[bracket_cache.size()-1] = LLCOM_OPEN_BLOCK; if (saveptr1) linex = saveptr1; else linex = (char *)""; _llUtils()->StripSpaces(&linex); ExtendWorkerCache(); goto repeat; } if (_stricmp(ptr, "}") == 0) { ExtendWorkerCache(); bracket_cache[bracket_cache.size()-1] = LLCOM_CLOSE_BLOCK; if (saveptr1) linex = saveptr1; else linex = (char *)""; _llUtils()->StripSpaces(&linex); ExtendWorkerCache(); goto repeat; } if (!worker->CheckFlag(ptr)) { ptr2 = strtok_int(ptr, '=', &saveptr2); if (ptr2!=NULL && strlen(ptr2)>0) { if (worker->CheckValue(ptr)) { ptr2 = strtok_int(NULL, '=', &saveptr2); if (ptr2) worker->AddValue(ptr2); else { mesg->WriteNextLine(-LOG_ERROR, "Compile error in line %i", l+1); mesg->WriteNextLine(-LOG_ERROR, LLCOM_SYNTAX_ERROR, ptr, CurrentCommand); } } else { mesg->WriteNextLine(-LOG_ERROR, "Compile error in line %i", l+1); mesg->WriteNextLine(-LOG_ERROR, LLCOM_UNKNOWN_OPTION, ptr, CurrentCommand); } } } ptr = strtok_int(NULL, ' ', &saveptr1); } goto exit; } //if stricmp } exit: if (!worker) { mesg->WriteNextLine(-LOG_ERROR, "Compile error in line %i", l+1); mesg->WriteNextLine(-LOG_ERROR, "--> Unknown command [%s]", ptr); } } //strlen ptr } //not section } //if (strlen(linex) > 0) } return 1; }
int llExportMeshToVRML::Exec(void) { if (!llTriMod::Exec()) return 0; if (!Used("-filename")) filename = (char *)"map.wrl"; if (!MakeSelection()) return 0; //look for _install_dir: if (_llUtils()->GetValue("_install_dir")) { char *filename_tmp = new char[strlen(filename) + strlen(_llUtils()->GetValue("_install_dir")) + 2]; sprintf_s(filename_tmp, strlen(filename) + strlen(_llUtils()->GetValue("_install_dir")) + 2, "%s\\%s", _llUtils()->GetValue("_install_dir"), filename); filename = filename_tmp; } //Now the VRML-specific part: FILE *fptr; if (fopen_s(&fptr, filename, "w")) { _llLogger()->WriteNextLine(-LOG_ERROR,"Unable to open VRML file '%s'\n", filename); return 0; } fprintf(fptr, "#VRML V2.0 utf8\n"); fprintf(fptr, "DEF MATERIAL Material {\n"); fprintf(fptr, " diffuseColor 1 1 1\n"); fprintf(fptr, "}\n"); fprintf(fptr, "Transform {\n"); fprintf(fptr, " rotation 0.5774 0.5774 0.5774 -2.094\n"); fprintf(fptr, " scale 1 1 1\n"); fprintf(fptr, " children [\n"); fprintf(fptr, " Shape {\n"); fprintf(fptr, " appearance Appearance {\n"); fprintf(fptr, " material USE MATERIAL\n"); if (texname) { fprintf(fptr, " texture ImageTexture {\n"); fprintf(fptr, " url \"%s\"\n", texname); fprintf(fptr, " }\n"); } fprintf(fptr, " }\n"); fprintf(fptr, " geometry IndexedFaceSet {\n"); fprintf(fptr, " creaseAngle 3.1415\n"); fprintf(fptr, " coord Coordinate {\n"); fprintf(fptr, " point [\n"); //Vertices: for (int i=0; i<newpoints->GetN(); i++) { fprintf(fptr, " %f %f %f\n", newpoints->GetX(i), newpoints->GetY(i), newpoints->GetZ(i)); } fprintf(fptr, " ] \n }\n"); //Tex-coords: if (texname) { fprintf(fptr, " texCoord TextureCoordinate {\n"); fprintf(fptr, " point [\n"); for (int i=0; i<newpoints->GetN(); i++) { fprintf(fptr, " %f %f\n", newpoints->GetU(i), newpoints->GetV(i)); } fprintf(fptr, " ] \n }\n"); } fprintf(fptr, " coordIndex [ \n"); for (int i=0; i<newtriangles->GetN(); i++) { fprintf(fptr, " %i %i %i -1 \n", newtriangles->GetPoint1(i), newtriangles->GetPoint2(i), newtriangles->GetPoint3(i)); } fprintf(fptr, " ]\n"); if (texname) { fprintf(fptr, " texCoordIndex [ \n"); for (int i=0; i<newtriangles->GetN(); i++) { fprintf(fptr, " %i %i %i -1 \n", newtriangles->GetPoint1(i), newtriangles->GetPoint2(i), newtriangles->GetPoint3(i)); } fprintf(fptr, " ] \n"); } if (_llUtils()->GetValue("_install_dir")) { delete filename; } fprintf(fptr, " } \n } \n ] \n} \n"); return 1; }
int llParseModList::Exec(void) { llWorker::Exec(); HKEY keyHandle; char rgValue [1024]; // char fnlRes [1024]; DWORD size1; DWORD Type; char *gamekey1 = "SOFTWARE\\Bethesda Softworks\\Oblivion"; char *gamekey2 = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\Oblivion"; if (_llUtils()->IsEnabled("_gamemode")) { if (_stricmp(_llUtils()->GetValue("_gamemode"), "Fallout3") == 0) { gamekey1 = "SOFTWARE\\Bethesda Softworks\\fallout3"; gamekey2 = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\fallout3"; } else if (_stricmp(_llUtils()->GetValue("_gamemode"), "Falloutnv") == 0) { gamekey1 = "SOFTWARE\\Bethesda Softworks\\falloutnv"; gamekey2 = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\falloutnv"; } else if (_stricmp(_llUtils()->GetValue("_gamemode"), "Skyrim") == 0) { gamekey1 = "SOFTWARE\\Bethesda Softworks\\skyrim"; gamekey2 = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\skyrim"; } } //seek for game dir, if not yet set by user if (!_llUtils()->IsEnabled("_gamedir")) { if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, gamekey1, 0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS) { size1 = 1023; RegQueryValueEx( keyHandle, "Installed Path", NULL, &Type, (LPBYTE)rgValue,&size1); char *oblivion_path = new char[strlen(rgValue)+2]; strcpy_s(oblivion_path, strlen(rgValue)+1, rgValue); _llLogger()->WriteNextLine(-LOG_INFO, "Game path is: %s", oblivion_path); _llUtils()->SetValue("_gamedir", oblivion_path); } else if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, gamekey2, 0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS) { size1 = 1023; RegQueryValueEx( keyHandle, "Installed Path", NULL, &Type, (LPBYTE)rgValue,&size1); char *oblivion_path = new char[strlen(rgValue)+2]; strcpy_s(oblivion_path, strlen(rgValue)+1, rgValue); _llLogger()->WriteNextLine(-LOG_INFO, "Game path is: %s", oblivion_path); _llUtils()->SetValue("_gamedir", oblivion_path); } else { if (_llUtils()->IsEnabled("_gamemode")) _llLogger()->WriteNextLine(LOG_WARNING, "Game '%s' not installed, I will use the working directory.", _llUtils()->GetValue("_gamemode")); else _llLogger()->WriteNextLine(LOG_WARNING, "Oblivion not installed, I will use the working directory."); TCHAR dir[1000]; GetCurrentDirectory(1000, dir); if ((strlen(dir) > 4) && _stricmp(dir+strlen(dir)-4, "data")==0) dir[strlen(dir)-4] = '\0'; if ((strlen(dir) > 15) && _stricmp(dir+strlen(dir)-15, "data\\ini\\tes4ll")==0) dir[strlen(dir)-15] = '\0'; _llUtils()->SetValue("_gamedir", dir); //DumpExit(); } RegCloseKey(keyHandle); } else { _llLogger()->WriteNextLine(LOG_INFO,"Game path is: %s", _llUtils()->GetValue("_gamedir")); } if (cd) { _llLogger()->WriteNextLine(LOG_COMMAND,"%s: change directory path to %s", command_name, _llUtils()->GetValue("_gamedir")); _chdir(_llUtils()->GetValue("_gamedir")); if (_llUtils()->GetValue("_datadir")) _chdir(_llUtils()->GetValue("_datadir")); else _chdir("Data"); } const char *option = _llUtils()->GetValue("_modlist"); if (!option) { // mod list not provided my main program char oblivion_app_path[1024]; //open registry if( RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS) { size1=1023; strcpy_s(rgValue,1024,"\0"); RegQueryValueEx( keyHandle, "Local Appdata", NULL, &Type, (LPBYTE)rgValue,&size1); //win7 if (strlen(rgValue) == 0) { strcpy_s(rgValue,1024,"\0"); RegQueryValueEx( keyHandle, "Appdata", NULL, &Type, (LPBYTE)rgValue,&size1); //win XP } if (strlen(rgValue) == 0) { _llLogger()->WriteNextLine(-LOG_FATAL,"Could not get Appdata path!"); } strcpy_s(oblivion_app_path,1024,rgValue); _llLogger()->WriteNextLine(LOG_INFO,"Appdata path is: %s",oblivion_app_path); } else { _llLogger()->WriteNextLine(-LOG_FATAL,"Could not get Appdata path!"); } RegCloseKey(keyHandle); char listname[2000]; sprintf_s(listname,2000,"%s\\Oblivion\\plugins.txt\0", oblivion_app_path); if (_llUtils()->IsEnabled("_gamemode")) { if (_stricmp(_llUtils()->GetValue("_gamemode"), "Fallout3") == 0) sprintf_s(listname,2000,"%s\\Fallout3\\plugins.txt\0", oblivion_app_path); if (_stricmp(_llUtils()->GetValue("_gamemode"), "FalloutNV") == 0) sprintf_s(listname,2000,"%s\\FalloutNV\\plugins.txt\0", oblivion_app_path); if (_stricmp(_llUtils()->GetValue("_gamemode"), "Skyrim") == 0) sprintf_s(listname,2000,"%s\\skyrim\\plugins.txt\0", oblivion_app_path); } FILE *fesplist = NULL; if (fopen_s(&fesplist,listname,"r")) { _llLogger()->WriteNextLine(-LOG_FATAL, "Unable to open plugin file \"%s\"\n",listname); } esp_list[0] = new char[1024]; while (fgets(esp_list[num_esp],1024,fesplist)) { if (esp_list[num_esp][0] != '#' && strlen(esp_list[num_esp])>5) { //remove the trailing \n if (num_esp == 256) { _llLogger()->WriteNextLine(-LOG_FATAL,"Too many mod files\n"); } esp_list[num_esp][strlen(esp_list[num_esp])-1] = '\0'; //cout << esp_list[num_esp]; if (num_esp < 256) num_esp++; esp_list[num_esp] = new char[1024]; } } fclose(fesplist); _llLogger()->WriteNextLine(LOG_INFO, "%i plugins will be used", num_esp); for (int i=0; i<num_esp; i++) { //open the esp WIN32_FILE_ATTRIBUTE_DATA fAt = {0}; char tmpName2[2000]; sprintf_s(tmpName2,2000, "%s", esp_list[i]); wchar_t tmpName[2000]; swprintf(tmpName, 2000, L"%s", tmpName2); if (!GetFileAttributesEx(tmpName2, GetFileExInfoStandard, &fAt)) { _llLogger()->WriteNextLine(-LOG_FATAL, "The mod file '%s' was not found", esp_list[i]); //cout << GetLastError() << endl; } FILETIME time = fAt.ftLastWriteTime; esp_list_sorted[num_esp_sorted] = esp_list[i]; time_list_sorted[num_esp_sorted] = time; num_esp_sorted++; for (int j=num_esp_sorted-1; j>0; j--) { //quicksort if (CompareFileTime(&time_list_sorted[j-1], &time_list_sorted[j]) > 0) { FILETIME ttmp = time_list_sorted[j-1]; char * tmp = esp_list_sorted[j-1]; time_list_sorted[j-1] = time_list_sorted[j]; esp_list_sorted[j-1] = esp_list_sorted[j]; time_list_sorted[j] = ttmp; esp_list_sorted[j] = tmp; } } } for (int j=0; j<num_esp_sorted; j++) { _llUtils()->AddMod(esp_list_sorted[j]); char * my_flag_list = new char[strlen(esp_list_sorted[j]) + 1]; strcpy_s(my_flag_list, strlen(esp_list_sorted[j])+1, esp_list_sorted[j]); for (unsigned int jj=0; jj<strlen(my_flag_list); jj++) { if (*(my_flag_list+jj) == ' ' || *(my_flag_list+jj) == ',') *(my_flag_list+jj)='_'; } _llLogger()->WriteNextLine(LOG_INFO, "Mod flag: %s", my_flag_list); _llUtils()->AddFlag(my_flag_list); } } else { //list mod option provided char *ptr; char *saveptr1 = NULL; char *list_string = _llUtils()->NewString(option); for (int ii=0; ii<strlen(list_string)-1; ii++) { if (list_string[ii] == '\\' && list_string[ii+1] == ',') { list_string[ii+1] = '#'; } } ptr = strtok_int(list_string, ',', &saveptr1); while(ptr != NULL) { char *flag_list = _llUtils()->NewString(ptr); _llUtils()->StripSpaces(&flag_list); flag_list = _llUtils()->Replace(flag_list, "\\#", "\\,"); flag_list = _llUtils()->ReplaceProtectedKomma(flag_list); char *mod_list = _llUtils()->NewString(ptr); _llUtils()->StripSpaces(&mod_list); mod_list = _llUtils()->Replace(mod_list, "\\#", "\\,"); mod_list = _llUtils()->ReplaceProtectedKomma(mod_list); _llUtils()->AddMod(mod_list); for (unsigned int j=0;j<strlen(flag_list);j++) { if (*(flag_list+j) == ' ' || *(flag_list+j) == ',') *(flag_list+j)='_'; } ptr = strtok_int(NULL, ',', &saveptr1); _llLogger()->WriteNextLine(LOG_INFO, "Mod flag: %s", flag_list); _llUtils()->AddFlag(flag_list); } } return 1; }