using GMAssetCompiler.Machines; using GMAssetCompiler.Output; using NDesk.Options; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net; using System.Net.Mail; using System.Reflection; using System.Text; using System.Windows.Forms; namespace GMAssetCompiler { internal static class Program { private static OptionSet m_options; //public static bool IsPSPFileLoaded = false; public static eTexType[] TextureType; public static IMachineType MachineType { get; set; } public static string OutputDir { get; set; } public static bool WriteTextures { get; set; } public static bool WriteWaves { get; set; } public static bool CompileOnly { get; set; } public static bool SplashOmit { get; set; } public static bool SeparateOpaqueAndAlpha { get; set; } public static bool DisplaySortedTextures { get; set; } public static int TexturePageWidth { get; set; } public static int TexturePageHeight { get; set; } public static int TextureScale { get; set; } public static bool Verbose { get; set; } public static bool CompileVerbose { get; set; } public static bool RemoveDND { get; set; } public static bool CenterHTML5Game { get; set; } public static bool NoCache { get; set; } public static bool NoIndexHTML { get; set; } public static string HTMLRunner { get; set; } public static bool DoObfuscate { get; set; } public static bool ObfuscateObfuscate { get; set; } public static bool ObfuscatePrettyPrint { get; set; } public static bool ObfuscateRemoveUnused { get; set; } public static bool ObfuscateEncodeStrings { get; set; } public static string LoadingBarName { get; set; } public static bool CustomLoadingScreen { get; set; } public static int ExitCode { get; set; } public static bool InhibitErrorOutput { get; set; } public static GMAssets Assets { get; set; } public static bool Studio { get; set; } public static Dictionary> TextureGroups { get; set; } public static TextWriter Out { get; set; } public static string TextureTypeExtension(eTexType _textureType) { switch (_textureType) { case eTexType.eDXT: return ".dds"; case eTexType.ePVR: return ".pvr"; case eTexType.eRaw: case eTexType.e4444: return ".raw"; case eTexType.ePNG: return ".png"; default: return ".dds"; } } private static void ShowHelp() { Console.WriteLine("Usage is:"); Console.WriteLine("\tSillicaAssetCompiler []+"); m_options.WriteOptionDescriptions(Console.Out); Environment.Exit(0); } public static void SetMachineType(string _m) { _m = "psp"; // Allways PSP switch (_m.ToLower()) { case "nokia": case "symbian": case "qt": MachineType = new Symbian(); break; case "droid": case "android": MachineType = new Android(); break; case "ipad": case "iphone": case "ipod": case "ios": MachineType = new IOS(); break; case "psp": MachineType = new PSP(); break; case "windows": case "win": MachineType = new Windows(); break; case "html5": MachineType = new HTML5(); break; } if (MachineType != null) { TextureType[0] = MachineType.OpaqueTextureType; TextureType[1] = MachineType.AlphaTextureType; TexturePageWidth = MachineType.TPageWidth; TexturePageHeight = MachineType.TPageHeight; } } private static eTexType SetTextureType(string _t) { eTexType result = eTexType.eRaw; switch (_t.ToLower()) { case "png": result = eTexType.ePNG; break; case "raw": result = eTexType.eRaw; break; case "dxt": result = eTexType.eDXT; break; case "pvr": result = eTexType.ePVR; break; case "16b": case "16bit": case "4444": result = eTexType.e4444; break; } return result; } private static void DoPreObfuscateLib(string _sourceDir, string _outputDir) { List files = new List(); HTML5Saver.GetFiles(_sourceDir, new string[3] { ".svn", "runner.js", "particles" }, files); List list = new List(); foreach (KeyValuePair ms_func in GMLCompile.ms_funcs) { list.Add(ms_func.Key); } foreach (KeyValuePair ms_builtin in GMLCompile.ms_builtins) { list.Add(ms_builtin.Key); if (!string.IsNullOrEmpty(ms_builtin.Value.setFunction)) { list.Add(ms_builtin.Value.setFunction); } if (!string.IsNullOrEmpty(ms_builtin.Value.getFunction)) { list.Add(ms_builtin.Value.getFunction); } } foreach (KeyValuePair item2 in GMLCompile.ms_builtinsArray) { list.Add(item2.Key); if (!string.IsNullOrEmpty(item2.Value.setFunction)) { list.Add(item2.Value.setFunction); } if (!string.IsNullOrEmpty(item2.Value.getFunction)) { list.Add(item2.Value.getFunction); } } foreach (KeyValuePair item3 in GMLCompile.ms_builtinsLocal) { list.Add(item3.Key); if (!string.IsNullOrEmpty(item3.Value.setFunction)) { list.Add(item3.Value.setFunction); } if (!string.IsNullOrEmpty(item3.Value.getFunction)) { list.Add(item3.Value.getFunction); } } foreach (KeyValuePair item4 in GMLCompile.ms_builtinsLocalArray) { list.Add(item4.Key); if (!string.IsNullOrEmpty(item4.Value.setFunction)) { list.Add(item4.Value.setFunction); } if (!string.IsNullOrEmpty(item4.Value.getFunction)) { list.Add(item4.Value.getFunction); } } foreach (KeyValuePair ms_constant in GMLCompile.ms_constants) { list.Add(ms_constant.Key); } string[] array = new string[] { "antialias", "charset", "i", "c", "JSON_game", "Options", "debugMode", "loadingBarCallback", "gameId", "gameGuid", "fullScreen", "interpolatePixels", "showCursor", "scale", "allowFullScreenKey", "freezeOnLostFocus", "showLoadingBar", "displayErrors", "writeErrors", "abortErrors", "variableErrors", "Textures", "Triggers", "pName", "moment", "pFunc", "Extensions", "TriggerEvents", "jsFiles", "init", "final", "Sounds", "pName", "kind", "extension", "origName", "effects", "volume", "pan", "preload", "Sprites", "width", "height", "bboxMode", "transparent", "smooth", "preload", "colCheck", "xOrigin", "yOrigin", "bboxLeft", "bboxRight", "bboxTop", "bboxBottom", "TPEntryIndex", "Masks", "Backgrounds", "Paths", "kind", "closed", "precision", "points", "speed", "Fonts", "size", "bold", "italic", "first", "last", "TPageEntry", "scaleX", "scaleY", "glyphs", "w", "h", "shift", "offset", "Timelines", "Events", "Time", "Event", "GMObjects", "spriteIndex", "visible", "solid", "persistent", "depth", "parent", "spritemask", "CollisionEvents", "CreateEvent", "DestroyEvent", "StepBeginEvent", "StepNormalEvent", "StepEndEvent", "DrawEvent", "NoButtonPressed", "LeftButtonDown", "RightButtonDown", "MiddleButtonDown", "LeftButtonPressed", "RightButtonPressed", "MiddleButtonPressed", "LeftButtonReleased", "RightButtonReleased", "MiddleButtonReleased", "GlobalLeftButtonDown", "GlobalRightButtonDown", "GlobalMiddleButtonDown", "GlobalLeftButtonPressed", "GlobalRightButtonPressed", "GlobalMiddleButtonPressed", "GlobalLeftButtonReleased", "GlobalRightButtonReleased", "GlobalMiddleButtonReleased", "MouseEnter", "MouseLeave", "OutsideEvent", "BoundaryEvent", "StartGameEvent", "EndGameEvent", "StartRoomEvent", "EndRoomEvent", "NoLivesEvent", "AnimationEndEvent", "EndOfPathEvent", "NoHealthEvent", "CloseButtonEvent", "OutsideView0Event", "BoundaryView0Event", "UserEvent0", "UserEvent1", "UserEvent2", "UserEvent3", "UserEvent4", "UserEvent5", "UserEvent6", "UserEvent7", "UserEvent8", "UserEvent9", "UserEvent10", "UserEvent11", "UserEvent12", "UserEvent13", "UserEvent14", "UserEvent15", "WebImageLoadedEvent", "WebSoundLoadedEvent", "WebAsyncEvent", "ObjAlarm0", "ObjAlarm1", "ObjAlarm2", "ObjAlarm3", "ObjAlarm4", "ObjAlarm5", "ObjAlarm6", "ObjAlarm7", "ObjAlarm8", "ObjAlarm9", "ObjAlarm10", "ObjAlarm11", "KeyPressed_", "KeyPressed_NOKEY", "KeyPressed_ANYKEY", "KeyPressed_BACKSPACE", "KeyPressed_TAB", "KeyPressed_ENTER", "KeyPressed_SHIFT", "KeyPressed_CTRL", "KeyPressed_ALT", "KeyPressed_PAUSE", "KeyPressed_ESCAPE", "KeyPressed_SPACE", "KeyPressed_PAGEUP", "KeyPressed_PAGEDOWN", "KeyPressed_END", "KeyPressed_HOME", "KeyPressed_LEFT", "KeyPressed_UP", "KeyPressed_RIGHT", "KeyPressed_DOWN", "KeyPressed_INSERT", "KeyPressed_DELETE", "KeyPressed_0", "KeyPressed_1", "KeyPressed_2", "KeyPressed_3", "KeyPressed_4", "KeyPressed_5", "KeyPressed_6", "KeyPressed_7", "KeyPressed_8", "KeyPressed_9", "KeyPressed_A", "KeyPressed_B", "KeyPressed_C", "KeyPressed_D", "KeyPressed_E", "KeyPressed_F", "KeyPressed_G", "KeyPressed_H", "KeyPressed_I", "KeyPressed_J", "KeyPressed_K", "KeyPressed_L", "KeyPressed_M", "KeyPressed_N", "KeyPressed_O", "KeyPressed_P", "KeyPressed_Q", "KeyPressed_R", "KeyPressed_S", "KeyPressed_T", "KeyPressed_U", "KeyPressed_V", "KeyPressed_W", "KeyPressed_X", "KeyPressed_Y", "KeyPressed_Z", "KeyPressed_F1", "KeyPressed_F2", "KeyPressed_F3", "KeyPressed_F4", "KeyPressed_F5", "KeyPressed_F6", "KeyPressed_F7", "KeyPressed_F8", "KeyPressed_F9", "KeyPressed_F10", "KeyPressed_F11", "KeyPressed_F12", "KeyPressed_NUM_LOCK", "KeyPressed_NUM_0", "KeyPressed_NUM_1", "KeyPressed_NUM_2", "KeyPressed_NUM_3", "KeyPressed_NUM_4", "KeyPressed_NUM_5", "KeyPressed_NUM_6", "KeyPressed_NUM_7", "KeyPressed_NUM_8", "KeyPressed_NUM_9", "KeyPressed_NUM_STAR", "KeyPressed_NUM_PLUS", "KeyPressed_NUM_MINUS", "KeyPressed_NUM_DOT", "KeyPressed_NUM_DIV", "Key_NOKEY", "Key_ANYKEY", "Key_BACKSPACE", "Key_TAB", "Key_ENTER", "Key_SHIFT", "Key_CTRL", "Key_ALT", "Key_PAUSE", "Key_ESCAPE", "Key_SPACE", "Key_PAGEUP", "Key_PAGEDOWN", "Key_END", "Key_HOME", "Key_LEFT", "Key_UP", "Key_RIGHT", "Key_DOWN", "Key_INSERT", "Key_DELETE", "Key_0", "Key_1", "Key_2", "Key_3", "Key_4", "Key_5", "Key_6", "Key_7", "Key_8", "Key_9", "Key_A", "Key_B", "Key_C", "Key_D", "Key_E", "Key_F", "Key_G", "Key_H", "Key_I", "Key_J", "Key_K", "Key_L", "Key_M", "Key_N", "Key_O", "Key_P", "Key_Q", "Key_R", "Key_S", "Key_T", "Key_U", "Key_V", "Key_W", "Key_X", "Key_Y", "Key_Z", "Key_F1", "Key_F2", "Key_F3", "Key_F4", "Key_F5", "Key_F6", "Key_F7", "Key_F8", "Key_F9", "Key_F10", "Key_F11", "Key_F12", "Key_NUM_LOCK", "Key_NUM_0", "Key_NUM_1", "Key_NUM_2", "Key_NUM_3", "Key_NUM_4", "Key_NUM_5", "Key_NUM_6", "Key_NUM_7", "Key_NUM_8", "Key_NUM_9", "Key_NUM_STAR", "Key_NUM_PLUS", "Key_NUM_MINUS", "Key_NUM_DOT", "Key_NUM_DIV", "KeyReleased_NOKEY", "KeyReleased_ANYKEY", "KeyReleased_BACKSPACE", "KeyReleased_TAB", "KeyReleased_ENTER", "KeyReleased_SHIFT", "KeyReleased_CTRL", "KeyReleased_ALT", "KeyReleased_PAUSE", "KeyReleased_ESCAPE", "KeyReleased_SPACE", "KeyReleased_PAGEUP", "KeyReleased_PAGEDOWN", "KeyReleased_END", "KeyReleased_HOME", "KeyReleased_LEFT", "KeyReleased_UP", "KeyReleased_RIGHT", "KeyReleased_DOWN", "KeyReleased_INSERT", "KeyReleased_DELETE", "KeyReleased_0", "KeyReleased_1", "KeyReleased_2", "KeyReleased_3", "KeyReleased_4", "KeyReleased_5", "KeyReleased_6", "KeyReleased_7", "KeyReleased_8", "KeyReleased_9", "KeyReleased_A", "KeyReleased_B", "KeyReleased_C", "KeyReleased_D", "KeyReleased_E", "KeyReleased_F", "KeyReleased_G", "KeyReleased_H", "KeyReleased_I", "KeyReleased_J", "KeyReleased_K", "KeyReleased_L", "KeyReleased_M", "KeyReleased_N", "KeyReleased_O", "KeyReleased_P", "KeyReleased_Q", "KeyReleased_R", "KeyReleased_S", "KeyReleased_T", "KeyReleased_U", "KeyReleased_V", "KeyReleased_W", "KeyReleased_X", "KeyReleased_Y", "KeyReleased_Z", "KeyReleased_F1", "KeyReleased_F2", "KeyReleased_F3", "KeyReleased_F4", "KeyReleased_F5", "KeyReleased_F6", "KeyReleased_F7", "KeyReleased_F8", "KeyReleased_F9", "KeyReleased_F10", "KeyReleased_F11", "KeyReleased_F12", "KeyReleased_NUM_LOCK", "KeyReleased_NUM_0", "KeyReleased_NUM_1", "KeyReleased_NUM_2", "KeyReleased_NUM_3", "KeyReleased_NUM_4", "KeyReleased_NUM_5", "KeyReleased_NUM_6", "KeyReleased_NUM_7", "KeyReleased_NUM_8", "KeyReleased_NUM_9", "KeyReleased_NUM_STAR", "KeyReleased_NUM_PLUS", "KeyReleased_NUM_MINUS", "KeyReleased_NUM_DOT", "KeyReleased_NUM_DIV", "GMRooms", "pCaption", "width", "height", "speed", "persistent", "colour", "showColour", "enableViews", "viewClearScreen", "pCode", "visible", "foreground", "index", "htiled", "vtiled", "hspeed", "vspeed", "stretch", "backgrounds", "views", "visible", "xview", "yview", "wview", "hview", "xport", "yport", "wport", "hport", "hborder", "vborder", "hspeed", "vspeed", "index", "pInstances", "id", "tiles", "xo", "yo", "depth", "RoomOrder", "TPageEntries", "XOffset", "YOffset", "CropWidth", "CropHeight", "ow", "oh", "tp", "fontname", "array_set_2D", "array_set_1D", "array_get_2D", "array_get_1D", "g_pBuiltIn", "GetWithArray", "yyInst", "Scripts", "WebGL", "CreateEventOrder" }; string[] array2 = array; foreach (string item in array2) { list.Add(item); } string outputfilename = Path.Combine(_outputDir, "gmRunner.js"); Out.WriteLine("Obfuscating..."); YYObfuscate yYObfuscate = new YYObfuscate(); yYObfuscate.Obfuscate = ObfuscateObfuscate; yYObfuscate.Verbose = Verbose; yYObfuscate.PrettyPrint = ObfuscatePrettyPrint; yYObfuscate.RemovedUnused = ObfuscateRemoveUnused; yYObfuscate.EncodeStrings = ObfuscateEncodeStrings; yYObfuscate.DoObfuscate(files, outputfilename, list); } [STAThread] private static int Main(string[] _args) { Trace.Write("------------ {1} {0} --------------", Assembly.GetExecutingAssembly().GetName().Version.ToString(), Assembly.GetExecutingAssembly().GetName().Name); /*if (!Debugger.IsAttached) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; }*/ //Unlike yoyogames. i see NO issue with running a debugger here :D Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); GMLCompile.Test(); GMLCompile.Code_Init(); HTMLRunner = "C:\\source\\GameMaker\\Runner\\HTML5\\scripts"; Verbose = false; CompileVerbose = false; Out = Console.Out; SplashOmit = true; TextureType = new eTexType[2]; SeparateOpaqueAndAlpha = false; DisplaySortedTextures = false; RemoveDND = true; CenterHTML5Game = false; NoCache = false; HTMLRunner = string.Empty; NoIndexHTML = false; TextureGroups = new Dictionary>(); DoObfuscate = false; ObfuscateObfuscate = true; ObfuscatePrettyPrint = false; ObfuscateRemoveUnused = true; ObfuscateEncodeStrings = true; LoadingBarName = null; CustomLoadingScreen = false; ExitCode = 0; InhibitErrorOutput = false; string PreObfuscateLib = string.Empty; TextureScale = 1; Studio = false; m_options = new OptionSet().Add("?|help", "display help usage", (Action)delegate { ShowHelp(); }).Add("m=|machine=", "set machine type (ios, psp, win, droid)", delegate(string m) { SetMachineType(m); }).Add("t=|tex=", "override opaque texture type (dxt,raw,pvr,png)", delegate(string s) { TextureType[0] = SetTextureType(s); }) .Add("at=|alphatex=", "override alpha texture type (dxt,raw,pvr,png)", delegate(string s) { TextureType[1] = SetTextureType(s); }) .Add("o=|outputDir=", "set output directory", delegate(string d) { OutputDir = d; }) .Add("w=|tpageWidth=", "set texture page width", delegate(int w) { TexturePageWidth = w; }) .Add("h=|tpageHeight=", "set texture page height", delegate(int h) { TexturePageHeight = h; }) .Add("wt|writeTextures", "optionally write textures generated to output directory", (Action)delegate { WriteTextures = true; }) .Add("ww|writeWaves", "optionally write audio waves generated to output directory", (Action)delegate { WriteTextures = true; }) .Add("so|splashOmit", "optionally disable writing of the Spash screen to output file", (Action)delegate { SplashOmit = true; }) .Add("dst|DisplaySortedTextures", "optionally display sorted texture information", (Action)delegate { DisplaySortedTextures = true; }) .Add("c|compile", "do not display gui compile only", (Action)delegate { CompileOnly = true; }) .Add("s|separate", "separate the alpha and opaque textures (false by default)", (Action)delegate { SeparateOpaqueAndAlpha = true; }) .Add("v|verbose", "output verbose debug info", (Action)delegate { Verbose = true; }) .Add("nohtml", "do not output index.html", (Action)delegate { NoIndexHTML = true; }) .Add("HTMLRunner=", "directory with HTML Runner (will be copied as scripts)", delegate(string d) { HTMLRunner = d; }) .Add("tg=|TextureGroup=", "Group resources onto texture pages comma param is a filename, file has format : , use # for comment (NOTE: entries MUST all be on the same line", delegate(string f) { string[] array4 = File.ReadAllLines(f); string[] array5 = array4; foreach (string text3 in array5) { string text4 = text3.Trim().Replace(" ", "").Replace("\t", ""); if (!string.IsNullOrEmpty(text4) && !text4.StartsWith("#")) { string[] array6 = text4.Split(':'); if (array6.Length == 2) { string[] collection2 = array6[1].Split(','); string key = array6[0]; List value = new List(collection2); TextureGroups.Add(key, value); } } } }) .Add("to=|TextureOption=", "Set an option for a set of textures via