예제 #1
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;
}
예제 #2
0
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();
}
예제 #3
0
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;
}