public static void ApplyOptions() { try { foreach (var w in UnityEngine.Object.FindObjectsOfType <WaterBiomeManager>()) { w.Rebuild(); } QualitySettings.masterTextureLimit = 4 - config.TextureQuality; foreach (var s in UnityEngine.Object.FindObjectsOfType <WaterSunShaftsOnCamera>()) { s.enabled = config.LightShafts; } if (!config.VariablePhysicsStep) { Time.fixedDeltaTime = 0.02f; Time.maximumDeltaTime = 0.33333f; Time.maximumParticleDeltaTime = 0.03f; } config.Save(); } catch (Exception e) { Logger.Log(Logger.Level.Error, msg: "Reload failed with Exception: \n", ex: e); } }
//private List<RecipeOverride> defaultRecipeOverrides public bool TryOverrideRecipe(TechType fragment, out TechData outRecipe) { string sFragment = fragment.ToString(); foreach (RecipeOverride r in RecipeOverrides) { if (sFragment == r.overridden) { outRecipe = new TechData(); foreach (StringIngredient s in r.replacements) { if (Enum.TryParse <TechType>(s.techType, out TechType t)) { outRecipe.Ingredients.Add(new Ingredient(t, s.amount)); } else { #if !RELEASE Logger.Log(Logger.Level.Error, $"Could not parse {s.techType} as TechType; check the spelling and/or case"); #endif outRecipe = null; return(false); } } return(true); } } outRecipe = null; return(false); }
public bool AddTank(TechType tank, float baseCapacity, Sprite sprite = null, bool bUpdate = false, bool bUnlockAtStart = false) { if (TankTypes == null) { TankTypes = new Dictionary <TechType, TankType>(); } //if (TankTypes[i].tankTechType == tank) if (TankTypes.TryGetValue(tank, out TankType tt)) { if (bUpdate) { #if !RELEASE Logger.Log(Logger.Level.Debug, $"Updating tank type for TechType '{tank.AsString()}' with value {baseCapacity}"); #endif TankTypes[tank].UpdateCapacity(baseCapacity); } return(false); } #if !RELEASE Logger.Log(Logger.Level.Debug, $"Adding Tank '{tank.AsString()}' with capacity of {baseCapacity}"); #endif TankTypes[tank] = new TankType(tank, baseCapacity, bUnlockAtStart: bUnlockAtStart); return(true); }
public bool TrySubstituteIngredient(TechType tech, out List <Ingredient> Substitutes) { Substitutes = new List <Ingredient>(); for (int i = 0; i < SubstitutionList.Count; i++) { if (tech.ToString() == SubstitutionList[i].replacedTech) { //for (int j = 0; j < SubstitutionList[i].replacements.Count; j++) foreach (StringIngredient si in SubstitutionList[i].replacements) { if (Enum.TryParse <TechType>(si.techType, out TechType tt)) { Substitutes.Add(new Ingredient(tt, si.amount)); } else { #if !RELEASE Logger.Log(Logger.Level.Error, $"Failed to parse string '{si.techType}' as TechType; check to make sure the entry is spelled correctly, and using the correct case"); #endif } } //Substitutes = SubstitutionList[i].replacements; return(Substitutes.Count > 0); // It's possible every single entry in the list failed to parse; we don't want to return true in that instance. But this condition is an easy fix. } } // We only get this far if the tech to be replaced doesn't match this object's replacedTech. Substitutes = null; return(false); }
public static void Patch() { Logger.Log(Logger.Level.Info, "Patched successfully!"); /// Here we are registering a console command by use of a delegate. The delegate will respond to the "delegatecommand" /// command from the dev console, passing values following "delegatecommand" as the correct types, provided they can be /// parsed to that type. For example, "delegatecommand foo 3 true" would be a valid command for the /// <see cref="MyCommand"/> delegate signature. You can also use Func or Action to define your delegate signatures /// if you prefer, and you can also pass a reference to a method that matches this signature. /// /// Registered commands must be unique. If another mod has already added the command, your command will be rejected. /// /// If the user enters incorrect parameters for a command, they will be notified of the expected parameter types, /// both on-screen and in the log. /// /// Note that a command can have a return type, but it is not necessary. If it does return any type, it will be printed /// both on-screen and in the log. ConsoleCommandsHandler.Main.RegisterConsoleCommand <MyCommand>("delegatecommand", (myString, myInt, myBool) => { return($"Parameters: {myString} {myInt} {myBool}"); }); /// Here we are registering all console commands defined in <see cref="ExampleMod"/>, defined by decorating them /// with the <see cref="ConsoleCommandAttribute"/>. See <see cref="MyAttributedCommand(string, int, bool)"/> below /// for an example. ConsoleCommandsHandler.Main.RegisterConsoleCommands(typeof(ExampleMod)); }
private void Start() { _light = GetComponentInChildren <Light>(true); _renderers = transform.GetChild(0).GetComponentsInChildren <Renderer>(true); _particleRenderer = _renderers.First(r => r.material.shader.name.Contains("Particle")); PrefabIdentifier prefabIdentifier = GetComponentInParent <PrefabIdentifier>(); if ((prefabIdentifier ??= GetComponent <PrefabIdentifier>()) is null) { return; } string saveFolder = Main.GetSaveFolderPath(); string filePath = Main.Combine(saveFolder, prefabIdentifier.Id + ".json"); if (File.Exists(filePath)) { ColorInfo colorInfo; using (StreamReader reader = new StreamReader(filePath)) { var serializer = new JsonSerializer(); colorInfo = serializer.Deserialize(reader, typeof(ColorInfo)) as ColorInfo; } if (colorInfo != null) { _savedColor = new Color(colorInfo.RedLevel, colorInfo.GreenLevel, colorInfo.BlueLevel); _dirty = true; return; } Logger.Log(Logger.Level.Warn, "colorInfo is null"); } }
private static bool LoadLanguageFile() { if (!File.Exists(languageFile)) { #if !RELEASE Logger.Log(Logger.Level.Error, "File does not exist"); #endif return(false); } JsonData jsonData; using (StreamReader streamReader = new StreamReader(languageFile)) { try { jsonData = JsonMapper.ToObject(streamReader); //Logger.Log(Logger.Level.Debug, $"Read JSON data of: {JsonConvert.SerializeObject(jsonData, Oculus.Newtonsoft.Json.Formatting.Indented)}"); } catch (Exception exception) { Debug.LogException(exception); return(false); } } foreach (string text in jsonData.Keys) { Main.vehiclePromptDict[text] = (string)jsonData[text]; } return(true); }
static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { List <CodeInstruction> codes = new(instructions); var pickupText = AccessTools.Method(typeof(ExosuitPatcher), nameof(PickupText)); bool found = false; for (int i = 0; i < codes.Count(); i++) { if (codes[i].opcode == OpCodes.Ldstr && (string)codes[i].operand == "PropulsionCannonToRelease") { codes.Insert(i + 5, new CodeInstruction(OpCodes.Ldarg_0)); codes.Insert(i + 6, new CodeInstruction(OpCodes.Call, pickupText)); found = true; break; } } if (found is true) { Logger.Log(Logger.Level.Debug, "Transpiler Succeeded!"); } else { Logger.Log(Logger.Level.Error, "Transpiler Failed."); } return(codes.AsEnumerable()); }
private static bool TryCreateModParticleParams(Workbench workbench) { if (modParticlesParams != null) { return(true); } try { var sparks = ((GameObject[])sparksField.GetValue(workbench))[0].GetComponent <ParticleSystem>(); originParticlesParams = new ParticleSystemParameters() { startColor = sparks.main.startColor }; modParticlesParams = new ParticleSystemParameters() { startColor = Config.BeamAlphaColor }; return(true); } catch (Exception e) { Logger.Log(Logger.Level.Error, null, e); return(false); } }
public void Activate() { spin = gameObject.FindChild("Blade Parent").EnsureComponent <TurbineSpin>(); powerSource = gameObject.EnsureComponent <PowerSource>(); powerSource.maxPower = QPatch.config.MaxPower; relay = gameObject.EnsureComponent <PowerRelay>(); relay.internalPowerSource = powerSource; relay.dontConnectToRelays = false; relay.maxOutboundDistance = 50; //relay.powerSystemPreviewPrefab = Resources.Load<GameObject>("Base/Ghosts/PowerSystemPreview.prefab"); if (relayPrefab != null) { PowerFX yourPowerFX = gameObject.AddComponent <PowerFX>(); yourPowerFX.vfxPrefab = relayPrefab.powerFX.vfxPrefab; yourPowerFX.attachPoint = gameObject.transform; relay.powerFX = yourPowerFX; } #if SUBNAUTICA Resources.UnloadAsset(powerRelay); #endif relay.UpdateConnection(); if (QPatch.config.TurbineMakesNoise) { SetupAudio(); } Logger.Log(Logger.Level.Debug, $"WindTurbine.Activate: end"); }
public bool InitSubstitutions() { if (SubstitutionList == null) { #if !RELEASE Logger.Log(Logger.Level.Warn, "No SubstitutionList found, setting default values"); #endif SubstitutionList = new List <SSubstitutionEntry>() { new SSubstitutionEntry( "AdvancedWiringKit", new List <StringIngredient> { new StringIngredient("Silver", 2), new StringIngredient("ComputerChip", 1) } ), new SSubstitutionEntry( "PlasteelIngot", new List <StringIngredient> { #if SUBNAUTICA_STABLE new StringIngredient("ScrapMetal", 2), new StringIngredient("Lithium", 1) #elif BELOWZERO new StringIngredient("ScrapMetal", 1), new StringIngredient("Lithium", 1) #endif }
// The gloves texture is used for the suit as well, on the arms, so we need to do something about that. // The block that generates the glove texture is sizable, so it's made into a function here. private static Material GetGloveMaterial(Shader shader, Material OriginalMaterial) { // if the gloves shader isn't null, add the shader //Logger.Log(Logger.Level.Debug, "Creating new brineGloveMaterial"); if (OriginalMaterial != null) { Material newMat = new Material(OriginalMaterial); // if the suit's shader isn't null, add the shader if (shader != null) { newMat.shader = shader; } // add the gloves main Texture when equipped //Logger.Log(Logger.Level.Debug, $"add the gloves main Texture when equipped"); newMat.mainTexture = Main.glovesTexture; // add the gloves illum texture when equipped //Logger.Log(Logger.Level.Debug, $"add the gloves illum texture when equipped"); newMat.SetTexture(ShaderPropertyID._Illum, Main.glovesIllumTexture); // add the gloves spec texture when equipped //Logger.Log(Logger.Level.Debug, $"add the gloves spec texture when equipped"); newMat.SetTexture(ShaderPropertyID._SpecTex, Main.glovesTexture); return(newMat); } else { #if !RELEASE Logger.Log(Logger.Level.Debug, "Default material not found while trying to create new brineGloveMaterial"); #endif } return(null); }
public static bool PreAllowedToAdd(Equipment __instance, ref bool __result, string slot, Pickupable pickupable, bool verbose) { //Log.LogDebug($"EquipmentPatches.PreAllowedToAdd(): __result = {__result}, slot = '{slot}'"); TechType objTechType = pickupable.GetTechType(); //Log.LogDebug($"EquipmentPatches.PreAllowedToAdd(): objTechType = {objTechType.AsString()}"); EquipmentType slotType = Equipment.GetSlotType(slot); if (slotType == EquipmentType.BatteryCharger && InventoryPatches.IsChip(objTechType)) { #if BELOWZERO EquipmentType eType = TechData.GetEquipmentType(objTechType); #else EquipmentType eType = CraftData.GetEquipmentType(objTechType); #endif if (eType == EquipmentType.Chip || eType == EquipmentType.BatteryCharger) { #if false Logger.Log("DEBUG: AllowedToAdd battery charger for " + objTechType.AsString(false)); #endif bool result = ((IItemsContainer)__instance).AllowedToAdd(pickupable, verbose); __result = result; return(false); } } return(true); }
private static bool TryCreateModParticleParams(Fabricator fabricator) { if (modParticlesParams != null) { return(true); } try { var sparksL = ((GameObject)sparksLFieldInfo.GetValue(fabricator)).GetComponent <ParticleSystem>(); originParticlesParams = new ParticleSystemParameters() { startColor = sparksL.main.startColor }; modParticlesParams = new ParticleSystemParameters() { startColor = Config.BeamAlphaColor }; return(true); } catch (Exception e) { Logger.Log(Logger.Level.Error, null, e); return(false); } }
public static void Load() { var assembly = Assembly.GetExecutingAssembly(); var harmony = Harmony.CreateAndPatchAll(assembly, $"MrPurple6411_{assembly.GetName().Name}"); var EasyCraft = AppDomain.CurrentDomain.GetAssemblies() .Where((x) => x.FullName.StartsWith("EasyCraft")) .FirstOrFallback(null); if (EasyCraft == null) { return; } var ClosestItemContainers = AccessTools.TypeByName("ClosestItemContainers"); if (ClosestItemContainers == null) { return; } containers = AccessTools.Property(ClosestItemContainers, "containers"); if (containers == null) { return; } var ClosestItemContainers_GetPickupCount = AccessTools.Method(ClosestItemContainers, "GetPickupCount"); var ClosestItemContainers_DestroyItem = AccessTools.Method(ClosestItemContainers, "DestroyItem"); if (ClosestItemContainers_GetPickupCount == null || ClosestItemContainers_DestroyItem == null) { return; } harmony.Patch(ClosestItemContainers_GetPickupCount, prefix: new HarmonyMethod(typeof(ClosestItemContainers_Patches), nameof(ClosestItemContainers_Patches.ClosestItemContainers_GetPickupCount_Prefix))); harmony.Patch(ClosestItemContainers_DestroyItem, prefix: new HarmonyMethod(typeof(ClosestItemContainers_Patches), nameof(ClosestItemContainers_Patches.ClosestItemContainers_DestroyItem_Prefix))); Logger.Log(Logger.Level.Info, "Successfully Patched EasyCraft Methods."); }
internal void Init() { if (NewScannables == null) { #if !RELEASE Logger.Log(Logger.Level.Debug, $"NewScannables list is null, initialising defaults"); #endif NewScannables = new List <TechType>() // List of TechTypes to add ResourceTrackers to, if they don't have one already. { TechType.BasaltChunk, TechType.BaseFiltrationMachine, TechType.BatteryChargerFragment, TechType.Bleeder, TechType.Crabsnake, TechType.CrabSquid, TechType.SeaCrown, TechType.Warper }; } if (NonScannables == null) { #if !RELEASE Logger.Log(Logger.Level.Debug, $"NonScannables list is null, initialising defaults"); #endif NonScannables = new List <TechType>() // For any object whose TechType is on this list, its ResourceTracker, if it has one, should be removed. { TechType.Wreck }; } }
private static void CreateAndPatchPacks() { Logger.Log(Logger.Level.Info, "Started Patching BioPlasma MK2"); var bioPlasma = new BioPlasma(); bioPlasma.Patch(); Logger.Log(Logger.Level.Info, "Finished Patching BioPlasma MK2"); var bioChemBattery = new CbBattery() { ID = "BioChemBatteryMK2", Name = "Biochemical Battery", FlavorText = "Alterra battery technology combined with a Warper power core makes for quite a potent renewable energy source.", EnergyCapacity = Config.BioChemBatteryEnergy, UnlocksWith = bioPlasma.TechType, CraftingMaterials = new List <TechType>() { bioPlasma.TechType, bioPlasma.TechType, TechType.Silver, TechType.Silver, TechType.Gold, TechType.Lead }, CustomIcon = new Atlas.Sprite(assetBundle.LoadAsset <Sprite>("BioChemBattery")), CBModelData = new CBModelData() { UseIonModelsAsBase = true, CustomTexture = assetBundle.LoadAsset <Texture2D>("BioChemBatteryskin"), CustomSpecMap = assetBundle.LoadAsset <Texture2D>("BioChemBatteryspec"), CustomIllumMap = assetBundle.LoadAsset <Texture2D>("BioChemBatteryillum"), }, }; bioChemBattery.Patch(); var bioChemCell = new CbPowerCell() { ID = "BioChemCellMK2", Name = "Biochemical Power Cell", FlavorText = "Alterra power cell technology combined with a Warper power core makes for quite a potent renewable energy source.", EnergyCapacity = Config.BioChemCellenergy, UnlocksWith = bioPlasma.TechType, CraftingMaterials = new List <TechType>() { bioChemBattery.TechType, bioChemBattery.TechType, TechType.Silicone }, CustomIcon = new Atlas.Sprite(assetBundle.LoadAsset <Sprite>("BioChemCell.png")), CBModelData = new CBModelData() { UseIonModelsAsBase = true, CustomTexture = assetBundle.LoadAsset <Texture2D>("BioChemCellskin"), CustomSpecMap = assetBundle.LoadAsset <Texture2D>("BioChemCellskin"), CustomIllumMap = assetBundle.LoadAsset <Texture2D>("BioChemCellillum") }, }; bioChemCell.Patch(); }
// Attempt to get the text for a vehicle prompt. // initialKey should be "Enter", "Exit" or "Leave", followed by "Seamoth", "Exosuit" or "Cyclops". Any other value will return false. public static bool TryGetVehiclePrompt(string initialKey, string targetLanguage, string VehicleName, out string prompt) { string targetKey = targetLanguage + initialKey; bool result; if (string.IsNullOrEmpty(VehicleName)) { prompt = Language.main.Get(initialKey); return(true); } else { result = vehiclePromptDict.TryGetValue(targetKey, out prompt); if (result) { prompt = prompt.Replace("<vehicle>", VehicleName); } #if !RELEASE Logger.Log(Logger.Level.Debug, $"Main.TryGetVehiclePrompt: got prompt value of {prompt} with key {targetKey}"); #endif } //return vehiclePromptDict.TryGetValue(targetKey, out prompt); return(result); }
private static void SetFabricatorLightColor(Fabricator fabricator, Color color) { try { fabricator.fabLight.color = color; } catch (Exception e) { Logger.Log(Logger.Level.Error, null, e); } }
public static void AddSubstitution(TechType substituted, TechType substitution) { Substitutions.Add(new TechTypeSub(substituted, substitution)); substitutionTargets.Add(substitution); #if !RELEASE Logger.Log(Logger.Level.Debug, $"AddSubstitution: Added sub with substituted {substituted.ToString()} and substitution {substitution.ToString()}, new count {Substitutions.Count}"); #endif }
public static bool TryGetResourceName(string uniqueId, out string resourceName) { bool result = IdToResourceNameDict.TryGetValue(uniqueId, out resourceName); QLogger.Log(QLogger.Level.Debug, $"Attempting to retrieve resource name for unique ID '{uniqueId}': Result is {result}" + (result ? $", retrieved string '{resourceName}'" : "")); return(result); }
private static void SetWorkbenchLightColor(Workbench workbench, Color color) { try { workbench.workingLight.GetComponent <Light>().color = color; } catch (Exception e) { Logger.Log(Logger.Level.Error, null, e); } }
private static void SetFabricatorBeamsMaterial(Fabricator fabricator, Material material) { try { fabricator.leftBeam.GetComponent <Renderer>().material = material; fabricator.rightBeam.GetComponent <Renderer>().material = material; } catch (Exception e) { Logger.Log(Logger.Level.Error, null, e); } }
public static void Load() { Logger.Log(Logger.Level.Info, "Started Patching"); Config.Load(); CreateAndPatchPacks(); Logger.Log(Logger.Level.Info, "Patching Complete"); }
private static GameObject SetupPrefab(GameObject activePrefab) { var obj = GameObject.Instantiate(activePrefab); if (obj == null) { return(null); } Knife knife = obj.GetComponent <Knife>(); VibrobladeBehaviour blade = obj.EnsureComponent <VibrobladeBehaviour>(); if (blade != null) { if (hbPrefab != null) { HeatBlade hb = hbPrefab.GetComponent <HeatBlade>(); blade.fxControl = hb.fxControl; blade.vfxEventType = hb.vfxEventType; } if (knife != null) { #if SUBNAUTICA_STABLE blade.attackSound = knife.attackSound; blade.underwaterMissSound = knife.underwaterMissSound; blade.surfaceMissSound = knife.surfaceMissSound; #endif blade.mainCollider = knife.mainCollider; blade.drawSound = knife.drawSound; blade.firstUseSound = knife.firstUseSound; blade.hitBleederSound = knife.hitBleederSound; if (hbPrefab == null) { blade.vfxEventType = knife.vfxEventType; } GameObject.DestroyImmediate(knife); } blade.attackDist = 2f; blade.damageType = DamageType.Normal; blade.socket = PlayerTool.Socket.RightHand; blade.ikAimRightArm = true; #if BELOWZERO blade.bleederDamage = 90f; #endif } else { #if !RELEASE Logger.Log(Logger.Level.Debug, $"Could not ensure VibrobladeBehaviour component in Vibroblade prefab"); #endif } ModPrefabCache.AddPrefab(obj, false); return(obj); }
public static void PostPatch() { if (HasNitrogenMod()) { TechType suitMk1 = TechTypeUtils.GetModTechType("AcidSuit"); TechType suitMk2 = TechTypeUtils.GetModTechType("NitrogenBrineSuit2"); TechType suitMk3 = TechTypeUtils.GetModTechType("NitrogenBrineSuit3"); #if !RELEASE Logger.Log(Logger.Level.Debug, $"Setting up Nitrogen suit TechTypes"); #endif if (suitMk2 != TechType.None) { Main.DamageResistances.Add(suitMk2, new List <DamageInfo> { new DamageInfo(DamageType.Acid, -0.6f) /*, * new DamageInfo(DamageType.Radiation, -0.70f)*/ }); Patches.EquipmentPatches.AddSubstitution(suitMk2, TechType.RadiationSuit); Patches.EquipmentPatches.AddSubstitution(suitMk2, TechType.ReinforcedDiveSuit); } else { #if !RELEASE Logger.Log(Logger.Level.Error, $"NitrogenBrinesuit2 techtype could not be found"); #endif } if (suitMk3 != TechType.None) { Main.DamageResistances.Add(suitMk3, new List <DamageInfo> { new DamageInfo(DamageType.Acid, -0.6f) /*, * new DamageInfo(DamageType.Radiation, -0.70f)*/ }); Patches.EquipmentPatches.AddSubstitution(suitMk3, TechType.RadiationSuit); Patches.EquipmentPatches.AddSubstitution(suitMk3, TechType.ReinforcedDiveSuit); } else { #if !RELEASE Logger.Log(Logger.Level.Error, $"NitrogenBrinesuit3 techtype could not be found"); #endif } if (NitroAddDiveSuit != null) { #if !RELEASE Logger.Log(Logger.Level.Debug, $"Found Nitrogen API, adding dive suits."); #endif NitroAddDiveSuit.Invoke(null, new object[] { suitMk1, 800f, 0.85f, 15f }); NitroAddDiveSuit.Invoke(null, new object[] { suitMk2, 1300f, 0.75f, 20f }); NitroAddDiveSuit.Invoke(null, new object[] { suitMk3, 8000f, 0.55f, 35f }); } } }
private static void SetFabricatorParticlesParams(Fabricator fabricator, ParticleSystemParameters @params) { try { var sparksL = ((GameObject)sparksLFieldInfo.GetValue(fabricator)).GetComponent <ParticleSystem>(); var sparksR = ((GameObject)sparksRFieldInfo.GetValue(fabricator)).GetComponent <ParticleSystem>(); @params.Apply(sparksL); @params.Apply(sparksR); } catch (Exception e) { Logger.Log(Logger.Level.Error, null, e); } }
private static void SetWorkbenchBeamsMaterial(Workbench workbench, Material material) { try { foreach (var beam in workbench.fxLaserBeam) { beam.GetComponent <Renderer>().material = material; } } catch (Exception e) { Logger.Log(Logger.Level.Error, null, e); } }
public static void Load() { if (!LoadLanguageFile()) { #if !RELEASE Logger.Log(Logger.Level.Error, $"Failed loading language file {languageFile}"); #endif } var assembly = Assembly.GetExecutingAssembly(); new Harmony($"DaWrecka_{assembly.GetName().Name}").PatchAll(assembly); }
/// <summary> /// Allows mods to adds their own custom batteries directly. The plugin pack will be patched and the modded battery data returned. /// </summary> /// <param name="packItem">The battery data.</param> /// <returns> /// A <see cref="CbItemPack" /> containing the patched <see cref="SMLHelper.V2.Assets.ModPrefab" /> intance for the battery requested. /// </returns> public CbItemPack PatchAsBattery() { string name = this.GetType().Assembly.GetName().Name; Logger.Log(Logger.Level.Info, $"Received Custom Battery pack from '{name}'"); var pack = new CbItemPack(name, this, ItemTypes.Battery); pack.Patch(); return(pack); }