"BGM continues after Battle" - need a ".dll" file

In the default of RMXP, after a battle, the Map BGM will be re-played :( that's bad!
And this is an useful Script to make BGM can continue playing after battle of RMXP
But it needs a file called "Audio.dll", but I can't find out it
So someone know that file, please help me :(
Here is the Script :

  1. #==============================================================================
  2. # Não reinciar Música do mapa após uma batalha
  3. # por Atoa
  4. # Novo modulo de Audio por Poccil
  5. #==============================================================================
  6.  
  7. class Win32API
  8. @@RGSSWINDOW=nil
  9. @@GetCurrentThreadId=Win32API.new('kernel32','GetCurrentThreadId', '%w()','l')
  10. @@GetWindowThreadProcessId=Win32API.new('user32','GetWindowThreadProcessId', '%w(l p)','l')
  11. @@FindWindowEx=Win32API.new('user32','FindWindowEx', '%w(l l p p)','l')
  12. def Win32API.GetPrivateProfileString(section, key)
  13. val = "\0"*256
  14. gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l')
  15. gps.call(section, key, "", val, 256, ".\\Game.ini")
  16. val.delete!("\0")
  17. return val
  18. end
  19. end
  20.  
  21. class Thread
  22. def Thread.exclusive
  23. _old = Thread.critical
  24. begin
  25. Thread.critical = true
  26. return yield
  27. ensure
  28. Thread.critical = _old
  29. end
  30. end
  31. end
  32.  
  33. class AudioContext
  34. attr_reader :context
  35. def initialize
  36. init = Win32API.new("audio.dll", "AudioContextInitialize", '', 'l')
  37. @context=init.call()
  38. end
  39. def dispose
  40. if @context!=0
  41. init = Win32API.new("audio.dll", "AudioContextFree", 'l', '')
  42. init.call(context)
  43. @context=0
  44. end
  45. end
  46. end
  47.  
  48. $AtExitProcs=[] if !$AtExitProcs
  49. def exit(code=0)
  50. for p in $AtExitProcs
  51. p.call
  52. end
  53. raise SystemExit.new(code)
  54. end
  55.  
  56. def at_exit(&block)
  57. $AtExitProcs.push(Proc.new(&block))
  58. end
  59.  
  60. module AudioState
  61. w32_LL = Win32API.new("kernel32.dll", "LoadLibrary", 'p', 'l')
  62. w32_FL = Win32API.new("kernel32.dll", "FreeLibrary", 'p', 'l')
  63. @handle = w32_LL.call("audio.dll")
  64. at_exit { w32_FL.call(@handle) }
  65. AudioContextIsActive=Win32API.new("audio.dll","AudioContextIsActive","l","l")
  66. AudioContextPlay=Win32API.new("audio.dll","AudioContextPlay","lpllll","")
  67. AudioContextStop=Win32API.new("audio.dll","AudioContextStop","l","")
  68. AudioContextFadeOut=Win32API.new("audio.dll","AudioContextFadeOut","ll","")
  69. AudioContextGetPosition=Win32API.new("audio.dll","AudioContextGetPosition","l","l")
  70. AudioContextFadeIn=Win32API.new("audio.dll","AudioContextFadeIn","ll","")
  71. AudioContextSetVolume=Win32API.new("audio.dll","AudioContextSetVolume","ll","")
  72. AudioContextSEPlay=Win32API.new("audio.dll","AudioContextSEPlay","lplll","")
  73. if !@MEContext
  74. @MEContext=AudioContext.new
  75. at_exit { @MEContext.dispose }
  76. end
  77. if !@BGMContext
  78. @BGMContext=AudioContext.new
  79. at_exit { @BGMContext.dispose }
  80. end
  81. if !@SEContext
  82. @SEContext=AudioContext.new
  83. at_exit { @SEContext.dispose }
  84. end
  85. @channel=nil
  86. @bgm=nil
  87. @name=""
  88. @pitch=100
  89. @bgmVolume=100.0
  90. @meVolume=100.0
  91. @seVolume=100.0
  92. def self.setWaitingBGM(bgm,volume,pitch,position)
  93. @waitingBGM=[bgm,volume,pitch,position]
  94. end
  95. def self.bgmActive?
  96. return (AudioContextIsActive.call(@BGMContext.context)!=0)
  97. end
  98. def self.meActive?
  99. return (AudioContextIsActive.call(@MEContext.context)!=0)
  100. end
  101. def self.waitingBGM
  102. @waitingBGM
  103. end
  104. def self.context
  105. @BGMContext.context
  106. end
  107. def self.system
  108. @system
  109. end
  110. def self.bgm
  111. @bgm
  112. end
  113. def self.name
  114. @name
  115. end
  116. def self.pitch
  117. @pitch
  118. end
  119. def self.volume
  120. @volume
  121. end
  122. def self.waitingBGM=(value)
  123. Thread.exclusive{@waitingBGM=value}
  124. end
  125. def self.volume=(value)
  126. @volume=value
  127. end
  128. def self.bgm=(value)
  129. @bgm=value
  130. end
  131. def self.name=(value)
  132. @name=value
  133. end
  134. def self.pitch=(value)
  135. @pitch=value
  136. end
  137. end
  138.  
  139. def Audio_bgm_playing?
  140. AudioState.channel!=nil
  141. end
  142. def Audio_bgm_name
  143. AudioState.name
  144. end
  145. def Audio_bgm_pitch
  146. AudioState.pitch
  147. end
  148. def Audio_bgm_play(name, volume, pitch, position = 0)
  149. begin
  150. filename = canonicalize(rtpGetPath(name,[".mid",".mp3",".wma",".ogg",".wav",""]))
  151. if AudioState.meActive?
  152. AudioState.setWaitingBGM(filename,volume,pitch,position)
  153. return
  154. end
  155. AudioState::AudioContextPlay.call(AudioState.context,filename,volume,pitch,position,1)
  156. AudioState.name=filename
  157. AudioState.volume=volume
  158. AudioState.pitch=pitch
  159. rescue Hangup
  160. rescue
  161. p $!.message,$!.backtrace
  162. end
  163. end
  164. def Audio_bgm_stop()
  165. begin
  166. AudioState::AudioContextStop.call(AudioState.context)
  167. AudioState.waitingBGM=nil
  168. AudioState.name = ""
  169. rescue
  170. p $!.message,$!.backtrace
  171. end
  172. end
  173. def Audio_bgm_get_position
  174. return AudioState::AudioContextGetPosition.call(AudioState.context)
  175. end
  176. def Audio_bgm_fade(ms)
  177. AudioState::AudioContextFadeOut.call(AudioState.context,ms.to_i)
  178. end
  179. def Audio_bgm_fadein(ms)
  180. AudioState::AudioContextFadeIn.call(AudioState.context,ms.to_i)
  181. end
  182. def Audio_bgm_get_volume
  183. return 0 if !AudioState.bgmActive?
  184. return AudioState.volume
  185. end
  186. def Audio_bgm_set_volume(volume)
  187. return if !AudioState.bgmActive?
  188. AudioState.volume = volume * 1.0
  189. AudioState::AudioContextSetVolume.call(AudioState.context,volume.to_i)
  190. end
  191.  
  192. module Graphics
  193. if !defined?(audiomodule_update)
  194. class << self
  195. alias audiomodule_update update
  196. end
  197. end
  198. def self.update
  199. Audio.update
  200. audiomodule_update
  201. end
  202. end
  203.  
  204. module Audio
  205. @@musicstate=nil
  206. @@soundstate=nil
  207. def self.update
  208. return if Graphics.frame_count%10!=0
  209. if AudioState.waitingBGM && !AudioState.meActive?
  210. waitbgm=AudioState.waitingBGM
  211. AudioState.waitingBGM=nil
  212. bgm_play(waitbgm[0],waitbgm[1],waitbgm[2],waitbgm[3])
  213. end
  214. end
  215. def self.bgm_play(name,volume=80,pitch=100,position=nil)
  216. begin
  217. if position==nil || position==0
  218. Kernel.Audio_bgm_play(name,volume,pitch,0)
  219. else
  220. Kernel.Audio_bgm_play(name,volume,pitch,position)
  221. Kernel.Audio_bgm_fadein(500)
  222. end
  223. rescue Hangup
  224. bgm_play(name,volume,pitch,position)
  225. end
  226. end
  227. def self.bgm_fade(ms)
  228. Kernel.Audio_bgm_fade(ms)
  229. end
  230. def self.bgm_stop
  231. Kernel.Audio_bgm_stop()
  232. end
  233. def self.bgm_position
  234. ret=Kernel.Audio_bgm_get_position
  235. return ret
  236. end
  237. end
  238.  
  239. module Win32
  240. class Registry
  241. module Constants
  242. HKEY_CLASSES_ROOT = 0x80000000
  243. HKEY_CURRENT_USER = 0x80000001
  244. HKEY_LOCAL_MACHINE = 0x80000002
  245. HKEY_USERS = 0x80000003
  246. HKEY_PERFORMANCE_DATA = 0x80000004
  247. HKEY_PERFORMANCE_TEXT = 0x80000050
  248. HKEY_PERFORMANCE_NLSTEXT = 0x80000060
  249. HKEY_CURRENT_CONFIG = 0x80000005
  250. HKEY_DYN_DATA = 0x80000006
  251. REG_NONE = 0
  252. REG_SZ = 1
  253. REG_EXPAND_SZ = 2
  254. REG_BINARY = 3
  255. REG_DWORD = 4
  256. REG_DWORD_LITTLE_ENDIAN = 4
  257. REG_DWORD_BIG_ENDIAN = 5
  258. REG_LINK = 6
  259. REG_MULTI_SZ = 7
  260. REG_RESOURCE_LIST = 8
  261. REG_FULL_RESOURCE_DESCRIPTOR = 9
  262. REG_RESOURCE_REQUIREMENTS_LIST = 10
  263. REG_QWORD = 11
  264. REG_QWORD_LITTLE_ENDIAN = 11
  265. STANDARD_RIGHTS_READ = 0x00020000
  266. STANDARD_RIGHTS_WRITE = 0x00020000
  267. KEY_QUERY_VALUE = 0x0001
  268. KEY_SET_VALUE = 0x0002
  269. KEY_CREATE_SUB_KEY = 0x0004
  270. KEY_ENUMERATE_SUB_KEYS = 0x0008
  271. KEY_NOTIFY = 0x0010
  272. KEY_CREATE_LINK = 0x0020
  273. KEY_READ = STANDARD_RIGHTS_READ |
  274. KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
  275. KEY_WRITE = STANDARD_RIGHTS_WRITE |
  276. KEY_SET_VALUE | KEY_CREATE_SUB_KEY
  277. KEY_EXECUTE = KEY_READ
  278. KEY_ALL_ACCESS = KEY_READ | KEY_WRITE | KEY_CREATE_LINK
  279. REG_OPTION_RESERVED = 0x0000
  280. REG_OPTION_NON_VOLATILE = 0x0000
  281. REG_OPTION_VOLATILE = 0x0001
  282. REG_OPTION_CREATE_LINK = 0x0002
  283. REG_OPTION_BACKUP_RESTORE = 0x0004
  284. REG_OPTION_OPEN_LINK = 0x0008
  285. REG_LEGAL_OPTION = REG_OPTION_RESERVED |
  286. REG_OPTION_NON_VOLATILE | REG_OPTION_CREATE_LINK |
  287. REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK
  288. REG_CREATED_NEW_KEY = 1
  289. REG_OPENED_EXISTING_KEY = 2
  290. REG_WHOLE_HIVE_VOLATILE = 0x0001
  291. REG_REFRESH_HIVE = 0x0002
  292. REG_NO_LAZY_FLUSH = 0x0004
  293. REG_FORCE_RESTORE = 0x0008
  294. MAX_KEY_LENGTH = 514
  295. MAX_VALUE_LENGTH = 32768
  296. end
  297. include Constants
  298. include Enumerable
  299. class Error < ::StandardError
  300. FormatMessageA=Win32API.new('kernel32.dll','FormatMessageA','LPLLPLP','L')
  301. def initialize(code)
  302. @code = code
  303. msg = "\0" * 1024
  304. len = FormatMessageA.call(0x1200, 0, code, 0, msg, 1024, 0)
  305. super msg[0, len].tr("\r", '').chomp
  306. end
  307. attr_reader :code
  308. end
  309. class PredefinedKey < Registry
  310. def initialize(hkey, keyname)
  311. @hkey = hkey
  312. @parent = nil
  313. @keyname = keyname
  314. @disposition = REG_OPENED_EXISTING_KEY
  315. end
  316. def close
  317. raise Error.new(5)
  318. end
  319. def class
  320. Registry
  321. end
  322. Constants.constants.grep(/^HKEY_/) do |c|
  323. Registry.const_set c, new(Constants.const_get(c), c)
  324. end
  325. end
  326. module API
  327. [
  328. %w/RegOpenKeyExA LPLLP L/,
  329. %w/RegCreateKeyExA LPLLLLPPP L/,
  330. %w/RegEnumValueA LLPPPPPP L/,
  331. %w/RegEnumKeyExA LLPPLLLP L/,
  332. %w/RegQueryValueExA LPLPPP L/,
  333. %w/RegSetValueExA LPLLPL L/,
  334. %w/RegFlushKey L L/,
  335. %w/RegCloseKey L L/,
  336. %w/RegQueryInfoKey LPPPPPPPPPPP L/,
  337. ].each do |fn|
  338. const_set fn[0].intern, Win32API.new('advapi32.dll', *fn)
  339. end
  340. module_function
  341. def check(result)
  342. raise Error, result, caller(2) if result != 0
  343. end
  344. def packdw(dw)
  345. [dw].pack('V')
  346. end
  347. def unpackdw(dw)
  348. dw += [0].pack('V')
  349. dw.unpack('V')[0]
  350. end
  351. def packqw(qw)
  352. [ qw & 0xFFFFFFFF, qw >> 32 ].pack('VV')
  353. end
  354. def unpackqw(qw)
  355. qw = qw.unpack('VV')
  356. (qw[1] << 32) | qw[0]
  357. end
  358. def OpenKey(hkey, name, opt, desired)
  359. result = packdw(0)
  360. check RegOpenKeyExA.call(hkey, name, opt, desired, result)
  361. unpackdw(result)
  362. end
  363. def CreateKey(hkey, name, opt, desired)
  364. result = packdw(0)
  365. disp = packdw(0)
  366. check RegCreateKeyExA.call(hkey, name, 0, 0, opt, desired,
  367. 0, result, disp)
  368. [ unpackdw(result), unpackdw(disp) ]
  369. end
  370. def EnumValue(hkey, index)
  371. name = ' ' * Constants::MAX_KEY_LENGTH
  372. size = packdw(Constants::MAX_KEY_LENGTH)
  373. check RegEnumValueA.call(hkey, index, name, size, 0, 0, 0, 0)
  374. name[0, unpackdw(size)]
  375. end
  376. def EnumKey(hkey, index)
  377. name = ' ' * Constants::MAX_KEY_LENGTH
  378. size = packdw(Constants::MAX_KEY_LENGTH)
  379. wtime = ' ' * 8
  380. check RegEnumKeyExA.call(hkey, index, name, size, 0, 0, 0, wtime)
  381. [ name[0, unpackdw(size)], unpackqw(wtime) ]
  382. end
  383. def QueryValue(hkey, name)
  384. type = packdw(0)
  385. size = packdw(0)
  386. check RegQueryValueExA.call(hkey, name, 0, type, 0, size)
  387. data = ' ' * unpackdw(size)
  388. check RegQueryValueExA.call(hkey, name, 0, type, data, size)
  389. [ unpackdw(type), data[0, unpackdw(size)] ]
  390. end
  391. def SetValue(hkey, name, type, data, size)
  392. check RegSetValueExA.call(hkey, name, 0, type, data, size)
  393. end
  394. def FlushKey(hkey)
  395. check RegFlushKey.call(hkey)
  396. end
  397. def CloseKey(hkey)
  398. check RegCloseKey.call(hkey)
  399. end
  400. def QueryInfoKey(hkey)
  401. subkeys = packdw(0)
  402. maxsubkeylen = packdw(0)
  403. values = packdw(0)
  404. maxvaluenamelen = packdw(0)
  405. maxvaluelen = packdw(0)
  406. secdescs = packdw(0)
  407. wtime = ' ' * 8
  408. check RegQueryInfoKey.call(hkey, 0, 0, 0, subkeys, maxsubkeylen, 0,
  409. values, maxvaluenamelen, maxvaluelen, secdescs, wtime)
  410. [ unpackdw(subkeys), unpackdw(maxsubkeylen), unpackdw(values),
  411. unpackdw(maxvaluenamelen), unpackdw(maxvaluelen),
  412. unpackdw(secdescs), unpackqw(wtime) ]
  413. end
  414. end
  415. def self.expand_environ(str)
  416. str.gsub(/%([^%]+)%/) { ENV[$1] || $& }
  417. end
  418. @@type2name = { }
  419. %w[
  420. REG_NONE REG_SZ REG_EXPAND_SZ REG_BINARY REG_DWORD
  421. REG_DWORD_BIG_ENDIAN REG_LINK REG_MULTI_SZ
  422. REG_RESOURCE_LIST REG_FULL_RESOURCE_DESCRIPTOR
  423. REG_RESOURCE_REQUIREMENTS_LIST REG_QWORD
  424. ].each do |type|
  425. @@type2name[Constants.const_get(type)] = type
  426. end
  427. def self.type2name(type)
  428. @@type2name[type] || type.to_s
  429. end
  430. def self.wtime2time(wtime)
  431. Time.at((wtime - 116444736000000000) / 10000000)
  432. end
  433. def self.time2wtime(time)
  434. time.to_i * 10000000 + 116444736000000000
  435. end
  436. private_class_method :new
  437. def self.open(hkey, subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED)
  438. subkey = subkey.chomp('\')
  439. begin
  440. newkey = API.OpenKey(hkey.hkey, subkey, opt, desired)
  441. rescue Error
  442. return nil
  443. end
  444. obj = new(newkey, hkey, subkey, REG_OPENED_EXISTING_KEY)
  445. if block_given?
  446. begin
  447. yield obj
  448. ensure
  449. obj.close
  450. end
  451. else
  452. obj
  453. end
  454. end
  455. def self.create(hkey, subkey, desired = KEY_ALL_ACCESS, opt = 0x0000)
  456. newkey, disp = API.CreateKey(hkey.hkey, subkey, opt, desired)
  457. obj = new(newkey, hkey, subkey, disp)
  458. if block_given?
  459. begin
  460. yield obj
  461. ensure
  462. obj.close
  463. end
  464. else
  465. obj
  466. end
  467. end
  468. @@final = proc { |hkey| proc { API.CloseKey(hkey[0]) if hkey[0] } }
  469. def initialize(hkey, parent, keyname, disposition)
  470. @hkey = hkey
  471. @parent = parent
  472. @keyname = keyname
  473. @disposition = disposition
  474. @hkeyfinal = [ hkey ]
  475. ObjectSpace.define_finalizer self, @@final.call(@hkeyfinal)
  476. end
  477. attr_reader :hkey, :parent, :keyname, :disposition
  478. def created?
  479. @disposition == REG_CREATED_NEW_KEY
  480. end
  481. def open?
  482. [email protected]?
  483. end
  484. def name
  485. parent = self
  486. name = @keyname
  487. while parent = parent.parent
  488. name = parent.keyname + '\' + name
  489. end
  490. name
  491. end
  492. def inspect
  493. "\#"
  494. end
  495. def _dump(depth)
  496. raise TypeError, "can't dump Win32::Registry"
  497. end
  498. def open(subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED, &blk)
  499. self.class.open(self, subkey, desired, opt, &blk)
  500. end
  501. def create(subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED, &blk)
  502. self.class.create(self, subkey, desired, opt, &blk)
  503. end
  504. def close
  505. API.CloseKey(@hkey)
  506. @hkey = @parent = @keyname = nil
  507. @hkeyfinal[0] = nil
  508. end
  509. def each_value
  510. index = 0
  511. while true
  512. begin
  513. subkey = API.EnumValue(@hkey, index)
  514. rescue Error
  515. break
  516. end
  517. begin
  518. type, data = read(subkey)
  519. rescue Error
  520. next
  521. end
  522. yield subkey, type, data
  523. index += 1
  524. end
  525. index
  526. end
  527. alias each each_value
  528. def each_key
  529. index = 0
  530. while true
  531. begin
  532. subkey, wtime = API.EnumKey(@hkey, index)
  533. rescue Error
  534. break
  535. end
  536. yield subkey, wtime
  537. index += 1
  538. end
  539. index
  540. end
  541. def keys
  542. keys_ary = []
  543. each_key { |key,| keys_ary << key }
  544. keys_ary
  545. end
  546. def read(name, *rtype)
  547. type, data = API.QueryValue(@hkey, name)
  548. unless rtype.empty? or rtype.include?(type)
  549. string = "Type mismatch (expect #{rtype.inspect} but #{type} present)"
  550. raise TypeError, string
  551. end
  552. case type
  553. when REG_SZ, REG_EXPAND_SZ
  554. [ type, data.chop ]
  555. when REG_MULTI_SZ
  556. [ type, data.split(/\0/) ]
  557. when REG_BINARY
  558. [ type, data ]
  559. when REG_DWORD
  560. [ type, API.unpackdw(data) ]
  561. when REG_DWORD_BIG_ENDIAN
  562. [ type, data.unpack('N')[0] ]
  563. when REG_QWORD
  564. [ type, API.unpackqw(data) ]
  565. else
  566. raise TypeError, "Type #{type} is not supported."
  567. end
  568. end
  569. def [](name, *rtype)
  570. type, data = read(name, *rtype)
  571. case type
  572. when REG_SZ, REG_DWORD, REG_QWORD, REG_MULTI_SZ
  573. data
  574. when REG_EXPAND_SZ
  575. Registry.expand_environ(data)
  576. else
  577. raise TypeError, "Type #{type} is not supported."
  578. end
  579. end
  580. def read_s(name)
  581. read(name, REG_SZ)[1]
  582. end
  583. def read_s_expand(name)
  584. type, data = read(name, REG_SZ, REG_EXPAND_SZ)
  585. if type == REG_EXPAND_SZ
  586. Registry.expand_environ(data)
  587. else
  588. data
  589. end
  590. end
  591. def read_i(name)
  592. read(name, REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_QWORD)[1]
  593. end
  594. def read_bin(name)
  595. read(name, REG_BINARY)[1]
  596. end
  597. def write(name, type, data)
  598. case type
  599. when REG_SZ, REG_EXPAND_SZ
  600. data = data.to_s + "\0"
  601. when REG_MULTI_SZ
  602. data = data.to_a.join("\0") + "\0\0"
  603. when REG_BINARY
  604. data = data.to_s
  605. when REG_DWORD
  606. data = API.packdw(data.to_i)
  607. when REG_DWORD_BIG_ENDIAN
  608. data = [data.to_i].pack('N')
  609. when REG_QWORD
  610. data = API.packqw(data.to_i)
  611. else
  612. raise TypeError, "Unsupported type #{type}"
  613. end
  614. API.SetValue(@hkey, name, type, data, data.length)
  615. end
  616. def []=(name, rtype, value = nil)
  617. if value
  618. write name, rtype, value
  619. else
  620. case value = rtype
  621. when Integer
  622. write name, REG_DWORD, value
  623. when String
  624. write name, REG_SZ, value
  625. when Array
  626. write name, REG_MULTI_SZ, value
  627. else
  628. raise TypeError, "Unexpected type #{value.class}"
  629. end
  630. end
  631. value
  632. end
  633. def write_s(name, value)
  634. write name, REG_SZ, value.to_s
  635. end
  636. def write_i(name, value)
  637. write name, REG_DWORD, value.to_i
  638. end
  639. def write_bin(name, value)
  640. write name, REG_BINARY, value.to_s
  641. end
  642. def flush
  643. API.FlushKey @hkey
  644. end
  645. def info
  646. API.QueryInfoKey(@hkey)
  647. end
  648. %w[
  649. num_keys max_key_length
  650. num_values max_value_name_length max_value_length
  651. descriptor_length wtime
  652. ].each_with_index do |s, i|
  653. eval <<-__END__
  654. def #{s}
  655. info[#{i}]
  656. end
  657. __END__
  658. end
  659. end
  660. end
  661.  
  662. def getExistingPath(file,extensions=[])
  663. return file if FileTest.exist?(file)
  664. if extensions
  665. for ext in extensions
  666. fullfile=file+ext
  667. return fullfile if FileTest.exist?(fullfile)
  668. end
  669. end
  670. return nil
  671. end
  672.  
  673. def rtpGetDirectory(key,rtpname)
  674. rtp=Win32API.GetPrivateProfileString("Game",rtpname)
  675. return nil if !rtp || rtp==""
  676. begin
  677. path=key.read_s(rtp)
  678. if path && path!=""
  679. return path
  680. end
  681. return nil
  682. rescue
  683. return nil
  684. end
  685. end
  686.  
  687. def rtpGetPathHelper(key,rtpname,file,extensions)
  688. path=rtpGetDirectory(key,rtpname)
  689. return path ? getExistingPath(path+"\\"+file,extensions) : nil
  690. end
  691.  
  692. def chdirRTP(rtpname)
  693. Win32::Registry.open(
  694. Win32::Registry::HKEY_LOCAL_MACHINE,"SOFTWARE\\Enterbrain\\RGSS\\RTP"){|key|
  695. path=rtpGetDirectory(key,rtpname)
  696. if path && path!=""
  697. if block_given?
  698. Dir.chdir(path){ yield }
  699. else
  700. Dir.chdir(path)
  701. end
  702. end
  703. }
  704. end
  705.  
  706. def rtpGetPath(file,extensions=[])
  707. path=getExistingPath(file,extensions)
  708. if !path
  709. Win32::Registry.open(
  710. Win32::Registry::HKEY_LOCAL_MACHINE,"SOFTWARE\\Enterbrain\\RGSS\\RTP"){|key|
  711. path=rtpGetPathHelper(key,"RTP1",file,extensions)
  712. path=rtpGetPathHelper(key,"RTP2",file,extensions) if !path
  713. path=rtpGetPathHelper(key,"RTP3",file,extensions) if !path }
  714. end
  715. return path
  716. end
  717.  
  718.  
  719. def getPlayMusic
  720. begin
  721. ret=true
  722. Win32::Registry.open(
  723. Win32::Registry::HKEY_CURRENT_USER,"SOFTWARE\\Enterbrain\\RGSS"){|key|
  724. ret=(key["PlayMusic"] == 1)}
  725. return ret
  726. rescue
  727. return true
  728. end
  729. end
  730.  
  731. def getPlaySound
  732. begin
  733. ret=true
  734. Win32::Registry.open(
  735. Win32::Registry::HKEY_CURRENT_USER,"SOFTWARE\\Enterbrain\\RGSS"){|key|
  736. ret=(key["PlaySound"] == 1)}
  737. return ret
  738. rescue
  739. p $!.message,$!.class.name
  740. return true
  741. end
  742. end
  743.  
  744. module FileTest
  745. Image_ext = ['.bmp', '.png', '.jpg', '.jpeg']
  746. Audio_ext = ['.mp3', '.mid', '.midi', '.ogg', '.wav', '.wma']
  747. def self.audio_exist?(filename)
  748. return !rtpGetPath(filename,Audio_ext).nil?
  749. end
  750. def self.image_exist?(filename)
  751. return !rtpGetPath(filename,Image_ext).nil?
  752. end
  753. end
  754.  
  755. class Hangup < Exception
  756. end
  757.  
  758. def strsplit(str,re)
  759. ret=[]
  760. tstr=str
  761. while re=~tstr
  762. ret[ret.length]=$~.pre_match
  763. tstr=$~.post_match
  764. end
  765. ret[ret.length]=tstr if ret.length
  766. return ret
  767. end
  768.  
  769. def canonicalize(c)
  770. csplit=strsplit(c,/[\/\\]/)
  771. pos=-1
  772. ret=[]
  773. retstr=""
  774. for x in csplit
  775. if x=="."
  776. elsif x==".."
  777. if pos>=0
  778. ret.delete_at(pos)
  779. pos-=1
  780. end
  781. else
  782. ret.push(x)
  783. pos+=1
  784. end
  785. end
  786. for i in 0...ret.length
  787. retstr+="/" if i>0
  788. retstr+=ret[i]
  789. end
  790. return retstr
  791. end
  792.  
  793. class Game_System
  794. attr_accessor :bgm_position
  795. def audioBgmPlay(str,vol,pitch,position)
  796. Audio.bgm_play(str,vol,pitch,position)
  797. end
  798. def audioBgmFade(time)
  799. Audio.bgm_fade(time)
  800. end
  801. def audioBgmStop
  802. Audio.bgm_stop
  803. end
  804. def bgm_play_ex(bgm,volume,pitch,setplaying,position=0)
  805. if bgm.is_a?(String)
  806. bgm=RPG::AudioFile.new(bgm,volume,pitch)
  807. end
  808. if setplaying
  809. @playing_bgm = bgm==nil ? nil : bgm.clone
  810. end
  811. if bgm != nil and bgm.name != ""
  812. audioBgmPlay("Audio/BGM/" + bgm.name, bgm.volume, bgm.pitch,position) if !@defaultBGM
  813. else
  814. audioBgmStop if !@defaultBGM
  815. end
  816. if @defaultBGM
  817. audioBgmPlay("Audio/BGM/"[email hidden], @defaultBGM.volume,@defaultBGM.pitch,position)
  818. end
  819. Graphics.frame_reset
  820. end
  821. def bgm_play(bgm,volume=100,pitch=100,position=0)
  822. bgm_play_ex(bgm,volume,pitch,true,position)
  823. end
  824. def bgm_stop
  825. @bgm_position=0
  826. @playing_bgm = nil
  827. audioBgmStop if !@defaultBGM
  828. end
  829. def bgm_fade(time)
  830. @playing_bgm = nil
  831. audioBgmFade((time * 1000).floor) if !@defaultBGM
  832. end
  833. def getPlayingBGM
  834. return @playing_bgm ? @playing_bgm.clone : nil
  835. end
  836. def bgm_memorize
  837. @memorized_bgm = @playing_bgm
  838. end
  839. def bgm_restore
  840. bgm_play(@memorized_bgm)
  841. end
  842. def setDefaultBGM(bgm,volume=100,pitch=100)
  843. if bgm.is_a?(String)
  844. bgm=RPG::AudioFile.new(bgm,volume,pitch)
  845. end
  846. if bgm != nil and bgm.name != ""
  847. @defaultBGM=bgm==nil ? nil : bgm.clone
  848. Audio.bgm_play("Audio/BGM/"+bgm.name)
  849. else
  850. @defaultBGM=nil
  851. self.bgm_play(@playing_bgm)
  852. end
  853. end
  854. def bgm_pause(fadetime=0.0)
  855. pos=Audio.bgm_position
  856. if fadetime>0.0
  857. bgm_fade(fadetime)
  858. end
  859. @bgm_position=pos
  860. end
  861. def bgm_unpause
  862. @bgm_position=0
  863. end
  864. def bgm_resume(bgm,volume=100,pitch=100);
  865. bgm_play(bgm,volume,pitch,@bgm_position)
  866. @bgm_position=0
  867. end
  868. end
  869.  
  870. #==============================================================================
  871. # Scene_Map
  872. #==============================================================================
  873. class Scene_Map
  874. def call_battle
  875. $game_temp.battle_calling = false
  876. $game_temp.menu_calling = false
  877. $game_temp.menu_beep = false
  878. $game_player.make_encounter_count
  879. $playingBGM=$game_system.playing_bgm
  880. $game_system.bgm_pause
  881. $game_system.se_play($data_system.battle_start_se)
  882. $game_system.bgm_play($game_system.battle_bgm)
  883. $game_player.straighten
  884. $scene = Scene_Battle.new
  885. end
  886. end
  887.  
  888. #==============================================================================
  889. # Scene_Battle
  890. #==============================================================================
  891. class Scene_Battle
  892. #--------------------------------------------------------------------------
  893. alias battle_end_alias battle_end
  894. def battle_end(result)
  895. battle_end_alias(result)
  896. Audio.me_stop
  897. $game_system.bgm_resume($playingBGM)
  898. end
  899. end
Expand to see the code.


!
I can't find the original thread but what you are asking does exist
viewtopic.php?f=247&t=64153&p=637717&hilit=Bgm+continues+after+battle#p637717
best I could do on my phone :c
Good luck~
That's it! But the link download Audio.dll file is dead
So that I make this topic for a help :(

!
http://www.rmxpunlimited.net/forums/topic/8593-mci-audio-module-xpvxvxa/

Just use this script. It have a addon for that.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76739