From 9f174c8d0122ece30fc4fcabcd82f32b0f9d87f5 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 26 Sep 2018 17:14:27 +0200 Subject: [PATCH 01/88] Added all the modifications Signed-off-by: djpadbit --- BUILD.bat | 3 - gradlew | 0 .../com/sonicether/soundphysics/Config.java | 10 + .../soundphysics/CoreModInjector.java | 33 +- .../sonicether/soundphysics/ReverbParams.java | 180 +- .../sonicether/soundphysics/SoundPhysics.java | 1455 +++++++++-------- z_Link.bat | 1 - z_Setup.bat | 1 - 8 files changed, 946 insertions(+), 737 deletions(-) delete mode 100644 BUILD.bat mode change 100644 => 100755 gradlew delete mode 100644 z_Link.bat delete mode 100644 z_Setup.bat diff --git a/BUILD.bat b/BUILD.bat deleted file mode 100644 index 224c3705..00000000 --- a/BUILD.bat +++ /dev/null @@ -1,3 +0,0 @@ -rd /s "./build/classes/main/" -del /s "./build/libs/" -gradlew build \ No newline at end of file diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 045043ae..a7c9aec3 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -30,7 +30,10 @@ public class Config { // performance public static boolean skipRainOcclusionTracing; public static int environmentEvaluationRays; + public static int environmentEvaluationRaysBounces; public static boolean simplerSharedAirspaceSimulation; + public static boolean dynamicEnvironementEvalutaion; + public static int dynamicEnvironementEvalutaionFrequency; // block properties public static float stoneReflectivity; @@ -108,9 +111,16 @@ private void syncConfig() { environmentEvaluationRays = this.forgeConfig.getInt("Environment Evaluation Rays", categoryPerformance, 32, 8, 64, "The number of rays to trace to determine reverberation for each sound source. More rays provides more consistent tracing results but takes more time to calculate. Decrease this value if you experience lag spikes when sounds play."); + environmentEvaluationRaysBounces = this.forgeConfig.getInt("Environment Evaluation Rays Bounces", categoryPerformance, 4, 1, + 64, + "The number of rays bounces to determine reverberation for each sound source. More bounces provides more consistent tracing results but takes more time to calculate. Decrease this value if you experience lag spikes when sounds play."); simplerSharedAirspaceSimulation = this.forgeConfig.getBoolean("Simpler Shared Airspace Simulation", categoryPerformance, false, "If true, enables a simpler technique for determining when the player and a sound source share airspace. Might sometimes miss recognizing shared airspace, but it's faster to calculate."); + dynamicEnvironementEvalutaion = this.forgeConfig.getBoolean("Dynamic environment evaluation", categoryPerformance, true, + "WARNING it's implemented really badly so i'd recommend not always using it.If true, the environment will keep getting evaluated for every sound that is currently playing. This may affect performance"); + dynamicEnvironementEvalutaionFrequency = this.forgeConfig.getInt("Frequency of environment evaluation", categoryPerformance, 30, 1, 60, + "The frequency at witch to update environment of sounds if dynamic environment evaluation is enabled"); // material properties stoneReflectivity = this.forgeConfig.getFloat("Stone Reflectivity", categoryMaterialProperties, 0.95f, 0.0f, diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 76153951..5626ef7b 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -35,6 +35,15 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte if (obfuscated.equals("chm")) { // Inside SoundManager InsnList toInject = new InsnList(); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "setLastSound", "(Lnet/minecraft/client/audio/ISound;)V", false)); + + // Target method: playSound + bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setVolume", null, toInject, false, 0, 0, false, 0); + + toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 7)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", @@ -141,6 +150,27 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Inside target method, target node: Entity/getSoundCategory bytes = patchMethodInClass(obfuscated, bytes, "a", "(Lqe;FF)V", Opcodes.INVOKEVIRTUAL, AbstractInsnNode.METHOD_INSN, "bK", null, toInject, true, 0, 0, false, -3); + } else + // Fix for computronics's sound card and tape drive + if (obfuscated.equals("pl.asie.lib.audio.StreamingAudioPlayer")) { + // Inside StreamingAudioPlayer + InsnList toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.FLOAD, 2)); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 3)); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 4)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 8)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/lib/audio/StreamingAudioPlayer$SourceEntry", "src", + "Ljava/nio/IntBuffer;")); + toInject.add(new InsnNode(Opcodes.ICONST_0)); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/nio/IntBuffer", "get", "(I)I", false)); + + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "onPlaySound", "(FFFI)V", false)); + + // Target method: play + bytes = patchMethodInClass(obfuscated, bytes, "play", "(Ljava/lang/String;FFFF)V", Opcodes.INVOKESTATIC, + AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, toInject, false, 0, 0, false, 0); } return bytes; @@ -161,13 +191,12 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St final MethodNode m = methodIterator.next(); if (m.name.equals(targetMethod) && m.desc.equals(targetMethodSignature)) { - AbstractInsnNode targetNode = null; final ListIterator nodeIterator = m.instructions.iterator(); while (nodeIterator.hasNext()) { AbstractInsnNode currentNode = nodeIterator.next(); - + if (currentNode.getOpcode() == targetNodeOpcode) { if (targetNodeType == AbstractInsnNode.METHOD_INSN) { diff --git a/src/main/java/com/sonicether/soundphysics/ReverbParams.java b/src/main/java/com/sonicether/soundphysics/ReverbParams.java index 97f269f0..ec740c12 100644 --- a/src/main/java/com/sonicether/soundphysics/ReverbParams.java +++ b/src/main/java/com/sonicether/soundphysics/ReverbParams.java @@ -1,90 +1,90 @@ -package com.sonicether.soundphysics; - -public class ReverbParams { - - public float decayTime; // min: 0.1f max: 10.0f - public float density; // min: 0.0f max: 1.0f - public float diffusion; // min: 0.0f max: 1.0f - public float gain; // min: 0.0f max: 1.0f - public float gainHF; // min: 0.0f max: 1.0f - public float decayHFRatio; // min: 0.1f max: 2.0f - public float reflectionsGain; // min: 0.1f max: 3.16f - public float reflectionsDelay; // min: 0.0f max: 0.3f - public float lateReverbGain; // min: 0.0f max: 10.0f - public float lateReverbDelay; // min: 0.0f max: 0.1f - public float airAbsorptionGainHF; // min: 0.892f max: 1.0f - public float roomRolloffFactor; // min: 0.0f max: 10.0f - - public static ReverbParams getReverb0() { - final ReverbParams r = new ReverbParams(); - r.decayTime = 0.15f; - r.density = 0.0f; - r.diffusion = 1.0f; - r.gain = 0.2f * SoundPhysics.globalReverbMultiplier * 0.85f; - r.gainHF = 0.99f; - r.decayHFRatio = 0.6f * Config.globalReverbBrightness; - r.reflectionsGain = 2.5f; - r.reflectionsDelay = 0.001f; - r.lateReverbGain = 1.26f; - r.lateReverbDelay = 0.011f; - r.airAbsorptionGainHF = 0.994f; - r.roomRolloffFactor = 0.16f * Config.rolloffFactor; - - return r; - } - - public static ReverbParams getReverb1() { - final ReverbParams r = new ReverbParams(); - r.decayTime = 0.55f; - r.density = 0.0f; - r.diffusion = 1.0f; - r.gain = 0.3f * SoundPhysics.globalReverbMultiplier * 0.85f; - r.gainHF = 0.99f; - r.decayHFRatio = 0.7f * Config.globalReverbBrightness; - r.reflectionsGain = 0.2f; - r.reflectionsDelay = 0.015f; - r.lateReverbGain = 1.26f; - r.lateReverbDelay = 0.011f; - r.airAbsorptionGainHF = 0.994f; - r.roomRolloffFactor = 0.15f * Config.rolloffFactor; - - return r; - } - - public static ReverbParams getReverb2() { - final ReverbParams r = new ReverbParams(); - r.decayTime = 1.68f; - r.density = 0.1f; - r.diffusion = 1.0f; - r.gain = 0.5f * SoundPhysics.globalReverbMultiplier * 0.85f; - r.gainHF = 0.99f; - r.decayHFRatio = 0.7f * Config.globalReverbBrightness; - r.reflectionsGain = 0.0f; - r.reflectionsDelay = 0.021f; - r.lateReverbGain = 1.26f; - r.lateReverbDelay = 0.021f; - r.airAbsorptionGainHF = 0.994f; - r.roomRolloffFactor = 0.13f * Config.rolloffFactor; - - return r; - } - - public static ReverbParams getReverb3() { - final ReverbParams r = new ReverbParams(); - r.decayTime = 4.142f; - r.density = 0.5f; - r.diffusion = 1.0f; - r.gain = 0.4f * SoundPhysics.globalReverbMultiplier * 0.85f; - r.gainHF = 0.89f; - r.decayHFRatio = 0.7f * Config.globalReverbBrightness; - r.reflectionsGain = 0.0f; - r.reflectionsDelay = 0.025f; - r.lateReverbGain = 1.26f; - r.lateReverbDelay = 0.021f; - r.airAbsorptionGainHF = 0.994f; - r.roomRolloffFactor = 0.11f * Config.rolloffFactor; - - return r; - } - -} +package com.sonicether.soundphysics; + +public class ReverbParams { + + public float decayTime; // min: 0.1f max: 10.0f + public float density; // min: 0.0f max: 1.0f + public float diffusion; // min: 0.0f max: 1.0f + public float gain; // min: 0.0f max: 1.0f + public float gainHF; // min: 0.0f max: 1.0f + public float decayHFRatio; // min: 0.1f max: 2.0f + public float reflectionsGain; // min: 0.1f max: 3.16f + public float reflectionsDelay; // min: 0.0f max: 0.3f + public float lateReverbGain; // min: 0.0f max: 10.0f + public float lateReverbDelay; // min: 0.0f max: 0.1f + public float airAbsorptionGainHF; // min: 0.892f max: 1.0f + public float roomRolloffFactor; // min: 0.0f max: 10.0f + + public static ReverbParams getReverb0() { + final ReverbParams r = new ReverbParams(); + r.decayTime = 0.15f; + r.density = 0.0f; + r.diffusion = 1.0f; + r.gain = 0.2f * SoundPhysics.globalReverbMultiplier * 0.85f; + r.gainHF = 0.99f; + r.decayHFRatio = 0.6f * Config.globalReverbBrightness; + r.reflectionsGain = 2.5f; + r.reflectionsDelay = 0.001f; + r.lateReverbGain = 1.26f; + r.lateReverbDelay = 0.011f; + r.airAbsorptionGainHF = 0.994f; + r.roomRolloffFactor = 0.16f * Config.rolloffFactor; + + return r; + } + + public static ReverbParams getReverb1() { + final ReverbParams r = new ReverbParams(); + r.decayTime = 0.55f; + r.density = 0.0f; + r.diffusion = 1.0f; + r.gain = 0.3f * SoundPhysics.globalReverbMultiplier * 0.85f; + r.gainHF = 0.99f; + r.decayHFRatio = 0.7f * Config.globalReverbBrightness; + r.reflectionsGain = 0.2f; + r.reflectionsDelay = 0.015f; + r.lateReverbGain = 1.26f; + r.lateReverbDelay = 0.011f; + r.airAbsorptionGainHF = 0.994f; + r.roomRolloffFactor = 0.15f * Config.rolloffFactor; + + return r; + } + + public static ReverbParams getReverb2() { + final ReverbParams r = new ReverbParams(); + r.decayTime = 1.68f; + r.density = 0.1f; + r.diffusion = 1.0f; + r.gain = 0.5f * SoundPhysics.globalReverbMultiplier * 0.85f; + r.gainHF = 0.99f; + r.decayHFRatio = 0.7f * Config.globalReverbBrightness; + r.reflectionsGain = 0.0f; + r.reflectionsDelay = 0.021f; + r.lateReverbGain = 1.26f; + r.lateReverbDelay = 0.021f; + r.airAbsorptionGainHF = 0.994f; + r.roomRolloffFactor = 0.13f * Config.rolloffFactor; + + return r; + } + + public static ReverbParams getReverb3() { + final ReverbParams r = new ReverbParams(); + r.decayTime = 4.142f; + r.density = 0.5f; + r.diffusion = 1.0f; + r.gain = 0.4f * SoundPhysics.globalReverbMultiplier * 0.85f; + r.gainHF = 0.89f; + r.decayHFRatio = 0.7f * Config.globalReverbBrightness; + r.reflectionsGain = 0.0f; + r.reflectionsDelay = 0.025f; + r.lateReverbGain = 1.26f; + r.lateReverbDelay = 0.021f; + r.airAbsorptionGainHF = 0.994f; + r.roomRolloffFactor = 0.11f * Config.rolloffFactor; + + return r; + } + +} diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 57a41b1b..528b6732 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -1,640 +1,815 @@ -package com.sonicether.soundphysics; - -import java.util.regex.Pattern; - -import org.lwjgl.openal.AL10; -import org.lwjgl.openal.AL11; -import org.lwjgl.openal.ALC10; -import org.lwjgl.openal.ALCcontext; -import org.lwjgl.openal.ALCdevice; -import org.lwjgl.openal.EFX10; - -import net.minecraft.block.Block; -import net.minecraft.block.SoundType; -import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.Entity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvent; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import paulscode.sound.SoundSystemConfig; - -@Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory") -public class SoundPhysics { - - public static final String modid = "soundphysics"; - public static final String version = "1.0.4"; - public static final String mcVersion = "1.12.2"; - - private static final Pattern rainPattern = Pattern.compile(".*rain.*"); - private static final Pattern stepPattern = Pattern.compile(".*step.*"); - private static final Pattern blockPattern = Pattern.compile(".*block.*"); - - @Mod.EventHandler - public void preInit(final FMLPreInitializationEvent event) { - Config.instance.preInit(event); - } - - @Mod.EventHandler - public void init(final FMLInitializationEvent event) { - Config.instance.init(event); - } - - private static final String logPrefix = "[SOUND PHYSICS]"; - private static int auxFXSlot0; - private static int auxFXSlot1; - private static int auxFXSlot2; - private static int auxFXSlot3; - private static int reverb0; - private static int reverb1; - private static int reverb2; - private static int reverb3; - private static int directFilter0; - private static int sendFilter0; - private static int sendFilter1; - private static int sendFilter2; - private static int sendFilter3; - - private static Minecraft mc; - - private static SoundCategory lastSoundCategory; - private static String lastSoundName; - - // THESE VARIABLES ARE CONSTANTLY ACCESSED AND USED BY ASM INJECTED CODE! DO - // NOT REMOVE! - public static int attenuationModel = SoundSystemConfig.ATTENUATION_ROLLOFF; - public static float globalRolloffFactor = Config.rolloffFactor; - public static float globalVolumeMultiplier = 4.0f; - public static float globalReverbMultiplier = 0.7f * Config.globalReverbGain; - public static double soundDistanceAllowance = Config.soundDistanceAllowance; - - /** - * CALLED BY ASM INJECTED CODE! - */ - public static void init() { - setupEFX(); - mc = Minecraft.getMinecraft(); - } - - public static void applyConfigChanges() { - globalRolloffFactor = Config.rolloffFactor; - globalReverbMultiplier = 0.7f * Config.globalReverbGain; - soundDistanceAllowance = Config.soundDistanceAllowance; - - if (auxFXSlot0 != 0) { - // Set the global reverb parameters and apply them to the effect and - // effectslot - setReverbParams(ReverbParams.getReverb0(), auxFXSlot0, reverb0); - setReverbParams(ReverbParams.getReverb1(), auxFXSlot1, reverb1); - setReverbParams(ReverbParams.getReverb2(), auxFXSlot2, reverb2); - setReverbParams(ReverbParams.getReverb3(), auxFXSlot3, reverb3); - } - } - - private static void setupEFX() { - // Get current context and device - final ALCcontext currentContext = ALC10.alcGetCurrentContext(); - final ALCdevice currentDevice = ALC10.alcGetContextsDevice(currentContext); - - if (ALC10.alcIsExtensionPresent(currentDevice, "ALC_EXT_EFX")) { - log("EFX Extension recognized."); - } else { - logError("EFX Extension not found on current device. Aborting."); - return; - } - - // Create auxiliary effect slots - auxFXSlot0 = EFX10.alGenAuxiliaryEffectSlots(); - log("Aux slot " + auxFXSlot0 + " created"); - EFX10.alAuxiliaryEffectSloti(auxFXSlot0, EFX10.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, AL10.AL_TRUE); - - auxFXSlot1 = EFX10.alGenAuxiliaryEffectSlots(); - log("Aux slot " + auxFXSlot1 + " created"); - EFX10.alAuxiliaryEffectSloti(auxFXSlot1, EFX10.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, AL10.AL_TRUE); - - auxFXSlot2 = EFX10.alGenAuxiliaryEffectSlots(); - log("Aux slot " + auxFXSlot2 + " created"); - EFX10.alAuxiliaryEffectSloti(auxFXSlot2, EFX10.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, AL10.AL_TRUE); - - auxFXSlot3 = EFX10.alGenAuxiliaryEffectSlots(); - log("Aux slot " + auxFXSlot3 + " created"); - EFX10.alAuxiliaryEffectSloti(auxFXSlot3, EFX10.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, AL10.AL_TRUE); - checkErrorLog("Failed creating auxiliary effect slots!"); - - reverb0 = EFX10.alGenEffects(); - EFX10.alEffecti(reverb0, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_EAXREVERB); - checkErrorLog("Failed creating reverb effect slot 0!"); - reverb1 = EFX10.alGenEffects(); - EFX10.alEffecti(reverb1, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_EAXREVERB); - checkErrorLog("Failed creating reverb effect slot 1!"); - reverb2 = EFX10.alGenEffects(); - EFX10.alEffecti(reverb2, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_EAXREVERB); - checkErrorLog("Failed creating reverb effect slot 2!"); - reverb3 = EFX10.alGenEffects(); - EFX10.alEffecti(reverb3, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_EAXREVERB); - checkErrorLog("Failed creating reverb effect slot 3!"); - - // Create filters - directFilter0 = EFX10.alGenFilters(); - EFX10.alFilteri(directFilter0, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); - - sendFilter0 = EFX10.alGenFilters(); - EFX10.alFilteri(sendFilter0, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); - - sendFilter1 = EFX10.alGenFilters(); - EFX10.alFilteri(sendFilter1, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); - - sendFilter2 = EFX10.alGenFilters(); - EFX10.alFilteri(sendFilter2, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); - - sendFilter3 = EFX10.alGenFilters(); - EFX10.alFilteri(sendFilter3, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); - checkErrorLog("Error creating lowpass filters!"); - - applyConfigChanges(); - } - - /** - * CALLED BY ASM INJECTED CODE! - */ - public static void setLastSoundCategory(final SoundCategory sc) { - lastSoundCategory = sc; - } - - /** - * CALLED BY ASM INJECTED CODE! - */ - public static void setLastSoundName(final String name) { - lastSoundName = name; - } - - /** - * CALLED BY ASM INJECTED CODE! - */ - public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID) { - evaluateEnvironment(sourceID, posX, posY, posZ); - } - - /** - * CALLED BY ASM INJECTED CODE! - */ - public static double calculateEntitySoundOffset(final Entity entity, final SoundEvent sound) { - if (stepPattern.matcher(sound.getSoundName().getResourcePath()).matches()) { - return 0; - } - - return entity.getEyeHeight(); - } - - @SuppressWarnings("deprecation") - private static float getBlockReflectivity(final BlockPos blockPos) { - final Block block = mc.world.getBlockState(blockPos).getBlock(); - final SoundType soundType = block.getSoundType(); - - float reflectivity = 0.5f; - - if (soundType == SoundType.STONE) { - reflectivity = Config.stoneReflectivity; - } else if (soundType == SoundType.WOOD) { - reflectivity = Config.woodReflectivity; - } else if (soundType == SoundType.GROUND) { - reflectivity = Config.groundReflectivity; - } else if (soundType == SoundType.PLANT) { - reflectivity = Config.plantReflectivity; - } else if (soundType == SoundType.METAL) { - reflectivity = Config.metalReflectivity; - } else if (soundType == SoundType.GLASS) { - reflectivity = Config.glassReflectivity; - } else if (soundType == SoundType.CLOTH) { - reflectivity = Config.clothReflectivity; - } else if (soundType == SoundType.SAND) { - reflectivity = Config.sandReflectivity; - } else if (soundType == SoundType.SNOW) { - reflectivity = Config.snowReflectivity; - } else if (soundType == SoundType.LADDER) { - reflectivity = Config.woodReflectivity; - } else if (soundType == SoundType.ANVIL) { - reflectivity = Config.metalReflectivity; - } - - reflectivity *= Config.globalBlockReflectance; - - return reflectivity; - } - - private static Vec3d getNormalFromFacing(final EnumFacing sideHit) { - return new Vec3d(sideHit.getDirectionVec()); - } - - private static Vec3d reflect(final Vec3d dir, final Vec3d normal) { - final double dot2 = dir.dotProduct(normal) * 2; - - final double x = dir.x - dot2 * normal.x; - final double y = dir.y - dot2 * normal.y; - final double z = dir.z - dot2 * normal.z; - - return new Vec3d(x, y, z); - } - - private static Vec3d offsetSoundByName(final double soundX, final double soundY, final double soundZ, - final Vec3d playerPos, final String name, final SoundCategory category) { - double offsetX = 0.0; - double offsetY = 0.0; - double offsetZ = 0.0; - double offsetTowardsPlayer = 0.0; - - double tempNormX = 0; - double tempNormY = 0; - double tempNormZ = 0; - - if (soundY % 1.0 < 0.001 || stepPattern.matcher(name).matches()) { - offsetY = 0.1; - } - - if (category == SoundCategory.BLOCKS || blockPattern.matcher(name).matches()) { - // The ray will probably hit the block that it's emitting from - // before - // escaping. Offset the ray start position towards the player by the - // diagonal half length of a cube - - tempNormX = playerPos.x - soundX; - tempNormY = playerPos.y - soundY; - tempNormZ = playerPos.z - soundZ; - final double length = Math.sqrt(tempNormX * tempNormX + tempNormY * tempNormY + tempNormZ * tempNormZ); - tempNormX /= length; - tempNormY /= length; - tempNormZ /= length; - // 0.867 > square root of 0.5^2 * 3 - offsetTowardsPlayer = 0.867; - offsetX += tempNormX * offsetTowardsPlayer; - offsetY += tempNormY * offsetTowardsPlayer; - offsetZ += tempNormZ * offsetTowardsPlayer; - } - - return new Vec3d(soundX + offsetX, soundY + offsetY, soundZ + offsetZ); - } - - @SuppressWarnings("deprecation") - private static void evaluateEnvironment(final int sourceID, final float posX, final float posY, final float posZ) { - if (mc.player == null | mc.world == null | posY <= 0 | lastSoundCategory == SoundCategory.RECORDS - | lastSoundCategory == SoundCategory.MUSIC) { - // posY <= 0 as a condition has to be there: Ingame - // menu clicks do have a player and world present - setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); - return; - } - - final boolean isRain = rainPattern.matcher(lastSoundName).matches(); - - if (Config.skipRainOcclusionTracing && isRain) { - setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); - return; - } - - float directCutoff = 1.0f; - final float absorptionCoeff = Config.globalBlockAbsorption * 3.0f; - - final Vec3d playerPos = new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ); - final Vec3d soundPos = offsetSoundByName(posX, posY, posZ, playerPos, lastSoundName, lastSoundCategory); - final Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize(); - - Vec3d rayOrigin = soundPos; - - float occlusionAccumulation = 0.0f; - - for (int i = 0; i < 10; i++) { - final RayTraceResult rayHit = mc.world.rayTraceBlocks(rayOrigin, playerPos, true); - - if (rayHit == null) { - break; - } - - final Block blockHit = mc.world.getBlockState(rayHit.getBlockPos()).getBlock(); - - float blockOcclusion = 1.0f; - - if (!blockHit.isOpaqueCube(blockHit.getDefaultState())) { - // log("not a solid block!"); - blockOcclusion *= 0.15f; - } - - occlusionAccumulation += blockOcclusion; - - rayOrigin = new Vec3d(rayHit.hitVec.x + normalToPlayer.x * 0.1, rayHit.hitVec.y + normalToPlayer.y * 0.1, - rayHit.hitVec.z + normalToPlayer.z * 0.1); - } - - directCutoff = (float) Math.exp(-occlusionAccumulation * absorptionCoeff); - float directGain = (float) Math.pow(directCutoff, 0.1); - - // Calculate reverb parameters for this sound - float sendGain0 = 0.0f; - float sendGain1 = 0.0f; - float sendGain2 = 0.0f; - float sendGain3 = 0.0f; - - float sendCutoff0 = 1.0f; - float sendCutoff1 = 1.0f; - float sendCutoff2 = 1.0f; - float sendCutoff3 = 1.0f; - - if (mc.player.isInsideOfMaterial(Material.WATER)) { - directCutoff *= 1.0f - Config.underwaterFilter; - } - - if (isRain) { - setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, - sendCutoff3, directCutoff, directGain); - return; - } - - // Shoot rays around sound - final float phi = 1.618033988f; - final float gAngle = phi * (float) Math.PI * 2.0f; - final float maxDistance = 256.0f; - - final int numRays = Config.environmentEvaluationRays; - final int rayBounces = 4; - - final float[] bounceReflectivityRatio = new float[rayBounces]; - - float sharedAirspace = 0.0f; - - final float rcpTotalRays = 1.0f / (numRays * rayBounces); - final float rcpPrimaryRays = 1.0f / numRays; - - for (int i = 0; i < numRays; i++) { - final float fi = i; - final float fiN = fi / numRays; - final float longitude = gAngle * fi; - final float latitude = (float) Math.asin(fiN * 2.0f - 1.0f); - - final Vec3d rayDir = new Vec3d(Math.cos(latitude) * Math.cos(longitude), - Math.cos(latitude) * Math.sin(longitude), Math.sin(latitude)); - - final Vec3d rayStart = new Vec3d(soundPos.x, soundPos.y, soundPos.z); - - final Vec3d rayEnd = new Vec3d(rayStart.x + rayDir.x * maxDistance, rayStart.y + rayDir.y * maxDistance, - rayStart.z + rayDir.z * maxDistance); - - final RayTraceResult rayHit = mc.world.rayTraceBlocks(rayStart, rayEnd, true); - - if (rayHit != null) { - final double rayLength = soundPos.distanceTo(rayHit.hitVec); - - // Additional bounces - BlockPos lastHitBlock = rayHit.getBlockPos(); - Vec3d lastHitPos = rayHit.hitVec; - Vec3d lastHitNormal = getNormalFromFacing(rayHit.sideHit); - Vec3d lastRayDir = rayDir; - - float totalRayDistance = (float) rayLength; - - // Secondary ray bounces - for (int j = 0; j < rayBounces; j++) { - final Vec3d newRayDir = reflect(lastRayDir, lastHitNormal); - // Vec3d newRayDir = lastHitNormal; - final Vec3d newRayStart = new Vec3d(lastHitPos.x + lastHitNormal.x * 0.01, - lastHitPos.y + lastHitNormal.y * 0.01, lastHitPos.z + lastHitNormal.z * 0.01); - final Vec3d newRayEnd = new Vec3d(newRayStart.x + newRayDir.x * maxDistance, - newRayStart.y + newRayDir.y * maxDistance, newRayStart.z + newRayDir.z * maxDistance); - - final RayTraceResult newRayHit = mc.world.rayTraceBlocks(newRayStart, newRayEnd, true); - - float energyTowardsPlayer = 0.25f; - final float blockReflectivity = getBlockReflectivity(lastHitBlock); - energyTowardsPlayer *= blockReflectivity * 0.75f + 0.25f; - - if (newRayHit == null) { - totalRayDistance += lastHitPos.distanceTo(playerPos); - } else { - final double newRayLength = lastHitPos.distanceTo(newRayHit.hitVec); - - bounceReflectivityRatio[j] += blockReflectivity; - - totalRayDistance += newRayLength; - - lastHitPos = newRayHit.hitVec; - lastHitNormal = getNormalFromFacing(newRayHit.sideHit); - lastRayDir = newRayDir; - lastHitBlock = newRayHit.getBlockPos(); - - // Cast one final ray towards the player. If it's - // unobstructed, then the sound source and the player - // share airspace. - if (Config.simplerSharedAirspaceSimulation && j == rayBounces - 1 - || !Config.simplerSharedAirspaceSimulation) { - final Vec3d finalRayStart = new Vec3d(lastHitPos.x + lastHitNormal.x * 0.01, - lastHitPos.y + lastHitNormal.y * 0.01, lastHitPos.z + lastHitNormal.z * 0.01); - - final RayTraceResult finalRayHit = mc.world.rayTraceBlocks(finalRayStart, playerPos, true); - - if (finalRayHit == null) { - // log("Secondary ray hit the player!"); - sharedAirspace += 1.0f; - } - } - } - - final float reflectionDelay = (float) Math.max(totalRayDistance, 0.0) * 0.12f * blockReflectivity; - - final float cross0 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 0.0f), 0.0f, 1.0f); - final float cross1 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 1.0f), 0.0f, 1.0f); - final float cross2 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 2.0f), 0.0f, 1.0f); - final float cross3 = MathHelper.clamp(reflectionDelay - 2.0f, 0.0f, 1.0f); - - sendGain0 += cross0 * energyTowardsPlayer * 6.4f * rcpTotalRays; - sendGain1 += cross1 * energyTowardsPlayer * 12.8f * rcpTotalRays; - sendGain2 += cross2 * energyTowardsPlayer * 12.8f * rcpTotalRays; - sendGain3 += cross3 * energyTowardsPlayer * 12.8f * rcpTotalRays; - - // Nowhere to bounce off of, stop bouncing! - if (newRayHit == null) { - break; - } - } - } - - } - - // log("total reflectivity ratio: " + totalReflectivityRatio); - - bounceReflectivityRatio[0] = bounceReflectivityRatio[0] / numRays; - bounceReflectivityRatio[1] = bounceReflectivityRatio[1] / numRays; - bounceReflectivityRatio[2] = bounceReflectivityRatio[2] / numRays; - bounceReflectivityRatio[3] = bounceReflectivityRatio[3] / numRays; - - sharedAirspace *= 64.0f; - - if (Config.simplerSharedAirspaceSimulation) { - sharedAirspace *= rcpPrimaryRays; - } else { - sharedAirspace *= rcpTotalRays; - } - - final float sharedAirspaceWeight0 = MathHelper.clamp(sharedAirspace / 20.0f, 0.0f, 1.0f); - final float sharedAirspaceWeight1 = MathHelper.clamp(sharedAirspace / 15.0f, 0.0f, 1.0f); - final float sharedAirspaceWeight2 = MathHelper.clamp(sharedAirspace / 10.0f, 0.0f, 1.0f); - final float sharedAirspaceWeight3 = MathHelper.clamp(sharedAirspace / 10.0f, 0.0f, 1.0f); - - sendCutoff0 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.0f) * (1.0f - sharedAirspaceWeight0) - + sharedAirspaceWeight0; - sendCutoff1 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.0f) * (1.0f - sharedAirspaceWeight1) - + sharedAirspaceWeight1; - sendCutoff2 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.5f) * (1.0f - sharedAirspaceWeight2) - + sharedAirspaceWeight2; - sendCutoff3 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.5f) * (1.0f - sharedAirspaceWeight3) - + sharedAirspaceWeight3; - - // attempt to preserve directionality when airspace is shared by - // allowing some of the dry signal through but filtered - final float averageSharedAirspace = (sharedAirspaceWeight0 + sharedAirspaceWeight1 + sharedAirspaceWeight2 - + sharedAirspaceWeight3) * 0.25f; - directCutoff = Math.max((float) Math.pow(averageSharedAirspace, 0.5) * 0.2f, directCutoff); - - directGain = (float) Math.pow(directCutoff, 0.1); - - sendGain1 *= bounceReflectivityRatio[1]; - sendGain2 *= (float) Math.pow(bounceReflectivityRatio[2], 3.0); - sendGain3 *= (float) Math.pow(bounceReflectivityRatio[3], 4.0); - - sendGain0 = MathHelper.clamp(sendGain0, 0.0f, 1.0f); - sendGain1 = MathHelper.clamp(sendGain1, 0.0f, 1.0f); - sendGain2 = MathHelper.clamp(sendGain2 * 1.05f - 0.05f, 0.0f, 1.0f); - sendGain3 = MathHelper.clamp(sendGain3 * 1.05f - 0.05f, 0.0f, 1.0f); - - sendGain0 *= (float) Math.pow(sendCutoff0, 0.1); - sendGain1 *= (float) Math.pow(sendCutoff1, 0.1); - sendGain2 *= (float) Math.pow(sendCutoff2, 0.1); - sendGain3 *= (float) Math.pow(sendCutoff3, 0.1); - - if (mc.player.isInWater()) { - sendCutoff0 *= 0.4f; - sendCutoff1 *= 0.4f; - sendCutoff2 *= 0.4f; - sendCutoff3 *= 0.4f; - } - - setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, - sendCutoff3, directCutoff, directGain); - } - - private static void setEnvironment(final int sourceID, final float sendGain0, final float sendGain1, - final float sendGain2, final float sendGain3, final float sendCutoff0, final float sendCutoff1, - final float sendCutoff2, final float sendCutoff3, final float directCutoff, final float directGain) { - // Set reverb send filter values and set source to send to all reverb fx - // slots - EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAIN, sendGain0); - EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAINHF, sendCutoff0); - AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot0, 0, sendFilter0); - - EFX10.alFilterf(sendFilter1, EFX10.AL_LOWPASS_GAIN, sendGain1); - EFX10.alFilterf(sendFilter1, EFX10.AL_LOWPASS_GAINHF, sendCutoff1); - AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot1, 1, sendFilter1); - - EFX10.alFilterf(sendFilter2, EFX10.AL_LOWPASS_GAIN, sendGain2); - EFX10.alFilterf(sendFilter2, EFX10.AL_LOWPASS_GAINHF, sendCutoff2); - AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot2, 2, sendFilter2); - - EFX10.alFilterf(sendFilter3, EFX10.AL_LOWPASS_GAIN, sendGain3); - EFX10.alFilterf(sendFilter3, EFX10.AL_LOWPASS_GAINHF, sendCutoff3); - AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot3, 3, sendFilter3); - - EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAIN, directGain); - EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAINHF, directCutoff); - AL10.alSourcei(sourceID, EFX10.AL_DIRECT_FILTER, directFilter0); - - AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, Config.airAbsorption); - } - - /** - * Applies the parameters in the enum ReverbParams to the main reverb - * effect. - */ - protected static void setReverbParams(final ReverbParams r, final int auxFXSlot, final int reverbSlot) { - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_DENSITY, r.density); - checkErrorLog("Error while assigning reverb density: " + r.density); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_DIFFUSION, r.diffusion); - checkErrorLog("Error while assigning reverb diffusion: " + r.diffusion); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_GAIN, r.gain); - checkErrorLog("Error while assigning reverb gain: " + r.gain); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_GAINHF, r.gainHF); - checkErrorLog("Error while assigning reverb gainHF: " + r.gainHF); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_DECAY_TIME, r.decayTime); - checkErrorLog("Error while assigning reverb decayTime: " + r.decayTime); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_DECAY_HFRATIO, r.decayHFRatio); - checkErrorLog("Error while assigning reverb decayHFRatio: " + r.decayHFRatio); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_REFLECTIONS_GAIN, r.reflectionsGain); - checkErrorLog("Error while assigning reverb reflectionsGain: " + r.reflectionsGain); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_LATE_REVERB_GAIN, r.lateReverbGain); - checkErrorLog("Error while assigning reverb lateReverbGain: " + r.lateReverbGain); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_LATE_REVERB_DELAY, r.lateReverbDelay); - checkErrorLog("Error while assigning reverb lateReverbDelay: " + r.lateReverbDelay); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_AIR_ABSORPTION_GAINHF, r.airAbsorptionGainHF); - checkErrorLog("Error while assigning reverb airAbsorptionGainHF: " + r.airAbsorptionGainHF); - - EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, r.roomRolloffFactor); - checkErrorLog("Error while assigning reverb roomRolloffFactor: " + r.roomRolloffFactor); - - // Attach updated effect object - EFX10.alAuxiliaryEffectSloti(auxFXSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbSlot); - } - - public static void log(final String message) { - System.out.println(logPrefix.concat(" : ").concat(message)); - } - - public static void logError(final String errorMessage) { - System.out.println(logPrefix.concat(" [ERROR]: ").concat(errorMessage)); - } - - protected static boolean checkErrorLog(final String errorMessage) { - final int error = AL10.alGetError(); - if (error == AL10.AL_NO_ERROR) { - return false; - } - - String errorName; - - switch (error) { - case AL10.AL_INVALID_NAME: - errorName = "AL_INVALID_NAME"; - break; - case AL10.AL_INVALID_ENUM: - errorName = "AL_INVALID_ENUM"; - break; - case AL10.AL_INVALID_VALUE: - errorName = "AL_INVALID_VALUE"; - break; - case AL10.AL_INVALID_OPERATION: - errorName = "AL_INVALID_OPERATION"; - break; - case AL10.AL_OUT_OF_MEMORY: - errorName = "AL_OUT_OF_MEMORY"; - break; - default: - errorName = Integer.toString(error); - break; - } - - logError(errorMessage + " OpenAL error " + errorName); - return true; - } - -} +package com.sonicether.soundphysics; + +import java.util.regex.Pattern; +import java.util.List; +import java.util.ArrayList; +import java.util.ListIterator; +import java.util.Collections; +import java.nio.FloatBuffer; + +import org.lwjgl.openal.AL10; +import org.lwjgl.openal.AL11; +import org.lwjgl.openal.ALC10; +import org.lwjgl.openal.ALCcontext; +import org.lwjgl.openal.ALCdevice; +import org.lwjgl.openal.EFX10; +import org.lwjgl.BufferUtils; + +import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; +import net.minecraft.client.audio.ISound; +import net.minecraft.client.audio.SoundHandler; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.Text; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import paulscode.sound.SoundSystemConfig; + +import org.objectweb.asm.Type; + +@Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory") +public class SoundPhysics { + + public static final String modid = "soundphysics"; + public static final String version = "1.0.4"; + public static final String mcVersion = "1.12.2"; + + private static final Pattern rainPattern = Pattern.compile(".*rain.*"); + private static final Pattern stepPattern = Pattern.compile(".*step.*"); + private static final Pattern blockPattern = Pattern.compile(".*block.*"); + + @Mod.EventHandler + public void preInit(final FMLPreInitializationEvent event) { + Config.instance.preInit(event); + } + + @Mod.EventHandler + public void init(final FMLInitializationEvent event) { + Config.instance.init(event); + } + + private static final String logPrefix = "[SOUND PHYSICS]"; + private static int auxFXSlot0; + private static int auxFXSlot1; + private static int auxFXSlot2; + private static int auxFXSlot3; + private static int reverb0; + private static int reverb1; + private static int reverb2; + private static int reverb3; + private static int directFilter0; + private static int sendFilter0; + private static int sendFilter1; + private static int sendFilter2; + private static int sendFilter3; + + private static Minecraft mc; + + private static SoundHandler sndHandler; + + private static SoundCategory lastSoundCategory; + private static String lastSoundName; + private static ISound lastSound; + + private static ProcThread proc_thread; + private static boolean thread_alive; + private static List source_list; + + // THESE VARIABLES ARE CONSTANTLY ACCESSED AND USED BY ASM INJECTED CODE! DO + // NOT REMOVE! + public static int attenuationModel = SoundSystemConfig.ATTENUATION_ROLLOFF; + public static float globalRolloffFactor = Config.rolloffFactor; + public static float globalVolumeMultiplier = 4.0f; + public static float globalReverbMultiplier = 0.7f * Config.globalReverbGain; + public static double soundDistanceAllowance = Config.soundDistanceAllowance; + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void init() { + setupEFX(); + mc = Minecraft.getMinecraft(); + sndHandler = mc.getSoundHandler(); + setupThread(); + //System.out.println("---------------------------------"); + //System.out.println(Type.getMethodDescriptor(Type.getType(void.class),Type.getType(String.class),Type.getType(Float.class),Type.getType(Float.class),Type.getType(Float.class),Type.getType(Float.class))); + } + + public static class Source { + public static int sourceID; + public static float posX; + public static float posY; + public static float posZ; + public static SoundCategory category; + public static String name; + public static ISound sound; + public static int frequency; + public static int size; + public static int bufferID; + + public Source(int sid,float px,float py,float pz,SoundCategory cat,String n,ISound is) { + this.sourceID = sid; + this.posX = px; + this.posY = py; + this.posZ = pz; + this.category = cat; + this.name = n; + this.sound = is; + bufferID = AL10.alGetSourcei(sid, AL10.AL_BUFFER); + size = AL10.alGetBufferi(bufferID, AL10.AL_SIZE); + frequency = AL10.alGetBufferi(bufferID, AL10.AL_FREQUENCY); + } + } + + public static class ProcThread extends Thread { + @Override + public void run() { + while (thread_alive) { + while (!Config.dynamicEnvironementEvalutaion) { + try { + Thread.sleep(1000); + } catch (Exception e) { + logError(String.valueOf(e)); + } + } + synchronized (source_list) { + //log("Updating env " + String.valueOf(source_list.size())); + ListIterator iter = source_list.listIterator(); + while (iter.hasNext()) { + Source source = iter.next(); + //log("Updating sound '" + source.name + "' SourceID:" + String.valueOf(source.sourceID)); + //boolean pl = sndHandler.isSoundPlaying(source.sound); + //FloatBuffer pos = BufferUtils.createFloatBuffer(3); + //AL10.alGetSource(source.sourceID,AL10.AL_POSITION,pos); + //To try ^ + int state = AL10.alGetSourcei(source.sourceID, AL10.AL_SOURCE_STATE); + //int byteoff = AL10.alGetSourcei(source.sourceID, AL11.AL_BYTE_OFFSET); + //boolean finished = source.size == byteoff; + if (state == AL10.AL_PLAYING) { + /*float x = source.sound.getXPosF(); + float y = source.sound.getYPosF(); + float z = source.sound.getZPosF(); + if (x != source.posX || y != source.posY || z != source.posZ) { + log("Sound changed position"); + log("OLD:"+String.valueOf(source.posX)+","+String.valueOf(source.posY)+","+String.valueOf(source.posZ)); + log("NEW:"+String.valueOf(x)+","+String.valueOf(y)+","+String.valueOf(z)); + }*/ + /*source.posX = source.sound.getXPosF();//x; + source.posY = source.sound.getYPosF();//y; + source.posZ = source.sound.getZPosF();//z;*/ + FloatBuffer pos = BufferUtils.createFloatBuffer(3); + AL10.alGetSource(source.sourceID,AL10.AL_POSITION,pos); + source.posX = pos.get(0); + source.posY = pos.get(1); + source.posZ = pos.get(2); + evaluateEnvironment(source.sourceID,source.posX,source.posY,source.posZ,source.category,source.name); + } else if (state == AL10.AL_STOPPED) { + iter.remove(); + } + } + } + try { + Thread.sleep(1000/Config.dynamicEnvironementEvalutaionFrequency); + } catch (Exception e) { + logError(String.valueOf(e)); + } + } + } + } + + public static boolean source_check(Source s) { + synchronized (source_list) { + ListIterator iter = source_list.listIterator(); + while (iter.hasNext()) { + Source sn = iter.next(); + if (sn.sourceID == s.sourceID && sn.sound == s.sound && sn.bufferID == s.bufferID) { + return true; + } + } + } + return false; + } + + @Mod.EventBusSubscriber + public static class DebugDisplayEventHandler { + @SubscribeEvent + public static void onDebugOverlay(RenderGameOverlayEvent.Text event) + { + if(mc.gameSettings.showDebugInfo && Config.dynamicEnvironementEvalutaion) { + event.getLeft().add(""); + event.getLeft().add("[SoundPhysics] "+String.valueOf(source_list.size())+" Sources"); + event.getLeft().add("[SoundPhysics] Source list :"); + synchronized (source_list) { + ListIterator iter = source_list.listIterator(); + while (iter.hasNext()) { + Source s = iter.next(); + event.getLeft().add(String.valueOf(s.sourceID)+"-"+String.valueOf(s.posX)+","+String.valueOf(s.posY)+","+String.valueOf(s.posZ)); + int buffq = AL10.alGetSourcei(s.sourceID, AL10.AL_BUFFERS_QUEUED); + int buffp = AL10.alGetSourcei(s.sourceID, AL10.AL_BUFFERS_PROCESSED); + int sampoff = AL10.alGetSourcei(s.sourceID, AL11.AL_SAMPLE_OFFSET); + int byteoff = AL10.alGetSourcei(s.sourceID, AL11.AL_BYTE_OFFSET); + String k = ""; + if (sampoff!=0) { + //k = String.valueOf(sampoff)+"/"+String.valueOf((byteoff/sampoff)*size)+" "; + k = String.valueOf((float)sampoff/(float)s.frequency)+"/"+String.valueOf((float)((byteoff/sampoff)*s.size)/(float)s.frequency)+" "; + } else { + k = "0/? "; + } + event.getLeft().add(k+String.valueOf(buffp)+"/"+String.valueOf(buffq)+" "+String.valueOf(s.bufferID)); + event.getLeft().add("----"); + } + } + } + } + } + + private static void setupThread() { + thread_alive = false; + source_list = Collections.synchronizedList(new ArrayList()); + proc_thread = new ProcThread(); + thread_alive = true; + proc_thread.start(); + } + + public static void applyConfigChanges() { + globalRolloffFactor = Config.rolloffFactor; + globalReverbMultiplier = 0.7f * Config.globalReverbGain; + soundDistanceAllowance = Config.soundDistanceAllowance; + + if (auxFXSlot0 != 0) { + // Set the global reverb parameters and apply them to the effect and + // effectslot + setReverbParams(ReverbParams.getReverb0(), auxFXSlot0, reverb0); + setReverbParams(ReverbParams.getReverb1(), auxFXSlot1, reverb1); + setReverbParams(ReverbParams.getReverb2(), auxFXSlot2, reverb2); + setReverbParams(ReverbParams.getReverb3(), auxFXSlot3, reverb3); + } + } + + private static void setupEFX() { + // Get current context and device + final ALCcontext currentContext = ALC10.alcGetCurrentContext(); + final ALCdevice currentDevice = ALC10.alcGetContextsDevice(currentContext); + + if (ALC10.alcIsExtensionPresent(currentDevice, "ALC_EXT_EFX")) { + log("EFX Extension recognized."); + } else { + logError("EFX Extension not found on current device. Aborting."); + return; + } + + // Create auxiliary effect slots + auxFXSlot0 = EFX10.alGenAuxiliaryEffectSlots(); + log("Aux slot " + auxFXSlot0 + " created"); + EFX10.alAuxiliaryEffectSloti(auxFXSlot0, EFX10.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, AL10.AL_TRUE); + + auxFXSlot1 = EFX10.alGenAuxiliaryEffectSlots(); + log("Aux slot " + auxFXSlot1 + " created"); + EFX10.alAuxiliaryEffectSloti(auxFXSlot1, EFX10.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, AL10.AL_TRUE); + + auxFXSlot2 = EFX10.alGenAuxiliaryEffectSlots(); + log("Aux slot " + auxFXSlot2 + " created"); + EFX10.alAuxiliaryEffectSloti(auxFXSlot2, EFX10.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, AL10.AL_TRUE); + + auxFXSlot3 = EFX10.alGenAuxiliaryEffectSlots(); + log("Aux slot " + auxFXSlot3 + " created"); + EFX10.alAuxiliaryEffectSloti(auxFXSlot3, EFX10.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, AL10.AL_TRUE); + checkErrorLog("Failed creating auxiliary effect slots!"); + + reverb0 = EFX10.alGenEffects(); + EFX10.alEffecti(reverb0, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_EAXREVERB); + checkErrorLog("Failed creating reverb effect slot 0!"); + reverb1 = EFX10.alGenEffects(); + EFX10.alEffecti(reverb1, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_EAXREVERB); + checkErrorLog("Failed creating reverb effect slot 1!"); + reverb2 = EFX10.alGenEffects(); + EFX10.alEffecti(reverb2, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_EAXREVERB); + checkErrorLog("Failed creating reverb effect slot 2!"); + reverb3 = EFX10.alGenEffects(); + EFX10.alEffecti(reverb3, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_EAXREVERB); + checkErrorLog("Failed creating reverb effect slot 3!"); + + // Create filters + directFilter0 = EFX10.alGenFilters(); + EFX10.alFilteri(directFilter0, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); + + sendFilter0 = EFX10.alGenFilters(); + EFX10.alFilteri(sendFilter0, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); + + sendFilter1 = EFX10.alGenFilters(); + EFX10.alFilteri(sendFilter1, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); + + sendFilter2 = EFX10.alGenFilters(); + EFX10.alFilteri(sendFilter2, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); + + sendFilter3 = EFX10.alGenFilters(); + EFX10.alFilteri(sendFilter3, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); + checkErrorLog("Error creating lowpass filters!"); + + applyConfigChanges(); + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void setLastSoundCategory(final SoundCategory sc) { + lastSoundCategory = sc; + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void setLastSoundName(final String name) { + lastSoundName = name; + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void setLastSound(final ISound sound) + { + lastSound = sound; + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID) { + //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)); + evaluateEnvironment(sourceID, posX, posY, posZ,lastSoundCategory,lastSoundName); + if (!Config.dynamicEnvironementEvalutaion) return; + if (((mc.player == null | mc.world == null | posY <= 0 | lastSoundCategory == SoundCategory.RECORDS + | lastSoundCategory == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(lastSoundName).matches()))) return; + Source tmp = new Source(sourceID,posX,posY,posZ,lastSoundCategory,lastSoundName,lastSound); + if (source_check(tmp)) return; + source_list.add(tmp); + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static double calculateEntitySoundOffset(final Entity entity, final SoundEvent sound) { + if (stepPattern.matcher(sound.getSoundName().getResourcePath()).matches()) { + return 0; + } + + return entity.getEyeHeight(); + } + + @SuppressWarnings("deprecation") + private static float getBlockReflectivity(final BlockPos blockPos) { + final Block block = mc.world.getBlockState(blockPos).getBlock(); + final SoundType soundType = block.getSoundType(); + + float reflectivity = 0.5f; + + if (soundType == SoundType.STONE) { + reflectivity = Config.stoneReflectivity; + } else if (soundType == SoundType.WOOD) { + reflectivity = Config.woodReflectivity; + } else if (soundType == SoundType.GROUND) { + reflectivity = Config.groundReflectivity; + } else if (soundType == SoundType.PLANT) { + reflectivity = Config.plantReflectivity; + } else if (soundType == SoundType.METAL) { + reflectivity = Config.metalReflectivity; + } else if (soundType == SoundType.GLASS) { + reflectivity = Config.glassReflectivity; + } else if (soundType == SoundType.CLOTH) { + reflectivity = Config.clothReflectivity; + } else if (soundType == SoundType.SAND) { + reflectivity = Config.sandReflectivity; + } else if (soundType == SoundType.SNOW) { + reflectivity = Config.snowReflectivity; + } else if (soundType == SoundType.LADDER) { + reflectivity = Config.woodReflectivity; + } else if (soundType == SoundType.ANVIL) { + reflectivity = Config.metalReflectivity; + } + + reflectivity *= Config.globalBlockReflectance; + + return reflectivity; + } + + private static Vec3d getNormalFromFacing(final EnumFacing sideHit) { + return new Vec3d(sideHit.getDirectionVec()); + } + + private static Vec3d reflect(final Vec3d dir, final Vec3d normal) { + final double dot2 = dir.dotProduct(normal) * 2; + + final double x = dir.x - dot2 * normal.x; + final double y = dir.y - dot2 * normal.y; + final double z = dir.z - dot2 * normal.z; + + return new Vec3d(x, y, z); + } + + private static Vec3d offsetSoundByName(final double soundX, final double soundY, final double soundZ, + final Vec3d playerPos, final String name, final SoundCategory category) { + double offsetX = 0.0; + double offsetY = 0.0; + double offsetZ = 0.0; + double offsetTowardsPlayer = 0.0; + + double tempNormX = 0; + double tempNormY = 0; + double tempNormZ = 0; + + if (soundY % 1.0 < 0.001 || stepPattern.matcher(name).matches()) { + offsetY = 0.1; + } + + if (category == SoundCategory.BLOCKS || blockPattern.matcher(name).matches()) { + // The ray will probably hit the block that it's emitting from + // before + // escaping. Offset the ray start position towards the player by the + // diagonal half length of a cube + + tempNormX = playerPos.x - soundX; + tempNormY = playerPos.y - soundY; + tempNormZ = playerPos.z - soundZ; + final double length = Math.sqrt(tempNormX * tempNormX + tempNormY * tempNormY + tempNormZ * tempNormZ); + tempNormX /= length; + tempNormY /= length; + tempNormZ /= length; + // 0.867 > square root of 0.5^2 * 3 + offsetTowardsPlayer = 0.867; + offsetX += tempNormX * offsetTowardsPlayer; + offsetY += tempNormY * offsetTowardsPlayer; + offsetZ += tempNormZ * offsetTowardsPlayer; + } + + return new Vec3d(soundX + offsetX, soundY + offsetY, soundZ + offsetZ); + } + + @SuppressWarnings("deprecation") + private static void evaluateEnvironment(final int sourceID, final float posX, final float posY, final float posZ, final SoundCategory category, final String name) { + if (mc.player == null | mc.world == null | posY <= 0 | category == SoundCategory.RECORDS + | category == SoundCategory.MUSIC) { + // posY <= 0 as a condition has to be there: Ingame + // menu clicks do have a player and world present + setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + return; + } + + final boolean isRain = rainPattern.matcher(name).matches(); + + if (Config.skipRainOcclusionTracing && isRain) { + setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + return; + } + + float directCutoff = 1.0f; + final float absorptionCoeff = Config.globalBlockAbsorption * 3.0f; + + final Vec3d playerPos = new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ); + final Vec3d soundPos = offsetSoundByName(posX, posY, posZ, playerPos, name, category); + final Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize(); + + Vec3d rayOrigin = soundPos; + + float occlusionAccumulation = 0.0f; + + for (int i = 0; i < 10; i++) { + final RayTraceResult rayHit = mc.world.rayTraceBlocks(rayOrigin, playerPos, true); + + if (rayHit == null) { + break; + } + + final Block blockHit = mc.world.getBlockState(rayHit.getBlockPos()).getBlock(); + + float blockOcclusion = 1.0f; + + if (!blockHit.isOpaqueCube(blockHit.getDefaultState())) { + // log("not a solid block!"); + blockOcclusion *= 0.15f; + } + + occlusionAccumulation += blockOcclusion; + + rayOrigin = new Vec3d(rayHit.hitVec.x + normalToPlayer.x * 0.1, rayHit.hitVec.y + normalToPlayer.y * 0.1, + rayHit.hitVec.z + normalToPlayer.z * 0.1); + } + + directCutoff = (float) Math.exp(-occlusionAccumulation * absorptionCoeff); + float directGain = (float) Math.pow(directCutoff, 0.1); + + // Calculate reverb parameters for this sound + float sendGain0 = 0.0f; + float sendGain1 = 0.0f; + float sendGain2 = 0.0f; + float sendGain3 = 0.0f; + + float sendCutoff0 = 1.0f; + float sendCutoff1 = 1.0f; + float sendCutoff2 = 1.0f; + float sendCutoff3 = 1.0f; + + if (mc.player.isInsideOfMaterial(Material.WATER)) { + directCutoff *= 1.0f - Config.underwaterFilter; + } + + if (isRain) { + setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, + sendCutoff3, directCutoff, directGain); + return; + } + + // Shoot rays around sound + final float phi = 1.618033988f; + final float gAngle = phi * (float) Math.PI * 2.0f; + final float maxDistance = 256.0f; + + final int numRays = Config.environmentEvaluationRays; + final int rayBounces = Config.environmentEvaluationRaysBounces; + + final float[] bounceReflectivityRatio = new float[rayBounces]; + + float sharedAirspace = 0.0f; + + final float rcpTotalRays = 1.0f / (numRays * rayBounces); + final float rcpPrimaryRays = 1.0f / numRays; + + for (int i = 0; i < numRays; i++) { + final float fi = i; + final float fiN = fi / numRays; + final float longitude = gAngle * fi; + final float latitude = (float) Math.asin(fiN * 2.0f - 1.0f); + + final Vec3d rayDir = new Vec3d(Math.cos(latitude) * Math.cos(longitude), + Math.cos(latitude) * Math.sin(longitude), Math.sin(latitude)); + + final Vec3d rayStart = new Vec3d(soundPos.x, soundPos.y, soundPos.z); + + final Vec3d rayEnd = new Vec3d(rayStart.x + rayDir.x * maxDistance, rayStart.y + rayDir.y * maxDistance, + rayStart.z + rayDir.z * maxDistance); + + final RayTraceResult rayHit = mc.world.rayTraceBlocks(rayStart, rayEnd, true); + + if (rayHit != null) { + final double rayLength = soundPos.distanceTo(rayHit.hitVec); + + // Additional bounces + BlockPos lastHitBlock = rayHit.getBlockPos(); + Vec3d lastHitPos = rayHit.hitVec; + Vec3d lastHitNormal = getNormalFromFacing(rayHit.sideHit); + Vec3d lastRayDir = rayDir; + + float totalRayDistance = (float) rayLength; + + // Secondary ray bounces + for (int j = 0; j < rayBounces; j++) { + final Vec3d newRayDir = reflect(lastRayDir, lastHitNormal); + // Vec3d newRayDir = lastHitNormal; + final Vec3d newRayStart = new Vec3d(lastHitPos.x + lastHitNormal.x * 0.01, + lastHitPos.y + lastHitNormal.y * 0.01, lastHitPos.z + lastHitNormal.z * 0.01); + final Vec3d newRayEnd = new Vec3d(newRayStart.x + newRayDir.x * maxDistance, + newRayStart.y + newRayDir.y * maxDistance, newRayStart.z + newRayDir.z * maxDistance); + + final RayTraceResult newRayHit = mc.world.rayTraceBlocks(newRayStart, newRayEnd, true); + + float energyTowardsPlayer = 0.25f; + final float blockReflectivity = getBlockReflectivity(lastHitBlock); + energyTowardsPlayer *= blockReflectivity * 0.75f + 0.25f; + + if (newRayHit == null) { + totalRayDistance += lastHitPos.distanceTo(playerPos); + } else { + final double newRayLength = lastHitPos.distanceTo(newRayHit.hitVec); + + bounceReflectivityRatio[j] += blockReflectivity; + + totalRayDistance += newRayLength; + + lastHitPos = newRayHit.hitVec; + lastHitNormal = getNormalFromFacing(newRayHit.sideHit); + lastRayDir = newRayDir; + lastHitBlock = newRayHit.getBlockPos(); + + // Cast one final ray towards the player. If it's + // unobstructed, then the sound source and the player + // share airspace. + if (Config.simplerSharedAirspaceSimulation && j == rayBounces - 1 + || !Config.simplerSharedAirspaceSimulation) { + final Vec3d finalRayStart = new Vec3d(lastHitPos.x + lastHitNormal.x * 0.01, + lastHitPos.y + lastHitNormal.y * 0.01, lastHitPos.z + lastHitNormal.z * 0.01); + + final RayTraceResult finalRayHit = mc.world.rayTraceBlocks(finalRayStart, playerPos, true); + + if (finalRayHit == null) { + // log("Secondary ray hit the player!"); + sharedAirspace += 1.0f; + } + } + } + + final float reflectionDelay = (float) Math.max(totalRayDistance, 0.0) * 0.12f * blockReflectivity; + + final float cross0 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 0.0f), 0.0f, 1.0f); + final float cross1 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 1.0f), 0.0f, 1.0f); + final float cross2 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 2.0f), 0.0f, 1.0f); + final float cross3 = MathHelper.clamp(reflectionDelay - 2.0f, 0.0f, 1.0f); + + sendGain0 += cross0 * energyTowardsPlayer * 6.4f * rcpTotalRays; + sendGain1 += cross1 * energyTowardsPlayer * 12.8f * rcpTotalRays; + sendGain2 += cross2 * energyTowardsPlayer * 12.8f * rcpTotalRays; + sendGain3 += cross3 * energyTowardsPlayer * 12.8f * rcpTotalRays; + + // Nowhere to bounce off of, stop bouncing! + if (newRayHit == null) { + break; + } + } + } + + } + + // log("total reflectivity ratio: " + totalReflectivityRatio); + + bounceReflectivityRatio[0] = bounceReflectivityRatio[0] / numRays; + bounceReflectivityRatio[1] = bounceReflectivityRatio[1] / numRays; + bounceReflectivityRatio[2] = bounceReflectivityRatio[2] / numRays; + bounceReflectivityRatio[3] = bounceReflectivityRatio[3] / numRays; + + sharedAirspace *= 64.0f; + + if (Config.simplerSharedAirspaceSimulation) { + sharedAirspace *= rcpPrimaryRays; + } else { + sharedAirspace *= rcpTotalRays; + } + + final float sharedAirspaceWeight0 = MathHelper.clamp(sharedAirspace / 20.0f, 0.0f, 1.0f); + final float sharedAirspaceWeight1 = MathHelper.clamp(sharedAirspace / 15.0f, 0.0f, 1.0f); + final float sharedAirspaceWeight2 = MathHelper.clamp(sharedAirspace / 10.0f, 0.0f, 1.0f); + final float sharedAirspaceWeight3 = MathHelper.clamp(sharedAirspace / 10.0f, 0.0f, 1.0f); + + sendCutoff0 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.0f) * (1.0f - sharedAirspaceWeight0) + + sharedAirspaceWeight0; + sendCutoff1 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.0f) * (1.0f - sharedAirspaceWeight1) + + sharedAirspaceWeight1; + sendCutoff2 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.5f) * (1.0f - sharedAirspaceWeight2) + + sharedAirspaceWeight2; + sendCutoff3 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.5f) * (1.0f - sharedAirspaceWeight3) + + sharedAirspaceWeight3; + + // attempt to preserve directionality when airspace is shared by + // allowing some of the dry signal through but filtered + final float averageSharedAirspace = (sharedAirspaceWeight0 + sharedAirspaceWeight1 + sharedAirspaceWeight2 + + sharedAirspaceWeight3) * 0.25f; + directCutoff = Math.max((float) Math.pow(averageSharedAirspace, 0.5) * 0.2f, directCutoff); + + directGain = (float) Math.pow(directCutoff, 0.1); + + sendGain1 *= bounceReflectivityRatio[1]; + sendGain2 *= (float) Math.pow(bounceReflectivityRatio[2], 3.0); + sendGain3 *= (float) Math.pow(bounceReflectivityRatio[3], 4.0); + + sendGain0 = MathHelper.clamp(sendGain0, 0.0f, 1.0f); + sendGain1 = MathHelper.clamp(sendGain1, 0.0f, 1.0f); + sendGain2 = MathHelper.clamp(sendGain2 * 1.05f - 0.05f, 0.0f, 1.0f); + sendGain3 = MathHelper.clamp(sendGain3 * 1.05f - 0.05f, 0.0f, 1.0f); + + sendGain0 *= (float) Math.pow(sendCutoff0, 0.1); + sendGain1 *= (float) Math.pow(sendCutoff1, 0.1); + sendGain2 *= (float) Math.pow(sendCutoff2, 0.1); + sendGain3 *= (float) Math.pow(sendCutoff3, 0.1); + + if (mc.player.isInWater()) { + sendCutoff0 *= 0.4f; + sendCutoff1 *= 0.4f; + sendCutoff2 *= 0.4f; + sendCutoff3 *= 0.4f; + } + + setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, + sendCutoff3, directCutoff, directGain); + } + + private static void setEnvironment(final int sourceID, final float sendGain0, final float sendGain1, + final float sendGain2, final float sendGain3, final float sendCutoff0, final float sendCutoff1, + final float sendCutoff2, final float sendCutoff3, final float directCutoff, final float directGain) { + // Set reverb send filter values and set source to send to all reverb fx + // slots + EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAIN, sendGain0); + EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAINHF, sendCutoff0); + AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot0, 0, sendFilter0); + + EFX10.alFilterf(sendFilter1, EFX10.AL_LOWPASS_GAIN, sendGain1); + EFX10.alFilterf(sendFilter1, EFX10.AL_LOWPASS_GAINHF, sendCutoff1); + AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot1, 1, sendFilter1); + + EFX10.alFilterf(sendFilter2, EFX10.AL_LOWPASS_GAIN, sendGain2); + EFX10.alFilterf(sendFilter2, EFX10.AL_LOWPASS_GAINHF, sendCutoff2); + AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot2, 2, sendFilter2); + + EFX10.alFilterf(sendFilter3, EFX10.AL_LOWPASS_GAIN, sendGain3); + EFX10.alFilterf(sendFilter3, EFX10.AL_LOWPASS_GAINHF, sendCutoff3); + AL11.alSource3i(sourceID, EFX10.AL_AUXILIARY_SEND_FILTER, auxFXSlot3, 3, sendFilter3); + + EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAIN, directGain); + EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAINHF, directCutoff); + AL10.alSourcei(sourceID, EFX10.AL_DIRECT_FILTER, directFilter0); + + AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, Config.airAbsorption); + } + + /** + * Applies the parameters in the enum ReverbParams to the main reverb + * effect. + */ + protected static void setReverbParams(final ReverbParams r, final int auxFXSlot, final int reverbSlot) { + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_DENSITY, r.density); + checkErrorLog("Error while assigning reverb density: " + r.density); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_DIFFUSION, r.diffusion); + checkErrorLog("Error while assigning reverb diffusion: " + r.diffusion); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_GAIN, r.gain); + checkErrorLog("Error while assigning reverb gain: " + r.gain); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_GAINHF, r.gainHF); + checkErrorLog("Error while assigning reverb gainHF: " + r.gainHF); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_DECAY_TIME, r.decayTime); + checkErrorLog("Error while assigning reverb decayTime: " + r.decayTime); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_DECAY_HFRATIO, r.decayHFRatio); + checkErrorLog("Error while assigning reverb decayHFRatio: " + r.decayHFRatio); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_REFLECTIONS_GAIN, r.reflectionsGain); + checkErrorLog("Error while assigning reverb reflectionsGain: " + r.reflectionsGain); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_LATE_REVERB_GAIN, r.lateReverbGain); + checkErrorLog("Error while assigning reverb lateReverbGain: " + r.lateReverbGain); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_LATE_REVERB_DELAY, r.lateReverbDelay); + checkErrorLog("Error while assigning reverb lateReverbDelay: " + r.lateReverbDelay); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_AIR_ABSORPTION_GAINHF, r.airAbsorptionGainHF); + checkErrorLog("Error while assigning reverb airAbsorptionGainHF: " + r.airAbsorptionGainHF); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, r.roomRolloffFactor); + checkErrorLog("Error while assigning reverb roomRolloffFactor: " + r.roomRolloffFactor); + + // Attach updated effect object + EFX10.alAuxiliaryEffectSloti(auxFXSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbSlot); + } + + public static void log(final String message) { + System.out.println(logPrefix.concat(" : ").concat(message)); + } + + public static void logError(final String errorMessage) { + System.out.println(logPrefix.concat(" [ERROR]: ").concat(errorMessage)); + } + + protected static boolean checkErrorLog(final String errorMessage) { + final int error = AL10.alGetError(); + if (error == AL10.AL_NO_ERROR) { + return false; + } + + String errorName; + + switch (error) { + case AL10.AL_INVALID_NAME: + errorName = "AL_INVALID_NAME"; + break; + case AL10.AL_INVALID_ENUM: + errorName = "AL_INVALID_ENUM"; + break; + case AL10.AL_INVALID_VALUE: + errorName = "AL_INVALID_VALUE"; + break; + case AL10.AL_INVALID_OPERATION: + errorName = "AL_INVALID_OPERATION"; + break; + case AL10.AL_OUT_OF_MEMORY: + errorName = "AL_OUT_OF_MEMORY"; + break; + default: + errorName = Integer.toString(error); + break; + } + + logError(errorMessage + " OpenAL error " + errorName); + return true; + } + +} diff --git a/z_Link.bat b/z_Link.bat deleted file mode 100644 index a1a90a1d..00000000 --- a/z_Link.bat +++ /dev/null @@ -1 +0,0 @@ -gradlew eclipse \ No newline at end of file diff --git a/z_Setup.bat b/z_Setup.bat deleted file mode 100644 index 57a83e41..00000000 --- a/z_Setup.bat +++ /dev/null @@ -1 +0,0 @@ -gradlew setupDecompWorkspace \ No newline at end of file From f7b9a8fea1c54e07534a471f234400ec712a596e Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 26 Sep 2018 17:25:47 +0200 Subject: [PATCH 02/88] Updated README Signed-off-by: djpadbit --- README.md | 8 +++++++- .../java/com/sonicether/soundphysics/CoreModInjector.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c04ef39b..7adaa80a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ # Sound-Physics A Minecraft mod that provides realistic sound attenuation, reverberation, and absorption through blocks. -This is a fork! TODO: There is still some cleanup left! Sonic Ether's original source code was very messy! \ No newline at end of file +This is a fork of a fork! I forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and updated the mod, i just added some stuff. + +The stuff added in this fork: +* Dynamic environement evaluation +* More compatibillity with mods (for now only computronics) + +And that's pretty much it. yeah that's not a lot. \ No newline at end of file diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 5626ef7b..23612279 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -191,12 +191,12 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St final MethodNode m = methodIterator.next(); if (m.name.equals(targetMethod) && m.desc.equals(targetMethodSignature)) { + AbstractInsnNode targetNode = null; final ListIterator nodeIterator = m.instructions.iterator(); while (nodeIterator.hasNext()) { AbstractInsnNode currentNode = nodeIterator.next(); - if (currentNode.getOpcode() == targetNodeOpcode) { if (targetNodeType == AbstractInsnNode.METHOD_INSN) { From 506e16a1149f7a68942837247987defc993efd4e Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 26 Sep 2018 21:55:21 +0200 Subject: [PATCH 03/88] Removed ISound thing because it's useless Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 10 ------- .../sonicether/soundphysics/SoundPhysics.java | 29 +++---------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 23612279..6bf55a32 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -35,16 +35,6 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte if (obfuscated.equals("chm")) { // Inside SoundManager InsnList toInject = new InsnList(); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); - toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "setLastSound", "(Lnet/minecraft/client/audio/ISound;)V", false)); - - // Target method: playSound - bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setVolume", null, toInject, false, 0, 0, false, 0); - - toInject = new InsnList(); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 7)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "setLastSoundCategory", "(Lqg;)V", false)); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 528b6732..adcf36c7 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -81,7 +81,6 @@ public void init(final FMLInitializationEvent event) { private static SoundCategory lastSoundCategory; private static String lastSoundName; - private static ISound lastSound; private static ProcThread proc_thread; private static boolean thread_alive; @@ -114,19 +113,17 @@ public static class Source { public static float posZ; public static SoundCategory category; public static String name; - public static ISound sound; public static int frequency; public static int size; public static int bufferID; - public Source(int sid,float px,float py,float pz,SoundCategory cat,String n,ISound is) { + public Source(int sid,float px,float py,float pz,SoundCategory cat,String n) { this.sourceID = sid; this.posX = px; this.posY = py; this.posZ = pz; this.category = cat; this.name = n; - this.sound = is; bufferID = AL10.alGetSourcei(sid, AL10.AL_BUFFER); size = AL10.alGetBufferi(bufferID, AL10.AL_SIZE); frequency = AL10.alGetBufferi(bufferID, AL10.AL_FREQUENCY); @@ -158,17 +155,6 @@ public void run() { //int byteoff = AL10.alGetSourcei(source.sourceID, AL11.AL_BYTE_OFFSET); //boolean finished = source.size == byteoff; if (state == AL10.AL_PLAYING) { - /*float x = source.sound.getXPosF(); - float y = source.sound.getYPosF(); - float z = source.sound.getZPosF(); - if (x != source.posX || y != source.posY || z != source.posZ) { - log("Sound changed position"); - log("OLD:"+String.valueOf(source.posX)+","+String.valueOf(source.posY)+","+String.valueOf(source.posZ)); - log("NEW:"+String.valueOf(x)+","+String.valueOf(y)+","+String.valueOf(z)); - }*/ - /*source.posX = source.sound.getXPosF();//x; - source.posY = source.sound.getYPosF();//y; - source.posZ = source.sound.getZPosF();//z;*/ FloatBuffer pos = BufferUtils.createFloatBuffer(3); AL10.alGetSource(source.sourceID,AL10.AL_POSITION,pos); source.posX = pos.get(0); @@ -194,7 +180,8 @@ public static boolean source_check(Source s) { ListIterator iter = source_list.listIterator(); while (iter.hasNext()) { Source sn = iter.next(); - if (sn.sourceID == s.sourceID && sn.sound == s.sound && sn.bufferID == s.bufferID) { + if (sn.sourceID == s.sourceID && sn.bufferID == s.bufferID && + sn.posX == s.posX && sn.posY == s.posY && sn.posZ == s.posZ) { return true; } } @@ -335,14 +322,6 @@ public static void setLastSoundName(final String name) { lastSoundName = name; } - /** - * CALLED BY ASM INJECTED CODE! - */ - public static void setLastSound(final ISound sound) - { - lastSound = sound; - } - /** * CALLED BY ASM INJECTED CODE! */ @@ -352,7 +331,7 @@ public static void onPlaySound(final float posX, final float posY, final float p if (!Config.dynamicEnvironementEvalutaion) return; if (((mc.player == null | mc.world == null | posY <= 0 | lastSoundCategory == SoundCategory.RECORDS | lastSoundCategory == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(lastSoundName).matches()))) return; - Source tmp = new Source(sourceID,posX,posY,posZ,lastSoundCategory,lastSoundName,lastSound); + Source tmp = new Source(sourceID,posX,posY,posZ,lastSoundCategory,lastSoundName); if (source_check(tmp)) return; source_list.add(tmp); } From 6698a71a2f0b9273ddc8ed34292f881c67a45d78 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 27 Sep 2018 22:59:41 +0200 Subject: [PATCH 04/88] NOT WORKING RIGHT NOW. Commit auto stereo to mono sound conversion, i'll finish tommorow. Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 19 +++++++ .../sonicether/soundphysics/SoundPhysics.java | 51 ++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 6bf55a32..6d0b8122 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -95,6 +95,23 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.METHOD_INSN, "play", null, toInject, false, 0, 0, false, 0); } else + // Convert stero sounds to mono + if (obfuscated.equals("paulscode.sound.libraries.LibraryLWJGLOpenAL")) { + // Inside LibraryLWJGLOpenAL + InsnList toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); + + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "onLoadSound", "(Lpaulscode/sound/SoundBuffer;)Lpaulscode/sound/SoundBuffer;", false)); + + toInject.add(new VarInsnNode(Opcodes.ASTORE, 4)); + + // Target method: loadSound + bytes = patchMethodInClass(obfuscated, bytes, "loadSound", "(Lpaulscode/sound/FilenameURL;)Z", Opcodes.INVOKEINTERFACE, + AbstractInsnNode.METHOD_INSN, "cleanup", null, toInject, false, 0, 0, false, 0); + } else + if (obfuscated.equals("paulscode.sound.SoundSystem")) { // Inside SoundSystem InsnList toInject = new InsnList(); @@ -141,6 +158,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte bytes = patchMethodInClass(obfuscated, bytes, "a", "(Lqe;FF)V", Opcodes.INVOKEVIRTUAL, AbstractInsnNode.METHOD_INSN, "bK", null, toInject, true, 0, 0, false, -3); } else + // Fix for computronics's sound card and tape drive if (obfuscated.equals("pl.asie.lib.audio.StreamingAudioPlayer")) { // Inside StreamingAudioPlayer @@ -162,6 +180,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte bytes = patchMethodInClass(obfuscated, bytes, "play", "(Ljava/lang/String;FFFF)V", Opcodes.INVOKESTATIC, AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, toInject, false, 0, 0, false, 0); } + //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); return bytes; } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index adcf36c7..715b3876 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -36,6 +36,9 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.Text; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import paulscode.sound.SoundSystemConfig; +import paulscode.sound.SoundBuffer; +import javax.sound.sampled.AudioFormat; +import java.nio.ByteBuffer; import org.objectweb.asm.Type; @@ -102,8 +105,11 @@ public static void init() { mc = Minecraft.getMinecraft(); sndHandler = mc.getSoundHandler(); setupThread(); - //System.out.println("---------------------------------"); - //System.out.println(Type.getMethodDescriptor(Type.getType(void.class),Type.getType(String.class),Type.getType(Float.class),Type.getType(Float.class),Type.getType(Float.class),Type.getType(Float.class))); + //System.out.println("---------------------------------"); + //System.out.println(Type.getMethodDescriptor(Type.getType(boolean.class),Type.getType(FilenameURL.class))); + //System.out.println(Type.getMethodDescriptor(Type.getType(void.class),Type.getType(SoundBuffer.class))); + //System.out.println(Type.getMethodDescriptor(Type.getType(SoundBuffer.class),Type.getType(SoundBuffer.class))); + } public static class Source { @@ -189,6 +195,47 @@ public static boolean source_check(Source s) { return false; } + /** + * CALLED BY ASM INJECTED CODE! + */ + public static SoundBuffer onLoadSound(SoundBuffer buff) { + if (buff == null || buff.audioFormat.getChannels() == 1) return buff; + AudioFormat orignalformat = buff.audioFormat; + int bits = orignalformat.getSampleSizeInBits(); + boolean bigendian = orignalformat.isBigEndian(); + AudioFormat monoformat = new AudioFormat(orignalformat.getEncoding(), orignalformat.getSampleRate(), bits, + 1, orignalformat.getFrameSize(), orignalformat.getFrameRate(), bigendian); + log("Converting sound ("+orignalformat.toString()+") to mono ("+monoformat.toString()+")"); + byte[] monodata = null; + if (bits == 8) { + //monodata = new byte[buff.audioData.length/2]; + for (int i = 0; i < buff.audioData.length; i+=2) { + buff.audioData[i/2] = (byte)((buff.audioData[i]+buff.audioData[i+1])/2); + } + } else if (bits == 16) { + //monodata = new byte[buff.audioData.length/4]; + for (int i = 0; i < buff.audioData.length; i+=4) { + int lsamp = 0; + int rsamp = 0; + if (bigendian) { + lsamp = buff.audioData[i+1] | (buff.audioData[i]<<8); + rsamp = buff.audioData[(i+2)+1] | (buff.audioData[(i+2)]<<8); + } else { + lsamp = buff.audioData[i] | (buff.audioData[i+1]<<8); + rsamp = buff.audioData[(i+2)] | (buff.audioData[(i+2)+1]<<8); + } + buff.audioData[i/4] = (byte)((lsamp+rsamp)/2); + } + } + if (monodata == null) { + log("Conversion of sound failed?"); + return buff; + } else { + log("Finished conversion of sound"); + return new SoundBuffer(monodata, monoformat); + } + } + @Mod.EventBusSubscriber public static class DebugDisplayEventHandler { @SubscribeEvent From fd5601a8c8071fe54ff49ead5bde26a3819dbc61 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 28 Sep 2018 21:03:35 +0200 Subject: [PATCH 05/88] Auto stero downmix to mono Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 15 ++++ .../soundphysics/CoreModInjector.java | 23 +++++- .../sonicether/soundphysics/SoundPhysics.java | 79 +++++++++---------- 3 files changed, 71 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index a7c9aec3..a9f99e79 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -46,9 +46,15 @@ public class Config { public static float sandReflectivity; public static float snowReflectivity; + //Compatibility + public static boolean computronicsPatching; + public static boolean autoSteroDownmix; + public static boolean autoSteroDownmixDebug; + private static final String categoryGeneral = "General"; private static final String categoryPerformance = "Performance"; private static final String categoryMaterialProperties = "Material properties"; + private static final String categoryCompatibility = "Compatibility"; static { instance = new Config(); @@ -79,6 +85,7 @@ public List getConfigElements() { list.add(new ConfigElement(this.forgeConfig.getCategory(Config.categoryGeneral))); list.add(new ConfigElement(this.forgeConfig.getCategory(Config.categoryPerformance))); list.add(new ConfigElement(this.forgeConfig.getCategory(Config.categoryMaterialProperties))); + list.add(new ConfigElement(this.forgeConfig.getCategory(Config.categoryCompatibility))); return list; } @@ -142,6 +149,14 @@ private void syncConfig() { snowReflectivity = this.forgeConfig.getFloat("Snow Reflectivity", categoryMaterialProperties, 0.2f, 0.0f, 1.0f, "Sound reflectivity for snow blocks."); + // compatibility + computronicsPatching = this.forgeConfig.getBoolean("Patch Computronics", categoryCompatibility, true, + "MAY REQUIRE RESTART.If true, patches the computronics sound sources so it works with sound physics."); + autoSteroDownmix = this.forgeConfig.getBoolean("Auto stereo downmix", categoryCompatibility, true, + "MAY REQUIRE RESTART.If true, Automatically downmix stereo sounds that are loaded to mono"); + autoSteroDownmixDebug = this.forgeConfig.getBoolean("Stereo downmix debug", categoryCompatibility, false, + "If true, Prints sound name and format of the sounds that get converted"); + if (this.forgeConfig.hasChanged()) { this.forgeConfig.save(); SoundPhysics.applyConfigChanges(); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 6d0b8122..e826a21c 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -96,20 +96,37 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte } else // Convert stero sounds to mono - if (obfuscated.equals("paulscode.sound.libraries.LibraryLWJGLOpenAL")) { + if (obfuscated.equals("paulscode.sound.libraries.LibraryLWJGLOpenAL") && Config.autoSteroDownmix) { // Inside LibraryLWJGLOpenAL InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "paulscode/sound/FilenameURL", "getFilename", "()Ljava/lang/String;", false)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "onLoadSound", "(Lpaulscode/sound/SoundBuffer;)Lpaulscode/sound/SoundBuffer;", false)); + "onLoadSound", "(Lpaulscode/sound/SoundBuffer;Ljava/lang/String;)Lpaulscode/sound/SoundBuffer;", false)); toInject.add(new VarInsnNode(Opcodes.ASTORE, 4)); + //buffer = onLoadSound(SoundPhysics.buffer,filenameURL.getFilename()); // Target method: loadSound bytes = patchMethodInClass(obfuscated, bytes, "loadSound", "(Lpaulscode/sound/FilenameURL;)Z", Opcodes.INVOKEINTERFACE, AbstractInsnNode.METHOD_INSN, "cleanup", null, toInject, false, 0, 0, false, 0); + + toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "onLoadSound", "(Lpaulscode/sound/SoundBuffer;Ljava/lang/String;)Lpaulscode/sound/SoundBuffer;", false)); + + toInject.add(new VarInsnNode(Opcodes.ASTORE, 0)); + + // Target method: loadSound + bytes = patchMethodInClass(obfuscated, bytes, "loadSound", "(Lpaulscode/sound/SoundBuffer;Ljava/lang/String;)Z", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "getChannels", null, toInject, true, 0, 0, false, -12); } else if (obfuscated.equals("paulscode.sound.SoundSystem")) { @@ -160,7 +177,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte } else // Fix for computronics's sound card and tape drive - if (obfuscated.equals("pl.asie.lib.audio.StreamingAudioPlayer")) { + if (obfuscated.equals("pl.asie.lib.audio.StreamingAudioPlayer") && Config.computronicsPatching) { // Inside StreamingAudioPlayer InsnList toInject = new InsnList(); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 715b3876..a316637e 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -39,6 +39,7 @@ import paulscode.sound.SoundBuffer; import javax.sound.sampled.AudioFormat; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import org.objectweb.asm.Type; @@ -195,47 +196,6 @@ public static boolean source_check(Source s) { return false; } - /** - * CALLED BY ASM INJECTED CODE! - */ - public static SoundBuffer onLoadSound(SoundBuffer buff) { - if (buff == null || buff.audioFormat.getChannels() == 1) return buff; - AudioFormat orignalformat = buff.audioFormat; - int bits = orignalformat.getSampleSizeInBits(); - boolean bigendian = orignalformat.isBigEndian(); - AudioFormat monoformat = new AudioFormat(orignalformat.getEncoding(), orignalformat.getSampleRate(), bits, - 1, orignalformat.getFrameSize(), orignalformat.getFrameRate(), bigendian); - log("Converting sound ("+orignalformat.toString()+") to mono ("+monoformat.toString()+")"); - byte[] monodata = null; - if (bits == 8) { - //monodata = new byte[buff.audioData.length/2]; - for (int i = 0; i < buff.audioData.length; i+=2) { - buff.audioData[i/2] = (byte)((buff.audioData[i]+buff.audioData[i+1])/2); - } - } else if (bits == 16) { - //monodata = new byte[buff.audioData.length/4]; - for (int i = 0; i < buff.audioData.length; i+=4) { - int lsamp = 0; - int rsamp = 0; - if (bigendian) { - lsamp = buff.audioData[i+1] | (buff.audioData[i]<<8); - rsamp = buff.audioData[(i+2)+1] | (buff.audioData[(i+2)]<<8); - } else { - lsamp = buff.audioData[i] | (buff.audioData[i+1]<<8); - rsamp = buff.audioData[(i+2)] | (buff.audioData[(i+2)+1]<<8); - } - buff.audioData[i/4] = (byte)((lsamp+rsamp)/2); - } - } - if (monodata == null) { - log("Conversion of sound failed?"); - return buff; - } else { - log("Finished conversion of sound"); - return new SoundBuffer(monodata, monoformat); - } - } - @Mod.EventBusSubscriber public static class DebugDisplayEventHandler { @SubscribeEvent @@ -376,13 +336,46 @@ public static void onPlaySound(final float posX, final float posY, final float p //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)); evaluateEnvironment(sourceID, posX, posY, posZ,lastSoundCategory,lastSoundName); if (!Config.dynamicEnvironementEvalutaion) return; - if (((mc.player == null | mc.world == null | posY <= 0 | lastSoundCategory == SoundCategory.RECORDS - | lastSoundCategory == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(lastSoundName).matches()))) return; + if ((mc.player == null | mc.world == null | posY <= 0 | lastSoundCategory == SoundCategory.RECORDS + | lastSoundCategory == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(lastSoundName).matches())) return; Source tmp = new Source(sourceID,posX,posY,posZ,lastSoundCategory,lastSoundName); if (source_check(tmp)) return; source_list.add(tmp); } + /** + * CALLED BY ASM INJECTED CODE! + */ + public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { + if (buff == null || buff.audioFormat.getChannels() == 1 || !Config.autoSteroDownmix) return buff; + if (mc.player == null | mc.world == null | lastSoundCategory == SoundCategory.RECORDS + | lastSoundCategory == SoundCategory.MUSIC) { + if (Config.autoSteroDownmixDebug) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); + return buff; + } + AudioFormat orignalformat = buff.audioFormat; + int bits = orignalformat.getSampleSizeInBits(); + boolean bigendian = orignalformat.isBigEndian(); + AudioFormat monoformat = new AudioFormat(orignalformat.getEncoding(), orignalformat.getSampleRate(), bits, + 1, orignalformat.getFrameSize(), orignalformat.getFrameRate(), bigendian); + if (Config.autoSteroDownmixDebug) log("Converting sound '"+filename+"'("+orignalformat.toString()+") to mono ("+monoformat.toString()+")"); + + ByteBuffer bb = ByteBuffer.wrap(buff.audioData,0,buff.audioData.length); + bb.order(bigendian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); + if (bits == 8) { + for (int i = 0; i < buff.audioData.length; i+=2) { + bb.put(i/2,(byte)((bb.get(i)+bb.get(i+1))/2)); + } + } else if (bits == 16) { + for (int i = 0; i < buff.audioData.length; i+=4) { + bb.putShort((i/2),(short)((bb.getShort(i)+bb.getShort(i+2))/2)); + } + } + buff.audioFormat = monoformat; + buff.trimData(buff.audioData.length/2); + return buff; + } + /** * CALLED BY ASM INJECTED CODE! */ From e7550b9b9bd482eda4a840ac00b4c69c09e02faf Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 28 Sep 2018 21:04:51 +0200 Subject: [PATCH 06/88] Updated README Signed-off-by: djpadbit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7adaa80a..c3c23ea5 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ This is a fork of a fork! I forked it from daipenger who forked it from soniceth The stuff added in this fork: * Dynamic environement evaluation +* Automatic stero to mono downmixing of sounds * More compatibillity with mods (for now only computronics) And that's pretty much it. yeah that's not a lot. \ No newline at end of file From 4ec26f8e822096e63dda8e86a9d52c9abdd4412d Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 28 Sep 2018 22:02:59 +0200 Subject: [PATCH 07/88] Fixed menu & ui sounds being converted to mono Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index a316637e..e4b9125d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -53,6 +53,8 @@ public class SoundPhysics { private static final Pattern rainPattern = Pattern.compile(".*rain.*"); private static final Pattern stepPattern = Pattern.compile(".*step.*"); private static final Pattern blockPattern = Pattern.compile(".*block.*"); + private static final Pattern uiPattern = Pattern.compile(".*ui.*"); + private static final Pattern clickPattern = Pattern.compile(".*random.click.*"); @Mod.EventHandler public void preInit(final FMLPreInitializationEvent event) { @@ -349,7 +351,7 @@ public static void onPlaySound(final float posX, final float posY, final float p public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { if (buff == null || buff.audioFormat.getChannels() == 1 || !Config.autoSteroDownmix) return buff; if (mc.player == null | mc.world == null | lastSoundCategory == SoundCategory.RECORDS - | lastSoundCategory == SoundCategory.MUSIC) { + | lastSoundCategory == SoundCategory.MUSIC | uiPattern.matcher(filename).matches() | clickPattern.matcher(filename).matches()) { if (Config.autoSteroDownmixDebug) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); return buff; } From 836328f601e230e2d6e2b2f687365e9189fb509f Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 28 Sep 2018 22:08:45 +0200 Subject: [PATCH 08/88] Disabled dynamic env by default Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index a9f99e79..f08c5826 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -124,7 +124,7 @@ private void syncConfig() { simplerSharedAirspaceSimulation = this.forgeConfig.getBoolean("Simpler Shared Airspace Simulation", categoryPerformance, false, "If true, enables a simpler technique for determining when the player and a sound source share airspace. Might sometimes miss recognizing shared airspace, but it's faster to calculate."); - dynamicEnvironementEvalutaion = this.forgeConfig.getBoolean("Dynamic environment evaluation", categoryPerformance, true, + dynamicEnvironementEvalutaion = this.forgeConfig.getBoolean("Dynamic environment evaluation", categoryPerformance, false, "WARNING it's implemented really badly so i'd recommend not always using it.If true, the environment will keep getting evaluated for every sound that is currently playing. This may affect performance"); dynamicEnvironementEvalutaionFrequency = this.forgeConfig.getInt("Frequency of environment evaluation", categoryPerformance, 30, 1, 60, "The frequency at witch to update environment of sounds if dynamic environment evaluation is enabled"); From 437b36dc80220fdfff4d1736c3f14dfe4d31787a Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 29 Sep 2018 12:52:14 +0200 Subject: [PATCH 09/88] Updated README Signed-off-by: djpadbit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3c23ea5..c60d1055 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A Minecraft mod that provides realistic sound attenuation, reverberation, and ab This is a fork of a fork! I forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and updated the mod, i just added some stuff. The stuff added in this fork: -* Dynamic environement evaluation +* Dynamic environement evaluation (disabled by default, enable in mod config ingame) * Automatic stero to mono downmixing of sounds * More compatibillity with mods (for now only computronics) From af813ac31e85abf4e18af6feed926d5ddcafafc7 Mon Sep 17 00:00:00 2001 From: Eddi2015 <36605424+Eddi2015@users.noreply.github.com> Date: Sun, 30 Sep 2018 07:37:41 +0000 Subject: [PATCH 10/88] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c60d1055..e2ed7b65 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # Sound-Physics A Minecraft mod that provides realistic sound attenuation, reverberation, and absorption through blocks. -This is a fork of a fork! I forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and updated the mod, i just added some stuff. +This is a fork of a fork of a fork! I forked it from djpabit who forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and updated the mod, djpadbit added some cool stuff and I updated the mod to the latest version and compile it, maybe some other stuff we'll see. The stuff added in this fork: * Dynamic environement evaluation (disabled by default, enable in mod config ingame) * Automatic stero to mono downmixing of sounds * More compatibillity with mods (for now only computronics) +* latest Forge version -And that's pretty much it. yeah that's not a lot. \ No newline at end of file +And that's pretty much it. yeah that's not a lot. From d873c7e2d136fbf78d060a33df2f60ca8fbc42cf Mon Sep 17 00:00:00 2001 From: Eddi2015 <36605424+Eddi2015@users.noreply.github.com> Date: Sun, 30 Sep 2018 07:55:51 +0000 Subject: [PATCH 11/88] update build.gradle latest Forge and mcp mappings --- build.gradle | 131 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 54 deletions(-) diff --git a/build.gradle b/build.gradle index b51e22bf..289afb1a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,54 +1,77 @@ -buildscript { - repositories { - jcenter() - maven { url = "http://files.minecraftforge.net/maven" } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - } -} -apply plugin: 'net.minecraftforge.gradle.forge' -//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. - -version = "1.12.2" -archivesBaseName = "Sound-Physics" - -jar { - manifest { - attributes 'FMLCorePlugin': 'com.sonicether.soundphysics.CoreModLoader' - attributes 'FMLCorePluginContainsFMLMod': 'true' - } -} - -sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. -compileJava { - sourceCompatibility = targetCompatibility = '1.8' -} - -minecraft { - version = "1.12.2-14.23.0.2542" - runDir = "run" - mappings = "snapshot_20171003" -} - -dependencies { -} - -processResources { - // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version - - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - - // replace version and mcversion - expand 'version':project.version, 'mcversion':project.minecraft.version - } - - // copy everything else except the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } -} +buildscript { + repositories { + jcenter() + maven { url = "http://files.minecraftforge.net/maven" } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' + } +} +apply plugin: 'net.minecraftforge.gradle.forge' +//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. + + +version = "1.0" +group = "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = "modid" + +sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. +compileJava { + sourceCompatibility = targetCompatibility = '1.8' +} + +minecraft { + version = "1.12.2-14.23.4.2765" + runDir = "run" + + // the mappings can be changed at any time, and must be in the following format. + // snapshot_YYYYMMDD snapshot are built nightly. + // stable_# stables are built at the discretion of the MCP team. + // Use non-default mappings at your own risk. they may not always work. + // simply re-run your setup task after changing the mappings to update your workspace. + mappings = "snapshot_20180814" + // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. +} + +dependencies { + // you may put jars on which you depend on in ./libs + // or you may define them like so.. + //compile "some.group:artifact:version:classifier" + //compile "some.group:artifact:version" + + // real examples + //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env + //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env + + // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. + //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' + + // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, + // except that these dependencies get remapped to your current MCP mappings + //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev' + //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev' + + // for more info... + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html + // http://www.gradle.org/docs/current/userguide/dependency_management.html + +} + +processResources { + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + + // replace version and mcversion + expand 'version':project.version, 'mcversion':project.minecraft.version + } + + // copy everything else except the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} From 08eba91ac37a91ff585105f3506b2cfed23588c8 Mon Sep 17 00:00:00 2001 From: Eddi2015 <36605424+Eddi2015@users.noreply.github.com> Date: Sun, 30 Sep 2018 07:58:35 +0000 Subject: [PATCH 12/88] fix getPath() error --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index e4b9125d..b77fa822 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -382,7 +382,7 @@ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { * CALLED BY ASM INJECTED CODE! */ public static double calculateEntitySoundOffset(final Entity entity, final SoundEvent sound) { - if (stepPattern.matcher(sound.getSoundName().getResourcePath()).matches()) { + if (stepPattern.matcher(sound.getSoundName().getPath()).matches()) { return 0; } From 2e7d7ab45132fb431b6214d6c351b812baef1cdb Mon Sep 17 00:00:00 2001 From: Eddi2015 <36605424+Eddi2015@users.noreply.github.com> Date: Mon, 1 Oct 2018 19:59:46 +0200 Subject: [PATCH 13/88] align with upstream readme.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index e2ed7b65..caf95276 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ # Sound-Physics A Minecraft mod that provides realistic sound attenuation, reverberation, and absorption through blocks. -This is a fork of a fork of a fork! I forked it from djpabit who forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and updated the mod, djpadbit added some cool stuff and I updated the mod to the latest version and compile it, maybe some other stuff we'll see. +This is a fork of a fork! I forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and updated the mod, i just added some stuff. The stuff added in this fork: * Dynamic environement evaluation (disabled by default, enable in mod config ingame) * Automatic stero to mono downmixing of sounds * More compatibillity with mods (for now only computronics) -* latest Forge version And that's pretty much it. yeah that's not a lot. From ebf4c33b2eaaab460f57929f6699c358dd564243 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 1 Oct 2018 20:36:22 +0200 Subject: [PATCH 14/88] Added speed of sound delay testing (commented) Signed-off-by: djpadbit --- .../sonicether/soundphysics/SoundPhysics.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index e4b9125d..351eba49 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -40,6 +40,8 @@ import javax.sound.sampled.AudioFormat; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.Timer; +import java.util.TimerTask; import org.objectweb.asm.Type; @@ -501,6 +503,22 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi final Vec3d soundPos = offsetSoundByName(posX, posY, posZ, playerPos, name, category); final Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize(); + /*final double distance = playerPos.distanceTo(soundPos); + final double time = (distance/343.3)*1000; + AL10.alSourcePause(sourceID); + log("paused, time "+String.valueOf(time)); + + new java.util.Timer().schedule( + new java.util.TimerTask() { + @Override + public void run() { + log("play, time "+String.valueOf(time)); + AL10.alSourcePlay(sourceID); + } + }, + (long)time + );*/ + Vec3d rayOrigin = soundPos; float occlusionAccumulation = 0.0f; From b10ee2dd84170d504a89c0b3d668e2a117efd6c8 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Tue, 2 Oct 2018 18:41:13 +0200 Subject: [PATCH 15/88] Updated build.gradle Signed-off-by: djpadbit --- build.gradle | 95 ++++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 58 deletions(-) diff --git a/build.gradle b/build.gradle index 289afb1a..2dec2ad9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,77 +1,56 @@ buildscript { - repositories { - jcenter() - maven { url = "http://files.minecraftforge.net/maven" } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - } + repositories { + jcenter() + maven { url = "http://files.minecraftforge.net/maven" } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' + } } apply plugin: 'net.minecraftforge.gradle.forge' //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. +version = "1.12.2" +group = "com.sonicether.soundphysics" +archivesBaseName = "Sound-Physics" -version = "1.0" -group = "com.yourname.modid" // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = "modid" +jar { + manifest { + attributes 'FMLCorePlugin': 'com.sonicether.soundphysics.CoreModLoader' + attributes 'FMLCorePluginContainsFMLMod': 'true' + } +} sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. compileJava { - sourceCompatibility = targetCompatibility = '1.8' + sourceCompatibility = targetCompatibility = '1.8' } minecraft { - version = "1.12.2-14.23.4.2765" - runDir = "run" - - // the mappings can be changed at any time, and must be in the following format. - // snapshot_YYYYMMDD snapshot are built nightly. - // stable_# stables are built at the discretion of the MCP team. - // Use non-default mappings at your own risk. they may not always work. - // simply re-run your setup task after changing the mappings to update your workspace. - mappings = "snapshot_20180814" - // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. + version = "1.12.2-14.23.4.2765" + runDir = "run" + + mappings = "snapshot_20180814" } dependencies { - // you may put jars on which you depend on in ./libs - // or you may define them like so.. - //compile "some.group:artifact:version:classifier" - //compile "some.group:artifact:version" - - // real examples - //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env - //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env - - // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. - //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' - - // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, - // except that these dependencies get remapped to your current MCP mappings - //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev' - //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev' - - // for more info... - // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html - // http://www.gradle.org/docs/current/userguide/dependency_management.html - } processResources { - // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version - - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - - // replace version and mcversion - expand 'version':project.version, 'mcversion':project.minecraft.version - } - - // copy everything else except the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + + // replace version and mcversion + expand 'version':project.version, 'mcversion':project.minecraft.version + } + + // copy everything else except the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } } From 7417af93d50b4a63da2f4e9a441d3677314c3e69 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Tue, 2 Oct 2018 23:40:37 +0200 Subject: [PATCH 16/88] Fixed computronics sound fuckery Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 4 ++-- .../sonicether/soundphysics/SoundPhysics.java | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index e826a21c..dc8f26bd 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -191,11 +191,11 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/nio/IntBuffer", "get", "(I)I", false)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "onPlaySound", "(FFFI)V", false)); + "onPlaySoundAL", "(FFFI)V", false)); // Target method: play bytes = patchMethodInClass(obfuscated, bytes, "play", "(Ljava/lang/String;FFFF)V", Opcodes.INVOKESTATIC, - AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, toInject, true, 0, 0, false, -5); } //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 3fe6c12f..47920562 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -336,13 +336,29 @@ public static void setLastSoundName(final String name) { /** * CALLED BY ASM INJECTED CODE! */ + // For sounds that get played normally public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID) { + onPlaySound(posX, posY, posZ, sourceID, lastSoundCategory, lastSoundName); + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + // For sounds that get played using OpenAL directly or just not using the minecraft sound system + public static void onPlaySoundAL(final float posX, final float posY, final float posZ, final int sourceID) { + onPlaySound(posX, posY, posZ, sourceID, SoundCategory.BLOCKS, "null"); + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName) { //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)); - evaluateEnvironment(sourceID, posX, posY, posZ,lastSoundCategory,lastSoundName); + evaluateEnvironment(sourceID, posX, posY, posZ,soundCat,soundName); if (!Config.dynamicEnvironementEvalutaion) return; - if ((mc.player == null | mc.world == null | posY <= 0 | lastSoundCategory == SoundCategory.RECORDS - | lastSoundCategory == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(lastSoundName).matches())) return; - Source tmp = new Source(sourceID,posX,posY,posZ,lastSoundCategory,lastSoundName); + if ((mc.player == null | mc.world == null | posY <= 0 | soundCat == SoundCategory.RECORDS + | soundCat == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(soundName).matches())) return; + Source tmp = new Source(sourceID,posX,posY,posZ,soundCat,soundName); if (source_check(tmp)) return; source_list.add(tmp); } From cc91e41edac96f22c02d60ab88b1c89cf697b80e Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 4 Oct 2018 19:47:02 +0200 Subject: [PATCH 17/88] 1.0.5 Release Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 5 +---- src/main/resources/mcmod.info | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 47920562..f4f21542 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -49,7 +49,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; - public static final String version = "1.0.4"; + public static final String version = "1.0.5"; public static final String mcVersion = "1.12.2"; private static final Pattern rainPattern = Pattern.compile(".*rain.*"); @@ -85,8 +85,6 @@ public void init(final FMLInitializationEvent event) { private static Minecraft mc; - private static SoundHandler sndHandler; - private static SoundCategory lastSoundCategory; private static String lastSoundName; @@ -108,7 +106,6 @@ public void init(final FMLInitializationEvent event) { public static void init() { setupEFX(); mc = Minecraft.getMinecraft(); - sndHandler = mc.getSoundHandler(); setupThread(); //System.out.println("---------------------------------"); //System.out.println(Type.getMethodDescriptor(Type.getType(boolean.class),Type.getType(FilenameURL.class))); diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 8241d747..5c837060 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,9 +3,9 @@ "modid": "soundphysics", "name": "Sound Physics", "description": "Provides realistic sound attenuation, reverberation, and absorption through blocks.", - "version": "1.0.4", + "version": "1.0.5", "mcversion": "1.12.2", - "url": "", - "authorList": ["Sonic Ether","daipenger"] + "url": "https://github.com/djpadbit/Sound-Physics", + "authorList": ["Sonic Ether","daipenger","djpadbit"] } ] From e96b000cb1364da999c623ee78b651f331753a18 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 31 Dec 2018 17:33:57 +0100 Subject: [PATCH 18/88] Fixed bug that caused sounds with "ui" to not get converted such as the liquid splash sounds Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index f4f21542..657dbb2d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -55,7 +55,7 @@ public class SoundPhysics { private static final Pattern rainPattern = Pattern.compile(".*rain.*"); private static final Pattern stepPattern = Pattern.compile(".*step.*"); private static final Pattern blockPattern = Pattern.compile(".*block.*"); - private static final Pattern uiPattern = Pattern.compile(".*ui.*"); + private static final Pattern uiPattern = Pattern.compile(".*\\/ui\\/.*"); private static final Pattern clickPattern = Pattern.compile(".*random.click.*"); @Mod.EventHandler From ceacd1589abe67a986385f06b46e3a70af62e488 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 31 Dec 2018 17:42:53 +0100 Subject: [PATCH 19/88] 1.0.5 Patch 1 Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- src/main/resources/mcmod.info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 657dbb2d..ae943717 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -49,7 +49,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; - public static final String version = "1.0.5"; + public static final String version = "1.0.5-1"; public static final String mcVersion = "1.12.2"; private static final Pattern rainPattern = Pattern.compile(".*rain.*"); diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 5c837060..f5d704b0 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "soundphysics", "name": "Sound Physics", "description": "Provides realistic sound attenuation, reverberation, and absorption through blocks.", - "version": "1.0.5", + "version": "1.0.5-1", "mcversion": "1.12.2", "url": "https://github.com/djpadbit/Sound-Physics", "authorList": ["Sonic Ether","daipenger","djpadbit"] From 98664d5c99b40afb10f84e170202393e7875978b Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 3 Jan 2019 15:13:58 +0100 Subject: [PATCH 20/88] Quick hack to fix the new dynamic surrounding's footsteps sounds Signed-off-by: djpadbit --- .../java/com/sonicether/soundphysics/CoreModInjector.java | 8 +++++--- .../java/com/sonicether/soundphysics/SoundPhysics.java | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index dc8f26bd..cfef9d42 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -44,11 +44,13 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.METHOD_INSN, "setVolume", null, toInject, false, 0, 0, false, 0); toInject = new InsnList(); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); - toInject.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "cgt", "a", "()Lnf;", true)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "cgq", "a", "()Lnf;", false)); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "nf", "toString", "()Ljava/lang/String;", false)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 3)); toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "nf", "toString", "()Ljava/lang/String;", false)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "setLastSoundName", "(Ljava/lang/String;)V", false)); + "setLastSoundName", "(Ljava/lang/String;Ljava/lang/String;)V", false)); // Target method: playSound bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index ae943717..51ab3752 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -326,8 +326,8 @@ public static void setLastSoundCategory(final SoundCategory sc) { /** * CALLED BY ASM INJECTED CODE! */ - public static void setLastSoundName(final String name) { - lastSoundName = name; + public static void setLastSoundName(final String soundName, final String eventName) { + lastSoundName = soundName+"||"+eventName; // Quick hack to check the event and sound name } /** From b2d3119833252806f3d05cfd37de9bac37dbd9e2 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 3 Jan 2019 15:25:21 +0100 Subject: [PATCH 21/88] Just a tid bit cleaner but still a dirt hack Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 51ab3752..43939439 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -327,7 +327,7 @@ public static void setLastSoundCategory(final SoundCategory sc) { * CALLED BY ASM INJECTED CODE! */ public static void setLastSoundName(final String soundName, final String eventName) { - lastSoundName = soundName+"||"+eventName; // Quick hack to check the event and sound name + lastSoundName = eventName+"|"+soundName.split(":")[1]; // Quick and dirty hack to check the event and sound name } /** From 577cf401652c09c0be526958bc5bd9cef5b3cffb Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 3 Jan 2019 15:28:23 +0100 Subject: [PATCH 22/88] 1.0.5 Patch 2 Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- src/main/resources/mcmod.info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 43939439..17a1fbd1 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -49,7 +49,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; - public static final String version = "1.0.5-1"; + public static final String version = "1.0.5-2"; public static final String mcVersion = "1.12.2"; private static final Pattern rainPattern = Pattern.compile(".*rain.*"); diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index f5d704b0..1166ff91 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "soundphysics", "name": "Sound Physics", "description": "Provides realistic sound attenuation, reverberation, and absorption through blocks.", - "version": "1.0.5-1", + "version": "1.0.5-2", "mcversion": "1.12.2", "url": "https://github.com/djpadbit/Sound-Physics", "authorList": ["Sonic Ether","daipenger","djpadbit"] From 5161cd2b20b065073563932bf206acd10de1fa12 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 27 Jan 2019 16:21:32 +0100 Subject: [PATCH 23/88] Fixed Dynmaic Env. thing Signed-off-by: djpadbit --- .../sonicether/soundphysics/SoundPhysics.java | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 17a1fbd1..a2ac09cd 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -89,8 +89,9 @@ public void init(final FMLInitializationEvent event) { private static String lastSoundName; private static ProcThread proc_thread; - private static boolean thread_alive; - private static List source_list; + private static volatile boolean thread_alive; + private static volatile boolean thread_signal_death; + private static volatile List source_list; // THESE VARIABLES ARE CONSTANTLY ACCESSED AND USED BY ASM INJECTED CODE! DO // NOT REMOVE! @@ -107,23 +108,18 @@ public static void init() { setupEFX(); mc = Minecraft.getMinecraft(); setupThread(); - //System.out.println("---------------------------------"); - //System.out.println(Type.getMethodDescriptor(Type.getType(boolean.class),Type.getType(FilenameURL.class))); - //System.out.println(Type.getMethodDescriptor(Type.getType(void.class),Type.getType(SoundBuffer.class))); - //System.out.println(Type.getMethodDescriptor(Type.getType(SoundBuffer.class),Type.getType(SoundBuffer.class))); - } public static class Source { - public static int sourceID; - public static float posX; - public static float posY; - public static float posZ; - public static SoundCategory category; - public static String name; - public static int frequency; - public static int size; - public static int bufferID; + public int sourceID; + public float posX; + public float posY; + public float posZ; + public SoundCategory category; + public String name; + public int frequency; + public int size; + public int bufferID; public Source(int sid,float px,float py,float pz,SoundCategory cat,String n) { this.sourceID = sid; @@ -140,7 +136,7 @@ public Source(int sid,float px,float py,float pz,SoundCategory cat,String n) { public static class ProcThread extends Thread { @Override - public void run() { + public synchronized void run() { while (thread_alive) { while (!Config.dynamicEnvironementEvalutaion) { try { @@ -169,7 +165,7 @@ public void run() { source.posY = pos.get(1); source.posZ = pos.get(2); evaluateEnvironment(source.sourceID,source.posX,source.posY,source.posZ,source.category,source.name); - } else if (state == AL10.AL_STOPPED) { + } else /*if (state == AL10.AL_STOPPED)*/ { iter.remove(); } } @@ -180,12 +176,13 @@ public void run() { logError(String.valueOf(e)); } } + thread_signal_death = true; } } public static boolean source_check(Source s) { synchronized (source_list) { - ListIterator iter = source_list.listIterator(); + ListIterator iter = source_list.listIterator(); while (iter.hasNext()) { Source sn = iter.next(); if (sn.sourceID == s.sourceID && sn.bufferID == s.bufferID && @@ -210,8 +207,9 @@ public static void onDebugOverlay(RenderGameOverlayEvent.Text event) ListIterator iter = source_list.listIterator(); while (iter.hasNext()) { Source s = iter.next(); - event.getLeft().add(String.valueOf(s.sourceID)+"-"+String.valueOf(s.posX)+","+String.valueOf(s.posY)+","+String.valueOf(s.posZ)); - int buffq = AL10.alGetSourcei(s.sourceID, AL10.AL_BUFFERS_QUEUED); + Vec3d tmp = new Vec3d(s.posX,s.posY,s.posZ); + event.getLeft().add(String.valueOf(s.sourceID)+"-"+s.category.toString()+"-"+s.name+"-"+tmp.toString()); + /*int buffq = AL10.alGetSourcei(s.sourceID, AL10.AL_BUFFERS_QUEUED); int buffp = AL10.alGetSourcei(s.sourceID, AL10.AL_BUFFERS_PROCESSED); int sampoff = AL10.alGetSourcei(s.sourceID, AL11.AL_SAMPLE_OFFSET); int byteoff = AL10.alGetSourcei(s.sourceID, AL11.AL_BYTE_OFFSET); @@ -223,16 +221,21 @@ public static void onDebugOverlay(RenderGameOverlayEvent.Text event) k = "0/? "; } event.getLeft().add(k+String.valueOf(buffp)+"/"+String.valueOf(buffq)+" "+String.valueOf(s.bufferID)); - event.getLeft().add("----"); + event.getLeft().add("----");*/ } } } } } - private static void setupThread() { - thread_alive = false; - source_list = Collections.synchronizedList(new ArrayList()); + private static synchronized void setupThread() { + if (proc_thread != null) { + thread_signal_death = false; + thread_alive = false; + while (!thread_signal_death); + } + if (source_list == null) source_list = Collections.synchronizedList(new ArrayList()); + else source_list.clear(); proc_thread = new ProcThread(); thread_alive = true; proc_thread.start(); @@ -350,7 +353,7 @@ public static void onPlaySoundAL(final float posX, final float posY, final float * CALLED BY ASM INJECTED CODE! */ public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName) { - //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)); + //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); evaluateEnvironment(sourceID, posX, posY, posZ,soundCat,soundName); if (!Config.dynamicEnvironementEvalutaion) return; if ((mc.player == null | mc.world == null | posY <= 0 | soundCat == SoundCategory.RECORDS From 12a2266c816cd4a1c9ddda8cd1e4ab3bc5b62004 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 27 Jan 2019 18:22:45 +0100 Subject: [PATCH 24/88] Modifed logging and options Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 18 +++++++++++++++--- .../soundphysics/CoreModInjector.java | 14 ++++++++++++-- .../sonicether/soundphysics/SoundPhysics.java | 8 ++++---- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index f08c5826..95b0fa00 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -46,15 +46,20 @@ public class Config { public static float sandReflectivity; public static float snowReflectivity; - //Compatibility + // compatibility public static boolean computronicsPatching; public static boolean autoSteroDownmix; - public static boolean autoSteroDownmixDebug; + + // misc + public static boolean autoSteroDownmixLogging; + public static boolean debugInfoShow; + public static boolean injectorLogging; private static final String categoryGeneral = "General"; private static final String categoryPerformance = "Performance"; private static final String categoryMaterialProperties = "Material properties"; private static final String categoryCompatibility = "Compatibility"; + private static final String categoryMisc = "Misc"; static { instance = new Config(); @@ -86,6 +91,7 @@ public List getConfigElements() { list.add(new ConfigElement(this.forgeConfig.getCategory(Config.categoryPerformance))); list.add(new ConfigElement(this.forgeConfig.getCategory(Config.categoryMaterialProperties))); list.add(new ConfigElement(this.forgeConfig.getCategory(Config.categoryCompatibility))); + list.add(new ConfigElement(this.forgeConfig.getCategory(Config.categoryMisc))); return list; } @@ -154,8 +160,14 @@ private void syncConfig() { "MAY REQUIRE RESTART.If true, patches the computronics sound sources so it works with sound physics."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto stereo downmix", categoryCompatibility, true, "MAY REQUIRE RESTART.If true, Automatically downmix stereo sounds that are loaded to mono"); - autoSteroDownmixDebug = this.forgeConfig.getBoolean("Stereo downmix debug", categoryCompatibility, false, + + // misc + autoSteroDownmixLogging = this.forgeConfig.getBoolean("Stereo downmix Logging", categoryMisc, false, "If true, Prints sound name and format of the sounds that get converted"); + debugInfoShow = this.forgeConfig.getBoolean("Dynamic env. info in F3", categoryMisc, false, + "If true, Shows sources currently playing in the F3 debug info"); + injectorLogging = this.forgeConfig.getBoolean("Injector Logging", categoryMisc, false, + "If true, Logs debug info about the injector"); if (this.forgeConfig.hasChanged()) { this.forgeConfig.save(); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index cfef9d42..fe8b4e2c 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -19,6 +19,8 @@ public class CoreModInjector implements IClassTransformer { + private static final String logPrefix = "[SOUND PHYSICS INJECTOR]"; + @Override public byte[] transform(final String obfuscated, final String deobfuscated, byte[] bytes) { if (obfuscated.equals("chm$a")) { @@ -199,7 +201,6 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte bytes = patchMethodInClass(obfuscated, bytes, "play", "(Ljava/lang/String;FFFF)V", Opcodes.INVOKESTATIC, AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, toInject, true, 0, 0, false, -5); } - //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); return bytes; } @@ -209,6 +210,7 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St final String targetInvocationMethodName, final String targetInvocationMethodSignature, final InsnList instructionsToInject, final boolean insertBefore, final int nodesToDeleteBefore, final int nodesToDeleteAfter, final boolean deleteTargetNode, final int targetNodeOffset) { + log("Patching class : "+className); final ClassNode classNode = new ClassNode(); final ClassReader classReader = new ClassReader(bytes); @@ -252,7 +254,7 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St } if (targetNode == null) { - SoundPhysics.logError("Target node not found!" + className); + logError("Target node not found!" + className); break; } @@ -291,10 +293,18 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St break; } } + log("Class finished : "+className); final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); } + public static void log(final String message) { + if (Config.injectorLogging) System.out.println(logPrefix.concat(" : ").concat(message)); + } + + public static void logError(final String errorMessage) { + System.out.println(logPrefix.concat(" [ERROR] : ").concat(errorMessage)); + } } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index a2ac09cd..22144b0d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -199,7 +199,7 @@ public static class DebugDisplayEventHandler { @SubscribeEvent public static void onDebugOverlay(RenderGameOverlayEvent.Text event) { - if(mc.gameSettings.showDebugInfo && Config.dynamicEnvironementEvalutaion) { + if(mc.gameSettings.showDebugInfo && Config.dynamicEnvironementEvalutaion && Config.debugInfoShow) { event.getLeft().add(""); event.getLeft().add("[SoundPhysics] "+String.valueOf(source_list.size())+" Sources"); event.getLeft().add("[SoundPhysics] Source list :"); @@ -370,7 +370,7 @@ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { if (buff == null || buff.audioFormat.getChannels() == 1 || !Config.autoSteroDownmix) return buff; if (mc.player == null | mc.world == null | lastSoundCategory == SoundCategory.RECORDS | lastSoundCategory == SoundCategory.MUSIC | uiPattern.matcher(filename).matches() | clickPattern.matcher(filename).matches()) { - if (Config.autoSteroDownmixDebug) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); + if (Config.autoSteroDownmixLogging) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); return buff; } AudioFormat orignalformat = buff.audioFormat; @@ -378,7 +378,7 @@ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { boolean bigendian = orignalformat.isBigEndian(); AudioFormat monoformat = new AudioFormat(orignalformat.getEncoding(), orignalformat.getSampleRate(), bits, 1, orignalformat.getFrameSize(), orignalformat.getFrameRate(), bigendian); - if (Config.autoSteroDownmixDebug) log("Converting sound '"+filename+"'("+orignalformat.toString()+") to mono ("+monoformat.toString()+")"); + if (Config.autoSteroDownmixLogging) log("Converting sound '"+filename+"'("+orignalformat.toString()+") to mono ("+monoformat.toString()+")"); ByteBuffer bb = ByteBuffer.wrap(buff.audioData,0,buff.audioData.length); bb.order(bigendian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); @@ -831,7 +831,7 @@ public static void log(final String message) { } public static void logError(final String errorMessage) { - System.out.println(logPrefix.concat(" [ERROR]: ").concat(errorMessage)); + System.out.println(logPrefix.concat(" [ERROR] : ").concat(errorMessage)); } protected static boolean checkErrorLog(final String errorMessage) { From 932996830a4b9f78356206417be1ac80e269db34 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 30 Jan 2019 22:38:01 +0100 Subject: [PATCH 25/88] Added snow air absorption. Now sounds get muffled when it's snowing Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 3 + .../sonicether/soundphysics/SoundPhysics.java | 56 +++++++++++++++++-- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 95b0fa00..4e53b7f6 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -25,6 +25,7 @@ public class Config { public static float globalBlockAbsorption; public static float globalBlockReflectance; public static float airAbsorption; + public static float snowAirAbsorptionFactor; public static float underwaterFilter; // performance @@ -115,6 +116,8 @@ private void syncConfig() { "Minecraft won't allow sounds to play past a certain distance. This parameter is a multiplier for how far away a sound source is allowed to be in order for it to actually play. Values too high can cause polyphony issues."); airAbsorption = this.forgeConfig.getFloat("Air Absorption", categoryGeneral, 1.0f, 0.0f, 5.0f, "A value controlling the amount that air absorbs high frequencies with distance. A value of 1.0 is physically correct for air with normal humidity and temperature. Higher values mean air will absorb more high frequencies with distance. 0 disables this effect."); + snowAirAbsorptionFactor = this.forgeConfig.getFloat("Max Snow Air Absorption Factor", categoryGeneral, 5.0f, 0.0f, 16.0f, + "The maximum air absorption factor when it's snowing. The real absorption factor will depend on the snow's intensity. Set to 1 or lower to disable"); underwaterFilter = this.forgeConfig.getFloat("Underwater Filter", categoryGeneral, 0.8f, 0.0f, 1.0f, "How much sound is filtered when the player is underwater. 0.0 means no filter. 1.0 means fully filtered."); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 22144b0d..21c3d2d2 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -407,6 +407,31 @@ public static double calculateEntitySoundOffset(final Entity entity, final Sound return entity.getEyeHeight(); } + // Copy of isRainingAt + private static boolean isSnowingAt(BlockPos position) + { + if (!mc.world.isRaining()) + { + return false; + } + else if (!mc.world.canSeeSky(position)) + { + return false; + } + else if (mc.world.getPrecipitationHeight(position).getY() > position.getY()) + { + return false; + } + else + { + /*boolean cansnow = mc.world.canSnowAt(position, false); + if (mc.world.getBiome(position).getEnableSnow() && cansnow) return true; + else if (cansnow) return true; + else return false;*/ + return mc.world.canSnowAt(position, false) | mc.world.getBiome(position).getEnableSnow(); + } + } + @SuppressWarnings("deprecation") private static float getBlockReflectivity(final BlockPos blockPos) { final Block block = mc.world.getBlockState(blockPos).getBlock(); @@ -501,14 +526,14 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi | category == SoundCategory.MUSIC) { // posY <= 0 as a condition has to be there: Ingame // menu clicks do have a player and world present - setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); return; } final boolean isRain = rainPattern.matcher(name).matches(); if (Config.skipRainOcclusionTracing && isRain) { - setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); return; } @@ -519,6 +544,24 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi final Vec3d soundPos = offsetSoundByName(posX, posY, posZ, playerPos, name, category); final Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize(); + float snowFactor = 0.0f; + + if (mc.world.isRaining()) { + final Vec3d middlePos = playerPos.add(soundPos).scale(0.5); + final BlockPos playerPosBlock = new BlockPos(playerPos); + final BlockPos soundPosBlock = new BlockPos(soundPos); + final BlockPos middlePosBlock = new BlockPos(middlePos); + final int snowingPlayer = isSnowingAt(playerPosBlock) ? 1 : 0; + final int snowingSound = isSnowingAt(soundPosBlock) ? 1 : 0; + final int snowingMiddle = isSnowingAt(middlePosBlock) ? 1 : 0; + snowFactor = snowingPlayer * 0.25f + snowingMiddle * 0.5f + snowingSound * 0.25f; + } + + float airAbsorptionFactor = 1.0f; + if (snowFactor > 0.0f) { + airAbsorptionFactor = Math.max(Config.snowAirAbsorptionFactor*mc.world.getRainStrength(1.0f)*snowFactor,airAbsorptionFactor); + } + /*final double distance = playerPos.distanceTo(soundPos); final double time = (distance/343.3)*1000; AL10.alSourcePause(sourceID); @@ -581,7 +624,7 @@ public void run() { if (isRain) { setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, - sendCutoff3, directCutoff, directGain); + sendCutoff3, directCutoff, directGain, airAbsorptionFactor); return; } @@ -753,12 +796,13 @@ public void run() { } setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, - sendCutoff3, directCutoff, directGain); + sendCutoff3, directCutoff, directGain, airAbsorptionFactor); } private static void setEnvironment(final int sourceID, final float sendGain0, final float sendGain1, final float sendGain2, final float sendGain3, final float sendCutoff0, final float sendCutoff1, - final float sendCutoff2, final float sendCutoff3, final float directCutoff, final float directGain) { + final float sendCutoff2, final float sendCutoff3, final float directCutoff, final float directGain, + final float airAbsorptionFactor) { // Set reverb send filter values and set source to send to all reverb fx // slots EFX10.alFilterf(sendFilter0, EFX10.AL_LOWPASS_GAIN, sendGain0); @@ -781,7 +825,7 @@ private static void setEnvironment(final int sourceID, final float sendGain0, fi EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAINHF, directCutoff); AL10.alSourcei(sourceID, EFX10.AL_DIRECT_FILTER, directFilter0); - AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, Config.airAbsorption); + AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, Config.airAbsorption*airAbsorptionFactor); } /** From b54eaff0afc3e3bbf4b42df143e2b0bfa5227e74 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 30 Jan 2019 22:39:58 +0100 Subject: [PATCH 26/88] Bit of spaces Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 21c3d2d2..739bc4b8 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -558,6 +558,7 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi } float airAbsorptionFactor = 1.0f; + if (snowFactor > 0.0f) { airAbsorptionFactor = Math.max(Config.snowAirAbsorptionFactor*mc.world.getRainStrength(1.0f)*snowFactor,airAbsorptionFactor); } @@ -825,7 +826,7 @@ private static void setEnvironment(final int sourceID, final float sendGain0, fi EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAINHF, directCutoff); AL10.alSourcei(sourceID, EFX10.AL_DIRECT_FILTER, directFilter0); - AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, Config.airAbsorption*airAbsorptionFactor); + AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, Config.airAbsorption * airAbsorptionFactor); } /** From b75414cb31dca79336cc9bc357ded8ab4ca98504 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 31 Jan 2019 19:13:31 +0100 Subject: [PATCH 27/88] More logging in injector Added support for var nodes Patch computronics to have bigger play distance (kind of hack? maybe revisit one day?) Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index fe8b4e2c..9d31dd37 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -31,7 +31,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: Constructor bytes = patchMethodInClass(obfuscated, bytes, "", "(Lchm;)V", Opcodes.INVOKESPECIAL, - AbstractInsnNode.METHOD_INSN, "", null, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "", null, -1, toInject, false, 0, 0, false, 0); } else if (obfuscated.equals("chm")) { @@ -43,7 +43,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setVolume", null, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, false, 0, 0, false, 0); toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); @@ -56,7 +56,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setVolume", null, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, false, 0, 0, false, 0); toInject = new InsnList(); toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", @@ -65,7 +65,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound, target invocation getClampedVolume bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKESPECIAL, - AbstractInsnNode.METHOD_INSN, "e", "(Lcgt;)F", toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "e", "(Lcgt;)F", -1, toInject, false, 0, 0, false, 0); } else if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL")) { @@ -96,7 +96,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: play bytes = patchMethodInClass(obfuscated, bytes, "play", "(Lpaulscode/sound/Channel;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "play", null, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "play", null, -1, toInject, false, 0, 0, false, 0); } else // Convert stero sounds to mono @@ -116,7 +116,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: loadSound bytes = patchMethodInClass(obfuscated, bytes, "loadSound", "(Lpaulscode/sound/FilenameURL;)Z", Opcodes.INVOKEINTERFACE, - AbstractInsnNode.METHOD_INSN, "cleanup", null, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "cleanup", null, -1, toInject, false, 0, 0, false, 0); toInject = new InsnList(); @@ -130,7 +130,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: loadSound bytes = patchMethodInClass(obfuscated, bytes, "loadSound", "(Lpaulscode/sound/SoundBuffer;Ljava/lang/String;)Z", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "getChannels", null, toInject, true, 0, 0, false, -12); + AbstractInsnNode.METHOD_INSN, "getChannels", null, -1, toInject, true, 0, 0, false, -12); } else if (obfuscated.equals("paulscode.sound.SoundSystem")) { @@ -145,7 +145,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: newSource bytes = patchMethodInClass(obfuscated, bytes, "newSource", "(ZLjava/lang/String;Ljava/net/URL;Ljava/lang/String;ZFFFIF)V", Opcodes.INVOKESPECIAL, - AbstractInsnNode.METHOD_INSN, "", null, toInject, true, 2, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "", null, -1, toInject, true, 2, 0, false, 0); } else if (obfuscated.equals("pl")) { @@ -160,7 +160,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: sendToAllNearExcept bytes = patchMethodInClass(obfuscated, bytes, "a", "(Laed;DDDDILht;)V", Opcodes.DCMPG, - AbstractInsnNode.INSN, "", "", toInject, true, 0, 0, false, 0); + AbstractInsnNode.INSN, "", "", -1, toInject, true, 0, 0, false, 0); } else if (obfuscated.equals("vg")) { @@ -177,7 +177,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound // Inside target method, target node: Entity/getSoundCategory bytes = patchMethodInClass(obfuscated, bytes, "a", "(Lqe;FF)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "bK", null, toInject, true, 0, 0, false, -3); + AbstractInsnNode.METHOD_INSN, "bK", null, -1, toInject, true, 0, 0, false, -3); } else // Fix for computronics's sound card and tape drive @@ -199,7 +199,18 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: play bytes = patchMethodInClass(obfuscated, bytes, "play", "(Ljava/lang/String;FFFF)V", Opcodes.INVOKESTATIC, - AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, toInject, true, 0, 0, false, -5); + AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, -1, toInject, true, 0, 0, false, -5); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new InsnNode(Opcodes.D2F)); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: setHearing + bytes = patchMethodInClass(obfuscated, bytes, "setHearing", "(FF)V", Opcodes.FLOAD, + AbstractInsnNode.VAR_INSN, "", null, 1, toInject, false, 0, 0, false, 0); } return bytes; @@ -207,7 +218,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte private byte[] patchMethodInClass(String className, final byte[] bytes, final String targetMethod, final String targetMethodSignature, final int targetNodeOpcode, final int targetNodeType, - final String targetInvocationMethodName, final String targetInvocationMethodSignature, + final String targetInvocationMethodName, final String targetInvocationMethodSignature, final int targetVarNodeIndex, final InsnList instructionsToInject, final boolean insertBefore, final int nodesToDeleteBefore, final int nodesToDeleteAfter, final boolean deleteTargetNode, final int targetNodeOffset) { log("Patching class : "+className); @@ -219,8 +230,10 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St while (methodIterator.hasNext()) { final MethodNode m = methodIterator.next(); + //log("@" + m.name + " " + m.desc); if (m.name.equals(targetMethod) && m.desc.equals(targetMethodSignature)) { + log("Inside target method: " + targetMethod); AbstractInsnNode targetNode = null; @@ -235,6 +248,7 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St if (method.name.equals(targetInvocationMethodName)) { if (method.desc.equals(targetInvocationMethodSignature) || targetInvocationMethodSignature == null) { + log("Found target method invocation for injection: " + targetInvocationMethodName); targetNode = currentNode; // Due to collisions, do not put break // statements here! @@ -242,8 +256,19 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St } } + } else if (targetNodeType == AbstractInsnNode.VAR_INSN) { + if (currentNode.getType() == AbstractInsnNode.VAR_INSN) { + final VarInsnNode varnode = (VarInsnNode) currentNode; + if (targetVarNodeIndex < 0 || varnode.var == targetVarNodeIndex) { + log("Found target var node for injection: " + targetVarNodeIndex); + targetNode = currentNode; + // Due to collisions, do not put break + // statements here! + } + } } else { if (currentNode.getType() == targetNodeType) { + log("Found target node for injection: " + targetNodeType); targetNode = currentNode; // Due to collisions, do not put break // statements here! @@ -254,7 +279,7 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St } if (targetNode == null) { - logError("Target node not found!" + className); + logError("Target node not found! " + className); break; } @@ -272,11 +297,13 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St // If we've found the target, inject the instructions! for (int i = 0; i < nodesToDeleteBefore; i++) { final AbstractInsnNode previousNode = targetNode.getPrevious(); + log("Removing Node " + previousNode.getOpcode()); m.instructions.remove(previousNode); } for (int i = 0; i < nodesToDeleteAfter; i++) { final AbstractInsnNode nextNode = targetNode.getNext(); + log("Removing Node " + nextNode.getOpcode()); m.instructions.remove(nextNode); } From 1bd9112c85ec2929d7a139ab716bc6a0c43b92e2 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 31 Jan 2019 21:53:42 +0100 Subject: [PATCH 28/88] Now works on note blocks (configurable) Removed redundant check Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 5 ++++- .../sonicether/soundphysics/SoundPhysics.java | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 4e53b7f6..a3354f71 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -27,6 +27,7 @@ public class Config { public static float airAbsorption; public static float snowAirAbsorptionFactor; public static float underwaterFilter; + public static boolean noteBlockEnable; // performance public static boolean skipRainOcclusionTracing; @@ -116,10 +117,12 @@ private void syncConfig() { "Minecraft won't allow sounds to play past a certain distance. This parameter is a multiplier for how far away a sound source is allowed to be in order for it to actually play. Values too high can cause polyphony issues."); airAbsorption = this.forgeConfig.getFloat("Air Absorption", categoryGeneral, 1.0f, 0.0f, 5.0f, "A value controlling the amount that air absorbs high frequencies with distance. A value of 1.0 is physically correct for air with normal humidity and temperature. Higher values mean air will absorb more high frequencies with distance. 0 disables this effect."); - snowAirAbsorptionFactor = this.forgeConfig.getFloat("Max Snow Air Absorption Factor", categoryGeneral, 5.0f, 0.0f, 16.0f, + snowAirAbsorptionFactor = this.forgeConfig.getFloat("Max Snow Air Absorption Factor", categoryGeneral, 5.0f, 0.0f, 10.0f, "The maximum air absorption factor when it's snowing. The real absorption factor will depend on the snow's intensity. Set to 1 or lower to disable"); underwaterFilter = this.forgeConfig.getFloat("Underwater Filter", categoryGeneral, 0.8f, 0.0f, 1.0f, "How much sound is filtered when the player is underwater. 0.0 means no filter. 1.0 means fully filtered."); + noteBlockEnable = this.forgeConfig.getBoolean("Affect Note Blocks", categoryGeneral, true, + "If true, note blocks will be processed."); // performance skipRainOcclusionTracing = this.forgeConfig.getBoolean("Skip Rain Occlusion Tracing", categoryPerformance, true, diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 739bc4b8..ee08d989 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -57,6 +57,7 @@ public class SoundPhysics { private static final Pattern blockPattern = Pattern.compile(".*block.*"); private static final Pattern uiPattern = Pattern.compile(".*\\/ui\\/.*"); private static final Pattern clickPattern = Pattern.compile(".*random.click.*"); + private static final Pattern noteBlockPattern = Pattern.compile(".*note.harp.*"); @Mod.EventHandler public void preInit(final FMLPreInitializationEvent event) { @@ -354,6 +355,7 @@ public static void onPlaySoundAL(final float posX, final float posY, final float */ public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName) { //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); + if (Config.noteBlockEnable && soundCat == SoundCategory.RECORDS && noteBlockPattern.matcher(soundName).matches()) soundCat = SoundCategory.BLOCKS; evaluateEnvironment(sourceID, posX, posY, posZ,soundCat,soundName); if (!Config.dynamicEnvironementEvalutaion) return; if ((mc.player == null | mc.world == null | posY <= 0 | soundCat == SoundCategory.RECORDS @@ -407,11 +409,16 @@ public static double calculateEntitySoundOffset(final Entity entity, final Sound return entity.getEyeHeight(); } - // Copy of isRainingAt + // Unused private static boolean isSnowingAt(BlockPos position) { - if (!mc.world.isRaining()) - { + return isSnowingAt(position, true); + } + + // Copy of isRainingAt + private static boolean isSnowingAt(BlockPos position, boolean check_rain) + { + if (check_rain && !mc.world.isRaining()) { return false; } else if (!mc.world.canSeeSky(position)) @@ -551,9 +558,9 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi final BlockPos playerPosBlock = new BlockPos(playerPos); final BlockPos soundPosBlock = new BlockPos(soundPos); final BlockPos middlePosBlock = new BlockPos(middlePos); - final int snowingPlayer = isSnowingAt(playerPosBlock) ? 1 : 0; - final int snowingSound = isSnowingAt(soundPosBlock) ? 1 : 0; - final int snowingMiddle = isSnowingAt(middlePosBlock) ? 1 : 0; + final int snowingPlayer = isSnowingAt(playerPosBlock,false) ? 1 : 0; + final int snowingSound = isSnowingAt(soundPosBlock,false) ? 1 : 0; + final int snowingMiddle = isSnowingAt(middlePosBlock,false) ? 1 : 0; snowFactor = snowingPlayer * 0.25f + snowingMiddle * 0.5f + snowingSound * 0.25f; } @@ -826,7 +833,7 @@ private static void setEnvironment(final int sourceID, final float sendGain0, fi EFX10.alFilterf(directFilter0, EFX10.AL_LOWPASS_GAINHF, directCutoff); AL10.alSourcei(sourceID, EFX10.AL_DIRECT_FILTER, directFilter0); - AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, Config.airAbsorption * airAbsorptionFactor); + AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, MathHelper.clamp(Config.airAbsorption * airAbsorptionFactor,0.0f,10.0f)); } /** From f6b30dc333ffbee9bf4003339f4bc6facdf655a7 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 3 Feb 2019 17:04:12 +0100 Subject: [PATCH 29/88] Don't try to restart the thread as it is useless and causes problems if it can't (Like with Liteloader) Also the dynamic env thing needs a full rewrite as it's not that great Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/SoundPhysics.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index ee08d989..92cab54a 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -230,16 +230,19 @@ public static void onDebugOverlay(RenderGameOverlayEvent.Text event) } private static synchronized void setupThread() { - if (proc_thread != null) { + if (source_list == null) source_list = Collections.synchronizedList(new ArrayList()); + else source_list.clear(); + + /*if (proc_thread != null) { thread_signal_death = false; thread_alive = false; while (!thread_signal_death); + }*/ + if (proc_thread == null) { + proc_thread = new ProcThread(); + thread_alive = true; + proc_thread.start(); } - if (source_list == null) source_list = Collections.synchronizedList(new ArrayList()); - else source_list.clear(); - proc_thread = new ProcThread(); - thread_alive = true; - proc_thread.start(); } public static void applyConfigChanges() { From 3f20d9ba51284a03bc5f69529d643de1c07f2079 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 3 Feb 2019 19:13:39 +0100 Subject: [PATCH 30/88] Fixed computronics play sound distance Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 19 +++++++++++++++++++ .../sonicether/soundphysics/SoundPhysics.java | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 9d31dd37..dff0e0ec 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -211,8 +211,27 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: setHearing bytes = patchMethodInClass(obfuscated, bytes, "setHearing", "(FF)V", Opcodes.FLOAD, AbstractInsnNode.VAR_INSN, "", null, 1, toInject, false, 0, 0, false, 0); + } else + + if (obfuscated.equals("pl.asie.computronics.api.audio.AudioPacket") && Config.computronicsPatching) { + // Inside AudioPacket + InsnList toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new InsnNode(Opcodes.DMUL)); + toInject.add(new InsnNode(Opcodes.D2I)); + toInject.add(new InsnNode(Opcodes.IMUL)); + + // Target method: canHearReceiver + bytes = patchMethodInClass(obfuscated, bytes, "canHearReceiver", "(Lnet/minecraft/entity/player/EntityPlayerMP;Lpl/asie/computronics/api/audio/IAudioReceiver;)Z", Opcodes.IMUL, + AbstractInsnNode.INSN, "", null, -1, toInject, false, 0, 0, false, 0); } + //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); + return bytes; } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 92cab54a..524dda5b 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -45,7 +45,8 @@ import org.objectweb.asm.Type; -@Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory") +@Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory", + dependencies="before:computronics") // Dependencies to make sure that SP's config is loaded before patching Computronics public class SoundPhysics { public static final String modid = "soundphysics"; From aea1b4eeae9c2d530b3ee6c53bc0d3363c89b158 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 13 Feb 2019 11:34:36 +0100 Subject: [PATCH 31/88] 1.0.6 Release Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- src/main/resources/mcmod.info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 524dda5b..bb8f7146 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -50,7 +50,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; - public static final String version = "1.0.5-2"; + public static final String version = "1.0.6"; public static final String mcVersion = "1.12.2"; private static final Pattern rainPattern = Pattern.compile(".*rain.*"); diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 1166ff91..4e714701 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "soundphysics", "name": "Sound Physics", "description": "Provides realistic sound attenuation, reverberation, and absorption through blocks.", - "version": "1.0.5-2", + "version": "1.0.6", "mcversion": "1.12.2", "url": "https://github.com/djpadbit/Sound-Physics", "authorList": ["Sonic Ether","daipenger","djpadbit"] From 89c7f87690783ca84173484ba209604be4fabac9 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 4 Mar 2019 19:13:02 +0100 Subject: [PATCH 32/88] Fixed only harp note blocks sound would get processed Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index bb8f7146..c681b2ce 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -58,7 +58,7 @@ public class SoundPhysics { private static final Pattern blockPattern = Pattern.compile(".*block.*"); private static final Pattern uiPattern = Pattern.compile(".*\\/ui\\/.*"); private static final Pattern clickPattern = Pattern.compile(".*random.click.*"); - private static final Pattern noteBlockPattern = Pattern.compile(".*note.harp.*"); + private static final Pattern noteBlockPattern = Pattern.compile(".*block.note.*"); @Mod.EventHandler public void preInit(final FMLPreInitializationEvent event) { From 282c15ccfe56fe2a8403fa9083a3bb669b608b48 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 13 Apr 2019 02:29:09 +0200 Subject: [PATCH 33/88] Computronics fix source position for tape drive, speaker and speech box I haven't tested the speech box but it should work Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 63 ++++++++++++++++++- .../sonicether/soundphysics/SoundPhysics.java | 10 +++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index dff0e0ec..fdb74f64 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -180,7 +180,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.METHOD_INSN, "bK", null, -1, toInject, true, 0, 0, false, -3); } else - // Fix for computronics's sound card and tape drive + // Fix for computronics's devices if (obfuscated.equals("pl.asie.lib.audio.StreamingAudioPlayer") && Config.computronicsPatching) { // Inside StreamingAudioPlayer InsnList toInject = new InsnList(); @@ -228,6 +228,67 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: canHearReceiver bytes = patchMethodInClass(obfuscated, bytes, "canHearReceiver", "(Lnet/minecraft/entity/player/EntityPlayerMP;Lpl/asie/computronics/api/audio/IAudioReceiver;)Z", Opcodes.IMUL, AbstractInsnNode.INSN, "", null, -1, toInject, false, 0, 0, false, 0); + } else + + if (obfuscated.equals("pl.asie.computronics.tile.TileTapeDrive$1") && Config.computronicsPatching) { + // Inside TileTapeDrive.internalSpeaker + InsnList toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/computronics/tile/TileTapeDrive$1", "this$0", + "Lpl/asie/computronics/tile/TileTapeDrive;")); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "pl/asie/computronics/Computronics", + "tapeReader", "Lpl/asie/computronics/block/BlockTapeReader;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/computronics/block/BlockTapeReader", "rotation", + "Lpl/asie/lib/block/BlockBase$Rotation;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/lib/block/BlockBase$Rotation", "FACING", + "Lnet/minecraft/block/properties/PropertyDirection;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "computronicsOffset", + "(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/tileentity/TileEntity;Lnet/minecraft/block/properties/PropertyDirection;)Lnet/minecraft/util/math/Vec3d;", false)); + + // Target method: getSoundPos + bytes = patchMethodInClass(obfuscated, bytes, "getSoundPos", "()Lnet/minecraft/util/math/Vec3d;", Opcodes.ARETURN, + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); + } else + + if (obfuscated.equals("pl.asie.computronics.tile.TileSpeaker") && Config.computronicsPatching) { + // Inside TileSpeaker + InsnList toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "pl/asie/computronics/Computronics", + "speaker", "Lpl/asie/computronics/block/BlockSpeaker;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/computronics/block/BlockSpeaker", "rotation", + "Lpl/asie/lib/block/BlockBase$Rotation;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/lib/block/BlockBase$Rotation", "FACING", + "Lnet/minecraft/block/properties/PropertyDirection;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "computronicsOffset", + "(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/tileentity/TileEntity;Lnet/minecraft/block/properties/PropertyDirection;)Lnet/minecraft/util/math/Vec3d;", false)); + + // Target method: getSoundPos + bytes = patchMethodInClass(obfuscated, bytes, "getSoundPos", "()Lnet/minecraft/util/math/Vec3d;", Opcodes.ARETURN, + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); + } else + + if (obfuscated.equals("pl.asie.computronics.tile.TileSpeechBox$1") && Config.computronicsPatching) { + // Inside TileSpeechBox.internalSpeaker + InsnList toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/computronics/tile/TileSpeechBox$1", "this$0", + "Lpl/asie/computronics/tile/TileSpeechBox;")); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "pl/asie/computronics/Computronics", + "speechBox", "Lpl/asie/computronics/block/BlockSpeechBox;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/computronics/block/BlockSpeechBox", "rotation", + "Lpl/asie/lib/block/BlockBase$Rotation;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "pl/asie/lib/block/BlockBase$Rotation", "FACING", + "Lnet/minecraft/block/properties/PropertyDirection;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "computronicsOffset", + "(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/tileentity/TileEntity;Lnet/minecraft/block/properties/PropertyDirection;)Lnet/minecraft/util/math/Vec3d;", false)); + + // Target method: getSoundPos + bytes = patchMethodInClass(obfuscated, bytes, "getSoundPos", "()Lnet/minecraft/util/math/Vec3d;", Opcodes.ARETURN, + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); } //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index c681b2ce..a107052d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -18,6 +18,8 @@ import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyDirection; +import net.minecraft.tileentity.TileEntity; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.util.EnumFacing; @@ -413,6 +415,14 @@ public static double calculateEntitySoundOffset(final Entity entity, final Sound return entity.getEyeHeight(); } + public static Vec3d computronicsOffset(Vec3d or, TileEntity te, PropertyDirection pd) + { + if (!te.hasWorld()) return or; + EnumFacing ef = te.getWorld().getBlockState(te.getPos()).getValue(pd); + Vec3d efv = getNormalFromFacing(ef).scale(0.51); + return or.add(efv); + } + // Unused private static boolean isSnowingAt(BlockPos position) { From e5115716e85fffea6e792a9f413741379280aa5c Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 13 Apr 2019 18:44:07 +0200 Subject: [PATCH 34/88] Added server support (seems to work for now) Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 2 +- .../sonicether/soundphysics/SoundPhysics.java | 24 +++++++++++++++---- .../soundphysics/SoundPhysicsServer.java | 21 ++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index a3354f71..dbf6bf8d 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -175,9 +175,9 @@ private void syncConfig() { injectorLogging = this.forgeConfig.getBoolean("Injector Logging", categoryMisc, false, "If true, Logs debug info about the injector"); + SoundPhysics.applyConfigChanges(); if (this.forgeConfig.hasChanged()) { this.forgeConfig.save(); - SoundPhysics.applyConfigChanges(); } } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index a107052d..7a461b3b 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -25,12 +25,11 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; -import net.minecraft.client.audio.ISound; -import net.minecraft.client.audio.SoundHandler; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -45,15 +44,18 @@ import java.util.Timer; import java.util.TimerTask; -import org.objectweb.asm.Type; +import org.apache.commons.lang3.reflect.FieldUtils; @Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory", - dependencies="before:computronics") // Dependencies to make sure that SP's config is loaded before patching Computronics + dependencies = SoundPhysics.deps) public class SoundPhysics { public static final String modid = "soundphysics"; public static final String version = "1.0.6"; public static final String mcVersion = "1.12.2"; + public static final String deps = "before:computronics"; // Dependencies to make sure that SP's config is loaded before patching Computronics + + public static boolean onServer = false; private static final Pattern rainPattern = Pattern.compile(".*rain.*"); private static final Pattern stepPattern = Pattern.compile(".*step.*"); @@ -408,7 +410,19 @@ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { * CALLED BY ASM INJECTED CODE! */ public static double calculateEntitySoundOffset(final Entity entity, final SoundEvent sound) { - if (stepPattern.matcher(sound.getSoundName().getPath()).matches()) { + String soundPath = ""; + // getSoundName() isn't on the server side, and soundName is private + if (!onServer) { + soundPath = sound.getSoundName().getPath(); + } else { + try { // field_187506_b = soundName + ResourceLocation rl = (ResourceLocation)FieldUtils.readField(sound, "field_187506_b", true); + soundPath = rl.getPath(); + } catch (Exception e) { + logError(e.toString()); + } + } + if (stepPattern.matcher(soundPath).matches()) { return 0; } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java b/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java new file mode 100644 index 00000000..fd36820f --- /dev/null +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java @@ -0,0 +1,21 @@ +package com.sonicether.soundphysics; + +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +//Server side mod to load the config +@Mod(modid = SoundPhysics.modid, serverSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory", + dependencies = SoundPhysics.deps) +public class SoundPhysicsServer { + @Mod.EventHandler + public void preInit(final FMLPreInitializationEvent event) { + SoundPhysics.onServer = true; + Config.instance.preInit(event); + } + + @Mod.EventHandler + public void init(final FMLInitializationEvent event) { + Config.instance.init(event); + } +} \ No newline at end of file From 0d0ccf3741bc84d509f0e0ac13835e121a31bdb5 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 14 Apr 2019 18:18:26 +0200 Subject: [PATCH 35/88] Another bugfix for the dynamic thing Signed-off-by: djpadbit --- .../sonicether/soundphysics/SoundPhysics.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 7a461b3b..7e28922d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -186,18 +186,22 @@ public synchronized void run() { } } - public static boolean source_check(Source s) { + public static void source_check_add(Source s) { synchronized (source_list) { ListIterator iter = source_list.listIterator(); while (iter.hasNext()) { Source sn = iter.next(); - if (sn.sourceID == s.sourceID && sn.bufferID == s.bufferID && - sn.posX == s.posX && sn.posY == s.posY && sn.posZ == s.posZ) { - return true; + if (sn.sourceID == s.sourceID) { + sn.posX = s.posX; + sn.posY = s.posY; + sn.posZ = s.posZ; + sn.category = s.category; + sn.name = s.name; + return; } } + source_list.add(s); } - return false; } @Mod.EventBusSubscriber @@ -369,8 +373,7 @@ public static void onPlaySound(final float posX, final float posY, final float p if ((mc.player == null | mc.world == null | posY <= 0 | soundCat == SoundCategory.RECORDS | soundCat == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(soundName).matches())) return; Source tmp = new Source(sourceID,posX,posY,posZ,soundCat,soundName); - if (source_check(tmp)) return; - source_list.add(tmp); + source_check_add(tmp); } /** From d2b5fcd77719d6cc7957c26541f537be212ac35a Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 18 Apr 2019 23:09:02 +0200 Subject: [PATCH 36/88] Bugfixes Signed-off-by: djpadbit --- .../sonicether/soundphysics/SoundPhysics.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 7e28922d..91ac724f 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -111,9 +111,15 @@ public void init(final FMLInitializationEvent event) { * CALLED BY ASM INJECTED CODE! */ public static void init() { - setupEFX(); mc = Minecraft.getMinecraft(); - setupThread(); + // I could check if the sound system loaded correctly but that's long and anoying + try { + setupEFX(); + setupThread(); + } catch (Throwable e) { + logError("Failed to init EFX or thread"); + logError(e.toString()); + } } public static class Source { @@ -209,7 +215,8 @@ public static class DebugDisplayEventHandler { @SubscribeEvent public static void onDebugOverlay(RenderGameOverlayEvent.Text event) { - if(mc.gameSettings.showDebugInfo && Config.dynamicEnvironementEvalutaion && Config.debugInfoShow) { + if (mc == null) return; // In case we fuck up somewhere + if (mc.gameSettings.showDebugInfo && Config.dynamicEnvironementEvalutaion && Config.debugInfoShow) { event.getLeft().add(""); event.getLeft().add("[SoundPhysics] "+String.valueOf(source_list.size())+" Sources"); event.getLeft().add("[SoundPhysics] Source list :"); @@ -370,8 +377,9 @@ public static void onPlaySound(final float posX, final float posY, final float p if (Config.noteBlockEnable && soundCat == SoundCategory.RECORDS && noteBlockPattern.matcher(soundName).matches()) soundCat = SoundCategory.BLOCKS; evaluateEnvironment(sourceID, posX, posY, posZ,soundCat,soundName); if (!Config.dynamicEnvironementEvalutaion) return; - if ((mc.player == null | mc.world == null | posY <= 0 | soundCat == SoundCategory.RECORDS - | soundCat == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(soundName).matches())) return; + if ((mc.player == null || mc.world == null || posY <= 0 || soundCat == SoundCategory.RECORDS + || soundCat == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(soundName).matches())) return; + if (clickPattern.matcher(soundName).matches() || uiPattern.matcher(soundName).matches()) return; Source tmp = new Source(sourceID,posX,posY,posZ,soundCat,soundName); source_check_add(tmp); } From 8bc501caaf7ec85c93a3dba2c705f4277b31e6fe Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 22 Apr 2019 22:02:41 +0200 Subject: [PATCH 37/88] Fix sound position moving for computronics Signed-off-by: djpadbit --- .../java/com/sonicether/soundphysics/SoundPhysics.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 91ac724f..154c1d0e 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -213,10 +213,8 @@ public static void source_check_add(Source s) { @Mod.EventBusSubscriber public static class DebugDisplayEventHandler { @SubscribeEvent - public static void onDebugOverlay(RenderGameOverlayEvent.Text event) - { - if (mc == null) return; // In case we fuck up somewhere - if (mc.gameSettings.showDebugInfo && Config.dynamicEnvironementEvalutaion && Config.debugInfoShow) { + public static void onDebugOverlay(RenderGameOverlayEvent.Text event) { + if (mc != null && mc.gameSettings.showDebugInfo && Config.dynamicEnvironementEvalutaion && Config.debugInfoShow) { event.getLeft().add(""); event.getLeft().add("[SoundPhysics] "+String.valueOf(source_list.size())+" Sources"); event.getLeft().add("[SoundPhysics] Source list :"); @@ -366,7 +364,7 @@ public static void onPlaySound(final float posX, final float posY, final float p */ // For sounds that get played using OpenAL directly or just not using the minecraft sound system public static void onPlaySoundAL(final float posX, final float posY, final float posZ, final int sourceID) { - onPlaySound(posX, posY, posZ, sourceID, SoundCategory.BLOCKS, "null"); + onPlaySound(posX, posY, posZ, sourceID, SoundCategory.MASTER, "null"); } /** From bbe011d88a2cdba3b3641a4ad4e33202185e5c65 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 15 May 2019 22:21:09 +0200 Subject: [PATCH 38/88] Added config for ray max distance Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/Config.java | 3 +++ src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index dbf6bf8d..26cd34b4 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -28,6 +28,7 @@ public class Config { public static float snowAirAbsorptionFactor; public static float underwaterFilter; public static boolean noteBlockEnable; + public static float maxDistance; // performance public static boolean skipRainOcclusionTracing; @@ -123,6 +124,8 @@ private void syncConfig() { "How much sound is filtered when the player is underwater. 0.0 means no filter. 1.0 means fully filtered."); noteBlockEnable = this.forgeConfig.getBoolean("Affect Note Blocks", categoryGeneral, true, "If true, note blocks will be processed."); + maxDistance = this.forgeConfig.getFloat("Max ray distance", categoryGeneral, 256.0f, 1.0f, 8192.0f, + "How far the rays should be traced."); // performance skipRainOcclusionTracing = this.forgeConfig.getBoolean("Skip Rain Occlusion Tracing", categoryPerformance, true, diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 154c1d0e..63404046 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -676,7 +676,7 @@ public void run() { // Shoot rays around sound final float phi = 1.618033988f; final float gAngle = phi * (float) Math.PI * 2.0f; - final float maxDistance = 256.0f; + final float maxDistance = Config.maxDistance; final int numRays = Config.environmentEvaluationRays; final int rayBounces = Config.environmentEvaluationRaysBounces; From 7d71747879d63b23b66820a8f0e8cfafab95fb71 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 20 Jun 2019 21:36:25 +0200 Subject: [PATCH 39/88] 1.0.7 Release Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- src/main/resources/mcmod.info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 63404046..f48c218c 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -51,7 +51,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; - public static final String version = "1.0.6"; + public static final String version = "1.0.7"; public static final String mcVersion = "1.12.2"; public static final String deps = "before:computronics"; // Dependencies to make sure that SP's config is loaded before patching Computronics diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 4e714701..194e7be1 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "soundphysics", "name": "Sound Physics", "description": "Provides realistic sound attenuation, reverberation, and absorption through blocks.", - "version": "1.0.6", + "version": "1.0.7", "mcversion": "1.12.2", "url": "https://github.com/djpadbit/Sound-Physics", "authorList": ["Sonic Ether","daipenger","djpadbit"] From 58e36ad4fddd3bc611db6656246748558e4a8b12 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 27 Jun 2019 05:05:10 +0200 Subject: [PATCH 40/88] Fix computronics sounds being muffled on server without sound physics Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index f48c218c..b8f43c64 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -364,7 +364,7 @@ public static void onPlaySound(final float posX, final float posY, final float p */ // For sounds that get played using OpenAL directly or just not using the minecraft sound system public static void onPlaySoundAL(final float posX, final float posY, final float posZ, final int sourceID) { - onPlaySound(posX, posY, posZ, sourceID, SoundCategory.MASTER, "null"); + onPlaySound(posX, posY, posZ, sourceID, SoundCategory.MASTER, "openal"); } /** @@ -541,7 +541,8 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, offsetY = 0.1; } - if (category == SoundCategory.BLOCKS || blockPattern.matcher(name).matches()) { + if (category == SoundCategory.BLOCKS || blockPattern.matcher(name).matches() || + (name == "openal" && !mc.world.isAirBlock(new BlockPos(soundX,soundY,soundZ)))) { // The ray will probably hit the block that it's emitting from // before // escaping. Offset the ray start position towards the player by the From 47e6e575cbf5e853c8094988a137cd928274c12f Mon Sep 17 00:00:00 2001 From: djpadbit Date: Tue, 9 Jul 2019 00:19:56 +0200 Subject: [PATCH 41/88] Fix footsteps on soulsand being muffled Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index b8f43c64..34d6a9f4 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -538,7 +538,7 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, double tempNormZ = 0; if (soundY % 1.0 < 0.001 || stepPattern.matcher(name).matches()) { - offsetY = 0.1; + offsetY = 0.1875; } if (category == SoundCategory.BLOCKS || blockPattern.matcher(name).matches() || From 86522e0ed82029b7cd0e67e0eecc6c3849233fdb Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 12 Jul 2019 17:41:03 +0200 Subject: [PATCH 42/88] Catch exceptions in environment evaluation. Because some mods don't raytrace correctly and it can sometimes crash the sound thread like Thermal Expansion's duct (but it's pretty rare). Signed-off-by: djpadbit --- .../sonicether/soundphysics/SoundPhysics.java | 434 +++++++++--------- 1 file changed, 220 insertions(+), 214 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 34d6a9f4..1cb8047d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -567,282 +567,288 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, @SuppressWarnings("deprecation") private static void evaluateEnvironment(final int sourceID, final float posX, final float posY, final float posZ, final SoundCategory category, final String name) { - if (mc.player == null | mc.world == null | posY <= 0 | category == SoundCategory.RECORDS - | category == SoundCategory.MUSIC) { - // posY <= 0 as a condition has to be there: Ingame - // menu clicks do have a player and world present - setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); - return; - } + try { + if (mc.player == null | mc.world == null | posY <= 0 | category == SoundCategory.RECORDS + | category == SoundCategory.MUSIC) { + // posY <= 0 as a condition has to be there: Ingame + // menu clicks do have a player and world present + setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + return; + } - final boolean isRain = rainPattern.matcher(name).matches(); + final boolean isRain = rainPattern.matcher(name).matches(); - if (Config.skipRainOcclusionTracing && isRain) { - setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); - return; - } + if (Config.skipRainOcclusionTracing && isRain) { + setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + return; + } - float directCutoff = 1.0f; - final float absorptionCoeff = Config.globalBlockAbsorption * 3.0f; + float directCutoff = 1.0f; + final float absorptionCoeff = Config.globalBlockAbsorption * 3.0f; - final Vec3d playerPos = new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ); - final Vec3d soundPos = offsetSoundByName(posX, posY, posZ, playerPos, name, category); - final Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize(); + final Vec3d playerPos = new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ); + final Vec3d soundPos = offsetSoundByName(posX, posY, posZ, playerPos, name, category); + final Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize(); - float snowFactor = 0.0f; + float snowFactor = 0.0f; - if (mc.world.isRaining()) { - final Vec3d middlePos = playerPos.add(soundPos).scale(0.5); - final BlockPos playerPosBlock = new BlockPos(playerPos); - final BlockPos soundPosBlock = new BlockPos(soundPos); - final BlockPos middlePosBlock = new BlockPos(middlePos); - final int snowingPlayer = isSnowingAt(playerPosBlock,false) ? 1 : 0; - final int snowingSound = isSnowingAt(soundPosBlock,false) ? 1 : 0; - final int snowingMiddle = isSnowingAt(middlePosBlock,false) ? 1 : 0; - snowFactor = snowingPlayer * 0.25f + snowingMiddle * 0.5f + snowingSound * 0.25f; - } + if (mc.world.isRaining()) { + final Vec3d middlePos = playerPos.add(soundPos).scale(0.5); + final BlockPos playerPosBlock = new BlockPos(playerPos); + final BlockPos soundPosBlock = new BlockPos(soundPos); + final BlockPos middlePosBlock = new BlockPos(middlePos); + final int snowingPlayer = isSnowingAt(playerPosBlock,false) ? 1 : 0; + final int snowingSound = isSnowingAt(soundPosBlock,false) ? 1 : 0; + final int snowingMiddle = isSnowingAt(middlePosBlock,false) ? 1 : 0; + snowFactor = snowingPlayer * 0.25f + snowingMiddle * 0.5f + snowingSound * 0.25f; + } - float airAbsorptionFactor = 1.0f; + float airAbsorptionFactor = 1.0f; - if (snowFactor > 0.0f) { - airAbsorptionFactor = Math.max(Config.snowAirAbsorptionFactor*mc.world.getRainStrength(1.0f)*snowFactor,airAbsorptionFactor); - } + if (snowFactor > 0.0f) { + airAbsorptionFactor = Math.max(Config.snowAirAbsorptionFactor*mc.world.getRainStrength(1.0f)*snowFactor,airAbsorptionFactor); + } - /*final double distance = playerPos.distanceTo(soundPos); - final double time = (distance/343.3)*1000; - AL10.alSourcePause(sourceID); - log("paused, time "+String.valueOf(time)); - - new java.util.Timer().schedule( - new java.util.TimerTask() { - @Override - public void run() { - log("play, time "+String.valueOf(time)); - AL10.alSourcePlay(sourceID); - } - }, - (long)time - );*/ + /*final double distance = playerPos.distanceTo(soundPos); + final double time = (distance/343.3)*1000; + AL10.alSourcePause(sourceID); + log("paused, time "+String.valueOf(time)); + + new java.util.Timer().schedule( + new java.util.TimerTask() { + @Override + public void run() { + log("play, time "+String.valueOf(time)); + AL10.alSourcePlay(sourceID); + } + }, + (long)time + );*/ - Vec3d rayOrigin = soundPos; + Vec3d rayOrigin = soundPos; - float occlusionAccumulation = 0.0f; + float occlusionAccumulation = 0.0f; - for (int i = 0; i < 10; i++) { - final RayTraceResult rayHit = mc.world.rayTraceBlocks(rayOrigin, playerPos, true); + for (int i = 0; i < 10; i++) { + final RayTraceResult rayHit = mc.world.rayTraceBlocks(rayOrigin, playerPos, true); - if (rayHit == null) { - break; - } + if (rayHit == null) { + break; + } - final Block blockHit = mc.world.getBlockState(rayHit.getBlockPos()).getBlock(); + final Block blockHit = mc.world.getBlockState(rayHit.getBlockPos()).getBlock(); - float blockOcclusion = 1.0f; + float blockOcclusion = 1.0f; - if (!blockHit.isOpaqueCube(blockHit.getDefaultState())) { - // log("not a solid block!"); - blockOcclusion *= 0.15f; - } + if (!blockHit.isOpaqueCube(blockHit.getDefaultState())) { + // log("not a solid block!"); + blockOcclusion *= 0.15f; + } - occlusionAccumulation += blockOcclusion; + occlusionAccumulation += blockOcclusion; - rayOrigin = new Vec3d(rayHit.hitVec.x + normalToPlayer.x * 0.1, rayHit.hitVec.y + normalToPlayer.y * 0.1, - rayHit.hitVec.z + normalToPlayer.z * 0.1); - } + rayOrigin = new Vec3d(rayHit.hitVec.x + normalToPlayer.x * 0.1, rayHit.hitVec.y + normalToPlayer.y * 0.1, + rayHit.hitVec.z + normalToPlayer.z * 0.1); + } - directCutoff = (float) Math.exp(-occlusionAccumulation * absorptionCoeff); - float directGain = (float) Math.pow(directCutoff, 0.1); + directCutoff = (float) Math.exp(-occlusionAccumulation * absorptionCoeff); + float directGain = (float) Math.pow(directCutoff, 0.1); - // Calculate reverb parameters for this sound - float sendGain0 = 0.0f; - float sendGain1 = 0.0f; - float sendGain2 = 0.0f; - float sendGain3 = 0.0f; + // Calculate reverb parameters for this sound + float sendGain0 = 0.0f; + float sendGain1 = 0.0f; + float sendGain2 = 0.0f; + float sendGain3 = 0.0f; - float sendCutoff0 = 1.0f; - float sendCutoff1 = 1.0f; - float sendCutoff2 = 1.0f; - float sendCutoff3 = 1.0f; + float sendCutoff0 = 1.0f; + float sendCutoff1 = 1.0f; + float sendCutoff2 = 1.0f; + float sendCutoff3 = 1.0f; - if (mc.player.isInsideOfMaterial(Material.WATER)) { - directCutoff *= 1.0f - Config.underwaterFilter; - } + if (mc.player.isInsideOfMaterial(Material.WATER)) { + directCutoff *= 1.0f - Config.underwaterFilter; + } - if (isRain) { - setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, - sendCutoff3, directCutoff, directGain, airAbsorptionFactor); - return; - } + if (isRain) { + setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, + sendCutoff3, directCutoff, directGain, airAbsorptionFactor); + return; + } - // Shoot rays around sound - final float phi = 1.618033988f; - final float gAngle = phi * (float) Math.PI * 2.0f; - final float maxDistance = Config.maxDistance; + // Shoot rays around sound + final float phi = 1.618033988f; + final float gAngle = phi * (float) Math.PI * 2.0f; + final float maxDistance = Config.maxDistance; - final int numRays = Config.environmentEvaluationRays; - final int rayBounces = Config.environmentEvaluationRaysBounces; + final int numRays = Config.environmentEvaluationRays; + final int rayBounces = Config.environmentEvaluationRaysBounces; - final float[] bounceReflectivityRatio = new float[rayBounces]; + final float[] bounceReflectivityRatio = new float[rayBounces]; - float sharedAirspace = 0.0f; + float sharedAirspace = 0.0f; - final float rcpTotalRays = 1.0f / (numRays * rayBounces); - final float rcpPrimaryRays = 1.0f / numRays; + final float rcpTotalRays = 1.0f / (numRays * rayBounces); + final float rcpPrimaryRays = 1.0f / numRays; - for (int i = 0; i < numRays; i++) { - final float fi = i; - final float fiN = fi / numRays; - final float longitude = gAngle * fi; - final float latitude = (float) Math.asin(fiN * 2.0f - 1.0f); + for (int i = 0; i < numRays; i++) { + final float fi = i; + final float fiN = fi / numRays; + final float longitude = gAngle * fi; + final float latitude = (float) Math.asin(fiN * 2.0f - 1.0f); - final Vec3d rayDir = new Vec3d(Math.cos(latitude) * Math.cos(longitude), - Math.cos(latitude) * Math.sin(longitude), Math.sin(latitude)); + final Vec3d rayDir = new Vec3d(Math.cos(latitude) * Math.cos(longitude), + Math.cos(latitude) * Math.sin(longitude), Math.sin(latitude)); - final Vec3d rayStart = new Vec3d(soundPos.x, soundPos.y, soundPos.z); + final Vec3d rayStart = new Vec3d(soundPos.x, soundPos.y, soundPos.z); - final Vec3d rayEnd = new Vec3d(rayStart.x + rayDir.x * maxDistance, rayStart.y + rayDir.y * maxDistance, - rayStart.z + rayDir.z * maxDistance); + final Vec3d rayEnd = new Vec3d(rayStart.x + rayDir.x * maxDistance, rayStart.y + rayDir.y * maxDistance, + rayStart.z + rayDir.z * maxDistance); - final RayTraceResult rayHit = mc.world.rayTraceBlocks(rayStart, rayEnd, true); + final RayTraceResult rayHit = mc.world.rayTraceBlocks(rayStart, rayEnd, true); - if (rayHit != null) { - final double rayLength = soundPos.distanceTo(rayHit.hitVec); + if (rayHit != null) { + final double rayLength = soundPos.distanceTo(rayHit.hitVec); - // Additional bounces - BlockPos lastHitBlock = rayHit.getBlockPos(); - Vec3d lastHitPos = rayHit.hitVec; - Vec3d lastHitNormal = getNormalFromFacing(rayHit.sideHit); - Vec3d lastRayDir = rayDir; + // Additional bounces + BlockPos lastHitBlock = rayHit.getBlockPos(); + Vec3d lastHitPos = rayHit.hitVec; + Vec3d lastHitNormal = getNormalFromFacing(rayHit.sideHit); + Vec3d lastRayDir = rayDir; - float totalRayDistance = (float) rayLength; + float totalRayDistance = (float) rayLength; - // Secondary ray bounces - for (int j = 0; j < rayBounces; j++) { - final Vec3d newRayDir = reflect(lastRayDir, lastHitNormal); - // Vec3d newRayDir = lastHitNormal; - final Vec3d newRayStart = new Vec3d(lastHitPos.x + lastHitNormal.x * 0.01, - lastHitPos.y + lastHitNormal.y * 0.01, lastHitPos.z + lastHitNormal.z * 0.01); - final Vec3d newRayEnd = new Vec3d(newRayStart.x + newRayDir.x * maxDistance, - newRayStart.y + newRayDir.y * maxDistance, newRayStart.z + newRayDir.z * maxDistance); + // Secondary ray bounces + for (int j = 0; j < rayBounces; j++) { + final Vec3d newRayDir = reflect(lastRayDir, lastHitNormal); + // Vec3d newRayDir = lastHitNormal; + final Vec3d newRayStart = new Vec3d(lastHitPos.x + lastHitNormal.x * 0.01, + lastHitPos.y + lastHitNormal.y * 0.01, lastHitPos.z + lastHitNormal.z * 0.01); + final Vec3d newRayEnd = new Vec3d(newRayStart.x + newRayDir.x * maxDistance, + newRayStart.y + newRayDir.y * maxDistance, newRayStart.z + newRayDir.z * maxDistance); - final RayTraceResult newRayHit = mc.world.rayTraceBlocks(newRayStart, newRayEnd, true); + final RayTraceResult newRayHit = mc.world.rayTraceBlocks(newRayStart, newRayEnd, true); - float energyTowardsPlayer = 0.25f; - final float blockReflectivity = getBlockReflectivity(lastHitBlock); - energyTowardsPlayer *= blockReflectivity * 0.75f + 0.25f; + float energyTowardsPlayer = 0.25f; + final float blockReflectivity = getBlockReflectivity(lastHitBlock); + energyTowardsPlayer *= blockReflectivity * 0.75f + 0.25f; - if (newRayHit == null) { - totalRayDistance += lastHitPos.distanceTo(playerPos); - } else { - final double newRayLength = lastHitPos.distanceTo(newRayHit.hitVec); + if (newRayHit == null) { + totalRayDistance += lastHitPos.distanceTo(playerPos); + } else { + final double newRayLength = lastHitPos.distanceTo(newRayHit.hitVec); - bounceReflectivityRatio[j] += blockReflectivity; + bounceReflectivityRatio[j] += blockReflectivity; - totalRayDistance += newRayLength; + totalRayDistance += newRayLength; - lastHitPos = newRayHit.hitVec; - lastHitNormal = getNormalFromFacing(newRayHit.sideHit); - lastRayDir = newRayDir; - lastHitBlock = newRayHit.getBlockPos(); + lastHitPos = newRayHit.hitVec; + lastHitNormal = getNormalFromFacing(newRayHit.sideHit); + lastRayDir = newRayDir; + lastHitBlock = newRayHit.getBlockPos(); - // Cast one final ray towards the player. If it's - // unobstructed, then the sound source and the player - // share airspace. - if (Config.simplerSharedAirspaceSimulation && j == rayBounces - 1 - || !Config.simplerSharedAirspaceSimulation) { - final Vec3d finalRayStart = new Vec3d(lastHitPos.x + lastHitNormal.x * 0.01, - lastHitPos.y + lastHitNormal.y * 0.01, lastHitPos.z + lastHitNormal.z * 0.01); + // Cast one final ray towards the player. If it's + // unobstructed, then the sound source and the player + // share airspace. + if (Config.simplerSharedAirspaceSimulation && j == rayBounces - 1 + || !Config.simplerSharedAirspaceSimulation) { + final Vec3d finalRayStart = new Vec3d(lastHitPos.x + lastHitNormal.x * 0.01, + lastHitPos.y + lastHitNormal.y * 0.01, lastHitPos.z + lastHitNormal.z * 0.01); - final RayTraceResult finalRayHit = mc.world.rayTraceBlocks(finalRayStart, playerPos, true); + final RayTraceResult finalRayHit = mc.world.rayTraceBlocks(finalRayStart, playerPos, true); - if (finalRayHit == null) { - // log("Secondary ray hit the player!"); - sharedAirspace += 1.0f; + if (finalRayHit == null) { + // log("Secondary ray hit the player!"); + sharedAirspace += 1.0f; + } } } - } - final float reflectionDelay = (float) Math.max(totalRayDistance, 0.0) * 0.12f * blockReflectivity; + final float reflectionDelay = (float) Math.max(totalRayDistance, 0.0) * 0.12f * blockReflectivity; - final float cross0 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 0.0f), 0.0f, 1.0f); - final float cross1 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 1.0f), 0.0f, 1.0f); - final float cross2 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 2.0f), 0.0f, 1.0f); - final float cross3 = MathHelper.clamp(reflectionDelay - 2.0f, 0.0f, 1.0f); + final float cross0 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 0.0f), 0.0f, 1.0f); + final float cross1 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 1.0f), 0.0f, 1.0f); + final float cross2 = 1.0f - MathHelper.clamp(Math.abs(reflectionDelay - 2.0f), 0.0f, 1.0f); + final float cross3 = MathHelper.clamp(reflectionDelay - 2.0f, 0.0f, 1.0f); - sendGain0 += cross0 * energyTowardsPlayer * 6.4f * rcpTotalRays; - sendGain1 += cross1 * energyTowardsPlayer * 12.8f * rcpTotalRays; - sendGain2 += cross2 * energyTowardsPlayer * 12.8f * rcpTotalRays; - sendGain3 += cross3 * energyTowardsPlayer * 12.8f * rcpTotalRays; + sendGain0 += cross0 * energyTowardsPlayer * 6.4f * rcpTotalRays; + sendGain1 += cross1 * energyTowardsPlayer * 12.8f * rcpTotalRays; + sendGain2 += cross2 * energyTowardsPlayer * 12.8f * rcpTotalRays; + sendGain3 += cross3 * energyTowardsPlayer * 12.8f * rcpTotalRays; - // Nowhere to bounce off of, stop bouncing! - if (newRayHit == null) { - break; + // Nowhere to bounce off of, stop bouncing! + if (newRayHit == null) { + break; + } } } + } - } + // log("total reflectivity ratio: " + totalReflectivityRatio); - // log("total reflectivity ratio: " + totalReflectivityRatio); + bounceReflectivityRatio[0] = bounceReflectivityRatio[0] / numRays; + bounceReflectivityRatio[1] = bounceReflectivityRatio[1] / numRays; + bounceReflectivityRatio[2] = bounceReflectivityRatio[2] / numRays; + bounceReflectivityRatio[3] = bounceReflectivityRatio[3] / numRays; - bounceReflectivityRatio[0] = bounceReflectivityRatio[0] / numRays; - bounceReflectivityRatio[1] = bounceReflectivityRatio[1] / numRays; - bounceReflectivityRatio[2] = bounceReflectivityRatio[2] / numRays; - bounceReflectivityRatio[3] = bounceReflectivityRatio[3] / numRays; + sharedAirspace *= 64.0f; - sharedAirspace *= 64.0f; + if (Config.simplerSharedAirspaceSimulation) { + sharedAirspace *= rcpPrimaryRays; + } else { + sharedAirspace *= rcpTotalRays; + } - if (Config.simplerSharedAirspaceSimulation) { - sharedAirspace *= rcpPrimaryRays; - } else { - sharedAirspace *= rcpTotalRays; - } + final float sharedAirspaceWeight0 = MathHelper.clamp(sharedAirspace / 20.0f, 0.0f, 1.0f); + final float sharedAirspaceWeight1 = MathHelper.clamp(sharedAirspace / 15.0f, 0.0f, 1.0f); + final float sharedAirspaceWeight2 = MathHelper.clamp(sharedAirspace / 10.0f, 0.0f, 1.0f); + final float sharedAirspaceWeight3 = MathHelper.clamp(sharedAirspace / 10.0f, 0.0f, 1.0f); + + sendCutoff0 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.0f) * (1.0f - sharedAirspaceWeight0) + + sharedAirspaceWeight0; + sendCutoff1 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.0f) * (1.0f - sharedAirspaceWeight1) + + sharedAirspaceWeight1; + sendCutoff2 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.5f) * (1.0f - sharedAirspaceWeight2) + + sharedAirspaceWeight2; + sendCutoff3 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.5f) * (1.0f - sharedAirspaceWeight3) + + sharedAirspaceWeight3; + + // attempt to preserve directionality when airspace is shared by + // allowing some of the dry signal through but filtered + final float averageSharedAirspace = (sharedAirspaceWeight0 + sharedAirspaceWeight1 + sharedAirspaceWeight2 + + sharedAirspaceWeight3) * 0.25f; + directCutoff = Math.max((float) Math.pow(averageSharedAirspace, 0.5) * 0.2f, directCutoff); + + directGain = (float) Math.pow(directCutoff, 0.1); + + sendGain1 *= bounceReflectivityRatio[1]; + sendGain2 *= (float) Math.pow(bounceReflectivityRatio[2], 3.0); + sendGain3 *= (float) Math.pow(bounceReflectivityRatio[3], 4.0); + + sendGain0 = MathHelper.clamp(sendGain0, 0.0f, 1.0f); + sendGain1 = MathHelper.clamp(sendGain1, 0.0f, 1.0f); + sendGain2 = MathHelper.clamp(sendGain2 * 1.05f - 0.05f, 0.0f, 1.0f); + sendGain3 = MathHelper.clamp(sendGain3 * 1.05f - 0.05f, 0.0f, 1.0f); + + sendGain0 *= (float) Math.pow(sendCutoff0, 0.1); + sendGain1 *= (float) Math.pow(sendCutoff1, 0.1); + sendGain2 *= (float) Math.pow(sendCutoff2, 0.1); + sendGain3 *= (float) Math.pow(sendCutoff3, 0.1); + + if (mc.player.isInWater()) { + sendCutoff0 *= 0.4f; + sendCutoff1 *= 0.4f; + sendCutoff2 *= 0.4f; + sendCutoff3 *= 0.4f; + } - final float sharedAirspaceWeight0 = MathHelper.clamp(sharedAirspace / 20.0f, 0.0f, 1.0f); - final float sharedAirspaceWeight1 = MathHelper.clamp(sharedAirspace / 15.0f, 0.0f, 1.0f); - final float sharedAirspaceWeight2 = MathHelper.clamp(sharedAirspace / 10.0f, 0.0f, 1.0f); - final float sharedAirspaceWeight3 = MathHelper.clamp(sharedAirspace / 10.0f, 0.0f, 1.0f); - - sendCutoff0 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.0f) * (1.0f - sharedAirspaceWeight0) - + sharedAirspaceWeight0; - sendCutoff1 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.0f) * (1.0f - sharedAirspaceWeight1) - + sharedAirspaceWeight1; - sendCutoff2 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.5f) * (1.0f - sharedAirspaceWeight2) - + sharedAirspaceWeight2; - sendCutoff3 = (float) Math.exp(-occlusionAccumulation * absorptionCoeff * 1.5f) * (1.0f - sharedAirspaceWeight3) - + sharedAirspaceWeight3; - - // attempt to preserve directionality when airspace is shared by - // allowing some of the dry signal through but filtered - final float averageSharedAirspace = (sharedAirspaceWeight0 + sharedAirspaceWeight1 + sharedAirspaceWeight2 - + sharedAirspaceWeight3) * 0.25f; - directCutoff = Math.max((float) Math.pow(averageSharedAirspace, 0.5) * 0.2f, directCutoff); - - directGain = (float) Math.pow(directCutoff, 0.1); - - sendGain1 *= bounceReflectivityRatio[1]; - sendGain2 *= (float) Math.pow(bounceReflectivityRatio[2], 3.0); - sendGain3 *= (float) Math.pow(bounceReflectivityRatio[3], 4.0); - - sendGain0 = MathHelper.clamp(sendGain0, 0.0f, 1.0f); - sendGain1 = MathHelper.clamp(sendGain1, 0.0f, 1.0f); - sendGain2 = MathHelper.clamp(sendGain2 * 1.05f - 0.05f, 0.0f, 1.0f); - sendGain3 = MathHelper.clamp(sendGain3 * 1.05f - 0.05f, 0.0f, 1.0f); - - sendGain0 *= (float) Math.pow(sendCutoff0, 0.1); - sendGain1 *= (float) Math.pow(sendCutoff1, 0.1); - sendGain2 *= (float) Math.pow(sendCutoff2, 0.1); - sendGain3 *= (float) Math.pow(sendCutoff3, 0.1); - - if (mc.player.isInWater()) { - sendCutoff0 *= 0.4f; - sendCutoff1 *= 0.4f; - sendCutoff2 *= 0.4f; - sendCutoff3 *= 0.4f; + setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, + sendCutoff3, directCutoff, directGain, airAbsorptionFactor); + } catch(Exception e) { + logError("Error while evaluation environment:"); + e.printStackTrace(); + setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); } - - setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, - sendCutoff3, directCutoff, directGain, airAbsorptionFactor); } private static void setEnvironment(final int sourceID, final float sendGain0, final float sendGain1, From 2087d31d58f6fad39aa3c177c7915e6a0c984143 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 12 Jul 2019 21:40:54 +0200 Subject: [PATCH 43/88] WIP Immersive Railroading compatibility Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 3 ++ .../soundphysics/CoreModInjector.java | 42 +++++++++++++++++++ .../sonicether/soundphysics/SoundPhysics.java | 12 +++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 26cd34b4..92e96af5 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -51,6 +51,7 @@ public class Config { // compatibility public static boolean computronicsPatching; + public static boolean irPatching; public static boolean autoSteroDownmix; // misc @@ -167,6 +168,8 @@ private void syncConfig() { // compatibility computronicsPatching = this.forgeConfig.getBoolean("Patch Computronics", categoryCompatibility, true, "MAY REQUIRE RESTART.If true, patches the computronics sound sources so it works with sound physics."); + irPatching = this.forgeConfig.getBoolean("Patch Immersive Railroading", categoryCompatibility, true, + "MAY REQUIRE RESTART.If true, patches the immersive railroading sound sources so it works with sound physics."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto stereo downmix", categoryCompatibility, true, "MAY REQUIRE RESTART.If true, Automatically downmix stereo sounds that are loaded to mono"); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index fdb74f64..95a5851b 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -289,6 +289,48 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: getSoundPos bytes = patchMethodInClass(obfuscated, bytes, "getSoundPos", "()Lnet/minecraft/util/math/Vec3d;", Opcodes.ARETURN, AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); + } else + + if (obfuscated.equals("cam72cam.immersiverailroading.sound.ClientSound") && Config.irPatching) { + // Inside ClientSound + InsnList toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "qg","i", "Lqg;")); // Ambient sound category + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "setLastSoundCategory", "(Lqg;)V", false)); + /*toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "resource", + "Ljava/net/URL;"));*/ + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "oggLocation", + "Lnf;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "nf", "toString", "()Ljava/lang/String;", false)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "setLastSoundName", "(Ljava/lang/String;)V", false)); + + // Target method: play + bytes = patchMethodInClass(obfuscated, bytes, "play", "(Lnet/minecraft/util/math/Vec3d;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "update", null, -1, toInject, false, 0, 0, false, 0); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new InsnNode(Opcodes.DMUL)); + + // Target method: play + bytes = patchMethodInClass(obfuscated, bytes, "play", "(Lnet/minecraft/util/math/Vec3d;)V", Opcodes.DCMPG, + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier", "F")); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: update + bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESTATIC, + AbstractInsnNode.METHOD_INSN, "getDampeningAmount", null, -1, toInject, true, 0, 0, false, 0); } //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 1cb8047d..2b6a072c 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -1,5 +1,6 @@ package com.sonicether.soundphysics; +import java.net.URL; import java.util.regex.Pattern; import java.util.List; import java.util.ArrayList; @@ -53,7 +54,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; public static final String version = "1.0.7"; public static final String mcVersion = "1.12.2"; - public static final String deps = "before:computronics"; // Dependencies to make sure that SP's config is loaded before patching Computronics + public static final String deps = "before:computronics;before:immersiverailroading"; // Dependencies to make sure that SP's config is loaded before patching mods public static boolean onServer = false; @@ -351,6 +352,13 @@ public static void setLastSoundName(final String soundName, final String eventNa lastSoundName = eventName+"|"+soundName.split(":")[1]; // Quick and dirty hack to check the event and sound name } + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void setLastSoundName(final String soundName) { + lastSoundName = soundName; + } + /** * CALLED BY ASM INJECTED CODE! */ @@ -371,7 +379,7 @@ public static void onPlaySoundAL(final float posX, final float posY, final float * CALLED BY ASM INJECTED CODE! */ public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName) { - //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); + log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); if (Config.noteBlockEnable && soundCat == SoundCategory.RECORDS && noteBlockPattern.matcher(soundName).matches()) soundCat = SoundCategory.BLOCKS; evaluateEnvironment(sourceID, posX, posY, posZ,soundCat,soundName); if (!Config.dynamicEnvironementEvalutaion) return; From aa939875df2124ac6358ac7393cb47802aa5a8b7 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 12 Jul 2019 22:21:27 +0200 Subject: [PATCH 44/88] Use the logger instead of stdout Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/CoreModInjector.java | 9 ++++++--- .../java/com/sonicether/soundphysics/SoundPhysics.java | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 95a5851b..c4a2914a 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -15,11 +15,14 @@ import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.VarInsnNode; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + import net.minecraft.launchwrapper.IClassTransformer; public class CoreModInjector implements IClassTransformer { - private static final String logPrefix = "[SOUND PHYSICS INJECTOR]"; + public static final Logger logger = LogManager.getLogger(SoundPhysics.modid+"injector"); @Override public byte[] transform(final String obfuscated, final String deobfuscated, byte[] bytes) { @@ -450,10 +453,10 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St } public static void log(final String message) { - if (Config.injectorLogging) System.out.println(logPrefix.concat(" : ").concat(message)); + if (Config.injectorLogging) logger.info(message); } public static void logError(final String errorMessage) { - System.out.println(logPrefix.concat(" [ERROR] : ").concat(errorMessage)); + logger.error(errorMessage); } } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 2b6a072c..e1a8d964 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -45,6 +45,9 @@ import java.util.Timer; import java.util.TimerTask; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + import org.apache.commons.lang3.reflect.FieldUtils; @Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory", @@ -56,6 +59,8 @@ public class SoundPhysics { public static final String mcVersion = "1.12.2"; public static final String deps = "before:computronics;before:immersiverailroading"; // Dependencies to make sure that SP's config is loaded before patching mods + public static final Logger logger = LogManager.getLogger(modid); + public static boolean onServer = false; private static final Pattern rainPattern = Pattern.compile(".*rain.*"); @@ -75,7 +80,6 @@ public void init(final FMLInitializationEvent event) { Config.instance.init(event); } - private static final String logPrefix = "[SOUND PHYSICS]"; private static int auxFXSlot0; private static int auxFXSlot1; private static int auxFXSlot2; @@ -931,11 +935,11 @@ protected static void setReverbParams(final ReverbParams r, final int auxFXSlot, } public static void log(final String message) { - System.out.println(logPrefix.concat(" : ").concat(message)); + logger.info(message); } public static void logError(final String errorMessage) { - System.out.println(logPrefix.concat(" [ERROR] : ").concat(errorMessage)); + logger.error(errorMessage); } protected static boolean checkErrorLog(final String errorMessage) { From 6922bc8f73235630784f3519643310ceee51d211 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 13 Jul 2019 00:44:02 +0200 Subject: [PATCH 45/88] Added but commented out position shift for IR compat Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 18 +++++++++++++++--- .../sonicether/soundphysics/SoundPhysics.java | 1 - 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index c4a2914a..90d7057f 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -14,6 +14,7 @@ import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.VarInsnNode; +import org.objectweb.asm.tree.LdcInsnNode; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -301,9 +302,6 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "qg","i", "Lqg;")); // Ambient sound category toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "setLastSoundCategory", "(Lqg;)V", false)); - /*toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "resource", - "Ljava/net/URL;"));*/ toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "oggLocation", "Lnf;")); @@ -334,6 +332,20 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: update bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESTATIC, AbstractInsnNode.METHOD_INSN, "getDampeningAmount", null, -1, toInject, true, 0, 0, false, 0); + + /*toInject = new InsnList(); + + toInject.add(new LdcInsnNode(1.75d)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "gauge", + "Lcam72cam/immersiverailroading/library/Gauge;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "cam72cam/immersiverailroading/library/Gauge", "scale", "()D", false)); + toInject.add(new InsnNode(Opcodes.DMUL)); + toInject.add(new InsnNode(Opcodes.DADD)); + + // Target method: update + bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESPECIAL, + AbstractInsnNode.METHOD_INSN, "", "(ILjava/lang/String;FFF)V", -1, toInject, true, 0, 0, false, -5);*/ } //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index e1a8d964..f0e43b0d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -1,6 +1,5 @@ package com.sonicether.soundphysics; -import java.net.URL; import java.util.regex.Pattern; import java.util.List; import java.util.ArrayList; From 4ac40a7be21ddf57a48bde078d73a1c1506d6fa3 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 13 Jul 2019 00:46:42 +0200 Subject: [PATCH 46/88] Removed debugging Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index f0e43b0d..8b7a89b3 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -382,7 +382,7 @@ public static void onPlaySoundAL(final float posX, final float posY, final float * CALLED BY ASM INJECTED CODE! */ public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName) { - log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); + //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); if (Config.noteBlockEnable && soundCat == SoundCategory.RECORDS && noteBlockPattern.matcher(soundName).matches()) soundCat = SoundCategory.BLOCKS; evaluateEnvironment(sourceID, posX, posY, posZ,soundCat,soundName); if (!Config.dynamicEnvironementEvalutaion) return; From afaf3b5b19ca123516c43b50efb22e7358fce858 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 13 Jul 2019 01:10:45 +0200 Subject: [PATCH 47/88] Updated README Signed-off-by: djpadbit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index caf95276..b2dc6206 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,6 @@ This is a fork of a fork! I forked it from daipenger who forked it from soniceth The stuff added in this fork: * Dynamic environement evaluation (disabled by default, enable in mod config ingame) * Automatic stero to mono downmixing of sounds -* More compatibillity with mods (for now only computronics) +* More compatibillity with mods (Computronics & Immersive Railroading) And that's pretty much it. yeah that's not a lot. From 9eeae2979215079303fb0b9962614fa52c38c23b Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 20 Jul 2019 23:28:43 +0200 Subject: [PATCH 48/88] Remove ray bounce config as it is useless Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/Config.java | 4 ---- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 92e96af5..dbb85359 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -33,7 +33,6 @@ public class Config { // performance public static boolean skipRainOcclusionTracing; public static int environmentEvaluationRays; - public static int environmentEvaluationRaysBounces; public static boolean simplerSharedAirspaceSimulation; public static boolean dynamicEnvironementEvalutaion; public static int dynamicEnvironementEvalutaionFrequency; @@ -134,9 +133,6 @@ private void syncConfig() { environmentEvaluationRays = this.forgeConfig.getInt("Environment Evaluation Rays", categoryPerformance, 32, 8, 64, "The number of rays to trace to determine reverberation for each sound source. More rays provides more consistent tracing results but takes more time to calculate. Decrease this value if you experience lag spikes when sounds play."); - environmentEvaluationRaysBounces = this.forgeConfig.getInt("Environment Evaluation Rays Bounces", categoryPerformance, 4, 1, - 64, - "The number of rays bounces to determine reverberation for each sound source. More bounces provides more consistent tracing results but takes more time to calculate. Decrease this value if you experience lag spikes when sounds play."); simplerSharedAirspaceSimulation = this.forgeConfig.getBoolean("Simpler Shared Airspace Simulation", categoryPerformance, false, "If true, enables a simpler technique for determining when the player and a sound source share airspace. Might sometimes miss recognizing shared airspace, but it's faster to calculate."); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 8b7a89b3..1b5f88ae 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -692,7 +692,7 @@ public void run() { final float maxDistance = Config.maxDistance; final int numRays = Config.environmentEvaluationRays; - final int rayBounces = Config.environmentEvaluationRaysBounces; + final int rayBounces = 4; final float[] bounceReflectivityRatio = new float[rayBounces]; From b15efd5e800dc149ae7ca063288ce98fce3996cb Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 25 Jul 2019 22:13:50 +0200 Subject: [PATCH 49/88] Updated gradle and added access transformer Signed-off-by: djpadbit --- build.gradle | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- .../sonicether/soundphysics/SoundPhysics.java | 16 +--------------- src/main/resources/META-INF/soundphysics_at.cfg | 1 + 4 files changed, 4 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/META-INF/soundphysics_at.cfg diff --git a/build.gradle b/build.gradle index 2dec2ad9..69536762 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ jar { manifest { attributes 'FMLCorePlugin': 'com.sonicether.soundphysics.CoreModLoader' attributes 'FMLCorePluginContainsFMLMod': 'true' + attributes 'FMLAT': 'soundphysics_at.cfg' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e18cba72..af38095b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip \ No newline at end of file diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 1b5f88ae..259eda97 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -47,8 +47,6 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; -import org.apache.commons.lang3.reflect.FieldUtils; - @Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory", dependencies = SoundPhysics.deps) public class SoundPhysics { @@ -430,19 +428,7 @@ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { * CALLED BY ASM INJECTED CODE! */ public static double calculateEntitySoundOffset(final Entity entity, final SoundEvent sound) { - String soundPath = ""; - // getSoundName() isn't on the server side, and soundName is private - if (!onServer) { - soundPath = sound.getSoundName().getPath(); - } else { - try { // field_187506_b = soundName - ResourceLocation rl = (ResourceLocation)FieldUtils.readField(sound, "field_187506_b", true); - soundPath = rl.getPath(); - } catch (Exception e) { - logError(e.toString()); - } - } - if (stepPattern.matcher(soundPath).matches()) { + if (stepPattern.matcher(sound.soundName.getPath()).matches()) { return 0; } diff --git a/src/main/resources/META-INF/soundphysics_at.cfg b/src/main/resources/META-INF/soundphysics_at.cfg new file mode 100644 index 00000000..3d5e5a73 --- /dev/null +++ b/src/main/resources/META-INF/soundphysics_at.cfg @@ -0,0 +1 @@ +public net.minecraft.util.SoundEvent field_187506_b # soundName \ No newline at end of file From 1a168953c86bf0da6d986c6e051e3b9966d0a3a1 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 25 Jul 2019 23:12:14 +0200 Subject: [PATCH 50/88] Fix client mod rejection Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 1 - .../java/com/sonicether/soundphysics/SoundPhysicsServer.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 259eda97..629a25b4 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -25,7 +25,6 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java b/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java index fd36820f..9a5d3172 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java @@ -5,8 +5,8 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; //Server side mod to load the config -@Mod(modid = SoundPhysics.modid, serverSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory", - dependencies = SoundPhysics.deps) +@Mod(modid = SoundPhysics.modid, serverSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, acceptableRemoteVersions = "*", + guiFactory = "com.sonicether.soundphysics.SPGuiFactory", dependencies = SoundPhysics.deps) public class SoundPhysicsServer { @Mod.EventHandler public void preInit(final FMLPreInitializationEvent event) { From 8d403fb45032dd7093ec057763f590472fa3df51 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 26 Jul 2019 01:13:49 +0200 Subject: [PATCH 51/88] Updated README Signed-off-by: djpadbit --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b2dc6206..ee40660e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,16 @@ # Sound-Physics A Minecraft mod that provides realistic sound attenuation, reverberation, and absorption through blocks. -This is a fork of a fork! I forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and updated the mod, i just added some stuff. +Downloads are in the [releases tab](https://github.com/djpadbit/Sound-Physics/releases) + +This is a fork of a fork! I forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and cleaned up the codebase, i just added some stuff. The stuff added in this fork: * Dynamic environement evaluation (disabled by default, enable in mod config ingame) -* Automatic stero to mono downmixing of sounds -* More compatibillity with mods (Computronics & Immersive Railroading) +* Automatic stero to mono downmixing of sounds (So the original resourcepack is not needed anymore) +* More compatibility with mods (Computronics & Immersive Railroading) +* Server support (right position for entity and computronics sounds and higher distance before sound cutoff) -And that's pretty much it. yeah that's not a lot. +Todo: +* Rewrite/cleanup Dynamic environement evaluation +* More mod compatibility ? I'm open to suggestions \ No newline at end of file From 4808bd2ea8308607073b7f956de5f5d65a32cd1d Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 26 Jul 2019 01:19:14 +0200 Subject: [PATCH 52/88] Made it a bit clearer Signed-off-by: djpadbit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ee40660e..2f2585ff 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The stuff added in this fork: * Dynamic environement evaluation (disabled by default, enable in mod config ingame) * Automatic stero to mono downmixing of sounds (So the original resourcepack is not needed anymore) * More compatibility with mods (Computronics & Immersive Railroading) -* Server support (right position for entity and computronics sounds and higher distance before sound cutoff) +* Server-side support (right position for entity and computronics sounds and higher distance before sound cutoff) Todo: * Rewrite/cleanup Dynamic environement evaluation From a7b372567991344c6832e5328495f888cf6e8620 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 27 Jul 2019 22:42:53 +0200 Subject: [PATCH 53/88] Added doppler effect Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 9 ++- .../soundphysics/CoreModInjector.java | 56 ++++++++++++++++++- .../sonicether/soundphysics/SoundPhysics.java | 39 +++++++++++-- 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index dbb85359..76968336 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -29,6 +29,7 @@ public class Config { public static float underwaterFilter; public static boolean noteBlockEnable; public static float maxDistance; + public static boolean dopplerEnabled; // performance public static boolean skipRainOcclusionTracing; @@ -126,6 +127,8 @@ private void syncConfig() { "If true, note blocks will be processed."); maxDistance = this.forgeConfig.getFloat("Max ray distance", categoryGeneral, 256.0f, 1.0f, 8192.0f, "How far the rays should be traced."); + dopplerEnabled = this.forgeConfig.getBoolean("Enable doppler effect", categoryGeneral, true, + "REQUIRES RESTART. If true, the doppler effect will be enabled."); // performance skipRainOcclusionTracing = this.forgeConfig.getBoolean("Skip Rain Occlusion Tracing", categoryPerformance, true, @@ -163,11 +166,11 @@ private void syncConfig() { // compatibility computronicsPatching = this.forgeConfig.getBoolean("Patch Computronics", categoryCompatibility, true, - "MAY REQUIRE RESTART.If true, patches the computronics sound sources so it works with sound physics."); + "REQUIRES RESTART. If true, patches the computronics sound sources so it works with sound physics."); irPatching = this.forgeConfig.getBoolean("Patch Immersive Railroading", categoryCompatibility, true, - "MAY REQUIRE RESTART.If true, patches the immersive railroading sound sources so it works with sound physics."); + "REQUIRES RESTART. If true, patches the immersive railroading sound sources so it works with sound physics."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto stereo downmix", categoryCompatibility, true, - "MAY REQUIRE RESTART.If true, Automatically downmix stereo sounds that are loaded to mono"); + "REQUIRES RESTART. If true, Automatically downmix stereo sounds that are loaded to mono"); // misc autoSteroDownmixLogging = this.forgeConfig.getBoolean("Stereo downmix Logging", categoryMisc, false, diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 90d7057f..8c293811 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -3,6 +3,9 @@ import java.util.Iterator; import java.util.ListIterator; +import java.io.StringWriter; +import java.io.PrintWriter; + import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; @@ -16,6 +19,10 @@ import org.objectweb.asm.tree.VarInsnNode; import org.objectweb.asm.tree.LdcInsnNode; +import org.objectweb.asm.util.TraceMethodVisitor; +import org.objectweb.asm.util.Printer; +import org.objectweb.asm.util.Textifier; + import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -30,8 +37,9 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte if (obfuscated.equals("chm$a")) { // Inside SoundManager.SoundSystemStarterThread InsnList toInject = new InsnList(); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "init", - "()V", false)); + "(Lpaulscode/sound/SoundSystem;)V", false)); // Target method: Constructor bytes = patchMethodInClass(obfuscated, bytes, "", "(Lchm;)V", Opcodes.INVOKESPECIAL, @@ -70,6 +78,16 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound, target invocation getClampedVolume bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKESPECIAL, AbstractInsnNode.METHOD_INSN, "e", "(Lcgt;)F", -1, toInject, false, 0, 0, false, 0); + + toInject = new InsnList(); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 2)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "onSetListener", "(Lvg;F)V", false)); + + // This function has been added by forge so the name isn't obfuscated + bytes = patchMethodInClass(obfuscated, bytes, "setListener", "(Lvg;F)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setListenerOrientation", null, -1, toInject, false, 0, 0, false, 0); } else if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL")) { @@ -346,6 +364,28 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: update bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESPECIAL, AbstractInsnNode.METHOD_INSN, "", "(ILjava/lang/String;FFF)V", -1, toInject, true, 0, 0, false, -5);*/ + + if (Config.dopplerEnabled) { // IR has its own doppler shift so we remove that and just give the velocity to OpenAL so that it does it itself. + toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "velocity", + "Lbhe;")); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "id", + "Ljava/lang/String;")); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "currentPitch", + "F")); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 2)); + toInject.add(new InsnNode(Opcodes.FDIV)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "onIRUpdate", "(Lbhe;Ljava/lang/String;F)V", false)); + + // Target method: update + bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "CommandQueue", null, -1, toInject, false, 108, 1, true, 0); + } } //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); @@ -353,6 +393,17 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte return bytes; } + private static Printer printer = new Textifier(); + private static TraceMethodVisitor mp = new TraceMethodVisitor(printer); + + public static String insnToString(AbstractInsnNode insn){ + insn.accept(mp); + StringWriter sw = new StringWriter(); + printer.print(new PrintWriter(sw)); + printer.getText().clear(); + return sw.toString(); + } + private byte[] patchMethodInClass(String className, final byte[] bytes, final String targetMethod, final String targetMethodSignature, final int targetNodeOpcode, final int targetNodeType, final String targetInvocationMethodName, final String targetInvocationMethodSignature, final int targetVarNodeIndex, @@ -377,6 +428,7 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St final ListIterator nodeIterator = m.instructions.iterator(); while (nodeIterator.hasNext()) { AbstractInsnNode currentNode = nodeIterator.next(); + //log(insnToString(currentNode).replace("\n", "")); if (currentNode.getOpcode() == targetNodeOpcode) { if (targetNodeType == AbstractInsnNode.METHOD_INSN) { @@ -434,12 +486,14 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St // If we've found the target, inject the instructions! for (int i = 0; i < nodesToDeleteBefore; i++) { final AbstractInsnNode previousNode = targetNode.getPrevious(); + //log("Removing Node " + insnToString(previousNode).replace("\n", "")); log("Removing Node " + previousNode.getOpcode()); m.instructions.remove(previousNode); } for (int i = 0; i < nodesToDeleteAfter; i++) { final AbstractInsnNode nextNode = targetNode.getNext(); + //log("Removing Node " + insnToString(nextNode).replace("\n", "")); log("Removing Node " + nextNode.getOpcode()); m.instructions.remove(nextNode); } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 629a25b4..9c45564d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -36,6 +36,8 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent.Text; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import paulscode.sound.SoundSystemConfig; +import paulscode.sound.SoundSystem; +import paulscode.sound.CommandObject; import paulscode.sound.SoundBuffer; import javax.sound.sampled.AudioFormat; import java.nio.ByteBuffer; @@ -91,6 +93,7 @@ public void init(final FMLInitializationEvent event) { private static int sendFilter3; private static Minecraft mc; + private static SoundSystem sndSystem; private static SoundCategory lastSoundCategory; private static String lastSoundName; @@ -111,10 +114,14 @@ public void init(final FMLInitializationEvent event) { /** * CALLED BY ASM INJECTED CODE! */ - public static void init() { + public static void init(SoundSystem snds) { mc = Minecraft.getMinecraft(); - // I could check if the sound system loaded correctly but that's long and anoying + sndSystem = snds; try { + if (Config.dopplerEnabled) { + sndSystem.changeDopplerFactor(1.0f); + AL11.alSpeedOfSound(343.3f); // Should already be 343.3 but just in case + } setupEFX(); setupThread(); } catch (Throwable e) { @@ -434,14 +441,38 @@ public static double calculateEntitySoundOffset(final Entity entity, final Sound return entity.getEyeHeight(); } - public static Vec3d computronicsOffset(Vec3d or, TileEntity te, PropertyDirection pd) - { + /** + * CALLED BY ASM INJECTED CODE! + */ + public static Vec3d computronicsOffset(Vec3d or, TileEntity te, PropertyDirection pd) { if (!te.hasWorld()) return or; EnumFacing ef = te.getWorld().getBlockState(te.getPos()).getValue(pd); Vec3d efv = getNormalFromFacing(ef).scale(0.51); return or.add(efv); } + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void onSetListener(Entity player, float partial_tick) { + float motionX = (float)((player.posX - player.prevPosX) * 20.0d); + float motionY = (float)((player.posY - player.prevPosY) * 20.0d); + float motionZ = (float)((player.posZ - player.prevPosZ) * 20.0d); + sndSystem.setListenerVelocity(motionX,motionY,motionZ); + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static void onIRUpdate(Vec3d velocity, String source, float pitch) { + float motionX = (float)(velocity.x * 20.0d); + float motionY = (float)(velocity.y * 20.0d); + float motionZ = (float)(velocity.z * 20.0d); + sndSystem.CommandQueue(new CommandObject(CommandObject.SET_VELOCITY, source, motionX, motionY, motionZ)); + sndSystem.CommandQueue(new CommandObject(CommandObject.SET_PITCH, source, pitch)); + } + + // Unused private static boolean isSnowingAt(BlockPos position) { From ce62c61e5d284061af0f43770ddbc84d39482b34 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 28 Jul 2019 23:44:32 +0200 Subject: [PATCH 54/88] Commented out doppler effect because it sounds weird. Signed-off-by: djpadbit --- .../java/com/sonicether/soundphysics/Config.java | 6 +++--- .../com/sonicether/soundphysics/CoreModInjector.java | 8 ++++---- .../com/sonicether/soundphysics/SoundPhysics.java | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 76968336..de84772f 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -29,7 +29,7 @@ public class Config { public static float underwaterFilter; public static boolean noteBlockEnable; public static float maxDistance; - public static boolean dopplerEnabled; + //public static boolean dopplerEnabled; // performance public static boolean skipRainOcclusionTracing; @@ -127,8 +127,8 @@ private void syncConfig() { "If true, note blocks will be processed."); maxDistance = this.forgeConfig.getFloat("Max ray distance", categoryGeneral, 256.0f, 1.0f, 8192.0f, "How far the rays should be traced."); - dopplerEnabled = this.forgeConfig.getBoolean("Enable doppler effect", categoryGeneral, true, - "REQUIRES RESTART. If true, the doppler effect will be enabled."); + /*dopplerEnabled = this.forgeConfig.getBoolean("Enable doppler effect", categoryGeneral, true, + "REQUIRES RESTART. If true, the doppler effect will be enabled.");*/ // performance skipRainOcclusionTracing = this.forgeConfig.getBoolean("Skip Rain Occlusion Tracing", categoryPerformance, true, diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 8c293811..42cc0619 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -79,7 +79,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKESPECIAL, AbstractInsnNode.METHOD_INSN, "e", "(Lcgt;)F", -1, toInject, false, 0, 0, false, 0); - toInject = new InsnList(); + /*toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); toInject.add(new VarInsnNode(Opcodes.FLOAD, 2)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", @@ -87,7 +87,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // This function has been added by forge so the name isn't obfuscated bytes = patchMethodInClass(obfuscated, bytes, "setListener", "(Lvg;F)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setListenerOrientation", null, -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "setListenerOrientation", null, -1, toInject, false, 0, 0, false, 0);*/ } else if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL")) { @@ -365,7 +365,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESPECIAL, AbstractInsnNode.METHOD_INSN, "", "(ILjava/lang/String;FFF)V", -1, toInject, true, 0, 0, false, -5);*/ - if (Config.dopplerEnabled) { // IR has its own doppler shift so we remove that and just give the velocity to OpenAL so that it does it itself. + /*if (Config.dopplerEnabled) { // IR has its own doppler shift so we remove that and just give the velocity to OpenAL so that it does it itself. toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); @@ -385,7 +385,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: update bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKEVIRTUAL, AbstractInsnNode.METHOD_INSN, "CommandQueue", null, -1, toInject, false, 108, 1, true, 0); - } + }*/ } //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 9c45564d..a8029058 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -118,10 +118,10 @@ public static void init(SoundSystem snds) { mc = Minecraft.getMinecraft(); sndSystem = snds; try { - if (Config.dopplerEnabled) { + /*if (Config.dopplerEnabled) { sndSystem.changeDopplerFactor(1.0f); AL11.alSpeedOfSound(343.3f); // Should already be 343.3 but just in case - } + }*/ setupEFX(); setupThread(); } catch (Throwable e) { @@ -454,23 +454,23 @@ public static Vec3d computronicsOffset(Vec3d or, TileEntity te, PropertyDirectio /** * CALLED BY ASM INJECTED CODE! */ - public static void onSetListener(Entity player, float partial_tick) { + /*public static void onSetListener(Entity player, float partial_tick) { float motionX = (float)((player.posX - player.prevPosX) * 20.0d); float motionY = (float)((player.posY - player.prevPosY) * 20.0d); float motionZ = (float)((player.posZ - player.prevPosZ) * 20.0d); sndSystem.setListenerVelocity(motionX,motionY,motionZ); - } + }*/ /** * CALLED BY ASM INJECTED CODE! */ - public static void onIRUpdate(Vec3d velocity, String source, float pitch) { + /*public static void onIRUpdate(Vec3d velocity, String source, float pitch) { float motionX = (float)(velocity.x * 20.0d); float motionY = (float)(velocity.y * 20.0d); float motionZ = (float)(velocity.z * 20.0d); sndSystem.CommandQueue(new CommandObject(CommandObject.SET_VELOCITY, source, motionX, motionY, motionZ)); sndSystem.CommandQueue(new CommandObject(CommandObject.SET_PITCH, source, pitch)); - } + }*/ // Unused From 82031bfff2f5f5855679e7ae42b46ac8d7f5b724 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Tue, 30 Jul 2019 20:45:01 +0200 Subject: [PATCH 55/88] Check if sound is null before trying to get the name Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index a8029058..b694158d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -434,6 +434,7 @@ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { * CALLED BY ASM INJECTED CODE! */ public static double calculateEntitySoundOffset(final Entity entity, final SoundEvent sound) { + if (sound == null) return entity.getEyeHeight(); if (stepPattern.matcher(sound.soundName.getPath()).matches()) { return 0; } From 7e61fa9b82ba38ad0c7d3ccbdea9f9551e97c05e Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 12 Aug 2019 16:48:05 +0200 Subject: [PATCH 56/88] Use || instead of | Signed-off-by: djpadbit --- .../java/com/sonicether/soundphysics/SoundPhysics.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index b694158d..784fb1b5 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -402,8 +402,8 @@ public static void onPlaySound(final float posX, final float posY, final float p */ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { if (buff == null || buff.audioFormat.getChannels() == 1 || !Config.autoSteroDownmix) return buff; - if (mc.player == null | mc.world == null | lastSoundCategory == SoundCategory.RECORDS - | lastSoundCategory == SoundCategory.MUSIC | uiPattern.matcher(filename).matches() | clickPattern.matcher(filename).matches()) { + if (mc.player == null || mc.world == null || lastSoundCategory == SoundCategory.RECORDS + | lastSoundCategory == SoundCategory.MUSIC || uiPattern.matcher(filename).matches() || clickPattern.matcher(filename).matches()) { if (Config.autoSteroDownmixLogging) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); return buff; } @@ -500,7 +500,7 @@ else if (mc.world.getPrecipitationHeight(position).getY() > position.getY()) if (mc.world.getBiome(position).getEnableSnow() && cansnow) return true; else if (cansnow) return true; else return false;*/ - return mc.world.canSnowAt(position, false) | mc.world.getBiome(position).getEnableSnow(); + return mc.world.canSnowAt(position, false) || mc.world.getBiome(position).getEnableSnow(); } } @@ -596,8 +596,8 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, @SuppressWarnings("deprecation") private static void evaluateEnvironment(final int sourceID, final float posX, final float posY, final float posZ, final SoundCategory category, final String name) { try { - if (mc.player == null | mc.world == null | posY <= 0 | category == SoundCategory.RECORDS - | category == SoundCategory.MUSIC) { + if (mc.player == null || mc.world == null || posY <= 0 || category == SoundCategory.RECORDS + || category == SoundCategory.MUSIC) { // posY <= 0 as a condition has to be there: Ingame // menu clicks do have a player and world present setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); From 7a61e30f45f8cee4b61832e509f89b37154d5448 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 12 Aug 2019 16:53:02 +0200 Subject: [PATCH 57/88] Release 1.0.8 Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- src/main/resources/mcmod.info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 784fb1b5..38c1ca52 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -53,7 +53,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; - public static final String version = "1.0.7"; + public static final String version = "1.0.8"; public static final String mcVersion = "1.12.2"; public static final String deps = "before:computronics;before:immersiverailroading"; // Dependencies to make sure that SP's config is loaded before patching mods diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 194e7be1..93e61b28 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "soundphysics", "name": "Sound Physics", "description": "Provides realistic sound attenuation, reverberation, and absorption through blocks.", - "version": "1.0.7", + "version": "1.0.8", "mcversion": "1.12.2", "url": "https://github.com/djpadbit/Sound-Physics", "authorList": ["Sonic Ether","daipenger","djpadbit"] From fca2c27c96098543c763391d9f746efcd5809196 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 1 Sep 2019 17:56:42 +0200 Subject: [PATCH 58/88] Updated gradle again, added DS patch, fixed config loading Signed-off-by: djpadbit --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../com/sonicether/soundphysics/Config.java | 13 ++- .../soundphysics/CoreModInjector.java | 83 ++++++++++++------- .../soundphysics/CoreModLoader.java | 5 ++ .../sonicether/soundphysics/SoundPhysics.java | 2 +- 5 files changed, 71 insertions(+), 34 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index af38095b..9580f609 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip \ No newline at end of file diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index de84772f..5a1176da 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -1,5 +1,7 @@ package com.sonicether.soundphysics; +import java.io.File; + import java.util.ArrayList; import java.util.List; @@ -52,6 +54,7 @@ public class Config { // compatibility public static boolean computronicsPatching; public static boolean irPatching; + public static boolean dsPatching; public static boolean autoSteroDownmix; // misc @@ -70,10 +73,12 @@ public class Config { } private Config() { + this.forgeConfig = new Configuration(new File(new File(CoreModLoader.mcDir, "config"), SoundPhysics.modid+".cfg")); + syncConfig(); } public void preInit(final FMLPreInitializationEvent event) { - this.forgeConfig = new Configuration(event.getSuggestedConfigurationFile()); + //this.forgeConfig = new Configuration(event.getSuggestedConfigurationFile()); syncConfig(); } @@ -166,9 +171,11 @@ private void syncConfig() { // compatibility computronicsPatching = this.forgeConfig.getBoolean("Patch Computronics", categoryCompatibility, true, - "REQUIRES RESTART. If true, patches the computronics sound sources so it works with sound physics."); + "REQUIRES RESTART. If true, patches the Computronics sound sources so it works with Sound Physics."); irPatching = this.forgeConfig.getBoolean("Patch Immersive Railroading", categoryCompatibility, true, - "REQUIRES RESTART. If true, patches the immersive railroading sound sources so it works with sound physics."); + "REQUIRES RESTART. If true, patches the Immersive Railroading sound sources so it works with Sound Physics."); + dsPatching = this.forgeConfig.getBoolean("Patch Dynamic Surroundings", categoryCompatibility, true, + "REQUIRES RESTART. If true, patches Dynamic Surroundings to fix some bugs with Sound Physics."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto stereo downmix", categoryCompatibility, true, "REQUIRES RESTART. If true, Automatically downmix stereo sounds that are loaded to mono"); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 42cc0619..8f4b721b 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -43,7 +43,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: Constructor bytes = patchMethodInClass(obfuscated, bytes, "", "(Lchm;)V", Opcodes.INVOKESPECIAL, - AbstractInsnNode.METHOD_INSN, "", null, -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "", null, -1, toInject, false, 0, 0, false, 0, -1); } else if (obfuscated.equals("chm")) { @@ -55,7 +55,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, false, 0, 0, false, 0, -1); toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); @@ -68,7 +68,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, false, 0, 0, false, 0, -1); toInject = new InsnList(); toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", @@ -77,7 +77,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound, target invocation getClampedVolume bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKESPECIAL, - AbstractInsnNode.METHOD_INSN, "e", "(Lcgt;)F", -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "e", "(Lcgt;)F", -1, toInject, false, 0, 0, false, 0, -1); /*toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); @@ -87,7 +87,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // This function has been added by forge so the name isn't obfuscated bytes = patchMethodInClass(obfuscated, bytes, "setListener", "(Lvg;F)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setListenerOrientation", null, -1, toInject, false, 0, 0, false, 0);*/ + AbstractInsnNode.METHOD_INSN, "setListenerOrientation", null, -1, toInject, false, 0, 0, false, 0, -1);*/ } else if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL")) { @@ -118,7 +118,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: play bytes = patchMethodInClass(obfuscated, bytes, "play", "(Lpaulscode/sound/Channel;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "play", null, -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "play", null, -1, toInject, false, 0, 0, false, 0, -1); } else // Convert stero sounds to mono @@ -138,7 +138,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: loadSound bytes = patchMethodInClass(obfuscated, bytes, "loadSound", "(Lpaulscode/sound/FilenameURL;)Z", Opcodes.INVOKEINTERFACE, - AbstractInsnNode.METHOD_INSN, "cleanup", null, -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "cleanup", null, -1, toInject, false, 0, 0, false, 0, -1); toInject = new InsnList(); @@ -152,7 +152,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: loadSound bytes = patchMethodInClass(obfuscated, bytes, "loadSound", "(Lpaulscode/sound/SoundBuffer;Ljava/lang/String;)Z", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "getChannels", null, -1, toInject, true, 0, 0, false, -12); + AbstractInsnNode.METHOD_INSN, "getChannels", null, -1, toInject, true, 0, 0, false, -12, -1); } else if (obfuscated.equals("paulscode.sound.SoundSystem")) { @@ -167,7 +167,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: newSource bytes = patchMethodInClass(obfuscated, bytes, "newSource", "(ZLjava/lang/String;Ljava/net/URL;Ljava/lang/String;ZFFFIF)V", Opcodes.INVOKESPECIAL, - AbstractInsnNode.METHOD_INSN, "", null, -1, toInject, true, 2, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "", null, -1, toInject, true, 2, 0, false, 0, -1); } else if (obfuscated.equals("pl")) { @@ -182,7 +182,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: sendToAllNearExcept bytes = patchMethodInClass(obfuscated, bytes, "a", "(Laed;DDDDILht;)V", Opcodes.DCMPG, - AbstractInsnNode.INSN, "", "", -1, toInject, true, 0, 0, false, 0); + AbstractInsnNode.INSN, "", "", -1, toInject, true, 0, 0, false, 0, -1); } else if (obfuscated.equals("vg")) { @@ -199,7 +199,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound // Inside target method, target node: Entity/getSoundCategory bytes = patchMethodInClass(obfuscated, bytes, "a", "(Lqe;FF)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "bK", null, -1, toInject, true, 0, 0, false, -3); + AbstractInsnNode.METHOD_INSN, "bK", null, -1, toInject, true, 0, 0, false, -3, -1); } else // Fix for computronics's devices @@ -221,7 +221,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: play bytes = patchMethodInClass(obfuscated, bytes, "play", "(Ljava/lang/String;FFFF)V", Opcodes.INVOKESTATIC, - AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, -1, toInject, true, 0, 0, false, -5); + AbstractInsnNode.METHOD_INSN, "alSourceQueueBuffers", null, -1, toInject, true, 0, 0, false, -5, -1); toInject = new InsnList(); @@ -232,7 +232,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: setHearing bytes = patchMethodInClass(obfuscated, bytes, "setHearing", "(FF)V", Opcodes.FLOAD, - AbstractInsnNode.VAR_INSN, "", null, 1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.VAR_INSN, "", null, 1, toInject, false, 0, 0, false, 0, -1); } else if (obfuscated.equals("pl.asie.computronics.api.audio.AudioPacket") && Config.computronicsPatching) { @@ -249,7 +249,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: canHearReceiver bytes = patchMethodInClass(obfuscated, bytes, "canHearReceiver", "(Lnet/minecraft/entity/player/EntityPlayerMP;Lpl/asie/computronics/api/audio/IAudioReceiver;)Z", Opcodes.IMUL, - AbstractInsnNode.INSN, "", null, -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.INSN, "", null, -1, toInject, false, 0, 0, false, 0, -1); } else if (obfuscated.equals("pl.asie.computronics.tile.TileTapeDrive$1") && Config.computronicsPatching) { @@ -270,7 +270,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: getSoundPos bytes = patchMethodInClass(obfuscated, bytes, "getSoundPos", "()Lnet/minecraft/util/math/Vec3d;", Opcodes.ARETURN, - AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0, -1); } else if (obfuscated.equals("pl.asie.computronics.tile.TileSpeaker") && Config.computronicsPatching) { @@ -289,7 +289,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: getSoundPos bytes = patchMethodInClass(obfuscated, bytes, "getSoundPos", "()Lnet/minecraft/util/math/Vec3d;", Opcodes.ARETURN, - AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0, -1); } else if (obfuscated.equals("pl.asie.computronics.tile.TileSpeechBox$1") && Config.computronicsPatching) { @@ -310,7 +310,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: getSoundPos bytes = patchMethodInClass(obfuscated, bytes, "getSoundPos", "()Lnet/minecraft/util/math/Vec3d;", Opcodes.ARETURN, - AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0, -1); } else if (obfuscated.equals("cam72cam.immersiverailroading.sound.ClientSound") && Config.irPatching) { @@ -329,7 +329,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: play bytes = patchMethodInClass(obfuscated, bytes, "play", "(Lnet/minecraft/util/math/Vec3d;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "update", null, -1, toInject, false, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "update", null, -1, toInject, false, 0, 0, false, 0, -1); toInject = new InsnList(); @@ -339,7 +339,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: play bytes = patchMethodInClass(obfuscated, bytes, "play", "(Lnet/minecraft/util/math/Vec3d;)V", Opcodes.DCMPG, - AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0); + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0, -1); toInject = new InsnList(); @@ -349,7 +349,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: update bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESTATIC, - AbstractInsnNode.METHOD_INSN, "getDampeningAmount", null, -1, toInject, true, 0, 0, false, 0); + AbstractInsnNode.METHOD_INSN, "getDampeningAmount", null, -1, toInject, true, 0, 0, false, 0, -1); /*toInject = new InsnList(); @@ -363,7 +363,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: update bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESPECIAL, - AbstractInsnNode.METHOD_INSN, "", "(ILjava/lang/String;FFF)V", -1, toInject, true, 0, 0, false, -5);*/ + AbstractInsnNode.METHOD_INSN, "", "(ILjava/lang/String;FFF)V", -1, toInject, true, 0, 0, false, -5, -1);*/ /*if (Config.dopplerEnabled) { // IR has its own doppler shift so we remove that and just give the velocity to OpenAL so that it does it itself. toInject = new InsnList(); @@ -384,8 +384,32 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: update bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "CommandQueue", null, -1, toInject, false, 108, 1, true, 0); + AbstractInsnNode.METHOD_INSN, "CommandQueue", null, -1, toInject, false, 108, 1, true, 0, -1); }*/ + } else + + if (obfuscated.equals("org.orecruncher.dsurround.client.sound.SoundEffect") && Config.dsPatching) { + // Inside SoundEffect + InsnList toInject = new InsnList(); + + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/orecruncher/dsurround/client/sound/SoundInstance", + "noAttenuation", "()Lcgt$a;", false)); + + // Target method: createTrackingSound + bytes = patchMethodInClass(obfuscated, bytes, "createTrackingSound", "(Lnet/minecraft/entity/Entity;Z)Lorg/orecruncher/dsurround/client/sound/SoundInstance;", Opcodes.GETSTATIC, + AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, true, 0, -1); + } else + + if (obfuscated.equals("org.orecruncher.dsurround.client.sound.ConfigSoundInstance") && Config.dsPatching) { + // Inside ConfigSoundInstance + InsnList toInject = new InsnList(); + + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/orecruncher/dsurround/client/sound/SoundInstance", + "noAttenuation", "()Lcgt$a;", false)); + + // Target method: ConfigSoundInstance + bytes = patchMethodInClass(obfuscated, bytes, "", "(Ljava/lang/String;F)V", Opcodes.GETSTATIC, + AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, true, 0, 1); } //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); @@ -408,7 +432,7 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St final String targetMethodSignature, final int targetNodeOpcode, final int targetNodeType, final String targetInvocationMethodName, final String targetInvocationMethodSignature, final int targetVarNodeIndex, final InsnList instructionsToInject, final boolean insertBefore, final int nodesToDeleteBefore, - final int nodesToDeleteAfter, final boolean deleteTargetNode, final int targetNodeOffset) { + final int nodesToDeleteAfter, final boolean deleteTargetNode, final int targetNodeOffset, final int targetNodeNumber) { log("Patching class : "+className); final ClassNode classNode = new ClassNode(); @@ -424,6 +448,7 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St log("Inside target method: " + targetMethod); AbstractInsnNode targetNode = null; + int targetNodeNb = 0; final ListIterator nodeIterator = m.instructions.iterator(); while (nodeIterator.hasNext()) { @@ -439,8 +464,8 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St || targetInvocationMethodSignature == null) { log("Found target method invocation for injection: " + targetInvocationMethodName); targetNode = currentNode; - // Due to collisions, do not put break - // statements here! + if (targetNodeNumber >= 0 && targetNodeNb == targetNodeNumber) break; + targetNodeNb++; } } @@ -451,16 +476,16 @@ private byte[] patchMethodInClass(String className, final byte[] bytes, final St if (targetVarNodeIndex < 0 || varnode.var == targetVarNodeIndex) { log("Found target var node for injection: " + targetVarNodeIndex); targetNode = currentNode; - // Due to collisions, do not put break - // statements here! + if (targetNodeNumber >= 0 && targetNodeNb == targetNodeNumber) break; + targetNodeNb++; } } } else { if (currentNode.getType() == targetNodeType) { log("Found target node for injection: " + targetNodeType); targetNode = currentNode; - // Due to collisions, do not put break - // statements here! + if (targetNodeNumber >= 0 && targetNodeNb == targetNodeNumber) break; + targetNodeNb++; } } diff --git a/src/main/java/com/sonicether/soundphysics/CoreModLoader.java b/src/main/java/com/sonicether/soundphysics/CoreModLoader.java index 0f2f40ec..ba50cd89 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModLoader.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModLoader.java @@ -1,5 +1,7 @@ package com.sonicether.soundphysics; +import java.io.File; + import java.util.Map; import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; @@ -8,6 +10,8 @@ @MCVersion(value = SoundPhysics.mcVersion) public class CoreModLoader implements IFMLLoadingPlugin { + public static File mcDir; + @Override public String[] getASMTransformerClass() { return new String[] { CoreModInjector.class.getName() }; @@ -25,6 +29,7 @@ public String getSetupClass() { @Override public void injectData(final Map data) { + mcDir = (File)data.get("mcLocation"); } @Override diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 38c1ca52..f6e45f19 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -55,7 +55,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; public static final String version = "1.0.8"; public static final String mcVersion = "1.12.2"; - public static final String deps = "before:computronics;before:immersiverailroading"; // Dependencies to make sure that SP's config is loaded before patching mods + public static final String deps = ""; public static final Logger logger = LogManager.getLogger(modid); From 3c21e91f225f475d26d6c06384188c5cabbc375e Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 11 Sep 2019 15:22:44 +0200 Subject: [PATCH 59/88] Updated Forge to latest recommended Signed-off-by: djpadbit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 69536762..6fa7ac01 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ compileJava { } minecraft { - version = "1.12.2-14.23.4.2765" + version = "1.12.2-14.23.5.2768" runDir = "run" mappings = "snapshot_20180814" From aa4b5e53153c89190d21e469ef52df311d293b75 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 13 Oct 2019 18:43:06 +0200 Subject: [PATCH 60/88] Only patch DS if version is 3.5.x.x Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 8f4b721b..d54ec9b0 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -1,5 +1,6 @@ package com.sonicether.soundphysics; +import java.util.Map; import java.util.Iterator; import java.util.ListIterator; @@ -28,10 +29,26 @@ import net.minecraft.launchwrapper.IClassTransformer; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; + public class CoreModInjector implements IClassTransformer { public static final Logger logger = LogManager.getLogger(SoundPhysics.modid+"injector"); + public static boolean shouldPatchDS() { + if (Loader.isModLoaded("dsurround")) { + Map mods = Loader.instance().getIndexedModList(); + String version[] = mods.get("dsurround").getVersion().split("\\."); + if (version.length < 2) { + logError("What the hell, DS's version is not properly formatted ?"); + } else if (version[1].equals("5")) { + return true; + } + } + return false; + } + @Override public byte[] transform(final String obfuscated, final String deobfuscated, byte[] bytes) { if (obfuscated.equals("chm$a")) { @@ -388,7 +405,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte }*/ } else - if (obfuscated.equals("org.orecruncher.dsurround.client.sound.SoundEffect") && Config.dsPatching) { + if (obfuscated.equals("org.orecruncher.dsurround.client.sound.SoundEffect") && Config.dsPatching && shouldPatchDS()) { // Inside SoundEffect InsnList toInject = new InsnList(); @@ -400,7 +417,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, true, 0, -1); } else - if (obfuscated.equals("org.orecruncher.dsurround.client.sound.ConfigSoundInstance") && Config.dsPatching) { + if (obfuscated.equals("org.orecruncher.dsurround.client.sound.ConfigSoundInstance") && Config.dsPatching && shouldPatchDS()) { // Inside ConfigSoundInstance InsnList toInject = new InsnList(); From 7c1b39206eea9792e97387769a554fa1fcd6f984 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 23 Oct 2019 17:12:48 +0200 Subject: [PATCH 61/88] Simplify a bit the snow air absorption Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/SoundPhysics.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index f6e45f19..dbbc0d48 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -618,9 +618,9 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi final Vec3d soundPos = offsetSoundByName(posX, posY, posZ, playerPos, name, category); final Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize(); - float snowFactor = 0.0f; + float airAbsorptionFactor = 1.0f; - if (mc.world.isRaining()) { + if (Config.snowAirAbsorptionFactor > 1.0f && mc.world.isRaining()) { final Vec3d middlePos = playerPos.add(soundPos).scale(0.5); final BlockPos playerPosBlock = new BlockPos(playerPos); final BlockPos soundPosBlock = new BlockPos(soundPos); @@ -628,12 +628,7 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi final int snowingPlayer = isSnowingAt(playerPosBlock,false) ? 1 : 0; final int snowingSound = isSnowingAt(soundPosBlock,false) ? 1 : 0; final int snowingMiddle = isSnowingAt(middlePosBlock,false) ? 1 : 0; - snowFactor = snowingPlayer * 0.25f + snowingMiddle * 0.5f + snowingSound * 0.25f; - } - - float airAbsorptionFactor = 1.0f; - - if (snowFactor > 0.0f) { + final float snowFactor = snowingPlayer * 0.25f + snowingMiddle * 0.5f + snowingSound * 0.25f; airAbsorptionFactor = Math.max(Config.snowAirAbsorptionFactor*mc.world.getRainStrength(1.0f)*snowFactor,airAbsorptionFactor); } From 56a53db2dd0493be7a57df79a408da0532bf2b4d Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 25 Oct 2019 18:29:07 +0200 Subject: [PATCH 62/88] Fix muffled snow footstep sounds Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index dbbc0d48..eff80bba 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -566,7 +566,7 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, double tempNormZ = 0; if (soundY % 1.0 < 0.001 || stepPattern.matcher(name).matches()) { - offsetY = 0.1875; + offsetY = 0.225; } if (category == SoundCategory.BLOCKS || blockPattern.matcher(name).matches() || From 3354549b46687bfaa7d980dfb38189bc1cc42022 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 11 Nov 2019 14:27:21 +0100 Subject: [PATCH 63/88] Fixed IR compatiblity for IR 1.7.0+ Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index d54ec9b0..c4eb9574 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -330,22 +330,27 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0, -1); } else - if (obfuscated.equals("cam72cam.immersiverailroading.sound.ClientSound") && Config.irPatching) { + if ((obfuscated.equals("cam72cam.immersiverailroading.sound.ClientSound") || obfuscated.equals("cam72cam.mod.sound.ClientSound")) && Config.irPatching) { // Inside ClientSound InsnList toInject = new InsnList(); + final boolean newIR = obfuscated.equals("cam72cam.mod.sound.ClientSound"); + final String classCS = obfuscated.replace(".","/"); + final String playDesc = newIR ? "(Lcam72cam/mod/math/Vec3d;)V" : "(Lnet/minecraft/util/math/Vec3d;)V"; + final String classRes = newIR ? "cam72cam/mod/resource/Identifier" : "nf"; + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "qg","i", "Lqg;")); // Ambient sound category toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "setLastSoundCategory", "(Lqg;)V", false)); toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "oggLocation", - "Lnf;")); - toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "nf", "toString", "()Ljava/lang/String;", false)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, classCS, "oggLocation", + "L"+classRes+";")); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, classRes, "toString", "()Ljava/lang/String;", false)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "setLastSoundName", "(Ljava/lang/String;)V", false)); // Target method: play - bytes = patchMethodInClass(obfuscated, bytes, "play", "(Lnet/minecraft/util/math/Vec3d;)V", Opcodes.INVOKEVIRTUAL, + bytes = patchMethodInClass(obfuscated, bytes, "play", playDesc, Opcodes.INVOKEVIRTUAL, AbstractInsnNode.METHOD_INSN, "update", null, -1, toInject, false, 0, 0, false, 0, -1); toInject = new InsnList(); @@ -355,7 +360,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte toInject.add(new InsnNode(Opcodes.DMUL)); // Target method: play - bytes = patchMethodInClass(obfuscated, bytes, "play", "(Lnet/minecraft/util/math/Vec3d;)V", Opcodes.DCMPG, + bytes = patchMethodInClass(obfuscated, bytes, "play", playDesc, Opcodes.DCMPG, AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0, -1); toInject = new InsnList(); @@ -365,8 +370,8 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte toInject.add(new InsnNode(Opcodes.FMUL)); // Target method: update - bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESTATIC, - AbstractInsnNode.METHOD_INSN, "getDampeningAmount", null, -1, toInject, true, 0, 0, false, 0, -1); + bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.FMUL, + AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0, -1); /*toInject = new InsnList(); From ce1f3e241452760b3e830d4388d8c4c728aa1874 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 24 Nov 2019 20:17:36 +0100 Subject: [PATCH 64/88] 1.0.8-1 Release Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- src/main/resources/mcmod.info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index eff80bba..ac138c72 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -53,7 +53,7 @@ public class SoundPhysics { public static final String modid = "soundphysics"; - public static final String version = "1.0.8"; + public static final String version = "1.0.8-1"; public static final String mcVersion = "1.12.2"; public static final String deps = ""; diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 93e61b28..04ad874e 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "soundphysics", "name": "Sound Physics", "description": "Provides realistic sound attenuation, reverberation, and absorption through blocks.", - "version": "1.0.8", + "version": "1.0.8-1", "mcversion": "1.12.2", "url": "https://github.com/djpadbit/Sound-Physics", "authorList": ["Sonic Ether","daipenger","djpadbit"] From 8ba9172250ffd3f7e8ce587f13af19fdf0cc27de Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 6 Mar 2020 22:15:33 +0100 Subject: [PATCH 65/88] Fix rift sounds in The Betweenlands being converted to mono. Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index ac138c72..99fc1d88 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -67,6 +67,7 @@ public class SoundPhysics { private static final Pattern uiPattern = Pattern.compile(".*\\/ui\\/.*"); private static final Pattern clickPattern = Pattern.compile(".*random.click.*"); private static final Pattern noteBlockPattern = Pattern.compile(".*block.note.*"); + private static final Pattern betweenlandsPattern = Pattern.compile("thebetweenlands:sounds\\/rift_.*\\.ogg"); @Mod.EventHandler public void preInit(final FMLPreInitializationEvent event) { @@ -403,7 +404,8 @@ public static void onPlaySound(final float posX, final float posY, final float p public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { if (buff == null || buff.audioFormat.getChannels() == 1 || !Config.autoSteroDownmix) return buff; if (mc.player == null || mc.world == null || lastSoundCategory == SoundCategory.RECORDS - | lastSoundCategory == SoundCategory.MUSIC || uiPattern.matcher(filename).matches() || clickPattern.matcher(filename).matches()) { + || lastSoundCategory == SoundCategory.MUSIC || uiPattern.matcher(filename).matches() || clickPattern.matcher(filename).matches() + || betweenlandsPattern.matcher(filename).matches()) { if (Config.autoSteroDownmixLogging) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); return buff; } From beaed46eca367f2f6ee6b3802529e6b51261125b Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 27 Apr 2020 04:00:52 +0200 Subject: [PATCH 66/88] Added The Midnight patch to fix https://github.com/djpadbit/Sound-Physics/issues/27 Added a bit more openal error checking Signed-off-by: djpadbit --- .../java/com/sonicether/soundphysics/Config.java | 3 +++ .../sonicether/soundphysics/CoreModInjector.java | 13 +++++++++++++ .../com/sonicether/soundphysics/SoundPhysics.java | 2 ++ 3 files changed, 18 insertions(+) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 5a1176da..0fd2aa62 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -55,6 +55,7 @@ public class Config { public static boolean computronicsPatching; public static boolean irPatching; public static boolean dsPatching; + public static boolean midnightPatching; public static boolean autoSteroDownmix; // misc @@ -176,6 +177,8 @@ private void syncConfig() { "REQUIRES RESTART. If true, patches the Immersive Railroading sound sources so it works with Sound Physics."); dsPatching = this.forgeConfig.getBoolean("Patch Dynamic Surroundings", categoryCompatibility, true, "REQUIRES RESTART. If true, patches Dynamic Surroundings to fix some bugs with Sound Physics."); + midnightPatching = this.forgeConfig.getBoolean("Patch The Midnight", categoryCompatibility, true, + "REQUIRES RESTART. If true, patches The Midnight to disable redundant functionality that causes some problems."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto stereo downmix", categoryCompatibility, true, "REQUIRES RESTART. If true, Automatically downmix stereo sounds that are loaded to mono"); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index c4eb9574..70f2b287 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -19,6 +19,7 @@ import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.VarInsnNode; import org.objectweb.asm.tree.LdcInsnNode; +import org.objectweb.asm.tree.FrameNode; import org.objectweb.asm.util.TraceMethodVisitor; import org.objectweb.asm.util.Printer; @@ -432,6 +433,18 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: ConfigSoundInstance bytes = patchMethodInClass(obfuscated, bytes, "", "(Ljava/lang/String;F)V", Opcodes.GETSTATIC, AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, true, 0, 1); + } else + + if (obfuscated.equals("com.mushroom.midnight.client.SoundReverbHandler") && Config.midnightPatching) { + // Inside ConfigSoundInstance + InsnList toInject = new InsnList(); + + toInject.add(new InsnNode(Opcodes.RETURN)); + toInject.add(new FrameNode(Opcodes.F_SAME,0,new Object[] {},0,new Object[] {})); + + // Target method: ConfigSoundInstance + bytes = patchMethodInClass(obfuscated, bytes, "onPlaySound", "(I)V", Opcodes.GETSTATIC, + AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, false, 0, 0); } //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 99fc1d88..b2b1647d 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -903,6 +903,7 @@ private static void setEnvironment(final int sourceID, final float sendGain0, fi AL10.alSourcei(sourceID, EFX10.AL_DIRECT_FILTER, directFilter0); AL10.alSourcef(sourceID, EFX10.AL_AIR_ABSORPTION_FACTOR, MathHelper.clamp(Config.airAbsorption * airAbsorptionFactor,0.0f,10.0f)); + checkErrorLog("Error while setting environment for source: " + sourceID); } /** @@ -945,6 +946,7 @@ protected static void setReverbParams(final ReverbParams r, final int auxFXSlot, // Attach updated effect object EFX10.alAuxiliaryEffectSloti(auxFXSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbSlot); + checkErrorLog("Error while assigning reverb effect slot: " + reverbSlot); } public static void log(final String message) { From d0c5f5059300771c66c49bc9db3127c8fc36f499 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 27 Apr 2020 04:05:45 +0200 Subject: [PATCH 67/88] Comments Signed-off-by: djpadbit --- .../java/com/sonicether/soundphysics/CoreModInjector.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 70f2b287..c379ca75 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -430,19 +430,19 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/orecruncher/dsurround/client/sound/SoundInstance", "noAttenuation", "()Lcgt$a;", false)); - // Target method: ConfigSoundInstance + // Target method: constructor bytes = patchMethodInClass(obfuscated, bytes, "", "(Ljava/lang/String;F)V", Opcodes.GETSTATIC, AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, true, 0, 1); } else if (obfuscated.equals("com.mushroom.midnight.client.SoundReverbHandler") && Config.midnightPatching) { - // Inside ConfigSoundInstance + // Inside SoundReverbHandler InsnList toInject = new InsnList(); toInject.add(new InsnNode(Opcodes.RETURN)); toInject.add(new FrameNode(Opcodes.F_SAME,0,new Object[] {},0,new Object[] {})); - // Target method: ConfigSoundInstance + // Target method: onPlaySound bytes = patchMethodInClass(obfuscated, bytes, "onPlaySound", "(I)V", Opcodes.GETSTATIC, AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, false, 0, 0); } From 574d8f9fac479350deb170f7ad0429a05094443b Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 1 May 2020 18:29:04 +0200 Subject: [PATCH 68/88] Removed dynamic env. evalutaion + Cleaned up dead code Signed-off-by: djpadbit --- README.md | 3 +- .../com/sonicether/soundphysics/Config.java | 12 - .../soundphysics/CoreModInjector.java | 36 +-- .../sonicether/soundphysics/SoundPhysics.java | 210 +----------------- .../soundphysics/SoundPhysicsServer.java | 4 +- 5 files changed, 9 insertions(+), 256 deletions(-) diff --git a/README.md b/README.md index 2f2585ff..527ec48e 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,10 @@ Downloads are in the [releases tab](https://github.com/djpadbit/Sound-Physics/re This is a fork of a fork! I forked it from daipenger who forked it from sonicether, daipenger ported it to 1.12.2 and cleaned up the codebase, i just added some stuff. The stuff added in this fork: -* Dynamic environement evaluation (disabled by default, enable in mod config ingame) * Automatic stero to mono downmixing of sounds (So the original resourcepack is not needed anymore) * More compatibility with mods (Computronics & Immersive Railroading) * Server-side support (right position for entity and computronics sounds and higher distance before sound cutoff) Todo: -* Rewrite/cleanup Dynamic environement evaluation +* Rewrite Dynamic environement evaluation (feature removed for now) * More mod compatibility ? I'm open to suggestions \ No newline at end of file diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 0fd2aa62..91e03f1c 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -31,14 +31,11 @@ public class Config { public static float underwaterFilter; public static boolean noteBlockEnable; public static float maxDistance; - //public static boolean dopplerEnabled; // performance public static boolean skipRainOcclusionTracing; public static int environmentEvaluationRays; public static boolean simplerSharedAirspaceSimulation; - public static boolean dynamicEnvironementEvalutaion; - public static int dynamicEnvironementEvalutaionFrequency; // block properties public static float stoneReflectivity; @@ -60,7 +57,6 @@ public class Config { // misc public static boolean autoSteroDownmixLogging; - public static boolean debugInfoShow; public static boolean injectorLogging; private static final String categoryGeneral = "General"; @@ -133,8 +129,6 @@ private void syncConfig() { "If true, note blocks will be processed."); maxDistance = this.forgeConfig.getFloat("Max ray distance", categoryGeneral, 256.0f, 1.0f, 8192.0f, "How far the rays should be traced."); - /*dopplerEnabled = this.forgeConfig.getBoolean("Enable doppler effect", categoryGeneral, true, - "REQUIRES RESTART. If true, the doppler effect will be enabled.");*/ // performance skipRainOcclusionTracing = this.forgeConfig.getBoolean("Skip Rain Occlusion Tracing", categoryPerformance, true, @@ -145,10 +139,6 @@ private void syncConfig() { simplerSharedAirspaceSimulation = this.forgeConfig.getBoolean("Simpler Shared Airspace Simulation", categoryPerformance, false, "If true, enables a simpler technique for determining when the player and a sound source share airspace. Might sometimes miss recognizing shared airspace, but it's faster to calculate."); - dynamicEnvironementEvalutaion = this.forgeConfig.getBoolean("Dynamic environment evaluation", categoryPerformance, false, - "WARNING it's implemented really badly so i'd recommend not always using it.If true, the environment will keep getting evaluated for every sound that is currently playing. This may affect performance"); - dynamicEnvironementEvalutaionFrequency = this.forgeConfig.getInt("Frequency of environment evaluation", categoryPerformance, 30, 1, 60, - "The frequency at witch to update environment of sounds if dynamic environment evaluation is enabled"); // material properties stoneReflectivity = this.forgeConfig.getFloat("Stone Reflectivity", categoryMaterialProperties, 0.95f, 0.0f, @@ -185,8 +175,6 @@ private void syncConfig() { // misc autoSteroDownmixLogging = this.forgeConfig.getBoolean("Stereo downmix Logging", categoryMisc, false, "If true, Prints sound name and format of the sounds that get converted"); - debugInfoShow = this.forgeConfig.getBoolean("Dynamic env. info in F3", categoryMisc, false, - "If true, Shows sources currently playing in the F3 debug info"); injectorLogging = this.forgeConfig.getBoolean("Injector Logging", categoryMisc, false, "If true, Logs debug info about the injector"); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index c379ca75..2a744ebf 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -96,16 +96,6 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound, target invocation getClampedVolume bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKESPECIAL, AbstractInsnNode.METHOD_INSN, "e", "(Lcgt;)F", -1, toInject, false, 0, 0, false, 0, -1); - - /*toInject = new InsnList(); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); - toInject.add(new VarInsnNode(Opcodes.FLOAD, 2)); - toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "onSetListener", "(Lvg;F)V", false)); - - // This function has been added by forge so the name isn't obfuscated - bytes = patchMethodInClass(obfuscated, bytes, "setListener", "(Lvg;F)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setListenerOrientation", null, -1, toInject, false, 0, 0, false, 0, -1);*/ } else if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL")) { @@ -374,6 +364,8 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.FMUL, AbstractInsnNode.INSN, "", null, -1, toInject, true, 0, 0, false, 0, -1); + // Commented code to change the position of the sound source depending on the scale of the train + // Could be implemented but needs more work/proper positions for like the wheels and stuff /*toInject = new InsnList(); toInject.add(new LdcInsnNode(1.75d)); @@ -387,28 +379,6 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: update bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKESPECIAL, AbstractInsnNode.METHOD_INSN, "", "(ILjava/lang/String;FFF)V", -1, toInject, true, 0, 0, false, -5, -1);*/ - - /*if (Config.dopplerEnabled) { // IR has its own doppler shift so we remove that and just give the velocity to OpenAL so that it does it itself. - toInject = new InsnList(); - - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "velocity", - "Lbhe;")); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "id", - "Ljava/lang/String;")); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "cam72cam/immersiverailroading/sound/ClientSound", "currentPitch", - "F")); - toInject.add(new VarInsnNode(Opcodes.FLOAD, 2)); - toInject.add(new InsnNode(Opcodes.FDIV)); - toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "onIRUpdate", "(Lbhe;Ljava/lang/String;F)V", false)); - - // Target method: update - bytes = patchMethodInClass(obfuscated, bytes, "update", "()V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "CommandQueue", null, -1, toInject, false, 108, 1, true, 0, -1); - }*/ } else if (obfuscated.equals("org.orecruncher.dsurround.client.sound.SoundEffect") && Config.dsPatching && shouldPatchDS()) { @@ -447,7 +417,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, false, 0, 0); } - //System.out.println("[SP Inject] "+obfuscated+" ("+deobfuscated+")"); + //log("Finished processing class: '"+obfuscated+"' ('"+deobfuscated+"')"); return bytes; } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index b2b1647d..cc5a5f97 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -1,11 +1,6 @@ package com.sonicether.soundphysics; import java.util.regex.Pattern; -import java.util.List; -import java.util.ArrayList; -import java.util.ListIterator; -import java.util.Collections; -import java.nio.FloatBuffer; import org.lwjgl.openal.AL10; import org.lwjgl.openal.AL11; @@ -13,7 +8,6 @@ import org.lwjgl.openal.ALCcontext; import org.lwjgl.openal.ALCdevice; import org.lwjgl.openal.EFX10; -import org.lwjgl.BufferUtils; import net.minecraft.block.Block; import net.minecraft.block.SoundType; @@ -32,30 +26,23 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.Text; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import paulscode.sound.SoundSystemConfig; import paulscode.sound.SoundSystem; -import paulscode.sound.CommandObject; import paulscode.sound.SoundBuffer; import javax.sound.sampled.AudioFormat; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.Timer; -import java.util.TimerTask; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; -@Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory", - dependencies = SoundPhysics.deps) +@Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, + version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory") public class SoundPhysics { public static final String modid = "soundphysics"; public static final String version = "1.0.8-1"; public static final String mcVersion = "1.12.2"; - public static final String deps = ""; public static final Logger logger = LogManager.getLogger(modid); @@ -99,11 +86,6 @@ public void init(final FMLInitializationEvent event) { private static SoundCategory lastSoundCategory; private static String lastSoundName; - private static ProcThread proc_thread; - private static volatile boolean thread_alive; - private static volatile boolean thread_signal_death; - private static volatile List source_list; - // THESE VARIABLES ARE CONSTANTLY ACCESSED AND USED BY ASM INJECTED CODE! DO // NOT REMOVE! public static int attenuationModel = SoundSystemConfig.ATTENUATION_ROLLOFF; @@ -119,155 +101,13 @@ public static void init(SoundSystem snds) { mc = Minecraft.getMinecraft(); sndSystem = snds; try { - /*if (Config.dopplerEnabled) { - sndSystem.changeDopplerFactor(1.0f); - AL11.alSpeedOfSound(343.3f); // Should already be 343.3 but just in case - }*/ setupEFX(); - setupThread(); } catch (Throwable e) { - logError("Failed to init EFX or thread"); + logError("Failed to init EFX"); logError(e.toString()); } } - public static class Source { - public int sourceID; - public float posX; - public float posY; - public float posZ; - public SoundCategory category; - public String name; - public int frequency; - public int size; - public int bufferID; - - public Source(int sid,float px,float py,float pz,SoundCategory cat,String n) { - this.sourceID = sid; - this.posX = px; - this.posY = py; - this.posZ = pz; - this.category = cat; - this.name = n; - bufferID = AL10.alGetSourcei(sid, AL10.AL_BUFFER); - size = AL10.alGetBufferi(bufferID, AL10.AL_SIZE); - frequency = AL10.alGetBufferi(bufferID, AL10.AL_FREQUENCY); - } - } - - public static class ProcThread extends Thread { - @Override - public synchronized void run() { - while (thread_alive) { - while (!Config.dynamicEnvironementEvalutaion) { - try { - Thread.sleep(1000); - } catch (Exception e) { - logError(String.valueOf(e)); - } - } - synchronized (source_list) { - //log("Updating env " + String.valueOf(source_list.size())); - ListIterator iter = source_list.listIterator(); - while (iter.hasNext()) { - Source source = iter.next(); - //log("Updating sound '" + source.name + "' SourceID:" + String.valueOf(source.sourceID)); - //boolean pl = sndHandler.isSoundPlaying(source.sound); - //FloatBuffer pos = BufferUtils.createFloatBuffer(3); - //AL10.alGetSource(source.sourceID,AL10.AL_POSITION,pos); - //To try ^ - int state = AL10.alGetSourcei(source.sourceID, AL10.AL_SOURCE_STATE); - //int byteoff = AL10.alGetSourcei(source.sourceID, AL11.AL_BYTE_OFFSET); - //boolean finished = source.size == byteoff; - if (state == AL10.AL_PLAYING) { - FloatBuffer pos = BufferUtils.createFloatBuffer(3); - AL10.alGetSource(source.sourceID,AL10.AL_POSITION,pos); - source.posX = pos.get(0); - source.posY = pos.get(1); - source.posZ = pos.get(2); - evaluateEnvironment(source.sourceID,source.posX,source.posY,source.posZ,source.category,source.name); - } else /*if (state == AL10.AL_STOPPED)*/ { - iter.remove(); - } - } - } - try { - Thread.sleep(1000/Config.dynamicEnvironementEvalutaionFrequency); - } catch (Exception e) { - logError(String.valueOf(e)); - } - } - thread_signal_death = true; - } - } - - public static void source_check_add(Source s) { - synchronized (source_list) { - ListIterator iter = source_list.listIterator(); - while (iter.hasNext()) { - Source sn = iter.next(); - if (sn.sourceID == s.sourceID) { - sn.posX = s.posX; - sn.posY = s.posY; - sn.posZ = s.posZ; - sn.category = s.category; - sn.name = s.name; - return; - } - } - source_list.add(s); - } - } - - @Mod.EventBusSubscriber - public static class DebugDisplayEventHandler { - @SubscribeEvent - public static void onDebugOverlay(RenderGameOverlayEvent.Text event) { - if (mc != null && mc.gameSettings.showDebugInfo && Config.dynamicEnvironementEvalutaion && Config.debugInfoShow) { - event.getLeft().add(""); - event.getLeft().add("[SoundPhysics] "+String.valueOf(source_list.size())+" Sources"); - event.getLeft().add("[SoundPhysics] Source list :"); - synchronized (source_list) { - ListIterator iter = source_list.listIterator(); - while (iter.hasNext()) { - Source s = iter.next(); - Vec3d tmp = new Vec3d(s.posX,s.posY,s.posZ); - event.getLeft().add(String.valueOf(s.sourceID)+"-"+s.category.toString()+"-"+s.name+"-"+tmp.toString()); - /*int buffq = AL10.alGetSourcei(s.sourceID, AL10.AL_BUFFERS_QUEUED); - int buffp = AL10.alGetSourcei(s.sourceID, AL10.AL_BUFFERS_PROCESSED); - int sampoff = AL10.alGetSourcei(s.sourceID, AL11.AL_SAMPLE_OFFSET); - int byteoff = AL10.alGetSourcei(s.sourceID, AL11.AL_BYTE_OFFSET); - String k = ""; - if (sampoff!=0) { - //k = String.valueOf(sampoff)+"/"+String.valueOf((byteoff/sampoff)*size)+" "; - k = String.valueOf((float)sampoff/(float)s.frequency)+"/"+String.valueOf((float)((byteoff/sampoff)*s.size)/(float)s.frequency)+" "; - } else { - k = "0/? "; - } - event.getLeft().add(k+String.valueOf(buffp)+"/"+String.valueOf(buffq)+" "+String.valueOf(s.bufferID)); - event.getLeft().add("----");*/ - } - } - } - } - } - - private static synchronized void setupThread() { - if (source_list == null) source_list = Collections.synchronizedList(new ArrayList()); - else source_list.clear(); - - /*if (proc_thread != null) { - thread_signal_death = false; - thread_alive = false; - while (!thread_signal_death); - }*/ - if (proc_thread == null) { - proc_thread = new ProcThread(); - thread_alive = true; - proc_thread.start(); - } - } - public static void applyConfigChanges() { globalRolloffFactor = Config.rolloffFactor; globalReverbMultiplier = 0.7f * Config.globalReverbGain; @@ -390,12 +230,6 @@ public static void onPlaySound(final float posX, final float posY, final float p //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); if (Config.noteBlockEnable && soundCat == SoundCategory.RECORDS && noteBlockPattern.matcher(soundName).matches()) soundCat = SoundCategory.BLOCKS; evaluateEnvironment(sourceID, posX, posY, posZ,soundCat,soundName); - if (!Config.dynamicEnvironementEvalutaion) return; - if ((mc.player == null || mc.world == null || posY <= 0 || soundCat == SoundCategory.RECORDS - || soundCat == SoundCategory.MUSIC) || (Config.skipRainOcclusionTracing && rainPattern.matcher(soundName).matches())) return; - if (clickPattern.matcher(soundName).matches() || uiPattern.matcher(soundName).matches()) return; - Source tmp = new Source(sourceID,posX,posY,posZ,soundCat,soundName); - source_check_add(tmp); } /** @@ -454,28 +288,6 @@ public static Vec3d computronicsOffset(Vec3d or, TileEntity te, PropertyDirectio return or.add(efv); } - /** - * CALLED BY ASM INJECTED CODE! - */ - /*public static void onSetListener(Entity player, float partial_tick) { - float motionX = (float)((player.posX - player.prevPosX) * 20.0d); - float motionY = (float)((player.posY - player.prevPosY) * 20.0d); - float motionZ = (float)((player.posZ - player.prevPosZ) * 20.0d); - sndSystem.setListenerVelocity(motionX,motionY,motionZ); - }*/ - - /** - * CALLED BY ASM INJECTED CODE! - */ - /*public static void onIRUpdate(Vec3d velocity, String source, float pitch) { - float motionX = (float)(velocity.x * 20.0d); - float motionY = (float)(velocity.y * 20.0d); - float motionZ = (float)(velocity.z * 20.0d); - sndSystem.CommandQueue(new CommandObject(CommandObject.SET_VELOCITY, source, motionX, motionY, motionZ)); - sndSystem.CommandQueue(new CommandObject(CommandObject.SET_PITCH, source, pitch)); - }*/ - - // Unused private static boolean isSnowingAt(BlockPos position) { @@ -634,22 +446,6 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi airAbsorptionFactor = Math.max(Config.snowAirAbsorptionFactor*mc.world.getRainStrength(1.0f)*snowFactor,airAbsorptionFactor); } - /*final double distance = playerPos.distanceTo(soundPos); - final double time = (distance/343.3)*1000; - AL10.alSourcePause(sourceID); - log("paused, time "+String.valueOf(time)); - - new java.util.Timer().schedule( - new java.util.TimerTask() { - @Override - public void run() { - log("play, time "+String.valueOf(time)); - AL10.alSourcePlay(sourceID); - } - }, - (long)time - );*/ - Vec3d rayOrigin = soundPos; float occlusionAccumulation = 0.0f; diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java b/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java index 9a5d3172..13a964ec 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysicsServer.java @@ -5,8 +5,8 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; //Server side mod to load the config -@Mod(modid = SoundPhysics.modid, serverSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, acceptableRemoteVersions = "*", - guiFactory = "com.sonicether.soundphysics.SPGuiFactory", dependencies = SoundPhysics.deps) +@Mod(modid = SoundPhysics.modid, serverSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion,version = SoundPhysics.version, + acceptableRemoteVersions = "*", guiFactory = "com.sonicether.soundphysics.SPGuiFactory") public class SoundPhysicsServer { @Mod.EventHandler public void preInit(final FMLPreInitializationEvent event) { From ed7d90ec86a8d2b45d83f9735130fbc0cb99ed87 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Fri, 1 May 2020 19:08:49 +0200 Subject: [PATCH 69/88] Questionable code formatting Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 2 +- .../sonicether/soundphysics/SoundPhysics.java | 74 +++++++------------ 2 files changed, 27 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 2a744ebf..f03f8274 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -425,7 +425,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte private static Printer printer = new Textifier(); private static TraceMethodVisitor mp = new TraceMethodVisitor(printer); - public static String insnToString(AbstractInsnNode insn){ + public static String insnToString(AbstractInsnNode insn) { insn.accept(mp); StringWriter sw = new StringWriter(); printer.print(new PrintWriter(sw)); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index cc5a5f97..7c2a8ebf 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -229,7 +229,7 @@ public static void onPlaySoundAL(final float posX, final float posY, final float public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName) { //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); if (Config.noteBlockEnable && soundCat == SoundCategory.RECORDS && noteBlockPattern.matcher(soundName).matches()) soundCat = SoundCategory.BLOCKS; - evaluateEnvironment(sourceID, posX, posY, posZ,soundCat,soundName); + evaluateEnvironment(sourceID, posX, posY, posZ, soundCat, soundName); } /** @@ -237,9 +237,8 @@ public static void onPlaySound(final float posX, final float posY, final float p */ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { if (buff == null || buff.audioFormat.getChannels() == 1 || !Config.autoSteroDownmix) return buff; - if (mc.player == null || mc.world == null || lastSoundCategory == SoundCategory.RECORDS - || lastSoundCategory == SoundCategory.MUSIC || uiPattern.matcher(filename).matches() || clickPattern.matcher(filename).matches() - || betweenlandsPattern.matcher(filename).matches()) { + if (mc.player == null || mc.world == null || lastSoundCategory == SoundCategory.RECORDS || lastSoundCategory == SoundCategory.MUSIC || + uiPattern.matcher(filename).matches() || clickPattern.matcher(filename).matches() || betweenlandsPattern.matcher(filename).matches()) { if (Config.autoSteroDownmixLogging) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); return buff; } @@ -288,32 +287,12 @@ public static Vec3d computronicsOffset(Vec3d or, TileEntity te, PropertyDirectio return or.add(efv); } - // Unused - private static boolean isSnowingAt(BlockPos position) - { - return isSnowingAt(position, true); - } - // Copy of isRainingAt - private static boolean isSnowingAt(BlockPos position, boolean check_rain) - { - if (check_rain && !mc.world.isRaining()) { - return false; - } - else if (!mc.world.canSeeSky(position)) - { + private static boolean isSnowingAt(BlockPos position, boolean check_rain) { + if ((check_rain && !mc.world.isRaining()) || !mc.world.canSeeSky(position) || + mc.world.getPrecipitationHeight(position).getY() > position.getY()) { return false; - } - else if (mc.world.getPrecipitationHeight(position).getY() > position.getY()) - { - return false; - } - else - { - /*boolean cansnow = mc.world.canSnowAt(position, false); - if (mc.world.getBiome(position).getEnableSnow() && cansnow) return true; - else if (cansnow) return true; - else return false;*/ + } else { return mc.world.canSnowAt(position, false) || mc.world.getBiome(position).getEnableSnow(); } } @@ -410,8 +389,7 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, @SuppressWarnings("deprecation") private static void evaluateEnvironment(final int sourceID, final float posX, final float posY, final float posZ, final SoundCategory category, final String name) { try { - if (mc.player == null || mc.world == null || posY <= 0 || category == SoundCategory.RECORDS - || category == SoundCategory.MUSIC) { + if (mc.player == null || mc.world == null || posY <= 0 || category == SoundCategory.RECORDS || category == SoundCategory.MUSIC) { // posY <= 0 as a condition has to be there: Ingame // menu clicks do have a player and world present setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); @@ -762,24 +740,24 @@ protected static boolean checkErrorLog(final String errorMessage) { String errorName; switch (error) { - case AL10.AL_INVALID_NAME: - errorName = "AL_INVALID_NAME"; - break; - case AL10.AL_INVALID_ENUM: - errorName = "AL_INVALID_ENUM"; - break; - case AL10.AL_INVALID_VALUE: - errorName = "AL_INVALID_VALUE"; - break; - case AL10.AL_INVALID_OPERATION: - errorName = "AL_INVALID_OPERATION"; - break; - case AL10.AL_OUT_OF_MEMORY: - errorName = "AL_OUT_OF_MEMORY"; - break; - default: - errorName = Integer.toString(error); - break; + case AL10.AL_INVALID_NAME: + errorName = "AL_INVALID_NAME"; + break; + case AL10.AL_INVALID_ENUM: + errorName = "AL_INVALID_ENUM"; + break; + case AL10.AL_INVALID_VALUE: + errorName = "AL_INVALID_VALUE"; + break; + case AL10.AL_INVALID_OPERATION: + errorName = "AL_INVALID_OPERATION"; + break; + case AL10.AL_OUT_OF_MEMORY: + errorName = "AL_OUT_OF_MEMORY"; + break; + default: + errorName = Integer.toString(error); + break; } logError(errorMessage + " OpenAL error " + errorName); From 0a5879cb4c0dd2732a44cf5265c2a4aaaff6fb87 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 11 May 2020 17:19:11 +0200 Subject: [PATCH 70/88] Better build versioning Signed-off-by: djpadbit --- build.gradle | 17 ++++++++++------- gradle.properties | 3 +++ .../sonicether/soundphysics/SoundPhysics.java | 4 ++-- src/main/resources/mcmod.info | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 6fa7ac01..08c2c881 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { apply plugin: 'net.minecraftforge.gradle.forge' //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. -version = "1.12.2" +version = "${mc_version}-${mod_version}" group = "com.sonicether.soundphysics" archivesBaseName = "Sound-Physics" @@ -30,8 +30,11 @@ compileJava { minecraft { version = "1.12.2-14.23.5.2768" runDir = "run" - mappings = "snapshot_20180814" + + replace '${version}', mod_version + replace '${mc_version}', mc_version + replaceIn "SoundPhysics.java" } dependencies { @@ -39,17 +42,17 @@ dependencies { processResources { // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version + inputs.property "version", mod_version + inputs.property "mc_version", mc_version // replace stuff in mcmod.info, nothing else from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' - + // replace version and mcversion - expand 'version':project.version, 'mcversion':project.minecraft.version + expand 'version':mod_version, 'mc_version':mc_version } - + // copy everything else except the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' diff --git a/gradle.properties b/gradle.properties index e9b9fd5a..f02f5a87 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,6 @@ # Sets default memory used for gradle commands. Can be overridden by user or command line properties. # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G + +mc_version=1.12.2 +mod_version=1.0.8-1 \ No newline at end of file diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 7c2a8ebf..fb504566 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -41,8 +41,8 @@ public class SoundPhysics { public static final String modid = "soundphysics"; - public static final String version = "1.0.8-1"; - public static final String mcVersion = "1.12.2"; + public static final String version = "${version}"; + public static final String mcVersion = "${mc_version}"; public static final Logger logger = LogManager.getLogger(modid); diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 04ad874e..7d49cafa 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,8 +3,8 @@ "modid": "soundphysics", "name": "Sound Physics", "description": "Provides realistic sound attenuation, reverberation, and absorption through blocks.", - "version": "1.0.8-1", - "mcversion": "1.12.2", + "version": "${version}", + "mcversion": "${mc_version}", "url": "https://github.com/djpadbit/Sound-Physics", "authorList": ["Sonic Ether","daipenger","djpadbit"] } From 88092a38e3660ba2b24dc5af117d4f4a8c319d97 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 11 May 2020 17:20:06 +0200 Subject: [PATCH 71/88] build.gradle converted to unix line ending Signed-off-by: djpadbit --- build.gradle | 120 +++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/build.gradle b/build.gradle index 08c2c881..08f3d47c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,60 +1,60 @@ -buildscript { - repositories { - jcenter() - maven { url = "http://files.minecraftforge.net/maven" } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - } -} -apply plugin: 'net.minecraftforge.gradle.forge' -//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. - -version = "${mc_version}-${mod_version}" -group = "com.sonicether.soundphysics" -archivesBaseName = "Sound-Physics" - -jar { - manifest { - attributes 'FMLCorePlugin': 'com.sonicether.soundphysics.CoreModLoader' - attributes 'FMLCorePluginContainsFMLMod': 'true' - attributes 'FMLAT': 'soundphysics_at.cfg' - } -} - -sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. -compileJava { - sourceCompatibility = targetCompatibility = '1.8' -} - -minecraft { - version = "1.12.2-14.23.5.2768" - runDir = "run" - mappings = "snapshot_20180814" - - replace '${version}', mod_version - replace '${mc_version}', mc_version - replaceIn "SoundPhysics.java" -} - -dependencies { -} - -processResources { - // this will ensure that this task is redone when the versions change. - inputs.property "version", mod_version - inputs.property "mc_version", mc_version - - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - - // replace version and mcversion - expand 'version':mod_version, 'mc_version':mc_version - } - - // copy everything else except the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } -} +buildscript { + repositories { + jcenter() + maven { url = "http://files.minecraftforge.net/maven" } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' + } +} +apply plugin: 'net.minecraftforge.gradle.forge' +//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. + +version = "${mc_version}-${mod_version}" +group = "com.sonicether.soundphysics" +archivesBaseName = "Sound-Physics" + +jar { + manifest { + attributes 'FMLCorePlugin': 'com.sonicether.soundphysics.CoreModLoader' + attributes 'FMLCorePluginContainsFMLMod': 'true' + attributes 'FMLAT': 'soundphysics_at.cfg' + } +} + +sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. +compileJava { + sourceCompatibility = targetCompatibility = '1.8' +} + +minecraft { + version = "1.12.2-14.23.5.2768" + runDir = "run" + mappings = "snapshot_20180814" + + replace '${version}', mod_version + replace '${mc_version}', mc_version + replaceIn "SoundPhysics.java" +} + +dependencies { +} + +processResources { + // this will ensure that this task is redone when the versions change. + inputs.property "version", mod_version + inputs.property "mc_version", mc_version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + + // replace version and mcversion + expand 'version':mod_version, 'mc_version':mc_version + } + + // copy everything else except the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} From 22f424cbbd2962c18f7cd95b96025df604e67d84 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 13 May 2020 16:13:01 +0200 Subject: [PATCH 72/88] Added Global Volume Multiplier config option Global Volume Multiplier now only applies to affected sounds (Can be disabled in config) Moved noteblock sound category changing directly in setLastSoundCategory rather than before the eval Fixed #29 Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 6 +++++ .../soundphysics/CoreModInjector.java | 17 ++++++------ .../sonicether/soundphysics/SoundPhysics.java | 26 ++++++++++++++++--- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 91e03f1c..300ecd6c 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -22,6 +22,7 @@ public class Config { // general public static float rolloffFactor; public static float globalReverbGain; + public static float globalVolumeMultiplier; public static float globalReverbBrightness; public static float soundDistanceAllowance; public static float globalBlockAbsorption; @@ -31,6 +32,7 @@ public class Config { public static float underwaterFilter; public static boolean noteBlockEnable; public static float maxDistance; + public static boolean volumeMulOnlyAffected; // performance public static boolean skipRainOcclusionTracing; @@ -106,6 +108,8 @@ private void syncConfig() { // General rolloffFactor = this.forgeConfig.getFloat("Attenuation Factor", categoryGeneral, 1.0f, 0.2f, 1.0f, "Affects how quiet a sound gets based on distance. Lower values mean distant sounds are louder. 1.0 is the physically correct value."); + globalVolumeMultiplier = this.forgeConfig.getFloat("Global Volume Multiplier", categoryGeneral, 4.0f, 0.1f, 8.0f, + "The global volume multiplier of all sounds."); globalReverbGain = this.forgeConfig.getFloat("Global Reverb Gain", categoryGeneral, 1.0f, 0.1f, 2.0f, "The global volume of simulated reverberations."); globalReverbBrightness = this.forgeConfig.getFloat("Global Reverb Brightness", categoryGeneral, 1.0f, 0.1f, @@ -129,6 +133,8 @@ private void syncConfig() { "If true, note blocks will be processed."); maxDistance = this.forgeConfig.getFloat("Max ray distance", categoryGeneral, 256.0f, 1.0f, 8192.0f, "How far the rays should be traced."); + volumeMulOnlyAffected = this.forgeConfig.getBoolean("Volume Multiplier Only On Affected", categoryGeneral, true, + "If true, the global volume multiplier will only be applied to affected sounds (so not to the ui sounds for example)."); // performance skipRainOcclusionTracing = this.forgeConfig.getBoolean("Skip Rain Occlusion Tracing", categoryPerformance, true, diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index f03f8274..6787de00 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -73,7 +73,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, false, 0, 0, false, 0, -1); + AbstractInsnNode.METHOD_INSN, "setPitch", null, -1, toInject, false, 0, 0, false, 0, -1); toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); @@ -86,16 +86,17 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: playSound bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, false, 0, 0, false, 0, -1); + AbstractInsnNode.METHOD_INSN, "setPitch", null, -1, toInject, false, 0, 0, false, 0, -1); toInject = new InsnList(); - toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", - "globalVolumeMultiplier", "F")); - toInject.add(new InsnNode(Opcodes.FMUL)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + toInject.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "cgt", "j", "()F", true)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "applyGlobalVolumeMultiplier", "(FF)F", false)); - // Target method: playSound, target invocation getClampedVolume - bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKESPECIAL, - AbstractInsnNode.METHOD_INSN, "e", "(Lcgt;)F", -1, toInject, false, 0, 0, false, 0, -1); + // Target method: playSound, target invocation setVolume + bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, -1); } else if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL")) { diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index fb504566..bfcc14a1 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -55,6 +55,7 @@ public class SoundPhysics { private static final Pattern clickPattern = Pattern.compile(".*random.click.*"); private static final Pattern noteBlockPattern = Pattern.compile(".*block.note.*"); private static final Pattern betweenlandsPattern = Pattern.compile("thebetweenlands:sounds\\/rift_.*\\.ogg"); + private static final Pattern travelPattern = Pattern.compile(".*portal\\/travel*.*"); @Mod.EventHandler public void preInit(final FMLPreInitializationEvent event) { @@ -90,7 +91,7 @@ public void init(final FMLInitializationEvent event) { // NOT REMOVE! public static int attenuationModel = SoundSystemConfig.ATTENUATION_ROLLOFF; public static float globalRolloffFactor = Config.rolloffFactor; - public static float globalVolumeMultiplier = 4.0f; + public static float globalVolumeMultiplier = Config.globalVolumeMultiplier; public static float globalReverbMultiplier = 0.7f * Config.globalReverbGain; public static double soundDistanceAllowance = Config.soundDistanceAllowance; @@ -112,6 +113,7 @@ public static void applyConfigChanges() { globalRolloffFactor = Config.rolloffFactor; globalReverbMultiplier = 0.7f * Config.globalReverbGain; soundDistanceAllowance = Config.soundDistanceAllowance; + globalVolumeMultiplier = Config.globalVolumeMultiplier; if (auxFXSlot0 != 0) { // Set the global reverb parameters and apply them to the effect and @@ -190,7 +192,11 @@ private static void setupEFX() { * CALLED BY ASM INJECTED CODE! */ public static void setLastSoundCategory(final SoundCategory sc) { - lastSoundCategory = sc; + if (Config.noteBlockEnable && sc == SoundCategory.RECORDS && noteBlockPattern.matcher(lastSoundName).matches()) { + lastSoundCategory = SoundCategory.BLOCKS; + } else { + lastSoundCategory = sc; + } } /** @@ -207,6 +213,18 @@ public static void setLastSoundName(final String soundName) { lastSoundName = soundName; } + /** + * CALLED BY ASM INJECTED CODE! + */ + public static float applyGlobalVolumeMultiplier(final float volume, final float posY) { + if (!Config.volumeMulOnlyAffected || !(mc.player == null || mc.world == null || posY <= 0 || + lastSoundCategory == SoundCategory.RECORDS || lastSoundCategory == SoundCategory.MUSIC)) { + return volume*globalVolumeMultiplier; + } else { + return volume; + } + } + /** * CALLED BY ASM INJECTED CODE! */ @@ -228,7 +246,6 @@ public static void onPlaySoundAL(final float posX, final float posY, final float */ public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName) { //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); - if (Config.noteBlockEnable && soundCat == SoundCategory.RECORDS && noteBlockPattern.matcher(soundName).matches()) soundCat = SoundCategory.BLOCKS; evaluateEnvironment(sourceID, posX, posY, posZ, soundCat, soundName); } @@ -238,7 +255,8 @@ public static void onPlaySound(final float posX, final float posY, final float p public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { if (buff == null || buff.audioFormat.getChannels() == 1 || !Config.autoSteroDownmix) return buff; if (mc.player == null || mc.world == null || lastSoundCategory == SoundCategory.RECORDS || lastSoundCategory == SoundCategory.MUSIC || - uiPattern.matcher(filename).matches() || clickPattern.matcher(filename).matches() || betweenlandsPattern.matcher(filename).matches()) { + uiPattern.matcher(filename).matches() || clickPattern.matcher(filename).matches() || betweenlandsPattern.matcher(filename).matches() || + travelPattern.matcher(filename).matches()) { if (Config.autoSteroDownmixLogging) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); return buff; } From a6ce81d398112d60b4f7b9077ebd202d0a02afa3 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 13 May 2020 17:43:27 +0200 Subject: [PATCH 73/88] Fix bug with DS and globalVolumeMultiplier DS was internally multiplying the globalVolumeMultiplier inside of getClampedVolume so it ended up being multiplied twice and also when not needed Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/Config.java | 2 +- .../java/com/sonicether/soundphysics/CoreModInjector.java | 2 +- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 300ecd6c..7d4c8a3f 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -175,7 +175,7 @@ private void syncConfig() { "REQUIRES RESTART. If true, patches Dynamic Surroundings to fix some bugs with Sound Physics."); midnightPatching = this.forgeConfig.getBoolean("Patch The Midnight", categoryCompatibility, true, "REQUIRES RESTART. If true, patches The Midnight to disable redundant functionality that causes some problems."); - autoSteroDownmix = this.forgeConfig.getBoolean("Auto stereo downmix", categoryCompatibility, true, + autoSteroDownmix = this.forgeConfig.getBoolean("Auto Stereo Downmix", categoryCompatibility, true, "REQUIRES RESTART. If true, Automatically downmix stereo sounds that are loaded to mono"); // misc diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 6787de00..cabbbf75 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -358,7 +358,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte toInject = new InsnList(); toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", - "globalVolumeMultiplier", "F")); + "globalVolumeMultiplier0", "F")); toInject.add(new InsnNode(Opcodes.FMUL)); // Target method: update diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index bfcc14a1..98e0d21f 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -91,7 +91,7 @@ public void init(final FMLInitializationEvent event) { // NOT REMOVE! public static int attenuationModel = SoundSystemConfig.ATTENUATION_ROLLOFF; public static float globalRolloffFactor = Config.rolloffFactor; - public static float globalVolumeMultiplier = Config.globalVolumeMultiplier; + public static float globalVolumeMultiplier0 = Config.globalVolumeMultiplier; // 0 is because of DS trying to read the value of the original name public static float globalReverbMultiplier = 0.7f * Config.globalReverbGain; public static double soundDistanceAllowance = Config.soundDistanceAllowance; @@ -113,7 +113,7 @@ public static void applyConfigChanges() { globalRolloffFactor = Config.rolloffFactor; globalReverbMultiplier = 0.7f * Config.globalReverbGain; soundDistanceAllowance = Config.soundDistanceAllowance; - globalVolumeMultiplier = Config.globalVolumeMultiplier; + globalVolumeMultiplier0 = Config.globalVolumeMultiplier; if (auxFXSlot0 != 0) { // Set the global reverb parameters and apply them to the effect and @@ -219,7 +219,7 @@ public static void setLastSoundName(final String soundName) { public static float applyGlobalVolumeMultiplier(final float volume, final float posY) { if (!Config.volumeMulOnlyAffected || !(mc.player == null || mc.world == null || posY <= 0 || lastSoundCategory == SoundCategory.RECORDS || lastSoundCategory == SoundCategory.MUSIC)) { - return volume*globalVolumeMultiplier; + return volume*globalVolumeMultiplier0; } else { return volume; } From 0bfcf460aa9c95289711a34b85698cc6ee011602 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 31 May 2020 01:43:37 +0200 Subject: [PATCH 74/88] Don't offset block sounds if player is inside, fixes #30 Signed-off-by: djpadbit --- .../java/com/sonicether/soundphysics/SoundPhysics.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 98e0d21f..a4e8a32b 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -380,8 +380,11 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, offsetY = 0.225; } - if (category == SoundCategory.BLOCKS || blockPattern.matcher(name).matches() || - (name == "openal" && !mc.world.isAirBlock(new BlockPos(soundX,soundY,soundZ)))) { + if ((category == SoundCategory.BLOCKS || blockPattern.matcher(name).matches() || + (name == "openal" && !mc.world.isAirBlock(new BlockPos(soundX,soundY,soundZ)))) && + (MathHelper.floor(playerPos.x) != MathHelper.floor(soundX) || + MathHelper.floor(playerPos.y) != MathHelper.floor(soundY) || + MathHelper.floor(playerPos.z) != MathHelper.floor(soundZ))) { // The ray will probably hit the block that it's emitting from // before // escaping. Offset the ray start position towards the player by the From d57704f2c4592db099037b7d11c258c5eb8df7dd Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 1 Jun 2020 01:28:44 +0200 Subject: [PATCH 75/88] 1.0.9 Release Finally a new release huh, it's been a while Signed-off-by: djpadbit --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f02f5a87..b45f95a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx3G mc_version=1.12.2 -mod_version=1.0.8-1 \ No newline at end of file +mod_version=1.0.9 \ No newline at end of file From 91b191133e90ca3d41c978885303e3f5e7ab5773 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 24 Jun 2020 18:45:50 +0200 Subject: [PATCH 76/88] Added echo, may need to tweak the values though. Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/Config.java | 3 +++ .../java/com/sonicether/soundphysics/ReverbParams.java | 10 ++++++++++ .../java/com/sonicether/soundphysics/SoundPhysics.java | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 7d4c8a3f..207d2486 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -33,6 +33,7 @@ public class Config { public static boolean noteBlockEnable; public static float maxDistance; public static boolean volumeMulOnlyAffected; + public static float globalEchoMultiplier; // performance public static boolean skipRainOcclusionTracing; @@ -135,6 +136,8 @@ private void syncConfig() { "How far the rays should be traced."); volumeMulOnlyAffected = this.forgeConfig.getBoolean("Volume Multiplier Only On Affected", categoryGeneral, true, "If true, the global volume multiplier will only be applied to affected sounds (so not to the ui sounds for example)."); + globalEchoMultiplier = this.forgeConfig.getFloat("Global Echo Multiplier", categoryGeneral, 1.0f, 0.0f, 2.0f, + "The global volume multiplier of the echos, put to 0 to disable echos all together"); // performance skipRainOcclusionTracing = this.forgeConfig.getBoolean("Skip Rain Occlusion Tracing", categoryPerformance, true, diff --git a/src/main/java/com/sonicether/soundphysics/ReverbParams.java b/src/main/java/com/sonicether/soundphysics/ReverbParams.java index ec740c12..43099bc2 100644 --- a/src/main/java/com/sonicether/soundphysics/ReverbParams.java +++ b/src/main/java/com/sonicether/soundphysics/ReverbParams.java @@ -14,6 +14,8 @@ public class ReverbParams { public float lateReverbDelay; // min: 0.0f max: 0.1f public float airAbsorptionGainHF; // min: 0.892f max: 1.0f public float roomRolloffFactor; // min: 0.0f max: 10.0f + public float echoTime; // min: 0.075f max: 0.25f + public float echoDepth; // min: 0.0f max: 1.0f public static ReverbParams getReverb0() { final ReverbParams r = new ReverbParams(); @@ -29,6 +31,8 @@ public static ReverbParams getReverb0() { r.lateReverbDelay = 0.011f; r.airAbsorptionGainHF = 0.994f; r.roomRolloffFactor = 0.16f * Config.rolloffFactor; + r.echoTime = 0.090f; + r.echoDepth = 0.1f * Config.globalEchoMultiplier; return r; } @@ -47,6 +51,8 @@ public static ReverbParams getReverb1() { r.lateReverbDelay = 0.011f; r.airAbsorptionGainHF = 0.994f; r.roomRolloffFactor = 0.15f * Config.rolloffFactor; + r.echoTime = 0.1f; + r.echoDepth = 0.15f * Config.globalEchoMultiplier; return r; } @@ -65,6 +71,8 @@ public static ReverbParams getReverb2() { r.lateReverbDelay = 0.021f; r.airAbsorptionGainHF = 0.994f; r.roomRolloffFactor = 0.13f * Config.rolloffFactor; + r.echoTime = 0.13f; + r.echoDepth = 0.3f * Config.globalEchoMultiplier; return r; } @@ -83,6 +91,8 @@ public static ReverbParams getReverb3() { r.lateReverbDelay = 0.021f; r.airAbsorptionGainHF = 0.994f; r.roomRolloffFactor = 0.11f * Config.rolloffFactor; + r.echoTime = 0.20f; + r.echoDepth = 0.5f * Config.globalEchoMultiplier; return r; } diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index a4e8a32b..42736231 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -739,6 +739,12 @@ protected static void setReverbParams(final ReverbParams r, final int auxFXSlot, EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, r.roomRolloffFactor); checkErrorLog("Error while assigning reverb roomRolloffFactor: " + r.roomRolloffFactor); + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_ECHO_TIME, r.echoTime); + checkErrorLog("Error while assigning reverb echoTime: " + r.echoTime); + + EFX10.alEffectf(reverbSlot, EFX10.AL_EAXREVERB_ECHO_DEPTH, r.echoDepth); + checkErrorLog("Error while assigning reverb echoDepth: " + r.echoDepth); + // Attach updated effect object EFX10.alAuxiliaryEffectSloti(auxFXSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbSlot); checkErrorLog("Error while assigning reverb effect slot: " + reverbSlot); From 96453ba71c2d7bfba6f30332d87008efc4a90919 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 27 Jun 2020 18:48:03 +0200 Subject: [PATCH 77/88] Don't use Y coords as check if ingame, fixes #31 Unifed setLastSoundName and setLastSoundCategory and added sound attunuation type Modified Dynamic Surroudings injection Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 36 ++++--------- .../sonicether/soundphysics/SoundPhysics.java | 50 +++++++++++-------- 2 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index cabbbf75..2b18ebc4 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -37,13 +37,13 @@ public class CoreModInjector implements IClassTransformer { public static final Logger logger = LogManager.getLogger(SoundPhysics.modid+"injector"); - public static boolean shouldPatchDS() { + private static boolean shouldPatchDS(boolean checkNew) { if (Loader.isModLoaded("dsurround")) { Map mods = Loader.instance().getIndexedModList(); String version[] = mods.get("dsurround").getVersion().split("\\."); if (version.length < 2) { logError("What the hell, DS's version is not properly formatted ?"); - } else if (version[1].equals("5")) { + } else if ((!checkNew && version[1].equals("5")) || (checkNew && version[1].equals("6"))) { return true; } } @@ -67,32 +67,21 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte if (obfuscated.equals("chm")) { // Inside SoundManager InsnList toInject = new InsnList(); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); toInject.add(new VarInsnNode(Opcodes.ALOAD, 7)); - toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "setLastSoundCategory", "(Lqg;)V", false)); - - // Target method: playSound - bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "setPitch", null, -1, toInject, false, 0, 0, false, 0, -1); - - toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "cgq", "a", "()Lnf;", false)); - toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "nf", "toString", "()Ljava/lang/String;", false)); toInject.add(new VarInsnNode(Opcodes.ALOAD, 3)); - toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "nf", "toString", "()Ljava/lang/String;", false)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "setLastSoundName", "(Ljava/lang/String;Ljava/lang/String;)V", false)); + "setLastSound", "(Lcgt;Lqg;Lnf;Lnf;)V", false)); // Target method: playSound bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, AbstractInsnNode.METHOD_INSN, "setPitch", null, -1, toInject, false, 0, 0, false, 0, -1); toInject = new InsnList(); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); - toInject.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "cgt", "j", "()F", true)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "applyGlobalVolumeMultiplier", "(FF)F", false)); + "applyGlobalVolumeMultiplier", "(F)F", false)); // Target method: playSound, target invocation setVolume bytes = patchMethodInClass(obfuscated, bytes, "c", "(Lcgt;)V", Opcodes.INVOKEVIRTUAL, @@ -332,14 +321,12 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte final String classRes = newIR ? "cam72cam/mod/resource/Identifier" : "nf"; toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "qg","i", "Lqg;")); // Ambient sound category - toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "setLastSoundCategory", "(Lqg;)V", false)); toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); toInject.add(new FieldInsnNode(Opcodes.GETFIELD, classCS, "oggLocation", "L"+classRes+";")); toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, classRes, "toString", "()Ljava/lang/String;", false)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "setLastSoundName", "(Ljava/lang/String;)V", false)); + "setLastSound", "(Lqg;Ljava/lang/String;)V", false)); // Target method: play bytes = patchMethodInClass(obfuscated, bytes, "play", playDesc, Opcodes.INVOKEVIRTUAL, @@ -382,7 +369,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.METHOD_INSN, "", "(ILjava/lang/String;FFF)V", -1, toInject, true, 0, 0, false, -5, -1);*/ } else - if (obfuscated.equals("org.orecruncher.dsurround.client.sound.SoundEffect") && Config.dsPatching && shouldPatchDS()) { + if (obfuscated.equals("org.orecruncher.dsurround.client.sound.SoundEffect") && Config.dsPatching && shouldPatchDS(false)) { // Inside SoundEffect InsnList toInject = new InsnList(); @@ -394,16 +381,15 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, true, 0, -1); } else - if (obfuscated.equals("org.orecruncher.dsurround.client.sound.ConfigSoundInstance") && Config.dsPatching && shouldPatchDS()) { + if (obfuscated.equals("org.orecruncher.dsurround.client.sound.ConfigSoundInstance") && Config.dsPatching && shouldPatchDS(true)) { // Inside ConfigSoundInstance InsnList toInject = new InsnList(); - toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/orecruncher/dsurround/client/sound/SoundInstance", - "noAttenuation", "()Lcgt$a;", false)); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "cgt$a","a", "Lcgt$a;")); // ISound.AttenuationType.NONE // Target method: constructor - bytes = patchMethodInClass(obfuscated, bytes, "", "(Ljava/lang/String;F)V", Opcodes.GETSTATIC, - AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, true, 0, 1); + bytes = patchMethodInClass(obfuscated, bytes, "", "(Ljava/lang/String;F)V", Opcodes.INVOKESTATIC, + AbstractInsnNode.METHOD_INSN, "noAttenuation", null, -1, toInject, false, 0, 0, true, 0, -1); } else if (obfuscated.equals("com.mushroom.midnight.client.SoundReverbHandler") && Config.midnightPatching) { diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 42736231..5bdec58e 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -15,6 +15,8 @@ import net.minecraft.block.properties.PropertyDirection; import net.minecraft.tileentity.TileEntity; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; +import net.minecraft.client.audio.MovingSound; import net.minecraft.entity.Entity; import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; @@ -23,6 +25,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -86,6 +89,7 @@ public void init(final FMLInitializationEvent event) { private static SoundCategory lastSoundCategory; private static String lastSoundName; + private static ISound.AttenuationType lastSoundAtt; // THESE VARIABLES ARE CONSTANTLY ACCESSED AND USED BY ASM INJECTED CODE! DO // NOT REMOVE! @@ -188,37 +192,40 @@ private static void setupEFX() { applyConfigChanges(); } - /** - * CALLED BY ASM INJECTED CODE! - */ - public static void setLastSoundCategory(final SoundCategory sc) { - if (Config.noteBlockEnable && sc == SoundCategory.RECORDS && noteBlockPattern.matcher(lastSoundName).matches()) { - lastSoundCategory = SoundCategory.BLOCKS; + private static SoundCategory getSoundCategory(final SoundCategory sc, final String name) { + if (Config.noteBlockEnable && sc == SoundCategory.RECORDS && noteBlockPattern.matcher(name).matches()) { + return SoundCategory.BLOCKS; } else { - lastSoundCategory = sc; + return sc; } } /** * CALLED BY ASM INJECTED CODE! */ - public static void setLastSoundName(final String soundName, final String eventName) { - lastSoundName = eventName+"|"+soundName.split(":")[1]; // Quick and dirty hack to check the event and sound name + public static void setLastSound(final ISound snd, final SoundCategory sc, final ResourceLocation soundRes, final ResourceLocation eventRes) { + lastSoundName = eventRes.toString()+"|"+soundRes.getPath(); // Quick and dirty hack to check the event and sound name + lastSoundCategory = getSoundCategory(sc,lastSoundName); + lastSoundAtt = snd.getAttenuationType(); + if (snd instanceof MovingSound) // Hacky fix until i properly do moving sounds (I'm currently thinking about how) + lastSoundCategory = SoundCategory.MASTER; // because all (at least vanilla) moving sounds don't init their position when played } /** * CALLED BY ASM INJECTED CODE! */ - public static void setLastSoundName(final String soundName) { + public static void setLastSound(final SoundCategory sc, final String soundName) { + lastSoundCategory = sc; lastSoundName = soundName; + lastSoundAtt = ISound.AttenuationType.LINEAR; } /** * CALLED BY ASM INJECTED CODE! */ - public static float applyGlobalVolumeMultiplier(final float volume, final float posY) { - if (!Config.volumeMulOnlyAffected || !(mc.player == null || mc.world == null || posY <= 0 || - lastSoundCategory == SoundCategory.RECORDS || lastSoundCategory == SoundCategory.MUSIC)) { + public static float applyGlobalVolumeMultiplier(final float volume) { + if (!Config.volumeMulOnlyAffected || !(mc.player == null || mc.world == null || lastSoundCategory == SoundCategory.MASTER || + lastSoundAtt == ISound.AttenuationType.NONE || lastSoundCategory == SoundCategory.RECORDS || lastSoundCategory == SoundCategory.MUSIC)) { return volume*globalVolumeMultiplier0; } else { return volume; @@ -230,7 +237,7 @@ public static float applyGlobalVolumeMultiplier(final float volume, final float */ // For sounds that get played normally public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID) { - onPlaySound(posX, posY, posZ, sourceID, lastSoundCategory, lastSoundName); + onPlaySound(posX, posY, posZ, sourceID, lastSoundCategory, lastSoundName, lastSoundAtt); } /** @@ -238,15 +245,15 @@ public static void onPlaySound(final float posX, final float posY, final float p */ // For sounds that get played using OpenAL directly or just not using the minecraft sound system public static void onPlaySoundAL(final float posX, final float posY, final float posZ, final int sourceID) { - onPlaySound(posX, posY, posZ, sourceID, SoundCategory.MASTER, "openal"); + onPlaySound(posX, posY, posZ, sourceID, SoundCategory.AMBIENT, "openal", ISound.AttenuationType.LINEAR); } /** * CALLED BY ASM INJECTED CODE! */ - public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName) { - //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+soundName); - evaluateEnvironment(sourceID, posX, posY, posZ, soundCat, soundName); + public static void onPlaySound(final float posX, final float posY, final float posZ, final int sourceID, SoundCategory soundCat, String soundName, ISound.AttenuationType attType) { + //log(String.valueOf(posX)+" "+String.valueOf(posY)+" "+String.valueOf(posZ)+" - "+String.valueOf(sourceID)+" - "+soundCat.toString()+" - "+attType.toString()+" - "+soundName); + evaluateEnvironment(sourceID, posX, posY, posZ, soundCat, soundName, attType); } /** @@ -408,11 +415,14 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, } @SuppressWarnings("deprecation") - private static void evaluateEnvironment(final int sourceID, final float posX, final float posY, final float posZ, final SoundCategory category, final String name) { + private static void evaluateEnvironment(final int sourceID, final float posX, final float posY, final float posZ, final SoundCategory category, + final String name, ISound.AttenuationType attType) { try { - if (mc.player == null || mc.world == null || posY <= 0 || category == SoundCategory.RECORDS || category == SoundCategory.MUSIC) { + if (mc.player == null || mc.world == null || category == SoundCategory.MASTER || attType == ISound.AttenuationType.NONE || + category == SoundCategory.RECORDS || category == SoundCategory.MUSIC) { // posY <= 0 as a condition has to be there: Ingame // menu clicks do have a player and world present + // The Y position check has been removed due to problems with Cubic Chunks setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); return; } From e7ae8529bf6b4b1fd9965ffa1da36658e3802703 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 27 Jun 2020 19:05:40 +0200 Subject: [PATCH 78/88] Updated forge Signed-off-by: djpadbit --- build.gradle | 4 ++-- gradle.properties | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 08f3d47c..1288de33 100644 --- a/build.gradle +++ b/build.gradle @@ -28,9 +28,9 @@ compileJava { } minecraft { - version = "1.12.2-14.23.5.2768" + version = "${mc_version}-${forge_version}" runDir = "run" - mappings = "snapshot_20180814" + mappings = mcp_mappings replace '${version}', mod_version replace '${mc_version}', mc_version diff --git a/gradle.properties b/gradle.properties index b45f95a6..0ec2f36f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,5 +2,8 @@ # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G +forge_version=14.23.5.2847 +mcp_mappings=snapshot_20180814 + mc_version=1.12.2 mod_version=1.0.9 \ No newline at end of file From e3e745a5e662673b5680c88c631ea1dc16778156 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Wed, 15 Jul 2020 23:13:40 +0200 Subject: [PATCH 79/88] Readd reverb to The Midnight, fixes #36 Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/Config.java | 3 +++ .../com/sonicether/soundphysics/SoundPhysics.java | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 207d2486..7f2d1d5a 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -56,6 +56,7 @@ public class Config { public static boolean irPatching; public static boolean dsPatching; public static boolean midnightPatching; + public static boolean midnightPatchingFix; public static boolean autoSteroDownmix; // misc @@ -178,6 +179,8 @@ private void syncConfig() { "REQUIRES RESTART. If true, patches Dynamic Surroundings to fix some bugs with Sound Physics."); midnightPatching = this.forgeConfig.getBoolean("Patch The Midnight", categoryCompatibility, true, "REQUIRES RESTART. If true, patches The Midnight to disable redundant functionality that causes some problems."); + midnightPatchingFix = this.forgeConfig.getBoolean("Readd The Midnight Reverb", categoryCompatibility, true, + "If true, readds The Midnight reverb that is removed with the patch."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto Stereo Downmix", categoryCompatibility, true, "REQUIRES RESTART. If true, Automatically downmix stereo sounds that are loaded to mono"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 5bdec58e..ebcfc114 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -672,6 +672,17 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi sendCutoff3 *= 0.4f; } + if (Config.midnightPatching && Config.midnightPatchingFix && mc.world.provider.getDimensionType().getName() == "midnight") { + // Since the patch removes the incompatble reverb, readd some reverb everywhere + // It's not a great fix but it works fine + sendGain1 = MathHelper.clamp(sendGain1, 0.3f, 1.0f); + sendGain2 = MathHelper.clamp(sendGain2, 0.5f, 1.0f); + sendGain3 = MathHelper.clamp(sendGain3, 0.7f, 1.0f); + sendCutoff1 = MathHelper.clamp(sendCutoff1, 0.3f, 1.0f); + sendCutoff2 = MathHelper.clamp(sendCutoff2, 0.5f, 1.0f); + sendCutoff3 = MathHelper.clamp(sendCutoff3, 0.7f, 1.0f); + } + setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, sendCutoff3, directCutoff, directGain, airAbsorptionFactor); } catch(Exception e) { From 87ced9e3651d9efb2ad23d8f2ebc12b8f4fb96cf Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 26 Jul 2020 20:19:28 +0200 Subject: [PATCH 80/88] Added IC2 Compatbility Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 3 + .../soundphysics/CoreModInjector.java | 126 ++++++++++++++++++ .../sonicether/soundphysics/SoundPhysics.java | 22 +++ 3 files changed, 151 insertions(+) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 7f2d1d5a..d14036e4 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -57,6 +57,7 @@ public class Config { public static boolean dsPatching; public static boolean midnightPatching; public static boolean midnightPatchingFix; + public static boolean ic2Patching; public static boolean autoSteroDownmix; // misc @@ -181,6 +182,8 @@ private void syncConfig() { "REQUIRES RESTART. If true, patches The Midnight to disable redundant functionality that causes some problems."); midnightPatchingFix = this.forgeConfig.getBoolean("Readd The Midnight Reverb", categoryCompatibility, true, "If true, readds The Midnight reverb that is removed with the patch."); + ic2Patching = this.forgeConfig.getBoolean("Patch IC2", categoryCompatibility, true, + "REQUIRES RESTART. If true, patches IC2 audio to better work with Sound Physics."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto Stereo Downmix", categoryCompatibility, true, "REQUIRES RESTART. If true, Automatically downmix stereo sounds that are loaded to mono"); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 2b18ebc4..20f38800 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -166,6 +166,19 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte bytes = patchMethodInClass(obfuscated, bytes, "newSource", "(ZLjava/lang/String;Ljava/net/URL;Ljava/lang/String;ZFFFIF)V", Opcodes.INVOKESPECIAL, AbstractInsnNode.METHOD_INSN, "", null, -1, toInject, true, 2, 0, false, 0, -1); + + // Can't reuse the list for some reason + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "attenuationModel", "I")); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalRolloffFactor", "F")); + + // Target method: newSource + bytes = patchMethodInClass(obfuscated, bytes, "newSource", + "(ZLjava/lang/String;Ljava/lang/String;ZFFFIF)V", Opcodes.INVOKESPECIAL, + AbstractInsnNode.METHOD_INSN, "", null, -1, toInject, true, 2, 0, false, 0, -1); } else if (obfuscated.equals("pl")) { @@ -344,6 +357,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte toInject = new InsnList(); + // TODO: use applyGlobalVolumeMultiplier here toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", "globalVolumeMultiplier0", "F")); toInject.add(new InsnNode(Opcodes.FMUL)); @@ -402,6 +416,118 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: onPlaySound bytes = patchMethodInClass(obfuscated, bytes, "onPlaySound", "(I)V", Opcodes.GETSTATIC, AbstractInsnNode.FIELD_INSN, "", null, -1, toInject, true, 0, 0, false, 0, 0); + } else + + if (obfuscated.equals("ic2.core.audio.AudioManagerClient") && Config.ic2Patching) { + // Inside AudioManagerClient + InsnList toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "attenuationModel", "I")); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalRolloffFactor", "F")); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 2)); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ic2/core/audio/PositionSpec", "ordinal", "()I", false)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 3)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "setLastSound", "(ILjava/lang/String;)V", false)); + + // Target method: playOnce + bytes = patchMethodInClass(obfuscated, bytes, "playOnce", "(Ljava/lang/Object;Lic2/core/audio/PositionSpec;Ljava/lang/String;ZF)Ljava/lang/String;", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "quickPlay", null, -1, toInject, true, 7, 0, false, 0, -1); + + toInject = new InsnList(); + + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "applyGlobalVolumeMultiplier", "(F)F", false)); + + // Target method: playOnce + bytes = patchMethodInClass(obfuscated, bytes, "playOnce", "(Ljava/lang/Object;Lic2/core/audio/PositionSpec;Ljava/lang/String;ZF)Ljava/lang/String;", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, -1); + } else + + if (obfuscated.equals("ic2.core.audio.AudioSourceClient") && Config.ic2Patching) { + // Inside AudioSourceClient + InsnList toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "positionSpec", + "Lic2/core/audio/PositionSpec;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ic2/core/audio/PositionSpec", "ordinal", "()I", false)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "initialSoundFile", + "Ljava/lang/String;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "setLastSound", "(ILjava/lang/String;)V", false)); + + // Target method: play + bytes = patchMethodInClass(obfuscated, bytes, "play", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "play", null, -1, toInject, true, 0, 0, false, 0, -1); + + toInject = new InsnList(); + + toInject.add(new InsnNode(Opcodes.FCONST_1)); + + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "getMasterVolume", null, -1, toInject, false, 0, 0, true, -5, 0); + + toInject = new InsnList(); + + /*toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier0", "F"));*/ + toInject.add(new InsnNode(Opcodes.FCONST_1)); + + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "getMasterVolume", null, -1, toInject, false, 1, 0, true, 0, 1); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new InsnNode(Opcodes.D2F)); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKESTATIC, + AbstractInsnNode.METHOD_INSN, "max", null, -1, toInject, false, 0, 0, false, 1, -1); + + toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + toInject.add(new InsnNode(Opcodes.ACONST_NULL)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "calculateEntitySoundOffset", "(Lvg;Lqe;)D", false)); + toInject.add(new InsnNode(Opcodes.DADD)); + + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "getWorld", null, -1, toInject, true, 0, 0, false, -15, -1); // -11 without labels + + toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", + "Lic2/core/audio/AudioPosition;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "x", "F")); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", + "Lic2/core/audio/AudioPosition;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "y", "F")); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", + "Lic2/core/audio/AudioPosition;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "z", "F")); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 6)); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 7)); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 8)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "ic2DistanceCheckHook", "(FFFFFFFF)I", false)); + + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.FCMPG, + AbstractInsnNode.INSN, null, null, -1, toInject, false, 0, 0, true, 0, -1); } //log("Finished processing class: '"+obfuscated+"' ('"+deobfuscated+"')"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index ebcfc114..13725945 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -220,6 +220,28 @@ public static void setLastSound(final SoundCategory sc, final String soundName) lastSoundAtt = ISound.AttenuationType.LINEAR; } + /** + * CALLED BY ASM INJECTED CODE! + */ + // For IC2 + public static void setLastSound(final int position, final String soundName) { + lastSoundCategory = position == 0 ? SoundCategory.BLOCKS : SoundCategory.PLAYERS; + lastSoundName = "ic2:"+soundName; + lastSoundAtt = ISound.AttenuationType.LINEAR; + } + + /** + * CALLED BY ASM INJECTED CODE! + */ + public static int ic2DistanceCheckHook(float i, float dst, float x1, float y1, float z1, float x2, float y2, float z2) { + if (i >= dst || + (MathHelper.floor(x1) == MathHelper.floor(x2) && + MathHelper.floor(y1) == MathHelper.floor(y2) && + MathHelper.floor(z1) == MathHelper.floor(z2))) return 1; + if (dst == i) return 0; + return -1; + } + /** * CALLED BY ASM INJECTED CODE! */ From d0bb85f1f47bcb75854b3e3f19460d5ba2154c0a Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 5 Sep 2020 00:53:57 +0200 Subject: [PATCH 81/88] Null check mc in onLoadSound Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 13725945..414d5f08 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -283,7 +283,7 @@ public static void onPlaySound(final float posX, final float posY, final float p */ public static SoundBuffer onLoadSound(SoundBuffer buff, String filename) { if (buff == null || buff.audioFormat.getChannels() == 1 || !Config.autoSteroDownmix) return buff; - if (mc.player == null || mc.world == null || lastSoundCategory == SoundCategory.RECORDS || lastSoundCategory == SoundCategory.MUSIC || + if (mc == null || mc.player == null || mc.world == null || lastSoundCategory == SoundCategory.RECORDS || lastSoundCategory == SoundCategory.MUSIC || uiPattern.matcher(filename).matches() || clickPattern.matcher(filename).matches() || betweenlandsPattern.matcher(filename).matches() || travelPattern.matcher(filename).matches()) { if (Config.autoSteroDownmixLogging) log("Not converting sound '"+filename+"'("+buff.audioFormat.toString()+")"); From 9e81d40ed30706c21348d9e7708bbbc8f8abd320 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 7 Sep 2020 18:31:49 +0200 Subject: [PATCH 82/88] 1.0.10 Release Signed-off-by: djpadbit --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 0ec2f36f..de6437d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ forge_version=14.23.5.2847 mcp_mappings=snapshot_20180814 mc_version=1.12.2 -mod_version=1.0.9 \ No newline at end of file +mod_version=1.0.10 \ No newline at end of file From 94a2e11f24a0e0f1f76ee2b0c23f5afd31f32eb0 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 4 Oct 2020 17:58:17 +0200 Subject: [PATCH 83/88] Fix #44 by throwing an IllegalStateException when a deadlock would happen Not the best fix but until i make something better, this fixes the game hanging Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/SoundPhysics.java | 15 ++++++++++++--- src/main/resources/META-INF/soundphysics_at.cfg | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 414d5f08..eeaaeb35 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -1,6 +1,7 @@ package com.sonicether.soundphysics; import java.util.regex.Pattern; +import java.util.concurrent.locks.ReentrantReadWriteLock; import org.lwjgl.openal.AL10; import org.lwjgl.openal.AL11; @@ -436,6 +437,15 @@ private static Vec3d offsetSoundByName(final double soundX, final double soundY, return new Vec3d(soundX + offsetX, soundY + offsetY, soundZ + offsetZ); } + private static float getPlayerEyeHeight() throws IllegalStateException { + ReentrantReadWriteLock lock = (ReentrantReadWriteLock)mc.player.getDataManager().lock; + if (lock.isWriteLocked()) { + logError("Deadlock detected, avoiding it by throwing exception"); + throw new IllegalStateException("Player's Data Mananger is write locked"); + } + return mc.player.getEyeHeight(); + } + @SuppressWarnings("deprecation") private static void evaluateEnvironment(final int sourceID, final float posX, final float posY, final float posZ, final SoundCategory category, final String name, ISound.AttenuationType attType) { @@ -459,7 +469,7 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi float directCutoff = 1.0f; final float absorptionCoeff = Config.globalBlockAbsorption * 3.0f; - final Vec3d playerPos = new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ); + final Vec3d playerPos = new Vec3d(mc.player.posX, mc.player.posY + getPlayerEyeHeight(), mc.player.posZ); final Vec3d soundPos = offsetSoundByName(posX, posY, posZ, playerPos, name, category); final Vec3d normalToPlayer = playerPos.subtract(soundPos).normalize(); @@ -708,8 +718,7 @@ private static void evaluateEnvironment(final int sourceID, final float posX, fi setEnvironment(sourceID, sendGain0, sendGain1, sendGain2, sendGain3, sendCutoff0, sendCutoff1, sendCutoff2, sendCutoff3, directCutoff, directGain, airAbsorptionFactor); } catch(Exception e) { - logError("Error while evaluation environment:"); - e.printStackTrace(); + logger.error("Error while evaluation environment:", e); setEnvironment(sourceID, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); } } diff --git a/src/main/resources/META-INF/soundphysics_at.cfg b/src/main/resources/META-INF/soundphysics_at.cfg index 3d5e5a73..c651c639 100644 --- a/src/main/resources/META-INF/soundphysics_at.cfg +++ b/src/main/resources/META-INF/soundphysics_at.cfg @@ -1 +1,2 @@ -public net.minecraft.util.SoundEvent field_187506_b # soundName \ No newline at end of file +public net.minecraft.util.SoundEvent field_187506_b # soundName +public net.minecraft.network.datasync.EntityDataManager field_187235_d # lock \ No newline at end of file From 5ffb68b33fe45347a28132ee928c2f37f8816c6b Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 4 Oct 2020 18:03:33 +0200 Subject: [PATCH 84/88] 1.0.10-1 Release Signed-off-by: djpadbit --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index de6437d7..bc130608 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ forge_version=14.23.5.2847 mcp_mappings=snapshot_20180814 mc_version=1.12.2 -mod_version=1.0.10 \ No newline at end of file +mod_version=1.0.10-1 \ No newline at end of file From df7c7ab77c82f131cae260f3788c808213c4f31b Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sun, 8 Nov 2020 18:34:39 +0100 Subject: [PATCH 85/88] Added Gibly's VC patching Doesn't actually give reverb to voices but fixes Sound Physics so it works with it Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 5 ++- .../soundphysics/CoreModInjector.java | 31 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index d14036e4..8fb9d17f 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -58,8 +58,9 @@ public class Config { public static boolean midnightPatching; public static boolean midnightPatchingFix; public static boolean ic2Patching; + public static boolean giblyVCPatching; public static boolean autoSteroDownmix; - + // misc public static boolean autoSteroDownmixLogging; public static boolean injectorLogging; @@ -184,6 +185,8 @@ private void syncConfig() { "If true, readds The Midnight reverb that is removed with the patch."); ic2Patching = this.forgeConfig.getBoolean("Patch IC2", categoryCompatibility, true, "REQUIRES RESTART. If true, patches IC2 audio to better work with Sound Physics."); + giblyVCPatching = this.forgeConfig.getBoolean("Patch Gibly's Voice Chat", categoryCompatibility, true, + "REQUIRES RESTART. If true, patches Gibly's VC's copied soundsystem classes to restore Sound Physics."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto Stereo Downmix", categoryCompatibility, true, "REQUIRES RESTART. If true, Automatically downmix stereo sounds that are loaded to mono"); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index 20f38800..d423260f 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -88,26 +88,32 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, -1); } else - if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL")) { + if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL") || + (obfuscated.equals("ovr.paulscode.sound.libraries.SourceLWJGLOpenAL") && Config.giblyVCPatching)) { + final String classPath = obfuscated.replace(".","/"); + String channelPath = "paulscode/sound/libraries/ChannelLWJGLOpenAL"; + if (obfuscated.equals("ovr.paulscode.sound.libraries.SourceLWJGLOpenAL")) + channelPath = "ovr/"+channelPath; + // Inside SourceLWJGLOpenAL InsnList toInject = new InsnList(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/libraries/SourceLWJGLOpenAL", "position", + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, classPath, "position", "Lpaulscode/sound/Vector3D;")); toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/Vector3D", "x", "F")); toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/libraries/SourceLWJGLOpenAL", "position", + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, classPath, "position", "Lpaulscode/sound/Vector3D;")); toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/Vector3D", "y", "F")); toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/libraries/SourceLWJGLOpenAL", "position", + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, classPath, "position", "Lpaulscode/sound/Vector3D;")); toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/Vector3D", "z", "F")); toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/libraries/SourceLWJGLOpenAL", - "channelOpenAL", "Lpaulscode/sound/libraries/ChannelLWJGLOpenAL;")); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/libraries/ChannelLWJGLOpenAL", "ALSource", + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, classPath, + "channelOpenAL", "L"+channelPath+";")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, channelPath, "ALSource", "Ljava/nio/IntBuffer;")); toInject.add(new InsnNode(Opcodes.ICONST_0)); toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/nio/IntBuffer", "get", "(I)I", false)); @@ -120,7 +126,8 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte } else // Convert stero sounds to mono - if (obfuscated.equals("paulscode.sound.libraries.LibraryLWJGLOpenAL") && Config.autoSteroDownmix) { + if ((obfuscated.equals("paulscode.sound.libraries.LibraryLWJGLOpenAL") || + (obfuscated.equals("ovr.paulscode.sound.libraries.LibraryLWJGLOpenAL") && Config.giblyVCPatching)) && Config.autoSteroDownmix) { // Inside LibraryLWJGLOpenAL InsnList toInject = new InsnList(); @@ -140,17 +147,17 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte toInject = new InsnList(); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 2)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "onLoadSound", "(Lpaulscode/sound/SoundBuffer;Ljava/lang/String;)Lpaulscode/sound/SoundBuffer;", false)); - toInject.add(new VarInsnNode(Opcodes.ASTORE, 0)); + toInject.add(new VarInsnNode(Opcodes.ASTORE, 1)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); // Target method: loadSound bytes = patchMethodInClass(obfuscated, bytes, "loadSound", "(Lpaulscode/sound/SoundBuffer;Ljava/lang/String;)Z", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "getChannels", null, -1, toInject, true, 0, 0, false, -12, -1); + AbstractInsnNode.METHOD_INSN, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", -1, toInject, true, 0, 0, false, 0, 0); } else if (obfuscated.equals("paulscode.sound.SoundSystem")) { From f1648ae748405f61f95fa0a7cd7e1add7b2c6c7d Mon Sep 17 00:00:00 2001 From: djpadbit Date: Mon, 9 Nov 2020 20:43:27 +0100 Subject: [PATCH 86/88] Added Patching for Gliby's VC Sources So now Gliby VC is affected by Sound Physics Also fixed spelling, it's Gliby not Gibly Signed-off-by: djpadbit --- .../com/sonicether/soundphysics/Config.java | 9 +- .../soundphysics/CoreModInjector.java | 198 +++++++++++++++++- .../sonicether/soundphysics/SoundPhysics.java | 40 +++- 3 files changed, 239 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/Config.java b/src/main/java/com/sonicether/soundphysics/Config.java index 8fb9d17f..97498ce5 100644 --- a/src/main/java/com/sonicether/soundphysics/Config.java +++ b/src/main/java/com/sonicether/soundphysics/Config.java @@ -58,7 +58,8 @@ public class Config { public static boolean midnightPatching; public static boolean midnightPatchingFix; public static boolean ic2Patching; - public static boolean giblyVCPatching; + public static boolean glibyVCPatching; + public static boolean glibyVCSrcPatching; public static boolean autoSteroDownmix; // misc @@ -185,8 +186,10 @@ private void syncConfig() { "If true, readds The Midnight reverb that is removed with the patch."); ic2Patching = this.forgeConfig.getBoolean("Patch IC2", categoryCompatibility, true, "REQUIRES RESTART. If true, patches IC2 audio to better work with Sound Physics."); - giblyVCPatching = this.forgeConfig.getBoolean("Patch Gibly's Voice Chat", categoryCompatibility, true, - "REQUIRES RESTART. If true, patches Gibly's VC's copied soundsystem classes to restore Sound Physics."); + glibyVCPatching = this.forgeConfig.getBoolean("Patch Gliby's Voice Chat", categoryCompatibility, true, + "REQUIRES RESTART. If true, patches Gliby's VC's copied soundsystem classes to restore Sound Physics."); + glibyVCSrcPatching = this.forgeConfig.getBoolean("Patch Gliby's VC sources", categoryCompatibility, true, + "REQUIRES RESTART. If true, patches Gliby's VC sources to work with Sound Physics."); autoSteroDownmix = this.forgeConfig.getBoolean("Auto Stereo Downmix", categoryCompatibility, true, "REQUIRES RESTART. If true, Automatically downmix stereo sounds that are loaded to mono"); diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index d423260f..fbbc6bcd 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -89,7 +89,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte } else if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL") || - (obfuscated.equals("ovr.paulscode.sound.libraries.SourceLWJGLOpenAL") && Config.giblyVCPatching)) { + (obfuscated.equals("ovr.paulscode.sound.libraries.SourceLWJGLOpenAL") && Config.glibyVCPatching)) { final String classPath = obfuscated.replace(".","/"); String channelPath = "paulscode/sound/libraries/ChannelLWJGLOpenAL"; if (obfuscated.equals("ovr.paulscode.sound.libraries.SourceLWJGLOpenAL")) @@ -127,7 +127,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Convert stero sounds to mono if ((obfuscated.equals("paulscode.sound.libraries.LibraryLWJGLOpenAL") || - (obfuscated.equals("ovr.paulscode.sound.libraries.LibraryLWJGLOpenAL") && Config.giblyVCPatching)) && Config.autoSteroDownmix) { + (obfuscated.equals("ovr.paulscode.sound.libraries.LibraryLWJGLOpenAL") && Config.glibyVCPatching)) && Config.autoSteroDownmix) { // Inside LibraryLWJGLOpenAL InsnList toInject = new InsnList(); @@ -257,6 +257,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Inside AudioPacket InsnList toInject = new InsnList(); + // This probably should only get multipled once, i don't know why i do it twice toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", "soundDistanceAllowance", "D")); toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", @@ -535,6 +536,199 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Target method: updateVolume bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.FCMPG, AbstractInsnNode.INSN, null, null, -1, toInject, false, 0, 0, true, 0, -1); + } else + + if (obfuscated.equals("net.gliby.voicechat.client.sound.ClientStreamManager") && Config.glibyVCSrcPatching) { + + InsnList toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/gliby/voicechat/common/PlayerProxy", "getPlayer", "()Lnet/minecraft/entity/Entity;", false)); + toInject.add(new InsnNode(Opcodes.ACONST_NULL)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "calculateEntitySoundOffset", "(Lvg;Lqe;)D", false)); + toInject.add(new InsnNode(Opcodes.D2F)); + toInject.add(new InsnNode(Opcodes.FADD)); + + // Target method: createStream + bytes = patchMethodInClass(obfuscated, bytes, "createStream", "(Lnet/gliby/voicechat/client/sound/Datalet;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "rawDataStream", null, -1, toInject, true, 0, 0, false, -8, 0); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "attenuationModel", "I")); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalRolloffFactor", "F")); + + // Target method: createStream + bytes = patchMethodInClass(obfuscated, bytes, "createStream", "(Lnet/gliby/voicechat/client/sound/Datalet;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "rawDataStream", null, -1, toInject, true, 6, 0, false, 0, 0); + + toInject = new InsnList(); + + toInject.add(new InsnNode(Opcodes.DUP)); + toInject.add(new VarInsnNode(Opcodes.ASTORE, 6)); + toInject.add(new InsnNode(Opcodes.ACONST_NULL)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "calculateEntitySoundOffset", "(Lvg;Lqe;)D", false)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 6)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/entity/EntityPlayerSP", "field_70163_u", "D")); + toInject.add(new InsnNode(Opcodes.DADD)); + + // Target method: createStream + bytes = patchMethodInClass(obfuscated, bytes, "createStream", "(Lnet/gliby/voicechat/client/sound/Datalet;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "rawDataStream", null, -1, toInject, true, 0, 0, true, -13, 1); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "attenuationModel", "I")); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalRolloffFactor", "F")); + + // Target method: createStream + bytes = patchMethodInClass(obfuscated, bytes, "createStream", "(Lnet/gliby/voicechat/client/sound/Datalet;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "rawDataStream", null, -1, toInject, true, 6, 0, false, 0, 1); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier0", "F")); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: createStream + bytes = patchMethodInClass(obfuscated, bytes, "createStream", "(Lnet/gliby/voicechat/client/sound/Datalet;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, 0); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier0", "F")); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: createStream + bytes = patchMethodInClass(obfuscated, bytes, "createStream", "(Lnet/gliby/voicechat/client/sound/Datalet;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, 1); + + toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 4)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "onPlaySound", "(Ljava/lang/String;)V", false)); + + // Target method: giveStream + bytes = patchMethodInClass(obfuscated, bytes, "giveStream", "(Lnet/gliby/voicechat/client/sound/Datalet;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "feedRawAudioData", null, -1, toInject, false, 0, 0, false, 0, -1); + + } else + + if (obfuscated.equals("net.gliby.voicechat.client.sound.thread.ThreadUpdateStream") && Config.glibyVCSrcPatching) { + + InsnList toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier0", "F")); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: run + bytes = patchMethodInClass(obfuscated, bytes, "run", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, 0); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier0", "F")); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: run + bytes = patchMethodInClass(obfuscated, bytes, "run", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, 1); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "attenuationModel", "I")); + + // Target method: run + bytes = patchMethodInClass(obfuscated, bytes, "run", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setAttenuation", null, -1, toInject, true, 1, 0, false, 0, -1); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalRolloffFactor", "F")); + + // Target method: run + bytes = patchMethodInClass(obfuscated, bytes, "run", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setDistOrRoll", null, -1, toInject, true, 5, 0, false, 0, -1); + + toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 3)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "net/gliby/voicechat/client/sound/ClientStream", "player", "Lnet/gliby/voicechat/common/PlayerProxy;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/gliby/voicechat/common/PlayerProxy", "getPlayer", "()Lnet/minecraft/entity/Entity;", false)); + toInject.add(new InsnNode(Opcodes.ACONST_NULL)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "calculateEntitySoundOffset", "(Lvg;Lqe;)D", false)); + toInject.add(new InsnNode(Opcodes.D2F)); + toInject.add(new InsnNode(Opcodes.FADD)); + + // Target method: createStream + bytes = patchMethodInClass(obfuscated, bytes, "run", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setPosition", null, -1, toInject, true, 0, 0, false, -2, 0); + + toInject = new InsnList(); + + toInject.add(new InsnNode(Opcodes.DUP)); + toInject.add(new VarInsnNode(Opcodes.ASTORE, 7)); + toInject.add(new InsnNode(Opcodes.ACONST_NULL)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "calculateEntitySoundOffset", "(Lvg;Lqe;)D", false)); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 7)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/entity/EntityPlayerSP", "field_70163_u", "D")); + toInject.add(new InsnNode(Opcodes.DADD)); + + // Target method: createStream + bytes = patchMethodInClass(obfuscated, bytes, "run", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setPosition", null, -1, toInject, true, 0, 0, true, -7, 1); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier0", "F")); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: run + bytes = patchMethodInClass(obfuscated, bytes, "run", "()V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, 2); + + } else + + if (obfuscated.equals("net.gliby.voicechat.common.networking.ServerStreamManager") && Config.glibyVCSrcPatching) { + + InsnList toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new InsnNode(Opcodes.DMUL)); + + // Target method: feedWithinEntityWithRadius + bytes = patchMethodInClass(obfuscated, bytes, "feedWithinEntityWithRadius", + "(Lnet/gliby/voicechat/common/networking/ServerStream;Lnet/gliby/voicechat/common/networking/ServerDatalet;)V", + Opcodes.DCMPG, AbstractInsnNode.INSN, null, null, -1, toInject, true, 0, 0, false, 0, 0); + + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new InsnNode(Opcodes.DMUL)); + + // Target method: feedWithinEntityWithRadius + bytes = patchMethodInClass(obfuscated, bytes, "feedWithinEntityWithRadius", + "(Lnet/gliby/voicechat/common/networking/ServerStream;Lnet/gliby/voicechat/common/networking/ServerDatalet;)V", + Opcodes.DCMPG, AbstractInsnNode.INSN, null, null, -1, toInject, true, 0, 0, false, 0, 1); + } //log("Finished processing class: '"+obfuscated+"' ('"+deobfuscated+"')"); diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index eeaaeb35..cafbb106 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -3,6 +3,12 @@ import java.util.regex.Pattern; import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.ByteOrder; + +import javax.sound.sampled.AudioFormat; + import org.lwjgl.openal.AL10; import org.lwjgl.openal.AL11; import org.lwjgl.openal.ALC10; @@ -30,16 +36,18 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + import paulscode.sound.SoundSystemConfig; import paulscode.sound.SoundSystem; import paulscode.sound.SoundBuffer; -import javax.sound.sampled.AudioFormat; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; +import paulscode.sound.Library; +import paulscode.sound.Source; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.commons.lang3.reflect.FieldUtils; + @Mod(modid = SoundPhysics.modid, clientSideOnly = true, acceptedMinecraftVersions = SoundPhysics.mcVersion, version = SoundPhysics.version, guiFactory = "com.sonicether.soundphysics.SPGuiFactory") public class SoundPhysics { @@ -263,6 +271,32 @@ public static void onPlaySound(final float posX, final float posY, final float p onPlaySound(posX, posY, posZ, sourceID, lastSoundCategory, lastSoundName, lastSoundAtt); } + /** + * CALLED BY ASM INJECTED CODE! + */ + // For Gliby's VC, sound system source id + // This is kind of hacked together, it's not great + public static void onPlaySound(final String id) { + try { // Getting the sound library here is not ideal but i can't really do better because gibly changes it after startup + Library sndLibrary = (Library)FieldUtils.readField(sndSystem,"soundLibrary",true); + if (sndLibrary == null) + return; + + Source src = sndLibrary.getSource(id); + if (src == null || src.channel == null) + return; + + IntBuffer srcid = (IntBuffer)FieldUtils.readField(src.channel,"ALSource"); + if (srcid == null) + return; + + onPlaySound(src.position.x, src.position.y, src.position.z, srcid.get(0), SoundCategory.PLAYERS, id, ISound.AttenuationType.LINEAR); + } catch (Exception e) { + logError("Error trying to get source info"); + logError(e.toString()); + } + } + /** * CALLED BY ASM INJECTED CODE! */ From 2da4ae9bf28ef2c48dbcb8d95da72ebaa08f27e7 Mon Sep 17 00:00:00 2001 From: djpadbit Date: Sat, 21 Nov 2020 22:07:16 +0100 Subject: [PATCH 87/88] Added IC2 Classic compatibility Signed-off-by: djpadbit --- .../soundphysics/CoreModInjector.java | 204 ++++++++++++------ .../sonicether/soundphysics/SoundPhysics.java | 24 ++- 2 files changed, 164 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java index fbbc6bcd..c1c6a8c7 100644 --- a/src/main/java/com/sonicether/soundphysics/CoreModInjector.java +++ b/src/main/java/com/sonicether/soundphysics/CoreModInjector.java @@ -50,6 +50,16 @@ private static boolean shouldPatchDS(boolean checkNew) { return false; } + private static boolean isIC2Classic() { + if (Loader.isModLoaded("ic2")) { + Map mods = Loader.instance().getIndexedModList(); + String version = mods.get("ic2").getVersion(); + if (version.endsWith("ex112")) return false; + return true; + } + return false; + } + @Override public byte[] transform(final String obfuscated, final String deobfuscated, byte[] bytes) { if (obfuscated.equals("chm$a")) { @@ -90,14 +100,14 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte if (obfuscated.equals("paulscode.sound.libraries.SourceLWJGLOpenAL") || (obfuscated.equals("ovr.paulscode.sound.libraries.SourceLWJGLOpenAL") && Config.glibyVCPatching)) { + // Inside SourceLWJGLOpenAL + InsnList toInject = new InsnList(); + final String classPath = obfuscated.replace(".","/"); String channelPath = "paulscode/sound/libraries/ChannelLWJGLOpenAL"; if (obfuscated.equals("ovr.paulscode.sound.libraries.SourceLWJGLOpenAL")) channelPath = "ovr/"+channelPath; - // Inside SourceLWJGLOpenAL - InsnList toInject = new InsnList(); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); toInject.add(new FieldInsnNode(Opcodes.GETFIELD, classPath, "position", "Lpaulscode/sound/Vector3D;")); @@ -430,19 +440,31 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Inside AudioManagerClient InsnList toInject = new InsnList(); + final boolean ic2Classic = isIC2Classic(); + String posSpecClass = "ic2/core/audio/PositionSpec"; + String playOnceDesc = "(Ljava/lang/Object;Lic2/core/audio/PositionSpec;Ljava/lang/String;ZF)Ljava/lang/String;"; + int quickPlayRemoveCnt = 7; + if (ic2Classic) { + posSpecClass = "ic2/api/classic/audio/PositionSpec"; + playOnceDesc = "(Ljava/lang/Object;Lic2/api/classic/audio/PositionSpec;Lnet/minecraft/util/ResourceLocation;ZF)V"; + quickPlayRemoveCnt = 6; + } + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", "attenuationModel", "I")); toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", "globalRolloffFactor", "F")); toInject.add(new VarInsnNode(Opcodes.ALOAD, 2)); - toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ic2/core/audio/PositionSpec", "ordinal", "()I", false)); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, posSpecClass, "ordinal", "()I", false)); toInject.add(new VarInsnNode(Opcodes.ALOAD, 3)); + if (ic2Classic)//toString + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "nf", "func_110623_a", "()Ljava/lang/String;", false)); toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "setLastSound", "(ILjava/lang/String;)V", false)); // Target method: playOnce - bytes = patchMethodInClass(obfuscated, bytes, "playOnce", "(Ljava/lang/Object;Lic2/core/audio/PositionSpec;Ljava/lang/String;ZF)Ljava/lang/String;", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "quickPlay", null, -1, toInject, true, 7, 0, false, 0, -1); + bytes = patchMethodInClass(obfuscated, bytes, "playOnce", playOnceDesc, Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "quickPlay", null, -1, toInject, true, quickPlayRemoveCnt, 0, false, 0, -1); toInject = new InsnList(); @@ -450,7 +472,7 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte "applyGlobalVolumeMultiplier", "(F)F", false)); // Target method: playOnce - bytes = patchMethodInClass(obfuscated, bytes, "playOnce", "(Ljava/lang/Object;Lic2/core/audio/PositionSpec;Ljava/lang/String;ZF)Ljava/lang/String;", Opcodes.INVOKEVIRTUAL, + bytes = patchMethodInClass(obfuscated, bytes, "playOnce", playOnceDesc, Opcodes.INVOKEVIRTUAL, AbstractInsnNode.METHOD_INSN, "setVolume", null, -1, toInject, true, 0, 0, false, 0, -1); } else @@ -458,13 +480,29 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte // Inside AudioSourceClient InsnList toInject = new InsnList(); + final boolean ic2Classic = isIC2Classic(); + String posSpecClass = "ic2/core/audio/PositionSpec"; + String audioPosClass = "ic2/core/audio/AudioPosition"; + String posSpecField = "positionSpec"; + int cmpgType = Opcodes.FCMPG; + if (ic2Classic) { + posSpecClass = "ic2/api/classic/audio/PositionSpec"; + audioPosClass = "ic2/api/classic/audio/IAudioPosition"; + posSpecField = "soundType"; + cmpgType = Opcodes.DCMPG; + } + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "positionSpec", - "Lic2/core/audio/PositionSpec;")); - toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "ic2/core/audio/PositionSpec", "ordinal", "()I", false)); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "initialSoundFile", - "Ljava/lang/String;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", posSpecField, + "L"+posSpecClass+";")); + toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, posSpecClass, "ordinal", "()I", false)); + if (ic2Classic) { + toInject.add(new InsnNode(Opcodes.ACONST_NULL)); + } else { + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "initialSoundFile", + "Ljava/lang/String;")); + } toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", "setLastSound", "(ILjava/lang/String;)V", false)); @@ -472,69 +510,109 @@ public byte[] transform(final String obfuscated, final String deobfuscated, byte bytes = patchMethodInClass(obfuscated, bytes, "play", "()V", Opcodes.INVOKEVIRTUAL, AbstractInsnNode.METHOD_INSN, "play", null, -1, toInject, true, 0, 0, false, 0, -1); - toInject = new InsnList(); - - toInject.add(new InsnNode(Opcodes.FCONST_1)); - - // Target method: updateVolume - bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "getMasterVolume", null, -1, toInject, false, 0, 0, true, -5, 0); - - toInject = new InsnList(); + if (ic2Classic) { + toInject = new InsnList(); - /*toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", - "globalVolumeMultiplier0", "F"));*/ - toInject.add(new InsnNode(Opcodes.FCONST_1)); + /*toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier0", "F")); + toInject.add(new InsnNode(Opcodes.FMUL));*/ - // Target method: updateVolume - bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "getMasterVolume", null, -1, toInject, false, 1, 0, true, 0, 1); + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEINTERFACE, + AbstractInsnNode.METHOD_INSN, "getPosition", null, -1, toInject, true, 14, 0, false, -17, 1); + } else { + toInject = new InsnList(); - toInject = new InsnList(); + toInject.add(new InsnNode(Opcodes.FCONST_1)); - toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", - "soundDistanceAllowance", "D")); - toInject.add(new InsnNode(Opcodes.D2F)); - toInject.add(new InsnNode(Opcodes.FMUL)); + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "getMasterVolume", null, -1, toInject, false, 0, 0, true, -5, 0); - // Target method: updateVolume - bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKESTATIC, - AbstractInsnNode.METHOD_INSN, "max", null, -1, toInject, false, 0, 0, false, 1, -1); + toInject = new InsnList(); - toInject = new InsnList(); + /*toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "globalVolumeMultiplier0", "F"));*/ + toInject.add(new InsnNode(Opcodes.FCONST_1)); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); - toInject.add(new InsnNode(Opcodes.ACONST_NULL)); - toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "calculateEntitySoundOffset", "(Lvg;Lqe;)D", false)); - toInject.add(new InsnNode(Opcodes.DADD)); + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "getMasterVolume", null, -1, toInject, false, 1, 0, true, 0, 1); + } - // Target method: updateVolume - bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, - AbstractInsnNode.METHOD_INSN, "getWorld", null, -1, toInject, true, 0, 0, false, -15, -1); // -11 without labels + if (ic2Classic) { + toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + toInject.add(new InsnNode(Opcodes.ACONST_NULL)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "calculateEntitySoundOffsetVec", "(Lbhe;Lvg;Lqe;)Lbhe;", false)); + toInject.add(new VarInsnNode(Opcodes.DLOAD, 3)); + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new InsnNode(Opcodes.DMUL)); + toInject.add(new VarInsnNode(Opcodes.DSTORE, 3)); + + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "func_174791_d", null, -1, toInject, false, 0, 0, false, 0, -1); + } else { + toInject = new InsnList(); + + toInject.add(new FieldInsnNode(Opcodes.GETSTATIC, "com/sonicether/soundphysics/SoundPhysics", + "soundDistanceAllowance", "D")); + toInject.add(new InsnNode(Opcodes.D2F)); + toInject.add(new InsnNode(Opcodes.FMUL)); + + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKESTATIC, + AbstractInsnNode.METHOD_INSN, "max", null, -1, toInject, false, 0, 0, false, 1, -1); + + toInject = new InsnList(); + + toInject.add(new VarInsnNode(Opcodes.ALOAD, 1)); + toInject.add(new InsnNode(Opcodes.ACONST_NULL)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "calculateEntitySoundOffset", "(Lvg;Lqe;)D", false)); + toInject.add(new InsnNode(Opcodes.DADD)); + + // Target method: updateVolume + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.INVOKEVIRTUAL, + AbstractInsnNode.METHOD_INSN, "getWorld", null, -1, toInject, true, 0, 0, false, -15, -1); // -11 without labels + } toInject = new InsnList(); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", - "Lic2/core/audio/AudioPosition;")); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "x", "F")); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", - "Lic2/core/audio/AudioPosition;")); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "y", "F")); - toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", - "Lic2/core/audio/AudioPosition;")); - toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "z", "F")); - toInject.add(new VarInsnNode(Opcodes.FLOAD, 6)); - toInject.add(new VarInsnNode(Opcodes.FLOAD, 7)); - toInject.add(new VarInsnNode(Opcodes.FLOAD, 8)); - toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", - "ic2DistanceCheckHook", "(FFFFFFFF)I", false)); + if (ic2Classic) { + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", + "Lic2/api/classic/audio/IAudioPosition;")); + toInject.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "ic2/api/classic/audio/IAudioPosition", + "getPosition", "()Lnet/minecraft/util/math/Vec3d;")); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 7)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "ic2DistanceCheckHook", "(DDLbhe;Lbhe;)I", false)); + } else { + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", + "Lic2/core/audio/AudioPosition;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "x", "F")); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", + "Lic2/core/audio/AudioPosition;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "y", "F")); + toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioSourceClient", "position", + "Lic2/core/audio/AudioPosition;")); + toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "ic2/core/audio/AudioPosition", "z", "F")); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 6)); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 7)); + toInject.add(new VarInsnNode(Opcodes.FLOAD, 8)); + toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/sonicether/soundphysics/SoundPhysics", + "ic2DistanceCheckHook", "(FFFFFFFF)I", false)); + } // Target method: updateVolume - bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", Opcodes.FCMPG, + bytes = patchMethodInClass(obfuscated, bytes, "updateVolume", "(Lnet/minecraft/entity/player/EntityPlayer;)V", cmpgType, AbstractInsnNode.INSN, null, null, -1, toInject, false, 0, 0, true, 0, -1); } else diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index cafbb106..24fc2afb 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -235,7 +235,10 @@ public static void setLastSound(final SoundCategory sc, final String soundName) // For IC2 public static void setLastSound(final int position, final String soundName) { lastSoundCategory = position == 0 ? SoundCategory.BLOCKS : SoundCategory.PLAYERS; - lastSoundName = "ic2:"+soundName; + if (soundName != null) + lastSoundName = "ic2:"+soundName; + else // Can't get easliy get sound name for normal IC2 Classic sources + lastSoundName = "ic2"; lastSoundAtt = ISound.AttenuationType.LINEAR; } @@ -251,6 +254,18 @@ public static int ic2DistanceCheckHook(float i, float dst, float x1, float y1, f return -1; } + /** + * CALLED BY ASM INJECTED CODE! + */ + public static int ic2DistanceCheckHook(double i, double dst, Vec3d p1, Vec3d p2) { + if (i >= dst || + (MathHelper.floor(p1.x) == MathHelper.floor(p2.x) && + MathHelper.floor(p1.y) == MathHelper.floor(p2.y) && + MathHelper.floor(p1.z) == MathHelper.floor(p2.z))) return 1; + if (dst == i) return 0; + return -1; + } + /** * CALLED BY ASM INJECTED CODE! */ @@ -359,6 +374,13 @@ public static double calculateEntitySoundOffset(final Entity entity, final Sound return entity.getEyeHeight(); } + /** + * CALLED BY ASM INJECTED CODE! + */ + public static Vec3d calculateEntitySoundOffsetVec(final Vec3d pos, final Entity entity, final SoundEvent sound) { + return new Vec3d(pos.x,pos.y+calculateEntitySoundOffset(entity,sound),pos.z); + } + /** * CALLED BY ASM INJECTED CODE! */ From 4641cd185310a1e3e809f062e424e47165954f9f Mon Sep 17 00:00:00 2001 From: djpadbit Date: Thu, 31 Dec 2020 20:28:46 +0100 Subject: [PATCH 88/88] Fix hacky fix to fix #52 Signed-off-by: djpadbit --- src/main/java/com/sonicether/soundphysics/SoundPhysics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java index 24fc2afb..ad15b7aa 100644 --- a/src/main/java/com/sonicether/soundphysics/SoundPhysics.java +++ b/src/main/java/com/sonicether/soundphysics/SoundPhysics.java @@ -217,7 +217,7 @@ public static void setLastSound(final ISound snd, final SoundCategory sc, final lastSoundCategory = getSoundCategory(sc,lastSoundName); lastSoundAtt = snd.getAttenuationType(); if (snd instanceof MovingSound) // Hacky fix until i properly do moving sounds (I'm currently thinking about how) - lastSoundCategory = SoundCategory.MASTER; // because all (at least vanilla) moving sounds don't init their position when played + lastSoundCategory = SoundCategory.RECORDS;// because all (at least vanilla) moving sounds don't init their position when played } /**