ContentPipeline at runtime in XNA? - c#

Does anyone know of anyway to simulate the ContentPipeline in XNA at run-time?
It is my understand that the XNA Content Pipeline makes use of MSBuild at game compile time, which is obviously not redistributable (and definitionally not at run-time).
But if I have an fxb file, and can read the fxb format directly, is there any way to process the file "inline" at run-time, and just build a model myself rather than calling
Model m = Content.Load<Model>("resource name")?
Any help greatly appreciated. Thanks.

This sample on the app hub site does just that:
http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_2
Its associated with widows forms and xna, but you may glean the run time content processing out of it even if your not using winforms.

Related

Run ICE Validation against windows installer database using c#

I'm wondering if anyone can help.
I have an c# application to make modifications to multiple in house msi files.
We want to run ICE validation and get the results back in my application. I know i can run MsiVal2.exe as a process and output the results back to the app but i would ideally like to run it all via code.
There is an evalcom2.dll which appears to be written in c++ but there seems to be very little information around using this.
Im surprised that nobody seems to have done this or is there an easier way like using one of the wix libraries or some thing?
Any Help would be much appreciated.
WiX Toolkit: I don't really use it manually that much (I validate using Orca), but the WiX toolset itself contains the binary smoke.exe. I believe it is run for every build in Visual Studio? Not sure. The full source available on github.com.
Looks possible to adapt to your own project. You could also just pass it to the compiled smoke.exe I guess. In the code, you can see:
Line 180: validator.Validate(Path.GetFullPath(inputFile));
Validator.cs is in the WiX project (https://github.com/wixtoolset/wix3/tree/develop/src/tools/wix)

What is the correct approach to integrate an external ChessEngine with my Unity project?

I am developing a Chess Game in Unity. I am not writing the AI by myself but using the chess engine named MadChess.
I downloaded the source code of the engine(which is written in C#) as well as the executable file named "MadChess.exe"(which is basically a command prompt through which we can talk with the engine following UCI protocols)
I haven't actually integrated a chess engine with a unity project before and also not able to find many resources online on how to do it.
Approach 1:
Initially, I wrote a C# script in Unity which creates a separate process to communicate with "MadChess.exe" but I later realized that the approach is buggy. This is because when I build my Unity Project as a standalone application for Windows, it is dependent on the physical "MadChess.exe" file located on my PC i.e. it doesn't build everything(My Unity Project code along with the Chess Engine Code) together into a single executable application. This according to me is faulty and can only be rectified by creating an installer of the game which injects the "MadChess.exe" file along with my main Unity code.
Approach 2:
Now, I am trying to go through the source code of MadChess chess engine project and basically creating .dll files of the chess engine project which I plan to use as plugins in my Unity project. I would interface with them through my C# code in Unity eventually. Is it the correct way or not?
I am stuck at this for around a week or so and still not able to find a clear way. I don't want to spend another week just to realize that I am doing it wrong. Even if I am wrong from the start please let me know. I simply want to integrate a Chess Engine with my Unity Project. If someone has any suggestions or ideas or if someone has done this before please guide me. I would be grateful. Thanks for bearing with me till here.
I recommend using Approach 1
Both approaches sound valid, but I recommend using Approach 1 to communicate with MadChess.exe as a process, because this is much less work than Approach 2, especially if you already have the first approach working (aside from the build issue).
Also, aside from the source code, if the MadChess project is only providing the exe and not the dll files, then I think it's safer to stick with the approach that is implicitly "recommended" by the project. You don't know what kinds of issues you'll run into when you try to make the dll files yourself (and it sounds like you have been running into issues already).
Even though it should be possible to use dll files, I think it's preferable to pick the approach that will let you progress on your project faster. You can always switch to Approach 2 later if you run into other issues.
(Just make sure to show appropriate errors in case MadChess.exe is not found, so that you can troubleshoot issues quickly.)
How to include MadChess.exe as part of your build
You don't necessarily need an installer to include the MadChess.exe file with your game. You can also copy MadChess.exe as part of the Build Player Pipeline. Using either BuildPipeline.BuildPlayer or the PostProcessBuildAttribute, you can get the path of the built project, and then use FileUtil.CopyFileOrDirectory to copy MadChess.exe during the build step.
Also, as #AdrianSgro mentioned in a comment, StreamingAssets works as well. (But note that the documentation explicitly mentions that .dll files in this folder are not included if you need to include any dll dependencies.)

Winform embeded XNA contentmanager only recognize XNB

I'm writing a MapEditor in winform with embeded XNA.
And my biggest problem is whenever I try to load any file with the ContentManager, it only reads .XNB files.
I wanted to read an effect file like this:
effect = contentManager.Load<Effect>("Effect2");
But then I get the error that "Effect2.xnb doesn't exists".
And if I add "Effect2.fx" it still give me error with the message "Effect2.fx.xnb doesn't exists" :\
I have no idea what to do.
I saw a solution by set the content properties. But I cannot set those properties in this case,because it's a winform application.
Does anyone have a great idea or anything?
Edit!
Solution found!
I implemented the ContentBuilder from this example with writing a few helper methods for dynamic loading: http://create.msdn.com/en-US/education/catalog/sample/winforms_series_2
You'll have to add an XNA Content project, and include your content in that project. All of those files will be compiled/processed into individual XNB files, which you'll be able to load. Just make sure to reference that project in your WinForms project.
The same rules apply for a Game project: It still needs an accompanying Content project.
EDIT:
Ahh, right... you want to load them dynamically. For that, you'll need to ensure that any computer that tries to use your map editor will have the XNA development framework installed. Then you'll need to process the files manually before loading them with the ContentManager... not entirely sure how to do this.
EDIT:
Take a look at this post for more information about loading unprocessed content at runtime: How do I load a texture in XNA at runtime?

How does one inject resources into an already built executable

I am working on a windows application that will need to be branded. The client will be selling this to other businesses, and needs a customized logo and name for each sale.
The client does not know how to use visual studio!
I think I need to write a packager app to inject custom logo and string resources into the executable. I am planning on using WPF. But since this is a critical requirement, I'd be willing to do it in winforms if that is easier.
What is the best way to do this? Any and all suggestions welcome.
It sounds like what you are after is application skinning. This doesn't mean you have to unpack the exe and inject resources. You just need to consider skinning from the start of the project and build the application to support your skinning requirements.
WPF will make skinning your app much easier. There will be several different ways to accomplish what you want.
Simplest is to leave the logo image loose and reference it with a relative path from the XAML file(s) that need to show this image.
You should look into Resource Dictionaries in WPF and how they help you group resources and support skinning. http://msdn.microsoft.com/en-us/library/ms750613.aspx
The text will be a little different but I am not sure what you need as far as a text goes. Do you mean you need to localize the strings or do you simply need different text (all the same locale) to show for different clients?
One possible solution (perhaps not the simplest one) is to use a parent application which compiles source code for generating child application. You can do it with CSharpCodeProvider and CompilerParameters classes. Add the image as an embedded resource and retrieve it in the child application. A working demo with a source code is available at Slide Show Builder.
My best suggestion for the exact question you asked (although I suspect there is another way by reconsidering the exact requirements) would be to write a utility which uses ildasm to disassemble the assembly, then use ilasm to reassemble it and include your new resource file.
http://msdn.microsoft.com/en-us/library/496e4ekx%28VS.71%29.aspx
The trivial solution is to provide the bitmap along with the EXE as a separate file. Actually replacing an embedded resource in the EXE requires decompiling it with ildasm.exe and putting it back together with ilasm.exe. Ildasm.exe is only available in the Windows SDK, it can be downloaded separately. Error prone and small odds that your customer can get that right, you'll need to provide them with, say, a .bat file that does this.
Of course, whomever is interested in replacing the logo, for whatever reason, would not be slowed down by replacing either the separate image file or using the Ildasm.exe trick. There is therefore very little point in making it any more complicated then it needs to be.

Working way to make video from images in C#

Does anybody have a known reliable way to create a video from a series of image files? Before you mod me down for not searching for the answer before posting the question, and before you fire off a simple message like "use FFMPEG," read the rest of this message.
I'm trying to create a video, it doesn't matter too much what format as long as it's widely supported, from a series of images (.jpg, .bmp, etc.). My platform is Windows Server 2008, 64-bit. If I can make the video from within my C# program, that's great, but I'm not averse to writing a series of image files to a directory and then firing off an external program to make a video from those images.
The only constraints are: it must work on my Windows Server 2008 system, and be scriptable. That is, no GUI programs that require operator intervention.
I found a number of similar questions on StackOverflow, and have tried several of the solutions, all with varying degrees of frustration and none with anything like success.
FFMPEG looks like a great program. Maybe it is, on Linux. The two Windows builds I downloaded are broken. Given this command line:
ffmpeg -r 1 -f image2 -i jpeg\*.jpg video.avi
One of the builds reads the images and then crashes due to data execution prevention. The other reads the first file and then spits out an error message that says "cannot find suitable codec for file jpeg/image2.jpg". Helpful, that. In any case, FFMPEG looks like a non-starter under Windows.
One answer to a previous posting recommended Splicer . It looks like pretty good code. I compiled the samples and tried to run, but got some cryptic error message about a file not found. It looks like a COM class isn't registered. I suppose I need to install something (DirectShow, maybe, although I thought that was already installed?). Depending on what's required, I might have a difficult time justifying its installation on a server. ("What? Why do you need that on a server?")
Another answer suggested the AviFile library from Code Project. That looks simple enough: a wrapper around the Windows AviFile subsystem. Except that the AVI files the package creates appear to have all of the frames, but only the first frame shows when I play the AVI in Windows Media Player. Well, that and if you try to create a compressed video, the program throws an exception.
So, I'm left wondering if there is a good, reliable way to do what I want: on a Windows system, create an AVI or other common video file format from a series of images, either through a .NET API or using an external program. Any help?
After working with it a while and taking a look at x264 and VideoLan, I went back to Splicer. It turns out that the cryptic error message was due to an error in my code.
It looks like Splicer will do what I want: programmatically create videos from a series of images.
Thanks to all who responded.
You can use VideoLan and I'd recommend it.
I've had direct experience in a C# application with VideoLan doing these two things:
Embedding a VLC viewer in my C# application (there are 3-4 C# "wrappers" for the VLC veiwer).
Using vlc.exe in a separate Process by sending it command-line arguments.
The fact that VideoLan has a command-line interface is a great thing. And VLC supports a command-line option that disables any visual element; so the VLC GUI doesn't pop up and neither does a command-line window. Thus, in a C# application you can farm out the video-related work to the VLC client. C# has the Process class which can manage your vlc.exe instances for you. It ends up being a pretty neat solution.
The handling of video on Windows (encoding and playback) is a real quagmire. And .NET isn't going to help you at all - you're always going to be either PInvoking/COM-interoping native APIs or using a .NET wrapper that someone else has built to do the same.
Anyway, I can't say I've used it, but a good bet seems to be the x264 library that is part of the videolan project. That gives you a self-contained C library that you can PInvoke and you don't have to worry about installing and DirectShow garbage on your server. It'll generate H.264 format video which is playable in Flash as I understand it.
I've used mplayer's mencoder to create AVI (with codecs msmpeg4/mp3, readable by default with Windows Media Player) from TGA files on linux like this:
mencoder mf://*.tga -mf fps=25:type=tga \
-audiofile /tmp/test.mp3 -oac copy \
-of lavf -ovc lavc \
-lavcopts vcodec=msmpeg4v2:mbd=2:mv0:trell:cbp:last_pred=3:vbitrate=3000 \
-o /tmp/test.avi
I know mplayer does have a Windows version.
Instead of just going through all the hassle, you could coppy all the images that you want to be included in your video to the clipboard and have it imported into Windows Live Movie Maker (dynamically, of course!) and have it compile for you!
All of this CAN be done through code, but this way, you don't have to create it yourself. As you said that the platform was Windows, and ALL Windows comps have Windows Live Movie Maker installed, so it shouldn't be a problem for anyone using your application unless
a) They uninstalled Windows Live Movie Maker
b) They are using a computer running on a Windows Version more than 8 or 9 years old...

Categories

Resources