Skip to content

Commit

Permalink
1.0.60.1241
Browse files Browse the repository at this point in the history
  • Loading branch information
SphereII committed Aug 24, 2024
1 parent 77453f3 commit dc34dc6
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Mods/0-SCore/0-SCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
<Compile Include="Scripts\ConsoleCmd\ConsoleCmdActionFireClear.cs" />
<Compile Include="Scripts\ConsoleCmd\ConsoleCmdAdjustCVar.cs" />
<Compile Include="Scripts\ConsoleCmd\ConsoleCmdReloadDialog.cs" />
<Compile Include="Scripts\ConsoleCmd\ConsoleCmdReloadSCore.cs" />
<Compile Include="Scripts\ConsoleCmd\ConsoleCmdUnitTestSCore.cs" />
<Compile Include="Scripts\ConsoleCmd\ConsoleCmdlock.cs" />
<Compile Include="Scripts\ConsoleCmd\ConsoleCmdUtilityAI.cs" />
Expand Down Expand Up @@ -348,6 +349,7 @@
<Compile Include="Scripts\Managers\SCoreQuestEventManager.cs" />
<Compile Include="Scripts\MinEvents\MinEventActionAddBuffByFactionSDX.cs" />
<Compile Include="Scripts\MinEvents\MinEventActionAddScriptToTransform.cs" />
<Compile Include="Scripts\MinEvents\MinEventActionAdjustTransformValues.cs" />
<Compile Include="Scripts\MinEvents\MinEventActionAnimatorFireTriggerSDX.cs" />
<Compile Include="Scripts\MinEvents\MinEventActionAnimatorSetFloatSDX.cs" />
<Compile Include="Scripts\MinEvents\MinEventActionAnimatorSetIntSDX.cs" />
Expand Down
46 changes: 44 additions & 2 deletions Mods/0-SCore/Features/ParticlesOnBlocks/Harmony/Blocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static string GetParticle(DynamicProperties classProperty, string key, V

// No particles at all? Boring.
if (string.IsNullOrEmpty(availableParticles)) return string.Empty;

// Check if the particles are comma delimited.
var particleArray = availableParticles.Split(',');
var randomIndex = _random.RandomRange(0, particleArray.Length);
Expand All @@ -68,6 +68,8 @@ private static bool CanPlaceParticle(DynamicProperties classProperty, string key
}
private static void CheckForParticle(Block block, Vector3i blockPos) {
if (!block.Properties.Classes.ContainsKey("Particles")) return;
if (!GameManager.Instance.World.GetBlock(blockPos + Vector3i.up).isair) return;

var particles = block.Properties.Classes["Particles"];
var particle = GetParticle(particles, "OnSpawnParticle", blockPos);
if (string.IsNullOrEmpty(particle)) return;
Expand All @@ -77,6 +79,25 @@ private static void CheckForParticle(Block block, Vector3i blockPos) {
}
}


// Reloading all the particles
[HarmonyPatch(typeof(Block))]
[HarmonyPatch("Init")]
public class BlockInit {
public static void Postfix(Block __instance) {
if (!__instance.Properties.Classes.ContainsKey("Particles")) return;
var particlesProperties = __instance.Properties.Classes["Particles"];
foreach (var property in particlesProperties.Values.dic)
{
if (!property.Value.Contains("modfolder")) continue;
foreach (var particle in property.Value.Split(','))
{
if (!ParticleEffect.IsAvailable(particle))
ParticleEffect.LoadAsset(particle);
}
}
}
}
[HarmonyPatch(typeof(Block))]
[HarmonyPatch("OnNeighborBlockChange")]
public class BlockOnNeighborBlockChange {
Expand All @@ -88,6 +109,22 @@ public static void Postfix(Block __instance, Vector3i _myBlockPos) {
[HarmonyPatch(typeof(Block))]
[HarmonyPatch("OnBlockUnloaded")]
public class BlockOnBlockUnloaded {
public static void Postfix(Block __instance, Vector3i _blockPos) {
BlockUtilitiesSDX.removeParticles(_blockPos);
}
}

[HarmonyPatch(typeof(Block))]
[HarmonyPatch("OnBlockLoaded")]
public class BlockOnBlockloaded {
public static void Postfix(Block __instance, Vector3i _blockPos) {
CheckForParticle(__instance, _blockPos);
}
}

[HarmonyPatch(typeof(Block))]
[HarmonyPatch("OnBlockAdded")]
public class BlockOnBlockAdded {
public static void Postfix(Block __instance, Vector3i _blockPos) {
CheckForParticle(__instance, _blockPos);
}
Expand All @@ -105,7 +142,12 @@ public static void Postfix(Block __instance, Vector3i _blockPos) {
[HarmonyPatch(typeof(Block))]
[HarmonyPatch("OnBlockRemoved")]
public class BlockOnBlockRemoved {
public static void Postfix(Vector3i _blockPos) {
public static void Postfix(Block __instance, Vector3i _blockPos) {
if (!__instance.Properties.Classes.ContainsKey("Particles")) return;

var particles = __instance.Properties.Classes["Particles"];
var particle = particles.GetBool("PeristAfterRemove");
if (particle) return;
BlockUtilitiesSDX.removeParticles(_blockPos);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Mods/0-SCore/ModInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<Description value="SCore Mod" />
<DisplayName value="0-SCore" />
<Website value="" />
<Version value="1.0.59.1007" />
<Version value="1.0.60.1616" />
</xml>
4 changes: 2 additions & 2 deletions Mods/0-SCore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
// [assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("20.0.*")]

[assembly: AssemblyVersion("1.0.59.1007")]
[assembly: AssemblyFileVersion("1.0.59.1007")]
[assembly: AssemblyVersion("1.0.60.1616")]
[assembly: AssemblyFileVersion("1.0.60.1616")]
35 changes: 35 additions & 0 deletions Mods/0-SCore/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@ Direct Download to the 0-SCore.zip available on gitlab mirror:
### Change Logs

[ Change Log ]
Version: 1.0.60.1241
[ MinEvent ]
- Added a new MinEvent to allow changing local transform / rotation on a particular transform on an entity.
<triggered_effect trigger="onSelfBuffUpdate"
action="AdjustTransformValues, SCore"
parent_transform="AK47"
local_offset="-0.05607828,0.07183618,-0.02150292"
local_rotation="-3.98,-9.826,-5.901"
<!-- Optional. Defaults to false -->
debug="true"
/>

[ Console Command ]
- Added a new console command to assist testing of the above MinEvent.
- Use this cautiously.
- Example:
ReloadSCore buffs
ReloadSCore entityclasses
[ Particles On Block ]
- Fixed a few issues where particles were being loaded incorrectly, causing a hard crash
- Added a patch on the init to pre-load Particles
- Added a check for to keep a particle upon removal of its block
<property name="PeristAfterRemove" value="false" />

- Somewhat realistic example:
<append xpath="/blocks/block[contains(@name,'emberPile')]">
<property class="Particles" >
<property name="OnSpawnParticle" value="#@modfolder(0-SCore_sphereii):Resources/gupFireParticles.unity3d?gupBeavis02-CampFire,#@modfolder(0-SCore_sphereii):Resources/gupFireParticles.unity3d?gupBeavis03-Cartoon,#@modfolder(0-SCore_sphereii):Resources/gupFireParticles.unity3d?gupBeavis04-SlowFire,#@modfolder(0-SCore_sphereii):Resources/gupFireParticles.unity3d?gupBeavis06-HeavyLight"/>
<property name="OnSpawnProb" value="0.1"/>
<property name="PeristAfterRemove" value="false" />
</property>
</append>


Version: 1.0.59.1007
[ Food Spoilage ]
- Added missing FreshnessOnly check on the ModifyCVar minevent patch.
Expand Down
Binary file modified Mods/0-SCore/SCore.dll
Binary file not shown.
Binary file modified Mods/0-SCore/SCore.pdb
Binary file not shown.
31 changes: 31 additions & 0 deletions Mods/0-SCore/Scripts/ConsoleCmd/ConsoleCmdReloadSCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

using System.Collections.Generic;
using UAI;


public class ConsoleCmdReloadBuffs : ConsoleCmdAbstract
{
public override bool IsExecuteOnClient
{
get { return true; }
}

public override string[] getCommands()
{
return new string[]
{
"ReloadSCore"
};
}

public override void Execute(List<string> _params, CommandSenderInfo _senderInfo) {
if (_params.Count != 1) return;
WorldStaticData.Reset(_params[0]);
SingletonMonoBehaviour<SdtdConsole>.Instance.Output($"Reloading {_params[0]}");
}

public override string getDescription()
{
return "SCore: Reloads the passed in xml. This could have catastrophic results.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

using System.Collections.Generic;
using System.Xml.Linq;
using UnityEngine;
/*
<triggered_effect trigger="onSelfBuffUpdate"
action="AdjustTransformValues, SCore"
parent_transform="AK47"
local_offset="-0.05607828,0.07183618,-0.02150292"
local_rotation="-3.98,-9.826,-5.901"
<!-- Optional. Defaults to false -->
debug="true"
/>
*/
public class MinEventActionAdjustTransformValues : MinEventActionBuffModifierBase {
private string _transform;
private Vector3 _localOffset;
private Quaternion _localRotation;

// This is just used for debugging so the same message doesn't get spammed.
private static string LastMessage = string.Empty;
private bool _debug;

private void DisplayLog(MinEventParams _params) {
var message =
$"{_params.Self.EntityName} : Adjusting {_transform}: Local Offset: {_localOffset} Local Rotation: {_localRotation}";
if (LastMessage == message) return;
LastMessage = message;
Debug.Log(message);
}

public override void Execute(MinEventParams _params) {
if (_params.Self != null || _params.Self.RootTransform != null)
{
var children = new List<Transform>();
GetAllChildren(_params.Self.RootTransform, ref children);
foreach (var child in children)
{
if (child.name != _transform) continue;
if ( _debug)
DisplayLog(_params);
child.localPosition = _localOffset;
child.localRotation = _localRotation;
break;
}
}

base.Execute(_params);
}

public static void GetAllChildren(Transform parent, ref List<Transform> transforms) {
foreach (Transform t in parent)
{
transforms.Add(t);
GetAllChildren(t, ref transforms);
}
}

public override bool ParseXmlAttribute(XAttribute _attribute) {
var flag = base.ParseXmlAttribute(_attribute);
if (flag) return true;
var name = _attribute.Name.LocalName;

switch (name)
{
case null:
return flag;
case "parent_transform":
_transform = _attribute.Value;
return true;
case "debug":
_debug = StringParsers.ParseBool(_attribute.Value);
return true;
case "local_offset":
_localOffset = StringParsers.ParseVector3(_attribute.Value);
return true;
case "local_rotation":
var rotation = StringParsers.ParseVector3(_attribute.Value);
var newQuaternion = new Quaternion();
newQuaternion.Set(rotation.x, rotation.y, rotation.z,1);
_localRotation = newQuaternion;
return true;

default:
return false;
}
}
}

0 comments on commit dc34dc6

Please sign in to comment.