How to get path to mod?

Started by lietu, October 03, 2016, 08:46:11 AM

Previous topic - Next topic

lietu

I would like to bundle certain kinds of assets that will be used outside of the defs with my mod, and I need to get the full path to those assets from within my code.

I've tried various methods from Google for getting the path of the currently executing assembly, etc., but everything seems to fail. I assume this is due to the way the .dll files are loaded, but I don't know enough about C# really to be sure.

I tried a bunch of things from e.g. http://stackoverflow.com/questions/52797/how-do-i-get-the-path-of-the-assembly-the-code-is-in but the results seem to end up with e.g. an empty string, or path of the .exe, or some odd non-existing path under steamapps/common, etc.

Is there some trick I could do to find the path to the mod? E.g. check list of currently loaded mods and find the mod itself from that list, or some such?

skullywag

I think what you are asking for is possible, but before we go into that what exactly are you trying to do? rimworld has a load of methods available for loading the types of assets it uses (textures, sounds etc).
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

lietu

I'm building an informational overlay tool for streamers. Think Xbox achievement -like popups on live streams, saying stuff like


  • Your colony now has 8 people.
  • The eclipse lasted 14 hours.
  • You have food for 3 days.

What I'm hoping, to make it as convenient as possible for users, is to bundle the HTML, CSS, JS, etc. assets with the mod, and provide a configuration interface in-game, so users would only have to enable the mod, and then point their browser source in OBS/Xsplit/similar to the correct URL and have their overlay work.

So, this would be used to host those assets that are relevant to the mod, but external to the game itself.

theubie

GenFilePaths has a CoreModsFolderPath method.  I'd start there.  See what it returns and then see if you can massage the data it gives you to be relevant to your mod's location.

skullywag

Might be some stuff in Verse.ModContentPack or Verse.ModMetaData you can use to achieve this.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

RawCode

check GenFilePaths class, it have everything you may need.

lietu

#6
I ended up using the following:

ModLister.AllInstalledMods.First(x => x.Name == "MyModName").RootDir.ToString()