fork/slippc
git clone https://git.julia.blue/fork/slippc
46ef8c0
testing
1#ifndef COMPRESSOR_H_ 2#define COMPRESSOR_H_ 3 4#include <iostream> 5#include <fstream> 6#include <sstream> 7#include <regex> 8#include <map> 9#include <cmath> 10#include <limits> 11#include <cstdio> 12#include <filesystem> 13 14#include "util.h" 15#include "enums.h" 16#include "schema.h" 17#include "gecko-legacy.h" 18 19// Replay File (.slp) Spec: https://github.com/project-slippi/slippi-wiki/blob/master/SPEC.md 20 21const uint8_t COMPRETZ_VERSION = 2 ;//Internal version of this compressor 22 23const uint32_t RAW_RNG_MASK = 0x40000000 ;//Second bit of unsigned int 24const uint32_t MAGIC_FLOAT = 0xFF000000 ;//First 8 bits of float 25const uint32_t EXPONENT_BITS = 0x7F800000 ;//Exponent bits 2-9 of a float 26const uint32_t DEFER_ITEM_BITS = 0xC000 ;//Bitmask for storing deferred writes of items 27 28const uint32_t ITEM_SLOTS = 256 ;//Max number of items we expect to track at once 29const uint32_t MESSAGE_SIZE = 517 ;//Size of Message Splitter event 30const uint32_t MAX_ITEMS_C = 2048 ;//Max number of items to track initially 31const uint32_t MAX_ROLLBACK = 128 ;//Max number of frames game can roll back 32const int RB_SIZE = 4 ;//Size of circular queue for tracking repeated frames 33 34const int FRAME_ENC_DELTA = 1 ;//Delta when predicting and encoding next frame 35const int ALLOC_EVENTS = 100000 ;//Number of events to initially allocate space for shuffling 36 37namespace slip { 38 39class Compressor { 40private : 41 42int _debug ;//Current debug level 43uint16_t _payload_sizes [256 ]= {0 };//Size of payload for each event 44uint8_t _slippi_maj = 0 ;//Major version number of replay being parsed 45uint8_t _slippi_min = 0 ;//Minor version number of replay being parsed 46uint8_t _slippi_rev = 0 ;//Revision number of replay being parsed 47uint8_t _encode_ver = 0 ;//Encryption status of replay being parsed 48int32_t _max_frames = 0 ;//Maximum number of frames that there will be in the replay file 49std ::string * _outfilename = nullptr ;//Name of the file to write 50std ::string * _outgeckofilename = nullptr ;//Name of gecko file to write 51 52//Variables needed for mapping floats to ints and vice versa 53std ::map < unsigned ,unsigned > float_to_int ;//Map of floats to ints 54std ::map < unsigned ,unsigned > int_to_float ;//Reverse map of ints back to floats 55std ::map < unsigned ,unsigned > int_to_float_c ;//Counter for reverse map of ints back to floats 56unsigned num_floats = 0 ;//Total number of floats in float map 57 58uint32_t _preds = 0 ; 59uint32_t _fails = 0 ; 60 61const char * _infilename = "" ; 62 63uint32_t _rng ;//Current RNG seed we're working with 64uint32_t _rng_start ;//Starting RNG seed 65char _x_pre_frame [8 ][256 ]= {0 };//Delta for pre-frames 66char _x_pre_frame_2 [8 ][256 ]= {0 };//Delta for 2 pre-frames ago 67char _x_post_frame [8 ][256 ]= {0 };//Delta for post-frames 68char _x_post_frame_2 [8 ][256 ]= {0 };//Delta for 2 post-frames ago 69char _x_post_frame_3 [8 ][256 ]= {0 };//Delta for 3 post-frames ago 70char _x_item [ITEM_SLOTS ][256 ]= {0 };//Delta for item updates 71char _x_item_2 [ITEM_SLOTS ][256 ]= {0 };//Delta for item updates 2 frames ago 72char _x_item_3 [ITEM_SLOTS ][256 ]= {0 };//Delta for item updates 3 frames ago 73char _x_item_4 [ITEM_SLOTS ][256 ]= {0 };//Delta for item updates 4 frames ago 74char _x_item_p [ITEM_SLOTS ][256 ]= {0 };//Delta for item position updates 75int32_t laststartframe = -123 ;//Last frame used in frame start event, encoding 76int32_t lastitemstartframe = -123 ;//Last frame used in item event, encoding 77int32_t lastshuffleframe = -123 ;//Last frame used in frame start event, shuffling 78int32_t lastitemshuffleframe = -123 ;//Last frame used in item event, shuffling 79int32_t lastpreframe [8 ]= {-123 };//Last frame used in pre frame event, encoding 80int32_t lastshufflepreframe [8 ]= {-123 };//Last frame used in pre frame event, shuffling 81int32_t lastpostframe [8 ]= {-123 };//Last frame used in post frame event, encoding 82int32_t lastshufflepostframe [8 ]= {-123 };//Last frame used in post frame event, shuffling 83 84char * _rb = nullptr ;//Read buffer 85char * _wb = nullptr ;//Write buffer 86unsigned _bp = 0 ;//Current position in buffer 87uint32_t _length_raw = 0 ;//Remaining length of raw payload 88uint32_t _length_raw_start = 0 ;//Total length of raw payload 89uint32_t _game_loop_start = 0 ;//First byte AFTER game start event 90uint32_t _game_loop_end = 0 ;//First byte OF game end event 91uint32_t _file_size = 0 ;//Total size of the replay file on disk 92uint32_t _message_count = 0 ;//Number of gecko messages we've parsed thus far 93bool _game_end_found = false;//Whether we've found the game end event 94 95// Frame event column byte widths (negative numbers denote bit shuffling) 96int32_t _cw_start [5 ]= {1 ,4 ,4 ,4 ,0 }; 97int32_t _cw_mesg [6 ]= {1 ,512 ,2 ,1 ,1 ,0 }; 98int32_t _cw_pre [21 ]= {1 ,4 ,1 ,1 ,4 ,2 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,2 ,4 ,4 ,1 ,4 ,0 }; 99int32_t _cw_item [21 ]= {1 ,4 ,2 ,1 ,4 ,4 ,4 ,4 ,4 ,2 ,4 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 };// Shuffle bytes of item id 100int32_t _cw_post [35 ]= {1 ,4 ,1 ,1 ,1 ,2 ,4 ,4 ,4 ,4 ,4 ,1 ,1 ,1 ,1 ,4 ,1 ,1 ,1 ,1 ,1 ,4 ,1 ,2 ,1 ,1 ,1 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,0 }; 101int32_t _cw_end [4 ]= {1 ,4 ,4 ,0 }; 102 103// Debug Frame event column byte widths (negative numbers denote bit shuffling) 104int32_t _dw_start [5 ]= {1 ,4 ,4 ,4 ,0 }; 105int32_t _dw_mesg [6 ]= {1 ,512 ,2 ,1 ,1 ,0 }; 106int32_t _dw_pre [21 ]= {1 ,4 ,1 ,1 ,4 ,2 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,2 ,4 ,4 ,1 ,4 ,0 }; 107int32_t _dw_item [21 ]= {1 ,4 ,2 ,1 ,4 ,4 ,4 ,4 ,4 ,2 ,4 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,0 };// Shuffle bytes of item id 108int32_t _dw_post [35 ]= {1 ,4 ,1 ,1 ,1 ,2 ,4 ,4 ,4 ,4 ,4 ,1 ,1 ,1 ,1 ,4 ,1 ,1 ,1 ,1 ,1 ,4 ,1 ,2 ,1 ,1 ,1 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,0 }; 109int32_t _dw_end [4 ]= {1 ,4 ,4 ,0 }; 110 111bool _parse ();//Internal main parsing funnction 112bool _parseHeader (); 113bool _parseEventDescriptions (); 114bool _parseEvents (); 115bool _parseGameStart (); 116bool _parseGeckoCodes (); 117bool _parsePreFrame (); 118bool _parsePostFrame (); 119bool _parseFrameStart (); 120bool _parseItemUpdate (); 121bool _parseBookend (); 122bool _shuffleEvents (bool unshuffle = false); 123bool _unshuffleEvents (); 124 125public : 126Compressor (int debug_level ); //Instantiate the parser (possibly in debug mode) 127~ Compressor (); //Destroy the parser 128bool loadFromFile ( const char * replayfilename); //Load a replay file 129void saveToFile ( bool rawencode); //Save an encoded replay file 130bool setOutputFilename ( const char * fname); //Set output file name 131bool setGeckoOutputFilename ( const char * fname); //Set gecko code output filename 132bool loadFromBuff ( char ** buffer, unsigned size); //Load a replay from a buffer 133unsigned saveToBuff ( char ** buffer); //Save an encoded replay buffer 134bool validate (); //Validate the encoding 135 136//https://www.reddit.com/r/SSBM/comments/71gn1d/the_basics_of_rng_in_melee/ 137inline int32_t rollRNGLegacy ( int32_t seed) const { 138int64_t bigseed = seed; //Cast from 32-bit to 64-bit int 139return ((bigseed * 214013 ) + 2531011 ) % 4294967296 ; 140} 141 142//Given the current frame's RNG value, just add 65536 to get the next frame's 143inline int32_t rollRNGRollback ( int32_t seed) const { 144return (seed + 65536 ) % 4294967296 ; 145} 146 147//Per Fizzi and Nikki, RNG is just the starting RNG + 65536*<0-indexed frame> 148inline int32_t computeRNGRollback ( int32_t framenum) const { 149return (((framenum + 123 ) * 65536 ) + _rng_start) % 4294967296 ; 150} 151 152//Check the RAW_RNG_MASK bit from a frame, and return whether that bit was flipped 153inline bool checkRawRNG ( int32_t & frame) const { 154//If first and second bits of frame are different, rng is stored raw 155uint8_t bit1 = (frame >> 31 ) & 0x01 ; 156uint8_t bit2 = (frame >> 30 ) & 0x01 ; 157uint8_t rng_is_raw = bit1 ^ bit2; 158return rng_is_raw > 0 ; 159} 160 161//Predict the next frame given a reference frame and delta encode the difference 162inline int32_t predictFrame ( int32_t frame, int32_t ref_frame, char * write_addr = nullptr ) const { 163//Remove RNG bit from frame 164bool rng_is_raw = checkRawRNG (frame); 165if (rng_is_raw) { 166frame ^= RAW_RNG_MASK ; 167} 168//Flip 2nd bit in _wb output if raw RNG flag is set 169uint32_t bitmask = rng_is_raw ? RAW_RNG_MASK : 0x00000000 ; 170 171int32_t frame_delta_pred; 172if (_encode_ver) { //Decode 173frame_delta_pred = frame + (ref_frame + FRAME_ENC_DELTA ); 174if (write_addr) { 175writeBE4S (frame_delta_pred ^ bitmask,write_addr); 176} 177} else { //Encode 178frame_delta_pred = frame - (ref_frame + FRAME_ENC_DELTA ); 179if (write_addr) { 180writeBE4S (frame_delta_pred,write_addr); 181} 182} 183return frame_delta_pred; 184} 185 186//Version of predictFrame used for _unshuffleEvents 187inline int32_t decodeFrame ( int32_t frame, int32_t ref_frame) const { 188return predictFrame (frame, ref_frame, nullptr ); 189} 190 191//Create a mapping of floats we've already seen by treating them as unsigned integer indices 192// to an index build on-the-fly 193inline void buildFloatMap ( unsigned off) { 194uint32_t enc_float = readBE4U ( & _rb[_bp + off]); 195if (_encode_ver) { //Decode 196if ((enc_float & MAGIC_FLOAT ) != MAGIC_FLOAT ) { 197//If it's our first encounter with a float, add it to our maps 198float_to_int[enc_float] = num_floats; 199int_to_float[num_floats] = enc_float; 200++ num_floats; 201} else { 202//Decode our int back to a float 203unsigned as_unsigned = int_to_float[enc_float & ( MAGIC_FLOAT ^ 0xFFFFFFFF )]; 204writeBE4U (as_unsigned, & _wb[_bp + off]); 205} 206} else { //Encode 207if (float_to_int. find (enc_float) == float_to_int. end ()) { 208//If it's our first encounter with a float, add it to our maps 209float_to_int[enc_float] = num_floats; 210int_to_float[num_floats] = enc_float; 211int_to_float_c[num_floats] = 1 ; 212++ num_floats; 213} else { 214//Set the 2nd and 3rd bit, since they will never be set simultaneously in real floats 215++ int_to_float_c[float_to_int[enc_float]]; 216writeBE4U (float_to_int[enc_float] | MAGIC_FLOAT , & _wb[_bp + off]); 217} 218} 219} 220 221//Compress analog float values by converting them to ints 222inline void encodeAnalog ( unsigned off, float mult) { 223union { float f ; uint32_t u ; uint8_t c [ 4 ]; int8_t i [ 4 ]; } float_true, float_pred, float_rest; 224 225// If any of exponent bits are set, we still have a float 226char * main_buf = _encode_ver ? _wb : _rb; 227float_true. u = readBE4U ( & main_buf[_bp + off]); 228if ((float_true. u & EXPONENT_BITS ) && _encode_ver) { 229return ; //If we have a float in the encoded state, nothing to do 230} 231 232float_pred. u = 0 ; //Initialize all bytes to zero 233if (_encode_ver) { 234if (mult > 127 ) { 235float_pred. f = float (float_true. c [ 0 ])/mult; 236} else { 237float_pred. f = float (float_true. i [ 0 ])/mult; 238} 239writeBE4F (float_pred. f , & _wb[_bp + off]); //Write our decoded float 240} else { 241if (mult > 127 ) { 242float_pred. c [ 0 ] = uint8_t ( round ( float (float_true. f * mult))); 243float_rest. f = float (float_pred. c [ 0 ])/mult; 244} else { 245float_pred. i [ 0 ] = int8_t ( round ( float (float_true. f * mult))); 246float_rest. f = float (float_pred. i [ 0 ])/mult; 247} 248if (float_rest. u == float_true. u ) { //Verify we can properly decode 249writeBE4U (float_pred. u , & _wb[_bp + off]); //Write our encoded int 250} 251} 252} 253 254//General purpose function for encoding the difference 255// between floats in two buffers, using a magic float value 256// to flag whether such an encoded value is present 257// (useful for computing item velocities in terms of positions) 258inline void predictAsDifference ( unsigned off, unsigned buffoff, char * buff) { 259union { float f ; uint32_t u ; } float_true, float_pred, float_temp; 260//If our prediction is accurate to at least the last 10 bits, it's close enough 261uint32_t MAXDIFF = 0x03FF ; 262 263char * main_buf = _encode_ver ? _wb : _rb; 264 265float_true. f = readBE4F ( & main_buf[_bp + off]); 266float_pred. f = readBE4F ( & main_buf[_bp + buffoff]) - readBE4F ( & buff[buffoff]); 267float_temp. u = float_pred. u ^ float_true. u ; 268 269if (_encode_ver) { 270uint32_t diff = float_true. u ^ MAGIC_FLOAT ; 271if (diff <= MAXDIFF ) { //If our prediction was accurate to at least the last few bits 272float_pred. u ^= diff; 273writeBE4F (float_pred. f , & _wb[_bp + off]); //Write our predicted float 274} 275} else { 276//If at most the last few bits are off, we succeeded 277if (float_temp. u <= MAXDIFF ) { 278writeBE4U ( MAGIC_FLOAT ^ float_temp. u , & _wb[_bp + off]); //Write an impossible float 279} else { 280// std::cout << "DIFF =" << float_temp.u << std::endl; 281} 282} 283 284memcpy ( & buff[buffoff], & main_buf[_bp + buffoff], 4 ); 285} 286 287//General purpose function for predicting jolt based 288// on float data in four buffers, using a magic float value 289// to flag whether such an encoded value is present 290inline void predictJolt ( unsigned p, unsigned off, char * buff1, char * buff2, char * buff3, char * buff4, bool verbose = false) { 291union { float f; uint32_t u; } float_true, float_pred, float_temp; 292//If our prediction is accurate to at least the last 8 bits, it's close enough 293const uint32_t MAXDIFF = 0xFF ; 294 295float_true. f = readBE4F ( & _rb[_bp + off]); 296float pos1 = readBE4F ( & buff1[off]); 297float pos2 = readBE4F ( & buff2[off]); 298float pos3 = readBE4F ( & buff3[off]); 299float pos4 = readBE4F ( & buff4[off]); 300float vel1 = pos1 - pos2; 301float vel2 = pos2 - pos3; 302float vel3 = pos3 - pos4; 303float acc1 = vel1 - vel2; 304float acc2 = vel2 - vel3; 305float jlt1 = acc1 - acc2; 306float_pred. f = pos1 + vel1 + acc1 + jlt1; 307 308if (_encode_ver) { 309uint32_t diff = float_true. u ^ MAGIC_FLOAT ; 310if (diff <= MAXDIFF ) { //If our prediction was accurate to at least the last few bits 311float_pred. u ^= diff; 312writeBE4F (float_pred. f , & _wb[_bp + off]); //Write our predicted float 313} 314} else { 315//If at most the last few bits are off, we succeeded 316if (verbose) { 317if (float_pred. u == float_true. u ) { 318std ::cout << " predicted " << float_pred. f << ", exact" << std::endl; 319} else { 320std :: streamsize ss = std::cout. precision (); 321std ::cout << std:: setprecision ( 30 ); 322std ::cout << " predicted " << float_pred. f << ", error = " << (float_pred. f - float_true. f ) << std::endl; 323std ::cout << " pos1 " << pos1 << std::endl; 324std ::cout << " vel1 " << vel1 << std::endl; 325std ::cout << " acc1 " << acc1 << std::endl; 326std ::cout << " jlt1 " << jlt1 << std::endl; 327std ::cout << " pos2 " << pos2 << std::endl; 328std ::cout << " vel2 " << vel2 << std::endl; 329std ::cout << " acc2 " << acc2 << std::endl; 330std ::cout << " pos3 " << pos3 << std::endl; 331std ::cout << " vel3 " << vel3 << std::endl; 332std ::cout << " pos4 " << pos4 << std::endl; 333std ::cout << std:: setprecision (ss); 334} 335} 336float_temp. u = float_pred. u ^ float_true. u ; 337if (float_temp. u <= MAXDIFF ) { 338if (verbose) { 339std ::cout << " we compress those " << pos3 << std::endl; 340} 341writeBE4U ( MAGIC_FLOAT ^ float_temp. u , & _wb[_bp + off]); //Write an impossible float 342} 343} 344 345memcpy ( & buff4[off], & buff3[off], 4 ); 346memcpy ( & buff3[off], & buff2[off], 4 ); 347memcpy ( & buff2[off], & buff1[off], 4 ); 348memcpy ( & buff1[off],_encode_ver ? & _wb[_bp + off] : & _rb[_bp + off], 4 ); 349} 350 351//General purpose function for predicting acceleration based 352// on float data in three buffers, using a magic float value 353// to flag whether such an encoded value is present 354inline void predictAccel ( unsigned p, unsigned off, char * buff1, char * buff2, char * buff3, bool verbose = false) { 355union { float f ; uint32_t u ; } float_true, float_pred, float_temp; 356//If our prediction is accurate to at least the last 8 bits, it's close enough 357const uint32_t MAXDIFF = 0xFF ; 358 359float_true. f = readBE4F ( & _rb[_bp + off]); 360float pos1 = readBE4F ( & buff1[off]); 361float pos2 = readBE4F ( & buff2[off]); 362float pos3 = readBE4F ( & buff3[off]); 363float vel1 = pos1 - pos2; 364float vel2 = pos2 - pos3; 365float acc1 = vel1 - vel2; 366float_pred. f = pos1 + vel1 + acc1; 367 368if (_encode_ver) { 369uint32_t diff = float_true. u ^ MAGIC_FLOAT ; 370if (diff <= MAXDIFF ) { //If our prediction was accurate to at least the last few bits 371float_pred. u ^= diff; 372writeBE4F (float_pred. f , & _wb[_bp + off]); //Write our predicted float 373} 374} else { 375//If at most the last few bits are off, we succeeded 376if (verbose) { 377if (float_pred. u == float_true. u ) { 378std ::cout << " predicted " << float_pred. f << ", exact" << std::endl; 379} else { 380std :: streamsize ss = std::cout. precision (); 381std ::cout << std:: setprecision ( 30 ); 382std ::cout << " predicted " << float_pred. f << ", error = " << (float_pred. f - float_true. f ) << std::endl; 383std ::cout << " pos1 " << pos1 << std::endl; 384std ::cout << " vel1 " << vel1 << std::endl; 385std ::cout << " acc1 " << acc1 << std::endl; 386std ::cout << " pos2 " << pos2 << std::endl; 387std ::cout << " vel2 " << vel2 << std::endl; 388std ::cout << " pos3 " << pos3 << std::endl; 389std ::cout << std:: setprecision (ss); 390} 391} 392float_temp. u = float_pred. u ^ float_true. u ; 393if (float_temp. u <= MAXDIFF ) { 394writeBE4U ( MAGIC_FLOAT ^ float_temp. u , & _wb[_bp + off]); //Write an impossible float 395} 396} 397 398memcpy ( & buff3[off], & buff2[off], 4 ); 399memcpy ( & buff2[off], & buff1[off], 4 ); 400memcpy ( & buff1[off],_encode_ver ? & _wb[_bp + off] : & _rb[_bp + off], 4 ); 401} 402 403//General purpose function for predicting velocity based 404// on float data in two buffers, using a magic float value 405// to flag whether such an encoded value is present 406inline void predictVeloc ( unsigned p, unsigned off, char * buff1, char * buff2) { 407union { float f ; uint32_t u ; } float_true, float_pred, float_temp; 408 409float_true. f = readBE4F ( & _rb[_bp + off]); 410float_pred. f = 2 * readBE4F ( & buff1[off]) - readBE4F ( & buff2[off]); 411float_temp. u = float_pred. u ^ float_true. u ; 412if (_encode_ver) { 413if (float_true. u == MAGIC_FLOAT ) { //If our prediction was exactly accurate 414writeBE4F (float_pred. f , & _wb[_bp + off]); //Write our predicted float 415} 416} else { 417if (float_temp. u == 0 ) { //If our prediction was exactly accurate 418writeBE4U ( MAGIC_FLOAT , & _wb[_bp + off]); //Write an impossible float 419} 420} 421 422memcpy ( & buff2[off], & buff1[off], 4 ); 423memcpy ( & buff1[off],_encode_ver ? & _wb[_bp + off] : & _rb[_bp + off], 4 ); 424} 425 426//Using the previous four item events as reference, predict a floating point value, and store 427// an otherwise-impossible float if our prediction was correct 428inline void predictJoltItem ( unsigned p, unsigned off, bool verbose = false) { 429predictJolt (p,off,_x_item[p],_x_item_2[p],_x_item_3[p],_x_item_4[p],verbose); 430} 431 432//Using the previous three post-frame events as reference, predict a floating point value, and store 433// an otherwise-impossible float if our prediction was correct 434inline void predictAccelPost ( unsigned p, unsigned off) { 435predictAccel (p,off,_x_post_frame[p],_x_post_frame_2[p],_x_post_frame_3[p]); 436} 437 438//Using the previous three item events as reference, predict a floating point value, and store 439// an otherwise-impossible float if our prediction was correct 440inline void predictAccelItem ( unsigned p, unsigned off, bool verbose = false) { 441predictAccel (p,off,_x_item[p],_x_item_2[p],_x_item_3[p],verbose); 442} 443 444//Using the previous two pre-frame events as reference, predict a floating point value, and store 445// an otherwise-impossible float if our prediction was correct 446inline void predictVelocPre ( unsigned p, unsigned off) { 447predictVeloc (p,off,_x_pre_frame[p],_x_pre_frame_2[p]); 448} 449 450//Using the previous two post-frame events as reference, predict a floating point value, and store 451// an otherwise-impossible float if our prediction was correct 452inline void predictVelocPost ( unsigned p, unsigned off) { 453predictVeloc (p,off,_x_post_frame[p],_x_post_frame_2[p]); 454} 455 456//Using the previous two item events with slot id as reference, predict a floating point value, and store 457// an otherwise-impossible float if our prediction was correct 458inline void predictVelocItem ( unsigned p, unsigned off) { 459predictVeloc (p,off,_x_item[p],_x_item_2[p]); 460} 461 462//Predict the RNG by reading a full (not delta-encoded) frame and 463// counting the number of rolls it takes to arrive at the correct seed 464inline void predictRNG ( unsigned frameoff, unsigned rngoff) { 465const uint32_t MAX_ROLLS = 128 ; //must be a power of 2 466 467//Read true frame from write buffer 468int32_t frame; 469if (_encode_ver) { //Read from write buffer 470frame = readBE4S ( & _wb[_bp + frameoff]); 471} else { //Read from read buffer 472frame = readBE4S ( & _rb[_bp + frameoff]); 473} 474bool rng_is_raw = checkRawRNG (frame); 475if (rng_is_raw) { 476frame ^= RAW_RNG_MASK ; 477} 478 479//Get RNG seed and record number of rolls it takes to get to that point 480if ( MIN_VERSION ( 3 , 6 , 0 )) { //New RNG 481_rng = computeRNGRollback (frame); 482if (_encode_ver) { //Decode 483if (rng_is_raw == 0 ) { //Roll RNG a few times until we get to the desired value 484unsigned rolls = readBE4U ( & _rb[_bp + rngoff]); 485if (rolls < MAX_ROLLS ) { 486for ( unsigned i = 0 ; i < rolls; ++ i) { 487_rng = rollRNGRollback (_rng); 488} 489} else { //Fallback on old RNG rolling method 490for ( unsigned i = MAX_ROLLS ; i < rolls; ++ i) { 491_rng = rollRNGLegacy (_rng); 492} 493} 494writeBE4U (_rng, & _wb[_bp + rngoff]); 495} else { 496writeBE4U (frame, & _wb[_bp + frameoff]); 497} 498} else { //Encode 499unsigned rolls = 0 ; 500unsigned target = readBE4U ( & _rb[_bp + rngoff]); 501for ( uint32_t start_rng = _rng; (start_rng != target) && (rolls < MAX_ROLLS ); ++ rolls) { 502start_rng = rollRNGRollback (start_rng); 503} 504if (rolls < MAX_ROLLS ) { //If we can encode RNG as < 256 rolls, do it 505// std::cout << "Rollback rolled " << rolls << " at byte " << _bp << " frame " << frame << std::endl; 506writeBE4U (rolls, & _wb[_bp + rngoff]); 507_rng = target; 508} else { 509rolls = 0 ; 510for ( uint32_t start_rng = _rng; (start_rng != target) && (rolls < MAX_ROLLS ); ++ rolls) { 511start_rng = rollRNGLegacy (start_rng); 512} 513if (rolls < MAX_ROLLS ) { 514// std::cout << "Legacy rolled " << rolls << " at byte " << _bp << " frame " << frame << std::endl; 515writeBE4U (rolls + MAX_ROLLS , & _wb[_bp + rngoff]); 516} else { //Store the raw RNG value 517// std::cout << "Legacy failed at byte " << _bp << " frame " << frame << std::endl; 518//Load the predicted frame value 519int32_t predicted_frame = readBE4S ( & _wb[_bp + frameoff]); 520//Flip second bit of cached frame number to signal raw rng 521writeBE4S (predicted_frame ^ RAW_RNG_MASK , & _wb[_bp + frameoff]); 522} 523} 524} 525} else { //Old RNG 526if (_encode_ver) { 527unsigned rolls = readBE4U ( & _rb[_bp + rngoff]); 528for ( unsigned i = 0 ; i < rolls; ++ i) { 529_rng = rollRNGLegacy (_rng); 530} 531writeBE4U (_rng, & _wb[_bp + rngoff]); 532} else { //Roll RNG until we hit the target, write the # of rolls 533unsigned rolls, seed = readBE4U ( & _rb[_bp + rngoff]); 534for (rolls = 0 ; _rng != seed; ++ rolls) { 535_rng = rollRNGLegacy (_rng); 536} 537writeBE4U (rolls, & _wb[_bp + rngoff]); 538} 539} 540} 541 542//XOR bytes in the current read buffer with bytes from another buffer 543inline void xorEncodeRange ( unsigned start, unsigned stop, char * buffer) { 544for ( unsigned i = start; i < stop; ++ i) { 545_wb[_bp + i] = _rb[_bp + i] ^ buffer[i]; 546buffer[i] = _encode_ver ? _wb[_bp + i] : _rb[_bp + i]; 547} 548} 549 550inline bool _shuffleItems ( char * iblock_start, unsigned iblock_len, bool shuffle = true) { 551// allocate temporary buffers for shuffling 552// TODO: dynamically reallocate this array later 553unsigned ps = _payload_sizes[Event:: ITEM_UPDATE ]; 554unsigned * icount = new unsigned[ MAX_ITEMS_C ]{ 0 }; 555unsigned * ilast = new unsigned[ MAX_ITEMS_C ]{ 0 }; 556char ** ibuffs = new char * [ MAX_ITEMS_C ]; 557for ( unsigned i = 0 ; i < MAX_ITEMS_C ; ++ i) { 558ibuffs[i] = nullptr ; 559} 560 561// bin item payloads by item ID 562bool success = true; 563bool first_item = true; //apparently the first item isn't always id 0 564unsigned wait = 0 ; 565unsigned ev_total = 0 ; 566unsigned cur_id = 0 ; 567unsigned max_item = 0 ; 568for ( unsigned i = 0 ; i < iblock_len; i += ps) { 569// read the raw (possibly encoded) item id 570uint32_t ouid = readBE4U ( & iblock_start[i + O_ITEM_ID ]); 571// parse out the frame modulus from the item id 572uint32_t uid = encodeFrameIntoItemId (ouid, getFrameModFromItemId (ouid)); 573 574// if we're shuffling, we need to do some counting 575if (shuffle) { 576unsigned encid; 577if (icount[uid] == 0 ) { 578// get the number of elapsed item events since the last new item, 579encid = encodeWaitIntoItemId (ouid,wait); 580// if this isn't item 0, flag this as a new item 581if (!first_item) { 582// ids aren't always consecutive, so count the item id delta since last item 583unsigned skip = 0 ; 584while (icount[uid - skip] == 0 ) { 585++ skip; 586} 587encid = encodeNewItemIntoId (encid,skip); 588} else { 589// if our first item isn't id 0, encode its uid as the skip value 590encid = encodeNewItemIntoId (encid,uid); 591// set first item status to false 592first_item = false; 593} 594 595// set the wait since last new item to 1 596wait = 0 ; 597} else { 598// get the number of elapsed item events since the last time we saw this item 599encid = encodeWaitIntoItemId (ouid,ev_total - ilast[uid]); 600} 601 602// increment the waiting counter 603wait += 1 ; 604 605// update the last time we saw this item with ev_total 606ilast[uid] = ev_total; 607 608// increment the total events 609ev_total += 1 ; 610 611// write the new encoded item back to the block to be copied 612writeBE4U (encid, & iblock_start[i + O_ITEM_ID ]); 613} else { // otherwise, we need to do some unpacking 614// if we've found a new item, increment our cur_id and copy as appropriate into the block 615unsigned skip = getIsNewItem (ouid); 616if (skip) { 617cur_id += skip; 618writeBE4U ( encodeNewItemIntoId (ouid,skip), & iblock_start[i + O_ITEM_ID ]); 619} 620// set uid to the current item 621uid = cur_id; 622} 623 624// allocate a buffer for this item if we don't have one already 625if (ibuffs[uid] == nullptr ) { 626ibuffs[uid] = new char[iblock_len]; 627} 628 629// copy an item payload into each item's individual buffer 630memcpy ( & (ibuffs[uid][ps * icount[uid]]), & iblock_start[i],ps); 631 632// increment number of payloads for this item 633icount[uid] += 1 ; 634 635// keep track of the highest item id we've encountered so far 636if (uid >= max_item) { 637max_item = uid + 1 ; 638} 639} 640 641// if we're shuffling, copy these payloads in item order back into main memory 642if (shuffle) { 643unsigned ind = 0 ; 644for ( unsigned n = 0 ; ind != iblock_len; ++ n) { 645if (icount[n] == 0 ) { 646continue ; 647} 648memcpy ( & iblock_start[ind], & (ibuffs[n][ 0 ]),icount[n] * ps); 649ind += icount[n] * ps; 650} 651} else { // otherwise, gotta do lots of math to unshuffle everything 652ev_total = 0 ; 653unsigned start = 0 ; 654unsigned waited = 0 ; 655unsigned ind = 0 ; 656unsigned * ipos = new unsigned[max_item]{ 0 }; 657// until we've copied every block 658while (ind < iblock_len) { 659bool written = false; 660// from the first active item until the last one 661for ( unsigned n = start; n < max_item; ++ n) { 662// if this item doesn't acutally exist, we're done with this iteration 663if (icount[n] == 0 ) { 664continue ; 665} 666// if we've already copied all of this item over, go on to the next one 667if (ipos[n] == icount[n]) { 668// if this item is the start, move our start forward 669if (n == start) { 670++ start; 671} 672continue ; 673} 674 675// determine whether we've spent an appropriate amount time waiting for previous item events 676bool donewaiting; 677unsigned ouid = readBE4U ( & (ibuffs[n][ipos[n] * ps + O_ITEM_ID ])); 678unsigned wait = getWaitFromItemId (ouid); 679// if this is the first time this item appears, wait time is based off item events since last new item 680if (ipos[n] == 0 ) { 681donewaiting = (wait == waited); 682} else { //otherwise, wait time is based on item events since this item last appeared 683donewaiting = (wait == (ev_total - ilast[n])); 684} 685 686// if we're done waiting, it's time to copy this item back into the buffer 687if (donewaiting) { 688if (ipos[n] == 0 ) { 689// if this is the first time this item has appeared, reset new item wait timer 690waited = 0 ; 691} 692ilast[n] = ev_total; 693// decode the actual item ID without the wait time and put it back into memory 694writeBE4U ( encodeWaitIntoItemId (ouid,n), & ibuffs[n][ipos[n] * ps + O_ITEM_ID ]); 695// copy over to main memory 696memcpy ( & iblock_start[ind], & (ibuffs[n][ipos[n] * ps]),ps); 697// update counters as appropriate 698ind += ps; 699ipos[n] += 1 ; 700waited += 1 ; 701ev_total += 1 ; 702written = true; 703continue ; 704} 705 706// if we've never actually written this item before, we haven't written any items after it 707// either, so we're done here 708if (ipos[n] == 0 ) { 709break ; 710} else { //otherwise, maybe we got rollbacked into this item, so we can continue looking 711continue ; 712} 713} 714if (!written) { 715YIKES ( " Got stuck writing item data" ); 716success = false; 717break ; 718} 719} 720delete[] ipos; //delete position buffer 721} 722 723// delete all the temporary buffers 724for ( unsigned i = 0 ; i < MAX_ITEMS_C ; ++ i) { 725if (ibuffs[i] != nullptr ) { 726delete[] ibuffs[i]; 727} 728} 729delete[] ibuffs; 730delete[] icount; 731delete[] ilast; 732return success; 733} 734 735inline bool _unshuffleItems (char * iblock_start, unsigned iblock_len) { 736return _shuffleItems (iblock_start, iblock_len, false); 737} 738 739inline bool _shuffleColumns (unsigned * offset) { 740truncateColumnWidthsToVersion (); 741char * main_buf = _wb; 742 743// Track the starting position of the buffer 744unsigned s = _game_loop_start; 745unsigned * mem_size = new unsigned[ 1 ]; 746 747// Shuffle message columns 748if (main_buf[s] == Event:: SPLIT_MSG ) { 749* mem_size = offset[ 19 ]; 750_transposeEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_mesg : this -> _cw_mesg ,false); 751s += * mem_size ; 752} 753 754// Shuffle frame start columns 755if (main_buf[s] == Event:: FRAME_START ) { 756* mem_size = offset[ 0 ]; 757_transposeEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_start : this -> _cw_start ,false); 758s += * mem_size; 759} 760 761// Shuffle pre frame columns 762for (unsigned p = 0 ; p < 8 ; ++ p) { 763// True player order: 0,4,1,5,2,6,3,7 764unsigned i = ( 4 * (p% 2 )) + unsigned (p/ 2 ); 765if (main_buf[s] != Event:: PRE_FRAME ) { 766break ; 767} 768* mem_size = offset[ 1 + i]; 769if ( * mem_size == 0 ) { 770continue ; 771} 772_transposeEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_pre : this -> _cw_pre ,false); 773s += * mem_size ; 774} 775 776 777// Shuffle item columns 778if (main_buf[s] == Event:: ITEM_UPDATE ) { 779* mem_size = offset[ 9 ]; 780if ( ENCODE_VERSION_MIN ( 2 )) { 781_shuffleItems( & main_buf[s], * mem_size); 782} 783_transposeEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_item : this -> _cw_item ,false); 784s += * mem_size; 785} 786 787// Shuffle post frame columns 788for (unsigned p = 0 ; p < 8 ; ++ p) { 789// True player order: 0,4,1,5,2,6,3,7 790unsigned i = ( 4 * (p% 2 )) + unsigned (p/ 2 ); 791if (main_buf[s] != Event:: POST_FRAME ) { 792break ; 793} 794* mem_size = offset[ 10 + i]; 795if ( * mem_size == 0 ) { 796continue ; 797} 798_transposeEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_post : this -> _cw_post ,false); 799s += * mem_size ; 800} 801 802// Shuffle frame end columns 803if (main_buf[s] == Event:: BOOKEND ) { 804* mem_size = offset[ 18 ]; 805_transposeEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_end : this -> _cw_end ,false); 806s += * mem_size; 807} 808 809delete[] mem_size; 810 811return true; 812} 813 814inline bool _unshuffleColumns (char * main_buf) { 815truncateColumnWidthsToVersion (); 816// We need to unshuffle event columns before doing anything else 817// Track the starting position of the buffer 818unsigned s = _game_loop_start; 819unsigned * mem_size = new unsigned[ 1 ]{ 0 }; 820 821// Unshuffle message columns 822if (main_buf[s] == Event:: SPLIT_MSG ) { 823_revertEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_mesg : this -> _cw_mesg ); 824s += * mem_size ; 825} 826 827// Unshuffle frame start columns 828if (main_buf[s] == Event:: FRAME_START ) { 829_revertEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_start : this -> _cw_start ); 830s += * mem_size; 831} 832 833// Unshuffle pre frame columns 834for (unsigned i = 0 ; i < 8 ; ++ i) { 835if (main_buf[s] != Event:: PRE_FRAME ) { 836break ; 837} 838_revertEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_pre : this -> _cw_pre ); 839s += * mem_size ; 840} 841 842// Unshuffle item columns 843if (main_buf[s] == Event:: ITEM_UPDATE ) { 844_revertEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_item : this -> _cw_item ); 845if ( ENCODE_VERSION_MIN ( 2 )) { 846_unshuffleItems( & main_buf[s], * mem_size); 847} 848s += * mem_size; 849} 850 851// Unshuffle post frame columns 852for (unsigned i = 0 ; i < 8 ; ++ i) { 853if (main_buf[s] != Event:: POST_FRAME ) { 854break ; 855} 856_revertEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_post : this -> _cw_post ); 857s += * mem_size ; 858} 859 860// Unshuffle frame end columns 861if (main_buf[s] == Event:: BOOKEND ) { 862_revertEventColumns(main_buf,s,mem_size,_debug ? this -> _dw_end : this -> _cw_end ); 863s += * mem_size; 864} 865 866// Reset _game_loop_start 867delete[] mem_size; 868 869// All done! 870return true; 871} 872 873inline bool _transposeEventColumns (char * mem_buf, unsigned mem_off, unsigned * mem_size, const int col_widths[], bool unshuffle = false) { 874bool shuffle = !unshuffle; //Convenience reference to whether we're shuffled 875char * mem_start = & mem_buf[mem_off]; //Convenience reference to proper memory offset 876uint8_t ev_code = mem_start[ 0 ]; //Always an event code regardless of shuffling 877 878// Compute the total size of all columns in the event struct 879unsigned struct_size = 0 ; 880unsigned col_offsets[ 1024 ] = { 0 }; 881for (unsigned i = 0 ; col_widths[i] != 0 ; ++ i) { 882col_offsets[i] = struct_size ; 883if (col_widths[i] > 0 ) { 884struct_size += col_widths[i]; 885} else { //Bit shuffling columns are always one byte 886struct_size += 1 ; 887} 888} 889 890// (Unshuffle only) Compute mem_size from consecutive event codes if necessary 891if (unshuffle) { 892// Ignore the existing mem_size, since it's invalid anyway 893* mem_size = 0 ; 894// While the current byte is still the event code, increment the memory size 895while (mem_start[ * mem_size] == ev_code) { 896++ ( * mem_size); 897} 898// Multiple the memory size by the size of the struct to get the true memory size 899* mem_size *= struct_size; 900} 901 902// Create a new buffer for storing all intermediate data 903char * buff = new char[ * mem_size]; 904 905// Use struct size to get the total number of entries in the event array 906unsigned num_entries = ( * mem_size) / struct_size; 907DOUT3 ( "Shuffling " << num_entries << " entries" ); 908 909// Transpose the columns! 910unsigned b = 0 ; 911for (unsigned i = 0 ; col_widths[i] != 0 ; ++ i) { 912unsigned block_start = mem_off + b ; 913if (col_widths[i] > 0 ) { //Normal column shuffling 914for (unsigned e = 0 ; e < num_entries; ++ e) { 915unsigned mempos = (e * struct_size + col_offsets[i]); 916memcpy( 917& buff[ unshuffle ? mempos : b], 918& mem_start[unshuffle ? b : mempos], 919col_widths[i] 920); 921b += col_widths[i]; 922} 923} else { //If col_widths[i] < 0, then use bitwise column shuffling 924for (int bit = 7 , ib = 7 ; ib >= 0 ; -- ib) { 925for (unsigned e = 0 ; e < num_entries; ++ e) { 926unsigned mempos = (e * struct_size + col_offsets[i]); 927char r_byte = mem_start[shuffle ? mempos : b]; 928char r_bit = (r_byte >> (shuffle ? ib : bit)) & 0x01 ; 929char w_bit = r_bit << (shuffle ? bit : ib); 930buff[shuffle ? b : mempos] ^= w_bit ; 931if (( -- bit) < 0 ) { 932bit = 7 ; 933b += 1 ; 934} 935} 936} 937} 938DOUT3 ( "SHUFFLE " << hex (ev_code) << " column " << i << " at " << block_start << " to " << mem_off + b); 939} 940 941// Copy back the shuffled columns 942memcpy( & mem_start[ 0 ], & buff[ 0 ], * mem_size); 943 944// Clear the memory buffer 945delete[] buff; 946 947// All done! 948return true; 949} 950 951inline bool _revertEventColumns (char * mem_buf, unsigned mem_off, unsigned * mem_size, const int col_widths[]) { 952return _transposeEventColumns (mem_buf,mem_off,mem_size,col_widths,true); 953} 954 955inline unsigned encodeFrameIntoItemId (unsigned item_id, int32_t frame) const { 956return item_id ^ (((frame + 256 ) % 256 ) << 24 ); 957} 958 959inline unsigned getFrameModFromItemId (unsigned item_id) const { 960return (item_id >> 24 ); 961} 962 963// first two bytes from right 964inline unsigned encodeWaitIntoItemId (unsigned item_id, unsigned wait) const { 965return (item_id & 0xFFFF0000 ) ^ ((wait + 65536 ) % 65536 ); 966} 967 968inline unsigned getWaitFromItemId (unsigned item_id) const { 969return item_id % 65536 ; 970} 971 972// 3rd byte from right 973inline unsigned encodeNewItemIntoId (unsigned item_id, unsigned skip) const { 974return (item_id ^ (skip << 16 )); 975} 976 977inline unsigned getIsNewItem(unsigned item_id) const { 978return ((item_id << 8 ) >> 24 ); 979} 980 981inline unsigned encodeDeferInfo(unsigned u16, unsigned defer) const { 982return u16 | (defer << 14 ); 983} 984 985inline unsigned getDeferInfo (unsigned u16) const { 986return (u16 & DEFER_ITEM_BITS ) >> 14 ; 987} 988 989inline unsigned decodeDeferInfo (unsigned u16) const { 990return u16 & (~ DEFER_ITEM_BITS ); 991} 992 993inline int32_t lookAheadToFinalizedFrame (char * mem_start, int32_t ref_frame = 0 ) const { 994unsigned mem_off = 0 ; 995while (mem_start[mem_off] != Event:: BOOKEND ) { 996mem_off += _payload_sizes[ uint8_t (mem_start[mem_off])]; 997} 998return readBE4S( & mem_start[mem_off + O_ROLLBACK_FRAME ]); 999} 1000 1001inline bool ensureAppropriateFilename() { 1002const char * ext = (_encode_ver > 0 ) ? ".slp" : ".zlp" ; 1003if (_outfilename == nullptr ) { 1004std::string fname = std::string(_infilename); 1005_outfilename = new std::string( 1006fname. substr ( 0 , 1007fname. find_last_of ( "." )) + 1008std ::string(ext)); 1009if ( fileExists ( * _outfilename)) { 1010FAIL ( " File " << * _outfilename << " already exists or is invalid" ); 1011return false; 1012} 1013} else { 1014if (! ensureExt (ext,_outfilename -> c_str ())) { 1015FAIL (" File " << * _outfilename << " does not have required extension " << ext); 1016return false; 1017} 1018} 1019return true; 1020} 1021 1022static inline const char * readLegacyGeckoCodes () { 1023static bool _legacy_codes_codes_read = false; 1024static char _legacy_gecko_codes[ 32571 ]; //exact magic number of decompressed bytes 1025if (! _legacy_codes_codes_read) { 1026_legacy_codes_codes_read = true; 1027// decompress the legacy gecko code data 1028std::string decomp = decompressWithLzma( GECKO_LZMA , GECKO_LZMA_LEN ); 1029// Copy buffer from the decompressed string 1030memcpy (_legacy_gecko_codes,decomp. c_str (),decomp. size ()); 1031} 1032return _legacy_gecko_codes; 1033} 1034 1035inline void truncateColumnWidthsToVersion() { 1036if ( MAX_VERSION ( 3 , 11 , 0 )) { 1037this -> _cw_post [ 33 ] = 0 ; //Animation index is invalid 1038this -> _dw_post [ 33 ] = 0 ; 1039} 1040if ( MAX_VERSION ( 3 , 10 , 0 )) { 1041this -> _cw_start [ 3 ] = 0 ; //Scene frame counter is invalid 1042this -> _dw_start [ 3 ] = 0 ; 1043} 1044if ( MAX_VERSION ( 3 , 8 , 0 )) { 1045this -> _cw_post [ 32 ] = 0 ; //Hitlag and onward is invalid 1046this -> _dw_post [ 32 ] = 0 ; 1047} 1048if ( MAX_VERSION ( 3 , 7 , 0 )) { 1049this -> _cw_end [ 2 ] = 0 ; //Rollback frame is invalid 1050this -> _dw_end [ 2 ] = 0 ; 1051} 1052if ( MAX_VERSION ( 3 , 6 , 0 )) { 1053this -> _cw_item [ 19 ] = 0 ; //Item owner is invalid 1054this -> _dw_item [ 19 ] = 0 ; 1055} 1056if ( MAX_VERSION ( 3 , 5 , 0 )) { 1057this -> _cw_post [ 27 ] = 0 ; //Self-induced Air x Speed and onward are invalid 1058this -> _dw_post [ 27 ] = 0 ; 1059} 1060if ( MAX_VERSION ( 3 , 2 , 0 )) { 1061this -> _cw_item [ 15 ] = 0 ; //Item state bits are invalid 1062this -> _dw_item [ 15 ] = 0 ; 1063} 1064if ( MAX_VERSION ( 2 , 1 , 0 )) { 1065this -> _cw_post [ 26 ] = 0 ; //Hurtbox Collision State and onward are invalid 1066this -> _dw_post [ 26 ] = 0 ; 1067} 1068if ( MAX_VERSION ( 2 , 0 , 0 )) { 1069this -> _cw_post [ 16 ] = 0 ; //State bit flags 1 and onward are invalid 1070this -> _dw_post [ 16 ] = 0 ; 1071} 1072if ( MAX_VERSION ( 1 , 4 , 0 )) { 1073this -> _cw_pre [ 19 ] = 0 ; //Pre-frame damage percent is invalid 1074this -> _dw_pre [ 19 ] = 0 ; 1075} 1076if ( MAX_VERSION ( 1 , 2 , 0 )) { 1077this -> _cw_pre [ 18 ] = 0 ; //UCF X-analog is invalid 1078this -> _dw_pre [ 18 ] = 0 ; 1079} 1080} 1081 1082}; 1083 1084} 1085 1086#endif /* COMPRESSOR_H_ */