ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

How to bundle a game's source file and its interpreter into a single EXE

<< < (5/7) > >>

hollowlife1987:
HollowLife, thank you for your offer.  It's much appreciated.  If I understand you correctly, you're staying that if I can come up with a working interpreter EXE, I can supply that, plus a binary game file produced by my game compiler, and you can give me source code that would incorporate those two files into an EXE.  What language would you supply this in?  I am only familiar with C# and (to a lesser extent) Visual Basic.  However, I do have a couple of different C/C++ compilers.
--- End quote ---

The language I can do it would be C# as that would be the best your interpreter is in C#

If you let me use your interpreter and a sample source file it would be alot easier for you to understand when I give you the source code.

kyrathaba:
Excellent.  I don't have the compiler anywhere near a functional level, yet.  I'm still working on methods to extract, from the source file, data for rooms, items, actors, etc.  I'll work on it.  If I can just get enough done to compile a simple game (say, two connected rooms), and can provide an interpreter to run the compiled game file, I can probably learn enough by seeing how you implement that for me to extend your source code as I add further functionality.

kyrathaba:
Thinking about it further, if I supplied you with a text file containing the string "I am a string", and an EXE interpreter that when executed would write that file's string to the console, could you in turn show me how to include those two files into an EXE wrapper such that executing the EXE caused the string to be written to the console?

hollowlife1987:
Sure that would work just fine.

kyrathaba:
I did a little experimentation and came up with a C# program that can, itself, compile C# source code.  The downloadable zip contains a folder with two files: (1) temp_app.exe, and (2) myfile.txt.  The first file is the physical executable I created with the Visual C# Express IDE.  The second file contains a brief C# program source code listing.  

Make sure you have the .NET Framework 2.0 installed, then open the folder and double-click on the EXE.  Read the program's console output and wait for it to exit, and you'll see that the text source file has been compiled into "myfile.exe" :> 

Here's the source code:


--- Code: C# ---using System;using System.IO;using System.CodeDom;using System.CodeDom.Compiler;using Microsoft.CSharp; namespace CompilationTest {       class Comp {         public static int Main(string[] args) {                         CodeDomProvider cdp = new CSharpCodeProvider();             bool result = Comp.CompileCode(cdp, "myfile.txt", "myexe.exe");             Console.WriteLine("\tProgram will exit on its own in 7 seconds...");            System.Threading.Thread.Sleep(7000);             return 1;         }          public static bool CompileCode(CodeDomProvider provider, string sourceFile, string exeFile) {             string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);            CompilerParameters cp = new CompilerParameters();            CompilerResults cr = null;             // Generate an executable instead of            // a class library.            cp.GenerateExecutable = true;             // Set the assembly file name to generate.            cp.OutputAssembly = exeFile;             // Generate debug information.            cp.IncludeDebugInformation = true;             cp.ReferencedAssemblies.Add("mscorlib.dll");             // Save the assembly as a physical file.            cp.GenerateInMemory = false;             // Set the level at which the compiler            // should start displaying warnings.            cp.WarningLevel = 3;             // Set whether to treat all warnings as errors.            cp.TreatWarningsAsErrors = false;             // Set compiler argument to optimize output.            cp.CompilerOptions = "/optimize";             // Set a temporary files collection.            // The TempFileCollection stores the temporary files            // generated during a build in the current directory,            // and does not delete them after compilation.            cp.TempFiles = new TempFileCollection(PersonalFolder, true);             Console.WriteLine();             if (provider.Supports(GeneratorSupport.EntryPointMethod)) {                // Specify the class that contains                // the main method of the executable.                //cp.MainClass = "Comp";                  // Invoke compilation.                cr = provider.CompileAssemblyFromFile(cp, sourceFile);                 if (cr.Errors.Count > 0) {                    // Display compilation errors.                    Console.WriteLine("\tErrors building {0} into {1}",                        sourceFile, cr.PathToAssembly);                    foreach (CompilerError ce in cr.Errors) {                        Console.WriteLine("  {0}", ce.ToString());                        Console.WriteLine();                    }                } else {                    Console.WriteLine("\tSource {0} built into {1} successfully.",                        sourceFile, cr.PathToAssembly);                    Console.WriteLine("\t{0} temporary files created during the compilation.",                        cp.TempFiles.Count.ToString());                }            }//end if             // Return the results of compilation.            if (cr.Errors.Count > 0) {                 return false;             } else {                 return true;            }          }//end method CompileCode()     }//end class Comp }//end namespace CompilationTest

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version