Changeset 582 for Daodan/MSVC
- Timestamp:
- Jan 19, 2011, 5:35:43 AM (14 years ago)
- Location:
- Daodan/MSVC
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/MSVC/Flatline.c
r581 r582 4 4 #include "Flatline_Server.h" 5 5 #include "Flatline_Events.h" 6 #include <Windows.h> 6 7 //#include <sys/time.h> 7 8 #include <time.h> 9 #include <float.h> 10 #define isnan(x) ((x) != (x)) 8 11 uint32_t last1 = 0; uint32_t last2 = 0; 9 12 player_info Players[MAX_PLAYERS] = {{0}, {0}, {0}, {0}}; 10 13 player_info * PlayerList[MAX_CONNECTIONS] = {0}; 11 14 multiplayer_status MultiplayerStatus; 12 15 unsigned int lastPingTime; 13 16 … … 207 210 break; 208 211 case PK_PONG: 209 212 for(i = 0; i < max_connections; i++) { 210 213 if(PlayerList[i] != 0 && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) { 211 214 found_player = 1; … … 221 224 else 222 225 { 223 PlayerList[i]->Ping = (ONgGameState->GameTime - packet->ping) * 1000 / 60;226 PlayerList[i]->Ping = GetTickCount() - packet->ping; 224 227 } 225 228 break; … … 278 281 //FLrClient_Run 279 282 //Looping function that waits for packets from the server. 280 281 283 int client_slot = 0; 284 285 void FLrClient_GetPackets() 286 { 287 flatline_packet packet; 288 uint16_t len; 289 //#define SPAM_INPUT 290 #ifdef SPAM_INPUT 291 struct timeval lasttime; 292 struct timeval thistime; 293 gettimeofday(&lasttime, 0); 294 #endif 295 296 297 while(NetUDPSocket_Recieve(client_sock, (sockaddr_storage *) &client_address, &packet, &len)) { 298 //packet = (flatline_packet*)data; 299 //DDrConsole_PrintF("Data recieved, length %i, type %i", len, ((flatline_packet*)data)->id); 300 switch(packet.id) { 301 case MESSAGE: 302 COrMessage_Print(packet.data, "chat", 0); 303 break; 304 case CONNECT_SEND: 305 ;if(1) { 306 flatline_packet connect_recv; 307 memcpy(&connect_recv.connect_reply.message,"This isn't a server!", sizeof("This isn't a server!")); 308 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&connect_recv, sizeof(bool) + FLATLINE_HEADER + sizeof("This isn't a server!")); 309 } 310 case CONNECT_REPLY: 311 break; //extra packet or something. 312 case NEW_PLAYER: 313 ;if(1) { //haxhaxhax 314 CharacterObject* Char = &(packet.new_player.Character); 315 uint32_t chr_index = 0; 316 Character* PC; 317 DDrConsole_PrintF("%i | %i", packet.new_player.Playernumber ,client_slot); 318 //Char->OSD.Options = 0; 319 if(packet.new_player.Playernumber == client_slot) { 320 PlayerList[packet.new_player.Playernumber] = &Players[0]; 321 PC = (ONgGameState->PlayerCharacter); 322 Players[0].Chr = PC; 323 324 } 325 else { 326 ONrGameState_NewCharacter(Char, NULL, NULL, &chr_index); 327 ONgGameState->CharacterStorage[chr_index].charType = 0; 328 PlayerList[packet.new_player.Playernumber] = &Players[chr_index]; 329 Players[chr_index].Chr = &(ONgGameState->CharacterStorage[chr_index]); 330 Players[chr_index].Chr->Flags &= 0xFFBFFFFF; 331 Players[chr_index].spawnnumber = chr_index; 332 DDrConsole_PrintF("Spawning player %s, class %s, slot %i", ((new_player*)(packet.data))->Character.OSD.Name, ((new_player*)(packet.data))->Character.OSD.Class,chr_index) ; 333 } 334 //Players[((new_player*)(packet.data))->Playernumber].spawnnumber = ONrGameState_NewCharacter(&(((new_player*)(packet.data))->Character), NULL, NULL, 0); 335 break; 336 } 337 case PLAYER_DATA: 338 if(1) { //haxhaxhax 339 player_data* pd = &packet.player_data; 340 uint16_t i = pd->PlayerNum; 341 342 pd = (void*)packet.data; 343 344 345 if (i > max_connections) break; 346 if( !PlayerList[i] ) break; 347 348 memcpy( &(PlayerList[i]->player_data), pd, sizeof(player_data) ); 349 350 if( !server_started && pd->rare_sync_index > PlayerList[i]->rare_sync_index ) 351 { 352 int sent_bytes; 353 flatline_packet sync_request = {0}; 354 sync_request.id = RARE_SYNC_DATA_REQUEST; 355 sync_request.sync_request = i; 356 DDrConsole_PrintF( "Requesting sync data for player %i, old index %u", i, PlayerList[i]->rare_sync_index); 357 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&sync_request, FLATLINE_HEADER + sizeof(int) ); 358 } 359 360 PlayerList[i]->DataApplied = 0; 361 362 363 break; 364 } 365 case RARE_SYNC_DATA: 366 if(1) { 367 sl_arg hax[2]; 368 int dontuse; 369 uint16_t i = packet.rare_sync_data.PlayerNum; 370 371 if (i > max_connections) break; 372 if( !PlayerList[i] ) break; 373 374 //WEAPONS ARE DISABLED. Why? Pain in the arse to sync. 375 packet.rare_sync_data.Inventory.Weapons[0] = NULL; 376 packet.rare_sync_data.Inventory.Weapons[1] = NULL; 377 packet.rare_sync_data.Inventory.Weapons[2] = NULL; 378 // TMrInstance_GetDataPtr( 'ONCC', packet.rare_sync_data.Class, PlayerList[ i ]->Chr->ONCC ); 379 380 //add the target character 381 hax[0].type = sl_int32; 382 hax[0].value_int32 = PlayerList[ packet.rare_sync_data.PlayerNum ]->spawnnumber; 383 384 //add the new class 385 //fix this later so we cant buffer overflow :O 386 hax[1].type = sl_str32; 387 hax[1].value_str32 = packet.rare_sync_data.Class; 388 389 //we are directly calling a bsl function instead of using the normal method for two reasons 390 //1. it has all the checking built in 391 iSetCharacterClass( 0, 2, hax, &dontuse, &dontuse, hax ); 392 //DDrConsole_PrintF( "Recieved sync data for player %i, class %s, old index %u, new index %u", i, packet.rare_sync_data.Class, PlayerList[i]->rare_sync_index, packet.rare_sync_data.index); 393 memcpy( &(PlayerList[ i ]->Chr->Inventory), &(packet.rare_sync_data.Inventory), sizeof(Inventory )); 394 395 PlayerList[i]->rare_sync_index = packet.rare_sync_data.index; 396 } 397 break; 398 case FLATLINE_EVENT: 399 FLcEventHandler( packet.flatline_event.event_index, packet.flatline_event.intArray ); 400 break; 401 case PK_PING: 402 packet.id = PK_PONG; 403 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&packet, FLATLINE_HEADER + 4); 404 break; 405 case PK_ALL_INPUT: 406 if(1) 407 { 408 int Player, i; 409 for(i = 0; packet.all_input[i].PlayerNum != -1; i++) 410 { 411 Player = packet.all_input[i].PlayerNum; 412 if(PlayerList[Player]) 413 { 414 PlayerList[Player]->Actions1 = packet.all_input[Player].Actions1; 415 PlayerList[Player]->Actions2 = packet.all_input[Player].Actions2; 416 PlayerList[Player]->MouseDeltaX = packet.all_input[Player].MouseDeltaX; 417 PlayerList[Player]->MouseDeltaY = packet.all_input[Player].MouseDeltaY; 418 PlayerList[Player]->Facing = packet.all_input[Player].Facing; 419 PlayerList[Player]->DesiredFacing = packet.all_input[Player].DesiredFacing; 420 PlayerList[Player]->Position = packet.all_input[Player].Position; 421 } 422 } 423 } 424 break; 425 default: 426 DDrConsole_PrintF("Warning, recieved badly formed packet!"); 427 break; 428 } 429 } 430 } 431 432 282 433 bool FLrClient_Run(flatline_packet* packet) 283 434 { … … 302 453 if(packet->id == CONNECT_REPLY) { 303 454 if(packet->connect_reply.goodtogo){ 455 304 456 client_connected = 1; 305 457 … … 313 465 //disable local input. 314 466 DDrPatch_NOOP(0x004FA929, 5 + 6 + 5); 467 468 //Disable local turning 469 //DDrPatch_NOOP(0x004F7EA8, 2); 470 //DDrPatch_Byte( 0x004F7EB1 , 0xE9); 471 //DDrPatch_MakeJump( 0x004F7EB1, 0x004F8030 ); 472 473 474 //DDrPatch_Byte(0x04ED6FB, 0xEB); 315 475 316 476 //DDrConsole_PrintF("Slot %i", ((connect_reply*)packet)->player_slot); 477 //DDrPatch_NOOP(0x43B23,0x10); 478 //DDrPatch_NOOP(0x4EC248,(0x5A-0x48)); 479 //DDrPatch_NOOP(0x4EC861, 6); 317 480 break; 318 481 } … … 333 496 return false; 334 497 } 335 else 336 { 337 ActiveCharacter * Active; 338 flatline_packet packet; 339 //#define SPAM_INPUT 340 #ifdef SPAM_INPUT 341 struct timeval lasttime; 342 struct timeval thistime; 343 gettimeofday(&lasttime, 0); 344 #endif 345 while(1) { 346 #ifdef SPAM_INPUT 347 gettimeofday(&thistime, 0); 348 349 //DDrConsole_PrintF("%i.%i | %i.%i | %i.%i",lasttime.tv_sec, lasttime.tv_usec, thistime.tv_sec, thistime.tv_usec, 350 // thistime.tv_sec - lasttime.tv_sec, thistime.tv_usec - lasttime.tv_usec); 351 //checks to see if enough time has passed since the last input update (by default once every 10ms) 352 if( 353 ((thistime.tv_sec > lasttime.tv_sec) && ((thistime.tv_usec + 1000000 - lasttime.tv_usec ) > update_rate * 1000) ) 354 || ((thistime.tv_sec == lasttime.tv_sec) && ((thistime.tv_usec - lasttime.tv_usec ) > update_rate * 1000)) 355 ) { 356 357 flatline_packet input_packet; 358 lasttime.tv_usec = ++thistime.tv_usec; //in case recieving packets takes less than 1 ms. 359 360 input_packet.id = PLAYER_INPUT; 361 362 if( ((GameState*)(ONgGameState))->Input.Current.Actions1 != last1 || ((GameState*)(ONgGameState))->Input.Current.Actions2 != last2) { 363 last1 =((GameState*)(ONgGameState))->Input.Current.Actions1; 364 last2 =((GameState*)(ONgGameState))->Input.Current.Actions2; 365 } 366 367 ((input_struct*)(void*)(input_packet.data))->Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1; 368 ((input_struct*)(void*)(input_packet.data))->Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2; 369 ((input_struct*)(void*)(input_packet.data))->MouseDeltaX = ((GameState*)(ONgGameState))->Input.MouseDeltaX; 370 ((input_struct*)(void*)(input_packet.data))->MouseDeltaY = ((GameState*)(ONgGameState))->Input.MouseDeltaY; 371 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&input_packet, sizeof(input_struct) + FLATLINE_HEADER); 372 //if(sent_bytes == SOCKET_ERROR) NetCatchError(); 373 } 374 #endif 375 if(NetUDPSocket_Recieve(client_sock, (sockaddr_storage *) &client_address, &packet, &len)) { 376 //packet = (flatline_packet*)data; 377 //DDrConsole_PrintF("Data recieved, length %i, type %i", len, ((flatline_packet*)data)->id); 378 switch(packet.id) { 379 case MESSAGE: 380 COrMessage_Print(packet.data, "chat", 0); 381 break; 382 case CONNECT_SEND: 383 ;if(1) { 384 flatline_packet connect_recv; 385 memcpy(&connect_recv.connect_reply.message,"This isn't a server!", sizeof("This isn't a server!")); 386 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&connect_recv, sizeof(bool) + FLATLINE_HEADER + sizeof("This isn't a server!")); 387 } 388 case CONNECT_REPLY: 389 break; //extra packet or something. 390 case NEW_PLAYER: 391 ;if(1) { //haxhaxhax 392 CharacterObject* Char = &(packet.new_player.Character); 393 uint32_t chr_index = 0; 394 Character* PC; 395 DDrConsole_PrintF("%i | %i", packet.new_player.Playernumber ,client_slot); 396 //Char->OSD.Options = 0; 397 if(packet.new_player.Playernumber == client_slot) { 398 PlayerList[packet.new_player.Playernumber] = &Players[0]; 399 PC = (ONgGameState->PlayerCharacter); 400 Players[0].Chr = PC; 401 402 } 403 else { 404 ONrGameState_NewCharacter(Char, NULL, NULL, &chr_index); 405 ONgGameState->CharacterStorage[chr_index].charType = 0; 406 PlayerList[packet.new_player.Playernumber] = &Players[chr_index]; 407 Players[chr_index].Chr = &(ONgGameState->CharacterStorage[chr_index]); 408 Players[chr_index].Chr->Flags &= 0xFFBFFFFF; 409 Players[chr_index].spawnnumber = chr_index; 410 DDrConsole_PrintF("Spawning player %s, class %s, slot %i", ((new_player*)(packet.data))->Character.OSD.Name, ((new_player*)(packet.data))->Character.OSD.Class,chr_index) ; 411 } 412 //Players[((new_player*)(packet.data))->Playernumber].spawnnumber = ONrGameState_NewCharacter(&(((new_player*)(packet.data))->Character), NULL, NULL, 0); 413 break; 414 } 415 case PLAYER_DATA: 416 if(1) { //haxhaxhax 417 player_data* pd = &packet.player_data; 418 uint16_t i = pd->PlayerNum; 419 GameInput * Active_Input; 420 pd = (void*)packet.data; 421 422 //DDrConsole_PrintF("Got data for Player %i, %x", i, PlayerList[i]); 423 if (i > max_connections) break; 424 if( !PlayerList[i] ) break; 425 //PlayerList[i]->Chr = ((GameState *)ONgGameState)->CharacterStorage; 426 427 /* PlayerList[i]->Actions1 = pd->Inputs.Actions1; 428 PlayerList[i]->Actions2 = pd->Inputs.Actions2; 429 PlayerList[i]->MouseDeltaX = pd->Inputs.MouseDeltaX; 430 PlayerList[i]->MouseDeltaY = pd->Inputs.MouseDeltaY;*/ 431 memcpy( &(PlayerList[i]->player_data), pd, sizeof(player_data) ); 432 433 if( !server_started && pd->rare_sync_index > PlayerList[i]->rare_sync_index ) 434 { 435 int sent_bytes; 436 flatline_packet sync_request = {0}; 437 sync_request.id = RARE_SYNC_DATA_REQUEST; 438 sync_request.sync_request = i; 439 DDrConsole_PrintF( "Requesting sync data for player %i, old index %u", i, PlayerList[i]->rare_sync_index); 440 sent_bytes = NetUDPSocket_Send(client_sock,(sockaddr *) &address, (char*)&sync_request, FLATLINE_HEADER + sizeof(int) ); 441 } 442 443 PlayerList[i]->DataApplied = 0; 444 445 446 break; 447 } 448 case RARE_SYNC_DATA: 449 if(1) { 450 sl_arg hax[2]; 451 int dontuse; 452 uint16_t i = packet.rare_sync_data.PlayerNum; 453 454 if (i > max_connections) break; 455 if( !PlayerList[i] ) break; 456 457 //WEAPONS ARE DISABLED. Why? Pain in the arse to sync. 458 packet.rare_sync_data.Inventory.Weapons[0] = NULL; 459 packet.rare_sync_data.Inventory.Weapons[1] = NULL; 460 packet.rare_sync_data.Inventory.Weapons[2] = NULL; 461 // TMrInstance_GetDataPtr( 'ONCC', packet.rare_sync_data.Class, PlayerList[ i ]->Chr->ONCC ); 462 463 //add the target character 464 hax[0].type = sl_int32; 465 hax[0].value_int32 = PlayerList[ packet.rare_sync_data.PlayerNum ]->spawnnumber; 466 467 //add the new class 468 //fix this later so we cant buffer overflow :O 469 hax[1].type = sl_str32; 470 hax[1].value_str32 = packet.rare_sync_data.Class; 471 472 //we are directly calling a bsl function instead of using the normal method for two reasons 473 //1. it has all the checking built in 474 iSetCharacterClass( 0, 2, hax, &dontuse, &dontuse, hax ); 475 //DDrConsole_PrintF( "Recieved sync data for player %i, class %s, old index %u, new index %u", i, packet.rare_sync_data.Class, PlayerList[i]->rare_sync_index, packet.rare_sync_data.index); 476 memcpy( &(PlayerList[ i ]->Chr->Inventory), &(packet.rare_sync_data.Inventory), sizeof(Inventory )); 477 478 PlayerList[i]->rare_sync_index = packet.rare_sync_data.index; 479 } 480 break; 481 case FLATLINE_EVENT: 482 FLcEventHandler( packet.flatline_event.event_index, packet.flatline_event.intArray ); 483 break; 484 case PK_PING: 485 packet.id = PK_PONG; 486 NetUDPSocket_Send(client_sock, (sockaddr *) &address, (char*)&packet, FLATLINE_HEADER + 4); 487 break; 488 case PK_ALL_INPUT: 489 if(1) 490 { 491 int Player; 492 for(Player = 0; Player < MAX_CONNECTIONS; Player++) 493 { 494 if(PlayerList[Player]) 495 { 496 PlayerList[Player]->Actions1 = packet.all_input[Player].Actions1; 497 PlayerList[Player]->Actions2 = packet.all_input[Player].Actions2; 498 PlayerList[Player]->MouseDeltaX = packet.all_input[Player].MouseDeltaX; 499 PlayerList[Player]->MouseDeltaY = packet.all_input[Player].MouseDeltaY; 500 } 501 } 502 } 503 break; 504 default: 505 DDrConsole_PrintF("Warning, recieved badly formed packet!"); 506 break; 507 } 508 } 509 else { 510 Sleep(1); 511 } 512 } 513 } 498 514 499 return true; 515 500 } … … 543 528 } IMtPoint2D; 544 529 static flatline_packet cache_input = {0}; 545 extern void* TSrTest; 530 enum 531 { 532 FirstPass, 533 SecondPass, 534 NoPass, 535 }; 536 bool ShouldSendUpdate( int i, Character* Player, ActiveCharacter* Active_Player ) 537 { 538 return 539 MultiplayerStatus.PleaseUpdateAllPlayers ? 1 : 540 strcmp(PlayerList[i]->player_data.Animation, 541 TMrInstance_GetInstanceName(Active_Player->Animation)) ? 1 : 542 PlayerList[i]->player_data.Health != Player->Health ? 1 : 0; 543 } 544 546 545 void * ONICALL FLrInput_Update_Keys(void) 547 546 { 548 547 uint16_t i; 549 548 flatline_packet all_input = {0}; 550 ActiveCharacter * Active_Player = ONgGameState->ActiveCharacters; 551 Active_Player->PhyContext->Rotation; 552 Active_Player->PhyContext->Position; 553 ONgGameState->PlayerCharacter->Position; 554 549 int16_t InputIndex = 0; 550 //ActiveCharacter * Active_Player = ONgGameState->ActiveCharacters; 551 555 552 if(client_connected) 556 553 { 557 554 int sent_bytes; 558 555 flatline_packet input_packet = {0}; 556 557 FLrClient_GetPackets(); 558 559 559 input_packet.id = PLAYER_INPUT; 560 560 input_packet.input_struct.Time = ONgGameState->GameTime; 561 // ((GameState*)(ONgGameState))->Input.Current.Actions1 |= Action_Backward | Action_StepLeft; 561 562 input_packet.input_struct.Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1; 562 563 input_packet.input_struct.Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2; … … 577 578 { 578 579 FLsPingAll(); 580 } 581 582 if(server_started && PlayerList[0]) 583 { 584 PlayerList[0]->Actions1 = ONgGameState->Input.Current.Actions1; 585 PlayerList[0]->Actions2 = ONgGameState->Input.Current.Actions2; 586 PlayerList[0]->MouseDeltaX = ONgGameState->Input.MouseDeltaX; 587 PlayerList[0]->MouseDeltaY = ONgGameState->Input.MouseDeltaY; 579 588 } 580 589 … … 584 593 GameInput * Active_Input; 585 594 if(PlayerList[i] == 0) continue; 586 587 588 if(i == 0) {589 all_input.all_input[i].Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1;590 all_input.all_input[i].Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2;591 all_input.all_input[i].MouseDeltaX = ONgGameState->Input.MouseDeltaX;592 all_input.all_input[i].MouseDeltaY = ONgGameState->Input.MouseDeltaY;593 }594 else{595 all_input.all_input[i].Actions1 = PlayerList[i]->Actions1;596 all_input.all_input[i].Actions2 = PlayerList[i]->Actions2;597 all_input.all_input[i].MouseDeltaX = PlayerList[i]->MouseDeltaX;598 all_input.all_input[i].MouseDeltaY = PlayerList[i]->MouseDeltaY;599 }600 601 595 Player = PlayerList[i]->Chr; 596 if(server_started) 597 { 598 599 //Set up input packets 600 601 all_input.all_input[InputIndex].Actions1 = PlayerList[i]->Actions1; 602 all_input.all_input[InputIndex].Actions2 = PlayerList[i]->Actions2; 603 all_input.all_input[InputIndex].MouseDeltaX = PlayerList[i]->MouseDeltaX; 604 all_input.all_input[InputIndex].MouseDeltaY = PlayerList[i]->MouseDeltaY; 605 606 all_input.all_input[InputIndex].Facing = Player->Facing; 607 all_input.all_input[InputIndex].DesiredFacing = Player->DesiredFacing; 608 609 //Infinity... 610 *(int *)&all_input.all_input[InputIndex].Position.X = 0x7f800000; 611 612 all_input.all_input[InputIndex].PlayerNum = i; 613 InputIndex++; 614 } 615 602 616 if( Player->Health == 0) 603 617 { … … 614 628 } 615 629 616 if(server_started & i == 0)630 if(server_started && i == 0) 617 631 { 618 632 Actions = ONgGameState->Input.Current.Actions1; … … 641 655 642 656 Active_Player = ONrGetActiveCharacter( PlayerList[i]->Chr); 643 657 644 658 if(Active_Player == 0) continue; 659 660 661 662 //Active_Player->PlayingFilm.Flags = 1; 645 663 Active_Input = &(Active_Player->Input); 646 647 if(server_started && strcmp(PlayerList[i]->player_data.Animation, TMrInstance_GetInstanceName(Active_Player->Animation))) 664 if(server_started) 665 { 666 all_input.all_input[InputIndex - 1].Position = Active_Player->PhyContext->Position; 667 } 668 if(server_started && 669 ShouldSendUpdate( i, PlayerList[i]->Chr, Active_Player) ) 648 670 { 649 671 player_data * data; … … 656 678 data->Health = PlayerList[i]->Chr->Health; 657 679 data->MaxHealth = PlayerList[i]->Chr->MaxHealth; 658 data->Position = PlayerList[i]->Chr->Position;659 data->Facing = PlayerList[i]->Chr->Facing;660 data->DesiredFacing = PlayerList[i]->Chr->DesiredFacing;661 data->Position = Active_Player->PhyContext->Position;680 //data->Position = PlayerList[i]->Chr->Position; 681 //data->Facing = PlayerList[i]->Chr->Facing; 682 //data->DesiredFacing = PlayerList[i]->Chr->DesiredFacing; 683 //data->Position = Active_Player->PhyContext->Position; 662 684 memcpy(data->Animation, TMrInstance_GetInstanceName(Active_Player->Animation), 31); 663 685 data->Frame = Active_Player->Frame; 686 687 data->UD = Active_Player->HeadPitch; 688 data->LR = Active_Player->HeadFacing; 664 689 665 690 if(Active_Player->targetThrow) … … 688 713 } 689 714 690 if( (server_started && i !=0) || (!server_started/* && i != client_slot*/))715 if( (server_started && i !=0) || !server_started ) 691 716 { 692 717 Active_Input->Stop.Actions1 = ~PlayerList[i]->Actions1 & Active_Input->Current.Actions1; … … 707 732 void* Animation; 708 733 player_data* pd = &PlayerList[i]->player_data; 709 710 711 //Note to self: sort out which needs to be applied the first time and which the second. 712 switch(PlayerList[i]->DataApplied) 734 735 PlayerList[i]->Chr->Facing = PlayerList[i]->Facing; 736 PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->DesiredFacing; 737 738 if(*(int*)&PlayerList[i]->Chr->Position.X != 0x7f800000) 713 739 { 714 case 1: 715 PlayerList[i]->DataApplied = 2; 716 break; 717 case 0: 718 PlayerList[i]->DataApplied = 1; 719 case 2: 720 continue; 721 } 722 723 Player->Health = PlayerList[i]->player_data.Health; 724 PlayerList[i]->Chr->MaxHealth = PlayerList[i]->player_data.MaxHealth; 725 726 PlayerList[i]->Chr->Facing = PlayerList[i]->player_data.Facing; 727 PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->player_data.DesiredFacing; 728 729 /* PlayerList[i]->Actions1 = PlayerList[i]->player_data.Inputs.Actions1; 730 PlayerList[i]->Actions2 = PlayerList[i]->player_data.Inputs.Actions2; 731 PlayerList[i]->MouseDeltaX = PlayerList[i]->player_data.Inputs.MouseDeltaX; 732 PlayerList[i]->MouseDeltaY = PlayerList[i]->player_data.Inputs.MouseDeltaY;*/ 733 Active_Player->PhyContext->Position = PlayerList[i]->player_data.Position; 734 OldAnimation = Active_Player->Animation; 735 736 if (!(Player->Flags & ONcCharacterFlag_BeingThrown) && 737 (pd->Animation != 0)) 740 Active_Player->PhyContext->Position = PlayerList[i]->Position; 741 } 742 else 738 743 { 739 // get a pointer to the animation 740 741 TMrInstance_GetDataPtr( 742 'TRAM', 743 pd->Animation, 744 &Animation); 745 if (Animation != OldAnimation) 744 int breakfast = 0; 745 } 746 /* 747 if(isnan(Active_Player->PhyContext->Position.Y) || 748 isnan(Active_Player->PhyContext->Position.X) || 749 isnan(Active_Player->PhyContext->Position.Z) ) 750 { 751 //DDrConsole_PrintF("Player is NAN! %x %x", Active_Player->PhyContext->Position.Y, PlayerList[i]->Height); 752 DDrConsole_PrintF("Player is NAN! %x %x %x", Active_Player->PhyContext->Position.X, Active_Player->PhyContext->Position.Y, Active_Player->PhyContext->Position.Z); 753 //DDrConsole_PrintF("Velocity %x %x %x", Active_Player->PhyContext->Velocity.X, Active_Player->PhyContext->Velocity.Y, Active_Player->PhyContext->Velocity.Z); 754 755 756 } 757 */ 758 759 if( PlayerList[i]->DataApplied == FirstPass ) 760 { 761 PlayerList[i]->DataApplied = SecondPass; 762 763 Player->Health = PlayerList[i]->player_data.Health; 764 PlayerList[i]->Chr->MaxHealth = PlayerList[i]->player_data.MaxHealth; 765 766 } 767 else if( PlayerList[i]->DataApplied == SecondPass ) 768 { 769 OldAnimation = Active_Player->Animation; 770 771 PlayerList[i]->DataApplied = NoPass; 772 773 PlayerList[i]->player_data.Frame++; 774 775 if (!(Player->Flags & ONcCharacterFlag_BeingThrown) && 776 (pd->Animation[0] != 0)) 746 777 { 747 short num_frames; 748 bool updateAnimation = true; 749 750 // if the character is dead, make sure this animation is appropriate for death 751 /* 752 if (Player->Flags & ONcCharacterFlag_Dead) 778 // get a pointer to the animation 779 780 TMrInstance_GetDataPtr( 781 'TRAM', 782 pd->Animation, 783 &Animation); 784 if (Animation != OldAnimation) 753 785 { 754 short curToState = TRrAnimation_GetTo(Active_Player->Animation); 755 short newToState = TRrAnimation_GetTo(animation); 756 757 // if we are currently heading towards fallen and the new animation would not 758 // then this is a better animation to run when we are dead 759 if ((ONrAnimState_IsFallen(curToState)) && 760 (!ONrAnimState_IsFallen(newToState))) 761 { 762 updateAnimation = false; 763 } 764 } 765 */ 766 if ((updateAnimation) && (Active_Player->Animation == Animation)) 767 { 768 int oldFrame = Active_Player->Frame; 769 int newFrame = pd->Frame; 770 771 if (abs(oldFrame - newFrame) < 2) 786 short num_frames; 787 bool updateAnimation = true; 788 789 // if the character is dead, make sure this animation is appropriate for death 790 /* 791 if (Player->Flags & ONcCharacterFlag_Dead) 772 792 { 773 updateAnimation = false; 793 short curToState = TRrAnimation_GetTo(Active_Player->Animation); 794 short newToState = TRrAnimation_GetTo(animation); 795 796 // if we are currently heading towards fallen and the new animation would not 797 // then this is a better animation to run when we are dead 798 if ((ONrAnimState_IsFallen(curToState)) && 799 (!ONrAnimState_IsFallen(newToState))) 800 { 801 updateAnimation = false; 802 } 803 } 804 */ 805 if ((updateAnimation) && (Active_Player->Animation == Animation)) 806 { 807 int oldFrame = Active_Player->Frame; 808 int newFrame = pd->Frame; 809 810 if (abs(oldFrame - newFrame) < 2) 811 { 812 updateAnimation = false; 813 } 814 } 815 816 if (updateAnimation) 817 { 818 // set the characters animation 819 /* ONrCharacter_SetAnimationInternal(Player, 820 Active_Player, 821 Active_Player->AnimationToState, 822 0, 823 Animation); 824 ONrCharacter_NewAnimationHook(Player, Active_Player);*/ 825 //Player->Flags |= 0x00000010; 826 ONrCharacter_SetAnimationExternal(Player, TRrAnimation_GetFrom(Animation), Animation, 0); 827 //ONrCharacter_NewAnimationHook(Player, Active_Player); 828 } 829 830 num_frames = TRrAnimation_GetDuration(Active_Player->Animation); 831 832 if (pd->Frame == num_frames) 833 { 834 Active_Player->Frame = num_frames - 1; 835 //Active_Player->Frame = 0; 836 } 837 else 838 { 839 Active_Player->Frame = pd->Frame; 774 840 } 775 841 } 776 777 if (updateAnimation) 842 } //animation check 843 844 if (PlayerList[i]->player_data.throw_data.throwName[0] != 0) 845 { 846 short throwTarget = PlayerList[pd->throw_data.throwing]->spawnnumber; 847 if ((throwTarget != Active_Player->throwing) && 848 (pd->throw_data.throwFrame < 10)) 778 849 { 779 // set the characters animation 780 /* ONrCharacter_SetAnimationInternal(Player, 781 Active_Player, 782 Active_Player->AnimationToState, 783 0, 784 Animation); 785 ONrCharacter_NewAnimationHook(Player, Active_Player);*/ 786 //Player->Flags |= 0x00000010; 787 ONrCharacter_SetAnimationExternal(Player, TRrAnimation_GetFrom(Animation), Animation, 0); 788 //ONrCharacter_NewAnimationHook(Player, Active_Player); 789 } 790 791 num_frames = TRrAnimation_GetDuration(Active_Player->Animation); 792 793 if (pd->Frame == num_frames) 794 { 795 Active_Player->Frame = num_frames - 1; 796 //Active_Player->Frame = 0; 797 } 798 else 799 { 800 Active_Player->Frame = pd->Frame; 801 } 802 } 803 } 804 805 if (PlayerList[i]->player_data.throw_data.throwName[0] != 0) 806 { 807 short throwTarget = PlayerList[pd->throw_data.throwing]->spawnnumber; 808 if ((throwTarget != Active_Player->throwing) && 809 (pd->throw_data.throwFrame < 10)) 810 { 811 void *throw_animation; 812 ActiveCharacter* Target; 813 // get the animation 814 815 TMrInstance_GetDataPtr( 816 'TRAM', 817 pd->throw_data.throwName, 818 &throw_animation); 819 //if (error) return; 820 821 // set the throw target 822 Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[throwTarget]; 823 Target = ONrGetActiveCharacter(Active_Player->ThrowTargetCharacter); 824 if ((Target->Animation != throw_animation) && 825 (OldAnimation != Animation) && 826 !(Active_Player->ThrowTargetCharacter->Flags & ONcCharacterFlag_BeingThrown)) 827 { 828 // set the throw variables 829 Active_Player->targetThrow = throw_animation; 830 Active_Player->throwing = throwTarget; 831 832 // run the throw 833 ONrCharacter_NewAnimationHook(Player, Active_Player); 834 835 if (Active_Player->ThrowTargetCharacter) 850 void *throw_animation; 851 ActiveCharacter* Target; 852 // get the animation 853 854 TMrInstance_GetDataPtr( 855 'TRAM', 856 pd->throw_data.throwName, 857 &throw_animation); 858 //if (error) return; 859 860 // set the throw target 861 Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[throwTarget]; 862 Target = ONrGetActiveCharacter(Active_Player->ThrowTargetCharacter); 863 if ((Target->Animation != throw_animation) && 864 (OldAnimation != Animation) && 865 !(Active_Player->ThrowTargetCharacter->Flags & ONcCharacterFlag_BeingThrown)) 836 866 { 837 Target->Frame += 2; 838 Target->thrownBy = Player->Number; 867 // set the throw variables 868 Active_Player->targetThrow = throw_animation; 869 Active_Player->throwing = throwTarget; 870 871 // run the throw 872 ONrCharacter_NewAnimationHook(Player, Active_Player); 873 874 if (Active_Player->ThrowTargetCharacter) 875 { 876 Target->Frame += 2; 877 Target->thrownBy = Player->Number; 878 } 839 879 } 840 880 } 841 } 842 } 843 844 } 845 } 881 } //throw check 882 } //second pass 883 } //if not dead 884 } //if( (server_started && i !=0) || !server_started ) 885 886 //Check for character switching requests 887 if(server_started && PlayerList[i]->Actions1 & Action_Block && PlayerList[i]->ShapeshiftCooldown < ONgGameState->GameTime) 888 { 889 int error; 890 891 892 893 ONCC *newClass; 894 short numClasses = (short)TMrInstance_GetTagCount('ONCC'); 895 /* 896 if(Active_Player->Input.Start.Actions1 & Action_Block) 897 { 898 //This might not be getting hit. Find out why, eh? 899 PlayerList[i]->ShapeshiftCooldown = ONgGameState->GameTime + 15; 900 } 901 else 902 { 903 PlayerList[i]->ShapeshiftCooldown = ONgGameState->GameTime + 5; 904 } 905 */ 906 if (PlayerList[i]->Actions1 & Action_Crouch) { 907 Player->ONCCnumber += numClasses - 1; 908 } 909 else { 910 Player->ONCCnumber += 1; 911 } 912 913 if (numClasses > 0) { 914 Player->ONCCnumber = Player->ONCCnumber % numClasses; 915 916 error = TMrInstance_GetDataPtr_ByNumber('ONCC', Player->ONCCnumber, &newClass); 917 918 if ((newClass != NULL) && (!error)) { 919 ONrCharacter_SetCharacterClass(Player, newClass); 920 } 921 } 922 923 } 924 846 925 847 926 } 848 927 if(server_started) 849 928 { 850 UDPServer_SendToAll(&all_input, FLATLINE_HEADER + sizeof(player_input) * 32); 851 } 852 929 all_input.all_input[InputIndex].PlayerNum = -1; 930 UDPServer_SendToAll(&all_input, 931 FLATLINE_HEADER + sizeof(player_input) * InputIndex + sizeof(int16_t)); 932 } 933 MultiplayerStatus.PleaseUpdateAllPlayers = 0; 853 934 return ONgGameState; 854 935 } … … 859 940 { 860 941 //FLsPublic_Event(EV_DISCONNECT, &Player ); 942 MultiplayerStatus.PleaseUpdateAllPlayers = 1; 861 943 } 862 944 //Kill off the character in another function, please … … 932 1014 } 933 1015 } 1016 1017 bool FlatlineInitialize() 1018 { 1019 1020 memset( Players, 0, sizeof( player_info ) * MAX_PLAYERS ); 1021 memset( PlayerList, 0, 4 * MAX_PLAYERS ); 1022 memset( &MultiplayerStatus, 0, sizeof( multiplayer_status )); 1023 return 1; 1024 } -
Daodan/MSVC/Flatline.h
r581 r582 116 116 typedef struct { 117 117 uint16_t PlayerNum; 118 Vector3 Position; 119 float Facing; 120 float DesiredFacing; 118 //Vector3 Position; 119 120 //float Facing; 121 //float DesiredFacing; 122 123 float UD; 124 float LR; 125 121 126 uint32_t Health; 122 127 uint32_t MaxHealth; … … 130 135 int Deaths; 131 136 uint16_t Ping; 137 132 138 } player_data; 133 139 … … 146 152 147 153 typedef struct { 154 int16_t PlayerNum; 148 155 float MouseDeltaX; 149 156 float MouseDeltaY; 150 157 uint32_t Actions1; 151 158 uint32_t Actions2; 159 float Facing; 160 float DesiredFacing; 161 Vector3 Position; 152 162 } player_input; 153 163 … … 210 220 211 221 222 typedef struct { 223 //Server Only 224 bool PleaseUpdateAllPlayers; 225 //Client stuff (can be used by server "client") 226 227 //Move from random scattered bools to these, please. 228 bool ClientConnected; 229 unsigned int ClientSlot; 230 bool ServerStatus; 231 } multiplayer_status; 212 232 213 233 enum { … … 227 247 uint16_t spawnnumber; 228 248 uint16_t list_slot; 249 250 //Todo: move into struct for slightly faster copying 229 251 float MouseDeltaX; 230 252 float MouseDeltaY; 231 253 uint32_t Actions1; 232 254 uint32_t Actions2; 255 float Facing; 256 float DesiredFacing; 257 //float Height; 258 Vector3 Position; 259 233 260 unsigned int LastInputTime; 234 261 input_struct CacheInput; … … 242 269 uint32_t Ping; 243 270 bool DataApplied; 271 272 uint32_t ShapeshiftCooldown; 244 273 } player_info; 245 274 … … 260 289 extern player_info Players[]; 261 290 extern player_info * PlayerList[]; 262 291 extern multiplayer_status MultiplayerStatus; 263 292 int UDPServer_SendToAll(void* packet, int size); 264 293 … … 271 300 void FLrPlayerRespawn( int Player ); 272 301 int FLrEvent_GetNumArgs( int eventIndex ); 273 302 bool FlatlineInitialize(); 274 303 extern unsigned int lastPingTime; 275 304 #endif -
Daodan/MSVC/Flatline_BSL.c
r580 r582 72 72 uint16_t ONICALL connect_to_server(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) 73 73 { 74 //TODO: Move this into the client initialization. Doing it like this is silly. 74 75 if( NetPlatform_Initalize()) { 75 76 static flatline_packet packet; … … 128 129 uint16_t ONICALL kick(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) 129 130 { 130 FLrPlayerDisconnect(args[0].value_int32 - 1);131 FLrPlayerDisconnect(args[0].value_int32); 131 132 FLsPublic_Event(EV_DISCONNECT, &args[0].value_int32); 132 133 return 0; … … 226 227 SLrScript_Command_Register_Void("kick", "Kicks a client from the server", "clientnum:int", kick); 227 228 SLrScript_Command_Register_Void("con", "Activates a console", "con:int", con); 228 //SLrScript_Command_Register_ReturnType("ai2_spawn","creates and starts an AI from a character object","ai_name:string [force_spawn:string{\"force\"} | ]", sl_void, spawnAI);229 229 SLrScript_Command_Register_Void("ping", "pong!", "", ping); 230 230 } -
Daodan/MSVC/Flatline_Net.c
r567 r582 207 207 } 208 208 209 210 209 211 DWORD WINAPI StartServer(void* lol){ 210 NetPlatform_Initalize(); 211 FLrServer_Run(); 212 if(NetPlatform_Initalize() && FlatlineInitialize()) 213 { 214 FLrServer_Run(); 215 } 212 216 return 0; 213 217 } … … 215 219 DWORD WINAPI StartClient(void* lol){ 216 220 //NetPlatform_Initalize(); 217 FLrClient_Run((flatline_packet*)lol); 221 if(FlatlineInitialize()) 222 { 223 FLrClient_Run((flatline_packet*)lol); 224 } 218 225 return 0; 219 226 } -
Daodan/MSVC/Flatline_Server.c
r580 r582 1 1 #include "Flatline.h" 2 2 #include "Flatline_Server.h" 3 #include <Windows.h> 3 4 4 5 //I hereby apologize for the uglyness of the below code. … … 92 93 sprintf(PlayerList[playerlist_slot]->name,"%.31s",name); 93 94 95 MultiplayerStatus.PleaseUpdateAllPlayers = 1; 96 94 97 return &Players[player_slot]; 95 98 } … … 146 149 flatline_packet ping; 147 150 ping.id = PK_PING; 148 lastPingTime = ping.ping = ONgGameState->GameTime;151 lastPingTime = ping.ping = GetTickCount(); 149 152 UDPServer_SendToAll(&ping, FLATLINE_HEADER + 4); 150 153 } -
Daodan/MSVC/Oni_GameState.h
r578 r582 769 769 int field_8; 770 770 ONCC* ONCC; 771 __int16 field_10;771 __int16 ONCCnumber; 772 772 __int16 Team; 773 773 char Name[32]; … … 799 799 int BNV; 800 800 int GraphNode; 801 int PelvisHeight;801 float PelvisHeight; 802 802 int field_190; 803 803 Inventory Inventory; … … 1257 1257 int field_21AC; 1258 1258 Vector3 field_21B0; 1259 int HeadFacing;1260 int HeadPitch;1259 float HeadFacing; 1260 float HeadPitch; 1261 1261 int field_21C4; 1262 1262 int field_21C8; … … 1322 1322 typedef struct 1323 1323 { 1324 char name[64]; // Must be same as ONcMaxLevelName above (for TE) 1325 1326 void *env; 1327 void *objectsetup; 1328 void *markers; 1329 void *flags; 1330 void *triggers; 1331 1332 void *Sky; 1333 float SkyHeight; 1334 1335 1336 } OniLevel; 1337 1338 typedef struct 1339 { 1324 1340 int TimerMode; 1325 1341 char TimerName[32]; … … 1379 1395 int field_148; 1380 1396 int field_14C; 1381 intLevel;1397 OniLevel* Level; 1382 1398 int field_154; 1383 1399 MotionBlur MotionBlur_[64]; -
Daodan/MSVC/Oni_Symbols.h
r579 r582 229 229 //typedef void ( *_ONiGameState_FindAutoPromptMessage)(char* Note, void* ptr); 230 230 DefFunc( void, ONiGameState_FindAutoPromptMessage, (char* Note, void* ptr), 0x004FDBE0 ); 231 DefFunc( void, ONrCharacter_SetCharacterClass, (Character* Char, ONCC* Class), 0x004D7C30 ); 232 DefFunc( short, TMrInstance_GetDataPtr_ByNumber, (int tag, int number, void** out), 0x00423680 ); 233 DefFunc( uint32_t, TMrInstance_GetTagCount, (int tag), 0x004236F0); 231 234 #endif
Note:
See TracChangeset
for help on using the changeset viewer.