Skip to content

Commit

Permalink
1.1.9.2008
Browse files Browse the repository at this point in the history
  • Loading branch information
SphereII committed Oct 9, 2024
1 parent 8121511 commit 723d937
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 26 deletions.
1 change: 1 addition & 0 deletions Mods/0-SCore/0-SCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
<Compile Include="Harmony\Animation\ModelBaseInitCommon.cs" />
<Compile Include="Harmony\Atmosphere\Spook.cs" />
<Compile Include="Harmony\Blocks\BlockWorkarounds.cs" />
<Compile Include="Harmony\Blocks\ChunkPoolBlockEntityTransform.cs" />
<Compile Include="Harmony\Blocks\ElectricityMultiDimFix.cs" />
<Compile Include="Harmony\Blocks\OnEntityCollidedWithBlock.cs" />
<Compile Include="Harmony\Blocks\Particles.cs" />
Expand Down
1 change: 0 additions & 1 deletion Mods/0-SCore/Config/Localization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ BreakBlock04Short,"Destroy any metal block in the pine forest"

SCore02challenges_key,"Fire Bug"
onStartFire,"Start a Fire"

BurnWithFire02,"Start a fire"
BurnWithFire02Desc,"Start a fire with the Fire Mod active."
onBigFire,"Start an out of control fire"
Expand Down
8 changes: 7 additions & 1 deletion Mods/0-SCore/Config/blocks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,14 @@

<property class="ErrorHandling">
<property name="Logging" value="false"/>
<property name="NoExceptionHijack" value="true" />
<!-- Disables the console drop down on red exception -->
<property name="NoExceptionHijack" value="true" />

<!-- If set to true, quiets the "Block Entity at pos null transform -->
<property name="EnablePoolBlockEntityTransformCheck" value="false" />
<!-- Turns on Advanced debugging -->
<property name="LogPoolBlockEntityTransformCheck" value="false" />

</property>

<property class="AdvancedUI">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public override void HandleRemoveHooks() {
FireManager.Instance.OnExtinguish -= Check_Block;
}

private void Check_Block(int count) {
private void Check_Block(int count, int entityId) {
if (entityId == -1) return;
var localPlayer = GameManager.Instance.World.GetPrimaryPlayer();
if (localPlayer.entityId != entityId) return;
Current = count;
CheckObjectiveComplete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public override void HandleRemoveHooks() {
FireManager.Instance.OnStartFire -= Check_Block;
}

private void Check_Block() {
private void Check_Block(int entityId) {
if (entityId == -1) return;
var localPlayer = GameManager.Instance.World.GetPrimaryPlayer();
if (localPlayer.entityId != entityId) return;
Current++;
CheckObjectiveComplete();
}
Expand Down
15 changes: 8 additions & 7 deletions Mods/0-SCore/Features/Fire/Scripts/FireManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ private static readonly ConcurrentDictionary<Vector3i, BlockValue>
public delegate void OnBlockDestroyedByFire();
public event OnBlockDestroyedByFire OnDestroyed;

public delegate void OnFireStart();
public delegate void OnFireStart(int entityId);
public event OnFireStart OnStartFire;

public delegate void OnFireRefresh(int count);
public event OnFireRefresh OnFireUpdate;

public delegate void OnExtinguishFire(int count);
public delegate void OnExtinguishFire(int count, int entityId);

public event OnExtinguishFire OnExtinguish;

Expand Down Expand Up @@ -608,7 +608,7 @@ private void Read(BinaryReader br)
{
if (string.IsNullOrEmpty(position)) continue;
var vector = StringParsers.ParseVector3i(position);
ExtinguishBlock(vector);
ExtinguishBlock(vector, -1);
}
}

Expand Down Expand Up @@ -636,6 +636,8 @@ public void Add(Vector3i blockPos, int entityID = -1)
{
if (!IsFlammable(blockPos))
return;

OnStartFire?.Invoke(entityID);


AddBlock(blockPos);
Expand All @@ -655,7 +657,7 @@ public void Add(Vector3i blockPos, int entityID = -1)
// General call to remove the fire from a block, and add an extinguished counter, so blocks can be temporarily immune to restarting.
public void Extinguish(Vector3i blockPos, int entityID = -1)
{
ExtinguishBlock(blockPos);
ExtinguishBlock(blockPos, entityID);
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
{
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(
Expand Down Expand Up @@ -709,7 +711,7 @@ public void RemoveFire(Vector3i blockPos)
FireMap.TryRemove(blockPos, out _);
}

public void ExtinguishBlock(Vector3i blockPos)
public void ExtinguishBlock(Vector3i blockPos, int entityId)
{
var worldTime = GameManager.Instance.World.GetWorldTime();
var expiry = worldTime + _smokeTime;
Expand All @@ -718,7 +720,7 @@ public void ExtinguishBlock(Vector3i blockPos)
// keep resetting the expired time.
ExtinguishPositions[blockPos] = expiry;
RemoveFire(blockPos);
OnExtinguish?.Invoke(ExtinguishPositions.Count);
OnExtinguish?.Invoke(ExtinguishPositions.Count, entityId);
//FireMap.TryRemove(blockPos, out _);

var block = GameManager.Instance.World.GetBlock(blockPos);
Expand All @@ -739,7 +741,6 @@ public void AddBlock(Vector3i blockPos)
var block = GameManager.Instance.World.GetBlock(blockPos);
if (!FireMap.TryAdd(blockPos, block)) return;

OnStartFire?.Invoke();

ToggleSound(blockPos, true);
ToggleParticle(blockPos, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public override void Execute(MinEventParams @params)
if (FireManager.Instance == null) return;
if (FireManager.Instance.Enabled == false) return;

var entityId = @params.Self.entityId;
var position = @params.Position;
if (targetType != TargetTypes.positionAOE)
{
Expand Down Expand Up @@ -51,10 +52,10 @@ public override void Execute(MinEventParams @params)

AdvLogging.DisplayLog(AdvFeatureClass, $"Executing AddFireDamage() at {position} Self: {@params.Self.position} Range: {maxRange} Delay: {_delayTime}");
Task.Delay((int) _delayTime)
.ContinueWith(_ => AddFire(position));
.ContinueWith(_ => AddFire(position, entityId));
}

private void AddFire(Vector3 position)
private void AddFire(Vector3 position, int entityId)
{
var range = (int) maxRange;
for (var x = -range; x <= range; x++)
Expand All @@ -64,7 +65,7 @@ private void AddFire(Vector3 position)
for (var y = -range; y <= range; y++)
{
var vector = new Vector3i(position.x + x, position.y + y, position.z + z);
FireManager.Instance.Add(vector);
FireManager.Instance.Add(vector, entityId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private enum FilterTypeCascade
public override void Execute(MinEventParams @params)
{
var position = @params.Position;
var entityId = @params.Self.entityId;
if (targetType != TargetTypes.positionAOE)
{
if (Voxel.voxelRayHitInfo.bHitValid)
Expand All @@ -45,10 +46,10 @@ public override void Execute(MinEventParams @params)
position = hitInfo.hit.blockPos;
}
}
SpreadFire(position);
SpreadFire(position, entityId);
}

private void SpreadFire(Vector3 position)
private void SpreadFire(Vector3 position, int entityId)
{
var targetBlock = GameManager.Instance.World.GetBlock(new Vector3i(position));

Expand All @@ -65,21 +66,21 @@ private void SpreadFire(Vector3 position)
{
case FilterTypeCascade.Type:
if (neighborBlock.type == targetBlock.type)
FireManager.Instance.Add(vector);
FireManager.Instance.Add(vector,entityId);
break;
case FilterTypeCascade.Material:
if (neighborBlock.Block.blockMaterial.id == targetBlock.Block.blockMaterial.id)
FireManager.Instance.Add(vector);
FireManager.Instance.Add(vector,entityId);
break;
case FilterTypeCascade.MaterialDamage:
if (neighborBlock.Block.blockMaterial.DamageCategory ==
targetBlock.Block.blockMaterial.DamageCategory)
FireManager.Instance.Add(vector);
FireManager.Instance.Add(vector,entityId);
break;
case FilterTypeCascade.MaterialSurface:
if (neighborBlock.Block.blockMaterial.SurfaceCategory ==
targetBlock.Block.blockMaterial.SurfaceCategory)
FireManager.Instance.Add(vector);
FireManager.Instance.Add(vector,entityId);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public override void Execute(MinEventParams @params)
if (FireManager.Instance.Enabled == false) return;

var position = @params.Position;
var entityId = @params.Self.entityId;
if (targetType != TargetTypes.positionAOE)
{
if (Voxel.voxelRayHitInfo.bHitValid)
Expand All @@ -40,7 +41,7 @@ public override void Execute(MinEventParams @params)
var vector = new Vector3i(position.x + x, position.y + y, position.z + z);
if (!FireManager.IsBurning(vector)) continue;
// FireManager.Instance.Remove(vector);
FireManager.Instance.Extinguish(vector);
FireManager.Instance.Extinguish(vector,entityId);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void ProcessPackage(World world, GameManager callbacks)
return;
}

FireManager.Instance.ExtinguishBlock(_position);
FireManager.Instance.ExtinguishBlock(_position, _entityThatCausedIt);
}
}

46 changes: 46 additions & 0 deletions Mods/0-SCore/Harmony/Blocks/ChunkPoolBlockEntityTransform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using HarmonyLib;
using UnityEngine;

namespace SCore.Harmony.Blocks {
public class ChunkPoolBlockEntityTransform {
private static readonly string AdvFeatureClass = "ErrorHandling";
private static readonly string Feature = "EnablePoolBlockEntityTransformCheck";
private static readonly string Logging = "LogPoolBlockEntityTransformCheck";

[HarmonyPatch(typeof(Chunk))]
[HarmonyPatch("poolBlockEntityTransform")]
public class ChunkpoolBlockEntityTransform {
public static bool Prefix(BlockEntityData _bed) {
// Check if this feature is enabled.
if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature)) return true;
if (_bed.transform != null && _bed.transform.gameObject != null) return true;
if (Configuration.CheckFeatureStatus(AdvFeatureClass, Logging))
{
Debug.Log("Error: There's a Block Entity without a Transform!");
Debug.Log($"Block Position: {_bed.pos} : BlockValue: {_bed.blockValue.Block.ToString()}");
}

return false;

}
}

[HarmonyPatch(typeof(Chunk))]
[HarmonyPatch("setBlockEntityRendering")]
public class ChunksetBlockEntityRendering {
public static bool Prefix(BlockEntityData _bed) {
// Check if this feature is enabled.
if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature)) return true;
if (_bed.transform != null && _bed.transform.gameObject != null) return true;
if (Configuration.CheckFeatureStatus(AdvFeatureClass, Logging))
{
Debug.Log("Error: There's a Block Entity without a Transform!");
Debug.Log($"Block Position: {_bed.pos} : BlockValue: {_bed.blockValue.Block.ToString()}");
}

return false;

}
}
}
}
24 changes: 24 additions & 0 deletions Mods/0-SCore/Harmony/Faction/FactionTweaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ public static bool Prefix(global::Faction __instance, byte _factionId, float _va
return false;
}
}

// Working around missing faction bug
[HarmonyPatch(typeof(FactionManager))]
[HarmonyPatch("GetFactionByName")]
public class FactionGetFactionByName
{
public static bool Prefix(ref global::Faction __result, FactionManager __instance, string _name) {
global::Faction defaultFaction = null;
for (var i = 0; i < __instance.Factions.Length; i++)
{
// If no faction is found, use this one.
if (__instance.Factions[i]?.Name == "undead")
defaultFaction = __instance.Factions[i];

if (__instance.Factions[i]?.Name != _name) continue;
__result = __instance.Factions[i];
return false;
}

Debug.Log($"FactionManager: Requested this Faction: {_name} but it was not defined in the npc.xml. Defaulting to Undead faction.");
__result = defaultFaction;
return false;
}
}

}
}
2 changes: 2 additions & 0 deletions Mods/0-SCore/Harmony/TileEntities/TileEntitySignGif.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static bool Prefix(TileEntitySign __instance) {
var smartTextMesh = __instance.smartTextMesh;
if (smartTextMesh == null) return true;
var parentTransform = smartTextMesh.transform.parent;
if (parentTransform.transform.childCount < 2)
return true;
var signMesh = parentTransform.transform.GetChild(0);
var prefab = parentTransform.transform.GetChild(1);

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.1.4.1542" />
<Version value="1.1.9.2008" />
</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.1.4.1542")]
[assembly: AssemblyFileVersion("1.1.4.1542")]
[assembly: AssemblyVersion("1.1.9.2008")]
[assembly: AssemblyFileVersion("1.1.9.2008")]
32 changes: 31 additions & 1 deletion Mods/0-SCore/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,37 @@ Direct Download to the 0-SCore.zip available on gitlab mirror: https://github.co
### Change Logs

[ Change Log ]
Version: 1.1.4.1542
Version: 1.1.9.2008
[ Faction Manager ]
- Added a Harmony Patch to GetFactionByName() to catch for invalid factions.
- If a faction is requested from an entityclass, but it's not defined in npc.xml,
the undead faction is used.
- A message in the console is printed when a faction was not found.

[ POI Error Check ]
- Added in two Harmony patches, gated by two new blocks.xml entry.
- Under the ErrorHandling section:
EnablePoolBlockEntityTransformCheck
LogPoolBlockEntityTransformCheck
- Some POis were throwing errors about block entity's without a proper transform:
BlockEntity {0} at pos {1} null transform!
2: {0} on pos {1} with empty transform/gameobject!
- These were being thrown in the Chunk class.
- These two patches block that error from being thrown, and silently returns.
- The LogPoolBlockEntityTransformCheck will throw an error, but it'll tell you which block it's failing at.
- Both these should be false, unless you are specifically having a problem
[ TileEntitySign Gif ]
- Fixed an issue where some older signs did not have the correct amount of transforms
- ie, pathing cubes

[ Challenges ]
- Fixed an issue with the StartAFire / Extinguish Fire where any entity would contribute

[ Fire Manager ]
- Updated the Fire Manager's StartFire / ExtinguishFire event takes an entity ID.

Version: 1.1.4.1542
[ Entity Targetting ]
- Updated the code for the ItemItemAction to first check if it's hitting an EntityAlive
- Then checks if the entity alive is dead. If so, let the damage through.
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.
Binary file modified Mods/SphereII Winter Project/SphereII_Winter_Project.dll
Binary file not shown.
Binary file modified Mods/SphereII Winter Project/SphereII_Winter_Project.pdb
Binary file not shown.

0 comments on commit 723d937

Please sign in to comment.