Remove instances of Miles in compiled build, implement simple Filesystem module and remove BinkDecoder

This commit is contained in:
GuglioIsStupid 2026-03-03 11:20:21 -05:00
parent 07ba01afed
commit 1aefbf347e
8 changed files with 171 additions and 1005 deletions

View file

@ -60,6 +60,10 @@ if(MSVC)
target_link_options(MinecraftClient PRIVATE
$<$<CONFIG:Release>:/LTCG /INCREMENTAL:NO>
)
# TEMP!
target_compile_options(MinecraftClient PRIVATE
$<$<COMPILE_LANGUAGE:C,CXX>:/wd4100 /wd4101 /wd4189 /wd4324 /wd4267 /wd4365 /wd4244 /wd4477 /wd4625 /wd4626 /wd4628 /wd5026 /wd5027>
)
endif()
set_target_properties(MinecraftClient PROPERTIES
@ -75,7 +79,7 @@ target_link_libraries(MinecraftClient PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Iggy/lib/iggy_w64.lib"
"${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Iggy/lib/iggyperfmon_w64.lib"
"${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Iggy/lib/iggyexpruntime_w64.lib"
"${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Miles/lib/mss64.lib"
#"${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Miles/lib/mss64.lib"
$<$<CONFIG:Debug>:
"${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/4JLibs/libs/4J_Input_d.lib"
"${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/4JLibs/libs/4J_Storage_d.lib"

View file

@ -1,173 +0,0 @@
#ifdef _WINDOWS64
#include "BinkDecoder.h"
#include <cmath>
#include <cstring>
#include <algorithm>
// Heavily referenced from https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/binkaudio.c
// and https://wiki.multimedia.cx/index.php?title=Bink_Audio
#define M_PI 3.14159265358979323846
static const int critical_freqs[25] = {
100, 200, 300, 400, 510, 630, 770, 920,
1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150,
3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500, 24500
};
static const int rle_lengths[16] = {2,3,4,5,6,8,9,10,11,12,13,14,15,16,32,64};
BinkDecoder::BinkDecoder()
: fileOpen(false), sampleRate(0), channels(0), frameLength(0), windowLength(0),
transform(TransformType::DCT)
{
prevBuffer[0].resize(8192, 0.0f);
prevBuffer[1].resize(8192, 0.0f);
}
BinkDecoder::~BinkDecoder() { close(); }
bool BinkDecoder::open(const std::string& filename) {
close();
fileStream.open(filename, std::ios::binary);
if (!fileStream.is_open()) return false;
if (!parseHeader()) { fileStream.close(); return false; }
fileOpen = true;
return true;
}
void BinkDecoder::close() {
if (fileStream.is_open()) fileStream.close();
fileOpen = false;
}
bool BinkDecoder::parseHeader() {
uint32_t reportedSize = 0;
fileStream.read(reinterpret_cast<char*>(&reportedSize), sizeof(uint32_t));
if (fileStream.gcount() != 4 || reportedSize == 0) return false;
sampleRate = 44100;
channels = 2;
transform = TransformType::DCT;
if (sampleRate < 22050) frameLength = 2048;
else if (sampleRate < 44100) frameLength = 4096;
else frameLength = 8192;
windowLength = frameLength / 16;
return true;
}
float BinkDecoder::readFloat29() {
uint32_t raw = 0;
fileStream.read(reinterpret_cast<char*>(&raw), 4);
if (fileStream.gcount() != 4) return 0.0f;
int exponent = (raw >> 23) & 0x1F;
int mantissa = raw & 0x7FFFFF;
bool sign = (raw >> 31) != 0;
float value = ldexpf(static_cast<float>(mantissa), exponent - 23);
return sign ? -value : value;
}
bool BinkDecoder::readPacket(std::vector<uint8_t>& packet) {
uint32_t packetSize = 0;
fileStream.read(reinterpret_cast<char*>(&packetSize), 4);
if (fileStream.eof() || packetSize == 0) return false;
packet.resize(packetSize);
fileStream.read(reinterpret_cast<char*>(packet.data()), packetSize);
return fileStream.gcount() == static_cast<std::streamsize>(packetSize);
}
void BinkDecoder::applyDCT(std::vector<float>& coeffs) {
size_t N = coeffs.size();
std::vector<float> tmp(N, 0.0f);
for (size_t k = 0; k < N; k++) {
float sum = 0.0f;
for (size_t n = 0; n < N; n++)
sum += coeffs[n] * cosf(M_PI * (n + 0.5f) * k / N);
tmp[k] = sum;
}
coeffs = tmp;
}
void BinkDecoder::applyRDFT(std::vector<float>& coeffs) {
size_t N = coeffs.size();
std::vector<float> tmp(N, 0.0f);
for (size_t k = 0; k < N; k++) {
float sumRe = 0.0f;
float sumIm = 0.0f;
for (size_t n = 0; n < N; n++) {
float angle = 2.0f * M_PI * k * n / N;
sumRe += coeffs[n] * cosf(angle);
sumIm -= coeffs[n] * sinf(angle);
}
tmp[k] = sumRe;
}
coeffs = tmp;
}
void BinkDecoder::decodeBlock(const std::vector<uint8_t>& packet, std::vector<std::vector<float>>& output) {
size_t bitPos = 0;
auto readBit = [&]() -> bool {
if (bitPos / 8 >= packet.size()) return 0;
bool b = (packet[bitPos / 8] >> (7 - (bitPos % 8))) & 1;
bitPos++;
return b;
};
auto readBits = [&](int n) -> uint32_t {
uint32_t val = 0;
for (int i = 0; i < n; i++) val = (val << 1) | readBit();
return val;
};
std::vector<float> coeffs(frameLength, 0.0f);
std::vector<float> quant(25, 0.0f);
for (uint32_t ch = 0; ch < channels; ch++) {
coeffs[0] = readFloat29();
coeffs[1] = readFloat29();
for (int i = 0; i < 25; i++) {
int value = readBits(8);
quant[i] = powf(10.0f, std::min(value,95) * 0.0664f);
}
int i = 2, k = 0;
while (i < static_cast<int>(frameLength)) {
int width = readBits(4);
if (width == 0) { i++; continue; }
while (i < static_cast<int>(frameLength)) {
if (i >= critical_freqs[k]) k++;
int coeff = readBits(width);
coeffs[i] = readBit() ? -coeff * quant[k] : coeff * quant[k];
i++;
}
}
if (transform == TransformType::DCT) applyDCT(coeffs);
else applyRDFT(coeffs);
for (uint32_t w = 0; w < windowLength; w++)
output[ch][w] = (prevBuffer[ch][w] * (windowLength - w) + coeffs[w] * w) / windowLength;
for (uint32_t s = windowLength; s < frameLength; s++)
output[ch][s] = coeffs[s];
std::copy(coeffs.end() - windowLength, coeffs.end(), prevBuffer[ch].begin());
}
}
int BinkDecoder::decodeFrame(std::vector<std::vector<float>>& output) {
if (!fileOpen) return -1;
std::vector<uint8_t> packet;
if (!readPacket(packet)) return -1;
output.resize(channels);
for (auto& buf : output) buf.resize(frameLength, 0.0f);
decodeBlock(packet, output);
return static_cast<int>(frameLength);
}
#endif

View file

@ -1,54 +0,0 @@
#pragma once
#ifdef _WINDOWS64
#include <fstream>
#include <vector>
#include <cstdint>
#include <string>
class BinkDecoder
{
public:
enum class TransformType {
DCT,
RDFT
};
BinkDecoder();
~BinkDecoder();
bool open(const std::string& filename);
void close();
int decodeFrame(std::vector<std::vector<float>>& output);
bool isOpen() const { return fileOpen; }
uint32_t getSampleRate() const { return sampleRate; }
uint32_t getChannels() const { return channels; }
uint32_t getFrameLength() const { return frameLength; }
TransformType getTransform() const { return transform; }
private:
std::ifstream fileStream;
bool fileOpen;
uint32_t sampleRate;
uint32_t channels;
uint32_t frameLength;
uint32_t windowLength;
TransformType transform;
std::vector<float> prevBuffer[2];
bool parseHeader();
float readFloat29();
bool readPacket(std::vector<uint8_t>& packet);
void decodeBlock(const std::vector<uint8_t>& packet, std::vector<std::vector<float>>& output);
void applyDCT(std::vector<float>& coeffs);
void applyRDFT(std::vector<float>& coeffs);
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -6,10 +6,6 @@ using namespace std;
#include "miniaudio.h"
#ifdef _WINDOWS64
#include "BinkDecoder.h"
#endif
enum eMUSICFILES
{
eStream_Overworld_Calm1 = 0,
@ -105,8 +101,6 @@ struct MiniAudioSound
};
extern std::vector<MiniAudioSound*> m_activeSounds;
bool FileExists(const char* path);
#endif
class SoundEngine : public ConsoleSoundEngine
@ -153,17 +147,11 @@ private:
int GetRandomishTrack(int iStart,int iEnd);
#ifdef _WINDOWS64
ma_engine m_engine;
ma_engine_config m_engineConfig;
ma_sound m_musicStream;
bool m_musicStreamActive;
BinkDecoder *binkaDecoder;
#else
HMSOUNDBANK m_hBank;
HDIGDRIVER m_hDriver;
HSTREAM m_hStream;
#endif
ma_engine m_engine;
ma_engine_config m_engineConfig;
ma_sound m_musicStream;
bool m_musicStreamActive;
static char m_szSoundPath[];
static char m_szMusicPath[];
static char m_szRedistName[];

View file

@ -0,0 +1,73 @@
#include "Filesystem.h"
#ifdef _WINDOWS64
#include <windows.h>
#endif // TODO: More os' filesystem handling when we move away from only Windows
#include <stdio.h>
bool FileOrDirectoryExists(const char* path)
{
#ifdef _WINDOWS64
DWORD attribs = GetFileAttributesA(path);
return (attribs != INVALID_FILE_ATTRIBUTES);
#else
#error "FileOrDirectoryExists not implemented for this platform"
return false;
#endif
}
bool FileExists(const char* path)
{
#ifdef _WINDOWS64
DWORD attribs = GetFileAttributesA(path);
return (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY));
#else
#error "FileExists not implemented for this platform"
return false;
#endif
}
bool DirectoryExists(const char* path)
{
#ifdef _WINDOWS64
DWORD attribs = GetFileAttributesA(path);
return (attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY));
#else
#error "DirectoryExists not implemented for this platform"
return false;
#endif
}
bool GetFirstFileInDirectory(const char* directory, char* outFilePath, size_t outFilePathSize)
{
#ifdef _WINDOWS64
char searchPath[MAX_PATH];
snprintf(searchPath, MAX_PATH, "%s\\*", directory);
WIN32_FIND_DATAA findData;
HANDLE hFind = FindFirstFileA(searchPath, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
return false;
}
do
{
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
// Found a file, copy its path to the output buffer
snprintf(outFilePath, outFilePathSize, "%s\\%s", directory, findData.cFileName);
FindClose(hFind);
return true;
}
} while (FindNextFileA(hFind, &findData) != 0);
FindClose(hFind);
return false; // No files found in the directory
#else
#error "GetFirstFileInDirectory not implemented for this platform"
return false;
#endif
}

View file

@ -0,0 +1,6 @@
#pragma once
bool FileOrDirectoryExists(const char* path);
bool FileExists(const char* path);
bool DirectoryExists(const char* path);
bool GetFirstFileInDirectory(const char* directory, char* outFilePath, size_t outFilePathSize);

View file

@ -32,7 +32,6 @@ set(MINECRAFT_CLIENT_SOURCES
"Common/Audio/Consoles_SoundEngine.cpp"
"Common/Audio/SoundEngine.cpp"
"Common/Audio/SoundNames.cpp"
"Common/Audio/BinkDecoder.cpp"
"Common/Colours/ColourTable.cpp"
"Common/ConsoleGameMode.cpp"
"Common/Console_Utils.cpp"
@ -49,6 +48,7 @@ set(MINECRAFT_CLIENT_SOURCES
"Common/DLC/DLCSkinFile.cpp"
"Common/DLC/DLCTextureFile.cpp"
"Common/DLC/DLCUIDataFile.cpp"
"Common/Filesystem/Filesystem.cpp"
"Common/GameRules/AddEnchantmentRuleDefinition.cpp"
"Common/GameRules/AddItemRuleDefinition.cpp"
"Common/GameRules/ApplySchematicRuleDefinition.cpp"