Advertisement
mzxrules

Untitled

Mar 7th, 2020
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.                    
  4. public class Program
  5. {
  6.     public enum InitChainType
  7.     {
  8.         ICHAIN_U8               = 0x00, //  sets byte
  9.         ICHAIN_S8               = 0x01, //  
  10.         ICHAIN_U16              = 0x02, //  sets short
  11.         ICHAIN_S16              = 0x03, //  
  12.         ICHAIN_U32              = 0x04, //  sets word
  13.         ICHAIN_S32              = 0x05, //  
  14.         ICHAIN_F32              = 0x06, //  sets float
  15.         ICHAIN_F32_DIV1000      = 0x07, //  sets float divided by 1000
  16.         ICHAIN_VEC3F            = 0x08, //  sets Vec3f members
  17.         ICHAIN_VEC3F_DIV1000    = 0x09, //  sets Vec3f members divided by 1000
  18.         ICHAIN_VEC3S            = 0x0A, //  sets Vec3s members
  19.         ICHAIN_0B,
  20.         ICHAIN_0C,
  21.         ICHAIN_0D,
  22.         ICHAIN_0E,
  23.         ICHAIN_0F,
  24.     }
  25.    
  26.     public static uint[] test = new uint[] { 0xB0F41C20, 0xB0F80320, 0x30FC05DC};
  27.     public static void Main(string[] args)
  28.     {
  29.         List<string> strs = new List<string>();
  30.         foreach (var item in test)
  31.         {
  32.             strs.Add(GetChain(item));
  33.         }
  34.         Console.WriteLine( string.Join(",\n",strs));
  35.     }
  36.     public static string GetChain(uint val)
  37.     {
  38.         bool cont = ((val >> 31) & 1) > 0;
  39.         InitChainType t = (InitChainType)((val >> 27) & 0x0F);
  40.         uint off = (val >> 16) & 0x7FF;
  41.         int v = (int)val & 0xFFFF;
  42.        
  43.         switch(t)
  44.         {
  45.             case InitChainType.ICHAIN_U8: v = (byte)v; break;
  46.             case InitChainType.ICHAIN_S8: v = (sbyte)v; break;
  47.             case InitChainType.ICHAIN_U16: v = (ushort)v; break;
  48.             case InitChainType.ICHAIN_S16: v = (short)v; break;
  49.             case InitChainType.ICHAIN_U32: goto case InitChainType.ICHAIN_U16;
  50.             case InitChainType.ICHAIN_S32: goto case InitChainType.ICHAIN_S16;
  51.             default:
  52.                 goto case InitChainType.ICHAIN_S16;
  53.         }
  54.        
  55.         string contStr = (cont) ? "ICHAIN_CONTINUE": "ICHAIN_STOP";
  56.        
  57.         return $"{t}({off:X}, {v}, {contStr})";
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement