Skip to content

TWiZA

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 48 total)
  • Author
    Posts
  • #191084
    TWiZA
    Member

    Yes, nice idea.
    and about this:

    public string[] getAllRoomsAndPms()
    {
    // Confusing static method ... hmm... but okay for now
    TwzPaltalkClass.refreshRooms();
    return TwzPaltalkClass.getRooms();
    }

    refreshRooms() indeed this has no business being outside. You can call it inside getRooms() and make a private static instead of public static.

    #191086
    TWiZA
    Member

    @NVYE wrote:

    TWiZA … I’ll use your library to make a Video Tutorial … I hope you don’t mind … I will give you full credit toward it.

    of course. It would be good if someone shows how to use it or even improve it since I lack time to do it 😉
    Thanks.

    #191089
    TWiZA
    Member

    @Chike wrote:

    This should never happen though, if you are not in the room it means the window is closed, if you are in the room the count cannot be zero.

    ameen

    and yeah NVYE, in general it depends on how you would use the function.
    fun fact, since C# is new to me, I’m still influenced by VB’s sloppiness and C/C++’s rigidity 😀

    #191093
    TWiZA
    Member

    I agree that is proper coding. However, one of the reasons (other than being lazy lol) that I omitted handling exceptions in this example is to help others understand. I Didn’t want surcharge the code. if there are too many “IFs” and conditions some people may get lost. In fact, that is a true story, when I started looking online for examples of how to steal another process’s memory, I got lost and confused.
    Thanks for time 🙂
    ps: there is just one typo here :

    uf (processHandle == IntPtr.Zero) return null; // error, no match
    #191095
    TWiZA
    Member

    (Chike you are making me revise my code after I decides that I’m done with it. nd with this method of paltalk programming in general 🙂 )

    @TWiZA wrote:

    Another thing is the use of strBuffer.Clear, there is simply no need for it if a new one is always created, and for better efficiency, create the StringBuilder with MAX_LVMSTRING outside the loop, and set it’s length in each loop.

    strBuffer should be declared outside the loop indeed.
    aAso (strLength – 1) was a makeshift to avoid getting garbage at the end of my string. But I kind of omitted that since everything was working. I’ve done quite a bit of debugging since this my first C# code. In fact, the whole thing is a sort of draft and I know there are more flaws.

    Thanks for pointing them out to me and to others who are reading.

    This looks better I think:

    public string[] getUserNames()
    
    {
    int lvCount = SendMessage(_listHwnd, LVM_GETITEMCOUNT, IntPtr.Zero, IntPtr.Zero);
    
    if (lvCount == 0) return null;
    
    int ProcessID = 0;
    
    string[] userNameArray = new string[lvCount];
    LVITEM lvLocalItem = new LVITEM();
    
    GetWindowThreadProcessId(_listHwnd, out ProcessID);
    
    IntPtr processHandle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, ProcessID);
    
    //ListViewItem
    lvLocalItem.mask = LVIF_TEXT;
    lvLocalItem.iSubItem = SYSVIEWLIST_SUBITEM;
    lvLocalItem.pszText = VirtualAllocEx(processHandle, IntPtr.Zero, MAX_LVMSTRING, MEM_COMMIT, PAGE_READWRITE); // alloc memory for the username string
    lvLocalItem.cchTextMax = MAX_LVMSTRING;
    
    IntPtr lvMemItem = VirtualAllocEx(processHandle, IntPtr.Zero, Marshal.SizeOf(lvLocalItem), MEM_COMMIT, PAGE_READWRITE); // alloc memory for my whole ListviewItem
    
    IntPtr tmpOut = (IntPtr)0; // null pointer to use with Read/Write process memory (last parameter)
    
    WriteProcessMemory(processHandle, lvMemItem, ref lvLocalItem, Marshal.SizeOf(lvLocalItem), out tmpOut);
    
    StringBuilder strBuffer = new StringBuilder();
    
    for( int i = 0; i < lvCount; i++)
    {
    strBuffer.Length = SendMessage(_listHwnd, LVM_GETITEMTEXT, i, lvMemItem);
    
    ReadProcessMemory(processHandle, lvLocalItem.pszText, strBuffer, strBuffer.Length, out tmpOut);
    
    userNameArray = strBuffer.ToString();
    
    }
    
    VirtualFreeEx(processHandle, lvLocalItem.pszText, 0, MEM_RELEASE);
    VirtualFreeEx(processHandle, lvMemItem, 0, MEM_RELEASE);
    CloseHandle(processHandle);
    
    return userNameArray;
    }

     

    #190673
    TWiZA
    Member

    Good luck, the fun is there. when you get it and you finish your program you are done. it is not fun anymore. 😉 You got find sometime new or harder.

    #191097
    TWiZA
    Member

    I agree. As I stated in the notes, there is no exception or error management in this code. it’s meant to be an example of OOP and some paltalk functions. It is kind of Take ‘n Bake code lol. The class written in VB used in my programs is written with better practices. Thanks for your remarks 🙂

    #190675
    TWiZA
    Member

    a typo:

    Color2(0) = .Color2.R
    Color2(1) = .Color2.G
    Color2(2) = .Color2.G <— should be Color2.B

    #190676
    TWiZA
    Member

    You are very welcome. Enjoy your coding!

    #190678
    TWiZA
    Member

    I don’t know why this sudden generosity about sharing my code…
    This the color fade function I use in TixT. I wrote it 4 years ago and it doesn’t look pretty 😆

    First of all, the function take a structure as parameter and return a string (rtf code).

    so you will need this:

    Public Structure TRTF
    Public Bold As Boolean
    Public Under As Boolean
    Public Italic As Boolean
    Public Size As Byte
    Public Color As Color
    Public Color2 As Color
    Public Text As String
    End Structure

    If you are not familiar with RTF codes (Rich Text Format) and Colors RGB, I strongly suggest to google them up. If you just copy and past without understanding (or at least trying) you will never learn.

    The messy part in the middle of the function that has no comment is pure math and logic. What I did is I take the positive difference between R G B values of the colors and divided by the length of my text ( Paltalk only allows 7 colors in one post, so 7 is the maximum I can divide by) that gives me the value by which I will increase from color1 to color2 to get the fade (Df variable in my code).

    The loop builds my R G B arrays tha I will use to generate an RTF color table.
    The rest of the code is just like generating html but it’s RTF codes: example bold, italic, etc…

     

    Public Shared Function sRTF_Fade(ByVal T As TRTF) As String
    
    Dim Rtf1 As String = "{rtf1ansiansicpg1252deff0deflang1036{fonttbl{f0fnilfcharset0 Tahoma;}}" '& vbCrLf
    
    Dim ColorTB As String = "{colortbl "
    
    Dim Color1(2) As Byte
    Dim Color2(2) As Byte
    
    With T
    
    Color1(0) = .Color.R 'breaking down the colors into Red Green Blue RGB
    Color1(1) = .Color.G
    Color1(2) = .Color.B
    
    Color2(0) = .Color2.R
    Color2(1) = .Color2.G
    Color2(2) = .Color2.G
    
    Dim NumberOfColors As Integer = .Text.Length ' length of the string
    Dim Df As Integer
    
    If NumberOfColors > 7 Then NumberOfColors = 7 'paltalk doesn't allow more than seven colors in one post
    
    Dim Tb(NumberOfColors - 1) As Byte 'the array to hold our color table of 7 colors or less
    
    Dim R(NumberOfColors - 1) As Byte, G(NumberOfColors - 1) As Byte, B(NumberOfColors - 1) As Byte
    
    For i As Byte = 0 To 2
    
    Select Case Color1(i)
    
    Case Is > Color2(i)
    
    Df = (Color1(i) - Color2(i)) / (NumberOfColors + 1)
    Tb(0) = Color1(i)
    For j As Integer = 2 To NumberOfColors - 1
    Tb(j - 1) = Color1(i) - (Df * (j - 1))
    Next
    Tb(NumberOfColors - 1) = Color2(i)
    
    Case Is < Color2(i)
    
    Df = (Color2(i) - Color1(i)) / (NumberOfColors + 1)
    Tb(0) = Color1(i)
    For j As Integer = 2 To NumberOfColors - 1
    Tb(j - 1) = Color1(i) + (Df * (j - 1))
    Next
    Tb(NumberOfColors - 1) = Color2(i)
    
    Case Is = Color2(i)
    
    For j = 0 To NumberOfColors - 1
    Tb(j) = Color1(i)
    Next
    
    End Select
    
    Select Case i
    Case 0 : Tb.CopyTo(R, 0) 'red
    Case 1 : Tb.CopyTo(G, 0) 'green
    Case 2 : Tb.CopyTo(B, 0) 'blue
    End Select
    
    Next
    
    Rtf1 &= "{colortbl "
    
    For i As Integer = 0 To NumberOfColors - 1
    Rtf1 &= ";red" & R(i).ToString & "green" & G(i).ToString & "blue" & B(i).ToString
    Next
    
    Rtf1 &= ";}" '& vbCrLf
    Rtf1 &= "viewkind4uc1pard" & IIf(.Bold, "b", "") & IIf(.Italic, "i", "") & IIf(.Under, "ul", "") & "fs" & CStr(.Size * 2)
    
    Dim x As Integer = 0
    If NumberOfColors < 7 Then
    For Each Ch As Char In .Text.ToCharArray
    x += 1
    Rtf1 &= "cf" & x.ToString & " " & Ch
    Next
    Else
    Dim nw As Integer = .Text.Length / 8
    For i As Integer = 0 To 8
    
    Try
    Rtf1 &= "cf" & (i + 1).ToString & " " & .Text.Substring(i * nw, nw)
    
    Catch eX As Exception
    Debug.Print(eX.Message)
    Rtf1 &= "cf" & (i + 1).ToString & " " & .Text.Substring(CInt(IIf((i * nw) > .Text.Length, .Text.Length, (i * nw)))) 'Right(.Text, .Text.Length - (i * nw) + 2)
    
    End Try
    Next
    End If
    End With
    Rtf1 = Replace(Rtf1, vbCrLf, "par ")
    Return Rtf1 & "par }"
    End Function

     

    The AlterColor function in TIXT is a joke once you understand this code. It’s only 5 or 6 lines of code. But You will have to DIY if you want it 😀

    #190685
    TWiZA
    Member

    In theory : before the line of code that sends the greet message, you’ll have to:
    GETTEXTLENGTH
    If > 0 then GETTEXT, store it in a variable
    after the greet message is posted, SETTEXT ( your stored text) then send the key “END” to set the cursor at the end of your text.
    I hope this pseudo-code is clear for you.

    #191101
    TWiZA
    Member

    alright, this function is working, but I forgot the clean up:

    private int getUserNameIndex(string strUser)

    these lines must be executed before the function returns the username’s index and exits:

    VirtualFreeEx(processHandle, lvLocalItem.pszText, 0, MEM_RELEASE);
    VirtualFreeEx(processHandle, lvMemItem, 0, MEM_RELEASE);
    CloseHandle(processHandle);

    I randomly noticed this, but my code may have more. Also, not planing to update it, so DIY 😉

    #191102
    TWiZA
    Member

    Thanks. I will wish good persistence instead because coding has nothing to do with luck :))

    #186199
    TWiZA
    Member

    what do you mean by RoomRecorder ?

    #186201
    TWiZA
    Member

    @NVYE wrote:

    This admin board is awesome.

    Thank you !

Viewing 15 posts - 1 through 15 (of 48 total)