5
5
#include " movie_lib.h"
6
6
7
7
#include < assert.h>
8
+ #include < stdint.h>
8
9
#include < stdio.h>
9
10
#include < string.h>
10
11
@@ -96,6 +97,10 @@ static int _MVE_sndDecompS16(unsigned short* a1, unsigned char* a2, int a3, int
96
97
static void _nfPkConfig ();
97
98
static void _nfPkDecomp (unsigned char * buf, unsigned char * a2, int a3, int a4, int a5, int a6);
98
99
100
+ static constexpr uint16_t loadUInt16LE (const uint8_t * b);
101
+ static constexpr uint32_t loadUInt32LE (const uint8_t * b);
102
+ static uint8_t getOffset (uint16_t v);
103
+
99
104
// 0x51EBD8
100
105
static int dword_51EBD8 = 0 ;
101
106
@@ -757,7 +762,7 @@ static unsigned char* _ioNextRecord()
757
762
return NULL ;
758
763
}
759
764
760
- _io_next_hdr = *( int *) (buf + (_io_next_hdr & 0xFFFF ));
765
+ _io_next_hdr = loadUInt32LE (buf + (_io_next_hdr & 0xFFFF ));
761
766
762
767
return buf;
763
768
}
@@ -854,7 +859,7 @@ int _MVE_rmStepMovie()
854
859
}
855
860
856
861
while (1 ) {
857
- v5 = *( unsigned int *) ((unsigned char *)v1 + v0);
862
+ v5 = loadUInt32LE ((unsigned char *)v1 + v0);
858
863
v1 = (unsigned short *)((unsigned char *)v1 + v0 + 4 );
859
864
v0 = v5 & 0xFFFF ;
860
865
@@ -877,7 +882,7 @@ int _MVE_rmStepMovie()
877
882
} else {
878
883
v7 = (v1[1 ] & 0x04 ) >> 2 ;
879
884
}
880
- v8 = *( unsigned int *) ((unsigned char *)v1 + 6 );
885
+ v8 = loadUInt32LE ((unsigned char *)v1 + 6 );
881
886
if ((v5 >> 24 ) == 0 ) {
882
887
v8 &= 0xFFFF ;
883
888
}
@@ -1438,7 +1443,7 @@ static int _MVE_sndAdd(unsigned char* dest, unsigned char** src_ptr, int a3, int
1438
1443
}
1439
1444
1440
1445
if (a5) {
1441
- v12 = *( unsigned int *) src;
1446
+ v12 = loadUInt32LE ( src) ;
1442
1447
src += 4 ;
1443
1448
1444
1449
*(unsigned int *)dest = v12;
@@ -1868,8 +1873,6 @@ static void _nfPkDecomp(unsigned char* a1, unsigned char* a2, int a3, int a4, in
1868
1873
int i;
1869
1874
int j;
1870
1875
ptrdiff_t v10;
1871
- int v11;
1872
- int v13;
1873
1876
int byte;
1874
1877
unsigned int value1;
1875
1878
unsigned int value2;
@@ -1919,38 +1922,36 @@ static void _nfPkDecomp(unsigned char* a1, unsigned char* a2, int a3, int a4, in
1919
1922
break ;
1920
1923
case 2 :
1921
1924
case 3 :
1922
- byte = *a2++;
1923
- v11 = word_51F618[byte];
1924
- if (v7 == 3 ) {
1925
- v11 = ((-(v11 & 0xFF )) & 0xFF ) | ((-(v11 >> 8 ) & 0xFF ) << 8 );
1926
- } else {
1927
- v11 = v11;
1925
+ if (1 ) {
1926
+ byte = *a2++;
1927
+ uint16_t offset = word_51F618[byte];
1928
+ if (v7 == 3 ) {
1929
+ offset = ((-(offset & 0xFF )) & 0xFF ) | ((-(offset >> 8 ) & 0xFF ) << 8 );
1930
+ }
1931
+ v10 = getOffset (offset);
1928
1932
}
1929
- v10 = ((v11 << 24 ) >> 24 ) + dword_51F018[v11 >> 8 ];
1930
1933
break ;
1931
1934
case 4 :
1932
1935
case 5 :
1933
- if (v7 == 4 ) {
1934
- byte = *a2++;
1935
- v13 = word_51F418[byte];
1936
- } else {
1937
- v13 = *(unsigned short *)a2;
1938
- a2 += 2 ;
1939
- }
1936
+ if (1 ) {
1937
+ uint16_t offset;
1938
+ if (v7 == 4 ) {
1939
+ byte = *a2++;
1940
+ offset = word_51F418[byte];
1941
+ } else {
1942
+ offset = loadUInt16LE (a2);
1943
+ a2 += 2 ;
1944
+ }
1940
1945
1941
- v10 = ((v13 << 24 ) >> 24 ) + dword_51F018[v13 >> 8 ] + (gMovieDirectDrawSurfaceBuffer2 - gMovieDirectDrawSurfaceBuffer1 );
1946
+ v10 = getOffset (offset) + (gMovieDirectDrawSurfaceBuffer2 - gMovieDirectDrawSurfaceBuffer1 );
1947
+ }
1942
1948
break ;
1943
1949
}
1944
1950
1945
1951
value2 = _mveBW;
1946
1952
1947
- for (i = 0 ; i < 8 ; i++) {
1948
- src_ptr = (unsigned int *)(dest + v10);
1949
- dest_ptr = (unsigned int *)dest;
1950
-
1951
- dest_ptr[0 ] = src_ptr[0 ];
1952
- dest_ptr[1 ] = src_ptr[1 ];
1953
-
1953
+ for (i = 0 ; i < 8 ; ++i) {
1954
+ memcpy (dest, dest + v10, 8 );
1954
1955
dest += value2;
1955
1956
}
1956
1957
@@ -2669,11 +2670,8 @@ static void _nfPkDecomp(unsigned char* a1, unsigned char* a2, int a3, int a4, in
2669
2670
case 11 :
2670
2671
value2 = _mveBW;
2671
2672
2672
- src_ptr = (unsigned int *)a2;
2673
- for (i = 0 ; i < 8 ; i++) {
2674
- dest_ptr = (unsigned int *)dest;
2675
- dest_ptr[0 ] = src_ptr[i * 2 ];
2676
- dest_ptr[1 ] = src_ptr[i * 2 + 1 ];
2673
+ for (i = 0 ; i < 32 ; i += 4 ) {
2674
+ memcpy (dest, &a2[i * 2 ], 8 );
2677
2675
dest += value2;
2678
2676
}
2679
2677
@@ -2763,7 +2761,7 @@ static void _nfPkDecomp(unsigned char* a1, unsigned char* a2, int a3, int a4, in
2763
2761
value1 = byte | (byte << 8 ) | (byte << 16 ) | (byte << 24 );
2764
2762
value2 = value1;
2765
2763
} else {
2766
- byte = *( unsigned short *)a2 ;
2764
+ byte = loadUInt16LE (a2) ;
2767
2765
a2 += 2 ;
2768
2766
value1 = byte | (byte << 16 );
2769
2767
value2 = value1;
@@ -2794,4 +2792,19 @@ static void _nfPkDecomp(unsigned char* a1, unsigned char* a2, int a3, int a4, in
2794
2792
}
2795
2793
}
2796
2794
2795
+ constexpr uint16_t loadUInt16LE (const uint8_t * b)
2796
+ {
2797
+ return (b[1 ] << 8 ) | b[0 ];
2798
+ }
2799
+
2800
+ constexpr uint32_t loadUInt32LE (const uint8_t * b)
2801
+ {
2802
+ return (b[3 ] << 24 ) | (b[2 ] << 16 ) | (b[1 ] << 8 ) | b[0 ];
2803
+ }
2804
+
2805
+ uint8_t getOffset (uint16_t v)
2806
+ {
2807
+ return static_cast <int8_t >(v & 0xFF ) + dword_51F018[v >> 8 ];
2808
+ }
2809
+
2797
2810
} // namespace fallout
0 commit comments