Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/OpenSHC/Audio/mss/SoundSystem.func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ namespace Audio {
meth_0x424700;

MACRO_FUNCTION_RESOLVER(
void (SoundSystem::*)(), false, Address::SHC_3BB0A8C1_0x00467810, &SoundSystem::stopMusicPlayback)
void (SoundSystem::*)(), true, Address::SHC_3BB0A8C1_0x00467810, &SoundSystem::stopMusicPlayback)
stopMusicPlayback;

MACRO_FUNCTION_RESOLVER(
void (SoundSystem::*)(), false, Address::SHC_3BB0A8C1_0x00467830, &SoundSystem::endSoundStreamsUnk)
endSoundStreamsUnk;

MACRO_FUNCTION_RESOLVER(void (SoundSystem::*)(SHC_SoundStreamInt), false, Address::SHC_3BB0A8C1_0x004799A0,
MACRO_FUNCTION_RESOLVER(void (SoundSystem::*)(SHC_SoundStreamInt), true, Address::SHC_3BB0A8C1_0x004799A0,
&SoundSystem::endSoundStream)
endSoundStream;

Expand Down
68 changes: 68 additions & 0 deletions src/OpenSHC/Audio/mss/SoundSystem/endSoundStream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "OpenSHC/Audio/MSS/SoundSystem.hpp"

#include "OpenSHC/Audio/MSS/enums/AILStatus.hpp"
#include "OpenSHC/Audio/MSS/enums/SHC_SoundStream.hpp"

#include "OpenSHC/OS.func.hpp"

#include "OpenSHC/Globals/DAT_00df3844.hpp"

// TODO:
// - DAT_00df3844 did not exist before and is therefore wrongly sorted into the status file
// - "UnkSoundFlagsAndLoopCount" plays not nice with any number-like operation, the more likely thing therefore are
// either a union, which allows to access the different parts separately, but this would likely compile to WORD
// operations, or a bitfield, maybe like this:
// int loopCount : 16;
// int reserved : 13;
// int unknownFlag1 : 1;
// int unknownFlag2 : 1;
// int uninterruptable : 1; // ?
// In a test in the current file it compiled to "& 0x80000000" properly when using the specific field, but no idea if
// this works for multifield checks or assigns

namespace OpenSHC {
namespace Audio {
namespace MSS {

// FUNCTION: STRONGHOLDCRUSADER 0x004799A0
void SoundSystem::endSoundStream(SHC_SoundStreamInt sndStreamIndex)
{
if (!this->waveOutOpenUnk_0x8) {
return;
}

if (sndStreamIndex == enums::SND_STR_MUSIC) {
this->streamActiveUnk_0x20[0] = 0;
*DAT_00df3844::ptr = 1;
if (this->musicSampleFileHandleUnk_0x174 != -1) {
AIL_end_sample(this->musicSampleUnk_0x170);
MACRO_CALL(OS_Func::_ucrt_close)(this->musicSampleFileHandleUnk_0x174);
}
if (this->musicFileHandle_0x178 != -1) {
MACRO_CALL(OS_Func::_ucrt_close)(this->musicFileHandle_0x178);
}
this->musicFileHandle_0x178 = -1;
this->musicSampleFileHandleUnk_0x174 = -1;
this->mbr_0x188 = 1;
*DAT_00df3844::ptr = 0;
this->sec_Section1055_0x3274 = 0;
return;
}

if (!this->streamActiveUnk_0x20[sndStreamIndex]) {
return;
}

// flag seems to indicate an "uninterruptable" stream; if it is set, a playing stream can not be ended
if ((*reinterpret_cast<unsigned int*>(&this->streamFlagsUnkAndLoopCount_0x34[sndStreamIndex]) & 0x80000000)
&& (AIL_stream_status(this->stream_0xc[sndStreamIndex]) == SMP_PLAYING)) {
return;
}
AIL_close_stream(this->stream_0xc[sndStreamIndex]);
this->streamActiveUnk_0x20[sndStreamIndex] = 0;
this->stream_0xc[sndStreamIndex] = 0x0;
}

}
}
}
20 changes: 20 additions & 0 deletions src/OpenSHC/Audio/mss/SoundSystem/stopMusicPlayback.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "OpenSHC/Audio/MSS/SoundSystem.hpp"

#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp"
#include "OpenSHC/Audio/MSS/enums/SHC_SoundStream.hpp"

namespace OpenSHC {
namespace Audio {
namespace MSS {

// FUNCTION: STRONGHOLDCRUSADER 0x00467810
void SoundSystem::stopMusicPlayback()
{
MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::endSoundStream, this)(enums::SND_STR_MUSIC);
this->mbr_0x154 = 0;
this->sec_Section1055_0x3274 = 0;
}

}
}
}
14 changes: 14 additions & 0 deletions src/OpenSHC/Globals/DAT_00df3844.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
THIS FILE IS AUTO GENERATED
Communicate changes to the dev team (e.g. via a Pull Request).
Changes get lost otherwise.
path: 'OpenSHC/Globals/DAT_00df3844.hpp'
*/

#pragma once

namespace OpenSHC {

MACRO_STRUCT_RESOLVER(undefined4, false, Address::SHC_3BB0A8C1_0x00df3844) DAT_00df3844;
} // namespace OpenSHC
41 changes: 20 additions & 21 deletions src/OpenSHC/OS.func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp"
#include "OpenSHC/WindowsHelper/Enums/OpenFlagInt.hpp"
#include "crtdefs.h"
#include "fileapi.h"
#include "guiddef.h"
#include "mbstring.h"
#include "time.h"
Expand All @@ -31,9 +30,13 @@ namespace OS_Func {
Address::SHC_3BB0A8C1_0x0047C5D0, &OpenSHC::OS::isEqualGUID)
isEqualGUID;

MACRO_FUNCTION_RESOLVER(tm*(__cdecl*)(__time32_t * _Time), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x0057F5FE,
&OpenSHC::OS::__localtime64)
__localtime64;
MACRO_FUNCTION_RESOLVER(
int(__cdecl*)(double _X), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x0057ECF1, &OpenSHC::OS::__isnan)
__isnan;

MACRO_FUNCTION_RESOLVER(
tm*(__cdecl*)(time_t* _Time), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x0057F5FE, &OpenSHC::OS::_localtime)
_localtime;

MACRO_FUNCTION_RESOLVER(__time64_t(__cdecl*)(__time64_t* _Time), REIMPLEMENTED_CRT,
Address::SHC_3BB0A8C1_0x0057F622, &OpenSHC::OS::__time64)
Expand All @@ -43,7 +46,7 @@ namespace OS_Func {
Address::SHC_3BB0A8C1_0x0057F660, &OpenSHC::OS::_memset)
_memset;

MACRO_FUNCTION_RESOLVER(int(__cdecl*)(char* _Dest, char* _Format), REIMPLEMENTED_CRT,
MACRO_FUNCTION_RESOLVER(int(__cdecl*)(char* _Dest, char* _Format, ...), REIMPLEMENTED_CRT,
Address::SHC_3BB0A8C1_0x0057F6DA, &OpenSHC::OS::_sprintf)
_sprintf;

Expand All @@ -59,9 +62,9 @@ namespace OS_Func {
void(__cdecl*)(void* _Memory), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x0057FA74, &OpenSHC::OS::_free)
_free;

MACRO_FUNCTION_RESOLVER(
int(__cdecl*)(int _C), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x0057FC19, &OpenSHC::OS::_tolower)
_tolower;
// MACRO_FUNCTION_RESOLVER(
// int(__cdecl*)(int _C), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x0057FC19, &OpenSHC::OS::_tolower)
//_tolower;

MACRO_FUNCTION_RESOLVER(
int(__cdecl*)(FILE* _File), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x0057FCB2, &OpenSHC::OS::_fclose)
Expand Down Expand Up @@ -107,17 +110,17 @@ namespace OS_Func {
Address::SHC_3BB0A8C1_0x00580B69, &OpenSHC::OS::__wcsicmp)
__wcsicmp;

MACRO_FUNCTION_RESOLVER(
void(__cdecl*)(void* _Memory), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x00580DC1, &OpenSHC::OS::_free)
_free;
// MACRO_FUNCTION_RESOLVER(
// void(__cdecl*)(void* _Memory), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x00580DC1, &OpenSHC::OS::_free)
//_free;

MACRO_FUNCTION_RESOLVER(errno_t(__cdecl*)(void* _Dst, rsize_t _DstSize, void* _Src, rsize_t _MaxCount),
REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x00580DC6, &OpenSHC::OS::_memcpy_s)
_memcpy_s;

MACRO_FUNCTION_RESOLVER(
void(__cdecl*)(void* _Memory), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x00580E9C, &OpenSHC::OS::_free)
_free;
// MACRO_FUNCTION_RESOLVER(
// void(__cdecl*)(void* _Memory), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x00580E9C, &OpenSHC::OS::_free)
//_free;

MACRO_FUNCTION_RESOLVER(int(__cdecl*)(int fileDescriptor), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x00580F38,
&OpenSHC::OS::_ucrt_close)
Expand Down Expand Up @@ -146,18 +149,14 @@ namespace OS_Func {
Address::SHC_3BB0A8C1_0x00582050, &OpenSHC::OS::_memcpy)
_memcpy;

MACRO_FUNCTION_RESOLVER(
int(__cdecl*)(int _C), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x005824CD, &OpenSHC::OS::_toupper)
_toupper;
// MACRO_FUNCTION_RESOLVER(
// int(__cdecl*)(int _C), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x005824CD, &OpenSHC::OS::_toupper)
//_toupper;

MACRO_FUNCTION_RESOLVER(int(__cdecl*)(int fileDescriptor, long lDistanceToMove, DWORD moveMethod),
REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x0058277E, &OpenSHC::OS::_ucrt_lseek)
_ucrt_lseek;

MACRO_FUNCTION_RESOLVER(
undefined4(__stdcall*)(), REIMPLEMENTED_CRT, Address::SHC_3BB0A8C1_0x005834A0, &OpenSHC::OS::__alloca_probe)
__alloca_probe;

MACRO_FUNCTION_RESOLVER(int(__cdecl*)(char* _Str1, char* _Str2, size_t _MaxCount), REIMPLEMENTED_CRT,
Address::SHC_3BB0A8C1_0x005835BB, &OpenSHC::OS::__strnicmp)
__strnicmp;
Expand Down
17 changes: 8 additions & 9 deletions src/OpenSHC/OS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp"
#include "OpenSHC/WindowsHelper/Enums/OpenFlagInt.hpp"
#include "crtdefs.h"
#include "fileapi.h"
#include "guiddef.h"
#include "mbstring.h"
#include "time.h"
Expand All @@ -26,21 +25,23 @@ namespace OS {

BOOLEnum __cdecl isEqualGUID(GUID* param_1, GUID* param_2);

tm* __cdecl __localtime64(__time32_t* _Time);
int __cdecl __isnan(double _X);

tm* __cdecl _localtime(time_t* _Time);

__time64_t __cdecl __time64(__time64_t* _Time);

void* __cdecl _memset(void* _Dst, int _Val, size_t _Size);

int __cdecl _sprintf(char* _Dest, char* _Format);
int __cdecl _sprintf(char* _Dest, char* _Format, ...);

int __cdecl __stricmp(char* _Str1, char* _Str2);

int __cdecl _atexit(void* param_1);

void __cdecl _free(void* _Memory);

int __cdecl _tolower(int _C);
// int __cdecl _tolower(int _C);

int __cdecl _fclose(FILE* _File);

Expand All @@ -64,11 +65,11 @@ namespace OS {

int __cdecl __wcsicmp(wchar_t* _Str1, wchar_t* _Str2);

void __cdecl _free(void* _Memory);
// void __cdecl _free(void* _Memory);

errno_t __cdecl _memcpy_s(void* _Dst, rsize_t _DstSize, void* _Src, rsize_t _MaxCount);

void __cdecl _free(void* _Memory);
// void __cdecl _free(void* _Memory);

int __cdecl _ucrt_close(int fileDescriptor);

Expand All @@ -84,12 +85,10 @@ namespace OS {

void* __cdecl _memcpy(void* _Dst, void* _Src, size_t _Size);

int __cdecl _toupper(int _C);
// int __cdecl _toupper(int _C);

int __cdecl _ucrt_lseek(int fileDescriptor, long lDistanceToMove, DWORD moveMethod);

undefined4 __stdcall __alloca_probe();

int __cdecl __strnicmp(char* _Str1, char* _Str2, size_t _MaxCount);

void __cdecl _exit(int _Code);
Expand Down
Loading