Skip to content

Commit 4186cc5

Browse files
committed
Explosive torpedo is now working. The mod now uses an "assetbundle" made 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.
1 parent 63b0e8f commit 4186cc5

13 files changed

+292
-156
lines changed

AlterraWeaponry/AlterraWeaponry.csproj

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<Reference Include="Assembly-CSharp-firstpass">
4343
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
4444
</Reference>
45+
<Reference Include="Assembly-CSharp_publicized">
46+
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\publicized_assemblies\Assembly-CSharp_publicized.dll</HintPath>
47+
</Reference>
4548
<Reference Include="BepInEx">
4649
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\BepInEx\core\BepInEx.dll</HintPath>
4750
</Reference>
@@ -71,6 +74,10 @@
7174
<Reference Include="UnityEngine.AnimationModule">
7275
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
7376
</Reference>
77+
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
78+
<SpecificVersion>False</SpecificVersion>
79+
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
80+
</Reference>
7481
<Reference Include="UnityEngine.AudioModule">
7582
<HintPath>B:\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.AudioModule.dll</HintPath>
7683
</Reference>
@@ -85,19 +92,22 @@
8592
</Reference>
8693
</ItemGroup>
8794
<ItemGroup>
95+
<Compile Include="patches\ExosuitTorpedoArm_OpenTorpedoStorageExternal_Patch.cs" />
96+
<Compile Include="patches\SeamothTorpedo_OnEnergyDepleted_Patch.cs" />
97+
<Compile Include="utils\ExplosiveTorpedoInitializer.cs" />
98+
<Compile Include="behaviours\TorpedoExplosionBehaviour.cs" />
8899
<Compile Include="Global.cs" />
89100
<Compile Include="items\BlackPowder.cs" />
90101
<Compile Include="items\Coal.cs" />
91102
<Compile Include="items\ExplosiveTorpedo.cs" />
92103
<Compile Include="Main.cs" />
93104
<Compile Include="patches\ItemGoalTracker_Start_Patch.cs" />
94105
<Compile Include="patches\uGUISceneLoading_End_Patch.cs" />
106+
<Compile Include="patches\Vehicle_Awake_Patch.cs" />
95107
<Compile Include="Properties\AssemblyInfo.cs" />
96108
<Compile Include="utils\LanguagesHandler.cs" />
97109
</ItemGroup>
98-
<ItemGroup>
99-
<Folder Include="behaviours\" />
100-
</ItemGroup>
110+
<ItemGroup />
101111
<ItemGroup>
102112
<Content Include="assets\Coal.png" />
103113
<Content Include="assets\ExplosiveTorpedo.png" />
@@ -114,10 +124,8 @@
114124
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
115125
<PropertyGroup>
116126
<PostBuildEvent>mkdir "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry"
117-
mkdir "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\assets"
118127
copy /Y "$(TargetPath)" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\"
119-
copy /Y "$(ProjectDir)\mod.json" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\mod.json"
120-
copy /Y "$(ProjectDir)\assets\" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\assets\"
121-
copy /Y "$(ProjectDir)\Localizations.xml" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\Localizations.xml"</PostBuildEvent>
128+
copy /Y "$(ProjectDir)\alterraweaponry.assets" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\"
129+
copy /Y "$(ProjectDir)\Localizations.xml" "$(SubnauticaRootPath)\BepInEx\plugins\AlterraWeaponry\"</PostBuildEvent>
122130
</PropertyGroup>
123131
</Project>

AlterraWeaponry/Global.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
global using BepInEx.Bootstrap;
1515
global using BepInEx.Configuration;
1616
global using BepInEx.Logging;
17-
global using UnityEngine;
1817
global using SMLHelper.V2.Assets;
1918
global using SMLHelper.V2.Commands;
2019
global using SMLHelper.V2.Crafting;
@@ -37,8 +36,12 @@
3736
global using HarmonyLib.Tools;
3837
global using Story;
3938
global using Subnautica;
39+
global using Unity;
40+
global using UnityEngine;
41+
global using UnityEditor;
4042

4143
// LOCAL
4244
global using VELD.AlterraWeaponry.items;
4345
global using VELD.AlterraWeaponry.patches;
44-
global using VELD.AlterraWeaponry.utils;
46+
global using VELD.AlterraWeaponry.utils;
47+
global using VELD.AlterraWeaponry.behaviours;

AlterraWeaponry/Main.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using VELD.AlterraWeaponry.items;
2-
3-
namespace VELD.AlterraWeaponry;
1+
namespace VELD.AlterraWeaponry;
42

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

2119

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

2523

2624
private void Awake()
2725
{
2826
logger = Logger;
2927
logger.LogInfo($"{modName} {modVers} started patching.");
3028
harmony.PatchAll();
31-
logger.LogInfo($"{modName} {modVers} harmony patched.");
32-
RegisterPDALogs();
33-
logger.LogInfo($"{modName} {modVers} PDA logs registered.");
29+
//logger.LogInfo($"{modName} {modVers} harmony patched.");
30+
//RegisterPDALogs();
31+
//logger.LogInfo($"{modName} {modVers} PDA logs registered.");
3432
RegisterPDAEncyEntries();
3533
logger.LogInfo($"{modName} {modVers} PDA encyclopedia entries registered.");
3634

@@ -48,19 +46,27 @@ private void Awake()
4846
}
4947
private static void RegisterPDALogs()
5048
{
49+
// Load audio clips
50+
logger.LogInfo($"{modName} {modVers} Loading audio clips...");
51+
AudioClip AWPresentationAudioClip = assets.LoadAsset<AudioClip>("pwa_presentation_message");
52+
AudioClip AWFirstLethalAudioClip = assets.LoadAsset<AudioClip>("first_lethal_message");
53+
logger.LogInfo($"{modName} {modVers} Audio clips loaded!");
54+
55+
logger.LogInfo($"{modName} {modVers} Registering PDA Logs...");
56+
5157
// Presentation PDA log "Hello xenoworker 91802..."
52-
CustomSoundHandler.RegisterCustomSound("Log_PDA_Goal_AWPresentation", Path.Combine(AssetsLocation, "pwa_presentation.ogg"), AudioUtils.BusPaths.PDAVoice);
58+
CustomSoundHandler.RegisterCustomSound(AWPresentationGoal.key, AWPresentationAudioClip, AudioUtils.BusPaths.PDAVoice);
5359
FMODAsset presentation = ScriptableObject.CreateInstance<FMODAsset>();
54-
presentation.path = "Log_PDA_Goal_AWPresentation";
55-
presentation.id = "Log_PDA_Goal_AWPresentation";
60+
presentation.path = AWPresentationGoal.key;
61+
presentation.id = AWPresentationGoal.key;
5662
PDALogHandler.AddCustomEntry(
5763
AWPresentationGoal.key,
5864
"Subtitles_AWPresentation",
5965
sound: presentation
6066
);
6167

6268
// First lethal weapon PDA log "A lethal weapon have been detected into your inventory..."
63-
CustomSoundHandler.RegisterCustomSound("Log_PDA_Goal_FirstLethal", Path.Combine(AssetsLocation, "first_lethal_message.ogg"), AudioUtils.BusPaths.PDAVoice);
69+
CustomSoundHandler.RegisterCustomSound("Log_PDA_Goal_FirstLethal", AWFirstLethalAudioClip, AudioUtils.BusPaths.PDAVoice);
6470
FMODAsset firstLethal = ScriptableObject.CreateInstance<FMODAsset>();
6571
firstLethal.path = "Log_PDA_Goal_FirstLethal";
6672
firstLethal.id = "Log_PDA_Goal_FirstLethal";
172 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace VELD.AlterraWeaponry.behaviours;
8+
9+
public class TorpedoExplosionBehaviour : MonoBehaviour
10+
{
11+
public void Start()
12+
{
13+
DamageSystem.RadiusDamage(250f, base.gameObject.transform.position, 5f, DamageType.Explosive, base.gameObject);
14+
Utils.PlayOneShotPS(VFXSunbeam.main.explosionPrefab, base.gameObject.transform.position, base.gameObject.transform.rotation, null);
15+
UnityEngine.Object.Destroy(base.gameObject);
16+
}
17+
18+
public static GameObject detonationEffectPrefab;
19+
}

AlterraWeaponry/items/BlackPowder.cs

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,57 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using UnityEngine.U2D;
78

8-
namespace VELD.AlterraWeaponry.items
9-
{
10-
internal class BlackPowder : Craftable
11-
{
12-
public static GameObject prefab;
13-
public static TechType techType { get; private set; } = 0;
9+
namespace VELD.AlterraWeaponry.items;
1410

15-
public override string AssetsFolder => Main.AssetsLocation;
11+
internal class BlackPowder : Craftable
12+
{
13+
public static GameObject prefab;
14+
public static TechType techType { get; private set; } = 0;
1615

17-
public BlackPowder() : base("BlackPowder", "BlackPowder", "Tooltip_BlackPowder")
18-
{
19-
OnFinishedPatching += () =>
20-
{
21-
techType = TechType;
22-
};
23-
}
24-
public override TechCategory CategoryForPDA => TechCategory.AdvancedMaterials;
25-
public override TechGroup GroupForPDA => TechGroup.Resources;
26-
public override List<TechType> CompoundTechsForUnlock => new()
16+
public BlackPowder() : base("BlackPowder", "BlackPowder", "Tooltip_BlackPowder")
17+
{
18+
OnFinishedPatching += () =>
2719
{
28-
Coal.techType,
29-
TechType.Sulphur,
20+
techType = TechType;
3021
};
31-
public override float CraftingTime => 2.5f;
32-
public override CraftTree.Type FabricatorType => CraftTree.Type.Fabricator;
33-
public override Vector2int SizeInInventory => new(1, 1);
34-
public override string[] StepsToFabricatorTab => new string[] { "Resources", "AdvancedMaterials"};
35-
protected override RecipeData GetBlueprintRecipe()
36-
{
37-
return new()
38-
{
39-
craftAmount = 1,
40-
Ingredients = new()
41-
{
42-
new(Coal.techType, 1),
43-
new(TechType.Sulphur, 1),
44-
new(TechType.JeweledDiskPiece, 3)
45-
}
46-
};
47-
}
48-
protected override Sprite GetItemSprite()
49-
{
50-
return ImageUtils.LoadSpriteFromFile(Path.Combine(AssetsFolder, "Coal.png"));
51-
}
52-
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
22+
}
23+
public override TechCategory CategoryForPDA => TechCategory.AdvancedMaterials;
24+
public override TechGroup GroupForPDA => TechGroup.Resources;
25+
public override TechType RequiredForUnlock => Coal.techType;
26+
public override float CraftingTime => 2.5f;
27+
public override CraftTree.Type FabricatorType => CraftTree.Type.Fabricator;
28+
public override Vector2int SizeInInventory => new(1, 1);
29+
public override string[] StepsToFabricatorTab => new string[] { "Resources", "AdvancedMaterials"};
30+
protected override RecipeData GetBlueprintRecipe()
31+
{
32+
return new()
5333
{
54-
if (prefab == null)
34+
craftAmount = 1,
35+
Ingredients = new()
5536
{
56-
CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.HydrochloricAcid);
57-
yield return task;
58-
59-
prefab = GameObject.Instantiate(task.GetResult());
37+
new(Coal.techType, 1),
38+
new(TechType.Sulphur, 1),
39+
new(TechType.JeweledDiskPiece, 3)
6040
}
41+
};
42+
}
43+
protected override Sprite GetItemSprite()
44+
{
45+
return Main.assets.LoadAsset<Sprite>("Coal");
46+
}
47+
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
48+
{
49+
if (prefab == null)
50+
{
51+
CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.HydrochloricAcid);
52+
yield return task;
6153

62-
GameObject go = GameObject.Instantiate(prefab);
63-
gameObject.Set(go);
54+
prefab = GameObject.Instantiate(task.GetResult());
6455
}
56+
57+
GameObject go = GameObject.Instantiate(prefab);
58+
gameObject.Set(go);
6559
}
6660
}

AlterraWeaponry/items/Coal.cs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,56 @@
55
using System.Text;
66
using System.Threading.Tasks;
77

8-
namespace VELD.AlterraWeaponry.items
8+
namespace VELD.AlterraWeaponry.items;
9+
10+
internal class Coal : Craftable
911
{
10-
internal class Coal : Craftable
11-
{
12-
public static GameObject prefab;
13-
public static TechType techType { get; private set; } = 0;
14-
public override string AssetsFolder => Main.AssetsLocation;
12+
public static GameObject prefab;
13+
public static TechType techType { get; private set; } = 0;
1514

16-
public Coal() : base ("Coal", "Coal", "Tooltip_Coal")
15+
public Coal() : base ("Coal", "Coal", "Tooltip_Coal")
16+
{
17+
OnFinishedPatching += () =>
1718
{
18-
OnFinishedPatching += () =>
19-
{
20-
techType = TechType;
21-
};
22-
}
19+
techType = TechType;
20+
};
21+
}
2322

24-
public override CraftTree.Type FabricatorType => CraftTree.Type.Fabricator;
25-
public override TechCategory CategoryForPDA => TechCategory.BasicMaterials;
26-
public override TechGroup GroupForPDA => TechGroup.Resources;
27-
public override Vector2int SizeInInventory => new(1, 1);
28-
public override float CraftingTime => 3f;
29-
public override TechType RequiredForUnlock => TechType.CreepvinePiece;
30-
public override string[] StepsToFabricatorTab => new string[] { "Resources", "BasicMaterials" };
31-
protected override RecipeData GetBlueprintRecipe()
32-
{
33-
return new()
34-
{
35-
craftAmount = 4,
36-
Ingredients = new()
37-
{
38-
new(TechType.CreepvinePiece, 1)
39-
}
40-
};
41-
}
42-
protected override Sprite GetItemSprite()
43-
{
44-
return ImageUtils.LoadSpriteFromFile(Path.Combine(AssetsFolder, "Coal.png"));
45-
}
46-
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
23+
public override CraftTree.Type FabricatorType => CraftTree.Type.Fabricator;
24+
public override TechCategory CategoryForPDA => TechCategory.BasicMaterials;
25+
public override TechGroup GroupForPDA => TechGroup.Resources;
26+
public override Vector2int SizeInInventory => new(1, 1);
27+
public override float CraftingTime => 3f;
28+
public override TechType RequiredForUnlock => TechType.CreepvinePiece;
29+
public override string[] StepsToFabricatorTab => new string[] { "Resources", "BasicMaterials" };
30+
protected override RecipeData GetBlueprintRecipe()
31+
{
32+
return new()
4733
{
48-
if (prefab == null)
34+
craftAmount = 4,
35+
Ingredients = new()
4936
{
50-
CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.Titanium);
51-
yield return task;
52-
53-
prefab = GameObject.Instantiate(task.GetResult());
37+
new(TechType.CreepvinePiece, 1)
5438
}
39+
};
40+
}
41+
protected override Sprite GetItemSprite()
42+
{
43+
return Main.assets.LoadAsset<Sprite>("Coal");
44+
}
45+
public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
46+
{
47+
if (prefab == null)
48+
{
49+
CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.Titanium);
50+
yield return task;
5551

56-
GameObject go = GameObject.Instantiate(prefab);
57-
gameObject.Set(go);
52+
prefab = GameObject.Instantiate(task.GetResult());
5853
}
5954

60-
55+
GameObject go = GameObject.Instantiate(prefab);
56+
gameObject.Set(go);
6157
}
58+
59+
6260
}

0 commit comments

Comments
 (0)