Sunday, February 10, 2019

XNA game publishing help with incompatibilities via content built at runtime


MY XNA game is finally complete, but I'm having difficulty getting it to run on other Windows computers. I've read similar other stackexchange topics here, here, and here, but I'm still gonna need help on the specifics of my particular program.


I'm using XNA 4.0 in Visual Studio 2010 on a Windows 7 Professional 64-bit machine. The game was done in C#. I've made release builds on my machine and they work great.


I don't care about Windows XP or Windows Vista. I'm only targeting Windows 7 and Windows 8, 32- and 64-bit. I could not get my game to run properly on them. The game always crashes at startup, either silently or with a crash message.


So I discovered that the ClickOnce publisher/installer will supposedly ensure that the prerequisites (such as .Net 4.0 and XNA Redistributable) get put on the target machine. However, I found that microsoft says here: "Also, the XNA Framework Redistributable file does not contain the Content Pipeline Build Runtime. Building content at run time is supported only when XNA Game Studio has been installed on the Windows-based development computer."


This leads to a problem. I'm pretty sure my game does in fact build content at runtime because there is only one music resource that loads different music files at different times. Here is the code.


public void scr_play_song(byte s)
{

if (SEI_MSC != null)
SEI_MSC.Stop();

if (s == 1)
{
System.IO.FileStream fs = new System.IO.FileStream(@"Music\msc01_Legend.wav", System.IO.FileMode.Open);
TG.MUSIC = SoundEffect.FromStream(fs); // TG.MUSIC is a SoundEffect class
fs.Dispose();

SEI_MSC = TG.MUSIC.CreateInstance(); // SEI_MUSIC is a SoundEffectInstance class

SEI_MSC.IsLooped = true;
SEI_MSC.Volume = vol_music;
SEI_MSC.Play();
}
else if (s == 2)
{
// same stuff for other music files, etc
}
}


However, I could be mistaken, so: is this actually building content at runtime? Or is it just loading/streaming into an already-existing resource?


Before you ask, yes I'm using .wav files for music because .mp3 files are proprietary that charge an absurd license fee ($2,500 last I checked). Sadly in addition, I cannot let my .wav music files be normal resources that turn into .xnb files, because they total over 300 MB, which is too big of a download. Therefore, my installer will come with ogg vorbis files that then get decompressed into .wav files.


(BTW ive come across "solutions" where you can get .ogg natively working in XNA, but they were some real "hack" jobs in my experience and I have serious concerns that such "solutions" will add another layer of incompatibility.)


If someone has a better idea how to go about music, please let me know.


OK so now let me list all the references in my game:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Storage;
using System.IO;

And from the References tree in my game project, there's also:



Microsoft.Xna.Framework Microsoft.Xna.Framework.Avatar Microsoft.Xna.Framework.Game Microsoft.Xna.Framework.GamerServices Microsoft.Xna.Framework.Graphics Microsoft.Xna.Framework.Net Microsoft.Xna.Framework.Storage Microsoft.Xna.Framework.Video Microsoft.Xna.Framework.Xact mscorlib System System.Core System.Net System.Xml System.Xml.Linq


(I may need to remove some of these tho. I can't imagine where Framework.Video came from cuz i'm not using any video files at all. I've also heard bad incompatibility things about Framework.GamerServices. My game does NOT use the internet at all.)


Based on this list, can someone confirm that the only things my target machines will need are .Net 4.0 and XNA Redistributable?


Besides loading music at runtime, the only other "special" thing my game does is read/write to a file for the purposes of saving level progress. Here's the code:


    public void scr_load_progress()
{
if (File.Exists("Progress") == false)
{
scr_save_progress();
return;

}

LevelData = File.ReadAllLines("Progress");

for (int i = 0; i < ASZ; i += 1)
{
LevelDones[i] = LevelData[i].ElementAt(0) - '0';
}
}


public void scr_save_progress()
{
File.WriteAllLines("Progress", LevelData);
}

My game does not do anything else "special" as far as I know. It does not use the internet at all.


There's one more undesirable thing about ClickOnce publishing. It looks like I can't insert my own EULA (the legal agreement you have to accept) in it. This is why I'm using InnoSetup and would prefer to continue with it. I suppose I could use both and just let the Inno Installer call the setup.exe from ClickOnce, but that still doesn't get me around the other issue about building content at runtime.


At this point, I've considered moving this game to Mono or MonoGame (i have no idea what the difference is), but my deadline is fast approaching and I've never touched Mono and have no idea how difficult it will be to port my game. Plus i've already come across Mono topics about similar troubles with exactly what prerequisites are needed on target machines and how to get them installed.


Sorry for the many paragraphs but there were a lot of specifics I needed to list. I hope someone can help. To summarize:


Does my music code actually build content at runtime, or does it just load/stream?



Based on my list of references, will a ClickOnce setup.exe ensure the necessary prerequisites are installed?


Thanks in advance. I really miss the good old days where programs only ever called external .DLLs so you could just copy them in the same folder as the .exe, which has the added benefit of letting the developer (and user) easily see EXACTLY what dependencies there are. Oh well.



Answer



The following worked for Monogame. You can copy the .dlls to your game folder (the content folder is probably a better choice), then reference them and delete the old references, like I do below. You can take the exact same logic and apply it for Microsoft.Xna.Framework.dll, and every other Xna related .dll you are referencing. For Xna, all the .dlls are in this path for me C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\.


1


I copied the game folder, double clicked the .exe and my game opened on a fresh installed windows 7 64-bit computer.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...