119 lines
6.7 KiB
C#
119 lines
6.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Harmony.WorldBiomesPatches
|
|
{
|
|
|
|
[HarmonyPatch(typeof(WorldBiomes))]
|
|
[HarmonyPatch("readXML")]
|
|
public class readXMLPatch
|
|
{
|
|
public static bool Prefix(WorldBiomes __instance, XDocument _xml, bool _instantiateReferences)
|
|
{
|
|
Array.Clear((Array)__instance.m_Id2BiomeArr, 0, __instance.m_Id2BiomeArr.Length);
|
|
__instance.m_Color2BiomeMap.Clear();
|
|
__instance.m_Name2BiomeMap.Clear();
|
|
if (BiomeDefinition.nameToId == null)
|
|
BiomeDefinition.nameToId = new Dictionary<string, byte>();
|
|
foreach (XElement descendant in _xml.Descendants((XName)"biomemap"))
|
|
{
|
|
string attribute = descendant.GetAttribute((XName)"name");
|
|
if (!BiomeDefinition.nameToId.ContainsKey(attribute))
|
|
BiomeDefinition.nameToId.Add(attribute, byte.Parse(descendant.GetAttribute((XName)"id")));
|
|
}
|
|
foreach (XElement descendant in _xml.Descendants((XName)"biome"))
|
|
{
|
|
string attribute = descendant.GetAttribute((XName)"name");
|
|
if (!BiomeDefinition.nameToId.ContainsKey(attribute))
|
|
throw new Exception("Parsing biomes. Biome with name '" + attribute + "' also needs an entry in the biomemap");
|
|
BiomeDefinition biome = __instance.parseBiome(BiomeDefinition.nameToId[attribute], (byte)0, attribute, descendant, _instantiateReferences);
|
|
__instance.m_Id2BiomeArr[(int)biome.m_Id] = biome;
|
|
__instance.m_Color2BiomeMap.Add(biome.m_uiColor, biome);
|
|
__instance.m_Name2BiomeMap.Add(biome.m_sBiomeName, biome);
|
|
}
|
|
BiomeParticleManager.RegistrationCompleted = true;
|
|
foreach (XContainer descendant1 in _xml.Descendants((XName)"pois"))
|
|
{
|
|
foreach (XElement descendant2 in descendant1.Descendants((XName)"poi"))
|
|
{
|
|
uint uint32 = Convert.ToUInt32(descendant2.GetAttribute((XName)"poimapcolor").Substring(1), 16);
|
|
int _iSO = 0;
|
|
int num = 0;
|
|
int _iST = 0;
|
|
if (descendant2.HasAttribute((XName)"surfaceoffset"))
|
|
_iSO = Convert.ToInt32(descendant2.GetAttribute((XName)"surfaceoffset"));
|
|
if (descendant2.HasAttribute((XName)"smoothness"))
|
|
{
|
|
int int32 = Convert.ToInt32(descendant2.GetAttribute((XName)"smoothness"));
|
|
num = int32 < 0 ? 0 : int32;
|
|
}
|
|
if (descendant2.HasAttribute((XName)"starttunnel"))
|
|
{
|
|
int int32 = Convert.ToInt32(descendant2.GetAttribute((XName)"starttunnel"));
|
|
_iST = int32 < 0 ? 0 : int32;
|
|
}
|
|
BlockValue _blockValue1 = BlockValue.Air;
|
|
if (descendant2.HasAttribute((XName)"blockname"))
|
|
_blockValue1 = _instantiateReferences ? __instance.getBlockValueForName(descendant2.GetAttribute((XName)"blockname")) : BlockValue.Air;
|
|
BlockValue _blockBelow = BlockValue.Air;
|
|
if (descendant2.HasAttribute((XName)"blockbelow"))
|
|
_blockBelow = _instantiateReferences ? __instance.getBlockValueForName(descendant2.GetAttribute((XName)"blockbelow")) : BlockValue.Air;
|
|
int _ypos = -1;
|
|
if (descendant2.HasAttribute((XName)"ypos"))
|
|
_ypos = int.Parse(descendant2.GetAttribute((XName)"ypos"));
|
|
int _yposFill = -1;
|
|
if (descendant2.HasAttribute((XName)"yposfill"))
|
|
_yposFill = int.Parse(descendant2.GetAttribute((XName)"yposfill"));
|
|
PoiMapElement poiMapElement = new PoiMapElement(uint32, descendant2.GetAttribute((XName)"prefab"), _blockValue1, _blockBelow, _iSO, _ypos, _yposFill, _iST);
|
|
__instance.m_PoiMap.Add(uint32, poiMapElement);
|
|
foreach (XElement element in descendant2.Elements())
|
|
{
|
|
if (element.Name == (XName)"decal")
|
|
{
|
|
int int32_1 = Convert.ToInt32(element.GetAttribute((XName)"texture"));
|
|
BlockFace int32_2 = (BlockFace)Convert.ToInt32(element.GetAttribute((XName)"face"));
|
|
float _prob = StringParsers.ParseFloat(element.GetAttribute((XName)"prob"));
|
|
poiMapElement.decals.Add(new PoiMapDecal(int32_1, int32_2, _prob));
|
|
}
|
|
if (element.Name == (XName)"blockontop")
|
|
{
|
|
BlockValue _blockValue2 = _instantiateReferences ? __instance.getBlockValueForName(element.GetAttribute((XName)"blockname")) : BlockValue.Air;
|
|
float _prob = StringParsers.ParseFloat(element.GetAttribute((XName)"prob"));
|
|
|
|
if (element.GetAttribute((XName)"blockname") == "carsRandomHelperBiome")
|
|
{
|
|
string name = descendant2.GetAttribute((XName)"name");
|
|
float multiplier = 1;
|
|
|
|
if (name == "City Asphalt")
|
|
{
|
|
multiplier = 2.67f;
|
|
}
|
|
else if (name == "Country Road Asphalt")
|
|
{
|
|
multiplier = 1.335f;
|
|
}
|
|
else if (name == "Road Gravel")
|
|
{
|
|
multiplier = 1f;
|
|
}
|
|
|
|
//Log.Out("WorldBiomesPatches-readXML name: " + name);
|
|
//Log.Out("WorldBiomesPatches-readXML BEFORE _prob: " + _prob);
|
|
//Log.Out("WorldBiomesPatches-readXML multiplier: " + multiplier);
|
|
_prob = _prob * multiplier * (float.Parse(RebirthVariables.customVehicleDensityMultiplier) / 100);
|
|
//Log.Out("WorldBiomesPatches-readXML AFTER _prob: " + _prob);
|
|
}
|
|
|
|
int _offset = element.HasAttribute((XName)"offset") ? int.Parse(element.GetAttribute((XName)"offset")) : 0;
|
|
poiMapElement.blocksOnTop.Add(new PoiMapBlock(_blockValue2, _prob, _offset));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|