Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[EO]Adding Ogg support to EO2.0


Lavos
 Share

Recommended Posts

Alright I've used Damian666 tutorial as a reference to get this working so a big thanks to him for making this possible.
~~Keep in mind that it doesn't loop the file after it's done playing. So  I'm afraid you are just going to deal with it, until someone can figure this out.~~ Also keep in mind this is my first tutorial so go easy on me. xD

In modGenerals find: Main() and replace it.
```
Public Sub Main()
    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    ' set loading screen
    loadGUI True
    frmLoad.Visible = True

    ' load options
    Call SetStatus("Loading Options...")
    LoadOptions

    ' load main menu
    Call SetStatus("Loading Menu...")
    Load frmMenu

    ' load gui
    Call SetStatus("Loading interface...")
    loadGUI

    ' Check if the directory is there, if its not make it
    ChkDir App.Path & "\data files\", "graphics"
    ChkDir App.Path & "\data files\graphics\", "animations"
    ChkDir App.Path & "\data files\graphics\", "characters"
    ChkDir App.Path & "\data files\graphics\", "items"
    ChkDir App.Path & "\data files\graphics\", "paperdolls"
    ChkDir App.Path & "\data files\graphics\", "resources"
    ChkDir App.Path & "\data files\graphics\", "spellicons"
    ChkDir App.Path & "\data files\graphics\", "tilesets"
    ChkDir App.Path & "\data files\graphics\", "faces"
    ChkDir App.Path & "\data files\graphics\", "gui"
    ChkDir App.Path & "\data files\graphics\gui\", "menu"
    ChkDir App.Path & "\data files\graphics\gui\", "main"
    ChkDir App.Path & "\data files\graphics\gui\menu\", "buttons"
    ChkDir App.Path & "\data files\graphics\gui\main\", "buttons"
    ChkDir App.Path & "\data files\graphics\gui\main\", "bars"
    ChkDir App.Path & "\data files\", "logs"
    ChkDir App.Path & "\data files\", "maps"
    ChkDir App.Path & "\data files\", "music"
    ChkDir App.Path & "\data files\", "sound"

    ' Link the dll to the form
    InitOgg frmMenu.hwnd, 0&
    InitOgg frmMain.hwnd, 0&

    ' load the main game (and by extension, pre-load DD7)
    GettingMap = True
    vbQuote = ChrW$(34) ' "

    ' Update the form with the game's name before it's loaded
    frmMain.Caption = Options.Game_Name

    ' initialize DirectX
    If Not InitDirectDraw Then
        MsgBox "Error Initializing DirectX7 - DirectDraw."
        DestroyGame
    End If

    ' randomize rnd's seed
    Randomize
    Call SetStatus("Initializing TCP settings...")
    Call TcpInit
    Call InitMessages
    Call SetStatus("Initializing DirectX...")

    ' DX7 Master Object is already created, early binding
    Call CheckTilesets
    Call CheckCharacters
    Call CheckPaperdolls
    Call CheckAnimations
    Call CheckItems
    Call CheckResources
    Call CheckSpellIcons
    Call CheckFaces

    ' temp set music/sound vars
    Music_On = True
    Sound_On = True

    ' load music/sound engine
    InitSound
    InitMusic

    ' check if we have main-menu music
    If Len(Trim$(Options.MenuMusic)) > 0 Then PlayMidi Trim$(Options.MenuMusic)

    ' Reset values
    Ping = -1

    'Load frmMainMenu
    Load frmMenu

    ' cache the buttons then reset & render them
    Call SetStatus("Loading buttons...")
    cacheButtons
    resetButtons_Menu

    ' we can now see it
    frmMenu.Visible = True

    ' hide all pics
    frmMenu.picCredits.Visible = False
    frmMenu.picLogin.Visible = False
    frmMenu.picCharacter.Visible = False
    frmMenu.picRegister.Visible = False

    ' set values for directional blocking arrows
    DirArrowX(1) = 12 ' up
    DirArrowY(1) = 0
    DirArrowX(2) = 12 ' down
    DirArrowY(2) = 23
    DirArrowX(3) = 0 ' left
    DirArrowY(3) = 12
    DirArrowX(4) = 23 ' right
    DirArrowY(4) = 12

    ' set the paperdoll order
    ReDim PaperdollOrder(1 To Equipment.Equipment_Count - 1) As Long
    PaperdollOrder(1) = Equipment.Armor
    PaperdollOrder(2) = Equipment.Helmet
    PaperdollOrder(3) = Equipment.Shield
    PaperdollOrder(4) = Equipment.Weapon

    ' hide the load form
    frmLoad.Visible = False

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "Main", "modGeneral", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub

```
Then find: UnloadAllForms() and replace it.
```
Public Sub UnloadAllForms()
Dim frm As Form

    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    For Each frm In VB.Forms
        CloseOgg
        frmMain.tmrOgg.Interval = 0
        InitOgg frmMenu.hwnd, 0& = False
        InitOgg frmMain.hwnd, 0& = False
        Unload frm
    Next

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "UnloadAllForms", "modGeneral", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub

```
Last find: PopulateLists() and replace it.
```
Public Sub PopulateLists()
Dim strLoad As String, i As Long

    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    ' Cache music list
    strLoad = Dir(App.Path & MUSIC_PATH & "*.ogg")
    i = 1
    Do While strLoad > vbNullString
        ReDim Preserve musicCache(1 To i) As String
        musicCache(i) = strLoad
        strLoad = Dir
        i = i + 1
    Loop

    ' Cache sound list
    strLoad = Dir(App.Path & SOUND_PATH & "*.wav")
    i = 1
    Do While strLoad > vbNullString
        ReDim Preserve soundCache(1 To i) As String
        soundCache(i) = strLoad
        strLoad = Dir
        i = i + 1
    Loop

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "PopulateLists", "modGeneral", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub

```

Now in modSounds add in

```
Declare Function InitOgg Lib "vbogg.dll" (ByVal hwnd As Long, ByVal IsGlobal As Long) As Long

' returns true if bad file, false if ok
Declare Function PlayOggFile Lib "vbogg.dll" (ByVal fileName As String) As Long

Declare Function OggIsPlaying Lib "vbogg.dll" () As Long
Declare Function StopOgg Lib "vbogg.dll" () As Long
Declare Function UpdateOgg Lib "vbogg.dll" () As Long
Declare Function CloseOgg Lib "vbogg.dll" () As Long
Declare Function SetOggVolume Lib "vbogg.dll" (ByVal Volume As Long) As Long
Declare Function SetOggPan Lib "vbogg.dll" (ByVal Position As Long) As Long

```
find: PlayMidi and replace it with this code.

```
Public Sub PlayMidi(ByVal fileName As String)
Dim Splitmusic() As String

    If Options.Music = 0 Then Exit Sub

    Splitmusic = Split(fileName, ".", , vbTextCompare)

    If Performance Is Nothing Then Exit Sub
    If LenB(Trim$(fileName)) < 1 Then Exit Sub
    If UBound(Splitmusic) <> 1 Then Exit Sub

    If Not FileExist(App.Path & MUSIC_PATH & fileName, True) Then Exit Sub

    If Not Music_On Then Exit Sub

    If Music_Playing = fileName Then Exit Sub

    If Splitmusic(1) = "ogg" Then
        PlayOggFile (App.Path & MUSIC_PATH & fileName)
        frmMain.tmrOgg.Interval = 250
        Exit Sub
    ElseIf Splitmusic(1) <> "mid" Then
        Exit Sub
    End If

    Set Segment = Nothing
    Set Segment = Loader.LoadSegment(App.Path & MUSIC_PATH & fileName)

    ' repeat midi file
    Segment.SetLoopPoints 0, 0
    Segment.SetRepeats 100
    Segment.SetStandardMidiFile

    Performance.PlaySegment Segment, 0, 0

    Music_Playing = fileName

End Sub

```
Then find: StopMidi() and replace it.

```
Public Sub StopMidi()
    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    StopOgg
    frmMain.tmrOgg.Interval = 0

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "StopMidi", "modSound", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub

```
Now make a timer on frmMain and name it tmrOgg. then add the code in.

```
Private Sub tmrOgg_Timer()
Dim MusicFile As String

    If (OggIsPlaying And 1) = 1 Then
        UpdateOgg
    Else
    ' start music playing
        MusicFile = Trim$(Map.Music)
        If Not MusicFile = "None." Then
            PlayMidi MusicFile
        End If
    End If

End Sub

```

Then in frmMapProperites under cmdPlay add Options.Music = 1 and cmdStop add Options.Music = 0

Then Download the dll files and add it to your folder.
Link: http://www.mediafire.com/?xqvfckf9wfdowo0

Done! I hope I didn't miss anything else otherwise send a feed back if there is any problem.=)
Link to comment
Share on other sites

what you could do to make it loop, is add a check for if its playing, if not, restart it.

just add it in the main loop, something like LoopOgg()

```
Public sub LoopOgg()
    if not OggIsPlaying then
          PlayOggFile(map.music)
    end if
end sub

```
please note this is code from the top of my head, and should proberly be adjusted to work, lets call it pseudo code shall we? xd

Dami
Link to comment
Share on other sites

PlayOggFile will crash if you try to use it with any other format, but I finally figured it out. I've updated the first post so everything should work fine now. The only issues is that when I name my .ogg files to numbers, it saves it in the map file. Any other names would not save.
Its also sloppy but it works  :cheesy:
Link to comment
Share on other sites

  • 2 weeks later...
Hi there, just tried the tutorial and it works :)

Although there are a few things that could do with improving in the topic. Its best not to put code inside a spoiler box as you cant see all of it when you open the box, I like to see what code I'm adding to my source and it can be quite off putting pasting in something you don't know the size of.

Another issue is that all of your code requires overwriting subs with your own subs, this is fine if you are working with a fresh copy of Eclipse but not at all good if you have added in your own stuff or used other tutorials. For instance you told us to completely overwite the Sub Main while only adding in 2 extra lines of code.

Also you have some code that you have left over from another tutorial or something, "Call CheckBackgrounds" that gives an error.
Link to comment
Share on other sites

Thanks for pointing that out. I got checkbackground removed from the tutorial. Also sorry about the whole replacing the sub issue. This tutorial was mainly aimed for people who are still new to vb6, but I'm sure with skilled programmers would be able to read what is going on with the code.
Link to comment
Share on other sites

> Now in modSounds add in
>
> Code: [Select]
> Declare Function InitOgg Lib "vbogg.dll" (ByVal hwnd As Long, ByVal IsGlobal As Long) As Long
>
> ' returns true if bad file, false if ok
> Declare Function PlayOggFile Lib "vbogg.dll" (ByVal fileName As String) As Long
>
> Declare Function OggIsPlaying Lib "vbogg.dll" () As Long
> Declare Function StopOgg Lib "vbogg.dll" () As Long
> Declare Function UpdateOgg Lib "vbogg.dll" () As Long
> Declare Function CloseOgg Lib "vbogg.dll" () As Long
> Declare Function SetOggVolume Lib "vbogg.dll" (ByVal Volume As Long) As Long
> Declare Function SetOggPan Lib "vbogg.dll" (ByVal Position As Long) As Long

Where to add in in modSound?? ò.O
Link to comment
Share on other sites

So i got the same problem like in the MP3 turtorial i've done all 3 times but nothing happens when i push on play :/ the files are shown up but they dont want to play if i press the play button… :/ can some one help me? i got no error or like that the only thing is that the files make no sound.
Link to comment
Share on other sites

so i added this here

```
Private Sub cmdStop_Click()
    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    Add Options.Music = 0
    StopMidi

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "cmdStop_Click", "frmEditor_MapProperties", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub
```
And the play here

```
Private Sub cmdPlay_Click()
    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    Options.Music = 1
    StopMidi
    PlayMidi lstMusic.List(lstMusic.ListIndex)

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "cmdPlay_Click", "frmEditor_MapProperties", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub
```
should i have to add something in the server? because itt dont plays my musik >.<
Link to comment
Share on other sites

  • 4 weeks later...
I put in everything where you wanted me to in visual basic 6\. I wasn't sure of where to put Options.Music = 1 and Options.Music = 0 in cmdplay and cmdstop so i put them where i thought they should go. Whenever i go to map properties the .ogg files i have in the music folder don't show up.
Link to comment
Share on other sites

@Furryfox137:

> I put in everything where you wanted me to in visual basic 6\. I wasn't sure of where to put Options.Music = 1 and Options.Music = 0 in cmdplay and cmdstop so i put them where i thought they should go. Whenever i go to map properties the .ogg files i have in the music folder don't show up.

Double check everything. You probably not following the tutorial correctly. Look into modGenerals and modSounds to see if you have done everything with each sub.
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
~~How would I get this to work with sounds for Items and spells? I have 180 sound effects in OOG format.

-_-… as a matter of fact i cant use this thanks to previous mods... can some one please rewrite this to be more fiendly with custom clients and servers. Mine had way too many errors to count.~~

I have a converter (found one) XD
Link to comment
Share on other sites

  • 9 months later...
Hello,

Awesome tutorial, tried it and works wonders :) However I Noticed that stopmidi deleted the following lines:

    If Not (Performance Is Nothing) Then Performance.Stop Segment, Nothing, 0, 0
    Music_Playing = vbNullString

Hence if a midi was playing it will not stop it… if you add that line back it stops both midi and ogg...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...