Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // UnDiff - Apply difference block
  4. //
  5. //=============================================================================//
  6. #include "tier0/platform.h"
  7. #include "tier0/dbg.h"
  8. #include "tier1/diff.h"
  9. #include "mathlib/mathlib.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. void ApplyDiffs(uint8 const *OldBlock, uint8 const *DiffList,
  13. int OldSize, int DiffListSize, int &ResultListSize,uint8 *Output,uint32 OutSize)
  14. {
  15. uint8 const *copy_src=OldBlock;
  16. uint8 const *end_of_diff_list=DiffList+DiffListSize;
  17. uint8 const *obuf=Output;
  18. while(DiffList<end_of_diff_list)
  19. {
  20. // printf("dptr=%x ",DiffList-d);
  21. uint8 op=*(DiffList++);
  22. if (op==0)
  23. {
  24. uint16 copy_sz=DiffList[0]+256*DiffList[1];
  25. int copy_ofs=DiffList[2]+DiffList[3]*256;
  26. if (copy_ofs>32767)
  27. copy_ofs|=0xffff0000;
  28. // printf("long cp from %x to %x len=%d\n", copy_src+copy_ofs-OldBlock,Output-obuf,copy_sz);
  29. memcpy(Output,copy_src+copy_ofs,copy_sz);
  30. Output+=copy_sz;
  31. copy_src=copy_src+copy_ofs+copy_sz;
  32. DiffList+=4;
  33. }
  34. else
  35. {
  36. if (op & 0x80)
  37. {
  38. int copy_sz=op & 0x7f;
  39. int copy_ofs;
  40. if (copy_sz==0)
  41. {
  42. copy_sz=DiffList[0];
  43. if (copy_sz==0)
  44. {
  45. // big raw copy
  46. copy_sz=DiffList[1]+256*DiffList[2]+65536*DiffList[3];
  47. memcpy(Output,DiffList+4,copy_sz);
  48. // printf("big rawcopy to %x len=%d\n", Output-obuf,copy_sz);
  49. DiffList+=copy_sz+4;
  50. Output+=copy_sz;
  51. }
  52. else
  53. {
  54. copy_ofs=DiffList[1]+(DiffList[2]*256);
  55. if (copy_ofs>32767)
  56. copy_ofs|=0xffff0000;
  57. // printf("long ofs cp from %x to %x len=%d\n", copy_src+copy_ofs-OldBlock,Output-obuf,copy_sz);
  58. memcpy(Output,copy_src+copy_ofs,copy_sz);
  59. Output+=copy_sz;
  60. copy_src=copy_src+copy_ofs+copy_sz;
  61. DiffList+=3;
  62. }
  63. }
  64. else
  65. {
  66. copy_ofs=DiffList[0];
  67. if (copy_ofs>127)
  68. copy_ofs|=0xffffff80;
  69. // printf("cp from %x to %x len=%d\n", copy_src+copy_ofs-OldBlock,Output-obuf,copy_sz);
  70. memcpy(Output,copy_src+copy_ofs,copy_sz);
  71. Output+=copy_sz;
  72. copy_src=copy_src+copy_ofs+copy_sz;
  73. DiffList++;
  74. }
  75. }
  76. else
  77. {
  78. // printf("raw copy %d to %x\n",op & 127,Output-obuf);
  79. memcpy(Output,DiffList,op & 127);
  80. Output+=op & 127;
  81. DiffList+=(op & 127);
  82. }
  83. }
  84. }
  85. ResultListSize=Output-obuf;
  86. }