Python question ? - get the MOD name

Sto

Should i code today ...
Joined
Dec 15, 2005
Messages
1,144
Location
Marseille (France)
I try to get the mod name of the game without success ( to make some additonnal option for the mods i play into the map scripts ).

i try :

Code:
CyReplayInfo().getModName()

but this doesn't worked , i always get an empty string .

Any ideas ?

Thanks .
 
thank you :) , it's not into the API .

Tcho !
 
MatzeHH, are you sure about that? I just checked the SDK for both Warlords and vanilla and I don't see a getModName method in the global context class...
 
TheLopez said:
MatzeHH, are you sure about that? I just checked the SDK for both Warlords and vanilla and I don't see a getModName method in the global context class...

No, I'm not sure.

In CvReplayInfo the mod name is got with this line:
gDLL->getModName();
I think this could be used everywhere in the SDK.

Well, I think I was wrong about the global context, but it looks like it would be easy to add a new function to the global context passing gDLL->getModName() to python.

Matze
 
Another question along the same line:

How do I get which WBS file I'm using in a mod? EG: MaxRiga is one mod, but many WBS files. How do I find out which run is running?

Dale
 
I don t find anything . i tried to find the pathname of the file from wich "CvEventInterface" is imported (for an example) to extract the mod name from the string . But i can't get the prefix -> always "\Assets\Python\EntryPoi ..." .

So i will just try to use a specific function of the mod , and guess this is the good mod is there is no error .

Thanks all !

Dale : sorry , i can't help you . i even don't understand what you're looking for .
 
This isn't really a solution, more of a hack that another modder ended up using when he couldn't find a way to do what you're looking for:

DEG's ini parsing

It's what myself and TheLopez use to find and parse text config files from the mod folder. Check out CvPath for good ways to get to various civ folders, but the modname part really is a hack ... but it works.
 
jdog5000 said:
This isn't really a solution, more of a hack that another modder ended up using when he couldn't find a way to do what you're looking for:

DEG's ini parsing

It's what myself and TheLopez use to find and parse text config files from the mod folder. Check out CvPath for good ways to get to various civ folders, but the modname part really is a hack ... but it works.

Thanks ! :) that s right that was not a good solution . i will check that soon .

Tcho !
 
Meanwhile, I tried gDLL->getModName() within the SDK.
It returns a string with "mods\modname".
That should be enough to deal with.
Everything what is to do, is making a function in the global context which passes this to python.

Matze
 
Because i want to adapt the map script for a specific MOD ( and don't want to make a script for each MOD )... i can't mod . i'm restricted to python functions . I m also curious to know why CyReplayInfo().getModName() always give me an empty string , but i just begin to learn C++ and it's not a priority .

Thanks ! :)
 
jdog5000 said:
This isn't really a solution, more of a hack that another modder ended up using when he couldn't find a way to do what you're looking for:

DEG's ini parsing

It's what myself and TheLopez use to find and parse text config files from the mod folder. Check out CvPath for good ways to get to various civ folders, but the modname part really is a hack ... but it works.

Just for info :

I check CvPath : here how to get the MOD Name

Code:
activeModName = None
try:
    import CvModName
    activeModName = CvModName.modName
except:
    pass

and like written into the file : this need an extra python file into the mod named CvModName.py with modName="MOD name string"

I tried with several mods : some have no CvModName.py , and even one have an error (the mod name is not a string) .

I think the better way is now to check for some XML values specific to the MOD . Since i can't achieve to get the prefix of the file with regular python function . And if the famous Dr Elmer Jiggle find no other solution , there is probably no solution i can find .

Tcho !
 
For info :

I achieve to get the MOD name at the launch of civ4 like this :

this method bugs : C++ exeption

Code:
        CyReplay=CyGlobalContext().getGame().getReplayInfo()
        CyReplay.__init__()
        CyReplay.createInfo(-1)
        modName=CyReplay.getModName()

But i don't know i that may cause problems with CvReplayInfo() ... i will test a game to see if replay infos are not disfunctional . But i don't think , any ideas ?

Tcho !
 
After a game , i get no problem with replay info . But the function can't be called more than one time after the launching of Civ4 . I will make some more test with CyReplayInfo() to be sure that nothing is altered since i don't understand all in the C++ part .
 
I achieve to get the Mod Name of the current mod searching into the cache folder (not tested with warlords folder) . I get a valid mod name for every test i've done , return '' if there is no Mod loaded :

Code:
import os
import _winreg

def getMod():                
        try:
                civFolder = os.path.basename(regRead(_winreg.HKEY_LOCAL_MACHINE,"Software\\Firaxis Games\\Sid Meier's Civilization 4","INSTALLDIR"))
                cacheFolder=os.path.join(os.environ['APPDATA'],"My Games",civFolder,"cache")
                listFiles=os.listdir(cacheFolder)
                modName=""
                modFound=False
                for dFile in listFiles:
                        if modFound:break
                        Sfile=open(os.path.join(cacheFolder,dFile),"r")
                        fileString=Sfile.read()
                        textSplit=fileString.split("\\")
                        for item in textSplit :
                                if modFound :
                                        modName=item
                                        break
                                if "mods" in item:
                                        modFound=True
                        Sfile.close()
                print repr(modName)
        except:
                print " Error : getMod()"

# Dr Elmer Jiggle 's fuction .
def regRead(registry, path, field):
        pathKey = _winreg.OpenKey(registry, path)
        try:
                fieldValue = _winreg.QueryValueEx(pathKey, field)
                return fieldValue[0]
        finally:
                pathKey.Close()

I get problems to extract the mod name ( i don't understand very well encoding stuff ). Any commentary to help me to know if this method is valid ?

Tcho !
 
After some test , with enabling cache system and switching between MOD... the function don't return a good Mod Name , so this function is not valid . :cry:


Tcho !

Edit : I was achieved to make sure that "mods" was taken from a file path ... :cry: :cry:
 
One year later , i think i get it :) ... perhaps because of the recent updates , it's possible to force a dummy replayInfo . The code is just tested in SP games (vanilla , BtS) and i get no problem with replay infos and active players , i found no reason in the SDK that can make a problem . This probably need to be tested in MP (every different MP games ) . This work on initialization and during the map generation , i don't know if this work in game .So this can be use full for a map script to know which MOD you are running .

Code:
                replayInfo = CyReplayInfo()
                game = CyGame()
                iActivePlayer = game.getActivePlayer()

                if iActivePlayer != -1 : game.setActivePlayer(-1, False)
                replayInfo.createInfo(-1)
                if iActivePlayer != -1 : game.setActivePlayer(iActivePlayer, False)

                modName = replayInfo.getModName()

I hope this works with MP games . Tell me if you have a use of that .

Tcho !

Edit : After some tests , i've got no problem in SP and MP games . However this can be used only on initialization and during map generation ( for no HotSeat and no Pbem MP games ) . This don't work once the graphics are initialized .
 
Top Bottom