Skip to content

Commit

Permalink
Migrated to SmSdk and 0.7.0.771 support
Browse files Browse the repository at this point in the history
  • Loading branch information
QuestionableM committed Dec 6, 2024
1 parent 733837f commit 0ba38a5
Show file tree
Hide file tree
Showing 103 changed files with 4,263 additions and 224 deletions.
37 changes: 18 additions & 19 deletions Code/Hooks/fmod_hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "fmod_hooks.hpp"

#include "SM/DirectoryManager.hpp"
#include "SM/AudioManager.hpp"
#include "SM/GameSettings.hpp"

#include "win_include.hpp"
#include <SmSdk/DirectoryManager.hpp>
#include <SmSdk/AudioManager.hpp>
#include <SmSdk/GameSettings.hpp>
#include <SmSdk/win_include.hpp>

#include "Utils/Console.hpp"
#include "Utils/File.hpp"
Expand All @@ -26,7 +25,7 @@ FMOD_RESULT FakeEventDescription::setPosition(float new_position)

FMOD_RESULT FakeEventDescription::updateVolume()
{
return this->channel->setVolume(this->custom_volume * SM::GameSettings::GetEffectsVolume());
return this->channel->setVolume(this->custom_volume * GameSettings::GetEffectsVolume());
}

void FakeEventDescription::updateReverbData()
Expand All @@ -37,13 +36,13 @@ void FakeEventDescription::updateReverbData()

void FakeEventDescription::playSound()
{
SM::AudioManager* v_audio_mgr = SM::AudioManager::GetInstance();
if (!v_audio_mgr || this->isPlaying()) return;
AudioManager* v_pAudioMgr = AudioManager::GetInstance();
if (!v_pAudioMgr || this->isPlaying()) return;

if (v_audio_mgr->fmod_system->playSound(this->sound, nullptr, true, &this->channel) != FMOD_OK)
if (v_pAudioMgr->fmod_system->playSound(this->sound, nullptr, true, &this->channel) != FMOD_OK)
return;

this->channel->setVolume(SM::GameSettings::GetEffectsVolume());
this->channel->setVolume(GameSettings::GetEffectsVolume());
this->channel->set3DMinMaxDistance(this->min_distance, this->max_distance);
this->channel->set3DDistanceFilter(false, 1.0f, 10000.0f);

Expand All @@ -61,15 +60,15 @@ FMOD::Sound* SoundStorage::CreateSound(const std::string& path)
if (v_iter != SoundStorage::PathHashToSound.end())
return v_iter->second;

SM::AudioManager* v_audio_mgr = SM::AudioManager::GetInstance();
if (!v_audio_mgr)
AudioManager* v_pAudioMgr = AudioManager::GetInstance();
if (!v_pAudioMgr)
{
DebugErrorL("AudioManager is not initialized!");
return nullptr;
}

FMOD::Sound* v_custom_sound;
if (v_audio_mgr->fmod_system->createSound(path.c_str(), FMOD_ACCURATETIME, nullptr, &v_custom_sound) != FMOD_OK)
if (v_pAudioMgr->fmod_system->createSound(path.c_str(), FMOD_ACCURATETIME, nullptr, &v_custom_sound) != FMOD_OK)
{
DebugErrorL("Couldn't load the specified sound file: ", path);
return nullptr;
Expand Down Expand Up @@ -529,19 +528,19 @@ static FMODHookData g_fmodHookData[] =

void FMODHooks::UpdateReverbProperties()
{
SM::AudioManager* v_audio_mgr = SM::AudioManager::GetInstance();
if (!v_audio_mgr) return;
AudioManager* v_pAudioMgr = AudioManager::GetInstance();
if (!v_pAudioMgr) return;

DebugOutL("Injecting reverb properties");

FMOD_REVERB_PROPERTIES v_reverb_preset = FMOD_PRESET_MOUNTAINS;
v_audio_mgr->fmod_system->setReverbProperties(0, &v_reverb_preset);
v_pAudioMgr->fmod_system->setReverbProperties(0, &v_reverb_preset);
FMOD_REVERB_PROPERTIES v_reverb_preset2 = FMOD_PRESET_CAVE;
v_audio_mgr->fmod_system->setReverbProperties(1, &v_reverb_preset2);
v_pAudioMgr->fmod_system->setReverbProperties(1, &v_reverb_preset2);
FMOD_REVERB_PROPERTIES v_reverb_preset3 = FMOD_PRESET_GENERIC;
v_audio_mgr->fmod_system->setReverbProperties(2, &v_reverb_preset3);
v_pAudioMgr->fmod_system->setReverbProperties(2, &v_reverb_preset3);
FMOD_REVERB_PROPERTIES v_reverb_preset4 = FMOD_PRESET_UNDERWATER;
v_audio_mgr->fmod_system->setReverbProperties(3, &v_reverb_preset4);
v_pAudioMgr->fmod_system->setReverbProperties(3, &v_reverb_preset4);
}

void FMODHooks::Hook()
Expand Down
6 changes: 3 additions & 3 deletions Code/Hooks/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "fmod_hooks.hpp"

#include "SM/DirectoryManager.hpp"
#include "SM/AudioManager.hpp"
#include <SmSdk/DirectoryManager.hpp>
#include <SmSdk/AudioManager.hpp>

#include "Utils/Console.hpp"
#include "Utils/String.hpp"
Expand Down Expand Up @@ -145,7 +145,7 @@ void preload_sounds(const std::string& shape_set_path)
}

std::string v_replacement;
if (!SM::DirectoryManager::GetReplacement(v_key, v_replacement))
if (!DirectoryManager::GetReplacement(v_key, v_replacement))
{
DebugErrorL("Couldn't find a replacement for: ", shape_set_path);
return;
Expand Down
14 changes: 6 additions & 8 deletions Code/Hooks/offsets.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#pragma once

#define GAME_VERSION 066
#define GAME_VERSION 070771

#if !defined(GAME_VERSION)
#error GAME_VERSION must be defined!
#endif

#if GAME_VERSION == 066
#if GAME_VERSION == 070771
#define OFF_LOAD_SHAPESETS_FUNCTION 0x599180
#define OFF_INIT_SHAPESET_MANAGER_FUNCTION 0x34DA90
#define OFF_INIT_LUA_MANAGER_FUNCTION 0x54A850
#elif GAME_VERSION == 066
#define OFF_LOAD_SHAPESETS_FUNCTION 0x5A6A60
#define OFF_INIT_SHAPESET_MANAGER_FUNCTION 0x359490
#define OFF_INIT_LUA_MANAGER_FUNCTION 0x55A640
#define OFF_AUDIO_MANAGER_PTR 0x128D720
#define OFF_DIRECTORY_MANAGER_PTR 0x128D8F0
#define OFF_GAME_SETTINGS_PTR 0x128D830
#elif GAME_VERSION == 065
#define OFF_LOAD_SHAPESETS_FUNCTION 0x5C4250
#define OFF_INIT_SHAPESET_MANAGER_FUNCTION 0x378170
#define OFF_INIT_LUA_MANAGER_FUNCTION 0x5784D0
#define OFF_AUDIO_MANAGER_PTR 0x12A7710
#define OFF_DIRECTORY_MANAGER_PTR 0x12A78F0
#define OFF_GAME_SETTINGS_PTR 0x12A7840
#endif
42 changes: 0 additions & 42 deletions Code/SM/AudioManager.hpp

This file was deleted.

74 changes: 0 additions & 74 deletions Code/SM/DirectoryManager.hpp

This file was deleted.

54 changes: 0 additions & 54 deletions Code/SM/GameSettings.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion Code/Utils/ConColors.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "win_include.hpp"
#include <SmSdk/win_include.hpp>

class EngineConColor
{
Expand Down
2 changes: 1 addition & 1 deletion Code/Utils/Console.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "win_include.hpp"
#include <SmSdk/win_include.hpp>
#include "ConColors.hpp"

#include <sstream>
Expand Down
2 changes: 1 addition & 1 deletion Code/Utils/String.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "win_include.hpp"
#include <SmSdk/win_include.hpp>

#include <cwctype>
#include <string>
Expand Down
19 changes: 16 additions & 3 deletions Code/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include "win_include.hpp"
#include <MinHook.h>
#include <SmSdk/TimestampCheck.hpp>
#include <SmSdk/win_include.hpp>

#include "Hooks/fmod_hooks.hpp"
#include "Hooks/hooks.hpp"

#include "Utils/Console.hpp"

#include <MinHook.h>

#pragma comment(lib, "User32.lib")

void dll_initialize()
{
if (MH_Initialize() == MH_OK)
Expand Down Expand Up @@ -36,6 +39,16 @@ static bool g_mhAttached = false;

void dll_attach()
{
if (!SmSdk::CheckTimestamp(_SM_TIMESTAMP_070_771))
{
MessageBoxA(
NULL,
"Your game version is unsupposed by Custom Audio Extension. The current version of the mod has been built for Scrap Mechanic 0.7.0.771",
"Unsupported Version",
MB_ICONWARNING);
return;
}

if (MH_Initialize() == MH_OK)
{
g_mhInitialized = true;
Expand Down
Loading

0 comments on commit 0ba38a5

Please sign in to comment.