Skip to content

Commit

Permalink
Explosive torpedo is now working. The mod now uses an "assetbundle" m…
Browse files Browse the repository at this point in the history
…ade using unity. The bundle must always have this name. When adding new assets to the assetbundle, do not forget to set the type (Sprites, Textures, etc...).

While SMLHelper is not patched, audio will have to either stay in ogg files, either be suspended (I chosed the second option for now)
Next commit I will start working on the Prawn Self Defense module.
  • Loading branch information
VELD-Dev committed Apr 21, 2023
1 parent 63b0e8f commit 4186cc5
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 156 deletions.
22 changes: 15 additions & 7 deletions AlterraWeaponry/AlterraWeaponry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp_publicized">
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\publicized_assemblies\Assembly-CSharp_publicized.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -71,6 +74,10 @@
<Reference Include="UnityEngine.AnimationModule">
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AudioModule">
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.AudioModule.dll</HintPath>
</Reference>
Expand All @@ -85,19 +92,22 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="patches\ExosuitTorpedoArm_OpenTorpedoStorageExternal_Patch.cs" />
<Compile Include="patches\SeamothTorpedo_OnEnergyDepleted_Patch.cs" />
<Compile Include="utils\ExplosiveTorpedoInitializer.cs" />
<Compile Include="behaviours\TorpedoExplosionBehaviour.cs" />
<Compile Include="Global.cs" />
<Compile Include="items\BlackPowder.cs" />
<Compile Include="items\Coal.cs" />
<Compile Include="items\ExplosiveTorpedo.cs" />
<Compile Include="Main.cs" />
<Compile Include="patches\ItemGoalTracker_Start_Patch.cs" />
<Compile Include="patches\uGUISceneLoading_End_Patch.cs" />
<Compile Include="patches\Vehicle_Awake_Patch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="utils\LanguagesHandler.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="behaviours\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="assets\Coal.png" />
<Content Include="assets\ExplosiveTorpedo.png" />
Expand All @@ -114,10 +124,8 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry"
mkdir "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\assets"
copy /Y "$(TargetPath)" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\"
copy /Y "$(ProjectDir)\mod.json" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\mod.json"
copy /Y "$(ProjectDir)\assets\" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\assets\"
copy /Y "$(ProjectDir)\Localizations.xml" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\Localizations.xml"</PostBuildEvent>
copy /Y "$(ProjectDir)\alterraweaponry.assets" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\"
copy /Y "$(ProjectDir)\Localizations.xml" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\"</PostBuildEvent>
</PropertyGroup>
</Project>
7 changes: 5 additions & 2 deletions AlterraWeaponry/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
global using BepInEx.Bootstrap;
global using BepInEx.Configuration;
global using BepInEx.Logging;
global using UnityEngine;
global using SMLHelper.V2.Assets;
global using SMLHelper.V2.Commands;
global using SMLHelper.V2.Crafting;
Expand All @@ -37,8 +36,12 @@
global using HarmonyLib.Tools;
global using Story;
global using Subnautica;
global using Unity;
global using UnityEngine;
global using UnityEditor;

// LOCAL
global using VELD.AlterraWeaponry.items;
global using VELD.AlterraWeaponry.patches;
global using VELD.AlterraWeaponry.utils;
global using VELD.AlterraWeaponry.utils;
global using VELD.AlterraWeaponry.behaviours;
28 changes: 17 additions & 11 deletions AlterraWeaponry/Main.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using VELD.AlterraWeaponry.items;

namespace VELD.AlterraWeaponry;
namespace VELD.AlterraWeaponry;

[BepInPlugin(modGUID, modName, modVers)]
public class Main : BaseUnityPlugin
Expand All @@ -20,17 +18,17 @@ public class Main : BaseUnityPlugin


// PATHS
public static readonly string AssetsLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "assets");
public static readonly AssetBundle assets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "alterraweaponry.assets"));


private void Awake()
{
logger = Logger;
logger.LogInfo($"{modName} {modVers} started patching.");
harmony.PatchAll();
logger.LogInfo($"{modName} {modVers} harmony patched.");
RegisterPDALogs();
logger.LogInfo($"{modName} {modVers} PDA logs registered.");
//logger.LogInfo($"{modName} {modVers} harmony patched.");
//RegisterPDALogs();
//logger.LogInfo($"{modName} {modVers} PDA logs registered.");
RegisterPDAEncyEntries();
logger.LogInfo($"{modName} {modVers} PDA encyclopedia entries registered.");

Expand All @@ -48,19 +46,27 @@ private void Awake()
}
private static void RegisterPDALogs()
{
// Load audio clips
logger.LogInfo($"{modName} {modVers} Loading audio clips...");
AudioClip AWPresentationAudioClip = assets.LoadAsset<AudioClip>("pwa_presentation_message");
AudioClip AWFirstLethalAudioClip = assets.LoadAsset<AudioClip>("first_lethal_message");
logger.LogInfo($"{modName} {modVers} Audio clips loaded!");

logger.LogInfo($"{modName} {modVers} Registering PDA Logs...");

// Presentation PDA log "Hello xenoworker 91802..."
CustomSoundHandler.RegisterCustomSound("Log_PDA_Goal_AWPresentation", Path.Combine(AssetsLocation, "pwa_presentation.ogg"), AudioUtils.BusPaths.PDAVoice);
CustomSoundHandler.RegisterCustomSound(AWPresentationGoal.key, AWPresentationAudioClip, AudioUtils.BusPaths.PDAVoice);
FMODAsset presentation = ScriptableObject.CreateInstance<FMODAsset>();
presentation.path = "Log_PDA_Goal_AWPresentation";
presentation.id = "Log_PDA_Goal_AWPresentation";
presentation.path = AWPresentationGoal.key;
presentation.id = AWPresentationGoal.key;
PDALogHandler.AddCustomEntry(
AWPresentationGoal.key,
"Subtitles_AWPresentation",
sound: presentation
);

// First lethal weapon PDA log "A lethal weapon have been detected into your inventory..."
CustomSoundHandler.RegisterCustomSound("Log_PDA_Goal_FirstLethal", Path.Combine(AssetsLocation, "first_lethal_message.ogg"), AudioUtils.BusPaths.PDAVoice);
CustomSoundHandler.RegisterCustomSound("Log_PDA_Goal_FirstLethal", AWFirstLethalAudioClip, AudioUtils.BusPaths.PDAVoice);
FMODAsset firstLethal = ScriptableObject.CreateInstance<FMODAsset>();
firstLethal.path = "Log_PDA_Goal_FirstLethal";
firstLethal.id = "Log_PDA_Goal_FirstLethal";
Expand Down
Binary file added AlterraWeaponry/alterraweaponry.assets
Binary file not shown.
19 changes: 19 additions & 0 deletions AlterraWeaponry/behaviours/TorpedoExplosionBehaviour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VELD.AlterraWeaponry.behaviours;

public class TorpedoExplosionBehaviour : MonoBehaviour
{
public void Start()
{
DamageSystem.RadiusDamage(250f, base.gameObject.transform.position, 5f, DamageType.Explosive, base.gameObject);
Utils.PlayOneShotPS(VFXSunbeam.main.explosionPrefab, base.gameObject.transform.position, base.gameObject.transform.rotation, null);
UnityEngine.Object.Destroy(base.gameObject);
}

public static GameObject detonationEffectPrefab;
}
90 changes: 42 additions & 48 deletions AlterraWeaponry/items/BlackPowder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,57 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.U2D;

namespace VELD.AlterraWeaponry.items
{
internal class BlackPowder : Craftable
{
public static GameObject prefab;
public static TechType techType { get; private set; } = 0;
namespace VELD.AlterraWeaponry.items;

public override string AssetsFolder => Main.AssetsLocation;
internal class BlackPowder : Craftable
{
public static GameObject prefab;
public static TechType techType { get; private set; } = 0;

public BlackPowder() : base("BlackPowder", "BlackPowder", "Tooltip_BlackPowder")
{
OnFinishedPatching += () =>
{
techType = TechType;
};
}
public override TechCategory CategoryForPDA => TechCategory.AdvancedMaterials;
public override TechGroup GroupForPDA => TechGroup.Resources;
public override List<TechType> CompoundTechsForUnlock => new()
public BlackPowder() : base("BlackPowder", "BlackPowder", "Tooltip_BlackPowder")
{
OnFinishedPatching += () =>
{
Coal.techType,
TechType.Sulphur,
techType = TechType;
};
public override float CraftingTime => 2.5f;
public override CraftTree.Type FabricatorType => CraftTree.Type.Fabricator;
public override Vector2int SizeInInventory => new(1, 1);
public override string[] StepsToFabricatorTab => new string[] { "Resources", "AdvancedMaterials"};
protected override RecipeData GetBlueprintRecipe()
{
return new()
{
craftAmount = 1,
Ingredients = new()
{
new(Coal.techType, 1),
new(TechType.Sulphur, 1),
new(TechType.JeweledDiskPiece, 3)
}
};
}
protected override Sprite GetItemSprite()
{
return ImageUtils.LoadSpriteFromFile(Path.Combine(AssetsFolder, "Coal.png"));
}
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
}
public override TechCategory CategoryForPDA => TechCategory.AdvancedMaterials;
public override TechGroup GroupForPDA => TechGroup.Resources;
public override TechType RequiredForUnlock => Coal.techType;
public override float CraftingTime => 2.5f;
public override CraftTree.Type FabricatorType => CraftTree.Type.Fabricator;
public override Vector2int SizeInInventory => new(1, 1);
public override string[] StepsToFabricatorTab => new string[] { "Resources", "AdvancedMaterials"};
protected override RecipeData GetBlueprintRecipe()
{
return new()
{
if (prefab == null)
craftAmount = 1,
Ingredients = new()
{
CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.HydrochloricAcid);
yield return task;

prefab = GameObject.Instantiate(task.GetResult());
new(Coal.techType, 1),
new(TechType.Sulphur, 1),
new(TechType.JeweledDiskPiece, 3)
}
};
}
protected override Sprite GetItemSprite()
{
return Main.assets.LoadAsset<Sprite>("Coal");
}
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
{
if (prefab == null)
{
CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.HydrochloricAcid);
yield return task;

GameObject go = GameObject.Instantiate(prefab);
gameObject.Set(go);
prefab = GameObject.Instantiate(task.GetResult());
}

GameObject go = GameObject.Instantiate(prefab);
gameObject.Set(go);
}
}
84 changes: 41 additions & 43 deletions AlterraWeaponry/items/Coal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,56 @@
using System.Text;
using System.Threading.Tasks;

namespace VELD.AlterraWeaponry.items
namespace VELD.AlterraWeaponry.items;

internal class Coal : Craftable
{
internal class Coal : Craftable
{
public static GameObject prefab;
public static TechType techType { get; private set; } = 0;
public override string AssetsFolder => Main.AssetsLocation;
public static GameObject prefab;
public static TechType techType { get; private set; } = 0;

public Coal() : base ("Coal", "Coal", "Tooltip_Coal")
public Coal() : base ("Coal", "Coal", "Tooltip_Coal")
{
OnFinishedPatching += () =>
{
OnFinishedPatching += () =>
{
techType = TechType;
};
}
techType = TechType;
};
}

public override CraftTree.Type FabricatorType => CraftTree.Type.Fabricator;
public override TechCategory CategoryForPDA => TechCategory.BasicMaterials;
public override TechGroup GroupForPDA => TechGroup.Resources;
public override Vector2int SizeInInventory => new(1, 1);
public override float CraftingTime => 3f;
public override TechType RequiredForUnlock => TechType.CreepvinePiece;
public override string[] StepsToFabricatorTab => new string[] { "Resources", "BasicMaterials" };
protected override RecipeData GetBlueprintRecipe()
{
return new()
{
craftAmount = 4,
Ingredients = new()
{
new(TechType.CreepvinePiece, 1)
}
};
}
protected override Sprite GetItemSprite()
{
return ImageUtils.LoadSpriteFromFile(Path.Combine(AssetsFolder, "Coal.png"));
}
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
public override CraftTree.Type FabricatorType => CraftTree.Type.Fabricator;
public override TechCategory CategoryForPDA => TechCategory.BasicMaterials;
public override TechGroup GroupForPDA => TechGroup.Resources;
public override Vector2int SizeInInventory => new(1, 1);
public override float CraftingTime => 3f;
public override TechType RequiredForUnlock => TechType.CreepvinePiece;
public override string[] StepsToFabricatorTab => new string[] { "Resources", "BasicMaterials" };
protected override RecipeData GetBlueprintRecipe()
{
return new()
{
if (prefab == null)
craftAmount = 4,
Ingredients = new()
{
CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.Titanium);
yield return task;

prefab = GameObject.Instantiate(task.GetResult());
new(TechType.CreepvinePiece, 1)
}
};
}
protected override Sprite GetItemSprite()
{
return Main.assets.LoadAsset<Sprite>("Coal");
}
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
{
if (prefab == null)
{
CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.Titanium);
yield return task;

GameObject go = GameObject.Instantiate(prefab);
gameObject.Set(go);
prefab = GameObject.Instantiate(task.GetResult());
}


GameObject go = GameObject.Instantiate(prefab);
gameObject.Set(go);
}


}
Loading

0 comments on commit 4186cc5

Please sign in to comment.