#pragma once #include #include #include #include #include #include "msclr/marshal.h" #include "msclr/marshal_cppstd.h" using namespace msclr::interop; #pragma comment(lib, "user32.lib") #define PROF 256 int cancel; namespace fa { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace std; /// /// Form1 の概要 /// public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: ここにコンストラクター コードを追加します // //設定用データFWConfig.iniが同一フォルダに存在したら読み込む ifstream Config; Config.open("FWConfig.ini"); if(Config){ string buf; getline(Config, buf); textBox1->Text = marshal_as(buf);//MUGENフォルダ getline(Config, buf); textBox2->Text = marshal_as(buf);//対戦キャラクターリスト getline(Config, buf); textBox3->Text = marshal_as(buf);//使用ステージ } } protected: /// /// 使用中のリソースをすべてクリーンアップします。 /// ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::TextBox^ textBox1; private: System::Windows::Forms::TextBox^ textBox2; private: System::Windows::Forms::Button^ button2; private: System::Windows::Forms::Button^ button3; private: System::Windows::Forms::FolderBrowserDialog^ folderBrowserDialog1; private: System::Windows::Forms::Label^ label2; private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::OpenFileDialog^ openFileDialog1; private: System::Windows::Forms::GroupBox^ groupBox1; private: System::Windows::Forms::RadioButton^ radioButton2; private: System::Windows::Forms::RadioButton^ radioButton1; private: System::Windows::Forms::GroupBox^ groupBox2; private: System::Windows::Forms::RadioButton^ radioButton4; private: System::Windows::Forms::RadioButton^ radioButton3; private: System::Windows::Forms::Label^ label4; private: System::Windows::Forms::TextBox^ textBox3; private: System::Windows::Forms::CheckBox^ checkBox1; private: System::Windows::Forms::CheckBox^ checkBox2; private: System::Windows::Forms::CheckBox^ checkBox3; private: System::Windows::Forms::NumericUpDown^ numericUpDown1; private: System::Windows::Forms::NumericUpDown^ numericUpDown2; private: System::Windows::Forms::Label^ label5; private: System::Windows::Forms::Label^ label6; private: System::Windows::Forms::Button^ button4; protected: private: /// /// 必要なデザイナー変数です。 /// System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// /// デザイナー サポートに必要なメソッドです。このメソッドの内容を /// コード エディターで変更しないでください。 /// void InitializeComponent(void) { this->button1 = (gcnew System::Windows::Forms::Button()); this->label1 = (gcnew System::Windows::Forms::Label()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->button2 = (gcnew System::Windows::Forms::Button()); this->button3 = (gcnew System::Windows::Forms::Button()); this->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog()); this->label2 = (gcnew System::Windows::Forms::Label()); this->label3 = (gcnew System::Windows::Forms::Label()); this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog()); this->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); this->radioButton2 = (gcnew System::Windows::Forms::RadioButton()); this->radioButton1 = (gcnew System::Windows::Forms::RadioButton()); this->groupBox2 = (gcnew System::Windows::Forms::GroupBox()); this->radioButton4 = (gcnew System::Windows::Forms::RadioButton()); this->radioButton3 = (gcnew System::Windows::Forms::RadioButton()); this->label4 = (gcnew System::Windows::Forms::Label()); this->textBox3 = (gcnew System::Windows::Forms::TextBox()); this->checkBox1 = (gcnew System::Windows::Forms::CheckBox()); this->checkBox2 = (gcnew System::Windows::Forms::CheckBox()); this->checkBox3 = (gcnew System::Windows::Forms::CheckBox()); this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown()); this->numericUpDown2 = (gcnew System::Windows::Forms::NumericUpDown()); this->label5 = (gcnew System::Windows::Forms::Label()); this->label6 = (gcnew System::Windows::Forms::Label()); this->button4 = (gcnew System::Windows::Forms::Button()); this->groupBox1->SuspendLayout(); this->groupBox2->SuspendLayout(); (cli::safe_cast(this->numericUpDown1))->BeginInit(); (cli::safe_cast(this->numericUpDown2))->BeginInit(); this->SuspendLayout(); // // button1 // this->button1->Font = (gcnew System::Drawing::Font(L"MS UI Gothic", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, static_cast(128))); this->button1->Location = System::Drawing::Point(222, 219); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(79, 47); this->button1->TabIndex = 0; this->button1->Text = L"実行"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(12, 244); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(103, 12); this->label1->TabIndex = 1; this->label1->Text = L"進捗っぽいの表示?"; // // textBox1 // this->textBox1->Location = System::Drawing::Point(14, 24); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(226, 19); this->textBox1->TabIndex = 2; // // textBox2 // this->textBox2->Location = System::Drawing::Point(14, 61); this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(226, 19); this->textBox2->TabIndex = 3; // // button2 // this->button2->Location = System::Drawing::Point(248, 22); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(53, 23); this->button2->TabIndex = 4; this->button2->Text = L"選択"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // button3 // this->button3->Location = System::Drawing::Point(248, 59); this->button3->Name = L"button3"; this->button3->Size = System::Drawing::Size(53, 23); this->button3->TabIndex = 5; this->button3->Text = L"選択"; this->button3->UseVisualStyleBackColor = true; this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click); // // label2 // this->label2->AutoSize = true; this->label2->Location = System::Drawing::Point(12, 9); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(80, 12); this->label2->TabIndex = 6; this->label2->Text = L"MUGENフォルダ"; // // label3 // this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(12, 46); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(105, 12); this->label3->TabIndex = 7; this->label3->Text = L"対戦キャラクターリスト"; // // openFileDialog1 // this->openFileDialog1->FileName = L"openFileDialog1"; // // groupBox1 // this->groupBox1->Controls->Add(this->radioButton2); this->groupBox1->Controls->Add(this->radioButton1); this->groupBox1->Location = System::Drawing::Point(16, 128); this->groupBox1->Name = L"groupBox1"; this->groupBox1->Size = System::Drawing::Size(109, 85); this->groupBox1->TabIndex = 8; this->groupBox1->TabStop = false; this->groupBox1->Text = L"繰り返し方式1"; // // radioButton2 // this->radioButton2->AutoSize = true; this->radioButton2->Location = System::Drawing::Point(6, 56); this->radioButton2->Name = L"radioButton2"; this->radioButton2->Size = System::Drawing::Size(91, 16); this->radioButton2->TabIndex = 1; this->radioButton2->Text = L"先頭キャラ-他"; this->radioButton2->UseVisualStyleBackColor = true; // // radioButton1 // this->radioButton1->AutoSize = true; this->radioButton1->Checked = true; this->radioButton1->Location = System::Drawing::Point(6, 22); this->radioButton1->Name = L"radioButton1"; this->radioButton1->Size = System::Drawing::Size(67, 16); this->radioButton1->TabIndex = 0; this->radioButton1->TabStop = true; this->radioButton1->Text = L"総当り式"; this->radioButton1->UseVisualStyleBackColor = true; // // groupBox2 // this->groupBox2->Controls->Add(this->radioButton4); this->groupBox2->Controls->Add(this->radioButton3); this->groupBox2->Location = System::Drawing::Point(131, 128); this->groupBox2->Name = L"groupBox2"; this->groupBox2->Size = System::Drawing::Size(109, 85); this->groupBox2->TabIndex = 9; this->groupBox2->TabStop = false; this->groupBox2->Text = L"繰り返し方式2"; // // radioButton4 // this->radioButton4->AutoSize = true; this->radioButton4->Location = System::Drawing::Point(6, 56); this->radioButton4->Name = L"radioButton4"; this->radioButton4->Size = System::Drawing::Size(87, 16); this->radioButton4->TabIndex = 1; this->radioButton4->Text = L"表裏(2P-1P)"; this->radioButton4->UseVisualStyleBackColor = true; // // radioButton3 // this->radioButton3->AutoSize = true; this->radioButton3->Checked = true; this->radioButton3->Location = System::Drawing::Point(6, 22); this->radioButton3->Name = L"radioButton3"; this->radioButton3->Size = System::Drawing::Size(96, 16); this->radioButton3->TabIndex = 0; this->radioButton3->TabStop = true; this->radioButton3->Text = L"表のみ(1P-2P)"; this->radioButton3->UseVisualStyleBackColor = true; // // label4 // this->label4->AutoSize = true; this->label4->Location = System::Drawing::Point(12, 83); this->label4->Name = L"label4"; this->label4->Size = System::Drawing::Size(67, 12); this->label4->TabIndex = 11; this->label4->Text = L"使用ステージ"; // // textBox3 // this->textBox3->Location = System::Drawing::Point(14, 98); this->textBox3->Name = L"textBox3"; this->textBox3->Size = System::Drawing::Size(226, 19); this->textBox3->TabIndex = 12; // // checkBox1 // this->checkBox1->AutoSize = true; this->checkBox1->Location = System::Drawing::Point(16, 219); this->checkBox1->Name = L"checkBox1"; this->checkBox1->Size = System::Drawing::Size(66, 16); this->checkBox1->TabIndex = 13; this->checkBox1->Text = L"nomusic"; this->checkBox1->UseVisualStyleBackColor = true; // // checkBox2 // this->checkBox2->AutoSize = true; this->checkBox2->Location = System::Drawing::Point(88, 219); this->checkBox2->Name = L"checkBox2"; this->checkBox2->Size = System::Drawing::Size(66, 16); this->checkBox2->TabIndex = 14; this->checkBox2->Text = L"nosound"; this->checkBox2->UseVisualStyleBackColor = true; // // checkBox3 // this->checkBox3->AutoSize = true; this->checkBox3->Location = System::Drawing::Point(160, 219); this->checkBox3->Name = L"checkBox3"; this->checkBox3->Size = System::Drawing::Size(56, 16); this->checkBox3->TabIndex = 15; this->checkBox3->Text = L"Ctrl+S"; this->checkBox3->UseVisualStyleBackColor = true; // // numericUpDown1 // this->numericUpDown1->Location = System::Drawing::Point(248, 147); this->numericUpDown1->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {10, 0, 0, 0}); this->numericUpDown1->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0}); this->numericUpDown1->Name = L"numericUpDown1"; this->numericUpDown1->Size = System::Drawing::Size(53, 19); this->numericUpDown1->TabIndex = 16; this->numericUpDown1->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {2, 0, 0, 0}); // // numericUpDown2 // this->numericUpDown2->Location = System::Drawing::Point(248, 184); this->numericUpDown2->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0}); this->numericUpDown2->Name = L"numericUpDown2"; this->numericUpDown2->Size = System::Drawing::Size(53, 19); this->numericUpDown2->TabIndex = 17; this->numericUpDown2->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0}); // // label5 // this->label5->AutoSize = true; this->label5->Location = System::Drawing::Point(246, 132); this->label5->Name = L"label5"; this->label5->Size = System::Drawing::Size(52, 12); this->label5->TabIndex = 18; this->label5->Text = L"ラウンド数"; // // label6 // this->label6->AutoSize = true; this->label6->Location = System::Drawing::Point(246, 169); this->label6->Name = L"label6"; this->label6->Size = System::Drawing::Size(42, 12); this->label6->TabIndex = 19; this->label6->Text = L"セット数"; // // button4 // this->button4->BackColor = System::Drawing::Color::Khaki; this->button4->Enabled = false; this->button4->Font = (gcnew System::Drawing::Font(L"MS UI Gothic", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, static_cast(128))); this->button4->ForeColor = System::Drawing::Color::DarkOliveGreen; this->button4->Location = System::Drawing::Point(222, 219); this->button4->Name = L"button4"; this->button4->Size = System::Drawing::Size(79, 47); this->button4->TabIndex = 20; this->button4->Text = L"中止"; this->button4->UseVisualStyleBackColor = false; this->button4->Visible = false; this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 12); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(310, 306); this->Controls->Add(this->button4); this->Controls->Add(this->label6); this->Controls->Add(this->label5); this->Controls->Add(this->numericUpDown2); this->Controls->Add(this->numericUpDown1); this->Controls->Add(this->checkBox3); this->Controls->Add(this->checkBox2); this->Controls->Add(this->checkBox1); this->Controls->Add(this->textBox3); this->Controls->Add(this->label4); this->Controls->Add(this->groupBox2); this->Controls->Add(this->groupBox1); this->Controls->Add(this->label3); this->Controls->Add(this->label2); this->Controls->Add(this->button3); this->Controls->Add(this->button2); this->Controls->Add(this->textBox2); this->Controls->Add(this->textBox1); this->Controls->Add(this->label1); this->Controls->Add(this->button1); this->Name = L"Form1"; this->Text = L"Form1"; this->groupBox1->ResumeLayout(false); this->groupBox1->PerformLayout(); this->groupBox2->ResumeLayout(false); this->groupBox2->PerformLayout(); (cli::safe_cast(this->numericUpDown1))->EndInit(); (cli::safe_cast(this->numericUpDown2))->EndInit(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { //次回起動用に設定情報の書き出し(FWConfig.ini) OutConfig(); //GOTO 設定ファイル書出関数 //ボタン等のコントロールをOFFに textBox1->Enabled = false; textBox2->Enabled = false; textBox3->Enabled = false; button1->Enabled = false; button2->Enabled = false; button3->Enabled = false; button4->Enabled = true; radioButton1->Enabled = false; radioButton2->Enabled = false; radioButton3->Enabled = false; radioButton4->Enabled = false; numericUpDown1->Enabled = false; numericUpDown2->Enabled = false; checkBox1->Enabled = false; checkBox2->Enabled = false; checkBox3->Enabled = false; button1->Visible = false; button4->Visible = true; button1->Update(); button4->Update(); cancel = 0; //入力情報を取得 //MUGENフォルダ String^ MUGENfolder = gcnew String(textBox1->Text); marshal_context^ context = gcnew marshal_context; LPCTSTR MUGENfolderP = context->marshal_as(MUGENfolder); // 使わなくなったところで必要らしい。 // delete context; //キャラクターリスト String^ InputcharsTxT = textBox2->Text; std::string Inputchars = marshal_as(InputcharsTxT); //ステージ String^ Inputstagename = textBox3->Text; std::string Inputstage = marshal_as(Inputstagename); //ラウンド数 int numrounds = (int)numericUpDown1->Value; char t_char[3]; sprintf_s(t_char, "%d", numrounds); string numR; numR = t_char; //セット数 int numsets = (int)numericUpDown2->Value; //コマンドラインのデフォルト部分 DefC を作成 string DefC = ("Winmugen -p1.ai 1 -p2.ai 1 -p2.color 1 ");//1P2PのAI起動と、1Pカラーを2Pにデフォルトでセット string stageC = (" -s "); string roundsC = (" -rounds "); string nomusicC = (" -nomusic "); string nosoundC = (" -nosound "); string p1C = (" -p1 "); string p2C = (" -p2 "); DefC = DefC + stageC + Inputstage + roundsC + numR; if(checkBox1->Checked){ DefC += nomusicC; } if(checkBox2->Checked){ DefC += nosoundC; } std::ifstream ifs; ifs.open(Inputchars.c_str(), ios::in); if(ifs.fail()){ std::cerr << "キャラクターリスト読み込みに失敗\n"; exit(1); } string buf; string chars[2]; int linenum =0; int lineMAX =0; int line1P =3; int line2P =1; while(ifs && getline(ifs, buf)) { linenum++; if(linenum==line1P){ std::string::size_type pos = 0; while(pos = buf.find("-pn.color", pos), pos != std::string::npos) { buf.replace(pos, 9, "-p1.color"); pos += 9; } chars[0]=buf; } if(linenum==line2P){ std::string::size_type pos = 0; while(pos = buf.find("-pn.color", pos), pos != std::string::npos) { buf.replace(pos, 9, "-p2.color"); pos += 9; } chars[1]=buf; } } string MUGENCommand; MUGENCommand = DefC + p1C + chars[0] + p2C + chars[1]; size_t origsize = strlen(MUGENCommand.c_str()) + 1; size_t convertedChars = 0; wchar_t wcstring[1000]; mbstowcs_s(&convertedChars, wcstring, origsize, MUGENCommand.c_str(), _TRUNCATE); STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); ZeroMemory(&pi, sizeof(pi)); si.cb = sizeof(si); //カレントディレクトリをMUGENフォルダに SetCurrentDirectory(MUGENfolderP); CreateProcess( NULL, //szCmd, wcstring, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi); // MUGENのハンドルを取得する処理 // HWND hWnd; // DWORD dwPID; // HANDLE ph; // hWnd = FindWindow(NULL, L"M.U.G.E.N"); //ウィンドウハンドルを名称より取得、多重起動は放置。 // GetWindowThreadProcessId(hWnd,&dwPID); //プロセスID取得 // ph = OpenProcess(PROCESS_ALL_ACCESS,TRUE,dwPID); //プロセスハンドル取得、及び権限取得? HANDLE ph = pi.hProcess; char *lpData0; char *lpDataPP; char *lpDataRoS; char *lpDataP1life; char *lpDataP2life; char *lpDataCtrlS; LPVOID EAX[1]; LPVOID EBX[2]; LPVOID RoundState[1]; LPVOID P1Life[2]; LPVOID P2Life[2]; LPVOID FlagON[1]; DWORD dwAccessByte; Sleep(1000);//少し待たないとメモリ情報が取得できなくなる。判定方法不明 // 基本のアドレス EAX取得 // 004B5B4C:ポインタ → EAX[0] lpData0=(char *)0x004B5B4C; ReadProcessMemory(ph,lpData0,EAX,4,&dwAccessByte); // プレイヤー情報ポインタ取得 // EAX+B754h:1Pのポインタ → EBX[0] // EAX+B758h:2Pのポインタ → EBX[1] lpDataPP=(char *)EAX[0]; lpDataPP+=0xB754; ReadProcessMemory(ph,lpDataPP,EBX,8,&dwAccessByte); // ゲーム高速化ON // EAX+C934h:ゲームスピード高速化(Ctrl+S)フラグ if(checkBox3->Checked){ FlagON[0] = (char *)0x01; //書き込み用データ フラグON用 lpDataCtrlS=(char *)EAX[0]; lpDataCtrlS+=0xC934; WriteProcessMemory(ph,lpDataCtrlS,FlagON,1,&dwAccessByte); } // ラウンドステート取得 // EAX+BC30h:ラウンドステート → RoundState[0] // ※常時監視 // 勝利モーションに以降したらHPを確認 lpDataRoS=(char *)EAX[0]; lpDataRoS+=0xBC30; int RoundEnd; //試合終了フラグ RoundEnd = 0; do{ ReadProcessMemory(ph,lpDataRoS,RoundState,4,&dwAccessByte); if((int)RoundState[0] == 4){ lpDataP1life=(char *)EBX[0]; lpDataP1life+=0x0160; ReadProcessMemory(ph,lpDataP1life,P1Life,8,&dwAccessByte); lpDataP2life=(char *)EBX[1]; lpDataP2life+=0x0160; ReadProcessMemory(ph,lpDataP2life,P2Life,8,&dwAccessByte); RoundEnd = 1; } }while(RoundEnd==0 || cancel==0); //試合終了したらループを抜ける String^ a=L""; int P1L = (int)P1Life[0]; int P1LM = (int)P1Life[1]; int P2L = (int)P2Life[0]; int P2LM = (int)P2Life[1]; a = P1L.ToString() + L"/" + P1LM.ToString() + L":" + P2L.ToString() + L"/" + P2LM.ToString(); label1->Text=a; } //メインの終わり めもめも private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { // フォルダ選択ダイアログの表示 FolderBrowserDialog ^dlg=gcnew FolderBrowserDialog(); if(dlg->ShowDialog() == System::Windows::Forms::DialogResult::OK) { String ^folderName=dlg->SelectedPath; textBox1->Text = folderName; } } private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { //ファイルを開くダイアログの作成 OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog; //ダイアログの表示 (Cancelボタンがクリックされた場合は何もしない) if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::Cancel) return; //取得したファイル名 String^ FileName = openFileDialog1->FileName; textBox2->AppendText(FileName); } void OutConfig(){ std::ofstream Config("FWConfig.ini"); if(Config){ Config << marshal_as(textBox1->Text) << endl;//MUGENフォルダ Config << marshal_as(textBox2->Text) << endl;//対戦キャラクターリスト Config << marshal_as(textBox3->Text);//使用ステージ } } private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) { cancel = 1; //むりだった。 } }; }