Modding SelectDifficulty.lua to refresh the difficulty list in Basic game setup

Darn, that's really disappointing. I was convinced I had an acceptable workaround. I guess the only way to be sure that a user of my mod sees the new difficulties in the basic game setup is if I block Mongolia or something, as Pazyryk suggested. That may be fine for his Fantasy mod, but not for my general difficulty mod.

Oh well, I may block G&K anyway (and release an alternative version as above), just because I *really* would like my stuff visible on the basic setup screen, if at all possible.
 
EA also depends on ...
Aghhhh... that looks so much like Electronic Arts. I don't mind when folks miss the É. After all, Macintosh solved the difficult technology for that back in '84 (iirc) with a simple Option-e before the letter. Microsoft, on the other hand, requires you (you, that is, if you are in the US) to muck around in control panel keyboard settings, or somehow remember Alt+0201.

Please carry on now... this is a non-serious post.
 
Sorry to bring this up again, but I have a similar problem that appears related to the auto-block DLC bug/feature. This time the issue isn't Lua execution, but some kind of database refresh. Here's the context, in three steps.

1. I have a difficulty mod for BNW. My custom difficulties are working, but by default they can only be selected via Advanced Setup. See the mod in post #1 of this thread, which adds dummy difficulties Hello and World! after Deity. (The Lua in that mod is never loaded, so just ignore it.)

2. As mentioned in previous posts, I want my custom difficulty levels on the basic setup screen. This is possible using auto-block DLC if I block G&K in my mod. Users who don't have G&K installed will need to use Advanced Setup to set difficulty. Additionally, I want to remove the standard difficulty levels (Settler - Deity). Deleting standard difficulties would lead to a crash-to-desktop when starting the game, but following the advice here and reindexing HandicapInfos using SQL avoids a crash. This works perfectly provided that G&K is installed and can be auto-blocked, see attached mod below.

3. However, if G&K isn't installed, the SQL update somehow screws up the stuff that was working in step 1 - no more custom difficulties in Advanced setup. Try it by loading my test mod again with G&K disabled.

Why does this get messed up? I assume that auto-block DLC not only triggers a reload of Lua code, but also somehow refreshes the database. Strangely (for me), only deletions require this refresh. Inserts work anyway, as evidenced by the XML additions.

On the bright side, the problem occurs in Advanced Setup - which is moddable with Lua. Can I trigger this mysterious refresh myself in Lua somehow?
 

Attachments

  • MC Hello World Again.civ5mod
    1.9 KB · Views: 79
Not dug into the specifics of this, but there is a related problem in that you can no longer update certain tables via direct sql statements in Lua in the "pre-game" (ie front end menus) and get them to take immediate effect - which prior to one of the "multi-player improvement" patches you could.

Basically the pre-game didn't cache the database, but always read directly from the tables. That changed in the patch. I suspect the difficulties are getting cached, you're modding the db, the cached values are being used, and then when the game starts something is not matching up between the cached pre-game value and the value read from the db in the game setup and that's causing a crash.
 
Yes, it seems you're right (not that I doubted it). Here is some of the relevant code from CvPreGame.cpp, with an explanation of why they did this:

Spoiler :
Code:
void setHandicap(PlayerTypes p, HandicapTypes h)
{
	if(p >= 0 && p < MAX_PLAYERS){
		s_handicaps.setAt(p, h);

		if(slotStatus(p) == SS_TAKEN){
			//Cache the handicap of human players.  
			//We do this so we can recall the human handicap setting if the human player happens to disconnect and get replaced by an ai.
			setLastHumanHandicap(p, h);
		}
	}
}

void setLastHumanHandicap(PlayerTypes p, HandicapTypes h)
{
	if(p >= 0 && p < MAX_PLAYERS){
		s_lastHumanHandicaps.setAt(p, h);
	}
}
Spoiler :
Code:
void VerifyHandicap(PlayerTypes p)
{//Verifies that the current handicap is valid for the current player.
	//non-ai players can't use the default ai handicap and ai players MUST use it.
	if(slotStatus(p) == SS_COMPUTER){
		setHandicap(p, (HandicapTypes)GC.getAI_HANDICAP());
	}
	else if(handicap(p) == GC.getAI_HANDICAP()){
		if(lastHumanHandicap(p) != NO_HANDICAP){
			setHandicap(p, lastHumanHandicap(p));
		}
		else if(GC.getGame().isNetworkMultiPlayer()){
			setHandicap(p, (HandicapTypes)GC.getMULTIPLAYER_HANDICAP());
		}
		else{
			setHandicap(p, (HandicapTypes)GC.getSTANDARD_HANDICAP());
		}
	}
}
The big question for me is still: is there some way to manually trigger from Lua the refresh/reload/recache that takes place when a DLC is auto-blocked?
 
is there some way to manually trigger from Lua the refresh/reload/recache that takes place when a DLC is auto-blocked?

I doubt it. There is no "reload cache from db" method in the game core that we do have access to (I happen to know that as I had to write one!), so I very much doubt there is any way to reload the VFS (which is in code we don't have access to) - especially as the Lua code that would trigger such an event would itself be in the VFS which may not survive the reload ... CTD here we come!
 
Silly me, there was a much simpler solution. Since AdvancedSetup.lua is moddable and the auto-block DLC trick makes modding SelectDifficulty.lua possible, I no longer have to delete anything from the database. I can just mod the difficulty lists to only show my custom stuff.

A simple one-line edit to both Lua files, and everything works. Off to post my mod now, thanks for all your help!
 
So what did you do in the end to get it all working? Block Mongolia? I haven't gotten around to testing this in my mod yet. Remember that some players have never bought any DLC other than the expansions (I'm close to that, as I only have Babylon).

The only problem left now is that I would like my mod to work with all DLC ... :)
Assuming that the above was your solution, just re-add Mongolia as Mod content.

Adding DLC as mod content would normally be frowned upon. But here you are only adding it because you had to block it, and the mod only works if the user had it in the first place so that you could block it. And it's free unless the user stole Civ5. A bit confusing but I think the ethics are on you side.


Edit: Blocking G&K looses you 9 civs, doesn't it? Or were these all included with BNW?
 
Interesting ethical dilemma there. :) I never realized that I could re-add a blocked civ in the mod. I didn't need to, but I'll remember this idea in the future. Since I was doing a mod for BNW I ended up blocking G&K, which as far as I can tell has absolutely zero effect on available content or gameplay [see edit!!!]. But please let me know if you have evidence to the contrary!

As I explain in the mod announcement (see my signature), the auto-block DLC trick makes my custom difficulties appear on the basic setup screen for users who have G&K installed, but users with BNW only will have to use advanced setup to select them. Blocking G&K also lets me mod SelectDifficulty.lua to add a tiny bit more polish (by hiding the standard difficulties). I do the same thing in AdvancedSetup.lua, but this file is moddable anyway.

EDIT - Oh crap, you're completely right. I don't know how I missed this yesterday, but 8 or 9 civs are missing. :( I'll have to think about blocking Mongolia now. Even if I don't re-add it, it's better to lose one civ than 8-9 ...
 
Suppose I did enter the ethical gray zone by including Mongolia within my mod. You could argue (actually you already did) that this would be an acceptable form of bending the rules, but wouldn't that make me 100% guilty of redistributing Firaxis copyrighted content anyway? Sure, a Civ pirate almost certainly has access to Mongolia already, but in theory someone who didn't have it could just extract it from my mod. I could easily see bad things happening to me if I went down this path. For example, getting flagged as a pirate myself and getting banned from the Steam workshop, or maybe even Civfanatics ...

Anyone in the know want to weigh in on this?
 
Third post in a row - do I get an achievement for that? :)

I almost dare not suggest it, because I've misled myself several times already in this thread - but I may have a solution that works for BNW mods. It all hinges on the "Upgrade 1" DLC. More specifically:

  • Is it widespread? Does "almost everyone" have it? Or at least everyone with BNW?
  • Is it really FREE, as it says in the .Civ5Pkg file?
  • Can it be safely blocked without affecting anything for people with BNW (except the fixable TXT_KEY issue noted below)?
First of all, I'm not really sure what this DLC does. Peeking in the folders, it seems to add Cow, Pearls and Stone resources, Stone Quarry and Trading Post improvements, some region-specific Forest and Jungle textures, and other miscellaneous stuff - all of which seem to be included in BNW.

If I block it in my mod, the auto-block DLC trick works, and the only side effect I notice is that I lose some TXT_KEYs for the Explorers and Scrambled Continents map pack DLCs and for three natural wonders (El Dorado, Potosi and Fountain of Youth). But only the TXT_KEYs are lost, not the maps & natural wonders themselves. So these TXT_KEYs can be easily restored in a mod, with hopefully negligible copyright infringement concerns.

So, what about my three bullet points? Please tell me I'm on to something this time ...
 
I can't answer your questions about "Upgrade 1" DLC ... you know more than I do.

On the ethics of adding Mongolia (or Upgrade 1 content) as mod, it's really very simple: it's free so don't worry about it. The mechanics of the situation are so convoluted that I couldn't help making fun of it.
 
I blocked Upgrade1 in my mod ,add in text files,and played a map in Scrambled Continents .The mod runs correctly and no TEXT_KEY remains.However,the game crashed when I quit to the main menu.Tried <delete>&<row>,<Update> and <Replace> and the results are the same

Anyone could find a solution?
 
"Upgrade 1" (in the DLC/Shared sub-dir) contains way more than just text/data updates, so it doesn't surprise me the game crashes without it

Code:
  <TextData>CIV5GameTextInfos_Civilopedia_NaturalWonders.xml</TextData>
  <TextData>CIV5GameTextInfos_Objects_NaturalWonders.xml</TextData>
  <TextData>CIV5GameTextInfos_DLC_SP_Maps.xml</TextData>
  <TextData>CIV5GameTextInfos_DLC_SP_Maps_2.xml</TextData>
  <TextData>CIV5GameTextInfos_DLC_SP_Maps_3.xml</TextData>

  <GameData>Civ5ArtDefines_SV_Shared_Features.xml</GameData>
  <GameData>Civ5ArtDefines_SV_Shared_Resources.xml</GameData>  
	
  <VisEffectInfoDefines>Civ5ArtDefines_VisEffects_Shared.xml</VisEffectInfoDefines>
  <VisEffectParticleDefines>Civ5ArtDefines_VisEffectParticles_Shared.xml</VisEffectParticleDefines>
  <VisEffectModelDefines>Civ5ArtDefines_VisEffectModels_Shared.xml</VisEffectModelDefines>

  <AudioScripts3D>Audio3DScriptsDLCShared.xml</AudioScripts3D>
  <AudioDefines>AudioDefinesDLCShared.xml</AudioDefines>
	
  <LandmarkDefines>Civ5ArtDefines_LandmarkTypes_Upgrade1.xml</LandmarkDefines>
  <LandmarkDefines>Civ5ArtDefines_Landmarks_Upgrade1.xml</LandmarkDefines>

  <Paks>
    <File>Upgrade1Models.fpk</File>
    <File>Upgrade1Textures.fpk</File>
  </Paks>
 
Yes, but the question is how much of the content in Upgrade 1 is duplicated in BNW? Cattle, pearls and stone resources and improvements work fine when I block Upgrade 1, as do the three new natural wonders.

Roughly 10% of poll responders in this thread claim to have BNW but not Upgrade 1. If they are correct then Upgrade 1 isn't critical, but they could be mistaken.

I guess more testing is needed to figure out exactly what causes the crashes.
 
Well the information must be shared, however late. Following this thread I had success refreshing the menus by blocking the Explorer's Map Pack, which I'd say is safer than blocking Upgrade 1, and you can easily re-add the said maps with your mod. A late thanks to everyone in this thread!
 
Top Bottom