Example #1
0
bool Mod_TAZ::apply(Polygon *p)
{
  bool is_in[4];
  rvulong curentry;
  int i, nverts=p->numverts();
  Vector *vecs[4];
  rvulong look_id;
  ModList *mods;
  bool has_been_applied=false;
  
  /* cache the vector pointers */
  for(i=0;i<nverts;i++)
    vecs[i]= &( p->parent->verts[p->vertidx(i)]->pos );

  curentry=0;
  while(curentry < size)
    {
      /* at start of a zone sequence.
       * consider every point being outside
       */
      is_in[0]=is_in[1]=is_in[2]=is_in[3]=false;

      // only look at the current id
      look_id=zones[curentry].data.id;
      mods=zones[curentry].mods;

      // run through all entries with this id:
      while((curentry<size) && (zones[curentry].data.id==look_id))
	{
	  for(i=0;i<nverts;i++)
	    if(!is_in[i])
	      {
		// if point isn't already in the zones, we look now
		if(isPointInZone(*vecs[i], zones[curentry].data))
		  is_in[i]=true;
	      };
	  curentry++;
	};

      // now we are through the zones. Collect is_in's in is_in[0]:
      if(nverts==4)
	is_in[0] = is_in[0] && is_in[1] && is_in[2] && is_in[3];
      else
	is_in[0] = is_in[0] && is_in[1] && is_in[2];

      // if its inside, apply the mod
      if(is_in[0] && mods!=NULL)
	{
	  if(! mods->apply(p) )
	    return false;
	  has_been_applied=true;
	};
    };

  if(!has_been_applied && (defaultmod != NULL))
    return defaultmod->apply(p);

  return true;
}
Example #2
0
void
ModList::deselectCB(void *ptrToThis, SoPath *path)
{
    ModList		*me = (ModList *)ptrToThis;
    Modulate		*obj;
    int			oldCount;
    int			i;
    int			id;

    id = findToken(path);

    if (id < 0) {

#ifdef PCP_DEBUG
	if (pmDebug & DBG_TRACE_APPL1)
	    cerr << "ModList::deselectCB: Nothing deselected" << endl;
#endif

	return;
	/*NOTREACHED*/
    }

    obj = me->_list[id];

#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL1)
	cerr << "ModList::deselectCB: Deselected [" << id << "] = "
	     << *obj << endl;
#endif

    oldCount = me->_selList[id];
    me->_selList[id] = obj->remove(path);
    me->_numSel -= oldCount - me->_selList[id];
    if (me->_numSel == 1) {
	for (i = 0; i < me->_selList.size(); i++)
	    if (me->_selList[i] == 1)
		me->_oneSel = i;
    }

    if (me->_numSel == 0)
	me->_current = me->_list.size();

    if (me->_numSel < 2)
	(*(me->_selCB))(me, true);

    if (me->_deselInvCB != NULL)
	(*(me->_deselInvCB))(me, path);

#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL1) {
	cerr << "ModList::deselectCB: selection state:" << endl;
	me->dumpSelections(cerr);
    }
#endif
}
Example #3
0
void ModEditWindow::OnDragJarMod(wxListEvent &event)
{
	ModList *mods = m_inst->GetModList();
	wxFileDataObject modFileObj;
	
	wxArrayInt indices = jarModList->GetSelectedItems();
	for (wxArrayInt::const_iterator iter = indices.begin(); iter != indices.end(); ++iter)
	{
		wxFileName modFile = mods->at(*iter).GetFileName();
		modFile.MakeAbsolute();
		modFileObj.AddFile(modFile.GetFullPath());
	}
	
	wxDropSource modsDropSource(modFileObj, jarModList);
	modsDropSource.DoDragDrop(wxDrag_CopyOnly);
}
Example #4
0
void Instance::LoadModListFromDir(const wxFileName& dir, bool mlMod)
{
	ModList *list;
	
	if (mlMod)
		list = &mlModList;
	else
		list = &modList;
	
	wxDir modDir(dir.GetFullPath());
	
	if (!modDir.IsOpened())
	{
		wxLogError(_("Failed to open directory: ") + dir.GetFullPath());
		return;
	}
	
	wxString currentFile;
	if (modDir.GetFirst(&currentFile))
	{
		do
		{
			currentFile = Path::Combine(modDir.GetName(), currentFile);
			if (wxFileExists(currentFile) || mlMod)
			{
				Mod mod(currentFile);
				
				if (mlMod || !Any(list->begin(), list->end(), [&currentFile] (Mod mod) -> bool
					{ return mod.GetFileName().SameAs(wxFileName(currentFile)); }))
				{
					if (!mlMod)
						SetNeedsRebuild();

					list->push_back(mod);
				}
			}
			else if (wxDirExists(currentFile))
			{
				LoadModListFromDir(wxFileName(currentFile), mlMod);
			}
		} while (modDir.GetNext(&currentFile));
	}
}
Example #5
0
void ModEditWindow::MLModListCtrl::CopyMod()
{
	ModList *mods = m_inst->GetMLModList();
	wxFileDataObject *modFileObj = new wxFileDataObject;

	wxArrayInt indices = GetSelectedItems();
	for (wxArrayInt::const_iterator iter = indices.begin(); iter != indices.end(); ++iter)
	{
		wxFileName modFile = mods->at(*iter).GetFileName();
		modFile.MakeAbsolute();
		modFileObj->AddFile(modFile.GetFullPath());
	}

	if (wxTheClipboard->Open())
	{
		wxTheClipboard->SetData(modFileObj);
		wxTheClipboard->Close();
	}
}
Example #6
0
bool Mod_TAZ::readOneList(Parser &p)
{
  bool add_to_default;
  int cur_zone;
  ModList *newlist;

  if(strcasecmp(p.tok_text, KEY_DEFAULT)==0)
    {
      p.gentoken();
      add_to_default=true;
    }
  else
    {
      if(  (cur_zone=p.eatNumber()) <0)
	return false;
      add_to_default=false;
    };

  if(p.curtok != PT_BBEGIN)
    {
      p.error(ERROR_EMPTY_FILEOPT,"ignoring empty option set for taz zone %d", cur_zone);
      return true;
    };

  newlist=new ModList;
  if(!newlist->parse(p))
    return false;

  if(!add_to_default)
    enterList(newlist, (rvulong)cur_zone);
  else
    {
      if(defaultmod==NULL)
	defaultmod=newlist;
      else
	{
	  p.error(ERROR_DUPLICATE_FILEOPT,"Ignoring extra \"default\" group in TAZ modifier");
	  delete newlist;
	};
    };
  return true;
}
int main(int argc, char* argv[])
{
#ifdef VAULTMP_DEBUG
#ifdef __WIN32__

	if (LoadLibrary("exchndl.dll") == NULL)
		return 0;

#else
	system("ulimit -c unlimited");
#endif
#endif

#ifdef __WIN32__
	printf("Vault-Tec dedicated server %s (Windows)\n----------------------------------------------------------\n", DEDICATED_VERSION);
#else
	printf("Vault-Tec dedicated server %s (Unix)\n----------------------------------------------------------\n", DEDICATED_VERSION);
#endif

	unsigned char game;
	int port;
	int players;
	int fileslots;
	bool query;
	bool files;
	const char* announce;
	const char* scripts;
	const char* mods;
	const char* savegame;

	dictionary* config = iniparser_load(argc > 1 ? argv[1] : "vaultserver.ini");

	const char* game_str = iniparser_getstring(config, "general:game", "fallout3");

	if (stricmp(game_str, "newvegas") == 0)
		game = NEWVEGAS;
	else
		game = FALLOUT3;

	port = iniparser_getint(config, "general:port", RAKNET_STANDARD_PORT);
	players = iniparser_getint(config, "general:players", RAKNET_STANDARD_CONNECTIONS);
	query = (bool) iniparser_getboolean(config, "general:query", 1);
	files = (bool) iniparser_getboolean(config, "general:fileserve", 0);
	fileslots = iniparser_getint(config, "general:fileslots", 8);
	announce = iniparser_getstring(config, "general:master", "vaultmp.com");
	savegame = iniparser_getstring(config, "general:save", "default.fos");
	scripts = iniparser_getstring(config, "scripts:scripts", "");
	mods = iniparser_getstring(config, "mods:mods", "");

	ServerEntry* self = new ServerEntry(game);
	self->SetServerRule("version", DEDICATED_VERSION);
	Dedicated::SetServerEntry(self);

	char base[MAX_PATH];
	_getcwd(base, sizeof(base));

	try
	{
		putenv(PWNFILES_PATH);
		char _scripts[strlen(scripts) + 1];
		snprintf(_scripts, sizeof(_scripts), "%s", scripts);
		Script::LoadScripts(_scripts, base);
	}

	catch (std::exception& e)
	{
		try
		{
			VaultException& vaulterror = dynamic_cast<VaultException&>(e);
			vaulterror.Console();
		}

		catch (std::bad_cast& no_vaulterror)
		{
			VaultException vaulterror(e.what());
			vaulterror.Console();
		}
	}

	try
	{
		char file[MAX_PATH];
		snprintf(file, sizeof(file), "%s/%s/%s", base, SAVEGAME_PATH, savegame);

		unsigned int crc;

		if (!Utils::crc32file(file, &crc))
			throw VaultException("Could not find savegame %s in folder %s", savegame, SAVEGAME_PATH);

		Dedicated::SetSavegame(Savegame(string(savegame), crc));

		char buf[strlen(mods) + 1];
		strcpy(buf, mods);
		char* token = strtok(buf, ",");
		ModList modfiles;

		while (token != NULL)
		{
			snprintf(file, sizeof(file), "%s/%s/%s", base, MODFILES_PATH, token);

			if (!Utils::crc32file(file, &crc))
				throw VaultException("Could not find modfile %s in folder %s", token, MODFILES_PATH);

			modfiles.push_back(pair<string, unsigned int>(string(token), crc));

			token = strtok(NULL, ",");
		}

		Dedicated::SetModfiles(modfiles);

		thread hDedicatedThread = Dedicated::InitializeServer(port, players, announce, query, files, fileslots);
		thread hInputThread = thread(InputThread);

		hDedicatedThread.join();

		if (hInputThread.joinable())
			hInputThread.join();
	}

	catch (std::exception& e)
	{
		try
		{
			VaultException& vaulterror = dynamic_cast<VaultException&>(e);
			vaulterror.Console();
		}

		catch (std::bad_cast& no_vaulterror)
		{
			VaultException vaulterror(e.what());
			vaulterror.Console();
		}
	}

	Script::UnloadScripts();
	iniparser_freedict(config);
	delete self;

#ifdef __WIN32__
	system("PAUSE");
#endif

	return 0;
}
Example #8
0
void
ModList::motionCB(void *ptrToThis, SoEventCallback *theEvent)
{
    ModList		*me = (ModList *)ptrToThis;
    const SoPickedPoint	*pick = NULL;
    SoPath		*path = NULL;
    int			id = -1;

    // If one item is selected, return as we aren't interested
    if (me->_numSel == 1)
	return;

    pick = theEvent->getPickedPoint();
    if (pick != NULL) {
	path = pick->getPath();    
	if (path != NULL)
	    id = ModList::findToken(path);
    }

    // Nothing selected that we are interested in
    if (id < 0) {
	// Deselect anything selected
	if (me->_current < me->size()) {
	    (*me)[me->_current].removeInfo(path);
	    me->_current = me->size();

#ifdef PCP_DEBUG
	    if (pmDebug & DBG_TRACE_APPL1)
		cerr << "ModList::motionCB: remove object " << id << endl;
#endif
	}
    }
    else if (me->_current != id) {
	if (me->_current < me->size())
	    (*me)[me->_current].removeInfo(path);
	me->_current = id;
	(*me)[me->_current].selectInfo(path);

#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL1)
	cerr << "ModList::motionCB: new object " << id << endl;
#endif
    }
    else {
	(*me)[me->_current].selectInfo(path);

#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL1)
	cerr << "ModList::motionCB: same object " << id << endl;
#endif
    }

    // Note: the call to _selCB below used to only be done if the guard
    //    if (old != me->_current)
    // is true. But this does not work for stacked bars because
    // the object is the same even though the mouse has moved over 
    // a different block in the same stack. Hence the metric info
    // text window was not being updated for the mouse motion CB.
    // Since the render method for the metricLabel only updates the
    // text widget if the text has actually changed, it seems to me
    // that it is safe to call the selCB unconditionally and there
    // wont be any "flicker" problems.
    //    -- markgw 15 oct 1997
    //
    (*(me->_selCB))(me, false);
}
Example #9
0
void
ModList::selCB(void *ptrToThis, SoPath *path)
{
    ModList		*me = (ModList *)ptrToThis;
    Modulate		*obj;
    int			oldCount;
    int			id;

    if (!me->_allFlag)
	id = ModList::findToken(path);
    else
	id = me->_allId;
    
    if (id < 0) {

#ifdef PCP_DEBUG
	if (pmDebug & DBG_TRACE_APPL1)
	    cerr << "ModList::selCB: Nothing selected" << endl;
#endif

	return;
	/*NOTREACHED*/
    }
    else if (!me->_allFlag) {

	obj = me->_list[id];
	oldCount = me->_selList[id];

#ifdef PCP_DEBUG
	if (pmDebug & DBG_TRACE_APPL1)
	    cerr << "ModList::selCB: Before Selected [" << id << "] = "
		 << *obj << endl 
		 << "oldCount = " << oldCount << ", _numSel = "
		 << me->_numSel << ", _allFlag = false" << endl; 
#endif

	me->_selList[id] = obj->select(path);

	me->_numSel += me->_selList[id] - oldCount;
	if (me->_numSel == 1)
	    me->_oneSel = id;
    }

    if (!me->_allFlag)
	(*(me->_selCB))(me, true);

    if (me->_selInvCB != NULL)
	(*(me->_selInvCB))(me, path);

#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL1) {
	cerr << "ModList::selCB: After Selected [" << id << "] " << endl
	     << "oldCount = " << oldCount << ", _numSel = "
	     << me->_numSel << ", _allFlag = " 
	     << (me->_allFlag == true ? "true" : "false") << ", _allId = "
	     << me->_allId << endl;
	cerr << "ModList::selCB: selection state:" << endl;
	me->dumpSelections(cerr);
    }
#endif
}
Example #10
0
wxThread::ExitCode ModderTask::TaskStart()
{
	// Get the mod list
	ModList *modList = m_inst->GetModList();
	
	wxFileName mcBin = m_inst->GetBinDir();
	wxFileName mcJar = m_inst->GetMCJar();
	wxFileName mcBackup = m_inst->GetMCBackup();
	
	// Nothing to do if there are no jar mods to install, no backup and just the mc jar
	if(mcJar.FileExists() && !mcBackup.FileExists() && modList->empty())
	{
		m_inst->SetNeedsRebuild(false);
		return (ExitCode)1;
	}
	
	SetStatus(_("Installing mods - backing up minecraft.jar..."));
	if (!mcBackup.FileExists() && !wxCopyFile(mcJar.GetFullPath(), mcBackup.GetFullPath()))
	{
		OnFail(_("Failed to back up minecraft.jar"));
		return (ExitCode)0;
	}
	
	if (mcJar.FileExists() && !wxRemoveFile(mcJar.GetFullPath()))
	{
		OnFail(_("Failed to delete old minecraft.jar"));
		return (ExitCode)0;
	}
	
	// TODO: good spot for user cancel check? or not...
	
	TaskStep(); // STEP 1
	SetStatus(_("Installing mods - Opening minecraft.jar"));

	wxFFileOutputStream jarStream(mcJar.GetFullPath());
	wxZipOutputStream zipOut(jarStream);

	// Files already added to the jar.
	// These files will be skipped.
	std::set<wxString> addedFiles;

	// Modify the jar
	TaskStep(); // STEP 2
	SetStatus(_("Installing mods - Adding mod files..."));
	for (ModList::const_reverse_iterator iter = modList->rbegin(); iter != modList->rend(); iter++)
	{
		wxFileName modFileName = iter->GetFileName();
		SetStatus(_("Installing mods - Adding ") + modFileName.GetFullName());
		if (iter->IsZipMod())
		{
			wxFFileInputStream modStream(modFileName.GetFullPath());
			wxZipInputStream zipStream(modStream);
			std::auto_ptr<wxZipEntry> entry;
			while (entry.reset(zipStream.GetNextEntry()), entry.get() != NULL)
			{
				if (entry->IsDir())
					continue;

				wxString name = entry->GetName();
				if (addedFiles.count(name) == 0)
				{
					if (!zipOut.CopyEntry(entry.release(), zipStream))
						break;
					addedFiles.insert(name);
				}
			}
		}
		else
		{
			wxFileName destFileName = modFileName;
			destFileName.MakeRelativeTo(m_inst->GetInstModsDir().GetFullPath());
			wxString destFile = destFileName.GetFullPath();

			if (addedFiles.count(destFile) == 0)
			{
				wxFFileInputStream input(modFileName.GetFullPath());
				zipOut.PutNextEntry(destFile);
				zipOut.Write(input);

				addedFiles.insert(destFile);
			}
		}
	}

	{
		wxFFileInputStream inStream(mcBackup.GetFullPath());
		wxZipInputStream zipIn(inStream);

		std::auto_ptr<wxZipEntry> entry;
		while (entry.reset(zipIn.GetNextEntry()), entry.get() != NULL)
		{
			wxString name = entry->GetName();

			if (!name.Matches("META-INF*") &&
				addedFiles.count(name) == 0)
			{
				if (!zipOut.CopyEntry(entry.release(), zipIn))
					break;
				addedFiles.insert(name);
			}
		}
	}
	
	// Recompress the jar
	TaskStep(); // STEP 3
	SetStatus(_("Installing mods - Recompressing jar..."));

	m_inst->SetNeedsRebuild(false);
	m_inst->UpdateVersion(true);
	return (ExitCode)1;
}