Перейти к содержимому
View in the app

A better way to browse. Learn more.

Zloplay community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[help] dvar_t* Dvar_RegisterString thingy for music.

Опубликовано:

Yep you know NT has replaced menu music with 'bridge' music. I think its about storm.

 

Just looked MusicTalent :shock: cpp and see some awesome 'implementions' to game. Decided to make 'changeable' menu music by game dVar.

Did it by

dvar_t* music = Dvar_FindVar("iw4m_music");

 

if( music->current.integer == 0 ) { newFile.file = "hz_t_oilrig_themestealth_v1.mp3"; }

if( music->current.integer == 1 ) { newFile.file = "hz_boneyard_intro_LR_1.mp3"; }

if( music->current.integer == 2 ) { newFile.file = "hz_gulag_showers_LR_1.mp3"; }

if( music->current.integer == 3 ) { newFile.file = "hz_contingency_launch_LR_1.mp3"; }

if( music->current.integer == 4 ) { newFile.file = "hz_special_ops_2mx.mp3"; }

if( music->current.integer == 5 ) { newFile.file = "user.mp3"; }

 

and putting Dvar_RegisterInt("iw4m_music", 0, 0, 5, DVAR_FLAG_SAVED, "Main menu music theme. Specify by number:\n0: Default \n1: NTAuthority 'Bridge' \n2: Pvt. Mert* 'Showers' \n3: 'Launch' - Contingency \n4: Special Ops Theme \n5: User Specified*\n*) Put a mp3 file into m2demo/sound/music by named 'user.mp3'...");

after installhook codes.

when you set dvar 0 to 5 and make snd_restart the music will play and it also saves itself config file. thats not my problem :D

my problem is i wanted to make 'specify name' dvar.

replaced all these ifs with only 'newFile.file = music->current.string;' code. So game needs to be read this var at startup. but there is no such var so game crashes. (if you start game with iw4m +set iw4m_music hz_t_oilrig_themestealth_v1.mp3 no problem it works)

 

I tried to put Dvar_RegisterString("iw4m_music", "hz_t_oilrig_themestealth_v1.mp3", 1, "Menu music file name."); after these installhooks but game crashes instantly.

tried put this somewhere in patchmw2.cpp and still doesnt work.

 

After all, you can add your custom music by putting your file into m2demo/sound/music and typing its full name into console... it will play...

 

hope some1 helps me :) thx

Featured Replies

Опубликовано:
  • Автор

fixed completely used code is here: (full)

// ==========================================================
// IW4M project
// 
// Component: clientdll
// Sub-component: steam_api
// Purpose: The will of a single man. Makarov's men, fighting
//          Shepard's men. That, or a beautiful bridge...
//          about to be destroyed by some weird warfare.
//
// Initial author: NTAuthority
// Started: 2012-10-20
// ==========================================================

#include "StdInc.h"

//dvar_t* music = Dvar_RegisterString("iw4m_music", "hz_t_oilrig_themestealth_v1.mp3", 1, "Menu music file name.");
CallHook findSoundAliasHook;
DWORD findSoundAliasHookLoc = 0x6441E9;

snd_alias_list_t* FindSoundAliasHookFunc(assetType_t type, const char* name)
{
snd_alias_list_t* aliases = (snd_alias_list_t*)DB_FindXAssetHeader(type, name);

// the most hated sound at this point
if (!_stricmp(name, "music_mainmenu_mp"))
{
	static snd_alias_list_t newList;
	static snd_alias_t newAlias;
	static StreamFile newFile;

	// duplicate the asset as we can't modify pointers
	memcpy(&newList, aliases, sizeof(newList));

	memcpy(&newAlias, newList.aliases, sizeof(newAlias));
	newList.aliases = &newAlias;

	memcpy(&newFile, newAlias.stream, sizeof(newFile));
	newAlias.stream = &newFile;

	// and replace the filename.
	//newFile.file = "mp3file.mp3";


	//dvar_t* music = Dvar_FindVar("iw4m_music");
	/*
	if( music->current.integer == 0 ) { newFile.file = "hz_t_oilrig_themestealth_v1.mp3"; }
	if( music->current.integer == 1 ) { newFile.file = "hz_boneyard_intro_LR_1.mp3"; }
	if( music->current.integer == 2 ) { newFile.file = "hz_gulag_showers_LR_1.mp3"; }
	if( music->current.integer == 3 ) { newFile.file = "hz_contingency_launch_LR_1.mp3"; }
	if( music->current.integer == 4 ) { newFile.file = "hz_special_ops_2mx.mp3"; }
	if( music->current.integer == 5 ) { newFile.file = "user.mp3"; }
	*/
	if( Dvar_FindVar("iw4m_music") ) //{ Com_Printf(0,"empty"); }else{ Com_Printf(0,"okay"); }
	{ newFile.file = Dvar_FindVar("iw4m_music")->current.string; }else{ newFile.file = "hz_t_oilrig_themestealth_v1.mp3"; }
	if( !Dvar_FindVar("iw4m_music") ) { Dvar_RegisterString("iw4m_music", "hz_t_oilrig_themestealth_v1.mp3", DVAR_FLAG_SAVED, "Main menu music theme.\nEnter mp3 audio file name.\nFor using custom files, put them in m2demo/sound/music.\n*Type full name of file: example.mp3"); }

	// oh and this too
	aliases = &newList;
}

return aliases;
}

void PatchMW2_MusicalTalent()
{
findSoundAliasHook.initialize(findSoundAliasHookLoc, FindSoundAliasHookFunc);
findSoundAliasHook.installHook();
//Dvar_RegisterInt("iw4m_music", 0, 0, 5, DVAR_FLAG_SAVED, "Main menu music theme. Specify by number:\n0: Default \n1: NTAuthority 'Bridge' \n2: Pvt. Mert* 'Showers' \n3: 'Launch' - Contingency \n4: Special Ops Theme \n5: User Specified*\n*) Put a mp3 file into m2demo/sound/music by named 'user.mp3'...");
}

 

one more question: how to add multiple flags to dvar. DVAR_FLAG_SAVED | DVAR_FLAG_LATCHED or DVAR_FLAG_SAVED & DVAR_FLAG_LATCHED !?

Опубликовано:

This can't really work... The code is only called once when it loads common_mp.ff which is called on game startup... you would have to add arguments to the game to get those dvars to be considered at the time the code is running I don't know why the code to register the dvar doesn't work but It is irrelevant because it cannot be changed once the game starts. The way to compound flags like the ones for dvars is by using the binary OR operator "|". You can try adding the dvar to your config_mp.cfg (or is it m2?) and it might work.

Опубликовано:
  • Автор

I think found a fix: *i made that dvar saved to config, after loading config it seems to external dvar.*

 

// ==========================================================
// IW4M project
// 
// Component: clientdll
// Sub-component: steam_api
// Purpose: The will of a single man. Makarov's men, fighting
//          Shepard's men. That, or a beautiful bridge...
//          about to be destroyed by some weird warfare.
//
// Initial author: NTAuthority
// Started: 2012-10-20
// ==========================================================

#include "StdInc.h"
int mert = 0;

//dvar_t* music = Dvar_RegisterString("iw4m_music", "hz_t_oilrig_themestealth_v1.mp3", 1, "Menu music file name.");
CallHook findSoundAliasHook;
DWORD findSoundAliasHookLoc = 0x6441E9;

snd_alias_list_t* FindSoundAliasHookFunc(assetType_t type, const char* name)
{
snd_alias_list_t* aliases = (snd_alias_list_t*)DB_FindXAssetHeader(type, name);

// the most hated sound at this point
if (!_stricmp(name, "music_mainmenu_mp"))
{
	static snd_alias_list_t newList;
	static snd_alias_t newAlias;
	static StreamFile newFile;

	// duplicate the asset as we can't modify pointers
	memcpy(&newList, aliases, sizeof(newList));

	memcpy(&newAlias, newList.aliases, sizeof(newAlias));
	newList.aliases = &newAlias;

	memcpy(&newFile, newAlias.stream, sizeof(newFile));
	newAlias.stream = &newFile;

	// and replace the filename.
	//newFile.file = "mp3file.mp3";


	//dvar_t* music = Dvar_FindVar("iw4m_music");
	/*
	if( music->current.integer == 0 ) { newFile.file = "hz_t_oilrig_themestealth_v1.mp3"; }
	if( music->current.integer == 1 ) { newFile.file = "hz_boneyard_intro_LR_1.mp3"; }
	if( music->current.integer == 2 ) { newFile.file = "hz_gulag_showers_LR_1.mp3"; }
	if( music->current.integer == 3 ) { newFile.file = "hz_contingency_launch_LR_1.mp3"; }
	if( music->current.integer == 4 ) { newFile.file = "hz_special_ops_2mx.mp3"; }
	if( music->current.integer == 5 ) { newFile.file = "user.mp3"; }
	*/
	if( Dvar_FindVar("iw4m_music") ) //{ Com_Printf(0,"empty"); }else{ Com_Printf(0,"okay"); }
	{ newFile.file = Dvar_FindVar("iw4m_music")->current.string; }else{ newFile.file = "hz_t_oilrig_themestealth_v1.mp3"; }

	if( mert == 0 ) { Dvar_RegisterString("iw4m_music", "hz_t_oilrig_themestealth_v1.mp3", DVAR_FLAG_SAVED, "Main menu music theme.\nEnter mp3 audio file name.\nFor using custom files, put them in m2demo/sound/music.\n*Type full name of file: example.mp3"); }
	mert = 1;

	// oh and this too
	aliases = &newList;
}

return aliases;
}

void PatchMW2_MusicalTalent()
{
findSoundAliasHook.initialize(findSoundAliasHookLoc, FindSoundAliasHookFunc);
findSoundAliasHook.installHook();
//Dvar_RegisterInt("iw4m_music", 0, 0, 5, DVAR_FLAG_SAVED, "Main menu music theme. Specify by number:\n0: Default \n1: NTAuthority 'Bridge' \n2: Pvt. Mert* 'Showers' \n3: 'Launch' - Contingency \n4: Special Ops Theme \n5: User Specified*\n*) Put a mp3 file into m2demo/sound/music by named 'user.mp3'...");
}

* only set it once after starting game (to add description and default values to var)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Гость
Ответить в тему...

Сейчас на странице 0

  • Нет пользователей, просматривающих эту страницу

Важная информация

Используя этот сайт, вы соглашаетесь Условия использования.

Account

Navigation

Поиск

Поиск

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.