Skip to content

Commit

Permalink
sdfx, remove sound and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Mar 15, 2023
1 parent ff81a12 commit 4377bd8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 71 deletions.
41 changes: 23 additions & 18 deletions IndustrialPark/ArchiveEditor/ArchiveEditorFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,13 @@ protected Asset CreateAsset(Section_AHDR AHDR, Game game, Endianness endianness)
{
case AssetType.Animation:
{
if (AHDR.data.Length != 0)
{
var magic = AHDR.data.Take(4).ToArray();
if (endianness == Endianness.Big)
magic = magic.Reverse().ToArray();
if (magic[0] == 'S' && magic[1] == 'K' && magic[2] == 'B' && magic[3] == '1')
return new AssetANIM(AHDR, game, endianness);
}
if (AHDR.data.Length == 0)
return new AssetGeneric(AHDR, game, endianness);
var magic = AHDR.data.Take(4).ToArray();
if (endianness == Endianness.Big)
magic = magic.Reverse().ToArray();
if (magic[0] == 'S' && magic[1] == 'K' && magic[2] == 'B' && magic[3] == '1')
return new AssetANIM(AHDR, game, endianness);
throw new Exception($"Invalid Animation asset: {AHDR.ADBG.assetName}");
}
case AssetType.BSP:
Expand Down Expand Up @@ -819,7 +818,7 @@ protected Asset CreateAsset(Section_AHDR AHDR, Game game, Endianness endianness)
case AssetType.Script:
return new AssetSCRP(AHDR, game, endianness);
case AssetType.SDFX:
return new AssetSDFX(AHDR, game, endianness);
return new AssetSDFX(AHDR, game, endianness, GetSGRP);
case AssetType.SFX:
return new AssetSFX(AHDR, game, endianness);
case AssetType.SoundGroup:
Expand Down Expand Up @@ -1156,20 +1155,19 @@ public void RemoveAsset(IEnumerable<uint> assetIDs)
RemoveAsset(u);
}

public void RemoveAsset(Asset asset)
{
RemoveAsset(asset.assetID);
}

public void RemoveAsset(uint assetID, bool removeSound = true)
{
DisposeOfAsset(assetID);
autoCompleteSource.Remove(assetDictionary[assetID].assetName);

Layers.ForEach(l => l.AssetIDs.Remove(assetID));

if (removeSound && GetFromAssetID(assetID).assetType.ToString().Contains("SND"))
RemoveSoundFromSNDI(assetID);
if (removeSound)
{
var assetType = GetFromAssetID(assetID).assetType;
if (assetType == AssetType.Sound || assetType == AssetType.SoundStream)
RemoveSoundFromSNDI(assetID);
}

assetDictionary.Remove(assetID);
}
Expand Down Expand Up @@ -1268,7 +1266,7 @@ public void PasteAssetsFromClipboard(out List<uint> finalIndices, AssetClipboard
try
{
AddSoundToSNDI(sound.Data, sound.assetID, sound.assetType, out byte[] soundData);
sound.Data = soundData;
AHDR.data = soundData;
}
catch (Exception ex)
{
Expand All @@ -1288,7 +1286,7 @@ public void PasteAssetsFromClipboard(out List<uint> finalIndices, AssetClipboard
{
var AHDR = clipboard.assets[i];
string error = "";

assetDictionary[AHDR.assetID] = TryCreateAsset(AHDR, clipboard.games[i], clipboard.endiannesses[i], true, ref error);
}
}
Expand Down Expand Up @@ -1444,6 +1442,13 @@ public AssetMRKR GetMRKR(uint mrkr)
return null;
}

public AssetSGRP GetSGRP(uint sgrp)
{
if (ContainsAsset(sgrp) && GetFromAssetID(sgrp) is AssetSGRP SGRP)
return SGRP;
return null;
}

protected AssetID[] defaultJspAssetIds = null;

private AssetID[] GetJspAssetIDs(uint jspInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ private Asset CreateFromTemplate(AssetTemplate template, string assetName, Vecto
case AssetTemplate.Cauldron_Sfx:
return new AssetSFX(assetName, position, game, template);
case AssetTemplate.SDFX:
return new AssetSDFX(assetName, position);
return new AssetSDFX(assetName, position, GetSGRP);
case AssetTemplate.Light:
case AssetTemplate.Cauldron_Light:
return new AssetLITE(assetName, position, template);
Expand Down
4 changes: 1 addition & 3 deletions IndustrialPark/ArchiveEditor/Dialogs/ProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ProgressBar(string text)
public void SetProgressBar(int min, int max, int step)
{
if (InvokeRequired)
Invoke(new SetValue(SetProgressBar), min, max, step);
Invoke(new Action<int, int, int>(SetProgressBar), min, max, step);
else
{
pBar.Minimum = min;
Expand All @@ -25,8 +25,6 @@ public void SetProgressBar(int min, int max, int step)
}
}

private delegate void SetValue(int min, int max, int step);

public void PerformStep(string label = "")
{
if (InvokeRequired)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HipHopFile;
using IndustrialPark.Models;
using SharpDX;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using static IndustrialPark.ArchiveEditorFunctions;
Expand Down Expand Up @@ -48,17 +49,16 @@ public int LaunchAngle
[Category(dynaCategoryName), ValidReferenceRequired]
public AssetID TargetTeleportBox { get; set; }

public DynaGObjectTeleport(string assetName, uint mrkrId, DynaGObjectTeleportGetMRKR getMRKR) : base(assetName, DynaType.game_object__Teleport, Vector3.Zero)
public DynaGObjectTeleport(string assetName, uint mrkrId, Func<uint, AssetMRKR> getMRKR) : base(assetName, DynaType.game_object__Teleport, Vector3.Zero)
{
_mrkr = mrkrId;
GetMRKR = getMRKR;
Version = 2;
}

public delegate AssetMRKR DynaGObjectTeleportGetMRKR(uint mrkr);
private DynaGObjectTeleportGetMRKR GetMRKR;
private Func<uint, AssetMRKR> GetMRKR;

public DynaGObjectTeleport(Section_AHDR AHDR, Game game, Endianness endianness, DynaGObjectTeleportGetMRKR getMRKR) : base(AHDR, DynaType.game_object__Teleport, game, endianness)
public DynaGObjectTeleport(Section_AHDR AHDR, Game game, Endianness endianness, Func<uint, AssetMRKR> getMRKR) : base(AHDR, DynaType.game_object__Teleport, game, endianness)
{
GetMRKR = getMRKR;

Expand All @@ -80,32 +80,24 @@ public DynaGObjectTeleport(Section_AHDR AHDR, Game game, Endianness endianness,

protected override void SerializeDyna(EndianBinaryWriter writer)
{

writer.Write(_mrkr);
writer.Write(Opened ? 1 : 0);
writer.Write(_launchAngle);
if (game != Game.Incredibles && Version > 1)
writer.Write(CameraAngle);
writer.Write(TargetTeleportBox);


}

private void ValidateMRKR()
{
MRKR = GetMRKR(_mrkr);
writer.Write(_mrkr);
writer.Write(Opened ? 1 : 0);
writer.Write(_launchAngle);
if (game != Game.Incredibles && Version > 1)
writer.Write(CameraAngle);
writer.Write(TargetTeleportBox);
}

public override AssetSingle PositionX
{
get
{
ValidateMRKR();
var MRKR = GetMRKR(_mrkr);
return MRKR != null ? MRKR.PositionX : 0;
}
set
{
ValidateMRKR();
var MRKR = GetMRKR(_mrkr);
if (MRKR != null)
MRKR.PositionX = value;
CreateTransformMatrix();
Expand All @@ -116,12 +108,12 @@ public override AssetSingle PositionY
{
get
{
ValidateMRKR();
var MRKR = GetMRKR(_mrkr);
return MRKR != null ? MRKR.PositionY : 0;
}
set
{
ValidateMRKR();
var MRKR = GetMRKR(_mrkr);
if (MRKR != null)
MRKR.PositionY = value;
CreateTransformMatrix();
Expand All @@ -132,12 +124,12 @@ public override AssetSingle PositionZ
{
get
{
ValidateMRKR();
var MRKR = GetMRKR(_mrkr);
return MRKR != null ? MRKR.PositionZ : 0;
}
set
{
ValidateMRKR();
var MRKR = GetMRKR(_mrkr);
if (MRKR != null)
MRKR.PositionZ = value;
CreateTransformMatrix();
Expand All @@ -150,8 +142,6 @@ public override AssetSingle PositionZ

private static readonly uint _modelAssetID = Functions.BKDRHash("teleportation_box_bind");

private AssetMRKR MRKR;

public override void CreateTransformMatrix()
{
world = Matrix.RotationY(MathUtil.DegreesToRadians(LaunchAngle)) * Matrix.Translation(PositionX, PositionY, PositionZ);
Expand Down
35 changes: 14 additions & 21 deletions IndustrialPark/Assets/ObjectAssets/ClickableAssets/AssetSDFX.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HipHopFile;
using SharpDX;
using System.Collections.Generic;
using System;
using System.ComponentModel;

namespace IndustrialPark
Expand All @@ -9,7 +9,7 @@ public class AssetSDFX : BaseAsset, IRenderableAsset, IClickableAsset
{
private const string categoryName = "SDFX";
public override string AssetInfo => HexUIntTypeConverter.StringFromAssetID(SoundGroup);

private uint _soundGroup;
[Category(categoryName), ValidReferenceRequired]
public AssetID SoundGroup
Expand Down Expand Up @@ -46,16 +46,22 @@ public AssetSingle PositionZ
null,
"Play from Entity");

public AssetSDFX(string assetName, Vector3 position) : base(assetName, AssetType.SDFX, BaseAssetType.SDFX)
private Func<uint, AssetSGRP> GetSGRP;

public AssetSDFX(string assetName, Vector3 position, Func<uint, AssetSGRP> getSGRP) : base(assetName, AssetType.SDFX, BaseAssetType.SDFX)
{
GetSGRP = getSGRP;

_position = position;

CreateTransformMatrix();
ArchiveEditorFunctions.AddToRenderableAssets(this);
}

public AssetSDFX(Section_AHDR AHDR, Game game, Endianness endianness) : base(AHDR, game, endianness)
public AssetSDFX(Section_AHDR AHDR, Game game, Endianness endianness, Func<uint, AssetSGRP> getSGRP) : base(AHDR, game, endianness)
{
GetSGRP = getSGRP;

using (var reader = new EndianBinaryReader(AHDR.data, endianness))
{
reader.BaseStream.Position = baseHeaderEndPosition;
Expand Down Expand Up @@ -140,34 +146,21 @@ public void Draw(SharpRenderer renderer)

public float GetDistanceFrom(Vector3 cameraPosition) => Vector3.Distance(cameraPosition, _position) - _radius;

private AssetSGRP soundGroup
{
get
{
if (Program.MainForm != null)
foreach (var ae in Program.MainForm.archiveEditors)
if (ae.archive.ContainsAsset(SoundGroup))
if (ae.archive.GetFromAssetID(SoundGroup) is AssetSGRP sgrp)
return sgrp;
return null;
}
}

private float _radius
{
get
{
var sg = soundGroup;
return sg == null ? 1f : (float)sg.InnerRadius;
var soundGroup = GetSGRP(_soundGroup);
return soundGroup == null ? 1f : (float)soundGroup.InnerRadius;
}
}

private float _radius2
{
get
{
var sg = soundGroup;
return sg == null ? 1f : (float)sg.OuterRadius;
var soundGroup = GetSGRP(_soundGroup);
return soundGroup == null ? 1f : (float)soundGroup.OuterRadius;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions IndustrialPark/SharpDX/SharpRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ public void ResetColors()

DefaultRenderData renderData;

public delegate void DrawGeneric(Matrix world, bool isSelected, float multiplier);

public void DrawCube(Matrix world, bool isSelected, float multiplier = 0.5f)
{
renderData.worldViewProjection = Matrix.Scaling(multiplier) * world * viewProjection;
Expand Down

0 comments on commit 4377bd8

Please sign in to comment.