Hiển thị kết quả từ 1 đến 7 / 7
  1. #1
    Tham gia
    24-01-2008
    Bài viết
    87
    Like
    1
    Thanked 1 Time in 1 Post

    Code không run được ai giúp với

    như tiêu đề các bạn biết thì sữa giúp mình
    Code:
    //SimpleWc3Hack for Warcraft 3 Patch 1.22...
    #include <windows.h>
    #include <Tlhelp32.h>
    #include <iostream>
    using namespace std;
    
    DWORD GetPIDForProcess (char* process);
    void EnableDebugPriv();
    DWORD GetDLLBase(char* DllName, DWORD tPid);
    
    #define PATCH(i,w,l) WriteProcessMemory(hProc,reinterpret_cast<LPVOID>(gameBase+i),w,l,&dSize)
    #define NPATCH(i,w,l) WriteProcessMemory(hProc,reinterpret_cast<LPVOID>(i),w,l,&dSize)
    
    void main()
    {
    	cout << "SimpleWc3Hack v1.3 by sd333221 loaded!" << endl << endl;
    
    	cout << "Searching Wc3..." << endl;
    	if(GetPIDForProcess("WAR3.EXE") == 0)
    	{
    		cout << "Warcraft 3 was not found..." << endl;
    		system("Pause");
    		exit(0);
    	}
    	else
    	{
    		cout << "Getting debug privileges..." << endl;
    		EnableDebugPriv();
    		cout << "Opening Warcraft 3 Process..." << endl;
    		HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, GetPIDForProcess("WAR3.EXE"));
    		if(hProc)
    		{
    			cout << "Process opened... Patching" << endl;
    			DWORD gameBase = GetDLLBase("Game.dll",GetPIDForProcess("WAR3.EXE"));
    			DWORD dSize = 0;
    
    			PATCH(0x3A04AB,"\x90\x90",2); //Patch 6F3A04AB to nop nop :-)
    			if(dSize == 0)
    			{
    				cout << "Failed to patch showunitsingame" << endl;
    			}
    
    			PATCH(0x36087c,"\x00",1);
    			if(dSize == 0)
    			{
    				cout << "Failed to patch showunitsmap" << endl;
    			}
    
    			PATCH(0x28464C,"\x90\x90",2);  
    			if(dSize == 0)
    			{
    				cout << "Failed to patch clickableunits" << endl;
    			}
    
    			PATCH(0x284662,"\xEB\x29",2);  
    			if(dSize == 0)
    			{
    				cout << "Failed to patch clickableunits (2nd patch)" << endl;
    			}
    
    			PATCH(0x281F1C,"\x40\xc3",2);
    			if(dSize == 0)
    			{
    				cout << "Failed to patch revealillu" << endl;
    			}
    
    			PATCH(0x73B949,"\xB2\x00\x90\x90\x90\x90",6);
    			if(dSize == 0)
    			{
    				cout << "Failed to patch removefogingame" << endl;
    			}
    
    			PATCH(0x42F836,"\x3B\xC0\x0F\x85\xC0\x00\x00\x00\x8D\x8B\xF0\x00\x00\x00\xE8\x97\x3C\x03\x00\x3B\xC0\x0F\x85\xAD\x00\x00\x00",27);
    			if(dSize == 0)
    			{
    				cout << "Failed to patch pingsignal" << endl;
    			}
    
    			PATCH(0x360C91,"\x3B\xC0\x0F\x85\x30\x04\x00\x00",8);
    			if(dSize == 0)
    			{
    				cout << "Failed to patch showinvisiblemap" << endl;
    			}
    
    			PATCH(0x3558FE,"\x90\x90\x90",3);
    			if(dSize == 0)
    			{
    				cout << "Failed to patch showinvisiblemap" << endl;
    			}
    
    			PATCH(0x3C3F02,"\xEB",1);
    			PATCH(0x3BF63C,"\xB8\xFF\x00\x00\x00\xEB",6);
    			if(dSize == 0)
    			{
    				cout << "Failed to bypass DotA -ah command" << endl;
    			}
    
    			PATCH(0x3F75AA,"\x90\x90",2);
    			PATCH(0x3A03EB,"\xEB",1);
    			if(dSize == 0)
    			{
    				cout << "Failed to enable viewable items" << endl;
    			}
    
    			NPATCH(0x4559EC,"\x60\x0B\xC0\x75\x2F\x8A\x8E\xD0\x02\x00\x00\x80\xF9\x01\x74\x51\xC6\x86\xD0\x02\x00\x00\x01\xC6\x86\xD1\x02\x00\x00\x01\xC6\x86\xD2\x02\x00\x00\xFF\x8B\xCE\xB8\xFF\x01\x01\xFF\xFF\x15\x60\x5A\x45\x00\xEB\x2D\x8A\x8E\xD0\x02\x00\x00\x80\xF9\xFF\x74\x22\xC6\x86\xD0\x02\x00\x00\xFF\xC6\x86\xD1\x02\x00\x00\xFF\xC6\x86\xD2\x02\x00\x00\xFF\x8B\xCE\xB8\xFF\xFF\xFF\xFF\xFF\x15\x60\x5A\x45\x00\x61\xB8\x01\x00\x00\x00\x23\xD8\x89\x44\x24\xE4\xFF\x35\x65\x5A\x45\x00\xC3",116);
    			DWORD addr[3];
    			addr[0] = gameBase + 0x29CD30; //References to the Game.dll
    			addr[1] = gameBase + 0x398E0F; //
    			addr[2] = 0x4559EC;            //Detour
    			NPATCH(0x455A60,&addr[0],sizeof(DWORD));
    			NPATCH(0x455A65,&addr[1],sizeof(DWORD));
    			NPATCH(0x455A6A,&addr[2],sizeof(DWORD));
    			PATCH(0x398E09,"\xFF\x25\x6A\x5A\x45\x00",6); //Plant detour
    			if(dSize == 0)
    			{
    				cout << "Failed to enable colored invisibles" << endl;
    			}
    
    
    			PATCH(0x201B9C,"\x90\x90\x90\x90\x90\x90",6);
    			PATCH(0x34E6E8,"\x90\x90",2);
    			if(dSize == 0)
    			{
    				cout << "Failed to enable view skills" << endl;
    			}
    
    			PATCH(0x28d68e,"\xEB",1);
    			PATCH(0x34E726,"\x90\x90\x90\x90",4);
    			if(dSize == 0)
    			{
    				cout << "Failed to enable view cooldowns" << endl;
    			}
    
    			PATCH(0x284662,"\xEB",1);
    			if(dSize == 0)
    			{
    				cout << "Failed to enable click invisible units" << endl;
    			}
    
    			PATCH(0x34D1E2,"\xB8\x00\x00\x00\x00\x90",6);
    			DWORD highTradeAmount = 200;
    			PATCH(0x34D1E3,&highTradeAmount,sizeof(DWORD));
    			PATCH(0x34D1EA,"\xB8\x00\x00\x00\x00\x90",6);
    			DWORD lowTradeAmount = 100;
    			PATCH(0x34D1EB,&lowTradeAmount,sizeof(DWORD));
    			if(dSize == 0)
    			{
    				cout << "Failed to patch tradeamount" << endl;
    			}
    
    			cout << "Show hero icons: " << endl;
    			cout << "Press F1 to view all hero icons, F2 for enemy icons, F3 for ally icons, any key for nothing!" << endl;
    			system("Pause");
    			if(GetAsyncKeyState(VK_F1))
    			{
    				PATCH(0x36FFD1, "\x1B\x22",2);
    				PATCH(0x36FFD7, "\x90\x90\x90\x90\x90\x90",6);
    
    				if(dSize == 0)
    				{
    					cout << "Failed to patch view all icons" << endl;
    				}
    			}
    			else if(GetAsyncKeyState(VK_F2))
    			{
    				PATCH(0x36FFD1, "\x1B\x22",2);
    				PATCH(0x36FFD7, "´\x0F\x85\x8F\x02\x00\x00",6);
    
    				if(dSize == 0)
    				{
    					cout << "Failed to patch view enemy icons" << endl;
    				}
    
    			}
    			else if(GetAsyncKeyState(VK_F3))
    			{
    				PATCH(0x36FFD1, "\x1B\x22",2);
    				PATCH(0x36FFD7, "´\x0F\x84\x8F\x02\x00\x00",6);
    
    				if(dSize == 0)
    				{
    					cout << "Failed to patch view enemy icons" << endl;
    				}
    			}
    			else
    			{
    				cout << "View hero icons not enabled!" << endl;
    			}
    
    
    
    
    
    			cout << "Done, goodbye!" << endl;
    			system("Pause");
    			exit(1);
    
    
    		}
    		else
    		{
    			cout << "Warcraft 3 could not be opened..." << endl;
    			system("Pause");
    			exit(0);
    		}
    	}
    }
    
    //Queries the ProcessId of a certain process
    DWORD GetPIDForProcess (char* process)
    {
    	BOOL			working=0;
    	PROCESSENTRY32 lppe= {0};
    	DWORD			targetPid=0;
    
    	HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS ,0);
    	if (hSnapshot) 
    	{
    		lppe.dwSize=sizeof(lppe);
    		working=Process32First(hSnapshot,&lppe);
    		while (working)
    		{
    			if(_stricmp(lppe.szExeFile,process)==0)
    			{
    				targetPid=lppe.th32ProcessID;
    				break;
    			}
    			working=Process32Next(hSnapshot,&lppe);
    		}
    	}
    
    	CloseHandle( hSnapshot );
    	return targetPid;
    }
    
    //Enables to open other processes
    void EnableDebugPriv()
    {
    	HANDLE hToken;
    	LUID sedebugnameValue;
    	TOKEN_PRIVILEGES tkp;
    
    	if ( ! OpenProcessToken( GetCurrentProcess(),
    		TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
    		return;
    	if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) ){
    		CloseHandle( hToken );
    		return;
    	}
    	tkp.PrivilegeCount = 1;
    	tkp.Privileges[0].Luid = sedebugnameValue;
    	tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    	if ( ! AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) )
    		CloseHandle( hToken );
    } 
    
    //Gets the base of our dll
    DWORD GetDLLBase(char* DllName, DWORD tPid)
    {
    	HANDLE snapMod;  
    	MODULEENTRY32 me32;
    
    	if (tPid == 0) return 0;
    	snapMod = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, tPid);  
    	me32.dwSize = sizeof(MODULEENTRY32);  
    	if (Module32First(snapMod, &me32)){ 
    		do{
    			if (strcmp(DllName,me32.szModule) == 0){ 
    				CloseHandle(snapMod); 
    				return (DWORD) me32.modBaseAddr; 
    			}
    		}while(Module32Next(snapMod,&me32));
    	}
    
    	CloseHandle(snapMod); 
    	return 0;  
    
    }
    Quote Quote

  2. #2
    Tham gia
    01-05-2008
    Bài viết
    13
    Like
    0
    Thanked 0 Times in 0 Posts
    Compile, link okie
    Chương trình tạo ra vẫn chạy được
    Bạn nói lỗi cụ thể hơn đi

  3. #3
    Tham gia
    24-01-2008
    Bài viết
    87
    Like
    1
    Thanked 1 Time in 1 Post
    bạn compile = chương trình gì vậy ? Khi mình compile = dev c++ thì nó nói Code not compile !

  4. #4
    Tham gia
    03-09-2008
    Bài viết
    14
    Like
    0
    Thanked 0 Times in 0 Posts

    Ngạc nhiên Khẩn cấp..

    Có ai chi giup minh voi. Minh viet doan do hoa rieng thi chay rat binh thuong, khi ghep vao trong 1 bai hoan chinh thi no lai ko load duoc phan đồ họa. Chang hiu lam sao nua. Bạn nao bit chi giup minh voi nhe'.

    #include <stdio.h>
    #include <graphics.h>
    #include <conio.h>
    #include <string.h>
    #include <stdlib.h>

    struct process{
    char ten[12];
    int tvao;
    int txly;
    int tcho;
    int tluu;
    int stt;
    int dut;
    } P[20];
    int n, j, ok[20];

    int khoitaomenu();
    void nhapDL(process P[20]);
    void FIFO(void);
    void DUT(void);
    void SJF(void);
    void create_graph(process P[20]);


    void main(){
    clrscr();
    int choice;
    printf("\n Nhap so tien trinh yeu cau CPU: n = "); scanf("%d",&n);
    nhapDL(P);
    int mh=0, mode=0;
    initgraph(&mh, &mode, "c:\\Tc\\BGI");
    create_graph(P);
    getch();

    do{
    choice=khoitaomenu();
    switch(choice) {
    case 1:{
    FIFO();
    break;
    };
    case 2:{
    SJF();
    break;
    }
    /* case 3:{
    RR();
    break;
    }*/
    case 4:{
    DUT();
    break;
    }

    case 0:{
    break;
    }
    default:{
    gotoxy(18,20);
    printf("\n\t\tLoi! Hay nhap so [0-4] ");
    getch();
    break;
    }
    }
    }while(choice != 0);
    }

    int khoitaomenu(){
    int choice = -1;
    clrscr();
    gotoxy(22, 8);
    printf("***** Menu *****");
    gotoxy(18, 10);
    printf("1. Chiem luoc FIFO");
    gotoxy(18, 12);
    printf("2. Chien luoc SJF (do quyen)");
    gotoxy(18, 14);
    printf("3. Chien luoc Round Robin");
    gotoxy(18, 16);
    printf("4. Chien luoc Do uu tien");
    gotoxy(18, 18);
    printf("0. Thoat chuong trinh");
    gotoxy(18, 20);
    printf("Nhap vao lua chon cua ban:");
    scanf("%d", &choice);
    return choice;
    }
    void create_graph(process P[20])
    {
    int mh=0, mode=0;
    initgraph(&mh, &mode, "c:\\Tc\\BGI");
    if (graphresult() != grOk)
    {printf("\nLoi do hoa!");
    getch();
    exit(1);}
    setcolor(RED);
    moveto(50,30);
    outtext("******************* MO TA DO HOA *******************");
    moveto(70,60);
    outtext("******* Thuat toan dieu phoi tien trinh *******");
    moveto(20,100);
    outtext("Day cac tien trinh di vao theo thu tu da nhap:");
    setcolor(1);
    int y1=150, y2=y1+30, x1=100, x2=x1+15*P[1].txly;
    rectangle(x1,y1,x2,y2);
    outtextxy((x2+x1)/2, (y1+y2)/2, P[1].ten);
    for (int i=2; i<=n; i++)
    {
    x1=100+15*P[i].tvao; x2=x1+10*P[i].txly;
    y1=y2+8; y2=y1+30;
    setcolor(i+1);
    rectangle(x1,y1,x2,y2);
    moveto((x1+x2)/2, (y1+y2)/2);
    outtext(P[i].ten);
    }
    closegraph();
    }

    void nhapDL(process P[20]){
    int i=1;
    while (i<=n){
    //clrscr();
    fflush(stdin);
    printf("\n\tTen tien trinh : "); gets(P[i].ten);
    printf("\tThoi diem vao : "); scanf("%d",&P[i].tvao);
    printf("\tThoi gian xu ly: "); scanf("%d",&P[i].txly);
    printf("\tDo uu tien: "); scanf("%d",&P[i].dut);
    i++;
    // create_graph(P);
    }
    }

    void FIFO(){
    int i, t=0, s1=0, s2=0;
    process *Q=P;
    //sap xep theo thoi gian vao tang dan
    for(i=1; i<n;i++) for(j=i+1;j<=n;j++)
    if (Q[i].tvao>Q[j].tvao){
    process tg =Q[i];
    Q[i]=Q[j];
    Q[j]=tg;
    }
    Q[1].stt=1; // tien trinh dau tien duoc xu ly
    Q[1].tcho=0;
    t=Q[1].tvao + Q[1].txly;
    Q[1].tluu=Q[1].txly;
    j=1;
    for (i=2; i<=n; i++)
    if (Q[i].tvao<=t){
    j++;
    Q[i].stt=j;
    Q[i].tcho=t-Q[i].tvao;
    t=t+Q[i].txly;
    Q[i].tluu=t-Q[i].tvao;
    }
    else{ // neu chua co tien trinh nao cho xu ly
    j++;
    Q[i].stt=j;
    t=Q[i].tvao;
    Q[i].tcho=0;
    t=t+Q[i].txly;
    Q[i].tluu=Q[i].tcho+Q[i].txly;
    }
    // sap xep theo thu tu cap phat
    for(i=1; i<n;i++) for(j=i+1;j<=n;j++)
    if (Q[i].stt>Q[j].stt){
    process tg =Q[i];
    Q[i]=Q[j];
    Q[j]=tg;
    }
    //out ra danh sach
    clrscr();
    printf("\n\t__________ Ket qua dieu phoi theo FIFO__________\n");
    printf("\n\t|TTCP| Ten TT | Tvao | SD CPU | TLuu | TCho |\n");
    printf("\t======================================== =====");
    for (i=1; i<=n; i++){
    s1=s1+Q[i].tcho;
    s2=s2+Q[i].tluu;
    printf("\n\t| %2d | %6s | %4d | %6d | %4d | %4d |",
    i,Q[i].ten,Q[i].tvao,Q[i].txly,Q[i].tluu,Q[i].tcho);
    }
    printf("\n\t====================================== =======");
    printf("\n\t\t\t\t\t%4d%8d",s2,s1);
    printf("\n\n\tThoi gian cho TB %10.3f",(float)s1/n);
    printf("\n\tThoi gian luu TB %10.3f",(float)s2/n);
    printf("\n An bat ki Qhim nao de quay lai menu.");
    getch();
    }
    void SJF(void){
    int i,t,d,id,s1=0,s2=0;
    process *R=P;
    for (i=0; i<=n;i++) ok[i]=0;
    ok[1]=-1;
    t=R[1].txly; R[1].tcho=0;
    R[1].stt=1; R[1].tluu=t;
    j=2;
    while(j<=n){
    d=0; int tmin=99;
    for(i=1; i<=n; i++) if(ok[i]!=-1 &&R[i].tvao<=t){
    d++; ok[i]=1;}
    if (d!=0){
    d--;
    for (i=1; i<=n; i++)
    if (ok[i]==1 && R[i].txly<tmin){
    tmin=R[i].txly;id=i;
    }
    ok[id]=-1; R[id].stt=j;
    R[id].tcho=t-R[id].tvao; t=t+R[id].txly;
    R[id].tluu=R[id].tcho + R[id].txly;
    j++;
    }
    else{
    for (i=1; i<=n; i++)
    if (ok[i]==0 && R[i].txly<tmin){
    tmin=R[i].txly;id=i;
    }
    ok[id]=-1; R[id].stt=j;
    R[id].tcho=0; t=R[id].tvao+R[id].txly;
    R[id].tluu=R[id].tcho + R[id].txly;
    j++;
    }
    };
    // sap xep theo thu tu cap phat
    for(i=1; i<n;i++) for(j=i+1;j<=n;j++)
    if (R[i].stt>R[j].stt){
    process tg =R[i];
    R[i]=R[j];
    R[j]=tg;
    }

    clrscr();
    printf("\n\t__________ Ket qua dieu phoi SJF___________________\n");
    printf("\n\t|TTCP| Ten TT | Tvao | SD CPU | TLuu | TCho |\n");
    printf("\t======================================== =====");
    for (i=1; i<=n; i++){
    s1=s1+R[i].tcho;
    s2=s2+R[i].tluu;
    printf("\n\t| %2d | %6s | %4d | %6d | %4d | %4d |",
    i,R[i].ten,R[i].tvao,R[i].txly,R[i].tluu,R[i].tcho);
    }
    printf("\n\t====================================== =======");
    printf("\n\t\t\t\t\t%4d%8d",s2,s1);
    printf("\n\n\tThoi gian cho TB %10.3f",(float)s1/n);
    printf("\n\tThoi gian luu TB %10.3f",(float)s2/n);
    getch();
    printf("\n An bat ki phim nao de quay lai menu.");
    }
    void DUT(){
    int t,d,i,id,s1=0,s2=0;
    process *R=P;
    for(i=1;i<=n;i++) ok[i]=0;
    ok[1]=-1;
    t=R[1].txly; R[1].tcho=R[1].tluu=t;
    R[1].stt=1;
    j=2;
    d=0;
    while(j<=n){
    for(i=1; i<=n; i++) if(ok[i]!=-1 && R[i].tvao<=t && ok[i]==0){
    d++; ok[i]=1;}
    if (d!=0){
    d--;
    int Qmin=99;
    for (i=1; i<=n; i++)
    if (ok[i]==1 && R[i].dut<Qmin){
    Qmin=R[i].dut;
    id=i;
    }
    ok[id]=-1;
    R[id].stt=j;
    j++;
    R[id].tcho=t-R[id].tvao;
    t=t+R[id].txly;
    R[id].tluu=R[id].tcho+R[id].txly;
    }
    else{
    for (i=1;i<=n;i++)
    if (ok[i]!=-1){
    id=i;
    break;
    }
    ok[id]=-1;
    R[id].stt=j;
    j++;
    R[id].tcho=0;
    t=R[id].tvao+R[id].txly;
    R[id].tluu=R[id].tcho+R[id].txly;
    }
    };
    for(i=1; i<n;i++) for(j=i+1;j<=n;j++)
    if (R[i].stt>R[j].stt){
    process tg =R[i];
    R[i]=R[j];
    R[j]=tg;
    }

    //out ra danh sach
    clrscr();
    printf("\n\t__________ Ket qua dieu phoi theo do uu tien__________\n");
    printf("\n\t|TTCP| Ten TT | Tvao | SD CPU | DUT | Tcho | Tluu |\n");
    printf("\t======================================== ===========");
    for (i=1; i<=n; i++){
    s1=s1+R[i].tcho;
    s2=s2+R[i].tluu;
    printf("\n\t| %2d | %6s | %4d | %6d | %3d | %4d | %4d |",
    R[i].stt,R[i].ten,R[i].tvao,R[i].txly,R[i].dut,R[i].tcho,R[i].tluu);
    }
    printf("\n\t====================================== =============");
    printf("\n\t\t\t\t\t %4d %4d",s1,s2);
    printf("\n\t\tThoi gian cho TB =%5.3f",(float)s1/n);
    printf("\n\t\tThoi gian luu TB =%5.3f",(float)s2/n);
    getch();
    printf("\n An bat ki phim nao de quay lai menu.");
    }

  5. #5
    Tham gia
    10-11-2006
    Bài viết
    177
    Like
    0
    Thanked 1 Time in 1 Post
    Quote Được gửi bởi IA32 View Post
    Compile, link okie
    Chương trình tạo ra vẫn chạy được
    Bạn nói lỗi cụ thể hơn đi
    Chắc là IA32 sử dụng vc++.
    Quote Được gửi bởi longhaitac View Post
    bạn compile = chương trình gì vậy ? Khi mình compile = dev c++ thì nó nói Code not compile !
    Có thể với devc++ bạn phải tự thiết lập các lib để link.

    Bạn quănng lỗi lên xem nào.

    [=========> Bổ sung bài viết <=========]

    Quote Được gửi bởi dungnhik5h View Post
    Có ai chi giup minh voi. Minh viet doan do hoa rieng thi chay rat binh thuong, khi ghep vao trong 1 bai hoan chinh thi no lai ko load duoc phan đồ họa. Chang hiu lam sao nua. Bạn nao bit chi giup minh voi nhe'.

    #include <stdio.h>
    #include <graphics.h>
    #include <conio.h>
    #include <string.h>
    #include <stdlib.h>

    struct process{
    char ten[12];
    int tvao;
    int txly;
    int tcho;
    int tluu;
    int stt;
    int dut;
    } P[20];
    int n, j, ok[20];

    int khoitaomenu();
    void nhapDL(process P[20]);
    void FIFO(void);
    void DUT(void);
    void SJF(void);
    void create_graph(process P[20]);


    void main(){
    clrscr();
    int choice;
    printf("\n Nhap so tien trinh yeu cau CPU: n = "); scanf("%d",&n);
    nhapDL(P);
    int mh=0, mode=0;
    initgraph(&mh, &mode, "c:\\Tc\\BGI");
    create_graph(P);
    getch();

    do{
    choice=khoitaomenu();
    switch(choice) {
    case 1:{
    FIFO();
    break;
    };
    case 2:{
    SJF();
    break;
    }
    /* case 3:{
    RR();
    break;
    }*/
    case 4:{
    DUT();
    break;
    }

    case 0:{
    break;
    }
    default:{
    gotoxy(18,20);
    printf("\n\t\tLoi! Hay nhap so [0-4] ");
    getch();
    break;
    }
    }
    }while(choice != 0);
    }

    int khoitaomenu(){
    int choice = -1;
    clrscr();
    gotoxy(22, 8);
    printf("***** Menu *****");
    gotoxy(18, 10);
    printf("1. Chiem luoc FIFO");
    gotoxy(18, 12);
    printf("2. Chien luoc SJF (do quyen)");
    gotoxy(18, 14);
    printf("3. Chien luoc Round Robin");
    gotoxy(18, 16);
    printf("4. Chien luoc Do uu tien");
    gotoxy(18, 18);
    printf("0. Thoat chuong trinh");
    gotoxy(18, 20);
    printf("Nhap vao lua chon cua ban:");
    scanf("%d", &choice);
    return choice;
    }
    void create_graph(process P[20])
    {
    int mh=0, mode=0;
    initgraph(&mh, &mode, "c:\\Tc\\BGI");
    if (graphresult() != grOk)
    {printf("\nLoi do hoa!");
    getch();
    exit(1);}
    setcolor(RED);
    moveto(50,30);
    outtext("******************* MO TA DO HOA *******************");
    moveto(70,60);
    outtext("******* Thuat toan dieu phoi tien trinh *******");
    moveto(20,100);
    outtext("Day cac tien trinh di vao theo thu tu da nhap:");
    setcolor(1);
    int y1=150, y2=y1+30, x1=100, x2=x1+15*P[1].txly;
    rectangle(x1,y1,x2,y2);
    outtextxy((x2+x1)/2, (y1+y2)/2, P[1].ten);
    for (int i=2; i<=n; i++)
    {
    x1=100+15*P[i].tvao; x2=x1+10*P[i].txly;
    y1=y2+8; y2=y1+30;
    setcolor(i+1);
    rectangle(x1,y1,x2,y2);
    moveto((x1+x2)/2, (y1+y2)/2);
    outtext(P[i].ten);
    }
    closegraph();
    }

    void nhapDL(process P[20]){
    int i=1;
    while (i<=n){
    //clrscr();
    fflush(stdin);
    printf("\n\tTen tien trinh : "); gets(P[i].ten);
    printf("\tThoi diem vao : "); scanf("%d",&P[i].tvao);
    printf("\tThoi gian xu ly: "); scanf("%d",&P[i].txly);
    printf("\tDo uu tien: "); scanf("%d",&P[i].dut);
    i++;
    // create_graph(P);
    }
    }

    void FIFO(){
    int i, t=0, s1=0, s2=0;
    process *Q=P;
    //sap xep theo thoi gian vao tang dan
    for(i=1; i<n;i++) for(j=i+1;j<=n;j++)
    if (Q[i].tvao>Q[j].tvao){
    process tg =Q[i];
    Q[i]=Q[j];
    Q[j]=tg;
    }
    Q[1].stt=1; // tien trinh dau tien duoc xu ly
    Q[1].tcho=0;
    t=Q[1].tvao + Q[1].txly;
    Q[1].tluu=Q[1].txly;
    j=1;
    for (i=2; i<=n; i++)
    if (Q[i].tvao<=t){
    j++;
    Q[i].stt=j;
    Q[i].tcho=t-Q[i].tvao;
    t=t+Q[i].txly;
    Q[i].tluu=t-Q[i].tvao;
    }
    else{ // neu chua co tien trinh nao cho xu ly
    j++;
    Q[i].stt=j;
    t=Q[i].tvao;
    Q[i].tcho=0;
    t=t+Q[i].txly;
    Q[i].tluu=Q[i].tcho+Q[i].txly;
    }
    // sap xep theo thu tu cap phat
    for(i=1; i<n;i++) for(j=i+1;j<=n;j++)
    if (Q[i].stt>Q[j].stt){
    process tg =Q[i];
    Q[i]=Q[j];
    Q[j]=tg;
    }
    //out ra danh sach
    clrscr();
    printf("\n\t__________ Ket qua dieu phoi theo FIFO__________\n");
    printf("\n\t|TTCP| Ten TT | Tvao | SD CPU | TLuu | TCho |\n");
    printf("\t======================================== =====");
    for (i=1; i<=n; i++){
    s1=s1+Q[i].tcho;
    s2=s2+Q[i].tluu;
    printf("\n\t| %2d | %6s | %4d | %6d | %4d | %4d |",
    i,Q[i].ten,Q[i].tvao,Q[i].txly,Q[i].tluu,Q[i].tcho);
    }
    printf("\n\t====================================== =======");
    printf("\n\t\t\t\t\t%4d%8d",s2,s1);
    printf("\n\n\tThoi gian cho TB %10.3f",(float)s1/n);
    printf("\n\tThoi gian luu TB %10.3f",(float)s2/n);
    printf("\n An bat ki Qhim nao de quay lai menu.");
    getch();
    }
    void SJF(void){
    int i,t,d,id,s1=0,s2=0;
    process *R=P;
    for (i=0; i<=n;i++) ok[i]=0;
    ok[1]=-1;
    t=R[1].txly; R[1].tcho=0;
    R[1].stt=1; R[1].tluu=t;
    j=2;
    while(j<=n){
    d=0; int tmin=99;
    for(i=1; i<=n; i++) if(ok[i]!=-1 &&R[i].tvao<=t){
    d++; ok[i]=1;}
    if (d!=0){
    d--;
    for (i=1; i<=n; i++)
    if (ok[i]==1 && R[i].txly<tmin){
    tmin=R[i].txly;id=i;
    }
    ok[id]=-1; R[id].stt=j;
    R[id].tcho=t-R[id].tvao; t=t+R[id].txly;
    R[id].tluu=R[id].tcho + R[id].txly;
    j++;
    }
    else{
    for (i=1; i<=n; i++)
    if (ok[i]==0 && R[i].txly<tmin){
    tmin=R[i].txly;id=i;
    }
    ok[id]=-1; R[id].stt=j;
    R[id].tcho=0; t=R[id].tvao+R[id].txly;
    R[id].tluu=R[id].tcho + R[id].txly;
    j++;
    }
    };
    // sap xep theo thu tu cap phat
    for(i=1; i<n;i++) for(j=i+1;j<=n;j++)
    if (R[i].stt>R[j].stt){
    process tg =R[i];
    R[i]=R[j];
    R[j]=tg;
    }

    clrscr();
    printf("\n\t__________ Ket qua dieu phoi SJF___________________\n");
    printf("\n\t|TTCP| Ten TT | Tvao | SD CPU | TLuu | TCho |\n");
    printf("\t======================================== =====");
    for (i=1; i<=n; i++){
    s1=s1+R[i].tcho;
    s2=s2+R[i].tluu;
    printf("\n\t| %2d | %6s | %4d | %6d | %4d | %4d |",
    i,R[i].ten,R[i].tvao,R[i].txly,R[i].tluu,R[i].tcho);
    }
    printf("\n\t====================================== =======");
    printf("\n\t\t\t\t\t%4d%8d",s2,s1);
    printf("\n\n\tThoi gian cho TB %10.3f",(float)s1/n);
    printf("\n\tThoi gian luu TB %10.3f",(float)s2/n);
    getch();
    printf("\n An bat ki phim nao de quay lai menu.");
    }
    void DUT(){
    int t,d,i,id,s1=0,s2=0;
    process *R=P;
    for(i=1;i<=n;i++) ok[i]=0;
    ok[1]=-1;
    t=R[1].txly; R[1].tcho=R[1].tluu=t;
    R[1].stt=1;
    j=2;
    d=0;
    while(j<=n){
    for(i=1; i<=n; i++) if(ok[i]!=-1 && R[i].tvao<=t && ok[i]==0){
    d++; ok[i]=1;}
    if (d!=0){
    d--;
    int Qmin=99;
    for (i=1; i<=n; i++)
    if (ok[i]==1 && R[i].dut<Qmin){
    Qmin=R[i].dut;
    id=i;
    }
    ok[id]=-1;
    R[id].stt=j;
    j++;
    R[id].tcho=t-R[id].tvao;
    t=t+R[id].txly;
    R[id].tluu=R[id].tcho+R[id].txly;
    }
    else{
    for (i=1;i<=n;i++)
    if (ok[i]!=-1){
    id=i;
    break;
    }
    ok[id]=-1;
    R[id].stt=j;
    j++;
    R[id].tcho=0;
    t=R[id].tvao+R[id].txly;
    R[id].tluu=R[id].tcho+R[id].txly;
    }
    };
    for(i=1; i<n;i++) for(j=i+1;j<=n;j++)
    if (R[i].stt>R[j].stt){
    process tg =R[i];
    R[i]=R[j];
    R[j]=tg;
    }

    //out ra danh sach
    clrscr();
    printf("\n\t__________ Ket qua dieu phoi theo do uu tien__________\n");
    printf("\n\t|TTCP| Ten TT | Tvao | SD CPU | DUT | Tcho | Tluu |\n");
    printf("\t======================================== ===========");
    for (i=1; i<=n; i++){
    s1=s1+R[i].tcho;
    s2=s2+R[i].tluu;
    printf("\n\t| %2d | %6s | %4d | %6d | %3d | %4d | %4d |",
    R[i].stt,R[i].ten,R[i].tvao,R[i].txly,R[i].dut,R[i].tcho,R[i].tluu);
    }
    printf("\n\t====================================== =============");
    printf("\n\t\t\t\t\t %4d %4d",s1,s2);
    printf("\n\t\tThoi gian cho TB =%5.3f",(float)s1/n);
    printf("\n\t\tThoi gian luu TB =%5.3f",(float)s2/n);
    getch();
    printf("\n An bat ki phim nao de quay lai menu.");
    }
    ko dùng TC hơn 10 năm rồi
    Được sửa bởi _donquixote_ lúc 14:49 ngày 14-12-2008 Reason: Bổ sung bài viết

  6. #6
    Tham gia
    30-08-2008
    Bài viết
    116
    Like
    0
    Thanked 0 Times in 0 Posts
    sao không đưa vào code cho dễ đọc các pro?

  7. #7
    Tham gia
    10-11-2006
    Bài viết
    177
    Like
    0
    Thanked 1 Time in 1 Post
    Quote Được gửi bởi Anh_tn View Post
    sao không đưa vào code cho dễ đọc các pro?
    Chỉ quote thôi mà.

Bookmarks

Quy định

  • Bạn không thể tạo chủ đề mới
  • Bạn không thể trả lời bài viết
  • Bạn không thể gửi file đính kèm
  • Bạn không thể sửa bài viết của mình
  •