Gif Player problem

Hi. I'm using Gif Player by Shakugan no Shana, but it doesn't replace frames. I mean, it should look like that:

[IMG]http://www.czn.uj.edu.pl/moodle/pluginfile.php/14445/mod_book/chapter/6009/grafika/gimp/animowany_gif/emotek.gif[/IMG]

but looks like that

[IMG]http://www.czn.uj.edu.pl/moodle/pluginfile.php/14445/mod_book/chapter/6009/grafika/gimp/animowany_gif/emotek_sklad.gif[/IMG]

Spoiler
Code:
=begin  ???????? - GIF?????   ?????????GIF?? ? ?????   ??: ?????         1??? @gs = GIFSprite.new([viewport,[x,[,y,[loop_counts]]]])           ??GIF?????                   2????? @gs.bitmap = "gif_filename" ? ????????               3??? @gs.loop_counts = n                         ???????-1??????(???)?0??????                   [email protected] = x,@gs.y = y,@gs.z = z ?????????   ???1???????????????????????????????????         ??????????????????? GIFSprite.TmpFileclear ????               ???               2????? GIFSprite.pre_load(filename_arr) ??????????                ???v1.0         ???????? =end#==============================================================================# ? System#------------------------------------------------------------------------------# ?????????? ?#==============================================================================module System   #--------------------------------------------------------------------------  # ? ????  #--------------------------------------------------------------------------  module_function   #--------------------------------------------------------------------------  # ? API????  #--------------------------------------------------------------------------  WinExec = Win32API.new("kernel32","WinExec",'pi','i')  #--------------------------------------------------------------------------  # ? ?????????????  #  filename ?????????  #  #  +a -a    ?????? ?? ??  #  +r -r    ?????? ?? ??  #  +s -s    ?????? ?? ??  #  +h -h    ?????? ?? ??  #--------------------------------------------------------------------------  def attrib(filename,*args)    if args.empty?      astr = `attrib #{filename}`      attri_arr = Array.new      astr = astr.split(/:/)[0]      astr = astr[0,astr.size - 1]      astr.gsub!(/ /,"")      return astr.split(//)    else      cmdline = ""      for cmdchar in args        cmdchar.downcase!        next if cmdline.include? cmdchar        if ["+a","-a","+r","-r","+s","-s","+h","-h"].include? cmdchar          cmdline += " " + cmdchar        end      end      cmdline += " "      result = WinExec.call("attrib #{cmdline}#{filename}",0)      if result < 31        return      end    end  end end#==============================================================================# ? GIF#------------------------------------------------------------------------------# ?????GIF??????? ?#==============================================================================module GIF   # ????  SIZE_GIFH = 6   SIZE_GIFS = 7   SIZE_GIFI = 9   SIZE_GIFC = 6   SIZE_GIFP = 13   SIZE_GIFA = 12   CODE_MASK = [0x0000,               0x0001,0x0003,0x0007,0x000f,               0x001f,0x003f,0x007f,0x00ff,               0x01ff,0x03ff,0x07ff,0x0fff]   INC_TABLE = [8,8,4,2,0]   BGN_TABLE = [0,4,2,1,0]   # ?????  Dir.mkdir("GIF") unless Dir["*"].include?("GIF")   # ????  module_function   #--------------------------------------------------------------------------  # ? ??gif??  #--------------------------------------------------------------------------  def analyze_gif    @old_dir = Dir.pwd    Dir.chdir("GIF")    @total_gif = []    for g in Dir["*"]      suf = g.split(/\./)      if suf[1].is_a?(String) and suf[1].downcase == "gif"        @total_gif.push(g)        Dir.mkdir(suf[0]) unless Dir["*"].include? suf[0]      end    end    @total_gif.each{|file| self.readdata(file)}    Dir.chdir(@old_dir)    p '?????????????'    exit  end   #--------------------------------------------------------------------------  # ? ???????????@gif_infos?????nil  #--------------------------------------------------------------------------  def readdata(filename)    # ???????????    tmp_filename = File.basename(filename,".*")    unless Dir["~TEMP/#{tmp_filename}_infos.fmd"].empty?      begin        giffr = open("~TEMP/#{tmp_filename}_infos.fmd","rb")        tmp_infos = Marshal.load(giffr)        giffr.close        if Dir["~TEMP/#{tmp_filename}_*.png"].size == tmp_infos.total_frames          return tmp_infos        end      rescue      end    end    # ?????    self.initial_var(filename)    # ????    begin      @f = open(filename,"rb")      # ?????      self.read_gifh      # ?????????      self.read_gifs      # ???????      @temp = @f.read(1)[0]      # ???????????      while true        if @temp == 0x2c          # ???????          self.read_gifi        end        if @temp == 0x21          # ???????          self.read_gife        end        if @temp == 0x3b          break        end        # ???????        @temp = @f.read(1)[0]      end      # ? ??????      @gif_infos.total_frames = @frame_count      # ? ????????      giffw = open("~TEMP/#{@filename}_infos.fmd","wb")      Marshal.dump(@gif_infos,giffw)      giffw.close    rescue      return nil    ensure      @f.close    end    return @gif_infos  end   #--------------------------------------------------------------------------  # ? ?????  #--------------------------------------------------------------------------  def initial_var(filename)    # ? ????????    @gif_infos = GIFSprite::Infos.new    # ????    @frame_count = 0    @f = nil    @temp = nil    # ?????    @filename = File.basename(filename,".*")  end   #--------------------------------------------------------------------------  # ? ?????  #--------------------------------------------------------------------------  def read_gifh    @gifh = @f.read(SIZE_GIFH)    if @gifh[0,3] != "GIF"      raise "??GIF??!"    end    if @gifh[3,3] != "87a" and @gifh[3,3] != "89a"      raise "??????!"    end  end   #--------------------------------------------------------------------------  # ? ?????????  #--------------------------------------------------------------------------  def read_gifs    @gifs = @f.read(SIZE_GIFS).unpack("S2C3")    # ???????    @_pal_bits = (@gifs[2] & 7) + 1    # ? ??????    @gif_infos.width = @gifs[0]    # ? ??????    @gif_infos.height = @gifs[1]    # ????????    if @gifs[2] >> 7 == 1      # ???????      @g_pal_size = 3 * (1 << @_pal_bits)      # ?????????      @g_pal = @f.read(@g_pal_size).unpack("C*")    end  end   #--------------------------------------------------------------------------  # ? ???????  #--------------------------------------------------------------------------  def read_gifi    # ???????    @gifi = @f.read(SIZE_GIFI).unpack("S4C")    # ? ?????????    @gif_fd = GIFSprite::Infos::FrameData.new if @gif_fd.nil?    # ? ?????    @gif_fd.offset_x = @gifi[0]    @gif_fd.offset_y = @gifi[1]    # ???????    @_width = @gifi[2]    @_height = @gifi[3]    # ???????    @l_pal = nil    # ????????    if @gifi[4] >> 7 == 1      # ???????      @_pal_bits = (@gifi[4] & 7) + 1      # ???????      @l_pal_size = 3 * (1 << @_pal_bits)      # ?????????      @l_pal = @f.read(@l_pal_size).unpack("C*")    end    # ??????    @_lace = (@gifi[4] >> 6) & 1    # ???????    @_pal_bits = @_pal_bits == 1 ? 1 : (@_pal_bits <= 4 ? 4 : 8)    # ??????    @_width_bytes = (((@_width * @_pal_bits) + 31) >> 5) << 2    # ????????    self.read_lzw_data    # ? ??GIF???    @gif_infos.frame_data[@frame_count - 1] = @gif_fd    # ? ?????    @gif_fd = nil  end   #--------------------------------------------------------------------------  # ? ????????  #--------------------------------------------------------------------------  def read_lzw_data    # ???    lzw_mincodelen = @f.read(1)[0]    # ??? 1    @frame_count += 1    # ?????    image_data = ""    # ???    blocksize = @f.read(1)[0]    while blocksize > 0      image_data += @f.read(blocksize)      blocksize = @f.read(1)[0]    end    # ????    self.dump_imgs(image_data,lzw_mincodelen)  end   #--------------------------------------------------------------------------  # ? ?????  #--------------------------------------------------------------------------  def read_gife    label = @f.read(1)[0]    case label    when 0xf9 # ???????      @gifc = @f.read(SIZE_GIFC).unpack("C2SC2")      # ? ???????      @gif_fd = GIFSprite::Infos::FrameData.new         # ? ????? ????      @gif_fd.delay_time = @gifc[2]      # ? ??????????      @gif_fd.disposal_method = (@gifc[1] & 28) >> 2      # ??????      @_trans_index = nil      if @gifc[1] & 1 > 0        @_trans_index = @gifc[3]      end    when 0x01 # ???????      @gifp = @f.read(SIZE_GIFP).unpack("CS4C4")      blocksize = @f.read(1)[0]      while blocksize > 0        @f.read(blocksize)        blocksize = @f.read(1)[0]      end    when 0xfe # ???????      blocksize = @f.read(1)[0]      while blocksize > 0        @f.read(blocksize)        blocksize = @f.read(1)[0]      end    when 0xff # ???????      @gifa = @f.read(SIZE_GIFA).unpack("C*")      blocksize = @f.read(1)[0]      while blocksize > 0        @f.read(blocksize)        blocksize = @f.read(1)[0]      end    end  end   #--------------------------------------------------------------------------  # ? ?????  #--------------------------------------------------------------------------  def set_pal    @_pal = []    if @l_pal != nil      @_pal = @l_pal    elsif @g_pal != nil      @_pal = @g_pal    else      for i in 0...1 << @_pal_bits        @_pal.push i,i,i      end    end  end   #--------------------------------------------------------------------------  # ? ??????  #--------------------------------------------------------------------------  def dump_imgs(image_data,lze_len)    @image_data = image_data.unpack("C*")       self.set_pal       @png_data = []    @stack = []    @images = []       @prefix = []    @suffix = []       @bitcount = @_pal_bits    @widthcount = 0       @left_bits = 0x00    @current_bits = lze_len + 0x01       @lzw_clear = 1 << lze_len    @lzw_eoi = @lzw_clear + 1    @nowtablendx = @lzw_clear + 2    @toptablendx = 1 << @current_bits       @wdata = 0    @wcode = 0    @oldcode = 0xffff    @row_num = 0    @tempchar = 0x00    @pass = 0x00    @firstchar = 0    @tempndx = 0    # ??????    self.read_byte    # ??@lzw_eoi???    while @wcode != @lzw_eoi      # @lzw_clear?      if @wcode == @lzw_clear        for i in 0...@lzw_clear          @prefix[i] = 0xffff          @suffix[i] = i        end        for i in @nowtablendx...4096          @prefix[i] = 0xffff          @suffix[i] = 0x00        end        @current_bits = lze_len + 0x01        @nowtablendx = @lzw_clear + 2        @toptablendx = 1 << @current_bits        @oldcode = 0xffff        # ??????        self.read_byte        if @wcode != @lzw_eoi          while @prefix[@wcode] != 0xffff            @stack.push(@suffix[@wcode])            @wcode = @prefix[@wcode]          end          @stack.push(@suffix[@wcode])          @firstchar = @stack[-1]          # ??????          self.output_data        end      else        if @wcode < @nowtablendx          @tempndx = @wcode        else          @tempndx = @oldcode          @stack.push(@firstchar)        end        while @prefix[@tempndx] != 0xffff          @stack.push(@suffix[@tempndx])          @tempndx = @prefix[@tempndx]        end        @stack.push(@suffix[@tempndx])        @firstchar = @stack[-1]        @prefix[@nowtablendx] = @oldcode        @suffix[@nowtablendx] = @firstchar        @nowtablendx += 1        if @nowtablendx == @toptablendx and @current_bits < 12          @current_bits += 1          @toptablendx = 1 << @current_bits        end        # ??????        self.output_data      end      @oldcode = @wcode      # ??????      self.read_byte    end    Graphics.update    # ??png?    self.make_png  end  #--------------------------------------------------------------------------  # ? ???????  #--------------------------------------------------------------------------  def read_byte    while @left_bits < @current_bits      @next_char = @image_data.shift      @wdata |= (@next_char << @left_bits)      @left_bits += 0x08    end    @wcode = @wdata & CODE_MASK[@current_bits]    @wdata >>= @current_bits    @left_bits -= @current_bits  end   #--------------------------------------------------------------------------  # ? ??????  #--------------------------------------------------------------------------  def output_data    while [email protected]?      @tempchar |= (@stack.pop << (8 - @bitcount))      if @bitcount == 8        @images.push(@tempchar)        @tempchar = 0x00        @bitcount = @_pal_bits      else        @bitcount += @_pal_bits      end      @widthcount += 1      if @widthcount == @_width        if @bitcount != @_pal_bits          @images.push(@tempchar)          @tempchar = 0x00          @bitcount = @_pal_bits        end        @png_data[@row_num] = @images.clone        @images.clear        if @_lace > 0          @row_num += INC_TABLE[@pass]          if @row_num >= @_height            @pass += 1            @row_num = BGN_TABLE[@pass]          end        else          @row_num += 1        end        @widthcount = 0      end    end  end   #--------------------------------------------------------------------------  # ? ??png??  #--------------------------------------------------------------------------  def make_png    fp = open("~TEMP/#@filename" + sprintf("_%02d",@frame_count)+".png","wb")    fp.write(self.make_png_header)    fp.write(self.make_png_ihdr)    fp.write(self.make_png_plte) if @_trans_index.nil?    fp.write(self.make_png_idat)    fp.write(self.make_png_iend)    fp.close  end     #--------------------------------------------------------------------------  # ? png???  #--------------------------------------------------------------------------  def make_png_header    return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")  end   #--------------------------------------------------------------------------  # ? png????  #--------------------------------------------------------------------------  def make_png_ihdr    ih_size = [13].pack("N")    ih_sign = "IHDR"    ih_width = [@_width].pack("N")    ih_height = [@_height].pack("N")    if @_trans_index != nil      ih_bit_depth = [@_pal_bits > 8 ? 16 : 8].pack("C")      ih_color_type = [6].pack("C")    else      ih_bit_depth = [@_pal_bits].pack("C")      ih_color_type = [3].pack("C")    end    ih_compression_method = [0].pack("C")    ih_filter_method = [0].pack("C")    ih_interlace_method = [0].pack("C")    string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +             ih_compression_method + ih_filter_method + ih_interlace_method    ih_crc = [Zlib.crc32(string)].pack("N")    return ih_size + string + ih_crc  end   #--------------------------------------------------------------------------  # ? png????  #--------------------------------------------------------------------------  def make_png_plte    pl_size = [@_pal.size].pack("N")    pl_sign = "PLTE"    pl_data = @_pal.pack("C*")    pl_crc = [Zlib.crc32(pl_sign + pl_data)].pack("N")    return pl_size + pl_sign + pl_data + pl_crc  end   #--------------------------------------------------------------------------  # ? png???  #--------------------------------------------------------------------------  def make_png_idat    lz_data = []    if @_trans_index != nil      for i in 0...@png_data.size        lz_data.push 0        for j in @png_data[i]          if j == @_trans_index            lz_data.push @_pal[j*3],@_pal[j*3+1],@_pal[j*3+2],0          else            lz_data.push @_pal[j*3],@_pal[j*3+1],@_pal[j*3+2],255          end        end      end    else      for i in 0...@png_data.size        lz_data.push 0        lz_data += @png_data[i]      end    end    id_data = Zlib::Deflate.deflate(lz_data.pack("C*"),9)    id_size = [id_data.size].pack("N")    id_sign = "IDAT"    id_crc = [Zlib.crc32(id_sign + id_data)].pack("N")    return id_size + id_sign + id_data + id_crc  end   #--------------------------------------------------------------------------  # ? png ???  #--------------------------------------------------------------------------  def make_png_iend    ie_size = [0].pack("N")    ie_sign = "IEND"    ie_crc = [Zlib.crc32(ie_sign)].pack("N")    return ie_size + ie_sign + ie_crc  end end#==============================================================================# ? Graphics#------------------------------------------------------------------------------# ???????? ?#==============================================================================class << Graphics  #--------------------------------------------------------------------------  # ? ???????????  #--------------------------------------------------------------------------  unless method_defined? :origin_update    alias origin_update update    def update_critical      Thread.critical = true      origin_update      Thread.critical = false    end    Thread.new{loop{Graphics.update_critical;sleep(9)}}  end   #--------------------------------------------------------------------------  # ? ?????  #--------------------------------------------------------------------------  @@gif_sprites = Array.new   #--------------------------------------------------------------------------  # ? ??GIF????  #--------------------------------------------------------------------------  def add(gs)    @@gif_sprites << gs  end   #--------------------------------------------------------------------------  # ? ??GIF????  #--------------------------------------------------------------------------  def del(gs)    @@gif_sprites.delete gs  end  #--------------------------------------------------------------------------  # ? ????  #--------------------------------------------------------------------------  def update    update_critical    @@gif_sprites.each{|gs| gs.update}  end end#==============================================================================# ? GIFSprite#------------------------------------------------------------------------------# ?GIF?????? ?#==============================================================================class GIFSprite   #============================================================================  # ? GIFSprite::Infos  #----------------------------------------------------------------------------  # ?GIF????? ?  #============================================================================  class Infos       #------------------------------------------------------------------------    # ? ??????    #------------------------------------------------------------------------    attr_accessor :total_frames    attr_accessor :width    attr_accessor :height    attr_accessor :frame_data       #------------------------------------------------------------------------    # ? ???    #------------------------------------------------------------------------    def initialize      @total_frames = 0      @width = 0      @height = 0      @frame_data = Array.new    end       #==========================================================================    # ? GIFSprite::Infos::FrameData    #--------------------------------------------------------------------------    # ?GIF??????? ?    #==========================================================================    class FrameData           #----------------------------------------------------------------------      # ? ??????      #----------------------------------------------------------------------      attr_accessor :offset_x      attr_accessor :offset_y      attr_accessor :delay_time      attr_accessor :disposal_method           #----------------------------------------------------------------------      # ? ???      #----------------------------------------------------------------------      def initialize        @offset_x = 0        @offset_y = 0        @delay_time = 0        @disposal_method = 0      end         end     end   #--------------------------------------------------------------------------  # ? ???????????  #--------------------------------------------------------------------------  unless Dir["*"].include?("~TEMP")    Dir.mkdir("~TEMP")    System.attrib("~TEMP","+h","+s")  end   #--------------------------------------------------------------------------  # ? ?????  #--------------------------------------------------------------------------  def self.TmpFileclear    begin      Dir["~TEMP/*"].each{|filename| File.delete filename}    rescue    end  end   #--------------------------------------------------------------------------  # ? ?????  #--------------------------------------------------------------------------  def self.pre_load(filename_arr)    filename_arr.each{|fn| GIF.readdata(fn)}  end   #--------------------------------------------------------------------------  # ? ??????  #--------------------------------------------------------------------------  attr_accessor :x  attr_accessor :y  attr_reader   :z  attr_accessor :loop_counts  attr_accessor :viewport   #--------------------------------------------------------------------------  # ? ????  #--------------------------------------------------------------------------  def self.new(viewport = nil,x = 0,y = 0,loop_counts = -1)    obj = super()    obj.viewport = viewport    obj.x = x    obj.y = y    obj.loop_counts = loop_counts    Graphics.add(obj)    obj  end   #--------------------------------------------------------------------------  # ? ??????  #--------------------------------------------------------------------------  def bitmap    @gif_infos  end   #--------------------------------------------------------------------------  # ? ???????  #--------------------------------------------------------------------------  def bitmap=(filename)    @gif_infos = GIF.readdata(filename)    if @gif_infos != nil      @sp_arr = Array.new      basename = File.basename(filename,".*")      for i in 0...@gif_infos.total_frames        sp   = Sprite.new(@viewport)        sp.bitmap = Bitmap.new(sprintf("~TEMP/#{basename}_%02d.png",i + 1))        sp.visible = i == 0        sp.x = @gif_infos.frame_data[i].offset_x        sp.y = @gif_infos.frame_data[i].offset_y        @sp_arr << sp      end      @update_frame_count = 0      @current_show_frame = 0      @next_frame_counts =      (@gif_infos.frame_data[0].delay_time * Graphics.frame_rate / 100)    end  end   #--------------------------------------------------------------------------  # ? ??x=  #--------------------------------------------------------------------------  def x=(x)    if @gif_infos.nil?      @x = 0      return    end    @x = x    for i in 0...@gif_infos.total_frames      @sp_arr[i].x = @gif_infos.frame_data[i].offset_x + @x    end  end   #--------------------------------------------------------------------------  # ? ??y=  #--------------------------------------------------------------------------  def y=(y)    if @gif_infos.nil?      @y = 0      return    end    @y = y    for i in 0...@gif_infos.total_frames      @sp_arr[i].y = @gif_infos.frame_data[i].offset_y + @y    end  end   #--------------------------------------------------------------------------  # ? ??z=  #--------------------------------------------------------------------------  def z=(z)    if @gif_infos.nil?      @z = 0      return    end    @z = z    for i in 0...@gif_infos.total_frames      @sp_arr[i].z = @z    end  end   #--------------------------------------------------------------------------  # ? ????  #--------------------------------------------------------------------------  def width    return @gif_infos.nil? ? 0 : @gif_infos.width  end   #--------------------------------------------------------------------------  # ? ????  #--------------------------------------------------------------------------  def height    return @gif_infos.nil? ? 0 : @gif_infos.height  end   #--------------------------------------------------------------------------  # ? ????  #--------------------------------------------------------------------------  def dispose    Graphics.del(self)    @sp_arr.each{|sp|      sp.bitmap.dispose      sp.dispose    }    @sp_arr.clear    @gif_infos = nil  end   #--------------------------------------------------------------------------  # ? ????  #--------------------------------------------------------------------------  def update    if @gif_infos.nil?      return    end    @update_frame_count += 1    if @update_frame_count >= @next_frame_counts      @current_show_frame = (@current_show_frame + 1) % @gif_infos.total_frames      case @gif_infos.frame_data[@current_show_frame - 1].disposal_method      when 0 # ???             when 1 # ???????             when 2 # ??????        @sp_arr[@current_show_frame - 1].visible = false      when 3 # ??? = =             end      @sp_arr[@current_show_frame].visible = true      if @current_show_frame == 0        @loop_counts -= 1 if @loop_counts > 0        if @loop_counts == 0          self.dispose          return        end        for i in 0...@sp_arr.size          @sp_arr[i].visible = i == @current_show_frame        end      end      @update_frame_count = 0      @next_frame_counts = (@gif_infos.frame_data[@current_show_frame].\      delay_time * Graphics.frame_rate / 100)    end  end end
I've moved this thread to Script Support. Please be sure to post your threads in the correct forum next time. Thank you.

Scripts is for presenting scripts you've written yourself.

Please put the script in spoiler tags or (even better) link to the original post of the script instead of reposting here

Attention all: This is an RMXP script
Oh, sorry. I'm new here.

I got this script from someone, original (i think Japanese) website is down, I couldn't find it anywhere else.

Yup, I didn't mention that it's for XP (wrote it somewhere in RMXP sub-forum).
Okey, I modified Animated Battlers script from ToA and it's working correctly. Topic can be closed.
If you want a topic to be closed, please Report your opening post (the Report button is bottom right, next to the Multiquote button) and ask for it to be closed.  The mod for the forum might not see your post, but will see the Report.

Thanks.

Original thread: https://forums.rpgmakerweb.com/threads/gif-player-problem.42268/