/// <summary> /// 初始化启动器 /// </summary> /// <param name="javaPath"></param> /// <param name="javaXmx"></param> /// <param name="userName"></param> /// <param name="name"></param> /// <param name="info"></param> /// <param name="extarg"></param> /// <param name="li"></param> public Launcher(string javaPath, string javaXmx, string userName, string name, Gameinfo info, string extarg, LoginInfo li) { OnStateChangeEvent(LangManager.GetLangFromResource("LauncherCheckJava")); if (!File.Exists(javaPath)) { BMCLV4.Logger.Log("找不到java",BMCLV4.Logger.LogType.Error); throw new NoJavaException(); } OnStateChangeEvent(LangManager.GetLangFromResource("LauncherCheckMem")); _javaxmx = javaXmx; _username = userName; _version = info.id; this._name = name; _game.StartInfo.FileName = javaPath; if (BMCLV4.Logger.Debug) { _game.StartInfo.CreateNoWindow = true; _game.StartInfo.RedirectStandardOutput = true; _game.StartInfo.RedirectStandardError = true; } _info = info; this._li = li; this.Extarg = extarg; this._info = info; }
/// <summary> /// Get Game information (GameTitle and GameUID) from AGS EXE File /// </summary> /// <param name="filename">Game EXE File</param> public static Gameinfo GetGameInfo(string filename) { using (FileStream fs = new FileStream(filename, FileMode.Open)) { //The string we want to search in the AGS Game executable const string searchString = "Adventure Creator Game File v2"; // Gameinfo class to hold the information Gameinfo info = new Gameinfo(); const int blockSize = 1024; long fileSize = fs.Length; long position = 0; //Read AGS EXE and search for string, should actually never reach the end BinaryReader br = new BinaryReader(fs); while (position < fileSize) { byte[] data = br.ReadBytes(blockSize); string tempData = Encoding.Default.GetString(data); //If the search string is found get the game info if (tempData.Contains(searchString)) { int pos = tempData.IndexOf(searchString, 0); //Calculate and set the position to start reading pos = pos + 0x1E + (int)position; fs.Position = pos; //Dummy read 4 bytes br.ReadInt32(); int versionStringLength = br.ReadInt32(); //Get the AGS version the game was compiled with info.Version = new string(br.ReadChars(versionStringLength)); //Calculate and save GameUID position for later use long gameuidPos = fs.Position + 0x6f4; //Get the game title string gameTitle = new string(br.ReadChars(0x40)); info.GameTitle = gameTitle.Substring(0, gameTitle.IndexOf("\0")); //Read the GameUID fs.Position = gameuidPos; int GameUID = br.ReadInt32(); GameUID = SwapEndianness(GameUID); info.GameUID = GameUID.ToString("X"); //return the Game information return(info); } //Calculate new postiton position = position + blockSize; } } //if nothing found return just null return(null); }
void OnLoadGameData() { if (m_Info == null) { m_Info = new Gameinfo(); m_Info.m_DataProgress = new Dictionary <int, int> (); } else { m_Info.m_DataProgress.Clear(); } string path = Application.persistentDataPath + Constant.CONSTANT_NUMBER; if (File.Exists(path)) { FileStream f = File.Open(path, FileMode.Open); BinaryFormatter bif = new BinaryFormatter(); m_Info = (Gameinfo)bif.Deserialize(f); f.Close(); } }
/// <summary> /// Create a TRA File for AGS /// </summary> /// <param name="info">Game Information like Title,UID</param> /// <param name="filename">Output filename</param> /// <param name="entryList">List with Translation entries</param> public static void CreateTraFile(Gameinfo info, string filename, Dictionary <string, string> entryList) { Encoding encoding = Encoding.Default; //GetEncoding(1252); //Encoding.UTF8; bool encrypt = true; using (FileStream fs = new FileStream(filename, FileMode.Create)) { //Tail byte[] tail = { 0x01, 0x00, 0x00, 0x00, 0x41, 0x01, 0x00, 0x00, 0x00, 0x41, 0x03, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, }; //Write always header "AGSTranslation\0" byte[] agsHeader = { 0x41, 0x47, 0x53, 0x54, 0x72, 0x61, 0x6E, 0x73, 0x6C, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x00, }; fs.Write(agsHeader, 0, agsHeader.Length); //Padding not sure what exactly this is byte[] paddingBytes = { 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, }; fs.Write(paddingBytes, 0, paddingBytes.Length); //Write GameUID important or Translation does not load properly! string sGameUID = info.GameUID; int decAgain = int.Parse(sGameUID, System.Globalization.NumberStyles.HexNumber); byte[] bGameUID = BitConverter.GetBytes(SwapEndianness(decAgain)); fs.Write(bGameUID, 0, bGameUID.Length); //Encrypt and write the Title string GameTitle = info.GameTitle + "\0"; char[] cGameTitle = GameTitle.ToCharArray(); //Write GameTitle Length byte[] bGameTitleLength = BitConverter.GetBytes(GameTitle.Length); fs.Write(bGameTitleLength, 0, bGameTitleLength.Length); //Write the encrypted GameTitle byte[] bGameTitle = CharsToBytes(cGameTitle); if (encrypt) { EncryptBytes(bGameTitle); } fs.Write(bGameTitle, 0, bGameTitle.Length); //dummy write byte[] bDummy = { 0x01, 0x00, 0x00, 0x00, }; fs.Write(bDummy, 0, bDummy.Length); //Write Length translation long translationLengthPosition = fs.Position; //Dummy write for later fs.Write(bDummy, 0, bDummy.Length); long translationLength = 0; if (entryList.Count > 0) { foreach (KeyValuePair <string, string> pair in entryList) { if (!string.Equals(pair.Value, "")) { //Get original string string entry1 = pair.Key; entry1 = entry1 + "\0"; //Write original string length byte[] bEntry1Length = BitConverter.GetBytes(entry1.Length); fs.Write(bEntry1Length, 0, bEntry1Length.Length); //Write original string bytes char[] cEntry1 = entry1.ToCharArray(); byte[] bEntry1 = CharsToBytes(cEntry1); if (encrypt) { EncryptBytes(bEntry1); } fs.Write(bEntry1, 0, bEntry1.Length); //Get translation string string entry2 = pair.Value; entry2 = entry2 + "\0"; //Write translation string length byte[] bEntry2Length = BitConverter.GetBytes(entry2.Length); fs.Write(bEntry2Length, 0, bEntry2Length.Length); //Write translation string bytes char[] cEntry2 = entry2.ToCharArray(); byte[] bEntry2 = CharsToBytes(cEntry2); if (encrypt) { EncryptBytes(bEntry2); } fs.Write(bEntry2, 0, bEntry2.Length); long lengthTemp = BitConverter.ToInt32(bEntry1Length, 0) + 4 + BitConverter.ToInt32(bEntry2Length, 0) + 4; translationLength = translationLength + lengthTemp; } } //Write Tail fs.Write(tail, 0, tail.Length); //Write Translation length + 10 byte[] b = BitConverter.GetBytes((int)(translationLength + 10)); fs.Position = translationLengthPosition; fs.Write(b, 0, b.Length); fs.Close(); } } }
/// <summary> /// Create a TRA File for AGS /// </summary> /// <param name="info">Game Information like Title,UID</param> /// <param name="filename">Output filename</param> /// <param name="entryList">List with Translation entries</param> public static void CreateTRA_File(Gameinfo info, string filename, Dictionary<string,string> entryList) { using (FileStream fs = new FileStream(filename,FileMode.Create)) { //Tail byte[] tail = { 0x01, 0x00, 0x00, 0x00, 0x41, 0x01, 0x00, 0x00, 0x00, 0x41, 0x03, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, }; //Write always header "AGSTranslation\0 byte[] agsHeader = {0x41, 0x47, 0x53, 0x54, 0x72, 0x61, 0x6E, 0x73, 0x6C, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x00,}; fs.Write(agsHeader,0,agsHeader.Length); //Padding not sure what exactly this is byte[] paddingBytes = {0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00,}; fs.Write(paddingBytes,0,paddingBytes.Length); //Write GameUID important or Translation does not load properly! string sGameUID = info.GameUID; int decAgain = int.Parse(sGameUID, System.Globalization.NumberStyles.HexNumber); byte[] bGameUID = BitConverter.GetBytes(SwapEndianness(decAgain)); fs.Write(bGameUID,0,bGameUID.Length); //Encrypt and write the Title string GameTitle = info.GameTitle + "\0"; byte[] bGameTitle = Encoding.UTF8.GetBytes(GameTitle); char[] cGameTitle = new char[GameTitle.Length]; GameTitle.CopyTo(0, cGameTitle, 0, GameTitle.Length); encrypt_text(cGameTitle); //Write GameTitle Length byte[] bGameTitleLength = BitConverter.GetBytes(bGameTitle.Length); fs.Write(bGameTitleLength, 0, bGameTitleLength.Length); //Write the encrypted GameTitle ConvertCharToByte(cGameTitle, bGameTitle); fs.Write(bGameTitle, 0, bGameTitle.Length); //dummy write byte[] bDummy = {0x01, 0x00, 0x00, 0x00,}; fs.Write(bDummy, 0, bDummy.Length); //Write Length translation long translationLengthPosition = fs.Position; //Dummy write for later fs.Write(bDummy,0,bDummy.Length); long translationLength = 0; if (entryList.Count > 0) { foreach (KeyValuePair<string,string> pair in entryList) { if (!string.Equals(pair.Value, "")) { //encrypt string write length string entry1 = pair.Key; entry1 = entry1 + "\0"; byte[] bEntry1 = Encoding.UTF8.GetBytes(entry1); byte[] bEntry6 = Encoding.UTF7.GetBytes(entry1); byte[] bEntry5 = Encoding.ASCII.GetBytes(entry1); //Write string entry1 length byte[] bEntry1Length = BitConverter.GetBytes(bEntry1.Length); fs.Write(bEntry1Length, 0, bEntry1Length.Length); char[] cEntry1 = new char[bEntry1.Length]; Array.Copy(bEntry1, cEntry1, bEntry1.Length); encrypt_text(cEntry1); ConvertCharToByte(cEntry1,bEntry1); fs.Write(bEntry1, 0, bEntry1.Length); //Encrypt Entry2 and write length string entry2 = pair.Value; entry2 = entry2 + "\0"; byte[] bEntry2 = Encoding.UTF8.GetBytes(entry2); //Write string entry2 length byte[] bEntry2Length = BitConverter.GetBytes(bEntry2.Length); fs.Write(bEntry2Length, 0, bEntry2Length.Length); char[] cEntry2 = new char[bEntry2.Length]; Array.Copy(bEntry2, cEntry2, bEntry2.Length); encrypt_text(cEntry2); ConvertCharToByte(cEntry2,bEntry2); fs.Write(bEntry2, 0, bEntry2.Length); long lengthTemp = BitConverter.ToInt32(bEntry1Length, 0) + 4 + BitConverter.ToInt32(bEntry2Length, 0) + 4; translationLength = translationLength + lengthTemp; } } //Write Tail fs.Write(tail, 0, tail.Length); //Write Translation length + 10 byte[] b = BitConverter.GetBytes((int) (translationLength + 10)); fs.Position = translationLengthPosition; fs.Write(b, 0, b.Length); fs.Close(); } } }
/// <summary> /// Get Game information (GameTitle and GameUID) from AGS EXE File /// </summary> /// <param name="filename">Game EXE File</param> public static Gameinfo GetGameInfo(string filename) { using (FileStream fs = new FileStream(filename, FileMode.Open)) { //The string we want to search in the AGS Game executable const string searchString = "Adventure Creator Game File v2"; // Gameinfo class to hold the information Gameinfo info = new Gameinfo(); const int blockSize = 1024; long fileSize = fs.Length; long position = 0; //Read AGS EXE and search for string, should actually never reach the end BinaryReader br = new BinaryReader(fs); while (position < fileSize) { byte[] data = br.ReadBytes(blockSize); string tempData = Encoding.Default.GetString(data); //If the search string is found get the game info if (tempData.Contains(searchString)) { int pos = tempData.IndexOf(searchString, 0); //Calculate and set the position to start reading pos = pos + 0x1E + (int)position; fs.Position = pos; //Dummy read 4 bytes br.ReadInt32(); int versionStringLength = br.ReadInt32(); //Get the AGS version the game was compiled with info.Version = new string(br.ReadChars(versionStringLength)); //Calculate and save GameUID position for later use long gameuidPos = fs.Position + 0x6f4; //Get the game title string gameTitle = new string(br.ReadChars(0x40)); info.GameTitle = gameTitle.Substring(0, gameTitle.IndexOf("\0")); //Read the GameUID fs.Position = gameuidPos; int GameUID = br.ReadInt32(); GameUID = SwapEndianness(GameUID); info.GameUID = GameUID.ToString("X"); //return the Game information return info; } //Calculate new postiton position = position + blockSize; } } //if nothing found return just null return null; }